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

   ## Summary
   
   **Why.** The five global signal free lists (`g_sigfreeaction`, 
`g_sigpendingaction`, `g_sigpendingirqaction`, `g_sigpendingsignal`, 
`g_sigpendingirqsignal`) are protected by `enter_critical_section()`. On SMP 
that takes the global lock and disables interrupts on all CPUs just to push one 
node back onto a list. The sigaction free list also used its own private 
spinlock, so two locks protected structures of the same kind.
   
   **What.** Protect all five free lists with one dedicated spinlock, 
`g_sigspinlock`, so the release paths no longer take the global critical 
section, and drop the private `g_sigaction_spin`.
   
   **How.**
   - `signal.h` / `sig_initialize.c`: declare and define `g_sigspinlock`.
   - `sig_action.c`: the sigaction free list uses `g_sigspinlock`.
   - `sig_allocpendingsigaction.c`, `sig_releasependingsigaction.c`, 
`sig_releasependingsignal.c`: the critical section around the list operations 
becomes `g_sigspinlock`. The allocation paths relied on the critical section 
held by their caller; since the release paths now only take the spinlock, the 
allocation paths (including the interrupt-context ones) take it too.
   - `sig_dispatch.c`: `nxsig_alloc_pendingsignal()` takes the spinlock around 
`sq_remfirst()`. `nxsig_alloc_dyn_pending()` adds its refilled structures under 
the spinlock, because the release paths no longer hold the critical section.
   
   The critical section in `nxsig_tcbdispatch()` stays as it is. Every consumer 
of the free lists runs inside it, so a structure that 
`nxsig_alloc_dyn_pending()` reserves still cannot be taken by another sender 
before it is used. The unlocked `sq_empty()` checks in 
`nxsig_alloc_dyn_pending()` are safe for the same reason: while the critical 
section is held, only release paths can change the lists, and they only make 
them longer. A stale "empty" result means one extra structure gets allocated.
   
   Lock order is critical section → `g_sigspinlock`. The spinlock is held only 
around list operations. No allocation, logging, or critical-section entry 
happens under it.
   
   ## Impact
   
   - Users / API: none.
   - Build: none. No new Kconfig option.
   - Hardware: on SMP, releasing a signal structure no longer takes the global 
critical section; allocation still runs inside the critical section of 
`nxsig_tcbdispatch()`. Non-SMP: `spin_lock_irqsave()` reduces to disabling 
local interrupts, same as before.
   - Documentation: none.
   - Security: none.
   - Compatibility: none.
   
   ## Testing
   
   Host: Ubuntu x86_64, base master 31bb54f11bd, apps 0527829ccaf 
(smartl-c906:knsh was built on the previous base e9eefaa0e9a; the rebase only 
pulls in unrelated sched/init changes).
   
   | Config | Result |
   |---|---|
   | sim:smp | build OK |
   | sim:ostest | `ostest_main: Exiting with status 0` (1064 s) |
   | qemu-armv8a:nsh_smp (4 CPUs) | ostest `Exiting with status 0` |
   | smartl-c906:knsh | build OK |
   | qemu-intel64:citest_smp (4 CPUs), LTP | kill_1_1, kill_2_1, killpg_1_1, 
killpg_2_1, sigaction_1_1, sigwait_1_1, sigpending_1_1, pthread_kill_1_1, 
sigaddset_1_1, raise_1_1 PASS; sigqueue_7_1 delivers 32..63 in order |
   | checkpatch | All checks pass |
   


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