hujun260 opened a new pull request, #18135:
URL: https://github.com/apache/nuttx/pull/18135

   ### Summary
   
   This pull request refactors the NuttX critical section implementation to use 
rspinlock_t as the unified foundation while optimizing performance for both SMP 
and non-SMP configurations. The series introduces enhanced spinlock operations, 
consolidates the scheduler interface, and eliminates deprecated synchronization 
mechanisms.
   
   ### Changes Made
   
   1. **Spinlock Extensions** - Add try-lock variants (`rspin_trylock`, 
`rspin_trylock_irqsave`, `rspin_trylock_irqsave_nopreempt`) to support 
non-blocking spinlock acquisition patterns with comprehensive nesting support.
   
   2. **Consistent Rspinlock Interface** - Implement rspinlock count/owner 
tracking even when `CONFIG_SPINLOCK=n` to provide uniform APIs across 
configurations and enable portable synchronization code.
   
   3. **Critical Section Refactoring** - Standardize interface naming, remove 
redundant declarations, and consolidate SMP/non-SMP code paths for improved 
maintainability and reduced compilation complexity.
   
   4. **Performance Optimization** - Optimize critical section scope by 
narrowing protection windows to essential operations only, reducing interrupt 
latency and improving system responsiveness.
   
   5. **Architecture Consolidation** - Replace `up_switch_context` with unified 
`nxsched_switch` interface across all architecture implementations for improved 
consistency and reduced code duplication.
   
   6. **Cleanup and Removal** - Remove deprecated `irqcount` field and 
unnecessary preprocessor directives, simplifying the TCB structure and reducing 
memory overhead.
   
   ### Impact
   
   - **Performance**: Reduced context switch overhead in non-SMP mode and 
optimized critical section scope for better responsiveness
   - **Code Quality**: Improved consistency across SMP/non-SMP configurations 
and reduced code duplication in architecture layers
   - **Maintainability**: Simplified interfaces, standardized naming, and 
consolidated code paths reduce future maintenance burden
   - **Compatibility**: Maintains full backward compatibility with existing 
NuttX applications
   
   ### Files Modified
   
   **Core Scheduler**:
   - `sched/sched/sched.h` - Critical section interface refactoring
   - `sched/irq/irq_csection.c` - IRQ section cleanup
   - `sched/sched_critmonitor.c` - Monitoring code adaptation
   
   **Architecture Headers**:
   - `include/nuttx/spinlock.h` - Spinlock extensions and rspinlock 
standardization
   - `include/nuttx/irq.h` - Critical section declaration updates
   - `include/nuttx/sched.h` - Interface updates
   
   **Utilities**:
   - `drivers/note/note_driver.c` - Remove deprecated irqcount tracking
   - `sched/task/task_exit.c` - Adapt to refactored interface
   - `sched/task/task_restart.c` - Adapt to refactored interface
   
   **Performance**:
   - Multiple scheduler and IPC files adjusted to optimize critical section 
scope
   
   ### Testing Procedures
   
   1. **Unit Tests**: Verify critical section entry/exit on both SMP and 
non-SMP configurations
   2. **Nesting Tests**: Test maximum nesting depth (UINT16_MAX) with rspinlock 
operations
   3. **Performance Tests**: Measure context switch latency improvements on 
non-SMP and interrupt latency on SMP
   4. **Compatibility Tests**: Run full NuttX test suite to ensure no 
regressions
   5. **Architecture Tests**: Verify nxsched_switch implementation on all 
supported architectures
   
   ### Verification Checklist
   
   - [x] Code builds without warnings on all configurations
   - [x] Critical section operations maintain consistent semantics
   - [x] SMP and non-SMP code paths tested
   - [x] Spinlock nesting depth validated
   - [x] Context switch latency measurements verified
   - [x] No memory leaks or resource leaks introduced
   - [x] All existing tests pass
   - [x] Documentation updated for new spinlock operations
   
   ---
   
   ## Simplified PR Description (Concise Version)
   
   ### Summary
   Refactor NuttX critical section implementation using rspinlock_t foundation 
with optimizations for both SMP and non-SMP configurations. Consolidates 
scheduler interface, enhances spinlock operations, and eliminates deprecated 
mechanisms.
   
   ### Key Changes
   - Add `rspin_trylock/irqsave/nopreempt` variants for flexible synchronization
   - Implement consistent rspinlock interface across all configurations
   - Optimize critical section scope for reduced latency
   - Replace `up_switch_context` with `nxsched_switch` for consistency
   - Remove deprecated `irqcount` and cleanup code
   
   ### Benefits
   - Improved performance (reduced overhead in non-SMP mode)
   - Better code maintainability and consistency
   - Backward compatible with existing applications
   - Enhanced nesting support (up to UINT16_MAX)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to