Skip to contentSkip to conversation

virtio: Fix vring entry number issue

PATCH Superseded Ouyang Changchun 3 participants 8 messages Oct 11, 2014 – Oct 15, 2014 5 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 virtio: Fix vring entry number issue

-- V1 change:
Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring.

It fixes failing to transmit any packet with 1 segment in the circumstance of only 1 descriptor in the vring free list.

-- V2 change:
Refine description, 'vring descriptor' is more accurate than 'vring entry'; Accordingly update test condition (it needs one more descriptor for virtio header) to put packets to transmit queue.

---
 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +8 -2
index 0b10108..c736362 100644
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt + 1;
 		int deq_cnt = RTE_MIN(need, (int)num);
 
 		num -= (deq_cnt > 0) ? deq_cnt : 0;
@@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->pkt.nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt + 1;
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * decriptors to transmit.
+		 */
+		if (need <= 0) {
 			txm = tx_pkts[nb_tx];
 			/* Enqueue Packet buffers */
 			error = virtqueue_enqueue_xmit(txvq, txm);
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1413014735-24693-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v3 1/1 virtio: Fix vring entry number issue

-- V1 change:
Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring.

It fixes failing to transmit any packet with 1 segment in the circumstance of only 1 descriptor in the vring free list.

-- V2 change:
Refine description, 'vring descriptor' is more accurate than 'vring entry'; Accordingly update test condition (it needs one more descriptor for virtio header) to put packets to transmit queue.

-- V3 change:
Resolve compilation issue due to mbuf re-structure.

---
 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +8 -2
index 0b10108..ac44c65 100644
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
 		int deq_cnt = RTE_MIN(need, (int)num);
 
 		num -= (deq_cnt > 0) ? deq_cnt : 0;
@@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->pkt.nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * decriptors to transmit.
+		 */
+		if (need <= 0) {
 			txm = tx_pkts[nb_tx];
 			/* Enqueue Packet buffers */
 			error = virtqueue_enqueue_xmit(txvq, txm);
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1413299561-31263-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#4 lore raw

Hi Olivier,

Any other comments for this v3 patch?

Thanks and regards,
Changchun

Quoted 68 lines

-----Original Message-----
From: Ouyang, Changchun
Sent: Tuesday, October 14, 2014 11:13 PM
To: [email protected]
Cc: Cao, Waterman; Ouyang, Changchun
Subject: [PATCH v3] virtio: Fix vring entry number issue

-- V1 change:
Fix one issue in virtio TX: it needs one more vring descriptor to hold the
virtio
header when transmitting packets, it is used later to determine whether to
free
more entries from used vring.

It fixes failing to transmit any packet with 1 segment in the circumstance of
only
1 descriptor in the vring free list.

-- V2 change:
Refine description, 'vring descriptor' is more accurate than 'vring entry'; Accordingly update test condition (it needs one more descriptor for virtio
header) to
put packets to transmit queue.

-- V3 change:
Resolve compilation issue due to mbuf re-structure.

---
 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +2 -1
index 0b10108..ac44c65 100644
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf
 **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ?
 nb_used : VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq-
 >vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
lib/librte_pmd_virtio/virtio_rxtx.c +6 -1
 		int deq_cnt = RTE_MIN(need, (int)num);
 
 		num -= (deq_cnt > 0) ? deq_cnt : 0;
@@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf
 **tx_pkts, uint16_t nb_pkts)
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->pkt.nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt +
 1;
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * decriptors to transmit.
+		 */
+		if (need <= 0) {
 			txm = tx_pkts[nb_tx];
lib/librte_pmd_virtio/virtio_rxtx.c +0 -1
 			/* Enqueue Packet buffers */
 			error = virtqueue_enqueue_xmit(txvq, txm);
--

1.8.4.2

#5 lore raw

PATCH v4 1/1 virtio: Fix vring entry number issue

In reply to a message not in the archive

Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring.
It fixes failing to transmit any packet with 1 segment in the circumstance of only 1 descriptor in the vring free list.

---
-V4 change:
Relocate those changelog and annotation here.

-V3 change:
Resolve compilation issue due to mbuf re-structure.

-V2 change:
Refine description, 'vring descriptor' is more accurate than 'vring entry'; Accordingly update test condition (it needs one more descriptor for virtio header) to put packets to transmit queue.

-V1 change:
Fix the vring descriptor issue in virtio TX, it needs one more vring descriptor to hold the virtio header.

 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +8 -2
index 0b10108..ac44c65 100644
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
 		int deq_cnt = RTE_MIN(need, (int)num);
 
 		num -= (deq_cnt > 0) ? deq_cnt : 0;
@@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->pkt.nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * decriptors to transmit.
+		 */
+		if (need <= 0) {
 			txm = tx_pkts[nb_tx];
 			/* Enqueue Packet buffers */
 			error = virtqueue_enqueue_xmit(txvq, txm);
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1413302634-848-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#7 lore raw
Quoted 57 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ouyang Changchun
Sent: Tuesday, October 14, 2014 9:04 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4] virtio: Fix vring entry number issue

Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring.
It fixes failing to transmit any packet with 1 segment in the circumstance of
only
1 descriptor in the vring free list.

---

(quoted diff) +0 -3
-V4 change:
  Relocate those changelog and annotation here.
 
-V3 change:
  Resolve compilation issue due to mbuf re-structure.
 
-V2 change:
  Refine description, 'vring descriptor' is more accurate than 'vring entry';
  Accordingly update test condition (it needs one more descriptor for virtio

header) to
put packets to transmit queue.

-V1 change:
Fix the vring descriptor issue in virtio TX, it needs one more vring descriptor to
hold the
virtio header.

 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +2 -1
index 0b10108..ac44c65 100644
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf
 **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used :
 VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
 		int deq_cnt = RTE_MIN(need, (int)num);
lib/librte_pmd_virtio/virtio_rxtx.c +0 -0
 		num -= (deq_cnt > 0) ? deq_cnt : 0;
@@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf
 **tx_pkts, uint16_t nb_pkts)

lib/librte_pmd_virtio/virtio_rxtx.c virtio_xmit_pkts(void *tx_queue, struct rte_mbuf · line 718

Quoted 10 lines
lib/librte_pmd_virtio/virtio_rxtx.c +6 -1
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->pkt.nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * decriptors to transmit.
+		 */
+		if (need <= 0) {

Could we put a branch hint to favor the fast path?

Quoted 5 lines
lib/librte_pmd_virtio/virtio_rxtx.c +0 -0
 			txm = tx_pkts[nb_tx];
 			/* Enqueue Packet buffers */

error = virtqueue_enqueue_xmit(txvq, txm);
--
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F2BCA95-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#9 lore raw

Hi Huawei,
I have v5 patch for this comment.
Thanks,
Changchun

Quoted 85 lines

-----Original Message-----
From: Xie, Huawei
Sent: Wednesday, October 15, 2014 12:26 AM
To: Ouyang, Changchun; [email protected]
Subject: RE: [dpdk-dev] [PATCH v4] virtio: Fix vring entry number issue

Quoted 2 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ouyang

Changchun

Quoted 5 lines

Sent: Tuesday, October 14, 2014 9:04 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4] virtio: Fix vring entry number issue

Fix one issue in virtio TX: it needs one more vring descriptor to hold the

virtio

Quoted 1 line

header when transmitting packets, it is used later to determine whether

to free

Quoted 35 lines

more entries from used vring.
It fixes failing to transmit any packet with 1 segment in the
circumstance of only
1 descriptor in the vring free list.

---

(quoted diff) +0 -3
-V4 change:
  Relocate those changelog and annotation here.
 
-V3 change:
  Resolve compilation issue due to mbuf re-structure.
 
-V2 change:
  Refine description, 'vring descriptor' is more accurate than 'vring entry';
  Accordingly update test condition (it needs one more descriptor for

virtio
header) to
put packets to transmit queue.

-V1 change:
Fix the vring descriptor issue in virtio TX, it needs one more vring
descriptor to hold the
virtio header.

 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +0 -0
index 0b10108..ac44c65 100644

lib/librte_pmd_virtio/virtio_rxtx.c virtio_xmit_pkts(void *tx_queue, struct rte_mbuf · line 700

Quoted 2 lines
lib/librte_pmd_virtio/virtio_rxtx.c +0 -0
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf
 **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ?

nb_used :

Quoted 11 lines
lib/librte_pmd_virtio/virtio_rxtx.c +2 -1
 VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->pkt.nb_segs - txvq->vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
 		int deq_cnt = RTE_MIN(need, (int)num);

num -= (deq_cnt > 0) ? deq_cnt : 0; @@ -708,7 +709,12 @@
virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)

lib/librte_pmd_virtio/virtio_rxtx.c virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)

Quoted 5 lines
lib/librte_pmd_virtio/virtio_rxtx.c +1 -1
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->pkt.nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt +

1;

lib/librte_pmd_virtio/virtio_rxtx.c virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) · line 717

Quoted 5 lines
lib/librte_pmd_virtio/virtio_rxtx.c +5 -0
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * decriptors to transmit.
+		 */
+		if (need <= 0) {

Could we put a branch hint to favor the fast path?

Quoted 5 lines
lib/librte_pmd_virtio/virtio_rxtx.c +0 -1
 			txm = tx_pkts[nb_tx];
 			/* Enqueue Packet buffers */
 			error = virtqueue_enqueue_xmit(txvq, txm);
--

1.8.4.2

#10 lore raw

PATCH v5 1/1 virtio: Fix vring entry number issue

In reply to a message not in the archive

Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring.
It fixes failing to transmit any packet with 1 segment in the circumstance of only 1 descriptor in the vring free list.

---

-V5 change:
Use 'likely' to hint compiler to generate favorable codes.

-V4 change:
Relocate those changelog and annotation here.

-V3 change:
Resolve compilation issue due to mbuf re-structure.

-V2 change:
Refine description, 'vring descriptor' is more accurate than 'vring entry'; Accordingly update test condition (it needs one more descriptor for virtio header) to put packets to transmit queue.

-V1 change:
Fix the vring descriptor issue in virtio TX, it needs one more vring descriptor to hold the virtio header.

 lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_pmd_virtio/virtio_rxtx.c +8 -2
index ad6401c..3f6bad2 100644
@@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ);
 
 	while (nb_tx < nb_pkts) {
-		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt;
+		/* Need one more descriptor for virtio header. */
+		int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
 		int deq_cnt = RTE_MIN(need, (int)num);
 
 		num -= (deq_cnt > 0) ? deq_cnt : 0;
@@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 			deq_cnt--;
 		}
 
-		if (tx_pkts[nb_tx]->nb_segs <= txvq->vq_free_cnt) {
+		need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;
+		/*
+		 * Zero or negative value indicates it has enough free
+		 * descriptors to use for transmitting.
+		 */
+		if (likely(need <= 0)) {
 			txm = tx_pkts[nb_tx];
 			/* Enqueue Packet buffers */
 			error = virtqueue_enqueue_xmit(txvq, txm);
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1413342660-17894-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#12 lore raw

2014-10-15 11:11, Ouyang Changchun:

Quoted 8 lines

Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring.
It fixes failing to transmit any packet with 1 segment in the circumstance of only 1 descriptor in the vring free list.

Applied

Thanks

Signature · 1 line
Thomas