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

   ## Summary
   
   Rework the network device locking primitives around the per-device           
                                                                                
                                               
   rmutex (d_lock) and introduce an IOB allocator that breaks the new           
                                                                                
                                               
   per-connection / per-device locks while waiting.                             
                                                                                
                                               
                                                                                
                                                                                
                                               
   - **netdev_lock: change netdev_lock/unlock to a macro definition** —         
                                                                                
                                               
     d_lock is already an rmutex, so replace the out-of-line                    
                                                                                
                                               
     netdev_lock()/netdev_unlock() wrappers with macros over                    
                                                                                
                                               
     nxrmutex_lock()/unlock() and drop netdev_lock.c.                           
                                                                                
                                               
   - **netdev_lock: add netdev_trylock/breaklock/restorelock** — add the        
                                                                                
                                               
     try/break/restore variants as macros, matching the other rmutex locks.     
                                                                                
                                               
   - **net: modify g_netdevices_lock with rmutex_t** — IP forwarding can take   
                                                                                
                                               
     netdev_list_lock recursively (netdev_foreach/netdev_verify under a caller  
                                                                                
                                               
     that already holds it), so make g_netdevices_lock an rmutex.               
                                                                                
                                               
   - **net_lock.c: add conn_dev_iobtimedalloc to replace net_iobtimedalloc** —  
                                                                                
                                               
     net_iobtimedalloc() only broke the global net lock while waiting for an    
                                                                                
                                               
     IOB. Add conn_dev_iobtimedalloc()/conn_dev_ioballoc() that break both the  
                                                                                
                                               
     connection s_lock and the device d_lock, and route the UDP/TCP/PKT/CAN     
                                                                                
                                               
     write-buffer allocators through them.
   
   ## Impact
   
   - netdev_lock/unlock/trylock/breaklock/restorelock are now inline macros     
                                                                                
                                               
     over d_lock (rmutex); no functional change for existing callers.           
                         
   - g_netdevices_lock becomes recursive (rmutex), enabling nested              
                         
     netdev_list_lock under IP forwarding.                                      
                         
   - Write-buffer IOB allocation waits no longer block holders of the           
                                                                                
                                               
     per-connection/per-device locks. CAN callers (can_raw/can_isotp) were      
                                                                                
                                               
     updated to the new can_iob_timedalloc() signature.
   
   ## Testing
   
   Built and run on the simulator (flat build).                                 
                                                                                
                                               
                                                                                
                                                                                
                                               
   Build / checkpatch:                                                          
                                                                                
                                               
   - `./tools/configure.sh sim:dynconns` + NET_CAN/CAN_RAW/CAN_ISOTP — make     
                                                                                
                                               
     and link succeed.                                                          
                                                                                
                                               
   - `./tools/checkpatch.sh -c -m -g HEAD~4..HEAD` — passes for all 4 commits.  
                                                                                
                                               
                                                                                
                                                                                
                                               
   Runtime (loopback devices on sim):                                           
                                                                                
                                               
                                                                                
                                                                                
                                               
   UDP (sim:tcploop + NET_UDP, 127.0.0.1):                                      
                                                                                
                                               
                                                                                
                         
       nsh> udploop
       udploop: received 'udp-loopback-hello' (18 bytes) from 127.0.0.1:23203   
                         
       udploop: UDP loopback PASS
                                                      
   TCP (sim:tcploop, tcpclient):
                                                      
       nsh> tcpclient
       server: Accepting connections on port 5471
       client: Connected
       server: Connection accepted -- receiving
   
   SocketCAN (sim:lely-sock, SIM_CANDEV_SOCK bridged to a host vcan "can0";
   exercises the updated can_iob_timedalloc() callers in can_raw.c TX/RX):
   
       nsh> ifup can0
       ifup can0...OK
       nsh> canloop
       canloop: looped CAN id=0x123 dlc=4 data=deadbeef
       canloop: SocketCAN loopback PASS
   
   


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