Skip to contentSkip to conversation

kni: optimizing the rte_kni_rx_burst

PATCH Applied Hemant Agrawal 2 participants 5 messages Jul 23, 2014 – Feb 24, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kni: optimizing the rte_kni_rx_burst

The current implementation of rte_kni_rx_burst polls the fifo for buffers. Irrespective of success or failure, it allocates the mbuf and try to put them into the alloc_q if the buffers are not added to alloc_q, it frees them.
This waste lots of cpu cycles in allocating and freeing the buffers if alloc_q is full.

The logic has been changed to:
1. Initially allocand add buffer(burstsize) to alloc_q
2. Add buffers to alloc_q only when you are pulling out the buffers.

---
 lib/librte_kni/rte_kni.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_kni/rte_kni.c +6 -2
index 76feef4..01e85f8 100644
@@ -263,6 +263,9 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 
 	ctx->in_use = 1;
 
+	/* Allocate mbufs and then put them into alloc_q */
+	kni_allocate_mbufs(ctx);
+
 	return ctx;
 
 fail:
@@ -369,8 +372,9 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num)
 {
 	unsigned ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num);
 
-	/* Allocate mbufs and then put them into alloc_q */
-	kni_allocate_mbufs(kni);
+	/* If buffers removed, allocate mbufs and then put them into alloc_q */
+	if(ret)
+		kni_allocate_mbufs(kni);
 
 	return ret;
 }
Signature · 1 line
1.7.9.6

A message that is not in the archive (sent off-list or not yet received): 14060979121185-git-send-email-Hemant-KZfg59tc24xl57MIdRCFDg@public.gmane.org

#2 lore raw

Is there anyone interested in KNI to review this patch please?

2014-07-23 12:15, Hemant Agrawal:

Quoted 40 lines

The current implementation of rte_kni_rx_burst polls the fifo for buffers. Irrespective of success or failure, it allocates the mbuf and try to put them into the alloc_q if the buffers are not added to alloc_q, it frees them.
This waste lots of cpu cycles in allocating and freeing the buffers if alloc_q is full.

The logic has been changed to:
1. Initially allocand add buffer(burstsize) to alloc_q
2. Add buffers to alloc_q only when you are pulling out the buffers.

---
 lib/librte_kni/rte_kni.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_kni/rte_kni.c +6 -2
index 76feef4..01e85f8 100644
@@ -263,6 +263,9 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 
 	ctx->in_use = 1;
 
+	/* Allocate mbufs and then put them into alloc_q */
+	kni_allocate_mbufs(ctx);
+
 	return ctx;
 
 fail:
@@ -369,8 +372,9 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num)
 {
 	unsigned ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num);
 
-	/* Allocate mbufs and then put them into alloc_q */
-	kni_allocate_mbufs(kni);
+	/* If buffers removed, allocate mbufs and then put them into alloc_q */
+	if(ret)
+		kni_allocate_mbufs(kni);
 
 	return ret;
 }
#3 lore raw

Ping

2014-11-11 23:58, Thomas Monjalon:

Quoted 44 lines

Is there anyone interested in KNI to review this patch please?

2014-07-23 12:15, Hemant Agrawal:

Quoted 40 lines

The current implementation of rte_kni_rx_burst polls the fifo for buffers. Irrespective of success or failure, it allocates the mbuf and try to put them into the alloc_q if the buffers are not added to alloc_q, it frees them.
This waste lots of cpu cycles in allocating and freeing the buffers if alloc_q is full.

The logic has been changed to:
1. Initially allocand add buffer(burstsize) to alloc_q
2. Add buffers to alloc_q only when you are pulling out the buffers.

---
 lib/librte_kni/rte_kni.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_kni/rte_kni.c +6 -2
index 76feef4..01e85f8 100644
@@ -263,6 +263,9 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 
 	ctx->in_use = 1;
 
+	/* Allocate mbufs and then put them into alloc_q */
+	kni_allocate_mbufs(ctx);
+
 	return ctx;
 
 fail:
@@ -369,8 +372,9 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned num)
 {
 	unsigned ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num);
 
-	/* Allocate mbufs and then put them into alloc_q */
-	kni_allocate_mbufs(kni);
+	/* If buffers removed, allocate mbufs and then put them into alloc_q */
+	if(ret)
+		kni_allocate_mbufs(kni);
 
 	return ret;
 }
Reviewed-by Jay Rolette
#4 lore raw

2014-11-26 22:20, Thomas Monjalon:

Quoted 12 lines

Ping

2014-11-11 23:58, Thomas Monjalon:

Quoted 9 lines

Is there anyone interested in KNI to review this patch please?

2014-07-23 12:15, Hemant Agrawal:

Quoted 5 lines

The current implementation of rte_kni_rx_burst polls the fifo for buffers. Irrespective of success or failure, it allocates the mbuf and try to put them into the alloc_q if the buffers are not added to alloc_q, it frees them.
This waste lots of cpu cycles in allocating and freeing the buffers if alloc_q is full.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

The logic has been changed to:
1. Initially allocand add buffer(burstsize) to alloc_q
2. Add buffers to alloc_q only when you are pulling out the buffers.

From http://dpdk.org/ml/archives/dev/2015-January/011771.html, Jay said

"The patch looks good from a DPDK 1.6r2 viewpoint. We saw the same behavior in our app and ended up avoiding it higher in the stack (in our code)."

Signature · 1 line
Thomas
#5 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

2014-07-23 12:15, Hemant Agrawal:

Quoted 9 lines

The current implementation of rte_kni_rx_burst polls the fifo for buffers. Irrespective of success or failure, it allocates the mbuf and try to put them into the alloc_q if the buffers are not added to alloc_q, it frees them.
This waste lots of cpu cycles in allocating and freeing the buffers if alloc_q is full.

The logic has been changed to:
1. Initially allocand add buffer(burstsize) to alloc_q
2. Add buffers to alloc_q only when you are pulling out the buffers.

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

From http://dpdk.org/ml/archives/dev/2015-January/011771.html, Jay said "The patch looks good from a DPDK 1.6r2 viewpoint. We saw the same behavior in our app and ended up avoiding it higher in the stack (in our code)."

Applied, thanks