-
Notifications
You must be signed in to change notification settings - Fork 1.5k
sched/spinlock: Refactor critical section implementation with rspinlock foundation and SMP optimization #18135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
4e30316 to
3435fb0
Compare
|
@hujun260 please fix: |
3435fb0 to
6d88755
Compare
cederom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @hujun260 + for perfect PR descrition :-)
Please review build errors. Are you sure this only depends on apache/nuttx-apps#3375 ?
| do \ | ||
| { \ | ||
| uint16_t count = rspin_lock_count(&g_schedlock); \ | ||
| up_switch_context(tcb, rtcb); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance will degrade on AMP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6d88755 to
5c16756
Compare
Standardize critical section function naming conventions and simplify the interface by removing redundant function declarations and consolidating SMP/non-SMP code paths for improved maintainability. Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
Remove unnecessary preprocessor #undef directives to improve code clarity and reduce conditional compilation complexity. This cleanup aligns with the refactored critical section interface. Signed-off-by: hujun5 <hujun5@xiaomi.com>
Consolidate architecture-specific context switching by replacing up_switch_context with unified nxsched_switch interface, reducing code duplication and improving scheduler integration consistency across all architecture implementations. Signed-off-by: hujun5 <hujun5@xiaomi.com>
Optimize critical section usage by reducing protection scope to only cover essential operations, improving system responsiveness and reducing interrupt latency while maintaining synchronization safety. Signed-off-by: hujun5 <hujun5@xiaomi.com>
Refactor critical section implementation to use rspinlock_t as the foundation, providing consistent synchronization semantics across SMP and non-SMP configurations with improved nesting support and reduced overhead. Signed-off-by: hujun5 <hujun5@xiaomi.com>
Clean up and remove the deprecated irqcount field from task structures as it is no longer used by the refactored critical section implementation. This simplifies the TCB structure and reduces memory overhead. Signed-off-by: hujun5 <hujun5@xiaomi.com>
Inline enter_critical_section function calls in performance-critical paths to reduce function call overhead while maintaining consistent semantics, improving overall system latency and responsiveness in real-time scenarios. Signed-off-by: hujun5 <hujun5@xiaomi.com>
Optimize critical section implementation for non-SMP configurations by directly using up_irq_save/restore instead of rspinlock operations, reducing context switch overhead while maintaining compatibility with SMP code paths. Signed-off-by: hujun5 <hujun5@xiaomi.com>
5c16756 to
1e6af3a
Compare

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.
should merge after apache/nuttx-apps#3375
Changes Made
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.Consistent Rspinlock Interface - Implement rspinlock count/owner tracking even when
CONFIG_SPINLOCK=nto provide uniform APIs across configurations and enable portable synchronization code.Critical Section Refactoring - Standardize interface naming, remove redundant declarations, and consolidate SMP/non-SMP code paths for improved maintainability and reduced compilation complexity.
Performance Optimization - Optimize critical section scope by narrowing protection windows to essential operations only, reducing interrupt latency and improving system responsiveness.
Architecture Consolidation - Replace
up_switch_contextwith unifiednxsched_switchinterface across all architecture implementations for improved consistency and reduced code duplication.Cleanup and Removal - Remove deprecated
irqcountfield and unnecessary preprocessor directives, simplifying the TCB structure and reducing memory overhead.Simplified PR Description (Concise Version)
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
rspin_trylock/irqsave/nopreemptvariants for flexible synchronizationup_switch_contextwithnxsched_switchfor consistencyirqcountand cleanup codeBenefits
Impact
Files Modified
Core Scheduler:
sched/sched/sched.h- Critical section interface refactoringsched/irq/irq_csection.c- IRQ section cleanupsched/sched_critmonitor.c- Monitoring code adaptationArchitecture Headers:
include/nuttx/spinlock.h- Spinlock extensions and rspinlock standardizationinclude/nuttx/irq.h- Critical section declaration updatesinclude/nuttx/sched.h- Interface updatesUtilities:
drivers/note/note_driver.c- Remove deprecated irqcount trackingsched/task/task_exit.c- Adapt to refactored interfacesched/task/task_restart.c- Adapt to refactored interfacePerformance:
Testing
Verification Checklist