This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 16947ddacdd05e27eb7fdcbc69db92d809e0f83c
Author: zhanghongyu <[email protected]>
AuthorDate: Mon Jun 30 20:00:25 2025 +0800

    netdev_upperhalf: modify txavail to be sent directly in the current thread
    
    avoid packet processing delays caused by task switching,
    to support those applications that are extremely time-sensitive.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 drivers/net/netdev_upperhalf.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index b3d386943e2..3d26879c46a 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -380,12 +380,15 @@ static void netdev_upper_txavail_work(FAR struct 
netdev_upperhalf_s *upper)
 
   /* Ignore the notification if the interface is not yet up */
 
+  net_lock();
   if (IFF_IS_UP(dev->d_flags))
     {
       DEBUGASSERT(dev->d_buf == NULL); /* Make sure: IOB only. */
       while (netdev_upper_can_tx(upper) &&
              netdev_upper_tx(dev) == NETDEV_TX_CONTINUE);
     }
+
+  net_unlock();
 }
 
 /****************************************************************************
@@ -701,6 +704,7 @@ static void netdev_upper_rxpoll_work(FAR struct 
netdev_upperhalf_s *upper)
 
   /* Loop while receive() successfully retrieves valid Ethernet frames. */
 
+  net_lock();
   while ((pkt = lower->ops->receive(lower)) != NULL)
     {
       if (!IFF_IS_UP(dev->d_flags))
@@ -754,6 +758,8 @@ static void netdev_upper_rxpoll_work(FAR struct 
netdev_upperhalf_s *upper)
           break;
         }
     }
+
+  net_unlock();
 }
 
 /****************************************************************************
@@ -773,10 +779,8 @@ static void netdev_upper_work(FAR void *arg)
 
   /* RX may release quota and driver buffer, so do RX first. */
 
-  net_lock();
   netdev_upper_rxpoll_work(upper);
   netdev_upper_txavail_work(upper);
-  net_unlock();
 }
 
 /****************************************************************************
@@ -872,7 +876,7 @@ static inline void netdev_upper_queue_work(FAR struct 
net_driver_s *dev)
 
 static int netdev_upper_txavail(FAR struct net_driver_s *dev)
 {
-  netdev_upper_queue_work(dev);
+  netdev_upper_txavail_work(dev->d_private);
   return OK;
 }
 

Reply via email to