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

   ## Summary
   
   Replace global critical section protection with fine-grained spinlock 
protection for signal management structures. Signal action queue 
(tg_sigactionq) and signal pending queue (tg_sigpendingq) are now protected 
using `spin_lock_irqsave/spin_unlock_irqrestore(&group->tg_lock)` instead of 
`enter/leave_critical_section()`. This improves interrupt latency and SMP 
scalability while maintaining thread-safe access to signal data structures.
   
   ## Changes
   
   - **sched/signal/sig_action.c**: 
     - Add spinlock protection around signal action queue modifications (sq_rem 
and sq_addlast)
     - Use `spin_lock_irqsave/spin_unlock_irqrestore(&group->tg_lock)` around 
queue operations
     - Move `irqstate_t flags` declaration to function scope for consistency
   
   - **sched/signal/sig_cleanup.c**:
     - Add `#include <nuttx/spinlock.h>` header
     - Add spinlock protection in nxsig_release() for signal action and pending 
signal queue cleanup
     - Acquire/release lock around each dequeue operation to prevent deadlock 
during cleanup
   
   - **sched/signal/sig_dispatch.c**:
     - Add spinlock protection in nxsig_find_pendingsignal() to protect pending 
signal list traversal
     - Add spinlock protection in nxsig_add_pendingsignal() around pending 
signal queue insertion
     - Include comment explaining why lock is needed for interrupt-level signal 
additions
   
   - **sched/signal/sig_pending.c**:
     - Replace `enter_critical_section()` with 
`spin_lock_irqsave(&group->tg_lock)` 
     - Replace `leave_critical_section()` with 
`spin_unlock_irqrestore(&group->tg_lock, flags)`
     - Maintains same semantics with reduced interrupt latency
   
   - **sched/signal/sig_removependingsignal.c**:
     - Add `#include <nuttx/spinlock.h>` header
     - Replace global critical section with spinlock on signal pending queue 
access
     - Protect pending signal removal operations with group-level lock
   
   ## Benefits & Technical Details
   
   - **Reduced interrupt latency**: Spinlock-based synchronization keeps 
interrupts enabled during most operations, allowing faster interrupt response
   - **SMP scalability**: Fine-grained per-group locking enables parallel 
signal operations on different task groups
   - **Interrupt-safe**: Spinlock protects against simultaneous access from 
interrupt handlers and task context
   - **Lock scope optimization**: In cleanup path, lock is released between 
queue element processing to prevent excessive lock hold times
   - **Consistency**: All signal queue accesses now use uniform spinlock 
protection pattern
   
   ## Testing
   
   - Verified signal delivery and pending signal operations work correctly in 
single-threaded context
   - Confirmed proper synchronization when signals are sent from multiple 
threads in same group
   - Tested interrupt-safe pending signal addition from IRQ handlers
   - Validated on SMP systems that signal queues are accessed safely without 
global interrupt disabling
   - Confirmed no performance regression in signal dispatch path
   - Verified signal cleanup during task group termination works correctly with 
spinlock protection
   
   ## Impact
   
   - **Performance**: Reduced interrupt latency and improved context switching 
speed on SMP systems
   - **Real-time**: Better response time for external interrupts during signal 
operations
   - **Robustness**: Proper synchronization for concurrent signal operations 
from interrupt and task contexts
   - **Compatibility**: No API changes, fully backward compatible
   - **Scope**: Affects all signal delivery, pending signal management, and 
signal action installation operations


-- 
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