[v3,2/2] app/testpmd: add mempool bulk get for txonly mode

Message ID 20190326122625.10540-2-pbhagavatula@marvell.com
State Superseded, archived
Headers show
Series
  • [v3,1/2] app/testpmd: optimize testpmd txonly mode
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Pavan Nikhilesh Bhagavatula March 26, 2019, 12:27 p.m.
From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Use mempool bulk get ops to alloc burst of packets and process them.
If bulk get fails fallback to rte_mbuf_raw_alloc.

Tested-by: Yingya Han <yingyax.han@intel.com>
Suggested-by: Andrew Rybchenko <arybchenko@solarflare.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 app/test-pmd/txonly.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

Patch

diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 5610e0e42..3ca13e622 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -249,18 +249,33 @@  pkt_burst_transmit(struct fwd_stream *fs)
 	ether_addr_copy(&ports[fs->tx_port].eth_addr, &eth_hdr.s_addr);
 	eth_hdr.ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
 
-	for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
-		pkt = rte_mbuf_raw_alloc(mbp);
-		if (pkt == NULL)
-			break;
-		if (unlikely(!pkt_burst_prepare(pkt, mbp,
-						&eth_hdr, vlan_tci,
-						vlan_tci_outer,
-						ol_flags))) {
-			rte_mempool_put(mbp, pkt);
-			break;
+	if (rte_mempool_get_bulk(mbp, (void **)pkts_burst,
+				nb_pkt_per_burst) == 0) {
+		for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
+			if (unlikely(!pkt_burst_prepare(pkts_burst[nb_pkt], mbp,
+							&eth_hdr, vlan_tci,
+							vlan_tci_outer,
+							ol_flags))) {
+				rte_mempool_put_bulk(mbp,
+						(void **)&pkts_burst[nb_pkt],
+						nb_pkt_per_burst - nb_pkt);
+				break;
+			}
+		}
+	} else {
+		for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
+			pkt = rte_mbuf_raw_alloc(mbp);
+			if (pkt == NULL)
+				break;
+			if (unlikely(!pkt_burst_prepare(pkt, mbp,
+							&eth_hdr, vlan_tci,
+							vlan_tci_outer,
+							ol_flags))) {
+				rte_mempool_put(mbp, pkt);
+				break;
+			}
+			pkts_burst[nb_pkt] = pkt;
 		}
-		pkts_burst[nb_pkt] = pkt;
 	}
 
 	if (nb_pkt == 0)