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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4c10e9c71e2 arch/mips/pic32mz: limit the Wi-Fi frames queued in the 
library.
4c10e9c71e2 is described below

commit 4c10e9c71e2076aa8b1e45dea74844d0f4f0347f
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Sat Oct 10 09:25:24 2026 -0300

    arch/mips/pic32mz: limit the Wi-Fi frames queued in the library.
    
    wlan_transmit() copied the packet to a library buffer and released it
    at once, so the TX quota of the network device never limited anything.
    When the application sent faster than the radio, the library queue grew
    until the packet pool and then the whole heap were exhausted (106 KB of
    108 KB in use with UDP from the board to a station).
    
    Keep the network packet until the library frees the buffer, and signal
    the TX done event from there.  The TX quota now bounds the frames in
    flight; it is raised from 4 to 16 to keep the radio fed.
    
    Tested on an EV49N51A as Soft-AP with UDP from the board to a station:
    heap peak 106 KB -> 51 KB, throughput unchanged (22.6 Mbit/s), no
    leak after repeated station reassociation under load.
    
    Assisted-by: Claude Code:claude-sonnet-5-5
    Signed-off-by: Daniel P. Carvalho <[email protected]>
---
 arch/mips/src/pic32mz/pic32mz_w1_wlan.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/arch/mips/src/pic32mz/pic32mz_w1_wlan.c 
b/arch/mips/src/pic32mz/pic32mz_w1_wlan.c
index e7e25163fbb..b650f4dedb5 100644
--- a/arch/mips/src/pic32mz/pic32mz_w1_wlan.c
+++ b/arch/mips/src/pic32mz/pic32mz_w1_wlan.c
@@ -201,7 +201,7 @@
 #define WLAN_SCAN_TIMEOUT       SEC2TICK(10)
 
 #define WLAN_RX_QUOTA           8
-#define WLAN_TX_QUOTA           4
+#define WLAN_TX_QUOTA           16
 
 #define WLAN_CRYPTO_DEFER_MAX   8
 
@@ -955,7 +955,13 @@ static int wlan_transmit(FAR struct netdev_lowerhalf_s 
*dev,
     }
 
   netpkt_copyout(dev, buf + WLAN_TX_HDROFFSET, pkt, len, 0);
-  netpkt_free(dev, pkt, NETPKT_TX);
+
+  /* The packet is kept (and so its TX quota) until the library frees the
+   * buffer, see DRV_PIC32MZW_MemFree().  This bounds the frames queued in
+   * the library, which would otherwise be limited by the heap only.
+   */
+
+  wlan_hdr(buf)->spare = pkt;
 
   /* [EX] The library frees the buffer once it has been sent */
 
@@ -1472,6 +1478,7 @@ int8_t DRV_PIC32MZW_MemAddUsers(FAR void *buf, int count)
 int8_t DRV_PIC32MZW_MemFree(FAR void *buf)
 {
   FAR struct wlan_hdr_s *hdr;
+  FAR netpkt_t *pkt;
   irqstate_t flags;
 
   if (buf == NULL)
@@ -1493,16 +1500,28 @@ int8_t DRV_PIC32MZW_MemFree(FAR void *buf)
       g_pktmem_pri[hdr->prio].num_allocd--;
     }
 
+  /* A transmitted frame: release its network packet */
+
+  pkt        = hdr->spare;
+  hdr->spare = NULL;
+
   if (wlan_inpool(hdr))
     {
       sq_addlast((FAR sq_entry_t *)hdr, &g_wlan.pool);
       leave_critical_section(flags);
-      return 1;
+    }
+  else
+    {
+      leave_critical_section(flags);
+      kmm_free(hdr->alloc);
     }
 
-  leave_critical_section(flags);
+  if (pkt != NULL)
+    {
+      netpkt_free(&g_wlan.dev, pkt, NETPKT_TX);
+      netdev_lower_txdone(&g_wlan.dev);
+    }
 
-  kmm_free(hdr->alloc);
   return 1;
 }
 

Reply via email to