Skip to content

Conversation

@hujun260
Copy link
Contributor

Summary

This pull request refactors the spinlock instrumentation interface to eliminate redundant wrapper functions. Instead of calling separate sched_note_spinlock_lock(), sched_note_spinlock_locked(), sched_note_spinlock_abort(), and sched_note_spinlock_unlock() functions, the code now directly calls the unified sched_note_spinlock() function with the appropriate event type parameter. This simplification reduces code duplication, improves maintainability, and eliminates unnecessary function call overhead.

Changes

File modifications:

  • include/nuttx/spinlock.h: Removed 4 wrapper function declarations, updated all inline calls to use sched_note_spinlock(spinlock, type) directly, added include for <nuttx/sched_note.h>
  • drivers/note/note_driver.c: Removed 4 wrapper function implementations, modified sched_note_spinlock() to accept (spinlock, type) and get current task internally via running_task()
  • include/nuttx/sched_note.h: Updated sched_note_spinlock() function signature and stub macro

Statistics: 14 insertions(+), 48 deletions(-) - net reduction of 34 lines

Impact

  • Code Quality: Eliminates 4 redundant wrapper functions, reduces duplication
  • Maintainability: Single unified interface instead of 5 variations
  • Performance: Removes wrapper function call overhead in critical spinlock path
  • API Design: Cleaner interface with explicit event type parameter
  • Backward Compatibility: Internal API change only, no impact on external users

Technical Justification

Why consolidate instrumentation?

  1. Reduce duplication: Four wrapper functions performing nearly identical operations
  2. Unified interface: Single function handles all spinlock instrumentation events
  3. Explicit semantics: Type parameter clearly indicates which event is being recorded
  4. Easier maintenance: Changes to spinlock instrumentation happen in one place
  5. Lower overhead: Direct function calls eliminate wrapper invocation cost

Signature change:

  • Before: sched_note_spinlock(tcb, spinlock, type)
  • After: sched_note_spinlock(spinlock, type) with tcb obtained via running_task()

Testing

Verified with:

  • ✅ Spinlock instrumentation captures all event types correctly
  • ✅ Build succeeds with CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS enabled/disabled
  • ✅ No functional regression in spinlock operations
  • ✅ Trace events properly recorded for LOCK, LOCKED, ABORT, UNLOCK states
  • ✅ Performance metrics stable or improved

Related Work

Part of spinlock optimization series focusing on code simplification and interface consolidation.

Remove wrapper functions (sched_note_spinlock_lock, sched_note_spinlock_locked,
sched_note_spinlock_abort, sched_note_spinlock_unlock) and call the unified
sched_note_spinlock() function directly with appropriate type parameter.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
@github-actions github-actions bot added Area: Drivers Drivers issues Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Jan 26, 2026
@hujun260 hujun260 marked this pull request as draft January 26, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants