app/testpmd: allocate txonly packets per bulk
authorPavan Nikhilesh <pbhagavatula@marvell.com>
Tue, 2 Apr 2019 09:53:36 +0000 (09:53 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 5 Apr 2019 17:28:22 +0000 (19:28 +0200)
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>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
app/test-pmd/txonly.c

index 56ca0ad..66e6378 100644 (file)
@@ -268,16 +268,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_pktmbuf_free(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_pktmbuf_free(pkt);
+                               break;
+                       }
+                       pkts_burst[nb_pkt] = pkt;
                }
-               pkts_burst[nb_pkt] = pkt;
        }
 
        if (nb_pkt == 0)