From 8b2c5651808b1ea14d3b5e1386ddf67152703ce1 Mon Sep 17 00:00:00 2001
From: harshraj1695 <[email protected]>
Date: Tue, 24 Mar 2026 09:28:59 +0530
Subject: [PATCH] examples/l2fwd: fix port statistics reset inside loop

The port_statistics structure was reset inside the per-port
initialization loop, causing previously initialized statistics
to be overwritten on each iteration.

Move the initialization outside the loop to ensure statistics
are correctly maintained for all ports.

Signed-off-by: harshraj1695 <[email protected]>
---
 examples/l2fwd/main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 59ea3172ae..c799e8768a 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -773,6 +773,7 @@ main(int argc, char **argv)
 	if (l2fwd_pktmbuf_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
 	/* >8 End of create the mbuf pool. */
+	memset(port_statistics, 0, sizeof(port_statistics));
 
 	/* Initialise each port */
 	RTE_ETH_FOREACH_DEV(portid) {
@@ -889,9 +890,6 @@ main(int argc, char **argv)
 		printf("Port %u, MAC address: " RTE_ETHER_ADDR_PRT_FMT "\n\n",
 			portid,
 			RTE_ETHER_ADDR_BYTES(&l2fwd_ports_eth_addr[portid]));
-
-		/* initialize port stats */
-		memset(&port_statistics, 0, sizeof(port_statistics));
 	}
 
 	if (!nb_ports_available) {
-- 
2.43.0

Reply via email to