diff mbox series

[07/10] net/enetc: use bulk alloc in Rx refill ring

Message ID 20200302143209.11854-8-hemant.agrawal@nxp.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series net/enetc: optimization and cleanup | expand

Checks

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

Commit Message

Hemant Agrawal March 2, 2020, 2:32 p.m. UTC
From: Alex Marginean <alexandru.marginean@nxp.com>

Since we know in advance that we're going to fill in multiple descriptors
it's convenient to allocate the buffers in batches.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
---
 drivers/net/enetc/enetc_rxtx.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/enetc/enetc_rxtx.c b/drivers/net/enetc/enetc_rxtx.c
index 262ed8a0f..8b85c5371 100644
--- a/drivers/net/enetc/enetc_rxtx.c
+++ b/drivers/net/enetc/enetc_rxtx.c
@@ -14,6 +14,8 @@ 
 #include "enetc.h"
 #include "enetc_logs.h"
 
+#define ENETC_RXBD_BUNDLE 16 /* Number of buffers to allocate at once */
+
 static int
 enetc_clean_tx_ring(struct enetc_bdr *tx_ring)
 {
@@ -107,15 +109,25 @@  enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
 {
 	struct enetc_swbd *rx_swbd;
 	union enetc_rx_bd *rxbd;
-	int i, j;
+	int i, j, k = ENETC_RXBD_BUNDLE;
+	struct rte_mbuf *m[ENETC_RXBD_BUNDLE];
+	struct rte_mempool *mb_pool;
 
 	i = rx_ring->next_to_use;
+	mb_pool = rx_ring->mb_pool;
 	rx_swbd = &rx_ring->q_swbd[i];
 	rxbd = ENETC_RXBD(*rx_ring, i);
 	for (j = 0; j < buff_cnt; j++) {
-		rx_swbd->buffer_addr = (void *)(uintptr_t)
-			rte_cpu_to_le_64((uint64_t)(uintptr_t)
-					rte_pktmbuf_alloc(rx_ring->mb_pool));
+		/* bulk alloc for the next up to 8 BDs */
+		if (k == ENETC_RXBD_BUNDLE) {
+			k = 0;
+			int m_cnt = RTE_MIN(buff_cnt - j, ENETC_RXBD_BUNDLE);
+
+			if (rte_pktmbuf_alloc_bulk(mb_pool, m, m_cnt))
+				return -1;
+		}
+
+		rx_swbd->buffer_addr = m[k];
 		rxbd->w.addr = (uint64_t)(uintptr_t)
 			       rx_swbd->buffer_addr->buf_iova +
 			       rx_swbd->buffer_addr->data_off;
@@ -124,6 +136,7 @@  enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
 		rx_swbd++;
 		rxbd++;
 		i++;
+		k++;
 		if (unlikely(i == rx_ring->bd_count)) {
 			i = 0;
 			rxbd = ENETC_RXBD(*rx_ring, 0);