Fix-Point opened a new pull request, #21983: URL: https://github.com/apache/nuttx/pull/21983
## Summary This PR adds spinlock debug tooling and the `irq_save()`/`irq_restore()` wrappers, and fixes a small set of spinlock compile-time issues, preparing the ground for broader spinlock instrumentation. 1. **Add `irq_save()`/`irq_restore()` wrappers** (`irq: add irq_save/irq_restore wrapper and replace up_irq_save calls`): introduce architecture-independent wrappers around `up_irq_save()`/`up_irq_restore()` and convert the call sites in upper-layer code. This is complementary to the already merged `include/nuttx/irq.h: add irq_save/irq_restore` (which adds the definitions; this one converts the drivers/subsystems call sites). 2. **Add `irq_save_nopreempt`** (`add irq_save_nopreempt`): a variant that additionally takes the scheduler lock once. 3. **Spinlock debug tools** (`sched/spinlock: Debug tools for spinlock.` plus the `fix bug` follow-up): when `CONFIG_SPINLOCK_DEBUG` is enabled, mark lock acquisition/relock/unlock states, track the holder, and detect relock and multiple-wait misuse. The two-thread spinlock test in `ostest` no longer trips a false multi-wait PANIC; the critical-section lock `g_cpu_irqlock` is exempted from the multiple-wait check, matching the original semantics. 4. **Fix `spin_lock_init` zero-size memset** (`spinlock.h: fix the issue where the Memset buffer size was 0 during spin_lock_init`): guard the memset so a zero-length region is not passed through. 5. **MISRA C-2012 Rule 10.4 fix** (`spinlock: Fix MISRA C-2012 Rule 10.4.`): cast-expression type corrections. 6. **Coverity fix** (`spinlock: Fix Coverity CID 8904187 unsigned comparison with zero`): remove a signedness comparison warning. 7. **Lock-state helpers** (`include/spinlock: add is_in_critical_section.`): lock-state query helpers; the hold check runs inside an `irq_save()` window so a context switch cannot make it lie. 8. **Ignore switch checks in interrupt context** (`sched/spinlock: Ignore switch checks in interrupt context.`): the debug code must keep working in interrupt context. 9. **Fix alignment in `irq_dispatch`** (`sched/irq: fix alignment of intstack check`): style fix for an existing upstream alignment wart. ## Impact - **User impact**: new `irq_save()`/`irq_restore()`/`irq_save_nopreempt()` wrappers and lock-state helpers (`rspin_lock_is_hold`, `rspin_lock_is_locked`, `in_critical_section`); no existing call-site behavior change. - **Build**: builds with and without `CONFIG_SPINLOCK`, and with and without SMP, remain clean. - **Compatibility**: drivers/subsystems that called `up_irq_save()` directly now use the wrapper; no ABI change. - **Documentation**: comments updated on the affected functions. - **Security**: none. - **Hardware**: none. ## Testing Build Host: Linux x86_64; riscv64-unknown-elf-gcc 10.2.0 Boards/Configurations: - `rv-virt:smp` with `CONFIG_SPINLOCK_DEBUG=y`, `CONFIG_TESTING_OSTEST=y` (rv32, 8 CPUs) - `qemu-armv7a` SMP/UP builds Verification: - `tools/checkpatch.sh` green on every commit (11/11). - Full `ostest` on `rv-virt:smp` with `SPINLOCK_DEBUG=y`: two-thread spinlock test completes, no PANIC/assert, `ostest_main: Exiting with status 0`. - Full log: `/disk0/gitcode/.review-tmp/rv-virt-ostest-debug-tools.log` (1415 lines). ``` [Full ostest log will be appended here before final submission] -- 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]
