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

   ## Summary
   
   When a signal with a handler is for the calling thread, 
`nxsig_queue_action()` runs the handler at once. It is called from 
`nxsig_tcbdispatch()`, which holds the critical section. So the handler runs 
with interrupts disabled, and on SMP its thread holds the global critical 
section lock until the handler returns.
   
   In a protected or kernel build this happens at the end of each system call 
that leaves a pending signal unmasked: the user handler runs in user mode with 
interrupts disabled. Its CPU takes no interrupt, and the other CPUs wait for 
the critical section lock until the handler returns.
   
   This PR lets `nxsig_queue_action()` only mark the delivery. 
`nxsig_tcbdispatch()` delivers after it leaves the critical section. A signal 
that an interrupt queues meanwhile is delivered in the same loop.
   
   ## Impact
   
   A handler that runs at once for the calling thread now runs with interrupts 
enabled and without the critical section. It still runs before 
`nxsig_tcbdispatch()` returns, so `raise()` and `kill()` of the calling thread 
behave as before.
   
   Not changed here: `nxsig_unmask_pendingsignal()` holds `sched_lock()` while 
it dispatches, so such a handler still runs with preemption disabled.
   
   ## Testing
   
   `qemu-armv8a:knsh`, 1 CPU, with `CONFIG_SCHED_IRQMONITOR=y`. A test program 
blocks SIGUSR1, sends it to itself and unblocks it, so the handler runs at the 
end of `sigprocmask()`. The handler spins for about 50 ms and reads 
`/proc/irqs` before and after (a read returns the interrupts since the last 
read). Over 100 handlers:
   
   | | master | this PR |
   |---|---|---|
   | handlers that took no interrupt while they spun | 100 | 0 |
   
   `ostest` exits with status 0 on `qemu-armv8a:knsh` and on `qemu-armv8a:nsh` 
(flat build). Build: `lm3s6965-ek:qemu-flat`, no warnings.
   


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