diff mbox

[2/3] linux-gen: dpdk: bulk alloc mbufs in tx

Message ID 1472653448-23947-2-git-send-email-matias.elo@nokia.com
State Accepted
Commit 95b2d51738e97067f2e2423a83dd077b34c51b8f
Headers show

Commit Message

Elo, Matias (Nokia - FI/Espoo) Aug. 31, 2016, 2:24 p.m. UTC
Bulk alloc mbufs in dpdk_send(). Combined with dpdk mempool cache size
increase this improves odp_l2fwd throughput by 5-10 %.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 platform/linux-generic/include/odp_packet_dpdk.h |  2 +-
 platform/linux-generic/pktio/dpdk.c              | 28 ++++++++++++------------
 2 files changed, 15 insertions(+), 15 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_dpdk.h b/platform/linux-generic/include/odp_packet_dpdk.h
index 31e1ed7..c63685e 100644
--- a/platform/linux-generic/include/odp_packet_dpdk.h
+++ b/platform/linux-generic/include/odp_packet_dpdk.h
@@ -20,7 +20,7 @@ 
 #define DPDK_MEMORY_MB 512
 #define DPDK_NB_MBUF 16384
 #define DPDK_MBUF_BUF_SIZE RTE_MBUF_DEFAULT_BUF_SIZE
-#define DPDK_MEMPOOL_CACHE_SIZE 32
+#define DPDK_MEMPOOL_CACHE_SIZE 64
 #define DPDK_NM_RX_DESC  128
 #define DPDK_NM_TX_DESC  512
 
diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 0a800b7..99eb868 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -826,36 +826,36 @@  static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry,
 			      const odp_packet_t pkt_table[], uint16_t num)
 {
 	pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
-	int i;
+	int i, j;
 	char *data;
 	uint16_t pkt_len;
 
+	if (odp_unlikely((rte_pktmbuf_alloc_bulk(pkt_dpdk->pkt_pool,
+						 mbuf_table, num)))) {
+		ODP_ERR("Failed to alloc mbuf\n");
+		return 0;
+	}
 	for (i = 0; i < num; i++) {
 		pkt_len = odp_packet_len(pkt_table[i]);
 
 		if (pkt_len > pkt_dpdk->mtu) {
 			if (i == 0)
 				__odp_errno = EMSGSIZE;
-			break;
-		}
-
-		mbuf_table[i] = rte_pktmbuf_alloc(pkt_dpdk->pkt_pool);
-		if (mbuf_table[i] == NULL) {
-			ODP_ERR("Failed to alloc mbuf\n");
-			break;
+			goto fail;
 		}
 
+		/* Packet always fits in mbuf */
 		data = rte_pktmbuf_append(mbuf_table[i], pkt_len);
 
-		if (data == NULL) {
-			ODP_ERR("Failed to append mbuf\n");
-			rte_pktmbuf_free(mbuf_table[i]);
-			break;
-		}
-
 		odp_packet_copy_to_mem(pkt_table[i], 0, pkt_len, data);
 	}
 	return i;
+
+fail:
+	for (j = i; j < num; j++)
+		rte_pktmbuf_free(mbuf_table[j]);
+
+	return i;
 }
 
 static int dpdk_recv(pktio_entry_t *pktio_entry, int index,