patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
To: "Morten Brørup" <mb@smartsharesystems.com>,
	"Huisong Li" <lihuisong@huawei.com>,
	"Chengwen Feng" <fengchengwen@huawei.com>,
	"Jie Hai" <haijie1@huawei.com>
Cc: <dev@dpdk.org>, <stable@dpdk.org>,
	Venkat Kumar Ande <venkatkumar.ande@amd.com>,
	Dengdui Huang <huangdengdui@huawei.com>,
	"Pavan Nikhilesh" <pbhagavatula@marvell.com>
Subject: [PATCH v3] examples/l3fwd: add Tx burst size configuration option
Date: Thu, 6 Nov 2025 14:16:31 +0000	[thread overview]
Message-ID: <20251106141631.179443-1-sivaprasad.tummala@amd.com> (raw)
In-Reply-To: <20250609095827.4174387-1-sivaprasad.tummala@amd.com>

Previously, the TX burst size in l3fwd was fixed at 256, which could
lead to suboptimal performance in certain scenarios.

This patch introduces separate --rx-burst and --tx-burst options to
explicitly configure RX and TX burst sizes. By default, the TX burst
size now matches the RX burst size for better efficiency and pipeline
balance.

Fixes: d5c4897ecfb2 ("examples/l3fwd: add option to set Rx burst size")
Cc: haijie1@huawei.com
Cc: stable@dpdk.org

Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
Tested-by: Venkat Kumar Ande <venkatkumar.ande@amd.com>
Tested-by: Dengdui Huang <huangdengdui@huawei.com>
Tested-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

v3:
 - Added --tx-burst option to allow independent TX burst configuration
 - Renamed --burst to --rx-burst for clarity
 - Renamed variables for clarity:
     - nb_pkt_per_burst → rx_burst_size
     - max_tx_burst     → tx_burst_size
 - Modified parsing packet burst logic for RX and TX
 - Default TX burst size now equals RX burst size
 - Added logging of selected RX and TX burst sizes
 - Updated documentation for --rx-burst and --tx-burst options
---
 doc/guides/sample_app_ug/l3_forward.rst |  6 ++
 examples/l3fwd/l3fwd.h                  | 10 +--
 examples/l3fwd/l3fwd_acl.c              |  2 +-
 examples/l3fwd/l3fwd_common.h           |  5 +-
 examples/l3fwd/l3fwd_em.c               |  2 +-
 examples/l3fwd/l3fwd_fib.c              |  2 +-
 examples/l3fwd/l3fwd_lpm.c              |  2 +-
 examples/l3fwd/main.c                   | 81 ++++++++++++++++---------
 8 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/doc/guides/sample_app_ug/l3_forward.rst b/doc/guides/sample_app_ug/l3_forward.rst
index 9b0d0350aa..dfe9d68c99 100644
--- a/doc/guides/sample_app_ug/l3_forward.rst
+++ b/doc/guides/sample_app_ug/l3_forward.rst
@@ -77,6 +77,8 @@ The application has a number of command line options::
                              [-P]
                              [--lookup LOOKUP_METHOD]
                              --config(port,queue,lcore)[,(port,queue,lcore)]
+                             [--rx-burst NPKTS]
+                             [--tx-burst NPKTS]
                              [--eth-dest=X,MM:MM:MM:MM:MM:MM]
                              [--max-pkt-len PKTLEN]
                              [--no-numa]
@@ -113,6 +115,10 @@ Where,
 
 * ``--config (port,queue,lcore)[,(port,queue,lcore)]:`` Determines which queues from which ports are mapped to which cores.
 
+* ``--rx-burst NPKTS:`` Optional, RX burst size in decimal (default 32).
+
+* ``--tx-burst NPKTS:`` Optional, TX burst size in decimal (default 32).
+
 * ``--eth-dest=X,MM:MM:MM:MM:MM:MM:`` Optional, ethernet destination for port X.
 
 * ``--max-pkt-len:`` Optional, maximum packet length in decimal (64-9600).
diff --git a/examples/l3fwd/l3fwd.h b/examples/l3fwd/l3fwd.h
index 0cce3406ee..471e3b488f 100644
--- a/examples/l3fwd/l3fwd.h
+++ b/examples/l3fwd/l3fwd.h
@@ -32,10 +32,6 @@
 
 #define VECTOR_SIZE_DEFAULT   MAX_PKT_BURST
 #define VECTOR_TMO_NS_DEFAULT 1E6 /* 1ms */
-/*
- * Try to avoid TX buffering if we have at least MAX_TX_BURST packets to send.
- */
-#define	MAX_TX_BURST	  (MAX_PKT_BURST / 2)
 
 #define NB_SOCKETS        8
 
@@ -116,7 +112,7 @@ extern struct acl_algorithms acl_alg[];
 
 extern uint32_t max_pkt_len;
 
-extern uint32_t nb_pkt_per_burst;
+extern uint32_t rx_burst_size;
 extern uint32_t mb_mempool_cache_size;
 
 /* Send burst of packets on an output interface */
@@ -152,8 +148,8 @@ send_single_packet(struct lcore_conf *qconf,
 	len++;
 
 	/* enough pkts to be sent */
-	if (unlikely(len == MAX_PKT_BURST)) {
-		send_burst(qconf, MAX_PKT_BURST, port);
+	if (unlikely(len == rx_burst_size)) {
+		send_burst(qconf, rx_burst_size, port);
 		len = 0;
 	}
 
diff --git a/examples/l3fwd/l3fwd_acl.c b/examples/l3fwd/l3fwd_acl.c
index 4fc4b986cc..a1275e18bc 100644
--- a/examples/l3fwd/l3fwd_acl.c
+++ b/examples/l3fwd/l3fwd_acl.c
@@ -1136,7 +1136,7 @@ acl_main_loop(__rte_unused void *dummy)
 			portid = qconf->rx_queue_list[i].port_id;
 			queueid = qconf->rx_queue_list[i].queue_id;
 			nb_rx = rte_eth_rx_burst(portid, queueid,
-				pkts_burst, nb_pkt_per_burst);
+				pkts_burst, rx_burst_size);
 
 			if (nb_rx > 0) {
 				nb_drop = acl_process_pkts(pkts_burst, hops,
diff --git a/examples/l3fwd/l3fwd_common.h b/examples/l3fwd/l3fwd_common.h
index d94e5f1357..ccaf0cd402 100644
--- a/examples/l3fwd/l3fwd_common.h
+++ b/examples/l3fwd/l3fwd_common.h
@@ -25,6 +25,9 @@
  */
 #define SENDM_PORT_OVERHEAD(x) (x)
 
+extern uint32_t rx_burst_size;
+extern uint32_t tx_burst_size;
+
 /*
  * From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2:
  * - The IP version number must be 4.
@@ -71,7 +74,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],
 	 * If TX buffer for that queue is empty, and we have enough packets,
 	 * then send them straightway.
 	 */
-	if (num >= MAX_TX_BURST && len == 0) {
+	if (num >= tx_burst_size && len == 0) {
 		n = rte_eth_tx_burst(port, qconf->tx_queue_id[port], m, num);
 		if (unlikely(n < num)) {
 			do {
diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c
index da9c45e3a4..58c54ed77e 100644
--- a/examples/l3fwd/l3fwd_em.c
+++ b/examples/l3fwd/l3fwd_em.c
@@ -644,7 +644,7 @@ em_main_loop(__rte_unused void *dummy)
 			portid = qconf->rx_queue_list[i].port_id;
 			queueid = qconf->rx_queue_list[i].queue_id;
 			nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
-				nb_pkt_per_burst);
+				rx_burst_size);
 			if (nb_rx == 0)
 				continue;
 
diff --git a/examples/l3fwd/l3fwd_fib.c b/examples/l3fwd/l3fwd_fib.c
index 82f1739df7..4fc6bf90d5 100644
--- a/examples/l3fwd/l3fwd_fib.c
+++ b/examples/l3fwd/l3fwd_fib.c
@@ -239,7 +239,7 @@ fib_main_loop(__rte_unused void *dummy)
 			portid = qconf->rx_queue_list[i].port_id;
 			queueid = qconf->rx_queue_list[i].queue_id;
 			nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
-					nb_pkt_per_burst);
+					rx_burst_size);
 			if (nb_rx == 0)
 				continue;
 
diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c
index fec0aeb79c..a71eee69ec 100644
--- a/examples/l3fwd/l3fwd_lpm.c
+++ b/examples/l3fwd/l3fwd_lpm.c
@@ -205,7 +205,7 @@ lpm_main_loop(__rte_unused void *dummy)
 			portid = qconf->rx_queue_list[i].port_id;
 			queueid = qconf->rx_queue_list[i].queue_id;
 			nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
-				nb_pkt_per_burst);
+				rx_burst_size);
 			if (nb_rx == 0)
 				continue;
 
diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c
index ae3b4f6439..ddd6fec344 100644
--- a/examples/l3fwd/main.c
+++ b/examples/l3fwd/main.c
@@ -57,8 +57,9 @@
 static_assert(MEMPOOL_CACHE_SIZE >= MAX_PKT_BURST, "MAX_PKT_BURST should be at most MEMPOOL_CACHE_SIZE");
 uint16_t nb_rxd = RX_DESC_DEFAULT;
 uint16_t nb_txd = TX_DESC_DEFAULT;
-uint32_t nb_pkt_per_burst = DEFAULT_PKT_BURST;
+uint32_t rx_burst_size = DEFAULT_PKT_BURST;
 uint32_t mb_mempool_cache_size = MEMPOOL_CACHE_SIZE;
+uint32_t tx_burst_size = DEFAULT_PKT_BURST;
 
 /**< Ports set in promiscuous mode off by default. */
 static int promiscuous_on;
@@ -400,7 +401,8 @@ print_usage(const char *prgname)
 		" --config (port,queue,lcore)[,(port,queue,lcore)]"
 		" [--rx-queue-size NPKTS]"
 		" [--tx-queue-size NPKTS]"
-		" [--burst NPKTS]"
+		" [--rx-burst NPKTS]"
+		" [--tx-burst NPKTS]"
 		" [--mbcache CACHESZ]"
 		" [--eth-dest=X,MM:MM:MM:MM:MM:MM]"
 		" [--max-pkt-len PKTLEN]"
@@ -427,7 +429,9 @@ print_usage(const char *prgname)
 		"            Default: %d\n"
 		"  --tx-queue-size NPKTS: Tx queue size in decimal\n"
 		"            Default: %d\n"
-		"  --burst NPKTS: Burst size in decimal\n"
+		"  --rx-burst NPKTS: RX Burst size in decimal\n"
+		"            Default: %d\n"
+		"  --tx-burst NPKTS: TX Burst size in decimal\n"
 		"            Default: %d\n"
 		"  --mbcache CACHESZ: Mbuf cache size in decimal\n"
 		"            Default: %d\n"
@@ -460,8 +464,8 @@ print_usage(const char *prgname)
 		"                    another is route entry at while line leads with character '%c'.\n"
 		"  --rule_ipv6=FILE: Specify the ipv6 rules entries file.\n"
 		"  --alg: ACL classify method to use, one of: %s.\n\n",
-		prgname, RX_DESC_DEFAULT, TX_DESC_DEFAULT, DEFAULT_PKT_BURST, MEMPOOL_CACHE_SIZE,
-		ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg);
+		prgname, RX_DESC_DEFAULT, TX_DESC_DEFAULT, DEFAULT_PKT_BURST, DEFAULT_PKT_BURST,
+		MEMPOOL_CACHE_SIZE, ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg);
 }
 
 static int
@@ -695,7 +699,7 @@ parse_mbcache_size(const char *optarg)
 }
 
 static void
-parse_pkt_burst(const char *optarg)
+parse_pkt_burst(const char *optarg, bool is_rx_burst, uint32_t *burst_sz)
 {
 	struct rte_eth_dev_info dev_info;
 	unsigned long pkt_burst;
@@ -710,31 +714,38 @@ parse_pkt_burst(const char *optarg)
 
 	if (pkt_burst > MAX_PKT_BURST) {
 		RTE_LOG(INFO, L3FWD, "User provided burst must be <= %d. Using default value %d\n",
-			MAX_PKT_BURST, nb_pkt_per_burst);
+			MAX_PKT_BURST, *burst_sz);
 		return;
 	} else if (pkt_burst > 0) {
-		nb_pkt_per_burst = (uint32_t)pkt_burst;
+		*burst_sz = (uint32_t)pkt_burst;
 		return;
 	}
 
-	/* If user gives a value of zero, query the PMD for its recommended Rx burst size. */
-	ret = rte_eth_dev_info_get(0, &dev_info);
-	if (ret != 0)
-		return;
-	burst_size = dev_info.default_rxportconf.burst_size;
-	if (burst_size == 0) {
-		RTE_LOG(INFO, L3FWD, "PMD does not recommend a burst size. Using default value %d. "
-			"User provided value must be in [1, %d]\n",
-			nb_pkt_per_burst, MAX_PKT_BURST);
-		return;
-	} else if (burst_size > MAX_PKT_BURST) {
-		RTE_LOG(INFO, L3FWD, "PMD recommended burst size %d exceeds maximum value %d. "
-			"Using default value %d\n",
-			burst_size, MAX_PKT_BURST, nb_pkt_per_burst);
-		return;
+	if (is_rx_burst) {
+		/* If user gives a value of zero, query the PMD for its recommended
+		 * Rx burst size.
+		 */
+		ret = rte_eth_dev_info_get(0, &dev_info);
+		if (ret != 0)
+			return;
+		burst_size = dev_info.default_rxportconf.burst_size;
+		if (burst_size == 0) {
+			RTE_LOG(INFO, L3FWD, "PMD does not recommend a burst size. Using default value %d. "
+				"User provided value must be in [1, %d]\n",
+				rx_burst_size, MAX_PKT_BURST);
+			return;
+		} else if (burst_size > MAX_PKT_BURST) {
+			RTE_LOG(INFO, L3FWD, "PMD recommended burst size %d exceeds maximum value %d. "
+				"Using default value %d\n",
+				burst_size, MAX_PKT_BURST, rx_burst_size);
+			return;
+		}
+		*burst_sz = burst_size;
+		RTE_LOG(INFO, L3FWD, "Using PMD-provided RX burst value %d\n", burst_size);
+	} else {
+		RTE_LOG(INFO, L3FWD, "User provided TX burst is 0. Using default value %d\n",
+				*burst_sz);
 	}
-	nb_pkt_per_burst = burst_size;
-	RTE_LOG(INFO, L3FWD, "Using PMD-provided burst value %d\n", burst_size);
 }
 
 #define MAX_JUMBO_PKT_LEN  9600
@@ -768,7 +779,8 @@ static const char short_options[] =
 #define CMD_LINE_OPT_RULE_IPV4 "rule_ipv4"
 #define CMD_LINE_OPT_RULE_IPV6 "rule_ipv6"
 #define CMD_LINE_OPT_ALG "alg"
-#define CMD_LINE_OPT_PKT_BURST "burst"
+#define CMD_LINE_OPT_PKT_RX_BURST "rx-burst"
+#define CMD_LINE_OPT_PKT_TX_BURST "tx-burst"
 #define CMD_LINE_OPT_MB_CACHE_SIZE "mbcache"
 
 enum {
@@ -799,7 +811,8 @@ enum {
 	CMD_LINE_OPT_ENABLE_VECTOR_NUM,
 	CMD_LINE_OPT_VECTOR_SIZE_NUM,
 	CMD_LINE_OPT_VECTOR_TMO_NS_NUM,
-	CMD_LINE_OPT_PKT_BURST_NUM,
+	CMD_LINE_OPT_PKT_RX_BURST_NUM,
+	CMD_LINE_OPT_PKT_TX_BURST_NUM,
 	CMD_LINE_OPT_MB_CACHE_SIZE_NUM,
 };
 
@@ -827,7 +840,8 @@ static const struct option lgopts[] = {
 	{CMD_LINE_OPT_RULE_IPV4,   1, 0, CMD_LINE_OPT_RULE_IPV4_NUM},
 	{CMD_LINE_OPT_RULE_IPV6,   1, 0, CMD_LINE_OPT_RULE_IPV6_NUM},
 	{CMD_LINE_OPT_ALG,   1, 0, CMD_LINE_OPT_ALG_NUM},
-	{CMD_LINE_OPT_PKT_BURST,   1, 0, CMD_LINE_OPT_PKT_BURST_NUM},
+	{CMD_LINE_OPT_PKT_RX_BURST,   1, 0, CMD_LINE_OPT_PKT_RX_BURST_NUM},
+	{CMD_LINE_OPT_PKT_TX_BURST,   1, 0, CMD_LINE_OPT_PKT_TX_BURST_NUM},
 	{CMD_LINE_OPT_MB_CACHE_SIZE,   1, 0, CMD_LINE_OPT_MB_CACHE_SIZE_NUM},
 	{NULL, 0, 0, 0}
 };
@@ -917,8 +931,12 @@ parse_args(int argc, char **argv)
 			parse_queue_size(optarg, &nb_txd, 0);
 			break;
 
-		case CMD_LINE_OPT_PKT_BURST_NUM:
-			parse_pkt_burst(optarg);
+		case CMD_LINE_OPT_PKT_RX_BURST_NUM:
+			parse_pkt_burst(optarg, true, &rx_burst_size);
+			break;
+
+		case CMD_LINE_OPT_PKT_TX_BURST_NUM:
+			parse_pkt_burst(optarg, false, &tx_burst_size);
 			break;
 
 		case CMD_LINE_OPT_MB_CACHE_SIZE_NUM:
@@ -1654,6 +1672,9 @@ main(int argc, char **argv)
 	if (ret < 0)
 		rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
 
+	RTE_LOG(INFO, L3FWD, "Using RX burst %u TX burst %u\n",
+				rx_burst_size, tx_burst_size);
+
 	/* Setup function pointers for lookup method. */
 	setup_l3fwd_lookup_tables();
 
-- 
2.43.0


      parent reply	other threads:[~2025-11-06 14:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  4:54 [PATCH] examples/l3fwd: adjust Tx burst size based on Rx burst Sivaprasad Tummala
2025-02-12  9:17 ` Ande, Venkat Kumar
2025-02-12  9:46 ` Ande, Venkat Kumar
2025-02-19 16:59 ` Konstantin Ananyev
2025-06-09  9:58 ` [PATCH v2] " Sivaprasad Tummala
2025-06-09 15:21   ` Stephen Hemminger
2025-06-10 14:29   ` [EXTERNAL] " Pavan Nikhilesh Bhagavatula
2025-10-09  2:32     ` Tummala, Sivaprasad
2025-10-31  9:18       ` fengchengwen
2025-11-01 12:53         ` Tummala, Sivaprasad
2025-11-06 14:16   ` Sivaprasad Tummala [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251106141631.179443-1-sivaprasad.tummala@amd.com \
    --to=sivaprasad.tummala@amd.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=haijie1@huawei.com \
    --cc=huangdengdui@huawei.com \
    --cc=lihuisong@huawei.com \
    --cc=mb@smartsharesystems.com \
    --cc=pbhagavatula@marvell.com \
    --cc=stable@dpdk.org \
    --cc=venkatkumar.ande@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).