Repository navigation
Conversation
Fix-Point
requested review from
Donny9,
GUIDINGLI,
anchao,
btashton,
hartmannathan,
jerpelea,
masayuki2009,
michallenc,
pkarashchenko,
pussuw,
raiden00pl,
simbit18,
xiaoxiang781216,
yamt and
yf13
as code owners
November 23, 2026 12:07
Fix-Point
force-pushed
the
nuttx-spinlock-debug
branch
from
November 23, 2026 12:32
c1e031c to
7f3462f
Compare
jerpelea
requested changes
Nov 23, 2026
jerpelea
left a comment
Contributor
There was a problem hiding this comment.
please split this PR in 2 logical separate PRs
complete the debug/monitoring tools
fix unlock ordering
xiaoxiang781216
approved these changes
Nov 23, 2026
GUIDINGLI
previously approved these changes
Nov 23, 2026
seqlock: Move the header files to decouple compilation dependencies. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: hujun5 <hujun5@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
The critmon previously only tracked interrupt disable time within enter/leave_critical_section(). But spinlock and rspinlock also disable interrupts without being accounted for. Move nxsched_critmon_csection() to include/nuttx/irq.h and instrument irq_save()/irq_restore() directly, so all interrupt disable paths are automatically monitored. Add crit_count nesting counter in tcb to prevent recursion when perf_gettime() triggers irq_save internally. Also add critmon calls in rspin_breaklock/restorelock for proper tracking across context switches, and use up_irq_save directly in this_task() to avoid recursion. Remove #include <nuttx/irq.h> from all arch/<arch>/include/irq.h headers to break the circular dependency introduced by moving nxsched_critmon_csection() into nuttx/irq.h, since nuttx/irq.h now depends on arch irq primitives (up_irq_save/up_irq_restore) which are defined in arch headers. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Rename all csection-specific monitoring symbols to irqdis to better
reflect that the monitoring now covers all IRQ-disabled paths, not
just enter_critical_section.
Symbol renames:
- SCHED_CRITMONITOR_MAXTIME_CSECTION -> MAXTIME_IRQDISABLE (Kconfig)
- nxsched_critmon_csection() -> nxsched_critmon_irqdisable()
- CHECK_CSECTION -> CHECK_IRQDIS
- TCB fields: crit_start/max/count/caller/max_caller
-> irqdis_start/max/count/caller/max_caller
- g_crit_max -> g_irqdis_max
Update comments and Kconfig help text to replace 'critical section'
with 'IRQ disabled' where the statement now covers all irq_save /
irq_restore call sites.
Assisted-By: mimo-v2.6-pro
Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
…lock rspin_lock/rspin_unlock were missing sched_note_spinlock() trace points that spin_lock/spin_unlock already have. Add NOTE_SPINLOCK_LOCK, NOTE_SPINLOCK_LOCKED and NOTE_SPINLOCK_UNLOCK instrumentation to rspin_lock and rspin_unlock for symmetry with the non-recursive spinlock API. Only first-time acquisition and final release are traced, recursive lock/unlock are not instrumented. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: ligd <liguiding1@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Add rspin_lock_notrace, rspin_lock_irqsave_notrace, rspin_unlock_notrace and rspin_unlock_irqrestore_notrace that skip spinlock_mark_locking/locked/unlocked and sched_note_spinlock calls. This mirrors the existing spin_lock_notrace/spin_lock_irqsave_notrace pattern for non-recursive spinlocks. The notrace variants are needed by instrumentation code (e.g. noteram driver) that must acquire rspinlocks without triggering recursive note events. Refactor rspin_lock to call rspin_lock_notrace internally, and rspin_unlock to call rspin_unlock_notrace internally, keeping the trace/mark logic only in the outer wrappers. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: ligd <liguiding1@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
The _notrace variants of spin_lock/unlock_irqsave/restore are called from within the trace/note subsystem itself. If these variants call irq_save()/irq_restore() which may be instrumented, it leads to infinite recursion or ABBA deadlock when the note subsystem tries to acquire a spinlock while already holding one. Changes: - Use up_irq_save()/up_irq_restore() in all _notrace variants to bypass any instrumentation in the IRQ save/restore path. - In spin_lock_irqsave(), call irq_save() first (instrumented), then spin_lock_notrace() separately, so the trace note happens outside the critical irq-disabled region setup. - In spin_unlock_irqrestore(), call spin_unlock_notrace() first, emit the trace note, then call irq_restore() last. - For UP (non-SMP) builds, properly implement rspin_lock_notrace and rspin_unlock_notrace as standalone macros, and provide dedicated rspin_lock_irqsave_notrace/rspin_unlock_irqrestore_notrace using up_irq_save()/up_irq_restore() instead of aliasing to the traced versions. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
…upt context 1. spinlock.h: enter/leave_critical_section_notrace were calling traced irq_save()/irq_restore() (non-SMP) or traced rspin_lock_irqsave/rspin_unlock_irqrestore (SMP), which invoke nxsched_critmon_irqdisable() and modify irqdis_count. Replace with up_irq_save/up_irq_restore (non-SMP) and the _notrace spinlock variants (SMP) to avoid unintended critmon side effects. 2. spinlock.h: Remove nxsched_critmon_irqdisable() from the else branch of rspin_unlock_irqrestore_notrace() (SMP). The notrace variant should not invoke any monitoring code. Move the balance call to the traced rspin_unlock_irqrestore() only. 3. sched_critmonitor.c: Skip irqdis tracking entirely when called from interrupt context (up_interrupt_context()). IRQ handlers run with interrupts already disabled by hardware, so tracking irq disable duration inside them is meaningless and can cause irqdis_count imbalance across context switches. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This is a series-original fix: it completes the seqlock ripple outside the original patches' file set; the individual deltas have no single original patch (they are master-side form divergences plus already covered rewrites of the seqlock line). The seqcount_t sequence member is now atomic_t on SMP (picked from f369edc), so drop the (FAR atomic_t *) casts, use ~1 for the parity mask, and adopt the downstream header organization (EXTERN block, single <nuttx/arch.h> include, param form) so seqlock.h matches the downstream end state exactly. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This is a series-original fix: it completes the symbol rename outside the original patch's file set; it is not present in the original history. The irqdis rename left two dangling consumers: the critical sections documentation still names the old Kconfig symbol, and the nxgdb TCB field declarations still reference the old crit_* field names, which breaks GDB field resolution. Replace the identifiers so every tree consumer follows the rename. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This is a series-original fix: it completes the include-cycle break outside the original patch's file set; it is not present in the original history. The irqdis monitoring change moved nxsched_critmon_irqdisable() and the instrumented irq_save()/irq_restore() into <nuttx/irq.h>, which now depends on the arch primitives up_irq_save()/up_irq_restore(). The original change removed #include <nuttx/irq.h> from the top-level arch/<arch>/include/irq.h headers, but arch headers that define up_irq_save()/up_irq_restore() themselves still pull in <nuttx/irq.h> first, so a translation unit entering through those headers sees an implicit declaration of up_irq_save() and then fails on "static declaration follows non-static declaration". Drop the include from those headers as well, per the same rationale. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Enabling CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQDISABLE on RISC-V fails to compile because arch/mode.h includes nuttx/irq.h, creating a circular dependency that leaves up_irq_save() undefined at the point of use. Remove the unnecessary reverse include and add the missing direct stdbool.h dependency. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: Gan Jing <ganjing@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
…debugging. Add CONFIG_SPINLOCK_BACKTRACE: when enabled, record the full backtrace of the task that locked the spinlock and print it on misuse, replacing the single caller frame. Mark/clear the recorded backtrace in the spinlock mark_locked/mark_unlocked paths, and make the backtrace and pid-hash locks no-trace so the debug paths do not recurse into the spinlock mark machinery. Adapted for master: - sched/sched_gettcb.c: no g_pidhashlock in the master tree (already lock-free), the no-trace conversion has no target. - keeps the otherwise identical vela shape (stack field, conditional SPINLOCK_DEBUG_INIT, CONFIG_SPINLOCK_BACKTRACE). Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
The is_hold helper used the raw up_irq_save()/up_irq_restore() window and read the owner only through the atomic value. Align with the downstream implementation: use the instrumented irq_save()/irq_restore() window on SMP, and on !CONFIG_SPINLOCK builds report the recursive count from local_val (no atomic read is needed because interrupts are not disabled and the lock is task-local there). This is a series-original fix: it completes the alignment of the merge-stream helper with the reference implementation. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Add noinstrument_function attribute to all spinlock _notrace functions to prevent them from being instrumented when CONFIG_ARCH_INSTRUMENT_ALL is enabled. These functions are used in the instrument callback path and must not trigger instrumentation to avoid infinite recursion. Pick-adapted: three of the five call sites already carried the attribute in this tree (from the merged spinlock debug series), so only the missing spin_trylock_notrace() and spin_lock_irqsave_notrace() attributes are applied here. Assisted-By: mimo-v2.6-pro Signed-off-by: yezhonghui <yezhonghui@xiaomi.com>
spin_lock()/spin_trylock()/spin_lock_irqsave() recorded the holder (spinlock_mark_locked) after the busy-wait accounting and the sched_note trace, while the reference implementation marks the lock as held immediately after acquiring it. Reorder so that a relock misuse is detected before the accounting/trace steps and the holder is registered as soon as the lock is taken. This is a series-original fix: it aligns the merged spinlock helpers with the reference ordering. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
The rspinlock nesting comment said the lock can be nested UINT8_MAX deep while the assert and the count field allow up to UINT16_MAX. Align the comment with the actual limit. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Breaking the irq.h include cycles removed the reverse #include <nuttx/irq.h> from the arch irq headers. Chip headers and driver headers that use xcpt_t (defined in <nuttx/irq.h>) previously relied on that transitive include, which turned into a build error (e.g. imxrt1180-evk/nsh: unknown type name 'xcpt_t' in imxrt_rgpio.h). Add the explicit #include <nuttx/irq.h> to every arch header that uses xcpt_t and did not include it directly. This is a series-original fix: it completes the include-cycle break by adding the missing direct dependencies. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Fix-Point
dismissed stale reviews from GUIDINGLI and xiaoxiang781216
via
November 25, 2026 01:41
5ca873c
Fix-Point
force-pushed
the
nuttx-spinlock-debug
branch
from
November 25, 2026 01:41
a1f7d1d to
5ca873c
Compare
xiaoxiang781216
previously approved these changes
Nov 25, 2026
Split sched_note hooks that take a runtime type/event parameter into separate per-type macros with compile-time constant type. This prepares for static key replacement where each branch site needs a fixed key address. - irqhandler(i,h,e) -> irq_enter(i,h) + irq_leave(i,h) - preemption(t,l) -> preempt_lock(t) + preempt_unlock(t) - csection(t,e) -> csection_enter(t) + csection_leave(t) - spinlock(s,type) -> spinlock_lock/locked/unlock/abort(s) - wdog(e,h,a) -> wdog_start/cancel/enter/leave(h,a) - wqueue(e,w,a) -> wqueue_start/cancel/enter/leave(w,a) - heap(e,h,m,s,c) -> heap_add/remove/alloc/free(h,m,s,c) Old composite macros are removed; callers use new specific macros. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com> Signed-off-by: huojianchao <huojianchao@xiaomi.com> Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Fix-Point
force-pushed
the
nuttx-spinlock-debug
branch
from
November 25, 2026 03:19
5ca873c to
898b9b4
Compare
xiaoxiang781216
approved these changes
Nov 25, 2026
GUIDINGLI
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR brings the spinlock debug/monitoring tools to the reference level: IRQ-disabled-time monitoring for spinlocks, holder call-stack backtrace, the notrace split and the remaining alignments of the spinlock helpers.
sched/irq: extend interrupt-disabled time monitoring to spinlock+sched/spinlock: fix critmonitor irqdis tracking in notrace and interrupt context): the critmon timers account the interrupt-disabled window while a spinlock is held (nxsched_critmon_irqdisable()), and the accounting stays consistent in the notrace paths and in interrupt context.task_restart: restore critmon info): a restarted child no longer inherits stale per-task maxima.csectionmonitoring symbols toirqdis(sched/irq: rename csection monitoring symbols to irqdis+sched/irq: complete the irqdis rename in documentation and nxgdb): counters are named after the disabled-interrupt window they measure; the rename spans the source tree, Kconfig help, documentation and nxgdb, with a "no remaining references" check.sched/spinlock: Add backtrace information of lock holder in spinlock debugging.): withCONFIG_SPINLOCK_BACKTRACEthe debug tools record the holder call stack so misuse reports show the faulting code.add sched_note_spinlock trace points,add notrace versions,separate trace and notrace irq paths to fix recursion,sched/note: split composite hook macros into per-type entries): the rspinlock paths distinguish traced and notrace variants so instrumentation does not recurse; composite hooks are split per type.seqlock: Move the header files to decouple compilation dependencies.+seqlock: align seqlock.h with the downstream seqlock terminal form): the seqlock header is decoupled and its types aligned (seqcount_t.sequenceasatomic_ton SMP).irq.hinclude cycles (sched/irq: break the remaining irq.h include cycles in arch headers+arch/risc-v: fix circular include that breaks critmon build+arch: include nuttx/irq.h where xcpt_t is used): arch headers that define the irq primitives no longer include<nuttx/irq.h>themselves; headers usingxcpt_tget the explicit include (fixes the imxrt1180-evk/nsh build).spinlock: align rspin_lock_is_hold with the downstream form,spinlock: add noinstrument_function to _notrace functions,spinlock: mark the lock as held before the busy-wait accounting,spinlock: fix the max nesting depth comment):is_holduses the instrumented window and thelocal_valcount on!CONFIG_SPINLOCK; the notrace helpers carrynoinstrument_function; the holder is registered before the accounting/trace steps; the nesting comment matches theUINT16_MAXlimit.Depends-On: #22243 (unlock ordering fix, already merged).
Impact
csection-named symbols renamed toirqdis.CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQDISABLE/BUSYWAITdimensions cover spinlock holders;CONFIG_SPINLOCK_BACKTRACE(depends onSPINLOCK_DEBUG && LIBC_BACKTRACE_DEPTH > 0) adds holder stack recording;#include <nuttx/irq.h>removed from arch headers and added to 32xcpt_tusers.nxsched_critmon_csection→nxsched_critmon_irqdisable,crit_*TCB fields →irqdis_*); procfs/nxgdb tools updated.Testing
Build Host: Linux x86_64
Boards/Configurations:
qemu-armv7a:smpwithCONFIG_SPINLOCK_DEBUG=y,CONFIG_SPINLOCK_BACKTRACE=y,CONFIG_SCHED_CRITMONITOR=y,CONFIG_SCHED_BACKTRACE=y,CONFIG_TESTING_OSTEST=yrv-virt:smp(risc-v) withCONFIG_SPINLOCK_DEBUG=yimxrt1180-evk:nsh(restores thexcpt_tinclude chain)Verification:
tools/checkpatch.shgreen on every commit (19/19).ostestonqemu-armv7a:smp4 CPUs with the full feature chain: wqueue/HPWORK reports no false relock, all segments complete,ostest_main: Exiting with status 0./disk0/gitcode/.review-tmp/ostest-20261124.log(1423 lines).