DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/6] Testpmd code cleanup
@ 2023-01-24 10:47 David Marchand
  2023-01-24 10:47 ` [PATCH 1/6] app/testpmd: factorize core cycles record David Marchand
                   ` (8 more replies)
  0 siblings, 9 replies; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Here is a series to reduce code duplication in testpmd.

This work started from looking at Robin series on reporting lcore busy
cycles in telemetry, which is then added in testpmd [1].
While looking at the forward engines code, I saw way too much
duplicated code.

Warning: this is only compile tested.

1: https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/

-- 
David Marchand

David Marchand (6):
  app/testpmd: factorize core cycles record
  app/testpmd: don't send unprepared packets
  app/testpmd: bulk free mbufs
  app/testpmd: factorize fwd engine init
  app/testpmd: factorize fwd engine Rx
  app/testpmd: factorize fwd engine Tx

 app/test-pmd/5tswap.c         |  54 ++--------------
 app/test-pmd/csumonly.c       |  61 +++---------------
 app/test-pmd/flowgen.c        |  55 ++--------------
 app/test-pmd/icmpecho.c       |  60 +++---------------
 app/test-pmd/ieee1588fwd.c    |  35 ++++-------
 app/test-pmd/iofwd.c          |  54 ++--------------
 app/test-pmd/macfwd.c         |  53 ++--------------
 app/test-pmd/macswap.c        |  58 +++--------------
 app/test-pmd/noisy_vnf.c      | 115 +++++++++-------------------------
 app/test-pmd/rxonly.c         |  18 ++----
 app/test-pmd/shared_rxq_fwd.c |  14 ++---
 app/test-pmd/testpmd.c        |  26 ++++++--
 app/test-pmd/testpmd.h        |  46 +++++++++++++-
 app/test-pmd/txonly.c         |  45 ++++---------
 14 files changed, 173 insertions(+), 521 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 1/6] app/testpmd: factorize core cycles record
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
@ 2023-01-24 10:47 ` David Marchand
  2023-02-14 18:14   ` Ferruh Yigit
  2023-01-24 10:47 ` [PATCH 2/6] app/testpmd: don't send unprepared packets David Marchand
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Rather than have each forward engines deal with core cycles recording,
move this to testpmd common code.
fwd engines just need to report that they did some busy work.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/5tswap.c         | 11 ++++-------
 app/test-pmd/csumonly.c       | 10 +++-------
 app/test-pmd/flowgen.c        |  7 ++-----
 app/test-pmd/icmpecho.c       |  9 +++------
 app/test-pmd/ieee1588fwd.c    | 17 +++++++++--------
 app/test-pmd/iofwd.c          |  9 +++------
 app/test-pmd/macfwd.c         |  9 +++------
 app/test-pmd/macswap.c        | 10 ++++------
 app/test-pmd/noisy_vnf.c      | 26 +++++++++++++++-----------
 app/test-pmd/rxonly.c         |  9 +++------
 app/test-pmd/shared_rxq_fwd.c |  9 ++++-----
 app/test-pmd/testpmd.c        | 12 +++++++++---
 app/test-pmd/testpmd.h        |  2 +-
 app/test-pmd/txonly.c         |  9 +++------
 14 files changed, 66 insertions(+), 83 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index f041a5e1d5..e665643a65 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -81,7 +81,7 @@ swap_udp(struct rte_udp_hdr *udp_hdr)
  * 2,3,4. Swaps source and destination for MAC, IPv4/IPv6, UDP/TCP.
  * Parses each layer and swaps it. When the next layer doesn't match it stops.
  */
-static void
+static bool
 pkt_burst_5tuple_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -105,10 +105,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		uint8_t *byte;
 	} h;
 
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
-
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -116,7 +112,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -182,7 +178,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 1c24598515..dc64754a05 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -828,7 +828,7 @@ pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t nb_pkts, uint64
  * IP, UDP, TCP and SCTP flags always concern the inner layer. The
  * OUTER_IP is only useful for tunnel packets.
  */
-static void
+static bool
 pkt_burst_checksum_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -859,16 +859,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint32_t rx_bad_outer_ip_csum;
 	struct testpmd_offload_info info;
 
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
-
 	/* receive a burst of packet */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	rx_bad_ip_csum = 0;
@@ -1201,7 +1197,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		} while (++nb_tx < nb_rx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index fd6abc0f41..f26fd830f1 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -58,7 +58,7 @@ RTE_DEFINE_PER_LCORE(int, _next_flow);
  * terminate receive traffic.  Received traffic is simply discarded, but we
  * still do so in order to maintain traffic statistics.
  */
-static void
+static bool
 pkt_burst_flow_gen(struct fwd_stream *fs)
 {
 	unsigned pkt_size = tx_pkt_length - 4;	/* Adjust FCS */
@@ -78,11 +78,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t i;
 	uint32_t retry;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
-	get_start_cycles(&start_tsc);
-
 	/* Receive a burst of packets and discard them. */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
@@ -196,7 +193,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static int
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 066f2a3ab7..cd984d1ffb 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -269,7 +269,7 @@ ipv4_hdr_cksum(struct rte_ipv4_hdr *ip_h)
  * Receive a burst of packets, lookup for ICMP echo requests, and, if any,
  * send back ICMP echo replies.
  */
-static void
+static bool
 reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -292,9 +292,6 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	uint32_t cksum;
 	uint8_t  i;
 	int l2_len;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * First, receive a burst of packets.
@@ -303,7 +300,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	nb_replies = 0;
@@ -509,7 +506,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		}
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index fc4e2d014c..dab582cbf7 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -89,7 +89,7 @@ port_ieee1588_tx_timestamp_check(portid_t pi)
 	       (wait_us == 1) ? "" : "s");
 }
 
-static void
+static bool
 ieee1588_packet_fwd(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *mb;
@@ -103,7 +103,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	 * Receive 1 packet at a time.
 	 */
 	if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0)
-		return;
+		return false;
 
 	fs->rx_packets += 1;
 
@@ -126,14 +126,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 			       (unsigned) mb->pkt_len);
 		}
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	if (eth_type != RTE_ETHER_TYPE_1588) {
 		printf("Port %u Received NON PTP packet incorrectly"
 		       " detected by hardware\n",
 		       fs->rx_port);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/*
@@ -147,14 +147,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		       " protocol version 0x%x (should be 0x02)\n",
 		       fs->rx_port, ptp_hdr->version);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	if (ptp_hdr->msg_id != PTP_SYNC_MESSAGE) {
 		printf("Port %u Received PTP V2 Ethernet frame with unexpected"
 		       " message ID 0x%x (expected 0x0 - PTP_SYNC_MESSAGE)\n",
 		       fs->rx_port, ptp_hdr->msg_id);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	printf("Port %u IEEE1588 PTP V2 SYNC Message filtered by hardware\n",
 	       fs->rx_port);
@@ -168,7 +168,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		       " by hardware\n",
 		       fs->rx_port);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/* For i40e we need the timesync register index. It is ignored for the
@@ -189,13 +189,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		printf("Port %u sent PTP packet dropped\n", fs->rx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/*
 	 * Check the TX timestamp.
 	 */
 	port_ieee1588_tx_timestamp_check(fs->rx_port);
+	return true;
 }
 
 static int
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 8fafdec548..8218bd6b4b 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -41,16 +41,13 @@
  * This is the fastest possible forwarding operation, as it does not access
  * to packets data.
  */
-static void
+static bool
 pkt_burst_io_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -59,7 +56,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 			pkts_burst, nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 	fs->rx_packets += nb_rx;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
@@ -84,7 +81,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 		} while (++nb_tx < nb_rx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index beb220fbb4..c1b116e559 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -41,7 +41,7 @@
  * Change the source and the destination Ethernet addressed of packets
  * before forwarding them.
  */
-static void
+static bool
 pkt_burst_mac_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -54,9 +54,6 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -65,7 +62,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -115,7 +112,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 		} while (++nb_tx < nb_rx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 4f8deb3382..361341e075 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -47,7 +47,7 @@
  * MAC swap forwarding mode: Swap the source and the destination Ethernet
  * addresses of packets before forwarding them.
  */
-static void
+static bool
 pkt_burst_mac_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -55,9 +55,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -66,7 +63,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -93,7 +90,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 			rte_pktmbuf_free(pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index c65ec6f06a..e2fecafeac 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -137,7 +137,7 @@ drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
  *    out of the FIFO
  * 4. Cases 2 and 3 combined
  */
-static void
+static bool
 pkt_burst_noisy_vnf(struct fwd_stream *fs)
 {
 	const uint64_t freq_khz = rte_get_timer_hz() / 1000;
@@ -169,7 +169,8 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 		inc_tx_burst_stats(fs, nb_tx);
 		fs->tx_packets += nb_tx;
 		fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
-		return;
+
+		return true;
 	}
 
 	fifo_free = rte_ring_free_count(ncf->f);
@@ -198,15 +199,16 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	sim_memory_lookups(ncf, nb_enqd);
 
 flush:
-	if (ncf->do_flush) {
-		if (!ncf->prev_time)
-			now = ncf->prev_time = rte_get_timer_cycles();
-		else
-			now = rte_get_timer_cycles();
-		delta_ms = (now - ncf->prev_time) / freq_khz;
-		needs_flush = delta_ms >= noisy_tx_sw_buf_flush_time &&
-				noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
-	}
+	if (!ncf->do_flush)
+		return nb_rx != 0;
+
+	if (!ncf->prev_time)
+		now = ncf->prev_time = rte_get_timer_cycles();
+	else
+		now = rte_get_timer_cycles();
+	delta_ms = (now - ncf->prev_time) / freq_khz;
+	needs_flush = delta_ms >= noisy_tx_sw_buf_flush_time &&
+			noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
 	while (needs_flush && !rte_ring_empty(ncf->f)) {
 		unsigned int sent;
 		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
@@ -219,6 +221,8 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
 		ncf->prev_time = rte_get_timer_cycles();
 	}
+
+	return nb_tx != 0;
 }
 
 #define NOISY_STRSIZE 256
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index d528d4f34e..375be990bd 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -41,15 +41,12 @@
 /*
  * Received a burst of packets.
  */
-static void
+static bool
 pkt_burst_receive(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
 	uint16_t i;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets.
@@ -58,13 +55,13 @@ pkt_burst_receive(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	for (i = 0; i < nb_rx; i++)
 		rte_pktmbuf_free(pkts_burst[i]);
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 2e9047804b..4b3a87a3ba 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -90,21 +90,20 @@ forward_shared_rxq(struct fwd_stream *fs, uint16_t nb_rx,
 			  &pkts_burst[nb_rx - nb_sub_burst]);
 }
 
-static void
+static bool
 shared_rxq_fwd(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
 	uint16_t nb_rx;
-	uint64_t start_tsc = 0;
 
-	get_start_cycles(&start_tsc);
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 	forward_shared_rxq(fs, nb_rx, pkts_burst);
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 134d79a555..9afc107975 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2263,9 +2263,15 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 	fsm = &fwd_streams[fc->stream_idx];
 	nb_fs = fc->stream_nb;
 	do {
-		for (sm_id = 0; sm_id < nb_fs; sm_id++)
-			if (!fsm[sm_id]->disabled)
-				(*pkt_fwd)(fsm[sm_id]);
+		for (sm_id = 0; sm_id < nb_fs; sm_id++) {
+			uint64_t start_tsc = 0;
+
+			if (fsm[sm_id]->disabled)
+				continue;
+			get_start_cycles(&start_tsc);
+			if (likely((*pkt_fwd)(fsm[sm_id])))
+				get_end_cycles(fsm[sm_id], start_tsc);
+		}
 #ifdef RTE_LIB_BITRATESTATS
 		if (bitrate_enabled != 0 &&
 				bitrate_lcore_id == rte_lcore_id()) {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 7d24d25970..5c46844195 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -380,7 +380,7 @@ struct fwd_lcore {
 typedef int (*port_fwd_begin_t)(portid_t pi);
 typedef void (*port_fwd_end_t)(portid_t pi);
 typedef void (*stream_init_t)(struct fwd_stream *fs);
-typedef void (*packet_fwd_t)(struct fwd_stream *fs);
+typedef bool (*packet_fwd_t)(struct fwd_stream *fs);
 
 struct fwd_engine {
 	const char       *fwd_mode_name; /**< Forwarding mode name. */
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 021624952d..23e51a1bec 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -323,7 +323,7 @@ pkt_burst_prepare(struct rte_mbuf *pkt, struct rte_mempool *mbp,
 /*
  * Transmit a burst of multi-segments packets.
  */
-static void
+static bool
 pkt_burst_transmit(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -337,9 +337,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	mbp = current_fwd_lcore()->mbp;
 	txp = &ports[fs->tx_port];
@@ -392,7 +389,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	}
 
 	if (nb_pkt == 0)
-		return;
+		return false;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
 
@@ -426,7 +423,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 		} while (++nb_tx < nb_pkt);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static int
-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 2/6] app/testpmd: don't send unprepared packets
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
  2023-01-24 10:47 ` [PATCH 1/6] app/testpmd: factorize core cycles record David Marchand
@ 2023-01-24 10:47 ` David Marchand
  2023-02-14 18:14   ` Ferruh Yigit
  2023-01-24 10:47 ` [PATCH 3/6] app/testpmd: bulk free mbufs David Marchand
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev
  Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable,
	Tomasz Kulasek, Konstantin Ananyev

"unprepared" packets could get to the wire in the retry loop.

Split packets freeing in two stages: one for preparation failure, and
one for transmission failure.
Adjust dropped counter update accordingly.

Fixes: 6b520d54ebfe ("app/testpmd: use Tx preparation in checksum engine")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/csumonly.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index dc64754a05..700c79f122 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1164,10 +1164,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
 	nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
 			tx_pkts_burst, nb_rx);
-	if (nb_prep != nb_rx)
+	if (nb_prep != nb_rx) {
 		fprintf(stderr,
 			"Preparing packet burst to transmit failed: %s\n",
 			rte_strerror(rte_errno));
+		fs->fwd_dropped += (nb_rx - nb_prep);
+		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
+	}
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
 			nb_prep);
@@ -1175,12 +1178,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	/*
 	 * Retry if necessary
 	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
+	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
 		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
+		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
 			rte_delay_us(burst_tx_delay_time);
 			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&tx_pkts_burst[nb_tx], nb_rx - nb_tx);
+					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 		}
 	}
 	fs->tx_packets += nb_tx;
@@ -1190,11 +1193,11 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
 	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
+	if (unlikely(nb_tx < nb_prep)) {
+		fs->fwd_dropped += (nb_prep - nb_tx);
 		do {
 			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		} while (++nb_tx < nb_prep);
 	}
 
 	return true;
-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 3/6] app/testpmd: bulk free mbufs
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
  2023-01-24 10:47 ` [PATCH 1/6] app/testpmd: factorize core cycles record David Marchand
  2023-01-24 10:47 ` [PATCH 2/6] app/testpmd: don't send unprepared packets David Marchand
@ 2023-01-24 10:47 ` David Marchand
  2023-02-14 18:14   ` Ferruh Yigit
  2023-01-24 10:47 ` [PATCH 4/6] app/testpmd: factorize fwd engine init David Marchand
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Use the bulk free helper.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/5tswap.c         | 4 +---
 app/test-pmd/csumonly.c       | 4 +---
 app/test-pmd/flowgen.c        | 8 ++------
 app/test-pmd/icmpecho.c       | 4 +---
 app/test-pmd/iofwd.c          | 4 +---
 app/test-pmd/macfwd.c         | 4 +---
 app/test-pmd/macswap.c        | 4 +---
 app/test-pmd/noisy_vnf.c      | 7 ++-----
 app/test-pmd/rxonly.c         | 4 +---
 app/test-pmd/shared_rxq_fwd.c | 3 +--
 app/test-pmd/testpmd.c        | 4 +---
 app/test-pmd/txonly.c         | 4 +---
 12 files changed, 14 insertions(+), 40 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index e665643a65..0a3a897e7b 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -174,9 +174,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	return true;
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 700c79f122..07850501f4 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1195,9 +1195,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_prep)) {
 		fs->fwd_dropped += (nb_prep - nb_tx);
-		do {
-			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_prep);
+		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 	}
 
 	return true;
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index f26fd830f1..b3bd4f7c65 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -75,7 +75,6 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
-	uint16_t i;
 	uint32_t retry;
 	uint64_t tx_offloads;
 	int next_flow = RTE_PER_LCORE(_next_flow);
@@ -86,8 +85,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	inc_rx_burst_stats(fs, nb_rx);
 	fs->rx_packets += nb_rx;
 
-	for (i = 0; i < nb_rx; i++)
-		rte_pktmbuf_free(pkts_burst[i]);
+	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	mbp = current_fwd_lcore()->mbp;
 	vlan_tci = ports[fs->tx_port].tx_vlan_id;
@@ -186,9 +184,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			next_flow += nb_flows_flowgen;
 
 		fs->fwd_dropped += nb_dropped;
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_pkt);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index cd984d1ffb..5ef1116141 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -500,9 +500,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		inc_tx_burst_stats(fs, nb_tx);
 		if (unlikely(nb_tx < nb_replies)) {
 			fs->fwd_dropped += (nb_replies - nb_tx);
-			do {
-				rte_pktmbuf_free(pkts_burst[nb_tx]);
-			} while (++nb_tx < nb_replies);
+			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
 		}
 	}
 
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 8218bd6b4b..9d0af5f667 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -76,9 +76,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	return true;
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index c1b116e559..3a840247c7 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -107,9 +107,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	return true;
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 361341e075..14b3eefffd 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -86,9 +86,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	return true;
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index e2fecafeac..ecea51b603 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -111,11 +111,8 @@ do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
 static uint32_t
 drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
 {
-	if (nb_tx < nb_rx) {
-		do {
-			rte_pktmbuf_free(pkts[nb_tx]);
-		} while (++nb_tx < nb_rx);
-	}
+	if (nb_tx < nb_rx)
+		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
 
 	return nb_rx - nb_tx;
 }
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index 375be990bd..ad4597cf9a 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -46,7 +46,6 @@ pkt_burst_receive(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint16_t i;
 
 	/*
 	 * Receive a burst of packets.
@@ -58,8 +57,7 @@ pkt_burst_receive(struct fwd_stream *fs)
 		return false;
 
 	fs->rx_packets += nb_rx;
-	for (i = 0; i < nb_rx; i++)
-		rte_pktmbuf_free(pkts_burst[i]);
+	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 4b3a87a3ba..4902ec407e 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -53,8 +53,7 @@ forward_sub_burst(struct fwd_stream *src_fs, uint16_t port, uint16_t nb_rx,
 	} else {
 		/* Source stream not found, drop all packets. */
 		src_fs->fwd_dropped += nb_rx;
-		while (nb_rx > 0)
-			rte_pktmbuf_free(pkts[--nb_rx]);
+		rte_pktmbuf_free_bulk(pkts, nb_rx);
 	}
 }
 
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 9afc107975..dab67bce5c 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2196,7 +2196,6 @@ flush_fwd_rx_queues(void)
 	portid_t port_id;
 	queueid_t rxq;
 	uint16_t  nb_rx;
-	uint16_t  i;
 	uint8_t   j;
 	uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
 	uint64_t timer_period;
@@ -2229,8 +2228,7 @@ flush_fwd_rx_queues(void)
 				do {
 					nb_rx = rte_eth_rx_burst(port_id, rxq,
 						pkts_burst, MAX_PKT_BURST);
-					for (i = 0; i < nb_rx; i++)
-						rte_pktmbuf_free(pkts_burst[i]);
+					rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 					cur_tsc = rte_rdtsc();
 					diff_tsc = cur_tsc - prev_tsc;
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 23e51a1bec..63ad5e69bf 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -418,9 +418,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 			       (unsigned) nb_pkt, (unsigned) nb_tx,
 			       (unsigned) (nb_pkt - nb_tx));
 		fs->fwd_dropped += (nb_pkt - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_pkt);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	return true;
-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 4/6] app/testpmd: factorize fwd engine init
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
                   ` (2 preceding siblings ...)
  2023-01-24 10:47 ` [PATCH 3/6] app/testpmd: bulk free mbufs David Marchand
@ 2023-01-24 10:47 ` David Marchand
  2023-02-14 18:14   ` Ferruh Yigit
  2023-01-24 10:47 ` [PATCH 5/6] app/testpmd: factorize fwd engine Rx David Marchand
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
initialising the fs object.

While at it, remove unneeded initialisation of fwd_engine empty fields.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/5tswap.c         | 16 +---------------
 app/test-pmd/csumonly.c       | 16 +---------------
 app/test-pmd/flowgen.c        | 15 +--------------
 app/test-pmd/icmpecho.c       | 16 +---------------
 app/test-pmd/ieee1588fwd.c    | 14 +-------------
 app/test-pmd/iofwd.c          | 16 +---------------
 app/test-pmd/macfwd.c         | 16 +---------------
 app/test-pmd/macswap.c        | 16 +---------------
 app/test-pmd/noisy_vnf.c      | 14 +-------------
 app/test-pmd/shared_rxq_fwd.c |  2 --
 app/test-pmd/testpmd.c        | 10 ++++++++++
 app/test-pmd/testpmd.h        |  2 ++
 app/test-pmd/txonly.c         |  1 -
 13 files changed, 21 insertions(+), 133 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 0a3a897e7b..7b5f58f4d4 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -180,22 +180,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_5tuple_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine five_tuple_swap_fwd_engine = {
 	.fwd_mode_name  = "5tswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_5tuple_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_5tuple_swap,
 };
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 07850501f4..f72e2d74c7 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1201,22 +1201,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_checksum_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine csum_fwd_engine = {
 	.fwd_mode_name  = "csum",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_checksum_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_checksum_forward,
 };
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index b3bd4f7c65..6f42019353 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -199,22 +199,9 @@ flowgen_begin(portid_t pi)
 	return 0;
 }
 
-static void
-flowgen_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine flow_gen_engine = {
 	.fwd_mode_name  = "flowgen",
 	.port_fwd_begin = flowgen_begin,
-	.port_fwd_end   = NULL,
-	.stream_init    = flowgen_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_flow_gen,
 };
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 5ef1116141..eba8b99f1e 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -507,22 +507,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-icmpecho_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine icmp_echo_engine = {
 	.fwd_mode_name  = "icmpecho",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = icmpecho_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = reply_to_icmp_echo_rqsts,
 };
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index dab582cbf7..db7009c678 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -212,22 +212,10 @@ port_ieee1588_fwd_end(portid_t pi)
 	rte_eth_timesync_disable(pi);
 }
 
-static void
-port_ieee1588_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine ieee1588_fwd_engine = {
 	.fwd_mode_name  = "ieee1588",
 	.port_fwd_begin = port_ieee1588_fwd_begin,
 	.port_fwd_end   = port_ieee1588_fwd_end,
-	.stream_init    = port_ieee1588_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = ieee1588_packet_fwd,
 };
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 9d0af5f667..12be06fa79 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -82,22 +82,8 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine io_fwd_engine = {
 	.fwd_mode_name  = "io",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_io_forward,
 };
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 3a840247c7..953d9ea089 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -113,22 +113,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_fwd_engine = {
 	.fwd_mode_name  = "mac",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_forward,
 };
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 14b3eefffd..062542dc53 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -92,22 +92,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_swap_engine = {
 	.fwd_mode_name  = "macswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_swap,
 };
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index ecea51b603..be35023444 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -279,22 +279,10 @@ noisy_fwd_begin(portid_t pi)
 	return 0;
 }
 
-static void
-stream_init_noisy_vnf(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine noisy_vnf_engine = {
 	.fwd_mode_name  = "noisy",
 	.port_fwd_begin = noisy_fwd_begin,
 	.port_fwd_end   = noisy_fwd_end,
-	.stream_init    = stream_init_noisy_vnf,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_noisy_vnf,
 };
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 4902ec407e..67e5494735 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -114,8 +114,6 @@ shared_rxq_stream_init(struct fwd_stream *fs)
 
 struct fwd_engine shared_rxq_engine = {
 	.fwd_mode_name  = "shared_rxq",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = shared_rxq_stream_init,
 	.packet_fwd     = shared_rxq_fwd,
 };
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index dab67bce5c..d363adbbca 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2343,6 +2343,16 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
 	}
 }
 
+void
+common_fwd_stream_init(struct fwd_stream *fs)
+{
+	bool rx_stopped, tx_stopped;
+
+	rx_stopped = (ports[fs->rx_port].rxq[fs->rx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	tx_stopped = (ports[fs->tx_port].txq[fs->tx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	fs->disabled = rx_stopped || tx_stopped;
+}
+
 /*
  * Launch packet forwarding configuration.
  */
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 5c46844195..5d1a5cde7d 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -390,6 +390,8 @@ struct fwd_engine {
 	packet_fwd_t     packet_fwd;     /**< Mandatory. */
 };
 
+void common_fwd_stream_init(struct fwd_stream *fs);
+
 #define FLEX_ITEM_MAX_SAMPLES_NUM 16
 #define FLEX_ITEM_MAX_LINKS_NUM 16
 #define FLEX_MAX_FLOW_PATTERN_LENGTH 64
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 63ad5e69bf..b80ab6f5df 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -508,7 +508,6 @@ tx_only_stream_init(struct fwd_stream *fs)
 struct fwd_engine tx_only_engine = {
 	.fwd_mode_name  = "txonly",
 	.port_fwd_begin = tx_only_begin,
-	.port_fwd_end   = NULL,
 	.stream_init    = tx_only_stream_init,
 	.packet_fwd     = pkt_burst_transmit,
 };
-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 5/6] app/testpmd: factorize fwd engine Rx
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
                   ` (3 preceding siblings ...)
  2023-01-24 10:47 ` [PATCH 4/6] app/testpmd: factorize fwd engine init David Marchand
@ 2023-01-24 10:47 ` David Marchand
  2023-02-14 18:15   ` Ferruh Yigit
  2023-01-24 10:47 ` [PATCH 6/6] app/testpmd: factorize fwd engine Tx David Marchand
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
receiving packets and incrementing rx counter.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/5tswap.c      |  5 +----
 app/test-pmd/csumonly.c    |  5 +----
 app/test-pmd/flowgen.c     |  5 +----
 app/test-pmd/icmpecho.c    |  5 +----
 app/test-pmd/ieee1588fwd.c |  4 +---
 app/test-pmd/iofwd.c       |  5 +----
 app/test-pmd/macfwd.c      |  5 +----
 app/test-pmd/macswap.c     |  5 +----
 app/test-pmd/noisy_vnf.c   |  5 +----
 app/test-pmd/rxonly.c      |  5 +----
 app/test-pmd/testpmd.h     | 12 ++++++++++++
 11 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 7b5f58f4d4..27da867d7f 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -108,13 +108,10 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 	ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads);
 	vlan_qinq_set(pkts_burst, nb_rx, ol_flags,
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index f72e2d74c7..d758ae0ac6 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -860,13 +860,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	struct testpmd_offload_info info;
 
 	/* receive a burst of packet */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	rx_bad_ip_csum = 0;
 	rx_bad_l4_csum = 0;
 	rx_bad_outer_l4_csum = 0;
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 6f42019353..3705cc60c5 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -80,10 +80,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
 	/* Receive a burst of packets and discard them. */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
-	fs->rx_packets += nb_rx;
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index eba8b99f1e..48f8fe0bf1 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -296,13 +296,10 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	/*
 	 * First, receive a burst of packets.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	nb_replies = 0;
 	for (i = 0; i < nb_rx; i++) {
 		if (likely(i < nb_rx - 1))
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index db7009c678..e8bfd7d940 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -102,11 +102,9 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	/*
 	 * Receive 1 packet at a time.
 	 */
-	if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0)
+	if (common_fwd_stream_receive(fs, &mb, 1) == 0)
 		return false;
 
-	fs->rx_packets += 1;
-
 	/*
 	 * Check that the received packet is a PTP packet that was detected
 	 * by the hardware.
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 12be06fa79..69b583cb5b 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -52,12 +52,9 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
-			pkts_burst, nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
-	fs->rx_packets += nb_rx;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
 			pkts_burst, nb_rx);
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 953d9ea089..a72f5ccb75 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -58,13 +58,10 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 	tx_offloads = txp->dev_conf.txmode.offloads;
 	if (tx_offloads	& RTE_ETH_TX_OFFLOAD_VLAN_INSERT)
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 062542dc53..ab37123404 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -59,13 +59,10 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 
 	do_macswap(pkts_burst, nb_rx, txp);
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index be35023444..937d5a1d7d 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -150,12 +150,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	bool needs_flush = false;
 	uint64_t now;
 
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
-			pkts_burst, nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		goto flush;
-	fs->rx_packets += nb_rx;
 
 	if (!ncf->do_buffering) {
 		sim_memory_lookups(ncf, nb_rx);
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index ad4597cf9a..de3ddcf9a5 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -50,13 +50,10 @@ pkt_burst_receive(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	return true;
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 5d1a5cde7d..e6b28b4748 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -857,6 +857,18 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
 	if (record_burst_stats)
 		fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
 }
+static inline uint16_t
+common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
+	unsigned int count)
+{
+	uint16_t nb_rx;
+
+	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, count);
+	inc_rx_burst_stats(fs, nb_rx);
+	if (likely(nb_rx != 0))
+		fs->rx_packets += nb_rx;
+	return nb_rx;
+}
 
 /* Prototypes */
 unsigned int parse_item_list(const char *str, const char *item_name,
-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
                   ` (4 preceding siblings ...)
  2023-01-24 10:47 ` [PATCH 5/6] app/testpmd: factorize fwd engine Rx David Marchand
@ 2023-01-24 10:47 ` David Marchand
  2023-02-14 11:03   ` Singh, Aman Deep
  2023-02-14 18:16   ` Ferruh Yigit
  2023-01-25 13:50 ` [PATCH 0/6] Testpmd code cleanup Robin Jarry
                   ` (2 subsequent siblings)
  8 siblings, 2 replies; 48+ messages in thread
From: David Marchand @ 2023-01-24 10:47 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
transmitting, retrying if enabled and incrementing tx counter.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/5tswap.c    | 22 +------------
 app/test-pmd/csumonly.c  | 23 +-------------
 app/test-pmd/flowgen.c   | 22 +------------
 app/test-pmd/icmpecho.c  | 28 ++---------------
 app/test-pmd/iofwd.c     | 22 +------------
 app/test-pmd/macfwd.c    | 21 +------------
 app/test-pmd/macswap.c   | 27 ++--------------
 app/test-pmd/noisy_vnf.c | 67 +++++++---------------------------------
 app/test-pmd/testpmd.h   | 30 ++++++++++++++++++
 app/test-pmd/txonly.c    | 33 +++++---------------
 10 files changed, 58 insertions(+), 237 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 27da867d7f..ff8c2dcde5 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -91,9 +91,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	uint64_t ol_flags;
 	uint16_t proto;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
-
 	int i;
 	union {
 		struct rte_ether_hdr *eth;
@@ -155,24 +152,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		}
 		mbuf_field_set(mb, ol_flags);
 	}
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index d758ae0ac6..fc85c22a77 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -847,12 +847,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint8_t gro_enable;
 #endif
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_prep;
 	uint16_t i;
 	uint64_t rx_ol_flags, tx_ol_flags;
 	uint64_t tx_offloads;
-	uint32_t retry;
 	uint32_t rx_bad_ip_csum;
 	uint32_t rx_bad_l4_csum;
 	uint32_t rx_bad_outer_l4_csum;
@@ -1169,32 +1167,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
 	}
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
-			nb_prep);
+	common_fwd_stream_transmit(fs, tx_pkts_burst, nb_prep);
 
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
 	fs->rx_bad_ip_csum += rx_bad_ip_csum;
 	fs->rx_bad_l4_csum += rx_bad_l4_csum;
 	fs->rx_bad_outer_l4_csum += rx_bad_outer_l4_csum;
 	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_prep)) {
-		fs->fwd_dropped += (nb_prep - nb_tx);
-		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
-	}
-
 	return true;
 }
 
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 3705cc60c5..5a0d096309 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -71,11 +71,9 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t vlan_tci, vlan_tci_outer;
 	uint64_t ol_flags = 0;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
-	uint32_t retry;
 	uint64_t tx_offloads;
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
@@ -158,30 +156,12 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			next_flow = 0;
 	}
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_pkt - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-
-	inc_tx_burst_stats(fs, nb_tx);
-	nb_dropped = nb_pkt - nb_tx;
+	nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
 	if (unlikely(nb_dropped > 0)) {
 		/* Back out the flow counter. */
 		next_flow -= nb_dropped;
 		while (next_flow < 0)
 			next_flow += nb_flows_flowgen;
-
-		fs->fwd_dropped += nb_dropped;
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 48f8fe0bf1..68524484e3 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -280,10 +280,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	struct rte_ipv4_hdr *ip_h;
 	struct rte_icmp_hdr *icmp_h;
 	struct rte_ether_addr eth_addr;
-	uint32_t retry;
 	uint32_t ip_addr;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_replies;
 	uint16_t eth_type;
 	uint16_t vlan_id;
@@ -476,30 +474,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	}
 
 	/* Send back ICMP echo replies, if any. */
-	if (nb_replies > 0) {
-		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
-					 nb_replies);
-		/*
-		 * Retry if necessary
-		 */
-		if (unlikely(nb_tx < nb_replies) && fs->retry_enabled) {
-			retry = 0;
-			while (nb_tx < nb_replies &&
-					retry++ < burst_tx_retry_num) {
-				rte_delay_us(burst_tx_delay_time);
-				nb_tx += rte_eth_tx_burst(fs->tx_port,
-						fs->tx_queue,
-						&pkts_burst[nb_tx],
-						nb_replies - nb_tx);
-			}
-		}
-		fs->tx_packets += nb_tx;
-		inc_tx_burst_stats(fs, nb_tx);
-		if (unlikely(nb_tx < nb_replies)) {
-			fs->fwd_dropped += (nb_replies - nb_tx);
-			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
-		}
-	}
+	if (nb_replies > 0)
+		common_fwd_stream_transmit(fs, pkts_burst, nb_replies);
 
 	return true;
 }
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 69b583cb5b..ba06fae4a6 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -46,8 +46,6 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -56,25 +54,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-			pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index a72f5ccb75..7316d73315 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -48,9 +48,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct rte_ether_hdr *eth_hdr;
-	uint32_t retry;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
@@ -87,25 +85,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 		mb->vlan_tci = txp->tx_vlan_id;
 		mb->vlan_tci_outer = txp->tx_vlan_id_outer;
 	}
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
 
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index ab37123404..57f77003fe 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -51,10 +51,7 @@ static bool
 pkt_burst_mac_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
-	struct rte_port  *txp;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -63,28 +60,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	txp = &ports[fs->tx_port];
-
-	do_macswap(pkts_burst, nb_rx, txp);
-
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	do_macswap(pkts_burst, nb_rx, &ports[fs->tx_port]);
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 937d5a1d7d..3875590132 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -93,30 +93,6 @@ sim_memory_lookups(struct noisy_config *ncf, uint16_t nb_pkts)
 	}
 }
 
-static uint16_t
-do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
-	 struct fwd_stream *fs)
-{
-	uint32_t retry = 0;
-
-	while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-		rte_delay_us(burst_tx_delay_time);
-		nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-				&pkts[nb_tx], nb_rx - nb_tx);
-	}
-
-	return nb_tx;
-}
-
-static uint32_t
-drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
-{
-	if (nb_tx < nb_rx)
-		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
-
-	return nb_rx - nb_tx;
-}
-
 /*
  * Forwarding of packets in noisy VNF mode.  Forward packets but perform
  * memory operations first as specified on cmdline.
@@ -156,38 +132,23 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 
 	if (!ncf->do_buffering) {
 		sim_memory_lookups(ncf, nb_rx);
-		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-				pkts_burst, nb_rx);
-		if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
-			nb_tx += do_retry(nb_rx, nb_tx, pkts_burst, fs);
-		inc_tx_burst_stats(fs, nb_tx);
-		fs->tx_packets += nb_tx;
-		fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
+		nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 		return true;
 	}
 
 	fifo_free = rte_ring_free_count(ncf->f);
 	if (fifo_free >= nb_rx) {
-		nb_enqd = rte_ring_enqueue_burst(ncf->f,
-				(void **) pkts_burst, nb_rx, NULL);
-		if (nb_enqd < nb_rx)
-			fs->fwd_dropped += drop_pkts(pkts_burst,
-						     nb_rx, nb_enqd);
-	} else {
-		nb_deqd = rte_ring_dequeue_burst(ncf->f,
-				(void **) tmp_pkts, nb_rx, NULL);
-		nb_enqd = rte_ring_enqueue_burst(ncf->f,
-				(void **) pkts_burst, nb_deqd, NULL);
-		if (nb_deqd > 0) {
-			nb_tx = rte_eth_tx_burst(fs->tx_port,
-					fs->tx_queue, tmp_pkts,
-					nb_deqd);
-			if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
-				nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
-			inc_tx_burst_stats(fs, nb_tx);
-			fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, nb_tx);
+		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_rx, NULL);
+		if (nb_enqd < nb_rx) {
+			fs->fwd_dropped += nb_rx - nb_enqd;
+			rte_pktmbuf_free_bulk(&pkts_burst[nb_enqd], nb_rx - nb_enqd);
 		}
+	} else {
+		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **) tmp_pkts, nb_rx, NULL);
+		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_deqd, NULL);
+		if (nb_deqd > 0)
+			nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
 	}
 
 	sim_memory_lookups(ncf, nb_enqd);
@@ -204,15 +165,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	needs_flush = delta_ms >= noisy_tx_sw_buf_flush_time &&
 			noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
 	while (needs_flush && !rte_ring_empty(ncf->f)) {
-		unsigned int sent;
 		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
 				MAX_PKT_BURST, NULL);
-		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					 tmp_pkts, nb_deqd);
-		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
-			nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
-		inc_tx_burst_stats(fs, nb_tx);
-		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
+		nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index e6b28b4748..71ff70f55b 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -870,6 +870,36 @@ common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
 	return nb_rx;
 }
 
+/* Returns count of dropped packets. */
+static inline uint16_t
+common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
+	unsigned int count)
+{
+	uint16_t nb_tx;
+	uint32_t retry;
+
+	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, count);
+	/*
+	 * Retry if necessary
+	 */
+	if (unlikely(nb_tx < count) && fs->retry_enabled) {
+		retry = 0;
+		while (nb_tx < count && retry++ < burst_tx_retry_num) {
+			rte_delay_us(burst_tx_delay_time);
+			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
+				&burst[nb_tx], count - nb_tx);
+		}
+	}
+	fs->tx_packets += nb_tx;
+	inc_tx_burst_stats(fs, nb_tx);
+	if (unlikely(nb_tx < count)) {
+		fs->fwd_dropped += (count - nb_tx);
+		rte_pktmbuf_free_bulk(&burst[nb_tx], count - nb_tx);
+	}
+
+	return count - nb_tx;
+}
+
 /* Prototypes */
 unsigned int parse_item_list(const char *str, const char *item_name,
 			unsigned int max_items,
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index b80ab6f5df..7144b3d5eb 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -331,10 +331,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	struct rte_mbuf *pkt;
 	struct rte_mempool *mbp;
 	struct rte_ether_hdr eth_hdr;
-	uint16_t nb_tx;
+	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t vlan_tci, vlan_tci_outer;
-	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
 
@@ -391,34 +390,18 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	if (nb_pkt == 0)
 		return false;
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
-
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_pkt - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
+	nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
 
 	if (txonly_multi_flow)
-		RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
+		RTE_PER_LCORE(_ip_var) -= nb_dropped;
 
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_pkt)) {
+	if (unlikely(nb_dropped > 0)) {
 		if (verbose_level > 0 && fs->fwd_dropped == 0)
 			printf("port %d tx_queue %d - drop "
-			       "(nb_pkt:%u - nb_tx:%u)=%u packets\n",
-			       fs->tx_port, fs->tx_queue,
-			       (unsigned) nb_pkt, (unsigned) nb_tx,
-			       (unsigned) (nb_pkt - nb_tx));
-		fs->fwd_dropped += (nb_pkt - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
+				"(nb_pkt:%"PRIu16" - nb_tx:%"PRIu16")="
+				"%"PRIu16" packets\n",
+				fs->tx_port, fs->tx_queue, nb_pkt,
+				nb_pkt - nb_dropped, nb_dropped);
 	}
 
 	return true;
-- 
2.39.1


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 0/6] Testpmd code cleanup
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
                   ` (5 preceding siblings ...)
  2023-01-24 10:47 ` [PATCH 6/6] app/testpmd: factorize fwd engine Tx David Marchand
@ 2023-01-25 13:50 ` Robin Jarry
  2023-02-14 18:22   ` Ferruh Yigit
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
  8 siblings, 1 reply; 48+ messages in thread
From: Robin Jarry @ 2023-01-25 13:50 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang

David Marchand, Jan 24, 2023 at 11:47:
> Here is a series to reduce code duplication in testpmd.
>
> This work started from looking at Robin series on reporting lcore busy 
> cycles in telemetry, which is then added in testpmd [1]. While looking 
> at the forward engines code, I saw way too much duplicated code.
>
> Warning: this is only compile tested.
>
> 1: https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/

Hi David,

The code looks good to me. I have made some basic testing, it seems not 
to break obvious things.

Reviewed-by: Robin Jarry <rjarry@redhat.com>


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-01-24 10:47 ` [PATCH 6/6] app/testpmd: factorize fwd engine Tx David Marchand
@ 2023-02-14 11:03   ` Singh, Aman Deep
  2023-02-14 18:17     ` Ferruh Yigit
  2023-02-14 18:16   ` Ferruh Yigit
  1 sibling, 1 reply; 48+ messages in thread
From: Singh, Aman Deep @ 2023-02-14 11:03 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Ferruh Yigit, Yuying Zhang, Robin Jarry


On 1/24/2023 4:17 PM, David Marchand wrote:
> Reduce code duplication by introducing a helper that takes care of
> transmitting, retrying if enabled and incrementing tx counter.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>   app/test-pmd/5tswap.c    | 22 +------------
>   app/test-pmd/csumonly.c  | 23 +-------------
>   app/test-pmd/flowgen.c   | 22 +------------
>   app/test-pmd/icmpecho.c  | 28 ++---------------
>   app/test-pmd/iofwd.c     | 22 +------------
>   app/test-pmd/macfwd.c    | 21 +------------
>   app/test-pmd/macswap.c   | 27 ++--------------
>   app/test-pmd/noisy_vnf.c | 67 +++++++---------------------------------
>   app/test-pmd/testpmd.h   | 30 ++++++++++++++++++
>   app/test-pmd/txonly.c    | 33 +++++---------------
>   10 files changed, 58 insertions(+), 237 deletions(-)
>
> diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
> index 27da867d7f..ff8c2dcde5 100644
> --- a/app/test-pmd/5tswap.c
> +++ b/app/test-pmd/5tswap.c
> @@ -91,9 +91,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
>   	uint64_t ol_flags;
>   	uint16_t proto;
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
> -	uint32_t retry;
> -
>   	int i;
>   	union {
>   		struct rte_ether_hdr *eth;
> @@ -155,24 +152,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
>   		}
>   		mbuf_field_set(mb, ol_flags);
>   	}
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&pkts_burst[nb_tx], nb_rx - nb_tx);
> -		}
> -	}
> -	fs->tx_packets += nb_tx;
> -	inc_tx_burst_stats(fs, nb_tx);
> -	if (unlikely(nb_tx < nb_rx)) {
> -		fs->fwd_dropped += (nb_rx - nb_tx);
> -		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
> -	}
> +	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
>   
>   	return true;
>   }
> diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
> index d758ae0ac6..fc85c22a77 100644
> --- a/app/test-pmd/csumonly.c
> +++ b/app/test-pmd/csumonly.c
> @@ -847,12 +847,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
>   	uint8_t gro_enable;
>   #endif
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
>   	uint16_t nb_prep;
>   	uint16_t i;
>   	uint64_t rx_ol_flags, tx_ol_flags;
>   	uint64_t tx_offloads;
> -	uint32_t retry;
>   	uint32_t rx_bad_ip_csum;
>   	uint32_t rx_bad_l4_csum;
>   	uint32_t rx_bad_outer_l4_csum;
> @@ -1169,32 +1167,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
>   		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
>   	}
>   
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
> -			nb_prep);
> +	common_fwd_stream_transmit(fs, tx_pkts_burst, nb_prep);
>   
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
> -		}
> -	}
> -	fs->tx_packets += nb_tx;
>   	fs->rx_bad_ip_csum += rx_bad_ip_csum;
>   	fs->rx_bad_l4_csum += rx_bad_l4_csum;
>   	fs->rx_bad_outer_l4_csum += rx_bad_outer_l4_csum;
>   	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
>   
> -	inc_tx_burst_stats(fs, nb_tx);
> -	if (unlikely(nb_tx < nb_prep)) {
> -		fs->fwd_dropped += (nb_prep - nb_tx);
> -		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
> -	}
> -
>   	return true;
>   }
>   
> diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
> index 3705cc60c5..5a0d096309 100644
> --- a/app/test-pmd/flowgen.c
> +++ b/app/test-pmd/flowgen.c
> @@ -71,11 +71,9 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
>   	uint16_t vlan_tci, vlan_tci_outer;
>   	uint64_t ol_flags = 0;
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
>   	uint16_t nb_dropped;
>   	uint16_t nb_pkt;
>   	uint16_t nb_clones = nb_pkt_flowgen_clones;
> -	uint32_t retry;
>   	uint64_t tx_offloads;
>   	int next_flow = RTE_PER_LCORE(_next_flow);
>   
> @@ -158,30 +156,12 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
>   			next_flow = 0;
>   	}
>   
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&pkts_burst[nb_tx], nb_pkt - nb_tx);
> -		}
> -	}
> -	fs->tx_packets += nb_tx;
> -
> -	inc_tx_burst_stats(fs, nb_tx);
> -	nb_dropped = nb_pkt - nb_tx;
> +	nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
>   	if (unlikely(nb_dropped > 0)) {
>   		/* Back out the flow counter. */
>   		next_flow -= nb_dropped;
>   		while (next_flow < 0)
>   			next_flow += nb_flows_flowgen;
> -
> -		fs->fwd_dropped += nb_dropped;
> -		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
>   	}
>   
>   	RTE_PER_LCORE(_next_flow) = next_flow;
> diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
> index 48f8fe0bf1..68524484e3 100644
> --- a/app/test-pmd/icmpecho.c
> +++ b/app/test-pmd/icmpecho.c
> @@ -280,10 +280,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
>   	struct rte_ipv4_hdr *ip_h;
>   	struct rte_icmp_hdr *icmp_h;
>   	struct rte_ether_addr eth_addr;
> -	uint32_t retry;
>   	uint32_t ip_addr;
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
>   	uint16_t nb_replies;
>   	uint16_t eth_type;
>   	uint16_t vlan_id;
> @@ -476,30 +474,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
>   	}
>   
>   	/* Send back ICMP echo replies, if any. */
> -	if (nb_replies > 0) {
> -		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
> -					 nb_replies);
> -		/*
> -		 * Retry if necessary
> -		 */
> -		if (unlikely(nb_tx < nb_replies) && fs->retry_enabled) {
> -			retry = 0;
> -			while (nb_tx < nb_replies &&
> -					retry++ < burst_tx_retry_num) {
> -				rte_delay_us(burst_tx_delay_time);
> -				nb_tx += rte_eth_tx_burst(fs->tx_port,
> -						fs->tx_queue,
> -						&pkts_burst[nb_tx],
> -						nb_replies - nb_tx);
> -			}
> -		}
> -		fs->tx_packets += nb_tx;
> -		inc_tx_burst_stats(fs, nb_tx);
> -		if (unlikely(nb_tx < nb_replies)) {
> -			fs->fwd_dropped += (nb_replies - nb_tx);
> -			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
> -		}
> -	}
> +	if (nb_replies > 0)
> +		common_fwd_stream_transmit(fs, pkts_burst, nb_replies);
>   
>   	return true;
>   }
> diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
> index 69b583cb5b..ba06fae4a6 100644
> --- a/app/test-pmd/iofwd.c
> +++ b/app/test-pmd/iofwd.c
> @@ -46,8 +46,6 @@ pkt_burst_io_forward(struct fwd_stream *fs)
>   {
>   	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
> -	uint32_t retry;
>   
>   	/*
>   	 * Receive a burst of packets and forward them.
> @@ -56,25 +54,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
>   	if (unlikely(nb_rx == 0))
>   		return false;
>   
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -			pkts_burst, nb_rx);
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&pkts_burst[nb_tx], nb_rx - nb_tx);
> -		}
> -	}
> -	fs->tx_packets += nb_tx;
> -	inc_tx_burst_stats(fs, nb_tx);
> -	if (unlikely(nb_tx < nb_rx)) {
> -		fs->fwd_dropped += (nb_rx - nb_tx);
> -		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
> -	}
> +	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
>   
>   	return true;
>   }
> diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
> index a72f5ccb75..7316d73315 100644
> --- a/app/test-pmd/macfwd.c
> +++ b/app/test-pmd/macfwd.c
> @@ -48,9 +48,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
>   	struct rte_port  *txp;
>   	struct rte_mbuf  *mb;
>   	struct rte_ether_hdr *eth_hdr;
> -	uint32_t retry;
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
>   	uint16_t i;
>   	uint64_t ol_flags = 0;
>   	uint64_t tx_offloads;
> @@ -87,25 +85,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
>   		mb->vlan_tci = txp->tx_vlan_id;
>   		mb->vlan_tci_outer = txp->tx_vlan_id_outer;
>   	}
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&pkts_burst[nb_tx], nb_rx - nb_tx);
> -		}
> -	}
>   
> -	fs->tx_packets += nb_tx;
> -	inc_tx_burst_stats(fs, nb_tx);
> -	if (unlikely(nb_tx < nb_rx)) {
> -		fs->fwd_dropped += (nb_rx - nb_tx);
> -		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
> -	}
> +	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
>   
>   	return true;
>   }
> diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
> index ab37123404..57f77003fe 100644
> --- a/app/test-pmd/macswap.c
> +++ b/app/test-pmd/macswap.c
> @@ -51,10 +51,7 @@ static bool
>   pkt_burst_mac_swap(struct fwd_stream *fs)
>   {
>   	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
> -	struct rte_port  *txp;
>   	uint16_t nb_rx;
> -	uint16_t nb_tx;
> -	uint32_t retry;
>   
>   	/*
>   	 * Receive a burst of packets and forward them.
> @@ -63,28 +60,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
>   	if (unlikely(nb_rx == 0))
>   		return false;
>   
> -	txp = &ports[fs->tx_port];
> -
> -	do_macswap(pkts_burst, nb_rx, txp);
> -
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&pkts_burst[nb_tx], nb_rx - nb_tx);
> -		}
> -	}
> -	fs->tx_packets += nb_tx;
> -	inc_tx_burst_stats(fs, nb_tx);
> -	if (unlikely(nb_tx < nb_rx)) {
> -		fs->fwd_dropped += (nb_rx - nb_tx);
> -		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
> -	}
> +	do_macswap(pkts_burst, nb_rx, &ports[fs->tx_port]);
> +	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
>   
>   	return true;
>   }
> diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
> index 937d5a1d7d..3875590132 100644
> --- a/app/test-pmd/noisy_vnf.c
> +++ b/app/test-pmd/noisy_vnf.c
> @@ -93,30 +93,6 @@ sim_memory_lookups(struct noisy_config *ncf, uint16_t nb_pkts)
>   	}
>   }
>   
> -static uint16_t
> -do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
> -	 struct fwd_stream *fs)
> -{
> -	uint32_t retry = 0;
> -
> -	while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> -		rte_delay_us(burst_tx_delay_time);
> -		nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -				&pkts[nb_tx], nb_rx - nb_tx);
> -	}
> -
> -	return nb_tx;
> -}
> -
> -static uint32_t
> -drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
> -{
> -	if (nb_tx < nb_rx)
> -		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
> -
> -	return nb_rx - nb_tx;
> -}
> -
>   /*
>    * Forwarding of packets in noisy VNF mode.  Forward packets but perform
>    * memory operations first as specified on cmdline.
> @@ -156,38 +132,23 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
>   
>   	if (!ncf->do_buffering) {
>   		sim_memory_lookups(ncf, nb_rx);
> -		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -				pkts_burst, nb_rx);
> -		if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
> -			nb_tx += do_retry(nb_rx, nb_tx, pkts_burst, fs);
> -		inc_tx_burst_stats(fs, nb_tx);
> -		fs->tx_packets += nb_tx;
> -		fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
> +		nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
>   
>   		return true;
>   	}
>   
>   	fifo_free = rte_ring_free_count(ncf->f);
>   	if (fifo_free >= nb_rx) {
> -		nb_enqd = rte_ring_enqueue_burst(ncf->f,
> -				(void **) pkts_burst, nb_rx, NULL);
> -		if (nb_enqd < nb_rx)
> -			fs->fwd_dropped += drop_pkts(pkts_burst,
> -						     nb_rx, nb_enqd);
> -	} else {
> -		nb_deqd = rte_ring_dequeue_burst(ncf->f,
> -				(void **) tmp_pkts, nb_rx, NULL);
> -		nb_enqd = rte_ring_enqueue_burst(ncf->f,
> -				(void **) pkts_burst, nb_deqd, NULL);
> -		if (nb_deqd > 0) {
> -			nb_tx = rte_eth_tx_burst(fs->tx_port,
> -					fs->tx_queue, tmp_pkts,
> -					nb_deqd);
> -			if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
> -				nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
> -			inc_tx_burst_stats(fs, nb_tx);
> -			fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, nb_tx);
> +		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_rx, NULL);
> +		if (nb_enqd < nb_rx) {
> +			fs->fwd_dropped += nb_rx - nb_enqd;
> +			rte_pktmbuf_free_bulk(&pkts_burst[nb_enqd], nb_rx - nb_enqd);
>   		}
> +	} else {
> +		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **) tmp_pkts, nb_rx, NULL);
> +		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_deqd, NULL);
> +		if (nb_deqd > 0)
> +			nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
>   	}
>   
>   	sim_memory_lookups(ncf, nb_enqd);
> @@ -204,15 +165,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
>   	needs_flush = delta_ms >= noisy_tx_sw_buf_flush_time &&
>   			noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
>   	while (needs_flush && !rte_ring_empty(ncf->f)) {
> -		unsigned int sent;
>   		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
>   				MAX_PKT_BURST, NULL);
> -		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					 tmp_pkts, nb_deqd);
> -		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
> -			nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
> -		inc_tx_burst_stats(fs, nb_tx);
> -		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
> +		nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
>   		ncf->prev_time = rte_get_timer_cycles();
>   	}
>   
> diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
> index e6b28b4748..71ff70f55b 100644
> --- a/app/test-pmd/testpmd.h
> +++ b/app/test-pmd/testpmd.h
> @@ -870,6 +870,36 @@ common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
>   	return nb_rx;
>   }
>   
> +/* Returns count of dropped packets. */
> +static inline uint16_t
> +common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
> +	unsigned int count)
> +{
> +	uint16_t nb_tx;
> +	uint32_t retry;
> +
> +	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, count);
> +	/*
> +	 * Retry if necessary
> +	 */
> +	if (unlikely(nb_tx < count) && fs->retry_enabled) {
> +		retry = 0;
> +		while (nb_tx < count && retry++ < burst_tx_retry_num) {
> +			rte_delay_us(burst_tx_delay_time);
> +			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> +				&burst[nb_tx], count - nb_tx);
> +		}
> +	}
> +	fs->tx_packets += nb_tx;
> +	inc_tx_burst_stats(fs, nb_tx);
> +	if (unlikely(nb_tx < count)) {
> +		fs->fwd_dropped += (count - nb_tx);
> +		rte_pktmbuf_free_bulk(&burst[nb_tx], count - nb_tx);
> +	}
> +
> +	return count - nb_tx;
> +}
> +
>   /* Prototypes */
>   unsigned int parse_item_list(const char *str, const char *item_name,
>   			unsigned int max_items,
> diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
> index b80ab6f5df..7144b3d5eb 100644
> --- a/app/test-pmd/txonly.c
> +++ b/app/test-pmd/txonly.c
> @@ -331,10 +331,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
>   	struct rte_mbuf *pkt;
>   	struct rte_mempool *mbp;
>   	struct rte_ether_hdr eth_hdr;
> -	uint16_t nb_tx;
> +	uint16_t nb_dropped;
>   	uint16_t nb_pkt;
>   	uint16_t vlan_tci, vlan_tci_outer;
> -	uint32_t retry;
>   	uint64_t ol_flags = 0;
>   	uint64_t tx_offloads;
>   
> @@ -391,34 +390,18 @@ pkt_burst_transmit(struct fwd_stream *fs)
>   	if (nb_pkt == 0)
>   		return false;
>   
> -	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
> -
> -	/*
> -	 * Retry if necessary
> -	 */
> -	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
> -		retry = 0;
> -		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
> -			rte_delay_us(burst_tx_delay_time);
> -			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					&pkts_burst[nb_tx], nb_pkt - nb_tx);
> -		}
> -	}
> -	fs->tx_packets += nb_tx;
> +	nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
>   
>   	if (txonly_multi_flow)
> -		RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
> +		RTE_PER_LCORE(_ip_var) -= nb_dropped;
>   
> -	inc_tx_burst_stats(fs, nb_tx);
> -	if (unlikely(nb_tx < nb_pkt)) {
> +	if (unlikely(nb_dropped > 0)) {
>   		if (verbose_level > 0 && fs->fwd_dropped == 0)
>   			printf("port %d tx_queue %d - drop "
> -			       "(nb_pkt:%u - nb_tx:%u)=%u packets\n",
> -			       fs->tx_port, fs->tx_queue,
> -			       (unsigned) nb_pkt, (unsigned) nb_tx,
> -			       (unsigned) (nb_pkt - nb_tx));
> -		fs->fwd_dropped += (nb_pkt - nb_tx);
> -		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
> +				"(nb_pkt:%"PRIu16" - nb_tx:%"PRIu16")="
> +				"%"PRIu16" packets\n",
> +				fs->tx_port, fs->tx_queue, nb_pkt,
> +				nb_pkt - nb_dropped, nb_dropped);

Build error reported in this file here-
../app/test-pmd/txonly.c:404:5: error: format specifies type 'unsigned short' but the argument has type 'int' [-Werror,-Wformat]

>   	}
>   
>   	return true;

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 1/6] app/testpmd: factorize core cycles record
  2023-01-24 10:47 ` [PATCH 1/6] app/testpmd: factorize core cycles record David Marchand
@ 2023-02-14 18:14   ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:14 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 1/24/2023 10:47 AM, David Marchand wrote:
> Rather than have each forward engines deal with core cycles recording,
> move this to testpmd common code.
> fwd engines just need to report that they did some busy work.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 2/6] app/testpmd: don't send unprepared packets
  2023-01-24 10:47 ` [PATCH 2/6] app/testpmd: don't send unprepared packets David Marchand
@ 2023-02-14 18:14   ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:14 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: Aman Singh, Yuying Zhang, Robin Jarry, stable, Tomasz Kulasek,
	Konstantin Ananyev

On 1/24/2023 10:47 AM, David Marchand wrote:
> "unprepared" packets could get to the wire in the retry loop.
> 
> Split packets freeing in two stages: one for preparation failure, and
> one for transmission failure.
> Adjust dropped counter update accordingly.
> 
> Fixes: 6b520d54ebfe ("app/testpmd: use Tx preparation in checksum engine")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 3/6] app/testpmd: bulk free mbufs
  2023-01-24 10:47 ` [PATCH 3/6] app/testpmd: bulk free mbufs David Marchand
@ 2023-02-14 18:14   ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:14 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 1/24/2023 10:47 AM, David Marchand wrote:
> Use the bulk free helper.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 4/6] app/testpmd: factorize fwd engine init
  2023-01-24 10:47 ` [PATCH 4/6] app/testpmd: factorize fwd engine init David Marchand
@ 2023-02-14 18:14   ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:14 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 1/24/2023 10:47 AM, David Marchand wrote:
> Reduce code duplication by introducing a helper that takes care of
> initialising the fs object.
> 
> While at it, remove unneeded initialisation of fwd_engine empty fields.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 5/6] app/testpmd: factorize fwd engine Rx
  2023-01-24 10:47 ` [PATCH 5/6] app/testpmd: factorize fwd engine Rx David Marchand
@ 2023-02-14 18:15   ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:15 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 1/24/2023 10:47 AM, David Marchand wrote:
> Reduce code duplication by introducing a helper that takes care of
> receiving packets and incrementing rx counter.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>


<...>


> @@ -857,6 +857,18 @@ inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
>  	if (record_burst_stats)
>  		fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
>  }
> +static inline uint16_t
> +common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
> +	unsigned int count)
> +{
> +	uint16_t nb_rx;
> +
> +	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, count);
> +	inc_rx_burst_stats(fs, nb_rx);
> +	if (likely(nb_rx != 0))
> +		fs->rx_packets += nb_rx;


Minor but since "nb_rx != 0" is likely case, perhaps we can drop the
check and just have "fs->rx_packets += nb_rx;"?

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-01-24 10:47 ` [PATCH 6/6] app/testpmd: factorize fwd engine Tx David Marchand
  2023-02-14 11:03   ` Singh, Aman Deep
@ 2023-02-14 18:16   ` Ferruh Yigit
  2023-02-20 16:33     ` David Marchand
  1 sibling, 1 reply; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:16 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 1/24/2023 10:47 AM, David Marchand wrote:
> Reduce code duplication by introducing a helper that takes care of
> transmitting, retrying if enabled and incrementing tx counter.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

<...>

> diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
> index 937d5a1d7d..3875590132 100644
> --- a/app/test-pmd/noisy_vnf.c
> +++ b/app/test-pmd/noisy_vnf.c
> @@ -93,30 +93,6 @@ sim_memory_lookups(struct noisy_config *ncf, uint16_t nb_pkts)
>  	}
>  }
>  
> -static uint16_t
> -do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
> -	 struct fwd_stream *fs)
> -{
> -	uint32_t retry = 0;
> -
> -	while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> -		rte_delay_us(burst_tx_delay_time);
> -		nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -				&pkts[nb_tx], nb_rx - nb_tx);
> -	}
> -
> -	return nb_tx;
> -}
> -
> -static uint32_t
> -drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
> -{
> -	if (nb_tx < nb_rx)
> -		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
> -
> -	return nb_rx - nb_tx;
> -}
> -
>  /*
>   * Forwarding of packets in noisy VNF mode.  Forward packets but perform
>   * memory operations first as specified on cmdline.
> @@ -156,38 +132,23 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
>  
>  	if (!ncf->do_buffering) {
>  		sim_memory_lookups(ncf, nb_rx);
> -		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -				pkts_burst, nb_rx);
> -		if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
> -			nb_tx += do_retry(nb_rx, nb_tx, pkts_burst, fs);
> -		inc_tx_burst_stats(fs, nb_tx);
> -		fs->tx_packets += nb_tx;
> -		fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
> +		nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
>  

'nb_tx' is not used or necessary in this context, so assignment is not
necassary.

PS:
In the latest next-net head, there is a 'goto' here instead of return,
but that is becuase of recording cycles, becuase of optimization in this
set (patch 1/6) that needs to turn back to 'return' that is what I did
while applying patch.

>  		kreturn true;
>  	}
>  
>  	fifo_free = rte_ring_free_count(ncf->f);
>  	if (fifo_free >= nb_rx) {
> -		nb_enqd = rte_ring_enqueue_burst(ncf->f,
> -				(void **) pkts_burst, nb_rx, NULL);
> -		if (nb_enqd < nb_rx)
> -			fs->fwd_dropped += drop_pkts(pkts_burst,
> -						     nb_rx, nb_enqd);
> -	} else {
> -		nb_deqd = rte_ring_dequeue_burst(ncf->f,
> -				(void **) tmp_pkts, nb_rx, NULL);
> -		nb_enqd = rte_ring_enqueue_burst(ncf->f,
> -				(void **) pkts_burst, nb_deqd, NULL);
> -		if (nb_deqd > 0) {
> -			nb_tx = rte_eth_tx_burst(fs->tx_port,
> -					fs->tx_queue, tmp_pkts,
> -					nb_deqd);
> -			if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
> -				nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
> -			inc_tx_burst_stats(fs, nb_tx);
> -			fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, nb_tx);
> +		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_rx, NULL);
> +		if (nb_enqd < nb_rx) {
> +			fs->fwd_dropped += nb_rx - nb_enqd;
> +			rte_pktmbuf_free_bulk(&pkts_burst[nb_enqd], nb_rx - nb_enqd);

Why not keep 'drop_pkts()' for this block, it is easier to read with it.

>  		}
> +	} else {
> +		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **) tmp_pkts, nb_rx, NULL);
> +		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_deqd, NULL);
> +		if (nb_deqd > 0)
> +			nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);

'nb_tx' assignment looks wrong,
function returns 'nb_dropped' not 'nb_tx'. 'nb_tx' used below to detect
if flush needed ('needs_flush'), so 'needs_flush' may be set wrong
becuase dropped packet is used instead number of Tx packets.

>  	}
>  
>  	sim_memory_lookups(ncf, nb_enqd);
> @@ -204,15 +165,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
>  	needs_flush = delta_ms >= noisy_tx_sw_buf_flush_time &&
>  			noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
>  	while (needs_flush && !rte_ring_empty(ncf->f)) {
> -		unsigned int sent;
>  		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
>  				MAX_PKT_BURST, NULL);
> -		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> -					 tmp_pkts, nb_deqd);
> -		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
> -			nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
> -		inc_tx_burst_stats(fs, nb_tx);
> -		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
> +		nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);

similaryly 'nb_tx' assignment can be wrong here, and 'nb_tx' used for
return value to hint if record cycle is required, using number of
dropped packets (what 'common_fwd_stream_transmit()' returns) gives
wrong result.

>  		ncf->prev_time = rte_get_timer_cycles();
>  	}
>  
> diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
> index e6b28b4748..71ff70f55b 100644
> --- a/app/test-pmd/testpmd.h
> +++ b/app/test-pmd/testpmd.h
> @@ -870,6 +870,36 @@ common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
>  	return nb_rx;
>  }
>  
> +/* Returns count of dropped packets. */
> +static inline uint16_t
> +common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
> +	unsigned int count)

I would use 'nb_pkts' instead of 'count' as variable name since it is
more common, but of course this is subjective.

> +{
> +	uint16_t nb_tx;
> +	uint32_t retry;
> +
> +	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, count);
> +	/*
> +	 * Retry if necessary
> +	 */
> +	if (unlikely(nb_tx < count) && fs->retry_enabled) {
> +		retry = 0;
> +		while (nb_tx < count && retry++ < burst_tx_retry_num) {
> +			rte_delay_us(burst_tx_delay_time);
> +			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> +				&burst[nb_tx], count - nb_tx);
> +		}
> +	}
> +	fs->tx_packets += nb_tx;
> +	inc_tx_burst_stats(fs, nb_tx);
> +	if (unlikely(nb_tx < count)) {
> +		fs->fwd_dropped += (count - nb_tx);
> +		rte_pktmbuf_free_bulk(&burst[nb_tx], count - nb_tx);
> +	}
> +
> +	return count - nb_tx;

Instead of returning number of dropped packets, what about returning
number of packets sent ('nb_tx')?
Intuitively this is what expected from a function named
'common_fwd_stream_transmit()', and even if it is more optimised to
return number of dropped packet, this may have only a little impact on
the caller code.


And even 'fs->tx_packets' updated withing the function, updating it
externally and explicitly feels me as it clarifies usage more, although
this part is up to you, I mean usage like:
fs->tx_packets += common_fwd_stream_transmit(fs, pkts, nb_pkts);


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-02-14 11:03   ` Singh, Aman Deep
@ 2023-02-14 18:17     ` Ferruh Yigit
  2023-02-16  8:01       ` Singh, Aman Deep
  0 siblings, 1 reply; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:17 UTC (permalink / raw)
  To: Singh, Aman Deep, David Marchand, dev; +Cc: Yuying Zhang, Robin Jarry

On 2/14/2023 11:03 AM, Singh, Aman Deep wrote:
> 
> On 1/24/2023 4:17 PM, David Marchand wrote:
>> Reduce code duplication by introducing a helper that takes care of
>> transmitting, retrying if enabled and incrementing tx counter.
>>
>> Signed-off-by: David Marchand <david.marchand@redhat.com>

<...>

>> diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
>> index b80ab6f5df..7144b3d5eb 100644
>> --- a/app/test-pmd/txonly.c
>> +++ b/app/test-pmd/txonly.c
>> @@ -331,10 +331,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>       struct rte_mbuf *pkt;
>>       struct rte_mempool *mbp;
>>       struct rte_ether_hdr eth_hdr;
>> -    uint16_t nb_tx;
>> +    uint16_t nb_dropped;
>>       uint16_t nb_pkt;
>>       uint16_t vlan_tci, vlan_tci_outer;
>> -    uint32_t retry;
>>       uint64_t ol_flags = 0;
>>       uint64_t tx_offloads;
>>   @@ -391,34 +390,18 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>       if (nb_pkt == 0)
>>           return false;
>>   -    nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
>> nb_pkt);
>> -
>> -    /*
>> -     * Retry if necessary
>> -     */
>> -    if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
>> -        retry = 0;
>> -        while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
>> -            rte_delay_us(burst_tx_delay_time);
>> -            nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
>> -                    &pkts_burst[nb_tx], nb_pkt - nb_tx);
>> -        }
>> -    }
>> -    fs->tx_packets += nb_tx;
>> +    nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
>>         if (txonly_multi_flow)
>> -        RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
>> +        RTE_PER_LCORE(_ip_var) -= nb_dropped;
>>   -    inc_tx_burst_stats(fs, nb_tx);
>> -    if (unlikely(nb_tx < nb_pkt)) {
>> +    if (unlikely(nb_dropped > 0)) {
>>           if (verbose_level > 0 && fs->fwd_dropped == 0)
>>               printf("port %d tx_queue %d - drop "
>> -                   "(nb_pkt:%u - nb_tx:%u)=%u packets\n",
>> -                   fs->tx_port, fs->tx_queue,
>> -                   (unsigned) nb_pkt, (unsigned) nb_tx,
>> -                   (unsigned) (nb_pkt - nb_tx));
>> -        fs->fwd_dropped += (nb_pkt - nb_tx);
>> -        rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
>> +                "(nb_pkt:%"PRIu16" - nb_tx:%"PRIu16")="
>> +                "%"PRIu16" packets\n",
>> +                fs->tx_port, fs->tx_queue, nb_pkt,
>> +                nb_pkt - nb_dropped, nb_dropped);
> 
> Build error reported in this file here-
> ../app/test-pmd/txonly.c:404:5: error: format specifies type 'unsigned
> short' but the argument has type 'int' [-Werror,-Wformat]
> 

both 'nb_pkt' & 'nb_dropped' are 'uint16_t' (unsigned short), I wonder
which argument is causing this warning?



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 0/6] Testpmd code cleanup
  2023-01-25 13:50 ` [PATCH 0/6] Testpmd code cleanup Robin Jarry
@ 2023-02-14 18:22   ` Ferruh Yigit
  2023-02-20 15:02     ` David Marchand
  0 siblings, 1 reply; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-14 18:22 UTC (permalink / raw)
  To: Robin Jarry, David Marchand, dev; +Cc: Aman Singh, Yuying Zhang

On 1/25/2023 1:50 PM, Robin Jarry wrote:
> David Marchand, Jan 24, 2023 at 11:47:
>> Here is a series to reduce code duplication in testpmd.
>>
>> This work started from looking at Robin series on reporting lcore busy
>> cycles in telemetry, which is then added in testpmd [1]. While looking
>> at the forward engines code, I saw way too much duplicated code.
>>
>> Warning: this is only compile tested.
>>
>> 1:
>> https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/
> 
> Hi David,
> 
> The code looks good to me. I have made some basic testing, it seems not
> to break obvious things.
> 
> Reviewed-by: Robin Jarry <rjarry@redhat.com>
> 

Hi Robin,

This set conflicts with your set which is merged [1], I guess your test
was before your patch merged. Can you please check again after rebase?



[1]
Commit 99a4974aa569 ("app/testpmd: report lcore usage")

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-02-14 18:17     ` Ferruh Yigit
@ 2023-02-16  8:01       ` Singh, Aman Deep
  2023-02-16 10:07         ` Ferruh Yigit
  0 siblings, 1 reply; 48+ messages in thread
From: Singh, Aman Deep @ 2023-02-16  8:01 UTC (permalink / raw)
  To: Ferruh Yigit, David Marchand, dev; +Cc: Yuying Zhang, Robin Jarry


On 2/14/2023 11:47 PM, Ferruh Yigit wrote:
> On 2/14/2023 11:03 AM, Singh, Aman Deep wrote:
>> On 1/24/2023 4:17 PM, David Marchand wrote:
>>> Reduce code duplication by introducing a helper that takes care of
>>> transmitting, retrying if enabled and incrementing tx counter.
>>>
>>> Signed-off-by: David Marchand <david.marchand@redhat.com>
> <...>
>
>>> diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
>>> index b80ab6f5df..7144b3d5eb 100644
>>> --- a/app/test-pmd/txonly.c
>>> +++ b/app/test-pmd/txonly.c
>>> @@ -331,10 +331,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>>        struct rte_mbuf *pkt;
>>>        struct rte_mempool *mbp;
>>>        struct rte_ether_hdr eth_hdr;
>>> -    uint16_t nb_tx;
>>> +    uint16_t nb_dropped;
>>>        uint16_t nb_pkt;
>>>        uint16_t vlan_tci, vlan_tci_outer;
>>> -    uint32_t retry;
>>>        uint64_t ol_flags = 0;
>>>        uint64_t tx_offloads;
>>>    @@ -391,34 +390,18 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>>        if (nb_pkt == 0)
>>>            return false;
>>>    -    nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
>>> nb_pkt);
>>> -
>>> -    /*
>>> -     * Retry if necessary
>>> -     */
>>> -    if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
>>> -        retry = 0;
>>> -        while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
>>> -            rte_delay_us(burst_tx_delay_time);
>>> -            nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
>>> -                    &pkts_burst[nb_tx], nb_pkt - nb_tx);
>>> -        }
>>> -    }
>>> -    fs->tx_packets += nb_tx;
>>> +    nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
>>>          if (txonly_multi_flow)
>>> -        RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
>>> +        RTE_PER_LCORE(_ip_var) -= nb_dropped;
>>>    -    inc_tx_burst_stats(fs, nb_tx);
>>> -    if (unlikely(nb_tx < nb_pkt)) {
>>> +    if (unlikely(nb_dropped > 0)) {
>>>            if (verbose_level > 0 && fs->fwd_dropped == 0)
>>>                printf("port %d tx_queue %d - drop "
>>> -                   "(nb_pkt:%u - nb_tx:%u)=%u packets\n",
>>> -                   fs->tx_port, fs->tx_queue,
>>> -                   (unsigned) nb_pkt, (unsigned) nb_tx,
>>> -                   (unsigned) (nb_pkt - nb_tx));
>>> -        fs->fwd_dropped += (nb_pkt - nb_tx);
>>> -        rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
>>> +                "(nb_pkt:%"PRIu16" - nb_tx:%"PRIu16")="
>>> +                "%"PRIu16" packets\n",
>>> +                fs->tx_port, fs->tx_queue, nb_pkt,
>>> +                nb_pkt - nb_dropped, nb_dropped);
>> Build error reported in this file here-
>> ../app/test-pmd/txonly.c:404:5: error: format specifies type 'unsigned
>> short' but the argument has type 'int' [-Werror,-Wformat]
>>
> both 'nb_pkt' & 'nb_dropped' are 'uint16_t' (unsigned short), I wonder
> which argument is causing this warning?

I think, subtraction of two unsigned numbers promotes the result to int.
As 'nb_pkt > nb_dropped', we may explicitly typecast it-
'(unsigned)(nb_pkt - nb_dropped)'

>
>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-02-16  8:01       ` Singh, Aman Deep
@ 2023-02-16 10:07         ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-16 10:07 UTC (permalink / raw)
  To: Singh, Aman Deep, David Marchand, dev; +Cc: Yuying Zhang, Robin Jarry

On 2/16/2023 8:01 AM, Singh, Aman Deep wrote:
> 
> On 2/14/2023 11:47 PM, Ferruh Yigit wrote:
>> On 2/14/2023 11:03 AM, Singh, Aman Deep wrote:
>>> On 1/24/2023 4:17 PM, David Marchand wrote:
>>>> Reduce code duplication by introducing a helper that takes care of
>>>> transmitting, retrying if enabled and incrementing tx counter.
>>>>
>>>> Signed-off-by: David Marchand <david.marchand@redhat.com>
>> <...>
>>
>>>> diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
>>>> index b80ab6f5df..7144b3d5eb 100644
>>>> --- a/app/test-pmd/txonly.c
>>>> +++ b/app/test-pmd/txonly.c
>>>> @@ -331,10 +331,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>>>        struct rte_mbuf *pkt;
>>>>        struct rte_mempool *mbp;
>>>>        struct rte_ether_hdr eth_hdr;
>>>> -    uint16_t nb_tx;
>>>> +    uint16_t nb_dropped;
>>>>        uint16_t nb_pkt;
>>>>        uint16_t vlan_tci, vlan_tci_outer;
>>>> -    uint32_t retry;
>>>>        uint64_t ol_flags = 0;
>>>>        uint64_t tx_offloads;
>>>>    @@ -391,34 +390,18 @@ pkt_burst_transmit(struct fwd_stream *fs)
>>>>        if (nb_pkt == 0)
>>>>            return false;
>>>>    -    nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
>>>> nb_pkt);
>>>> -
>>>> -    /*
>>>> -     * Retry if necessary
>>>> -     */
>>>> -    if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
>>>> -        retry = 0;
>>>> -        while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
>>>> -            rte_delay_us(burst_tx_delay_time);
>>>> -            nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
>>>> -                    &pkts_burst[nb_tx], nb_pkt - nb_tx);
>>>> -        }
>>>> -    }
>>>> -    fs->tx_packets += nb_tx;
>>>> +    nb_dropped = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
>>>>          if (txonly_multi_flow)
>>>> -        RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
>>>> +        RTE_PER_LCORE(_ip_var) -= nb_dropped;
>>>>    -    inc_tx_burst_stats(fs, nb_tx);
>>>> -    if (unlikely(nb_tx < nb_pkt)) {
>>>> +    if (unlikely(nb_dropped > 0)) {
>>>>            if (verbose_level > 0 && fs->fwd_dropped == 0)
>>>>                printf("port %d tx_queue %d - drop "
>>>> -                   "(nb_pkt:%u - nb_tx:%u)=%u packets\n",
>>>> -                   fs->tx_port, fs->tx_queue,
>>>> -                   (unsigned) nb_pkt, (unsigned) nb_tx,
>>>> -                   (unsigned) (nb_pkt - nb_tx));
>>>> -        fs->fwd_dropped += (nb_pkt - nb_tx);
>>>> -        rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
>>>> +                "(nb_pkt:%"PRIu16" - nb_tx:%"PRIu16")="
>>>> +                "%"PRIu16" packets\n",
>>>> +                fs->tx_port, fs->tx_queue, nb_pkt,
>>>> +                nb_pkt - nb_dropped, nb_dropped);
>>> Build error reported in this file here-
>>> ../app/test-pmd/txonly.c:404:5: error: format specifies type 'unsigned
>>> short' but the argument has type 'int' [-Werror,-Wformat]
>>>
>> both 'nb_pkt' & 'nb_dropped' are 'uint16_t' (unsigned short), I wonder
>> which argument is causing this warning?
> 
> I think, subtraction of two unsigned numbers promotes the result to int.
> As 'nb_pkt > nb_dropped', we may explicitly typecast it-
> '(unsigned)(nb_pkt - nb_dropped)'
> 

You are right, subtraction promoted to int.
May be better to cast to 'uint16_t', since warning is not just sign but
also type related.


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 0/6] Testpmd code cleanup
  2023-02-14 18:22   ` Ferruh Yigit
@ 2023-02-20 15:02     ` David Marchand
  0 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 15:02 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: Robin Jarry, dev, Aman Singh, Yuying Zhang

Hi Robin, Ferruh,

On Tue, Feb 14, 2023 at 7:22 PM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 1/25/2023 1:50 PM, Robin Jarry wrote:
> > David Marchand, Jan 24, 2023 at 11:47:
> >> Here is a series to reduce code duplication in testpmd.
> >>
> >> This work started from looking at Robin series on reporting lcore busy
> >> cycles in telemetry, which is then added in testpmd [1]. While looking
> >> at the forward engines code, I saw way too much duplicated code.
> >>
> >> Warning: this is only compile tested.
> >>
> >> 1:
> >> https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/
> >
> > Hi David,
> >
> > The code looks good to me. I have made some basic testing, it seems not
> > to break obvious things.
> >
> > Reviewed-by: Robin Jarry <rjarry@redhat.com>
> >
>
> Hi Robin,
>
> This set conflicts with your set which is merged [1], I guess your test
> was before your patch merged. Can you please check again after rebase?
>

The rebase (that I will send later) needs some eyes indeed.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 6/6] app/testpmd: factorize fwd engine Tx
  2023-02-14 18:16   ` Ferruh Yigit
@ 2023-02-20 16:33     ` David Marchand
  0 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:33 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Aman Singh, Yuying Zhang, Robin Jarry

On Tue, Feb 14, 2023 at 7:16 PM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 1/24/2023 10:47 AM, David Marchand wrote:
> > Reduce code duplication by introducing a helper that takes care of
> > transmitting, retrying if enabled and incrementing tx counter.
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
>
> <...>
>
> > diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
> > index 937d5a1d7d..3875590132 100644
> > --- a/app/test-pmd/noisy_vnf.c
> > +++ b/app/test-pmd/noisy_vnf.c
> > @@ -93,30 +93,6 @@ sim_memory_lookups(struct noisy_config *ncf, uint16_t nb_pkts)
> >       }
> >  }
> >
> > -static uint16_t
> > -do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
> > -      struct fwd_stream *fs)
> > -{
> > -     uint32_t retry = 0;
> > -
> > -     while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
> > -             rte_delay_us(burst_tx_delay_time);
> > -             nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> > -                             &pkts[nb_tx], nb_rx - nb_tx);
> > -     }
> > -
> > -     return nb_tx;
> > -}
> > -
> > -static uint32_t
> > -drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
> > -{
> > -     if (nb_tx < nb_rx)
> > -             rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
> > -
> > -     return nb_rx - nb_tx;
> > -}
> > -
> >  /*
> >   * Forwarding of packets in noisy VNF mode.  Forward packets but perform
> >   * memory operations first as specified on cmdline.
> > @@ -156,38 +132,23 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
> >
> >       if (!ncf->do_buffering) {
> >               sim_memory_lookups(ncf, nb_rx);
> > -             nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> > -                             pkts_burst, nb_rx);
> > -             if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
> > -                     nb_tx += do_retry(nb_rx, nb_tx, pkts_burst, fs);
> > -             inc_tx_burst_stats(fs, nb_tx);
> > -             fs->tx_packets += nb_tx;
> > -             fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
> > +             nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
> >
>
> 'nb_tx' is not used or necessary in this context, so assignment is not
> necassary.
>
> PS:
> In the latest next-net head, there is a 'goto' here instead of return,
> but that is becuase of recording cycles, becuase of optimization in this
> set (patch 1/6) that needs to turn back to 'return' that is what I did
> while applying patch.

This part changed a bit after rebasing and I think nb_tx is still
needed in this context.
Please have a look at v2.


>
> >               kreturn true;
> >       }
> >
> >       fifo_free = rte_ring_free_count(ncf->f);
> >       if (fifo_free >= nb_rx) {
> > -             nb_enqd = rte_ring_enqueue_burst(ncf->f,
> > -                             (void **) pkts_burst, nb_rx, NULL);
> > -             if (nb_enqd < nb_rx)
> > -                     fs->fwd_dropped += drop_pkts(pkts_burst,
> > -                                                  nb_rx, nb_enqd);
> > -     } else {
> > -             nb_deqd = rte_ring_dequeue_burst(ncf->f,
> > -                             (void **) tmp_pkts, nb_rx, NULL);
> > -             nb_enqd = rte_ring_enqueue_burst(ncf->f,
> > -                             (void **) pkts_burst, nb_deqd, NULL);
> > -             if (nb_deqd > 0) {
> > -                     nb_tx = rte_eth_tx_burst(fs->tx_port,
> > -                                     fs->tx_queue, tmp_pkts,
> > -                                     nb_deqd);
> > -                     if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
> > -                             nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
> > -                     inc_tx_burst_stats(fs, nb_tx);
> > -                     fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, nb_tx);
> > +             nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_rx, NULL);
> > +             if (nb_enqd < nb_rx) {
> > +                     fs->fwd_dropped += nb_rx - nb_enqd;
> > +                     rte_pktmbuf_free_bulk(&pkts_burst[nb_enqd], nb_rx - nb_enqd);
>
> Why not keep 'drop_pkts()' for this block, it is easier to read with it.

That would be the only case where drop_pkts() is used.
I am not convinced about readability but if you feel strongly about
it, I don't mind restoring it (in a v3, I'll post v2 unchanged on this
matter).


>
> >               }
> > +     } else {
> > +             nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **) tmp_pkts, nb_rx, NULL);
> > +             nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_deqd, NULL);
> > +             if (nb_deqd > 0)
> > +                     nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
>
> 'nb_tx' assignment looks wrong,
> function returns 'nb_dropped' not 'nb_tx'. 'nb_tx' used below to detect
> if flush needed ('needs_flush'), so 'needs_flush' may be set wrong
> becuase dropped packet is used instead number of Tx packets.

Indeed, this is wrong, I had caught the issue when preparing v2 after
rebasing over Robin series.
I had changed common_fwd_stream_transmit() so it returns the number of
transmitted packets which is more in line with rte_eth_tx_burst().
This is easier to understand too.


>
> >       }
> >
> >       sim_memory_lookups(ncf, nb_enqd);
> > @@ -204,15 +165,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
> >       needs_flush = delta_ms >= noisy_tx_sw_buf_flush_time &&
> >                       noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
> >       while (needs_flush && !rte_ring_empty(ncf->f)) {
> > -             unsigned int sent;
> >               nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
> >                               MAX_PKT_BURST, NULL);
> > -             sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> > -                                      tmp_pkts, nb_deqd);
> > -             if (unlikely(sent < nb_deqd) && fs->retry_enabled)
> > -                     nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
> > -             inc_tx_burst_stats(fs, nb_tx);
> > -             fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
> > +             nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
>
> similaryly 'nb_tx' assignment can be wrong here, and 'nb_tx' used for
> return value to hint if record cycle is required, using number of
> dropped packets (what 'common_fwd_stream_transmit()' returns) gives
> wrong result.

Yes, and there are other issues in this part which I moved to a
separate patch for v2.


>
> >               ncf->prev_time = rte_get_timer_cycles();
> >       }
> >
> > diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
> > index e6b28b4748..71ff70f55b 100644
> > --- a/app/test-pmd/testpmd.h
> > +++ b/app/test-pmd/testpmd.h
> > @@ -870,6 +870,36 @@ common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
> >       return nb_rx;
> >  }
> >
> > +/* Returns count of dropped packets. */
> > +static inline uint16_t
> > +common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
> > +     unsigned int count)
>
> I would use 'nb_pkts' instead of 'count' as variable name since it is
> more common, but of course this is subjective.

Ok for me.
I did the same renaming for the rx helper.


>
> > +{
> > +     uint16_t nb_tx;
> > +     uint32_t retry;
> > +
> > +     nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, count);
> > +     /*
> > +      * Retry if necessary
> > +      */
> > +     if (unlikely(nb_tx < count) && fs->retry_enabled) {
> > +             retry = 0;
> > +             while (nb_tx < count && retry++ < burst_tx_retry_num) {
> > +                     rte_delay_us(burst_tx_delay_time);
> > +                     nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
> > +                             &burst[nb_tx], count - nb_tx);
> > +             }
> > +     }
> > +     fs->tx_packets += nb_tx;
> > +     inc_tx_burst_stats(fs, nb_tx);
> > +     if (unlikely(nb_tx < count)) {
> > +             fs->fwd_dropped += (count - nb_tx);
> > +             rte_pktmbuf_free_bulk(&burst[nb_tx], count - nb_tx);
> > +     }
> > +
> > +     return count - nb_tx;
>
> Instead of returning number of dropped packets, what about returning
> number of packets sent ('nb_tx')?
> Intuitively this is what expected from a function named
> 'common_fwd_stream_transmit()', and even if it is more optimised to
> return number of dropped packet, this may have only a little impact on
> the caller code.

Ah ah, well, I thought the same after rebasing v1.

This change is in v2.


>
>
> And even 'fs->tx_packets' updated withing the function, updating it
> externally and explicitly feels me as it clarifies usage more, although
> this part is up to you, I mean usage like:
> fs->tx_packets += common_fwd_stream_transmit(fs, pkts, nb_pkts);

We would have fs->tx_packets managed by fwd engine code, but
fwd_dropped by the common helper?
I prefer fwd engines do not have to deal with the stats at all.
We have a lot of fwd engines, and small issues are often
(re-)introduced with new fwd engines.
A centralised approach is more robust.


Thanks Ferruh.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 0/9] Testpmd code cleanup
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
                   ` (6 preceding siblings ...)
  2023-01-25 13:50 ` [PATCH 0/6] Testpmd code cleanup Robin Jarry
@ 2023-02-20 16:40 ` David Marchand
  2023-02-20 16:40   ` [PATCH v2 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
                     ` (8 more replies)
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
  8 siblings, 9 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:40 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Here is a series to reduce code duplication in testpmd.

This work started from looking at Robin series on reporting lcore busy
cycles in telemetry, which is then added in testpmd [1].
While looking at the forward engines code, I saw way too much
duplicated code.

Warning: this is only compile tested.

1: https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/

-- 
David Marchand

---
Changes since v1:
- rebased now that Robin series was merged,
- reordered patches (putting fixes first in the series),
- fixed more issues in separate patches for ieee1588 and noisy VNF
  fwd engines,
- removed unneeded helpers for cycles counting,

---

David Marchand (9):
  app/testpmd: fix Tx preparation in checksum engine
  app/testpmd: fix packet count in ieee15888 engine
  app/testpmd: rework ieee1588 engine fwd configuration
  app/testpmd: fix packet transmission in noisy VNF engine
  app/testpmd: bulk free mbufs
  app/testpmd: factorize core cycles record
  app/testpmd: factorize fwd engine init
  app/testpmd: factorize fwd engine Rx
  app/testpmd: factorize fwd engine Tx

 app/test-pmd/5tswap.c         | 54 +++----------------
 app/test-pmd/csumonly.c       | 61 ++++------------------
 app/test-pmd/flowgen.c        | 53 +++----------------
 app/test-pmd/icmpecho.c       | 60 +++-------------------
 app/test-pmd/ieee1588fwd.c    | 39 ++++++--------
 app/test-pmd/iofwd.c          | 54 +++----------------
 app/test-pmd/macfwd.c         | 53 +++----------------
 app/test-pmd/macswap.c        | 58 +++------------------
 app/test-pmd/noisy_vnf.c      | 97 ++++++-----------------------------
 app/test-pmd/rxonly.c         | 20 ++------
 app/test-pmd/shared_rxq_fwd.c | 18 +++----
 app/test-pmd/testpmd.c        | 33 +++++++++---
 app/test-pmd/testpmd.h        | 53 ++++++++++++-------
 app/test-pmd/txonly.c         | 31 ++---------
 14 files changed, 154 insertions(+), 530 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 1/9] app/testpmd: fix Tx preparation in checksum engine
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
@ 2023-02-20 16:40   ` David Marchand
  2023-02-20 16:40   ` [PATCH v2 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:40 UTC (permalink / raw)
  To: dev
  Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable,
	Tomasz Kulasek, Konstantin Ananyev

"unprepared" packets could get to the wire in the retry loop.

Split packets freeing in two stages: one for preparation failure, and
one for transmission failure.
Adjust dropped counter update accordingly.

Fixes: 6b520d54ebfe ("app/testpmd: use Tx preparation in checksum engine")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
 app/test-pmd/csumonly.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 1c24598515..90a59e0aa5 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1168,10 +1168,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
 	nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
 			tx_pkts_burst, nb_rx);
-	if (nb_prep != nb_rx)
+	if (nb_prep != nb_rx) {
 		fprintf(stderr,
 			"Preparing packet burst to transmit failed: %s\n",
 			rte_strerror(rte_errno));
+		fs->fwd_dropped += (nb_rx - nb_prep);
+		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
+	}
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
 			nb_prep);
@@ -1179,12 +1182,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	/*
 	 * Retry if necessary
 	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
+	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
 		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
+		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
 			rte_delay_us(burst_tx_delay_time);
 			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&tx_pkts_burst[nb_tx], nb_rx - nb_tx);
+					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 		}
 	}
 	fs->tx_packets += nb_tx;
@@ -1194,11 +1197,11 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
 	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
+	if (unlikely(nb_tx < nb_prep)) {
+		fs->fwd_dropped += (nb_prep - nb_tx);
 		do {
 			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		} while (++nb_tx < nb_prep);
 	}
 
 	get_end_cycles(fs, start_tsc);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 2/9] app/testpmd: fix packet count in ieee15888 engine
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
  2023-02-20 16:40   ` [PATCH v2 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
@ 2023-02-20 16:40   ` David Marchand
  2023-02-20 16:40   ` [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:40 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable

Don't count a packet has been transmitted before it is done.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/ieee1588fwd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index fc4e2d014c..896d5ef26a 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -184,13 +184,13 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 
 	/* Forward PTP packet with hardware TX timestamp */
 	mb->ol_flags |= RTE_MBUF_F_TX_IEEE1588_TMST;
-	fs->tx_packets += 1;
 	if (rte_eth_tx_burst(fs->rx_port, fs->tx_queue, &mb, 1) == 0) {
 		printf("Port %u sent PTP packet dropped\n", fs->rx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
 		return;
 	}
+	fs->tx_packets += 1;
 
 	/*
 	 * Check the TX timestamp.
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
  2023-02-20 16:40   ` [PATCH v2 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
  2023-02-20 16:40   ` [PATCH v2 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
@ 2023-02-20 16:40   ` David Marchand
  2023-02-24  9:11     ` Singh, Aman Deep
  2023-02-20 16:40   ` [PATCH v2 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
                     ` (5 subsequent siblings)
  8 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:40 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

This fwd engine currently ignores the forwarding configuration.
Force it explicitly when initialising the stream.
The code is then more consistent with other fwd engines (i.e. receiving
on fs->rx_port, transmitting on fs->tx_port).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/ieee1588fwd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 896d5ef26a..242d272948 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -184,8 +184,8 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 
 	/* Forward PTP packet with hardware TX timestamp */
 	mb->ol_flags |= RTE_MBUF_F_TX_IEEE1588_TMST;
-	if (rte_eth_tx_burst(fs->rx_port, fs->tx_queue, &mb, 1) == 0) {
-		printf("Port %u sent PTP packet dropped\n", fs->rx_port);
+	if (rte_eth_tx_burst(fs->tx_port, fs->tx_queue, &mb, 1) == 0) {
+		printf("Port %u sent PTP packet dropped\n", fs->tx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
 		return;
@@ -195,7 +195,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	/*
 	 * Check the TX timestamp.
 	 */
-	port_ieee1588_tx_timestamp_check(fs->rx_port);
+	port_ieee1588_tx_timestamp_check(fs->tx_port);
 }
 
 static int
@@ -216,6 +216,9 @@ port_ieee1588_stream_init(struct fwd_stream *fs)
 {
 	bool rx_stopped, tx_stopped;
 
+	/* Force transmission on reception port */
+	fs->tx_port = fs->rx_port;
+
 	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
 						RTE_ETH_QUEUE_STATE_STOPPED;
 	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 4/9] app/testpmd: fix packet transmission in noisy VNF engine
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
                     ` (2 preceding siblings ...)
  2023-02-20 16:40   ` [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
@ 2023-02-20 16:40   ` David Marchand
  2023-02-20 16:40   ` [PATCH v2 5/9] app/testpmd: bulk free mbufs David Marchand
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:40 UTC (permalink / raw)
  To: dev
  Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable,
	Jens Freimann, Kevin Traynor, Bernard Iremonger

nb_rx relates to the number of packets received from the driver.
nb_tx is the total number of packets transmitted by this forward engine.

Fix the retry stage, for dequeued packets, as it was incorrectly
passing nb_rx / nb_tx as bounds of the tmp_pkts[] array, and fix tx stats
accordingly.

Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/noisy_vnf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index ce5a3e5e69..0e72dc034f 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -217,9 +217,10 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
 					 tmp_pkts, nb_deqd);
 		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
-			nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
-		inc_tx_burst_stats(fs, nb_tx);
+			sent += do_retry(nb_deqd, sent, tmp_pkts, fs);
+		inc_tx_burst_stats(fs, sent);
 		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
+		nb_tx += sent;
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 end:
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 5/9] app/testpmd: bulk free mbufs
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
                     ` (3 preceding siblings ...)
  2023-02-20 16:40   ` [PATCH v2 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
@ 2023-02-20 16:40   ` David Marchand
  2023-02-20 16:41   ` [PATCH v2 6/9] app/testpmd: factorize core cycles record David Marchand
                     ` (3 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:40 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Use the bulk free helper.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
 app/test-pmd/5tswap.c         | 4 +---
 app/test-pmd/csumonly.c       | 4 +---
 app/test-pmd/flowgen.c        | 8 ++------
 app/test-pmd/icmpecho.c       | 4 +---
 app/test-pmd/iofwd.c          | 4 +---
 app/test-pmd/macfwd.c         | 4 +---
 app/test-pmd/macswap.c        | 4 +---
 app/test-pmd/noisy_vnf.c      | 7 ++-----
 app/test-pmd/rxonly.c         | 4 +---
 app/test-pmd/shared_rxq_fwd.c | 3 +--
 app/test-pmd/testpmd.c        | 4 +---
 app/test-pmd/txonly.c         | 4 +---
 12 files changed, 14 insertions(+), 40 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index f041a5e1d5..c45a811f59 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -178,9 +178,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 	get_end_cycles(fs, start_tsc);
 }
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 90a59e0aa5..0b2d4c0593 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1199,9 +1199,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_prep)) {
 		fs->fwd_dropped += (nb_prep - nb_tx);
-		do {
-			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_prep);
+		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index fd6abc0f41..bc3d684496 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -75,7 +75,6 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
-	uint16_t i;
 	uint32_t retry;
 	uint64_t tx_offloads;
 	uint64_t start_tsc = 0;
@@ -89,8 +88,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	inc_rx_burst_stats(fs, nb_rx);
 	fs->rx_packets += nb_rx;
 
-	for (i = 0; i < nb_rx; i++)
-		rte_pktmbuf_free(pkts_burst[i]);
+	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	mbp = current_fwd_lcore()->mbp;
 	vlan_tci = ports[fs->tx_port].tx_vlan_id;
@@ -189,9 +187,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			next_flow += nb_flows_flowgen;
 
 		fs->fwd_dropped += nb_dropped;
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_pkt);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 066f2a3ab7..5a779fca3c 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -503,9 +503,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		inc_tx_burst_stats(fs, nb_tx);
 		if (unlikely(nb_tx < nb_replies)) {
 			fs->fwd_dropped += (nb_replies - nb_tx);
-			do {
-				rte_pktmbuf_free(pkts_burst[nb_tx]);
-			} while (++nb_tx < nb_replies);
+			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
 		}
 	}
 
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 8fafdec548..2bcdf15728 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -79,9 +79,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index beb220fbb4..ba08b8f323 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -110,9 +110,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 4f8deb3382..9f0933bbff 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -89,9 +89,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 	get_end_cycles(fs, start_tsc);
 }
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 0e72dc034f..055a80a62c 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -111,11 +111,8 @@ do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
 static uint32_t
 drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
 {
-	if (nb_tx < nb_rx) {
-		do {
-			rte_pktmbuf_free(pkts[nb_tx]);
-		} while (++nb_tx < nb_rx);
-	}
+	if (nb_tx < nb_rx)
+		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
 
 	return nb_rx - nb_tx;
 }
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index d528d4f34e..8fa5e95ad4 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -46,7 +46,6 @@ pkt_burst_receive(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint16_t i;
 	uint64_t start_tsc = 0;
 
 	get_start_cycles(&start_tsc);
@@ -61,8 +60,7 @@ pkt_burst_receive(struct fwd_stream *fs)
 		return;
 
 	fs->rx_packets += nb_rx;
-	for (i = 0; i < nb_rx; i++)
-		rte_pktmbuf_free(pkts_burst[i]);
+	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	get_end_cycles(fs, start_tsc);
 }
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 2e9047804b..05f90185df 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -53,8 +53,7 @@ forward_sub_burst(struct fwd_stream *src_fs, uint16_t port, uint16_t nb_rx,
 	} else {
 		/* Source stream not found, drop all packets. */
 		src_fs->fwd_dropped += nb_rx;
-		while (nb_rx > 0)
-			rte_pktmbuf_free(pkts[--nb_rx]);
+		rte_pktmbuf_free_bulk(pkts, nb_rx);
 	}
 }
 
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 0c14325b8d..964cd0ce2b 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2204,7 +2204,6 @@ flush_fwd_rx_queues(void)
 	portid_t port_id;
 	queueid_t rxq;
 	uint16_t  nb_rx;
-	uint16_t  i;
 	uint8_t   j;
 	uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
 	uint64_t timer_period;
@@ -2237,8 +2236,7 @@ flush_fwd_rx_queues(void)
 				do {
 					nb_rx = rte_eth_rx_burst(port_id, rxq,
 						pkts_burst, MAX_PKT_BURST);
-					for (i = 0; i < nb_rx; i++)
-						rte_pktmbuf_free(pkts_burst[i]);
+					rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 					cur_tsc = rte_rdtsc();
 					diff_tsc = cur_tsc - prev_tsc;
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 021624952d..076cdb86d5 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -421,9 +421,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 			       (unsigned) nb_pkt, (unsigned) nb_tx,
 			       (unsigned) (nb_pkt - nb_tx));
 		fs->fwd_dropped += (nb_pkt - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_pkt);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 6/9] app/testpmd: factorize core cycles record
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
                     ` (4 preceding siblings ...)
  2023-02-20 16:40   ` [PATCH v2 5/9] app/testpmd: bulk free mbufs David Marchand
@ 2023-02-20 16:41   ` David Marchand
  2023-02-20 16:41   ` [PATCH v2 7/9] app/testpmd: factorize fwd engine init David Marchand
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:41 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Rather than have each forward engines deal with core cycles recording,
move this to testpmd common code.
fwd engines just need to report that they did some busy work.

By doing this, get_*_cycles() helpers are unneeded and removed.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v1:
- removed (now unneeded) get_*_cycles() helpers,
- removed unrelated changes on noisy_vnf change,

---
 app/test-pmd/5tswap.c         | 11 ++++-------
 app/test-pmd/csumonly.c       | 10 +++-------
 app/test-pmd/flowgen.c        |  7 ++-----
 app/test-pmd/icmpecho.c       |  9 +++------
 app/test-pmd/ieee1588fwd.c    | 17 +++++++++--------
 app/test-pmd/iofwd.c          |  9 +++------
 app/test-pmd/macfwd.c         |  9 +++------
 app/test-pmd/macswap.c        | 10 ++++------
 app/test-pmd/noisy_vnf.c      |  8 ++------
 app/test-pmd/rxonly.c         |  9 +++------
 app/test-pmd/shared_rxq_fwd.c |  9 ++++-----
 app/test-pmd/testpmd.c        | 19 ++++++++++++++-----
 app/test-pmd/testpmd.h        | 16 +---------------
 app/test-pmd/txonly.c         |  9 +++------
 14 files changed, 58 insertions(+), 94 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index c45a811f59..0a3a897e7b 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -81,7 +81,7 @@ swap_udp(struct rte_udp_hdr *udp_hdr)
  * 2,3,4. Swaps source and destination for MAC, IPv4/IPv6, UDP/TCP.
  * Parses each layer and swaps it. When the next layer doesn't match it stops.
  */
-static void
+static bool
 pkt_burst_5tuple_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -105,10 +105,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		uint8_t *byte;
 	} h;
 
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
-
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -116,7 +112,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -180,7 +176,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		fs->fwd_dropped += (nb_rx - nb_tx);
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 0b2d4c0593..07850501f4 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -828,7 +828,7 @@ pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t nb_pkts, uint64
  * IP, UDP, TCP and SCTP flags always concern the inner layer. The
  * OUTER_IP is only useful for tunnel packets.
  */
-static void
+static bool
 pkt_burst_checksum_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -859,16 +859,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint32_t rx_bad_outer_ip_csum;
 	struct testpmd_offload_info info;
 
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
-
 	/* receive a burst of packet */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	rx_bad_ip_csum = 0;
@@ -1202,7 +1198,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index bc3d684496..b3bd4f7c65 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -58,7 +58,7 @@ RTE_DEFINE_PER_LCORE(int, _next_flow);
  * terminate receive traffic.  Received traffic is simply discarded, but we
  * still do so in order to maintain traffic statistics.
  */
-static void
+static bool
 pkt_burst_flow_gen(struct fwd_stream *fs)
 {
 	unsigned pkt_size = tx_pkt_length - 4;	/* Adjust FCS */
@@ -77,11 +77,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
 	uint32_t retry;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
-	get_start_cycles(&start_tsc);
-
 	/* Receive a burst of packets and discard them. */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
@@ -192,7 +189,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static int
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 5a779fca3c..5ef1116141 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -269,7 +269,7 @@ ipv4_hdr_cksum(struct rte_ipv4_hdr *ip_h)
  * Receive a burst of packets, lookup for ICMP echo requests, and, if any,
  * send back ICMP echo replies.
  */
-static void
+static bool
 reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -292,9 +292,6 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	uint32_t cksum;
 	uint8_t  i;
 	int l2_len;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * First, receive a burst of packets.
@@ -303,7 +300,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	nb_replies = 0;
@@ -507,7 +504,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		}
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 242d272948..103c01fcb7 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -89,7 +89,7 @@ port_ieee1588_tx_timestamp_check(portid_t pi)
 	       (wait_us == 1) ? "" : "s");
 }
 
-static void
+static bool
 ieee1588_packet_fwd(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *mb;
@@ -103,7 +103,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	 * Receive 1 packet at a time.
 	 */
 	if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0)
-		return;
+		return false;
 
 	fs->rx_packets += 1;
 
@@ -126,14 +126,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 			       (unsigned) mb->pkt_len);
 		}
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	if (eth_type != RTE_ETHER_TYPE_1588) {
 		printf("Port %u Received NON PTP packet incorrectly"
 		       " detected by hardware\n",
 		       fs->rx_port);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/*
@@ -147,14 +147,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		       " protocol version 0x%x (should be 0x02)\n",
 		       fs->rx_port, ptp_hdr->version);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	if (ptp_hdr->msg_id != PTP_SYNC_MESSAGE) {
 		printf("Port %u Received PTP V2 Ethernet frame with unexpected"
 		       " message ID 0x%x (expected 0x0 - PTP_SYNC_MESSAGE)\n",
 		       fs->rx_port, ptp_hdr->msg_id);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	printf("Port %u IEEE1588 PTP V2 SYNC Message filtered by hardware\n",
 	       fs->rx_port);
@@ -168,7 +168,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		       " by hardware\n",
 		       fs->rx_port);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/* For i40e we need the timesync register index. It is ignored for the
@@ -188,7 +188,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		printf("Port %u sent PTP packet dropped\n", fs->tx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	fs->tx_packets += 1;
 
@@ -196,6 +196,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	 * Check the TX timestamp.
 	 */
 	port_ieee1588_tx_timestamp_check(fs->tx_port);
+	return true;
 }
 
 static int
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 2bcdf15728..9d0af5f667 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -41,16 +41,13 @@
  * This is the fastest possible forwarding operation, as it does not access
  * to packets data.
  */
-static void
+static bool
 pkt_burst_io_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -59,7 +56,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 			pkts_burst, nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 	fs->rx_packets += nb_rx;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
@@ -82,7 +79,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index ba08b8f323..3a840247c7 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -41,7 +41,7 @@
  * Change the source and the destination Ethernet addressed of packets
  * before forwarding them.
  */
-static void
+static bool
 pkt_burst_mac_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -54,9 +54,6 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -65,7 +62,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -113,7 +110,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 9f0933bbff..14b3eefffd 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -47,7 +47,7 @@
  * MAC swap forwarding mode: Swap the source and the destination Ethernet
  * addresses of packets before forwarding them.
  */
-static void
+static bool
 pkt_burst_mac_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -55,9 +55,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -66,7 +63,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -91,7 +88,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		fs->fwd_dropped += (nb_rx - nb_tx);
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 055a80a62c..396fdd7814 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -134,14 +134,13 @@ drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
  *    out of the FIFO
  * 4. Cases 2 and 3 combined
  */
-static void
+static bool
 pkt_burst_noisy_vnf(struct fwd_stream *fs)
 {
 	const uint64_t freq_khz = rte_get_timer_hz() / 1000;
 	struct noisy_config *ncf = noisy_cfg[fs->rx_port];
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	struct rte_mbuf *tmp_pkts[MAX_PKT_BURST];
-	uint64_t start_tsc = 0;
 	uint16_t nb_deqd = 0;
 	uint16_t nb_rx = 0;
 	uint16_t nb_tx = 0;
@@ -151,8 +150,6 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	bool needs_flush = false;
 	uint64_t now;
 
-	get_start_cycles(&start_tsc);
-
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
 			pkts_burst, nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
@@ -221,8 +218,7 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 end:
-	if (nb_rx > 0 || nb_tx > 0)
-		get_end_cycles(fs, start_tsc);
+	return nb_rx > 0 || nb_tx > 0;
 }
 
 #define NOISY_STRSIZE 256
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index 8fa5e95ad4..ad4597cf9a 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -41,14 +41,11 @@
 /*
  * Received a burst of packets.
  */
-static void
+static bool
 pkt_burst_receive(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets.
@@ -57,12 +54,12 @@ pkt_burst_receive(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 05f90185df..4902ec407e 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -89,21 +89,20 @@ forward_shared_rxq(struct fwd_stream *fs, uint16_t nb_rx,
 			  &pkts_burst[nb_rx - nb_sub_burst]);
 }
 
-static void
+static bool
 shared_rxq_fwd(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
 	uint16_t nb_rx;
-	uint64_t start_tsc = 0;
 
-	get_start_cycles(&start_tsc);
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 	forward_shared_rxq(fs, nb_rx, pkts_burst);
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 964cd0ce2b..cf2215d390 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2253,7 +2253,6 @@ flush_fwd_rx_queues(void)
 static void
 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 {
-	struct fwd_stream **fsm;
 	uint64_t prev_tsc;
 	streamid_t nb_fs;
 	streamid_t sm_id;
@@ -2267,13 +2266,23 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 	tics_datum = rte_rdtsc();
 	tics_per_1sec = rte_get_timer_hz();
 #endif
-	fsm = &fwd_streams[fc->stream_idx];
 	nb_fs = fc->stream_nb;
 	prev_tsc = rte_rdtsc();
 	do {
-		for (sm_id = 0; sm_id < nb_fs; sm_id++)
-			if (!fsm[sm_id]->disabled)
-				(*pkt_fwd)(fsm[sm_id]);
+		for (sm_id = 0; sm_id < nb_fs; sm_id++) {
+			uint64_t start_fs_tsc = 0;
+			struct fwd_stream *fs;
+			bool busy;
+
+			fs = &fwd_streams[fc->stream_idx][sm_id];
+			if (fs->disabled)
+				continue;
+			if (record_core_cycles)
+				start_fs_tsc = rte_rdtsc();
+			busy = (*pkt_fwd)(fs);
+			if (record_core_cycles && busy)
+				fs->busy_cycles += rte_rdtsc() - start_fs_tsc;
+		}
 #ifdef RTE_LIB_BITRATESTATS
 		if (bitrate_enabled != 0 &&
 				bitrate_lcore_id == rte_lcore_id()) {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 329a6378a1..ce47d1ed92 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -382,7 +382,7 @@ struct fwd_lcore {
 typedef int (*port_fwd_begin_t)(portid_t pi);
 typedef void (*port_fwd_end_t)(portid_t pi);
 typedef void (*stream_init_t)(struct fwd_stream *fs);
-typedef void (*packet_fwd_t)(struct fwd_stream *fs);
+typedef bool (*packet_fwd_t)(struct fwd_stream *fs);
 
 struct fwd_engine {
 	const char       *fwd_mode_name; /**< Forwarding mode name. */
@@ -837,20 +837,6 @@ mbuf_pool_find(unsigned int sock_id, uint16_t idx)
 	return rte_mempool_lookup((const char *)pool_name);
 }
 
-static inline void
-get_start_cycles(uint64_t *start_tsc)
-{
-	if (record_core_cycles)
-		*start_tsc = rte_rdtsc();
-}
-
-static inline void
-get_end_cycles(struct fwd_stream *fs, uint64_t start_tsc)
-{
-	if (record_core_cycles)
-		fs->busy_cycles += rte_rdtsc() - start_tsc;
-}
-
 static inline void
 inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx)
 {
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 076cdb86d5..63ad5e69bf 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -323,7 +323,7 @@ pkt_burst_prepare(struct rte_mbuf *pkt, struct rte_mempool *mbp,
 /*
  * Transmit a burst of multi-segments packets.
  */
-static void
+static bool
 pkt_burst_transmit(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -337,9 +337,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	mbp = current_fwd_lcore()->mbp;
 	txp = &ports[fs->tx_port];
@@ -392,7 +389,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	}
 
 	if (nb_pkt == 0)
-		return;
+		return false;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
 
@@ -424,7 +421,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static int
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 7/9] app/testpmd: factorize fwd engine init
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
                     ` (5 preceding siblings ...)
  2023-02-20 16:41   ` [PATCH v2 6/9] app/testpmd: factorize core cycles record David Marchand
@ 2023-02-20 16:41   ` David Marchand
  2023-02-20 16:41   ` [PATCH v2 8/9] app/testpmd: factorize fwd engine Rx David Marchand
  2023-02-20 16:41   ` [PATCH v2 9/9] app/testpmd: factorize fwd engine Tx David Marchand
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:41 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
initialising the fs object.

While at it, remove unneeded initialisation of fwd_engine empty fields.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v1:
- updated ieee1588,

---
 app/test-pmd/5tswap.c         | 16 +---------------
 app/test-pmd/csumonly.c       | 16 +---------------
 app/test-pmd/flowgen.c        | 15 +--------------
 app/test-pmd/icmpecho.c       | 16 +---------------
 app/test-pmd/ieee1588fwd.c    |  8 +-------
 app/test-pmd/iofwd.c          | 16 +---------------
 app/test-pmd/macfwd.c         | 16 +---------------
 app/test-pmd/macswap.c        | 16 +---------------
 app/test-pmd/noisy_vnf.c      | 14 +-------------
 app/test-pmd/rxonly.c         |  2 --
 app/test-pmd/shared_rxq_fwd.c |  2 --
 app/test-pmd/testpmd.c        | 10 ++++++++++
 app/test-pmd/testpmd.h        |  2 ++
 app/test-pmd/txonly.c         |  1 -
 14 files changed, 21 insertions(+), 129 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 0a3a897e7b..7b5f58f4d4 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -180,22 +180,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_5tuple_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine five_tuple_swap_fwd_engine = {
 	.fwd_mode_name  = "5tswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_5tuple_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_5tuple_swap,
 };
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 07850501f4..f72e2d74c7 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1201,22 +1201,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_checksum_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine csum_fwd_engine = {
 	.fwd_mode_name  = "csum",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_checksum_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_checksum_forward,
 };
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index b3bd4f7c65..6f42019353 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -199,22 +199,9 @@ flowgen_begin(portid_t pi)
 	return 0;
 }
 
-static void
-flowgen_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine flow_gen_engine = {
 	.fwd_mode_name  = "flowgen",
 	.port_fwd_begin = flowgen_begin,
-	.port_fwd_end   = NULL,
-	.stream_init    = flowgen_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_flow_gen,
 };
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 5ef1116141..eba8b99f1e 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -507,22 +507,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-icmpecho_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine icmp_echo_engine = {
 	.fwd_mode_name  = "icmpecho",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = icmpecho_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = reply_to_icmp_echo_rqsts,
 };
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 103c01fcb7..fd8ba27b2f 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -215,16 +215,10 @@ port_ieee1588_fwd_end(portid_t pi)
 static void
 port_ieee1588_stream_init(struct fwd_stream *fs)
 {
-	bool rx_stopped, tx_stopped;
-
 	/* Force transmission on reception port */
 	fs->tx_port = fs->rx_port;
 
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
+	common_fwd_stream_init(fs);
 }
 
 struct fwd_engine ieee1588_fwd_engine = {
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 9d0af5f667..12be06fa79 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -82,22 +82,8 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine io_fwd_engine = {
 	.fwd_mode_name  = "io",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_io_forward,
 };
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 3a840247c7..953d9ea089 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -113,22 +113,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_fwd_engine = {
 	.fwd_mode_name  = "mac",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_forward,
 };
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 14b3eefffd..062542dc53 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -92,22 +92,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_swap_engine = {
 	.fwd_mode_name  = "macswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_swap,
 };
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 396fdd7814..7bcab84db3 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -278,22 +278,10 @@ noisy_fwd_begin(portid_t pi)
 	return 0;
 }
 
-static void
-stream_init_noisy_vnf(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine noisy_vnf_engine = {
 	.fwd_mode_name  = "noisy",
 	.port_fwd_begin = noisy_fwd_begin,
 	.port_fwd_end   = noisy_fwd_end,
-	.stream_init    = stream_init_noisy_vnf,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_noisy_vnf,
 };
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index ad4597cf9a..d4bff9b5ea 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -71,8 +71,6 @@ stream_init_receive(struct fwd_stream *fs)
 
 struct fwd_engine rx_only_engine = {
 	.fwd_mode_name  = "rxonly",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = stream_init_receive,
 	.packet_fwd     = pkt_burst_receive,
 };
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 4902ec407e..67e5494735 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -114,8 +114,6 @@ shared_rxq_stream_init(struct fwd_stream *fs)
 
 struct fwd_engine shared_rxq_engine = {
 	.fwd_mode_name  = "shared_rxq",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = shared_rxq_stream_init,
 	.packet_fwd     = shared_rxq_fwd,
 };
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index cf2215d390..99eea989ae 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2386,6 +2386,16 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
 	}
 }
 
+void
+common_fwd_stream_init(struct fwd_stream *fs)
+{
+	bool rx_stopped, tx_stopped;
+
+	rx_stopped = (ports[fs->rx_port].rxq[fs->rx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	tx_stopped = (ports[fs->tx_port].txq[fs->tx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	fs->disabled = rx_stopped || tx_stopped;
+}
+
 /*
  * Launch packet forwarding configuration.
  */
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce47d1ed92..4b28cd0d0d 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -392,6 +392,8 @@ struct fwd_engine {
 	packet_fwd_t     packet_fwd;     /**< Mandatory. */
 };
 
+void common_fwd_stream_init(struct fwd_stream *fs);
+
 #define FLEX_ITEM_MAX_SAMPLES_NUM 16
 #define FLEX_ITEM_MAX_LINKS_NUM 16
 #define FLEX_MAX_FLOW_PATTERN_LENGTH 64
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 63ad5e69bf..b80ab6f5df 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -508,7 +508,6 @@ tx_only_stream_init(struct fwd_stream *fs)
 struct fwd_engine tx_only_engine = {
 	.fwd_mode_name  = "txonly",
 	.port_fwd_begin = tx_only_begin,
-	.port_fwd_end   = NULL,
 	.stream_init    = tx_only_stream_init,
 	.packet_fwd     = pkt_burst_transmit,
 };
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 8/9] app/testpmd: factorize fwd engine Rx
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
                     ` (6 preceding siblings ...)
  2023-02-20 16:41   ` [PATCH v2 7/9] app/testpmd: factorize fwd engine init David Marchand
@ 2023-02-20 16:41   ` David Marchand
  2023-02-20 16:41   ` [PATCH v2 9/9] app/testpmd: factorize fwd engine Tx David Marchand
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:41 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
receiving packets and incrementing rx counter.
inc_rx_burst_stats() is then unneeded and removed.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v1:
- updated shared_rxq fwd engine,
- removed inc_rx_burst_stats helper,
- removed likely() around rx stats update,

---
 app/test-pmd/5tswap.c         |  5 +----
 app/test-pmd/csumonly.c       |  5 +----
 app/test-pmd/flowgen.c        |  5 +----
 app/test-pmd/icmpecho.c       |  5 +----
 app/test-pmd/ieee1588fwd.c    |  4 +---
 app/test-pmd/iofwd.c          |  5 +----
 app/test-pmd/macfwd.c         |  5 +----
 app/test-pmd/macswap.c        |  5 +----
 app/test-pmd/noisy_vnf.c      |  5 +----
 app/test-pmd/rxonly.c         |  5 +----
 app/test-pmd/shared_rxq_fwd.c |  4 +---
 app/test-pmd/testpmd.h        | 10 ++++++++--
 12 files changed, 19 insertions(+), 44 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 7b5f58f4d4..27da867d7f 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -108,13 +108,10 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 	ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads);
 	vlan_qinq_set(pkts_burst, nb_rx, ol_flags,
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index f72e2d74c7..d758ae0ac6 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -860,13 +860,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	struct testpmd_offload_info info;
 
 	/* receive a burst of packet */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	rx_bad_ip_csum = 0;
 	rx_bad_l4_csum = 0;
 	rx_bad_outer_l4_csum = 0;
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 6f42019353..3705cc60c5 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -80,10 +80,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
 	/* Receive a burst of packets and discard them. */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
-	fs->rx_packets += nb_rx;
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index eba8b99f1e..48f8fe0bf1 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -296,13 +296,10 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	/*
 	 * First, receive a burst of packets.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	nb_replies = 0;
 	for (i = 0; i < nb_rx; i++) {
 		if (likely(i < nb_rx - 1))
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index fd8ba27b2f..1d51ebfe9d 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -102,11 +102,9 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	/*
 	 * Receive 1 packet at a time.
 	 */
-	if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0)
+	if (common_fwd_stream_receive(fs, &mb, 1) == 0)
 		return false;
 
-	fs->rx_packets += 1;
-
 	/*
 	 * Check that the received packet is a PTP packet that was detected
 	 * by the hardware.
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 12be06fa79..69b583cb5b 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -52,12 +52,9 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
-			pkts_burst, nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
-	fs->rx_packets += nb_rx;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
 			pkts_burst, nb_rx);
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 953d9ea089..a72f5ccb75 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -58,13 +58,10 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 	tx_offloads = txp->dev_conf.txmode.offloads;
 	if (tx_offloads	& RTE_ETH_TX_OFFLOAD_VLAN_INSERT)
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 062542dc53..ab37123404 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -59,13 +59,10 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 
 	do_macswap(pkts_burst, nb_rx, txp);
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 7bcab84db3..e543adc865 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -150,12 +150,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	bool needs_flush = false;
 	uint64_t now;
 
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
-			pkts_burst, nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		goto flush;
-	fs->rx_packets += nb_rx;
 
 	if (!ncf->do_buffering) {
 		sim_memory_lookups(ncf, nb_rx);
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index d4bff9b5ea..315f9286cd 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -50,13 +50,10 @@ pkt_burst_receive(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	return true;
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 67e5494735..623d62da88 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -95,9 +95,7 @@ shared_rxq_fwd(struct fwd_stream *fs)
 	struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
 	uint16_t nb_rx;
 
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 	forward_shared_rxq(fs, nb_rx, pkts_burst);
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 4b28cd0d0d..6c82cbab45 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -839,11 +839,17 @@ mbuf_pool_find(unsigned int sock_id, uint16_t idx)
 	return rte_mempool_lookup((const char *)pool_name);
 }
 
-static inline void
-inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx)
+static inline uint16_t
+common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
+	unsigned int nb_pkts)
 {
+	uint16_t nb_rx;
+
+	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, nb_pkts);
 	if (record_burst_stats)
 		fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
+	fs->rx_packets += nb_rx;
+	return nb_rx;
 }
 
 static inline void
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v2 9/9] app/testpmd: factorize fwd engine Tx
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
                     ` (7 preceding siblings ...)
  2023-02-20 16:41   ` [PATCH v2 8/9] app/testpmd: factorize fwd engine Rx David Marchand
@ 2023-02-20 16:41   ` David Marchand
  8 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 16:41 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
transmitting, retrying if enabled and incrementing tx counter.
inc_tx_burst_stats() is then unneeded and removed.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v1:
- changed Tx helper so it matches rte_eth_tx_burst() semantic,
- updated ieee1588,
- removed inc_tx_burst_stats helper,

---
 app/test-pmd/5tswap.c      | 22 +-----------
 app/test-pmd/csumonly.c    | 23 +------------
 app/test-pmd/flowgen.c     | 20 +----------
 app/test-pmd/icmpecho.c    | 28 ++--------------
 app/test-pmd/ieee1588fwd.c |  5 +--
 app/test-pmd/iofwd.c       | 22 +-----------
 app/test-pmd/macfwd.c      | 21 +-----------
 app/test-pmd/macswap.c     | 27 ++-------------
 app/test-pmd/noisy_vnf.c   | 68 ++++++--------------------------------
 app/test-pmd/testpmd.h     | 27 +++++++++++++--
 app/test-pmd/txonly.c      | 19 +----------
 11 files changed, 47 insertions(+), 235 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 27da867d7f..ff8c2dcde5 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -91,9 +91,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	uint64_t ol_flags;
 	uint16_t proto;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
-
 	int i;
 	union {
 		struct rte_ether_hdr *eth;
@@ -155,24 +152,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		}
 		mbuf_field_set(mb, ol_flags);
 	}
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index d758ae0ac6..fc85c22a77 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -847,12 +847,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint8_t gro_enable;
 #endif
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_prep;
 	uint16_t i;
 	uint64_t rx_ol_flags, tx_ol_flags;
 	uint64_t tx_offloads;
-	uint32_t retry;
 	uint32_t rx_bad_ip_csum;
 	uint32_t rx_bad_l4_csum;
 	uint32_t rx_bad_outer_l4_csum;
@@ -1169,32 +1167,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
 	}
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
-			nb_prep);
+	common_fwd_stream_transmit(fs, tx_pkts_burst, nb_prep);
 
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
 	fs->rx_bad_ip_csum += rx_bad_ip_csum;
 	fs->rx_bad_l4_csum += rx_bad_l4_csum;
 	fs->rx_bad_outer_l4_csum += rx_bad_outer_l4_csum;
 	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_prep)) {
-		fs->fwd_dropped += (nb_prep - nb_tx);
-		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
-	}
-
 	return true;
 }
 
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 3705cc60c5..53b5f24f11 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -75,7 +75,6 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
-	uint32_t retry;
 	uint64_t tx_offloads;
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
@@ -158,30 +157,13 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			next_flow = 0;
 	}
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_pkt - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-
-	inc_tx_burst_stats(fs, nb_tx);
+	nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
 	nb_dropped = nb_pkt - nb_tx;
 	if (unlikely(nb_dropped > 0)) {
 		/* Back out the flow counter. */
 		next_flow -= nb_dropped;
 		while (next_flow < 0)
 			next_flow += nb_flows_flowgen;
-
-		fs->fwd_dropped += nb_dropped;
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 48f8fe0bf1..68524484e3 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -280,10 +280,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	struct rte_ipv4_hdr *ip_h;
 	struct rte_icmp_hdr *icmp_h;
 	struct rte_ether_addr eth_addr;
-	uint32_t retry;
 	uint32_t ip_addr;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_replies;
 	uint16_t eth_type;
 	uint16_t vlan_id;
@@ -476,30 +474,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	}
 
 	/* Send back ICMP echo replies, if any. */
-	if (nb_replies > 0) {
-		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
-					 nb_replies);
-		/*
-		 * Retry if necessary
-		 */
-		if (unlikely(nb_tx < nb_replies) && fs->retry_enabled) {
-			retry = 0;
-			while (nb_tx < nb_replies &&
-					retry++ < burst_tx_retry_num) {
-				rte_delay_us(burst_tx_delay_time);
-				nb_tx += rte_eth_tx_burst(fs->tx_port,
-						fs->tx_queue,
-						&pkts_burst[nb_tx],
-						nb_replies - nb_tx);
-			}
-		}
-		fs->tx_packets += nb_tx;
-		inc_tx_burst_stats(fs, nb_tx);
-		if (unlikely(nb_tx < nb_replies)) {
-			fs->fwd_dropped += (nb_replies - nb_tx);
-			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
-		}
-	}
+	if (nb_replies > 0)
+		common_fwd_stream_transmit(fs, pkts_burst, nb_replies);
 
 	return true;
 }
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 1d51ebfe9d..386d9f10e6 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -182,13 +182,10 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 
 	/* Forward PTP packet with hardware TX timestamp */
 	mb->ol_flags |= RTE_MBUF_F_TX_IEEE1588_TMST;
-	if (rte_eth_tx_burst(fs->tx_port, fs->tx_queue, &mb, 1) == 0) {
+	if (common_fwd_stream_transmit(fs, &mb, 1) == 0) {
 		printf("Port %u sent PTP packet dropped\n", fs->tx_port);
-		fs->fwd_dropped += 1;
-		rte_pktmbuf_free(mb);
 		return false;
 	}
-	fs->tx_packets += 1;
 
 	/*
 	 * Check the TX timestamp.
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 69b583cb5b..ba06fae4a6 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -46,8 +46,6 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -56,25 +54,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-			pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index a72f5ccb75..7316d73315 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -48,9 +48,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct rte_ether_hdr *eth_hdr;
-	uint32_t retry;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
@@ -87,25 +85,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 		mb->vlan_tci = txp->tx_vlan_id;
 		mb->vlan_tci_outer = txp->tx_vlan_id_outer;
 	}
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
 
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index ab37123404..57f77003fe 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -51,10 +51,7 @@ static bool
 pkt_burst_mac_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
-	struct rte_port  *txp;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -63,28 +60,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	txp = &ports[fs->tx_port];
-
-	do_macswap(pkts_burst, nb_rx, txp);
-
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	do_macswap(pkts_burst, nb_rx, &ports[fs->tx_port]);
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index e543adc865..2bf90a983c 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -93,30 +93,6 @@ sim_memory_lookups(struct noisy_config *ncf, uint16_t nb_pkts)
 	}
 }
 
-static uint16_t
-do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
-	 struct fwd_stream *fs)
-{
-	uint32_t retry = 0;
-
-	while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-		rte_delay_us(burst_tx_delay_time);
-		nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-				&pkts[nb_tx], nb_rx - nb_tx);
-	}
-
-	return nb_tx;
-}
-
-static uint32_t
-drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
-{
-	if (nb_tx < nb_rx)
-		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
-
-	return nb_rx - nb_tx;
-}
-
 /*
  * Forwarding of packets in noisy VNF mode.  Forward packets but perform
  * memory operations first as specified on cmdline.
@@ -156,37 +132,22 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 
 	if (!ncf->do_buffering) {
 		sim_memory_lookups(ncf, nb_rx);
-		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-				pkts_burst, nb_rx);
-		if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
-			nb_tx += do_retry(nb_rx, nb_tx, pkts_burst, fs);
-		inc_tx_burst_stats(fs, nb_tx);
-		fs->tx_packets += nb_tx;
-		fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
+		nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 		goto end;
 	}
 
 	fifo_free = rte_ring_free_count(ncf->f);
 	if (fifo_free >= nb_rx) {
-		nb_enqd = rte_ring_enqueue_burst(ncf->f,
-				(void **) pkts_burst, nb_rx, NULL);
-		if (nb_enqd < nb_rx)
-			fs->fwd_dropped += drop_pkts(pkts_burst,
-						     nb_rx, nb_enqd);
-	} else {
-		nb_deqd = rte_ring_dequeue_burst(ncf->f,
-				(void **) tmp_pkts, nb_rx, NULL);
-		nb_enqd = rte_ring_enqueue_burst(ncf->f,
-				(void **) pkts_burst, nb_deqd, NULL);
-		if (nb_deqd > 0) {
-			nb_tx = rte_eth_tx_burst(fs->tx_port,
-					fs->tx_queue, tmp_pkts,
-					nb_deqd);
-			if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
-				nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
-			inc_tx_burst_stats(fs, nb_tx);
-			fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, nb_tx);
+		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_rx, NULL);
+		if (nb_enqd < nb_rx) {
+			fs->fwd_dropped += nb_rx - nb_enqd;
+			rte_pktmbuf_free_bulk(&pkts_burst[nb_enqd], nb_rx - nb_enqd);
 		}
+	} else {
+		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **) tmp_pkts, nb_rx, NULL);
+		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_deqd, NULL);
+		if (nb_deqd > 0)
+			nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
 	}
 
 	sim_memory_lookups(ncf, nb_enqd);
@@ -202,16 +163,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 				noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
 	}
 	while (needs_flush && !rte_ring_empty(ncf->f)) {
-		unsigned int sent;
 		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
 				MAX_PKT_BURST, NULL);
-		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					 tmp_pkts, nb_deqd);
-		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
-			sent += do_retry(nb_deqd, sent, tmp_pkts, fs);
-		inc_tx_burst_stats(fs, sent);
-		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
-		nb_tx += sent;
+		nb_tx += common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 end:
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 6c82cbab45..b9215720b6 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -852,11 +852,34 @@ common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
 	return nb_rx;
 }
 
-static inline void
-inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
+static inline uint16_t
+common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
+	unsigned int nb_pkts)
 {
+	uint16_t nb_tx;
+	uint32_t retry;
+
+	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, nb_pkts);
+	/*
+	 * Retry if necessary
+	 */
+	if (unlikely(nb_tx < nb_pkts) && fs->retry_enabled) {
+		retry = 0;
+		while (nb_tx < nb_pkts && retry++ < burst_tx_retry_num) {
+			rte_delay_us(burst_tx_delay_time);
+			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
+				&burst[nb_tx], nb_pkts - nb_tx);
+		}
+	}
+	fs->tx_packets += nb_tx;
 	if (record_burst_stats)
 		fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
+	if (unlikely(nb_tx < nb_pkts)) {
+		fs->fwd_dropped += (nb_pkts - nb_tx);
+		rte_pktmbuf_free_bulk(&burst[nb_tx], nb_pkts - nb_tx);
+	}
+
+	return nb_tx;
 }
 
 /* Prototypes */
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index b80ab6f5df..b3d6873104 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -334,7 +334,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	uint16_t nb_tx;
 	uint16_t nb_pkt;
 	uint16_t vlan_tci, vlan_tci_outer;
-	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
 
@@ -391,25 +390,11 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	if (nb_pkt == 0)
 		return false;
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
-
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_pkt - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
+	nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
 
 	if (txonly_multi_flow)
 		RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
 
-	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_pkt)) {
 		if (verbose_level > 0 && fs->fwd_dropped == 0)
 			printf("port %d tx_queue %d - drop "
@@ -417,8 +402,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 			       fs->tx_port, fs->tx_queue,
 			       (unsigned) nb_pkt, (unsigned) nb_tx,
 			       (unsigned) (nb_pkt - nb_tx));
-		fs->fwd_dropped += (nb_pkt - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	return true;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 0/9] Testpmd code cleanup
  2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
                   ` (7 preceding siblings ...)
  2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
@ 2023-02-20 18:34 ` David Marchand
  2023-02-20 18:34   ` [PATCH v3 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
                     ` (9 more replies)
  8 siblings, 10 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Here is a series to reduce code duplication in testpmd.

This work started from looking at Robin series on reporting lcore busy
cycles in telemetry, which is then added in testpmd [1].
While looking at the forward engines code, I saw way too much
duplicated code.

Warning: this is only compile tested.

1: https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/

-- 
David Marchand

---
Changes since v2:
- fixed fwd_streams[] access in patch 6,

Changes since v1:
- rebased now that Robin series was merged,
- reordered patches (putting fixes first in the series),
- fixed more issues in separate patches for ieee1588 and noisy VNF
  fwd engines,
- removed unneeded helpers for cycles counting,

---

David Marchand (9):
  app/testpmd: fix Tx preparation in checksum engine
  app/testpmd: fix packet count in ieee15888 engine
  app/testpmd: rework ieee1588 engine fwd configuration
  app/testpmd: fix packet transmission in noisy VNF engine
  app/testpmd: bulk free mbufs
  app/testpmd: factorize core cycles record
  app/testpmd: factorize fwd engine init
  app/testpmd: factorize fwd engine Rx
  app/testpmd: factorize fwd engine Tx

 app/test-pmd/5tswap.c         | 54 +++----------------
 app/test-pmd/csumonly.c       | 61 ++++------------------
 app/test-pmd/flowgen.c        | 53 +++----------------
 app/test-pmd/icmpecho.c       | 60 +++-------------------
 app/test-pmd/ieee1588fwd.c    | 39 ++++++--------
 app/test-pmd/iofwd.c          | 54 +++----------------
 app/test-pmd/macfwd.c         | 53 +++----------------
 app/test-pmd/macswap.c        | 58 +++------------------
 app/test-pmd/noisy_vnf.c      | 97 ++++++-----------------------------
 app/test-pmd/rxonly.c         | 20 ++------
 app/test-pmd/shared_rxq_fwd.c | 18 +++----
 app/test-pmd/testpmd.c        | 30 ++++++++---
 app/test-pmd/testpmd.h        | 53 ++++++++++++-------
 app/test-pmd/txonly.c         | 31 ++---------
 14 files changed, 153 insertions(+), 528 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 1/9] app/testpmd: fix Tx preparation in checksum engine
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
@ 2023-02-20 18:34   ` David Marchand
  2023-02-20 18:34   ` [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev
  Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable,
	Tomasz Kulasek, Konstantin Ananyev

"unprepared" packets could get to the wire in the retry loop.

Split packets freeing in two stages: one for preparation failure, and
one for transmission failure.
Adjust dropped counter update accordingly.

Fixes: 6b520d54ebfe ("app/testpmd: use Tx preparation in checksum engine")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
 app/test-pmd/csumonly.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 1c24598515..90a59e0aa5 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1168,10 +1168,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
 	nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
 			tx_pkts_burst, nb_rx);
-	if (nb_prep != nb_rx)
+	if (nb_prep != nb_rx) {
 		fprintf(stderr,
 			"Preparing packet burst to transmit failed: %s\n",
 			rte_strerror(rte_errno));
+		fs->fwd_dropped += (nb_rx - nb_prep);
+		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
+	}
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
 			nb_prep);
@@ -1179,12 +1182,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	/*
 	 * Retry if necessary
 	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
+	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
 		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
+		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
 			rte_delay_us(burst_tx_delay_time);
 			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&tx_pkts_burst[nb_tx], nb_rx - nb_tx);
+					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 		}
 	}
 	fs->tx_packets += nb_tx;
@@ -1194,11 +1197,11 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
 	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
+	if (unlikely(nb_tx < nb_prep)) {
+		fs->fwd_dropped += (nb_prep - nb_tx);
 		do {
 			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		} while (++nb_tx < nb_prep);
 	}
 
 	get_end_cycles(fs, start_tsc);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
  2023-02-20 18:34   ` [PATCH v3 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
@ 2023-02-20 18:34   ` David Marchand
  2023-02-24  8:24     ` Singh, Aman Deep
  2023-02-20 18:34   ` [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
                     ` (7 subsequent siblings)
  9 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable

Don't count a packet has been transmitted before it is done.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/ieee1588fwd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index fc4e2d014c..896d5ef26a 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -184,13 +184,13 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 
 	/* Forward PTP packet with hardware TX timestamp */
 	mb->ol_flags |= RTE_MBUF_F_TX_IEEE1588_TMST;
-	fs->tx_packets += 1;
 	if (rte_eth_tx_burst(fs->rx_port, fs->tx_queue, &mb, 1) == 0) {
 		printf("Port %u sent PTP packet dropped\n", fs->rx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
 		return;
 	}
+	fs->tx_packets += 1;
 
 	/*
 	 * Check the TX timestamp.
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
  2023-02-20 18:34   ` [PATCH v3 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
  2023-02-20 18:34   ` [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
@ 2023-02-20 18:34   ` David Marchand
  2023-02-28 18:50     ` Ferruh Yigit
  2023-02-20 18:34   ` [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
                     ` (6 subsequent siblings)
  9 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

This fwd engine currently ignores the forwarding configuration.
Force it explicitly when initialising the stream.
The code is then more consistent with other fwd engines (i.e. receiving
on fs->rx_port, transmitting on fs->tx_port).

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/ieee1588fwd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 896d5ef26a..242d272948 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -184,8 +184,8 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 
 	/* Forward PTP packet with hardware TX timestamp */
 	mb->ol_flags |= RTE_MBUF_F_TX_IEEE1588_TMST;
-	if (rte_eth_tx_burst(fs->rx_port, fs->tx_queue, &mb, 1) == 0) {
-		printf("Port %u sent PTP packet dropped\n", fs->rx_port);
+	if (rte_eth_tx_burst(fs->tx_port, fs->tx_queue, &mb, 1) == 0) {
+		printf("Port %u sent PTP packet dropped\n", fs->tx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
 		return;
@@ -195,7 +195,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	/*
 	 * Check the TX timestamp.
 	 */
-	port_ieee1588_tx_timestamp_check(fs->rx_port);
+	port_ieee1588_tx_timestamp_check(fs->tx_port);
 }
 
 static int
@@ -216,6 +216,9 @@ port_ieee1588_stream_init(struct fwd_stream *fs)
 {
 	bool rx_stopped, tx_stopped;
 
+	/* Force transmission on reception port */
+	fs->tx_port = fs->rx_port;
+
 	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
 						RTE_ETH_QUEUE_STATE_STOPPED;
 	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (2 preceding siblings ...)
  2023-02-20 18:34   ` [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
@ 2023-02-20 18:34   ` David Marchand
  2023-02-28 18:51     ` Ferruh Yigit
  2023-02-20 18:34   ` [PATCH v3 5/9] app/testpmd: bulk free mbufs David Marchand
                     ` (5 subsequent siblings)
  9 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev
  Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry, stable,
	Kevin Traynor, Bernard Iremonger, Jens Freimann

nb_rx relates to the number of packets received from the driver.
nb_tx is the total number of packets transmitted by this forward engine.

Fix the retry stage, for dequeued packets, as it was incorrectly
passing nb_rx / nb_tx as bounds of the tmp_pkts[] array, and fix tx stats
accordingly.

Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/noisy_vnf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index ce5a3e5e69..0e72dc034f 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -217,9 +217,10 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
 					 tmp_pkts, nb_deqd);
 		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
-			nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
-		inc_tx_burst_stats(fs, nb_tx);
+			sent += do_retry(nb_deqd, sent, tmp_pkts, fs);
+		inc_tx_burst_stats(fs, sent);
 		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
+		nb_tx += sent;
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 end:
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 5/9] app/testpmd: bulk free mbufs
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (3 preceding siblings ...)
  2023-02-20 18:34   ` [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
@ 2023-02-20 18:34   ` David Marchand
  2023-02-20 18:45     ` Stephen Hemminger
  2023-02-20 18:34   ` [PATCH v3 6/9] app/testpmd: factorize core cycles record David Marchand
                     ` (4 subsequent siblings)
  9 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Use the bulk free helper.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
 app/test-pmd/5tswap.c         | 4 +---
 app/test-pmd/csumonly.c       | 4 +---
 app/test-pmd/flowgen.c        | 8 ++------
 app/test-pmd/icmpecho.c       | 4 +---
 app/test-pmd/iofwd.c          | 4 +---
 app/test-pmd/macfwd.c         | 4 +---
 app/test-pmd/macswap.c        | 4 +---
 app/test-pmd/noisy_vnf.c      | 7 ++-----
 app/test-pmd/rxonly.c         | 4 +---
 app/test-pmd/shared_rxq_fwd.c | 3 +--
 app/test-pmd/testpmd.c        | 4 +---
 app/test-pmd/txonly.c         | 4 +---
 12 files changed, 14 insertions(+), 40 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index f041a5e1d5..c45a811f59 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -178,9 +178,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 	get_end_cycles(fs, start_tsc);
 }
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 90a59e0aa5..0b2d4c0593 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1199,9 +1199,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_prep)) {
 		fs->fwd_dropped += (nb_prep - nb_tx);
-		do {
-			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_prep);
+		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index fd6abc0f41..bc3d684496 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -75,7 +75,6 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
-	uint16_t i;
 	uint32_t retry;
 	uint64_t tx_offloads;
 	uint64_t start_tsc = 0;
@@ -89,8 +88,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	inc_rx_burst_stats(fs, nb_rx);
 	fs->rx_packets += nb_rx;
 
-	for (i = 0; i < nb_rx; i++)
-		rte_pktmbuf_free(pkts_burst[i]);
+	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	mbp = current_fwd_lcore()->mbp;
 	vlan_tci = ports[fs->tx_port].tx_vlan_id;
@@ -189,9 +187,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			next_flow += nb_flows_flowgen;
 
 		fs->fwd_dropped += nb_dropped;
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_pkt);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 066f2a3ab7..5a779fca3c 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -503,9 +503,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		inc_tx_burst_stats(fs, nb_tx);
 		if (unlikely(nb_tx < nb_replies)) {
 			fs->fwd_dropped += (nb_replies - nb_tx);
-			do {
-				rte_pktmbuf_free(pkts_burst[nb_tx]);
-			} while (++nb_tx < nb_replies);
+			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
 		}
 	}
 
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 8fafdec548..2bcdf15728 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -79,9 +79,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index beb220fbb4..ba08b8f323 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -110,9 +110,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 4f8deb3382..9f0933bbff 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -89,9 +89,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_rx);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 	get_end_cycles(fs, start_tsc);
 }
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 0e72dc034f..055a80a62c 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -111,11 +111,8 @@ do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
 static uint32_t
 drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
 {
-	if (nb_tx < nb_rx) {
-		do {
-			rte_pktmbuf_free(pkts[nb_tx]);
-		} while (++nb_tx < nb_rx);
-	}
+	if (nb_tx < nb_rx)
+		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
 
 	return nb_rx - nb_tx;
 }
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index d528d4f34e..8fa5e95ad4 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -46,7 +46,6 @@ pkt_burst_receive(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint16_t i;
 	uint64_t start_tsc = 0;
 
 	get_start_cycles(&start_tsc);
@@ -61,8 +60,7 @@ pkt_burst_receive(struct fwd_stream *fs)
 		return;
 
 	fs->rx_packets += nb_rx;
-	for (i = 0; i < nb_rx; i++)
-		rte_pktmbuf_free(pkts_burst[i]);
+	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	get_end_cycles(fs, start_tsc);
 }
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 2e9047804b..05f90185df 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -53,8 +53,7 @@ forward_sub_burst(struct fwd_stream *src_fs, uint16_t port, uint16_t nb_rx,
 	} else {
 		/* Source stream not found, drop all packets. */
 		src_fs->fwd_dropped += nb_rx;
-		while (nb_rx > 0)
-			rte_pktmbuf_free(pkts[--nb_rx]);
+		rte_pktmbuf_free_bulk(pkts, nb_rx);
 	}
 }
 
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 0c14325b8d..964cd0ce2b 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2204,7 +2204,6 @@ flush_fwd_rx_queues(void)
 	portid_t port_id;
 	queueid_t rxq;
 	uint16_t  nb_rx;
-	uint16_t  i;
 	uint8_t   j;
 	uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
 	uint64_t timer_period;
@@ -2237,8 +2236,7 @@ flush_fwd_rx_queues(void)
 				do {
 					nb_rx = rte_eth_rx_burst(port_id, rxq,
 						pkts_burst, MAX_PKT_BURST);
-					for (i = 0; i < nb_rx; i++)
-						rte_pktmbuf_free(pkts_burst[i]);
+					rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 					cur_tsc = rte_rdtsc();
 					diff_tsc = cur_tsc - prev_tsc;
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 021624952d..076cdb86d5 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -421,9 +421,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 			       (unsigned) nb_pkt, (unsigned) nb_tx,
 			       (unsigned) (nb_pkt - nb_tx));
 		fs->fwd_dropped += (nb_pkt - nb_tx);
-		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
-		} while (++nb_tx < nb_pkt);
+		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	get_end_cycles(fs, start_tsc);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 6/9] app/testpmd: factorize core cycles record
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (4 preceding siblings ...)
  2023-02-20 18:34   ` [PATCH v3 5/9] app/testpmd: bulk free mbufs David Marchand
@ 2023-02-20 18:34   ` David Marchand
  2023-02-20 18:35   ` [PATCH v3 7/9] app/testpmd: factorize fwd engine init David Marchand
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:34 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Rather than have each forward engines deal with core cycles recording,
move this to testpmd common code.
fwd engines just need to report that they did some busy work.

By doing this, get_*_cycles() helpers are unneeded and removed.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v2:
- fixed fwd_streams[] access,

Changes since v1:
- removed (now unneeded) get_*_cycles() helpers,
- removed unrelated changes on noisy_vnf change,

---
 app/test-pmd/5tswap.c         | 11 ++++-------
 app/test-pmd/csumonly.c       | 10 +++-------
 app/test-pmd/flowgen.c        |  7 ++-----
 app/test-pmd/icmpecho.c       |  9 +++------
 app/test-pmd/ieee1588fwd.c    | 17 +++++++++--------
 app/test-pmd/iofwd.c          |  9 +++------
 app/test-pmd/macfwd.c         |  9 +++------
 app/test-pmd/macswap.c        | 10 ++++------
 app/test-pmd/noisy_vnf.c      |  8 ++------
 app/test-pmd/rxonly.c         |  9 +++------
 app/test-pmd/shared_rxq_fwd.c |  9 ++++-----
 app/test-pmd/testpmd.c        | 16 +++++++++++++---
 app/test-pmd/testpmd.h        | 16 +---------------
 app/test-pmd/txonly.c         |  9 +++------
 14 files changed, 57 insertions(+), 92 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index c45a811f59..0a3a897e7b 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -81,7 +81,7 @@ swap_udp(struct rte_udp_hdr *udp_hdr)
  * 2,3,4. Swaps source and destination for MAC, IPv4/IPv6, UDP/TCP.
  * Parses each layer and swaps it. When the next layer doesn't match it stops.
  */
-static void
+static bool
 pkt_burst_5tuple_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -105,10 +105,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		uint8_t *byte;
 	} h;
 
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
-
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
@@ -116,7 +112,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -180,7 +176,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		fs->fwd_dropped += (nb_rx - nb_tx);
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 0b2d4c0593..07850501f4 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -828,7 +828,7 @@ pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t nb_pkts, uint64
  * IP, UDP, TCP and SCTP flags always concern the inner layer. The
  * OUTER_IP is only useful for tunnel packets.
  */
-static void
+static bool
 pkt_burst_checksum_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -859,16 +859,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint32_t rx_bad_outer_ip_csum;
 	struct testpmd_offload_info info;
 
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
-
 	/* receive a burst of packet */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	rx_bad_ip_csum = 0;
@@ -1202,7 +1198,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index bc3d684496..b3bd4f7c65 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -58,7 +58,7 @@ RTE_DEFINE_PER_LCORE(int, _next_flow);
  * terminate receive traffic.  Received traffic is simply discarded, but we
  * still do so in order to maintain traffic statistics.
  */
-static void
+static bool
 pkt_burst_flow_gen(struct fwd_stream *fs)
 {
 	unsigned pkt_size = tx_pkt_length - 4;	/* Adjust FCS */
@@ -77,11 +77,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
 	uint32_t retry;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
-	get_start_cycles(&start_tsc);
-
 	/* Receive a burst of packets and discard them. */
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
@@ -192,7 +189,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static int
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 5a779fca3c..5ef1116141 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -269,7 +269,7 @@ ipv4_hdr_cksum(struct rte_ipv4_hdr *ip_h)
  * Receive a burst of packets, lookup for ICMP echo requests, and, if any,
  * send back ICMP echo replies.
  */
-static void
+static bool
 reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -292,9 +292,6 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	uint32_t cksum;
 	uint8_t  i;
 	int l2_len;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * First, receive a burst of packets.
@@ -303,7 +300,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	nb_replies = 0;
@@ -507,7 +504,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		}
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 242d272948..103c01fcb7 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -89,7 +89,7 @@ port_ieee1588_tx_timestamp_check(portid_t pi)
 	       (wait_us == 1) ? "" : "s");
 }
 
-static void
+static bool
 ieee1588_packet_fwd(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *mb;
@@ -103,7 +103,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	 * Receive 1 packet at a time.
 	 */
 	if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0)
-		return;
+		return false;
 
 	fs->rx_packets += 1;
 
@@ -126,14 +126,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 			       (unsigned) mb->pkt_len);
 		}
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	if (eth_type != RTE_ETHER_TYPE_1588) {
 		printf("Port %u Received NON PTP packet incorrectly"
 		       " detected by hardware\n",
 		       fs->rx_port);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/*
@@ -147,14 +147,14 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		       " protocol version 0x%x (should be 0x02)\n",
 		       fs->rx_port, ptp_hdr->version);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	if (ptp_hdr->msg_id != PTP_SYNC_MESSAGE) {
 		printf("Port %u Received PTP V2 Ethernet frame with unexpected"
 		       " message ID 0x%x (expected 0x0 - PTP_SYNC_MESSAGE)\n",
 		       fs->rx_port, ptp_hdr->msg_id);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	printf("Port %u IEEE1588 PTP V2 SYNC Message filtered by hardware\n",
 	       fs->rx_port);
@@ -168,7 +168,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		       " by hardware\n",
 		       fs->rx_port);
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 
 	/* For i40e we need the timesync register index. It is ignored for the
@@ -188,7 +188,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 		printf("Port %u sent PTP packet dropped\n", fs->tx_port);
 		fs->fwd_dropped += 1;
 		rte_pktmbuf_free(mb);
-		return;
+		return false;
 	}
 	fs->tx_packets += 1;
 
@@ -196,6 +196,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	 * Check the TX timestamp.
 	 */
 	port_ieee1588_tx_timestamp_check(fs->tx_port);
+	return true;
 }
 
 static int
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 2bcdf15728..9d0af5f667 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -41,16 +41,13 @@
  * This is the fastest possible forwarding operation, as it does not access
  * to packets data.
  */
-static void
+static bool
 pkt_burst_io_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -59,7 +56,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 			pkts_burst, nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 	fs->rx_packets += nb_rx;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
@@ -82,7 +79,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index ba08b8f323..3a840247c7 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -41,7 +41,7 @@
  * Change the source and the destination Ethernet addressed of packets
  * before forwarding them.
  */
-static void
+static bool
 pkt_burst_mac_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -54,9 +54,6 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -65,7 +62,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -113,7 +110,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 9f0933bbff..14b3eefffd 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -47,7 +47,7 @@
  * MAC swap forwarding mode: Swap the source and the destination Ethernet
  * addresses of packets before forwarding them.
  */
-static void
+static bool
 pkt_burst_mac_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
@@ -55,9 +55,6 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint32_t retry;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -66,7 +63,7 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
@@ -91,7 +88,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 		fs->fwd_dropped += (nb_rx - nb_tx);
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
 	}
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 055a80a62c..396fdd7814 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -134,14 +134,13 @@ drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
  *    out of the FIFO
  * 4. Cases 2 and 3 combined
  */
-static void
+static bool
 pkt_burst_noisy_vnf(struct fwd_stream *fs)
 {
 	const uint64_t freq_khz = rte_get_timer_hz() / 1000;
 	struct noisy_config *ncf = noisy_cfg[fs->rx_port];
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	struct rte_mbuf *tmp_pkts[MAX_PKT_BURST];
-	uint64_t start_tsc = 0;
 	uint16_t nb_deqd = 0;
 	uint16_t nb_rx = 0;
 	uint16_t nb_tx = 0;
@@ -151,8 +150,6 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	bool needs_flush = false;
 	uint64_t now;
 
-	get_start_cycles(&start_tsc);
-
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
 			pkts_burst, nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
@@ -221,8 +218,7 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 end:
-	if (nb_rx > 0 || nb_tx > 0)
-		get_end_cycles(fs, start_tsc);
+	return nb_rx > 0 || nb_tx > 0;
 }
 
 #define NOISY_STRSIZE 256
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index 8fa5e95ad4..ad4597cf9a 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -41,14 +41,11 @@
 /*
  * Received a burst of packets.
  */
-static void
+static bool
 pkt_burst_receive(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	/*
 	 * Receive a burst of packets.
@@ -57,12 +54,12 @@ pkt_burst_receive(struct fwd_stream *fs)
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 
 	fs->rx_packets += nb_rx;
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 05f90185df..4902ec407e 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -89,21 +89,20 @@ forward_shared_rxq(struct fwd_stream *fs, uint16_t nb_rx,
 			  &pkts_burst[nb_rx - nb_sub_burst]);
 }
 
-static void
+static bool
 shared_rxq_fwd(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
 	uint16_t nb_rx;
-	uint64_t start_tsc = 0;
 
-	get_start_cycles(&start_tsc);
 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
 				 nb_pkt_per_burst);
 	inc_rx_burst_stats(fs, nb_rx);
 	if (unlikely(nb_rx == 0))
-		return;
+		return false;
 	forward_shared_rxq(fs, nb_rx, pkts_burst);
-	get_end_cycles(fs, start_tsc);
+
+	return true;
 }
 
 static void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 964cd0ce2b..f80b1c1ca7 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2271,9 +2271,19 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
 	nb_fs = fc->stream_nb;
 	prev_tsc = rte_rdtsc();
 	do {
-		for (sm_id = 0; sm_id < nb_fs; sm_id++)
-			if (!fsm[sm_id]->disabled)
-				(*pkt_fwd)(fsm[sm_id]);
+		for (sm_id = 0; sm_id < nb_fs; sm_id++) {
+			struct fwd_stream *fs = fsm[sm_id];
+			uint64_t start_fs_tsc = 0;
+			bool busy;
+
+			if (fs->disabled)
+				continue;
+			if (record_core_cycles)
+				start_fs_tsc = rte_rdtsc();
+			busy = (*pkt_fwd)(fs);
+			if (record_core_cycles && busy)
+				fs->busy_cycles += rte_rdtsc() - start_fs_tsc;
+		}
 #ifdef RTE_LIB_BITRATESTATS
 		if (bitrate_enabled != 0 &&
 				bitrate_lcore_id == rte_lcore_id()) {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 329a6378a1..ce47d1ed92 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -382,7 +382,7 @@ struct fwd_lcore {
 typedef int (*port_fwd_begin_t)(portid_t pi);
 typedef void (*port_fwd_end_t)(portid_t pi);
 typedef void (*stream_init_t)(struct fwd_stream *fs);
-typedef void (*packet_fwd_t)(struct fwd_stream *fs);
+typedef bool (*packet_fwd_t)(struct fwd_stream *fs);
 
 struct fwd_engine {
 	const char       *fwd_mode_name; /**< Forwarding mode name. */
@@ -837,20 +837,6 @@ mbuf_pool_find(unsigned int sock_id, uint16_t idx)
 	return rte_mempool_lookup((const char *)pool_name);
 }
 
-static inline void
-get_start_cycles(uint64_t *start_tsc)
-{
-	if (record_core_cycles)
-		*start_tsc = rte_rdtsc();
-}
-
-static inline void
-get_end_cycles(struct fwd_stream *fs, uint64_t start_tsc)
-{
-	if (record_core_cycles)
-		fs->busy_cycles += rte_rdtsc() - start_tsc;
-}
-
 static inline void
 inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx)
 {
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 076cdb86d5..63ad5e69bf 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -323,7 +323,7 @@ pkt_burst_prepare(struct rte_mbuf *pkt, struct rte_mempool *mbp,
 /*
  * Transmit a burst of multi-segments packets.
  */
-static void
+static bool
 pkt_burst_transmit(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
@@ -337,9 +337,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
-	uint64_t start_tsc = 0;
-
-	get_start_cycles(&start_tsc);
 
 	mbp = current_fwd_lcore()->mbp;
 	txp = &ports[fs->tx_port];
@@ -392,7 +389,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	}
 
 	if (nb_pkt == 0)
-		return;
+		return false;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
 
@@ -424,7 +421,7 @@ pkt_burst_transmit(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
-	get_end_cycles(fs, start_tsc);
+	return true;
 }
 
 static int
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 7/9] app/testpmd: factorize fwd engine init
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (5 preceding siblings ...)
  2023-02-20 18:34   ` [PATCH v3 6/9] app/testpmd: factorize core cycles record David Marchand
@ 2023-02-20 18:35   ` David Marchand
  2023-02-20 18:35   ` [PATCH v3 8/9] app/testpmd: factorize fwd engine Rx David Marchand
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:35 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
initialising the fs object.

While at it, remove unneeded initialisation of fwd_engine empty fields.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v1:
- updated ieee1588,

---
 app/test-pmd/5tswap.c         | 16 +---------------
 app/test-pmd/csumonly.c       | 16 +---------------
 app/test-pmd/flowgen.c        | 15 +--------------
 app/test-pmd/icmpecho.c       | 16 +---------------
 app/test-pmd/ieee1588fwd.c    |  8 +-------
 app/test-pmd/iofwd.c          | 16 +---------------
 app/test-pmd/macfwd.c         | 16 +---------------
 app/test-pmd/macswap.c        | 16 +---------------
 app/test-pmd/noisy_vnf.c      | 14 +-------------
 app/test-pmd/rxonly.c         |  2 --
 app/test-pmd/shared_rxq_fwd.c |  2 --
 app/test-pmd/testpmd.c        | 10 ++++++++++
 app/test-pmd/testpmd.h        |  2 ++
 app/test-pmd/txonly.c         |  1 -
 14 files changed, 21 insertions(+), 129 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 0a3a897e7b..7b5f58f4d4 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -180,22 +180,8 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_5tuple_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine five_tuple_swap_fwd_engine = {
 	.fwd_mode_name  = "5tswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_5tuple_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_5tuple_swap,
 };
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 07850501f4..f72e2d74c7 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -1201,22 +1201,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_checksum_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine csum_fwd_engine = {
 	.fwd_mode_name  = "csum",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_checksum_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_checksum_forward,
 };
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index b3bd4f7c65..6f42019353 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -199,22 +199,9 @@ flowgen_begin(portid_t pi)
 	return 0;
 }
 
-static void
-flowgen_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine flow_gen_engine = {
 	.fwd_mode_name  = "flowgen",
 	.port_fwd_begin = flowgen_begin,
-	.port_fwd_end   = NULL,
-	.stream_init    = flowgen_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_flow_gen,
 };
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 5ef1116141..eba8b99f1e 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -507,22 +507,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-icmpecho_stream_init(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine icmp_echo_engine = {
 	.fwd_mode_name  = "icmpecho",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = icmpecho_stream_init,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = reply_to_icmp_echo_rqsts,
 };
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 103c01fcb7..fd8ba27b2f 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -215,16 +215,10 @@ port_ieee1588_fwd_end(portid_t pi)
 static void
 port_ieee1588_stream_init(struct fwd_stream *fs)
 {
-	bool rx_stopped, tx_stopped;
-
 	/* Force transmission on reception port */
 	fs->tx_port = fs->rx_port;
 
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
+	common_fwd_stream_init(fs);
 }
 
 struct fwd_engine ieee1588_fwd_engine = {
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 9d0af5f667..12be06fa79 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -82,22 +82,8 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine io_fwd_engine = {
 	.fwd_mode_name  = "io",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_io_forward,
 };
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 3a840247c7..953d9ea089 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -113,22 +113,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_forward(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_fwd_engine = {
 	.fwd_mode_name  = "mac",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_forward,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_forward,
 };
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 14b3eefffd..062542dc53 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -92,22 +92,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	return true;
 }
 
-static void
-stream_init_mac_swap(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine mac_swap_engine = {
 	.fwd_mode_name  = "macswap",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
-	.stream_init    = stream_init_mac_swap,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_mac_swap,
 };
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 396fdd7814..7bcab84db3 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -278,22 +278,10 @@ noisy_fwd_begin(portid_t pi)
 	return 0;
 }
 
-static void
-stream_init_noisy_vnf(struct fwd_stream *fs)
-{
-	bool rx_stopped, tx_stopped;
-
-	rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
-						RTE_ETH_QUEUE_STATE_STOPPED;
-	fs->disabled = rx_stopped || tx_stopped;
-}
-
 struct fwd_engine noisy_vnf_engine = {
 	.fwd_mode_name  = "noisy",
 	.port_fwd_begin = noisy_fwd_begin,
 	.port_fwd_end   = noisy_fwd_end,
-	.stream_init    = stream_init_noisy_vnf,
+	.stream_init    = common_fwd_stream_init,
 	.packet_fwd     = pkt_burst_noisy_vnf,
 };
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index ad4597cf9a..d4bff9b5ea 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -71,8 +71,6 @@ stream_init_receive(struct fwd_stream *fs)
 
 struct fwd_engine rx_only_engine = {
 	.fwd_mode_name  = "rxonly",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = stream_init_receive,
 	.packet_fwd     = pkt_burst_receive,
 };
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 4902ec407e..67e5494735 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -114,8 +114,6 @@ shared_rxq_stream_init(struct fwd_stream *fs)
 
 struct fwd_engine shared_rxq_engine = {
 	.fwd_mode_name  = "shared_rxq",
-	.port_fwd_begin = NULL,
-	.port_fwd_end   = NULL,
 	.stream_init    = shared_rxq_stream_init,
 	.packet_fwd     = shared_rxq_fwd,
 };
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index f80b1c1ca7..b6197aa258 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2387,6 +2387,16 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
 	}
 }
 
+void
+common_fwd_stream_init(struct fwd_stream *fs)
+{
+	bool rx_stopped, tx_stopped;
+
+	rx_stopped = (ports[fs->rx_port].rxq[fs->rx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	tx_stopped = (ports[fs->tx_port].txq[fs->tx_queue].state == RTE_ETH_QUEUE_STATE_STOPPED);
+	fs->disabled = rx_stopped || tx_stopped;
+}
+
 /*
  * Launch packet forwarding configuration.
  */
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce47d1ed92..4b28cd0d0d 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -392,6 +392,8 @@ struct fwd_engine {
 	packet_fwd_t     packet_fwd;     /**< Mandatory. */
 };
 
+void common_fwd_stream_init(struct fwd_stream *fs);
+
 #define FLEX_ITEM_MAX_SAMPLES_NUM 16
 #define FLEX_ITEM_MAX_LINKS_NUM 16
 #define FLEX_MAX_FLOW_PATTERN_LENGTH 64
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 63ad5e69bf..b80ab6f5df 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -508,7 +508,6 @@ tx_only_stream_init(struct fwd_stream *fs)
 struct fwd_engine tx_only_engine = {
 	.fwd_mode_name  = "txonly",
 	.port_fwd_begin = tx_only_begin,
-	.port_fwd_end   = NULL,
 	.stream_init    = tx_only_stream_init,
 	.packet_fwd     = pkt_burst_transmit,
 };
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 8/9] app/testpmd: factorize fwd engine Rx
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (6 preceding siblings ...)
  2023-02-20 18:35   ` [PATCH v3 7/9] app/testpmd: factorize fwd engine init David Marchand
@ 2023-02-20 18:35   ` David Marchand
  2023-02-20 18:35   ` [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx David Marchand
  2023-02-28 18:54   ` [PATCH v3 0/9] Testpmd code cleanup Ferruh Yigit
  9 siblings, 0 replies; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:35 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
receiving packets and incrementing rx counter.
inc_rx_burst_stats() is then unneeded and removed.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Changes since v1:
- updated shared_rxq fwd engine,
- removed inc_rx_burst_stats helper,
- removed likely() around rx stats update,

---
 app/test-pmd/5tswap.c         |  5 +----
 app/test-pmd/csumonly.c       |  5 +----
 app/test-pmd/flowgen.c        |  5 +----
 app/test-pmd/icmpecho.c       |  5 +----
 app/test-pmd/ieee1588fwd.c    |  4 +---
 app/test-pmd/iofwd.c          |  5 +----
 app/test-pmd/macfwd.c         |  5 +----
 app/test-pmd/macswap.c        |  5 +----
 app/test-pmd/noisy_vnf.c      |  5 +----
 app/test-pmd/rxonly.c         |  5 +----
 app/test-pmd/shared_rxq_fwd.c |  4 +---
 app/test-pmd/testpmd.h        | 10 ++++++++--
 12 files changed, 19 insertions(+), 44 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 7b5f58f4d4..27da867d7f 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -108,13 +108,10 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 	ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads);
 	vlan_qinq_set(pkts_burst, nb_rx, ol_flags,
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index f72e2d74c7..d758ae0ac6 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -860,13 +860,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	struct testpmd_offload_info info;
 
 	/* receive a burst of packet */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	rx_bad_ip_csum = 0;
 	rx_bad_l4_csum = 0;
 	rx_bad_outer_l4_csum = 0;
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 6f42019353..3705cc60c5 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -80,10 +80,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
 	/* Receive a burst of packets and discard them. */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
-	fs->rx_packets += nb_rx;
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index eba8b99f1e..48f8fe0bf1 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -296,13 +296,10 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	/*
 	 * First, receive a burst of packets.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	nb_replies = 0;
 	for (i = 0; i < nb_rx; i++) {
 		if (likely(i < nb_rx - 1))
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index fd8ba27b2f..1d51ebfe9d 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -102,11 +102,9 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 	/*
 	 * Receive 1 packet at a time.
 	 */
-	if (rte_eth_rx_burst(fs->rx_port, fs->rx_queue, &mb, 1) == 0)
+	if (common_fwd_stream_receive(fs, &mb, 1) == 0)
 		return false;
 
-	fs->rx_packets += 1;
-
 	/*
 	 * Check that the received packet is a PTP packet that was detected
 	 * by the hardware.
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 12be06fa79..69b583cb5b 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -52,12 +52,9 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
-			pkts_burst, nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
-	fs->rx_packets += nb_rx;
 
 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
 			pkts_burst, nb_rx);
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index 953d9ea089..a72f5ccb75 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -58,13 +58,10 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 	tx_offloads = txp->dev_conf.txmode.offloads;
 	if (tx_offloads	& RTE_ETH_TX_OFFLOAD_VLAN_INSERT)
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index 062542dc53..ab37123404 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -59,13 +59,10 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets and forward them.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	txp = &ports[fs->tx_port];
 
 	do_macswap(pkts_burst, nb_rx, txp);
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index 7bcab84db3..e543adc865 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -150,12 +150,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 	bool needs_flush = false;
 	uint64_t now;
 
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
-			pkts_burst, nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		goto flush;
-	fs->rx_packets += nb_rx;
 
 	if (!ncf->do_buffering) {
 		sim_memory_lookups(ncf, nb_rx);
diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index d4bff9b5ea..315f9286cd 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -50,13 +50,10 @@ pkt_burst_receive(struct fwd_stream *fs)
 	/*
 	 * Receive a burst of packets.
 	 */
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	fs->rx_packets += nb_rx;
 	rte_pktmbuf_free_bulk(pkts_burst, nb_rx);
 
 	return true;
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 67e5494735..623d62da88 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -95,9 +95,7 @@ shared_rxq_fwd(struct fwd_stream *fs)
 	struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
 	uint16_t nb_rx;
 
-	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
-				 nb_pkt_per_burst);
-	inc_rx_burst_stats(fs, nb_rx);
+	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
 	if (unlikely(nb_rx == 0))
 		return false;
 	forward_shared_rxq(fs, nb_rx, pkts_burst);
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 4b28cd0d0d..6c82cbab45 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -839,11 +839,17 @@ mbuf_pool_find(unsigned int sock_id, uint16_t idx)
 	return rte_mempool_lookup((const char *)pool_name);
 }
 
-static inline void
-inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx)
+static inline uint16_t
+common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
+	unsigned int nb_pkts)
 {
+	uint16_t nb_rx;
+
+	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, nb_pkts);
 	if (record_burst_stats)
 		fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
+	fs->rx_packets += nb_rx;
+	return nb_rx;
 }
 
 static inline void
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (7 preceding siblings ...)
  2023-02-20 18:35   ` [PATCH v3 8/9] app/testpmd: factorize fwd engine Rx David Marchand
@ 2023-02-20 18:35   ` David Marchand
  2023-02-28 18:35     ` Ferruh Yigit
  2023-02-28 18:54   ` [PATCH v3 0/9] Testpmd code cleanup Ferruh Yigit
  9 siblings, 1 reply; 48+ messages in thread
From: David Marchand @ 2023-02-20 18:35 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

Reduce code duplication by introducing a helper that takes care of
transmitting, retrying if enabled and incrementing tx counter.
inc_tx_burst_stats() is then unneeded and removed.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v1:
- changed Tx helper so it matches rte_eth_tx_burst() semantic,
- updated ieee1588,
- removed inc_tx_burst_stats helper,

---
 app/test-pmd/5tswap.c      | 22 +-----------
 app/test-pmd/csumonly.c    | 23 +------------
 app/test-pmd/flowgen.c     | 20 +----------
 app/test-pmd/icmpecho.c    | 28 ++--------------
 app/test-pmd/ieee1588fwd.c |  5 +--
 app/test-pmd/iofwd.c       | 22 +-----------
 app/test-pmd/macfwd.c      | 21 +-----------
 app/test-pmd/macswap.c     | 27 ++-------------
 app/test-pmd/noisy_vnf.c   | 68 ++++++--------------------------------
 app/test-pmd/testpmd.h     | 27 +++++++++++++--
 app/test-pmd/txonly.c      | 19 +----------
 11 files changed, 47 insertions(+), 235 deletions(-)

diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c
index 27da867d7f..ff8c2dcde5 100644
--- a/app/test-pmd/5tswap.c
+++ b/app/test-pmd/5tswap.c
@@ -91,9 +91,6 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 	uint64_t ol_flags;
 	uint16_t proto;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
-
 	int i;
 	union {
 		struct rte_ether_hdr *eth;
@@ -155,24 +152,7 @@ pkt_burst_5tuple_swap(struct fwd_stream *fs)
 		}
 		mbuf_field_set(mb, ol_flags);
 	}
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index d758ae0ac6..fc85c22a77 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -847,12 +847,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint8_t gro_enable;
 #endif
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_prep;
 	uint16_t i;
 	uint64_t rx_ol_flags, tx_ol_flags;
 	uint64_t tx_offloads;
-	uint32_t retry;
 	uint32_t rx_bad_ip_csum;
 	uint32_t rx_bad_l4_csum;
 	uint32_t rx_bad_outer_l4_csum;
@@ -1169,32 +1167,13 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_prep], nb_rx - nb_prep);
 	}
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
-			nb_prep);
+	common_fwd_stream_transmit(fs, tx_pkts_burst, nb_prep);
 
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_prep) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_prep && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
 	fs->rx_bad_ip_csum += rx_bad_ip_csum;
 	fs->rx_bad_l4_csum += rx_bad_l4_csum;
 	fs->rx_bad_outer_l4_csum += rx_bad_outer_l4_csum;
 	fs->rx_bad_outer_ip_csum += rx_bad_outer_ip_csum;
 
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_prep)) {
-		fs->fwd_dropped += (nb_prep - nb_tx);
-		rte_pktmbuf_free_bulk(&tx_pkts_burst[nb_tx], nb_prep - nb_tx);
-	}
-
 	return true;
 }
 
diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c
index 3705cc60c5..53b5f24f11 100644
--- a/app/test-pmd/flowgen.c
+++ b/app/test-pmd/flowgen.c
@@ -75,7 +75,6 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 	uint16_t nb_dropped;
 	uint16_t nb_pkt;
 	uint16_t nb_clones = nb_pkt_flowgen_clones;
-	uint32_t retry;
 	uint64_t tx_offloads;
 	int next_flow = RTE_PER_LCORE(_next_flow);
 
@@ -158,30 +157,13 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 			next_flow = 0;
 	}
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_pkt - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-
-	inc_tx_burst_stats(fs, nb_tx);
+	nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
 	nb_dropped = nb_pkt - nb_tx;
 	if (unlikely(nb_dropped > 0)) {
 		/* Back out the flow counter. */
 		next_flow -= nb_dropped;
 		while (next_flow < 0)
 			next_flow += nb_flows_flowgen;
-
-		fs->fwd_dropped += nb_dropped;
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	RTE_PER_LCORE(_next_flow) = next_flow;
diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 48f8fe0bf1..68524484e3 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -280,10 +280,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	struct rte_ipv4_hdr *ip_h;
 	struct rte_icmp_hdr *icmp_h;
 	struct rte_ether_addr eth_addr;
-	uint32_t retry;
 	uint32_t ip_addr;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t nb_replies;
 	uint16_t eth_type;
 	uint16_t vlan_id;
@@ -476,30 +474,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	}
 
 	/* Send back ICMP echo replies, if any. */
-	if (nb_replies > 0) {
-		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
-					 nb_replies);
-		/*
-		 * Retry if necessary
-		 */
-		if (unlikely(nb_tx < nb_replies) && fs->retry_enabled) {
-			retry = 0;
-			while (nb_tx < nb_replies &&
-					retry++ < burst_tx_retry_num) {
-				rte_delay_us(burst_tx_delay_time);
-				nb_tx += rte_eth_tx_burst(fs->tx_port,
-						fs->tx_queue,
-						&pkts_burst[nb_tx],
-						nb_replies - nb_tx);
-			}
-		}
-		fs->tx_packets += nb_tx;
-		inc_tx_burst_stats(fs, nb_tx);
-		if (unlikely(nb_tx < nb_replies)) {
-			fs->fwd_dropped += (nb_replies - nb_tx);
-			rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_replies - nb_tx);
-		}
-	}
+	if (nb_replies > 0)
+		common_fwd_stream_transmit(fs, pkts_burst, nb_replies);
 
 	return true;
 }
diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c
index 1d51ebfe9d..386d9f10e6 100644
--- a/app/test-pmd/ieee1588fwd.c
+++ b/app/test-pmd/ieee1588fwd.c
@@ -182,13 +182,10 @@ ieee1588_packet_fwd(struct fwd_stream *fs)
 
 	/* Forward PTP packet with hardware TX timestamp */
 	mb->ol_flags |= RTE_MBUF_F_TX_IEEE1588_TMST;
-	if (rte_eth_tx_burst(fs->tx_port, fs->tx_queue, &mb, 1) == 0) {
+	if (common_fwd_stream_transmit(fs, &mb, 1) == 0) {
 		printf("Port %u sent PTP packet dropped\n", fs->tx_port);
-		fs->fwd_dropped += 1;
-		rte_pktmbuf_free(mb);
 		return false;
 	}
-	fs->tx_packets += 1;
 
 	/*
 	 * Check the TX timestamp.
diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c
index 69b583cb5b..ba06fae4a6 100644
--- a/app/test-pmd/iofwd.c
+++ b/app/test-pmd/iofwd.c
@@ -46,8 +46,6 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -56,25 +54,7 @@ pkt_burst_io_forward(struct fwd_stream *fs)
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-			pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c
index a72f5ccb75..7316d73315 100644
--- a/app/test-pmd/macfwd.c
+++ b/app/test-pmd/macfwd.c
@@ -48,9 +48,7 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 	struct rte_port  *txp;
 	struct rte_mbuf  *mb;
 	struct rte_ether_hdr *eth_hdr;
-	uint32_t retry;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
 	uint16_t i;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
@@ -87,25 +85,8 @@ pkt_burst_mac_forward(struct fwd_stream *fs)
 		mb->vlan_tci = txp->tx_vlan_id;
 		mb->vlan_tci_outer = txp->tx_vlan_id_outer;
 	}
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
 
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c
index ab37123404..57f77003fe 100644
--- a/app/test-pmd/macswap.c
+++ b/app/test-pmd/macswap.c
@@ -51,10 +51,7 @@ static bool
 pkt_burst_mac_swap(struct fwd_stream *fs)
 {
 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
-	struct rte_port  *txp;
 	uint16_t nb_rx;
-	uint16_t nb_tx;
-	uint32_t retry;
 
 	/*
 	 * Receive a burst of packets and forward them.
@@ -63,28 +60,8 @@ pkt_burst_mac_swap(struct fwd_stream *fs)
 	if (unlikely(nb_rx == 0))
 		return false;
 
-	txp = &ports[fs->tx_port];
-
-	do_macswap(pkts_burst, nb_rx, txp);
-
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
-	inc_tx_burst_stats(fs, nb_tx);
-	if (unlikely(nb_tx < nb_rx)) {
-		fs->fwd_dropped += (nb_rx - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_rx - nb_tx);
-	}
+	do_macswap(pkts_burst, nb_rx, &ports[fs->tx_port]);
+	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 
 	return true;
 }
diff --git a/app/test-pmd/noisy_vnf.c b/app/test-pmd/noisy_vnf.c
index e543adc865..2bf90a983c 100644
--- a/app/test-pmd/noisy_vnf.c
+++ b/app/test-pmd/noisy_vnf.c
@@ -93,30 +93,6 @@ sim_memory_lookups(struct noisy_config *ncf, uint16_t nb_pkts)
 	}
 }
 
-static uint16_t
-do_retry(uint16_t nb_rx, uint16_t nb_tx, struct rte_mbuf **pkts,
-	 struct fwd_stream *fs)
-{
-	uint32_t retry = 0;
-
-	while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
-		rte_delay_us(burst_tx_delay_time);
-		nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-				&pkts[nb_tx], nb_rx - nb_tx);
-	}
-
-	return nb_tx;
-}
-
-static uint32_t
-drop_pkts(struct rte_mbuf **pkts, uint16_t nb_rx, uint16_t nb_tx)
-{
-	if (nb_tx < nb_rx)
-		rte_pktmbuf_free_bulk(&pkts[nb_tx], nb_rx - nb_tx);
-
-	return nb_rx - nb_tx;
-}
-
 /*
  * Forwarding of packets in noisy VNF mode.  Forward packets but perform
  * memory operations first as specified on cmdline.
@@ -156,37 +132,22 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 
 	if (!ncf->do_buffering) {
 		sim_memory_lookups(ncf, nb_rx);
-		nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-				pkts_burst, nb_rx);
-		if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
-			nb_tx += do_retry(nb_rx, nb_tx, pkts_burst, fs);
-		inc_tx_burst_stats(fs, nb_tx);
-		fs->tx_packets += nb_tx;
-		fs->fwd_dropped += drop_pkts(pkts_burst, nb_rx, nb_tx);
+		nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
 		goto end;
 	}
 
 	fifo_free = rte_ring_free_count(ncf->f);
 	if (fifo_free >= nb_rx) {
-		nb_enqd = rte_ring_enqueue_burst(ncf->f,
-				(void **) pkts_burst, nb_rx, NULL);
-		if (nb_enqd < nb_rx)
-			fs->fwd_dropped += drop_pkts(pkts_burst,
-						     nb_rx, nb_enqd);
-	} else {
-		nb_deqd = rte_ring_dequeue_burst(ncf->f,
-				(void **) tmp_pkts, nb_rx, NULL);
-		nb_enqd = rte_ring_enqueue_burst(ncf->f,
-				(void **) pkts_burst, nb_deqd, NULL);
-		if (nb_deqd > 0) {
-			nb_tx = rte_eth_tx_burst(fs->tx_port,
-					fs->tx_queue, tmp_pkts,
-					nb_deqd);
-			if (unlikely(nb_tx < nb_rx) && fs->retry_enabled)
-				nb_tx += do_retry(nb_rx, nb_tx, tmp_pkts, fs);
-			inc_tx_burst_stats(fs, nb_tx);
-			fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, nb_tx);
+		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_rx, NULL);
+		if (nb_enqd < nb_rx) {
+			fs->fwd_dropped += nb_rx - nb_enqd;
+			rte_pktmbuf_free_bulk(&pkts_burst[nb_enqd], nb_rx - nb_enqd);
 		}
+	} else {
+		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **) tmp_pkts, nb_rx, NULL);
+		nb_enqd = rte_ring_enqueue_burst(ncf->f, (void **) pkts_burst, nb_deqd, NULL);
+		if (nb_deqd > 0)
+			nb_tx = common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
 	}
 
 	sim_memory_lookups(ncf, nb_enqd);
@@ -202,16 +163,9 @@ pkt_burst_noisy_vnf(struct fwd_stream *fs)
 				noisy_tx_sw_buf_flush_time > 0 && !nb_tx;
 	}
 	while (needs_flush && !rte_ring_empty(ncf->f)) {
-		unsigned int sent;
 		nb_deqd = rte_ring_dequeue_burst(ncf->f, (void **)tmp_pkts,
 				MAX_PKT_BURST, NULL);
-		sent = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					 tmp_pkts, nb_deqd);
-		if (unlikely(sent < nb_deqd) && fs->retry_enabled)
-			sent += do_retry(nb_deqd, sent, tmp_pkts, fs);
-		inc_tx_burst_stats(fs, sent);
-		fs->fwd_dropped += drop_pkts(tmp_pkts, nb_deqd, sent);
-		nb_tx += sent;
+		nb_tx += common_fwd_stream_transmit(fs, tmp_pkts, nb_deqd);
 		ncf->prev_time = rte_get_timer_cycles();
 	}
 end:
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 6c82cbab45..b9215720b6 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -852,11 +852,34 @@ common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
 	return nb_rx;
 }
 
-static inline void
-inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
+static inline uint16_t
+common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
+	unsigned int nb_pkts)
 {
+	uint16_t nb_tx;
+	uint32_t retry;
+
+	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, nb_pkts);
+	/*
+	 * Retry if necessary
+	 */
+	if (unlikely(nb_tx < nb_pkts) && fs->retry_enabled) {
+		retry = 0;
+		while (nb_tx < nb_pkts && retry++ < burst_tx_retry_num) {
+			rte_delay_us(burst_tx_delay_time);
+			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
+				&burst[nb_tx], nb_pkts - nb_tx);
+		}
+	}
+	fs->tx_packets += nb_tx;
 	if (record_burst_stats)
 		fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
+	if (unlikely(nb_tx < nb_pkts)) {
+		fs->fwd_dropped += (nb_pkts - nb_tx);
+		rte_pktmbuf_free_bulk(&burst[nb_tx], nb_pkts - nb_tx);
+	}
+
+	return nb_tx;
 }
 
 /* Prototypes */
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index b80ab6f5df..b3d6873104 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -334,7 +334,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	uint16_t nb_tx;
 	uint16_t nb_pkt;
 	uint16_t vlan_tci, vlan_tci_outer;
-	uint32_t retry;
 	uint64_t ol_flags = 0;
 	uint64_t tx_offloads;
 
@@ -391,25 +390,11 @@ pkt_burst_transmit(struct fwd_stream *fs)
 	if (nb_pkt == 0)
 		return false;
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
-
-	/*
-	 * Retry if necessary
-	 */
-	if (unlikely(nb_tx < nb_pkt) && fs->retry_enabled) {
-		retry = 0;
-		while (nb_tx < nb_pkt && retry++ < burst_tx_retry_num) {
-			rte_delay_us(burst_tx_delay_time);
-			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_pkt - nb_tx);
-		}
-	}
-	fs->tx_packets += nb_tx;
+	nb_tx = common_fwd_stream_transmit(fs, pkts_burst, nb_pkt);
 
 	if (txonly_multi_flow)
 		RTE_PER_LCORE(_ip_var) -= nb_pkt - nb_tx;
 
-	inc_tx_burst_stats(fs, nb_tx);
 	if (unlikely(nb_tx < nb_pkt)) {
 		if (verbose_level > 0 && fs->fwd_dropped == 0)
 			printf("port %d tx_queue %d - drop "
@@ -417,8 +402,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
 			       fs->tx_port, fs->tx_queue,
 			       (unsigned) nb_pkt, (unsigned) nb_tx,
 			       (unsigned) (nb_pkt - nb_tx));
-		fs->fwd_dropped += (nb_pkt - nb_tx);
-		rte_pktmbuf_free_bulk(&pkts_burst[nb_tx], nb_pkt - nb_tx);
 	}
 
 	return true;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v3 5/9] app/testpmd: bulk free mbufs
  2023-02-20 18:34   ` [PATCH v3 5/9] app/testpmd: bulk free mbufs David Marchand
@ 2023-02-20 18:45     ` Stephen Hemminger
  0 siblings, 0 replies; 48+ messages in thread
From: Stephen Hemminger @ 2023-02-20 18:45 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Ferruh Yigit, Aman Singh, Yuying Zhang, Robin Jarry

On Mon, 20 Feb 2023 19:34:58 +0100
David Marchand <david.marchand@redhat.com> wrote:

> Use the bulk free helper.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

Might be worth scanning for same pattern in examples and drivers.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine
  2023-02-20 18:34   ` [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
@ 2023-02-24  8:24     ` Singh, Aman Deep
  0 siblings, 0 replies; 48+ messages in thread
From: Singh, Aman Deep @ 2023-02-24  8:24 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Ferruh Yigit, Yuying Zhang, Robin Jarry, stable


On 2/21/2023 12:04 AM, David Marchand wrote:
> Don't count a packet has been transmitted before it is done.
>
> Fixes: af75078fece3 ("first public release")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Aman Singh <aman.deep.singh@intel.com>

<snip>


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration
  2023-02-20 16:40   ` [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
@ 2023-02-24  9:11     ` Singh, Aman Deep
  0 siblings, 0 replies; 48+ messages in thread
From: Singh, Aman Deep @ 2023-02-24  9:11 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Ferruh Yigit, Yuying Zhang, Robin Jarry


On 2/20/2023 10:10 PM, David Marchand wrote:
> This fwd engine currently ignores the forwarding configuration.
> Force it explicitly when initialising the stream.
> The code is then more consistent with other fwd engines (i.e. receiving
> on fs->rx_port, transmitting on fs->tx_port).
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Aman Singh <aman.deep.singh@intel.com>

> ---

<snip>


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx
  2023-02-20 18:35   ` [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx David Marchand
@ 2023-02-28 18:35     ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-28 18:35 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 2/20/2023 6:35 PM, David Marchand wrote:
> Reduce code duplication by introducing a helper that takes care of
> transmitting, retrying if enabled and incrementing tx counter.
> inc_tx_burst_stats() is then unneeded and removed.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration
  2023-02-20 18:34   ` [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
@ 2023-02-28 18:50     ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-28 18:50 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 2/20/2023 6:34 PM, David Marchand wrote:
> This fwd engine currently ignores the forwarding configuration.
> Force it explicitly when initialising the stream.
> The code is then more consistent with other fwd engines (i.e. receiving
> on fs->rx_port, transmitting on fs->tx_port).
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine
  2023-02-20 18:34   ` [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
@ 2023-02-28 18:51     ` Ferruh Yigit
  0 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-28 18:51 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: Aman Singh, Yuying Zhang, Robin Jarry, stable, Kevin Traynor,
	Bernard Iremonger, Jens Freimann

On 2/20/2023 6:34 PM, David Marchand wrote:
> nb_rx relates to the number of packets received from the driver.
> nb_tx is the total number of packets transmitted by this forward engine.
> 
> Fix the retry stage, for dequeued packets, as it was incorrectly
> passing nb_rx / nb_tx as bounds of the tmp_pkts[] array, and fix tx stats
> accordingly.
> 
> Fixes: 3c156061b938 ("app/testpmd: add noisy neighbour forwarding mode")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v3 0/9] Testpmd code cleanup
  2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
                     ` (8 preceding siblings ...)
  2023-02-20 18:35   ` [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx David Marchand
@ 2023-02-28 18:54   ` Ferruh Yigit
  9 siblings, 0 replies; 48+ messages in thread
From: Ferruh Yigit @ 2023-02-28 18:54 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: Aman Singh, Yuying Zhang, Robin Jarry

On 2/20/2023 6:34 PM, David Marchand wrote:
> Here is a series to reduce code duplication in testpmd.
> 
> This work started from looking at Robin series on reporting lcore busy
> cycles in telemetry, which is then added in testpmd [1].
> While looking at the forward engines code, I saw way too much
> duplicated code.
> 
> Warning: this is only compile tested.
> 
> 1: https://patchwork.dpdk.org/project/dpdk/patch/20230119150656.418404-5-rjarry@redhat.com/

Series applied to dpdk-next-net/main, thanks.

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2023-02-28 18:54 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 10:47 [PATCH 0/6] Testpmd code cleanup David Marchand
2023-01-24 10:47 ` [PATCH 1/6] app/testpmd: factorize core cycles record David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 2/6] app/testpmd: don't send unprepared packets David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 3/6] app/testpmd: bulk free mbufs David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 4/6] app/testpmd: factorize fwd engine init David Marchand
2023-02-14 18:14   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 5/6] app/testpmd: factorize fwd engine Rx David Marchand
2023-02-14 18:15   ` Ferruh Yigit
2023-01-24 10:47 ` [PATCH 6/6] app/testpmd: factorize fwd engine Tx David Marchand
2023-02-14 11:03   ` Singh, Aman Deep
2023-02-14 18:17     ` Ferruh Yigit
2023-02-16  8:01       ` Singh, Aman Deep
2023-02-16 10:07         ` Ferruh Yigit
2023-02-14 18:16   ` Ferruh Yigit
2023-02-20 16:33     ` David Marchand
2023-01-25 13:50 ` [PATCH 0/6] Testpmd code cleanup Robin Jarry
2023-02-14 18:22   ` Ferruh Yigit
2023-02-20 15:02     ` David Marchand
2023-02-20 16:40 ` [PATCH v2 0/9] " David Marchand
2023-02-20 16:40   ` [PATCH v2 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
2023-02-20 16:40   ` [PATCH v2 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
2023-02-20 16:40   ` [PATCH v2 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
2023-02-24  9:11     ` Singh, Aman Deep
2023-02-20 16:40   ` [PATCH v2 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
2023-02-20 16:40   ` [PATCH v2 5/9] app/testpmd: bulk free mbufs David Marchand
2023-02-20 16:41   ` [PATCH v2 6/9] app/testpmd: factorize core cycles record David Marchand
2023-02-20 16:41   ` [PATCH v2 7/9] app/testpmd: factorize fwd engine init David Marchand
2023-02-20 16:41   ` [PATCH v2 8/9] app/testpmd: factorize fwd engine Rx David Marchand
2023-02-20 16:41   ` [PATCH v2 9/9] app/testpmd: factorize fwd engine Tx David Marchand
2023-02-20 18:34 ` [PATCH v3 0/9] Testpmd code cleanup David Marchand
2023-02-20 18:34   ` [PATCH v3 1/9] app/testpmd: fix Tx preparation in checksum engine David Marchand
2023-02-20 18:34   ` [PATCH v3 2/9] app/testpmd: fix packet count in ieee15888 engine David Marchand
2023-02-24  8:24     ` Singh, Aman Deep
2023-02-20 18:34   ` [PATCH v3 3/9] app/testpmd: rework ieee1588 engine fwd configuration David Marchand
2023-02-28 18:50     ` Ferruh Yigit
2023-02-20 18:34   ` [PATCH v3 4/9] app/testpmd: fix packet transmission in noisy VNF engine David Marchand
2023-02-28 18:51     ` Ferruh Yigit
2023-02-20 18:34   ` [PATCH v3 5/9] app/testpmd: bulk free mbufs David Marchand
2023-02-20 18:45     ` Stephen Hemminger
2023-02-20 18:34   ` [PATCH v3 6/9] app/testpmd: factorize core cycles record David Marchand
2023-02-20 18:35   ` [PATCH v3 7/9] app/testpmd: factorize fwd engine init David Marchand
2023-02-20 18:35   ` [PATCH v3 8/9] app/testpmd: factorize fwd engine Rx David Marchand
2023-02-20 18:35   ` [PATCH v3 9/9] app/testpmd: factorize fwd engine Tx David Marchand
2023-02-28 18:35     ` Ferruh Yigit
2023-02-28 18:54   ` [PATCH v3 0/9] Testpmd code cleanup Ferruh Yigit

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).