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

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


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