DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] kni:optimization of rte_kni_rx_burst
@ 2015-02-25 11:48 Hemant Agrawal
  2015-02-25 12:13 ` Olivier Deme
  0 siblings, 1 reply; 9+ messages in thread
From: Hemant Agrawal @ 2015-02-25 11:48 UTC (permalink / raw)
  To: dev

From: Hemant Agrawal <hemant@freescale.com>

if any buffer is read from the tx_q, MAX_BURST buffers will be allocated and attempted to be added to to the alloc_q.
This seems terribly inefficient and it also looks like the alloc_q will quickly fill to its maximum capacity. If the system buffers are low in number, it will reach "out of memory" situation.

This patch allocates the number of buffers as many dequeued from tx_q.

Signed-off-by: Hemant Agrawal <hemant@freescale.com>
---
 lib/librte_kni/rte_kni.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 4e70fa0..4cf8e30 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -128,7 +128,7 @@ struct rte_kni_memzone_pool {
 
 
 static void kni_free_mbufs(struct rte_kni *kni);
-static void kni_allocate_mbufs(struct rte_kni *kni);
+static void kni_allocate_mbufs(struct rte_kni *kni, int num);
 
 static volatile int kni_fd = -1;
 static struct rte_kni_memzone_pool kni_memzone_pool = {
@@ -575,7 +575,7 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num)
 
 	/* If buffers removed, allocate mbufs and then put them into alloc_q */
 	if (ret)
-		kni_allocate_mbufs(kni);
+		kni_allocate_mbufs(kni, ret);
 
 	return ret;
 }
@@ -594,7 +594,7 @@ kni_free_mbufs(struct rte_kni *kni)
 }
 
 static void
-kni_allocate_mbufs(struct rte_kni *kni)
+kni_allocate_mbufs(struct rte_kni *kni, int num)
 {
 	int i, ret;
 	struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM];
@@ -620,7 +620,10 @@ kni_allocate_mbufs(struct rte_kni *kni)
 		return;
 	}
 
-	for (i = 0; i < MAX_MBUF_BURST_NUM; i++) {
+	if (num == 0 || num > MAX_MBUF_BURST_NUM)
+		num = MAX_MBUF_BURST_NUM;
+
+	for (i = 0; i < num; i++) {
 		pkts[i] = rte_pktmbuf_alloc(kni->pktmbuf_pool);
 		if (unlikely(pkts[i] == NULL)) {
 			/* Out of memory */
@@ -636,7 +639,7 @@ kni_allocate_mbufs(struct rte_kni *kni)
 	ret = kni_fifo_put(kni->alloc_q, (void **)pkts, i);
 
 	/* Check if any mbufs not put into alloc_q, and then free them */
-	if (ret >= 0 && ret < i && ret < MAX_MBUF_BURST_NUM) {
+	if (ret >= 0 && ret < i && ret < num) {
 		int j;
 
 		for (j = ret; j < i; j++)
-- 
1.9.1

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

end of thread, other threads:[~2015-02-26 12:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-25 11:48 [dpdk-dev] [PATCH] kni:optimization of rte_kni_rx_burst Hemant Agrawal
2015-02-25 12:13 ` Olivier Deme
2015-02-25 12:24   ` Hemant
2015-02-25 12:28     ` Olivier Deme
2015-02-25 12:38     ` Marc Sune
2015-02-25 12:51       ` Olivier Deme
2015-02-25 13:29       ` Jay Rolette
2015-02-26  7:00         ` Hemant
2015-02-26 12:56           ` Marc Sune

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