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

   ## Summary                                                                   
      
                                                                                
      
   Optimize common watchdog timer paths to reduce work done inside scheduler    
      
   critical sections.                                                           
      
                                                                                
      
   This includes two changes:                                                   
      
                                                                                
      
   1. Add fast paths for watchdog insertion:                                    
      
      - empty active list                                                       
      
      - new earliest expiration                                                 
      
      - new latest expiration                                                   
      
                                                                                
      
   2. Add `wd_cancel_locked()` for callers that already hold the scheduler      
      
      critical section, and use it from timed wakeup paths:                     
      
      - semaphore post                                                          
      
      - event post                                                              
      
      - signal dispatch                                                         
      
                                                                                
      
   ## Motivation                                                                
      
                                                                                
      
   Watchdog timers are used by common timed wait and scheduling paths, 
including      
   semaphores, events, signals, timers, and delayed work.                       
      
                                                                                
      
   Before this change, watchdog insertion always scanned the active watchdog 
list     
   even for common head/tail insertion cases. Also, timed wakeup paths that 
were      
   already running in a scheduler critical section still called `wd_cancel()`,  
      
   which entered the critical section again.                                    
      
                                                                                
      
   Reducing these costs helps shorten critical-section time in common timer and 
      
   timed-wakeup paths.                                                          
      
                                                                                
      
   ## Details                                                                   
      
                                                                                
      
   ### Fast-path watchdog insertion                                             
      
                                                                                
      
   `wd_insert()` now handles these common cases before falling back to a full 
list    
   scan:                                                                        
      
                                                                                
      
   - active watchdog list is empty                                              
      
   - new watchdog expires before the current head                               
      
   - new watchdog expires after the current tail                                
      
                                                                                
      
   This preserves the existing sorted active-list behavior while avoiding an    
      
   unnecessary linear scan in common cases.                                     
      
                                                                                
      
   ### Locked watchdog cancel helper                                            
      
                                                                                
      
   A new internal helper, `wd_cancel_locked()`, performs watchdog cancellation 
when   
   the caller already holds the scheduler critical section.                     
      
                                                                                
      
   `wd_cancel()` remains the public wrapper and keeps the existing external     
      
   behavior.                                                                    
      
                                                                                
      
   The following timed wakeup paths now use the locked helper:                  
      
                                                                                
      
   - `nxsem_post_slow()`                                                        
      
   - `nxevent_post()`                                                           
      
   - `nxsig_tcbdispatch()`                                                      
      
                                                                                
      
   ## Testing                                                                   
      
   
   sim/nsh


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