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-apps.git

commit d10533a312c076ba6c5e5af918c179fc896cf690
Author: zhangkai25 <[email protected]>
AuthorDate: Wed Jul 22 14:34:20 2026 +0800

    netutils/iperf: allow configurable traffic buffer length
    
    The traffic buffer size was hard-coded to 16K (IPERF_TCP_TX_LEN etc).
    On memory-constrained cores this single allocation can exceed the
    largest free block and, with CONFIG_MM_PANIC_ON_FAILURE enabled, the
    failed malloc panics the whole core instead of returning an error.
    
    Add a -l/--len option so the buffer length can be specified at runtime
    (e.g. "iperf -c <ip> -l 4096"). When omitted, the built-in defaults are
    used, so existing behaviour is unchanged.
    
    Signed-off-by: zhangkai25 <[email protected]>
    Assisted-by: Kiro:claude-opus-4
---
 netutils/iperf/iperf.c      | 13 ++++++++++++-
 netutils/iperf/iperf.h      |  1 +
 netutils/iperf/iperf_main.c | 14 +++++++++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/netutils/iperf/iperf.c b/netutils/iperf/iperf.c
index afa92f3fb..932b76463 100644
--- a/netutils/iperf/iperf.c
+++ b/netutils/iperf/iperf.c
@@ -47,7 +47,7 @@
 
 #define IPERF_TRAFFIC_TASK_NAME      "iperf_traffic"
 #define IPERF_TRAFFIC_TASK_PRIORITY  100
-#define IPERF_TRAFFIC_TASK_STACK     6144
+#define IPERF_TRAFFIC_TASK_STACK     5120
 #define IPERF_REPORT_TASK_NAME       "iperf_report"
 #define IPERF_REPORT_TASK_PRIORITY   101
 #define IPERF_REPORT_TASK_STACK      4096
@@ -927,6 +927,17 @@ static void iperf_task_traffic(FAR void *arg)
 
 static uint32_t iperf_get_buffer_len(FAR struct iperf_ctrl_t *ctrl)
 {
+  /* A user-specified length (iperf -l/--len) overrides the built-in
+   * defaults, so memory-constrained targets can use a smaller traffic
+   * buffer instead of failing to allocate the larger built-in default
+   * (default: TCP 8K, UDP TX 1472, UDP RX 16K).
+   */
+
+  if (ctrl->cfg.len != 0)
+    {
+      return ctrl->cfg.len;
+    }
+
   if (iperf_is_udp_client(ctrl))
     {
       return IPERF_UDP_TX_LEN;
diff --git a/netutils/iperf/iperf.h b/netutils/iperf/iperf.h
index 3a4ccb611..b43f9c29d 100644
--- a/netutils/iperf/iperf.h
+++ b/netutils/iperf/iperf.h
@@ -65,6 +65,7 @@ struct iperf_cfg_t
   uint32_t interval;
   uint32_t time;
   uint32_t cid;         /* vsock cid */
+  uint32_t len;         /* traffic buffer length, 0 = use built-in default */
   FAR const char *host; /* host name (dip) or rpmsg cpu */
   FAR const char *path; /* local path or rpmsg name */
 };
diff --git a/netutils/iperf/iperf_main.c b/netutils/iperf/iperf_main.c
index 5e4eb7f71..db3d358ad 100644
--- a/netutils/iperf/iperf_main.c
+++ b/netutils/iperf/iperf_main.c
@@ -65,6 +65,7 @@ struct wifi_iperf_s
   int interval;
   int abort;
   int time;
+  int len;
 };
 
 /****************************************************************************
@@ -97,6 +98,8 @@ static void iperf_showusage(FAR const char *progname)
          " reports\n"
          "  -t, --time=<time>    time in seconds to transmit for (default 10"
          " secs)\n"
+         "  -l, --len=<length>   length of buffer in bytes to read or write"
+         " (default: TCP 8K, UDP TX 1472, UDP RX 16K)\n"
          "  -a, --abort          abort running iperf\n");
 }
 
@@ -159,6 +162,7 @@ int main(int argc, FAR char *argv[])
     {"local", optional_argument, 0, 'L'},
     {"rpmsg", required_argument, 0, 'R'},
     {"vsock", required_argument, 0, 'V'},
+    {"len",   required_argument, 0, 'l'},
     {0, 0, 0, 0}
   };
 
@@ -175,7 +179,7 @@ int main(int argc, FAR char *argv[])
   cfg.sport = IPERF_DEFAULT_PORT;
   cfg.dport = IPERF_DEFAULT_PORT;
 
-  while ((opt = getopt_long(argc, argv, "suac:B:p:i:t:",
+  while ((opt = getopt_long(argc, argv, "suac:B:p:i:t:l:",
                             loptions, NULL)) != -1)
     {
       switch (opt)
@@ -206,6 +210,9 @@ int main(int argc, FAR char *argv[])
           case 't':
             iperf.time = strtoul(optarg, NULL, 0);
             break;
+          case 'l':
+            iperf.len = strtoul(optarg, NULL, 0);
+            break;
           case 'L':
             cfg.flag |= IPERF_FLAG_LOCAL;
             iperf.local = optarg;
@@ -361,6 +368,11 @@ int main(int argc, FAR char *argv[])
         }
     }
 
+  if (iperf.len > 0)
+    {
+      cfg.len = iperf.len;
+    }
+
   iperf_printcfg(&cfg);
   iperf_start(&cfg);
   return 0;

Reply via email to