Skip to contentSkip to conversation

virtio: fix rx ring descriptor starvation

PATCH In review Tom Kiely 6 participants 18 messages Nov 13, 2015 – Mar 10, 2016 Network drivers

lore
Share & tools
lore

Tom Kiely

author
#0 lore raw

PATCH 1/1 virtio: fix rx ring descriptor starvation

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
 drivers/net/virtio/virtio_rxtx.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +4 -2
index 5770fa2..a95e234 100644
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	if (likely(num > DESC_PER_CACHELINE))
 		num = num - ((rxvq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
 
-	if (num == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (num == 0 && virtqueue_full(rxvq))
 		return 0;
 
 	num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 
 	virtio_rmb();
 
-	if (nb_used == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (nb_used == 0 && virtqueue_full(rxvq))
 		return 0;
 
 	PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
Signature · 1 line
1.7.10.4
#1 lore raw

Any review, please?

2015-11-13 09:30, Tom Kiely:

Quoted 9 lines

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

#2 lore raw
Quoted 1 line · Thomas Monjalon

Any review, please?

Huawei, would you review it? Sorry that I've not read too much code about virtio PMD driver yet.

	--yliu
Quoted 10 lines

2015-11-13 09:30, Tom Kiely:

Quoted 9 lines

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

#3 lore raw
Quoted 4 lines · Yuanhan Liu
Quoted 1 line · Thomas Monjalon

Any review, please?

Huawei, would you review it? Sorry that I've not read too much code about virtio PMD driver yet.

Np. will do it by end of this week.

Quoted 14 lines
	--yliu
Quoted 10 lines

2015-11-13 09:30, Tom Kiely:

Quoted 9 lines

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

#4 lore raw
In reply to Tom Kiely
Quoted 18 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
 drivers/net/virtio/virtio_rxtx.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) · line 590

Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	if (likely(num > DESC_PER_CACHELINE))
 		num = num - ((rxvq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
 
-	if (num == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

    num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

    num == 0 && rxvq->vq_free_cnt == 0

?

Quoted 13 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
 		return 0;
 
 	num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 
 	virtio_rmb();
 
-	if (nb_used == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (nb_used == 0 && virtqueue_full(rxvq))
 		return 0;
 
 	PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
#5 lore raw
Quoted 27 lines · Huawei
Quoted 18 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
 drivers/net/virtio/virtio_rxtx.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) · line 590

Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	if (likely(num > DESC_PER_CACHELINE))
 		num = num - ((rxvq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
 
-	if (num == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 5 lines
    num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

    num == 0 && rxvq->vq_free_cnt == 0

?

Tom:
Any further progress?

Quoted 14 lines
Quoted 13 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
 		return 0;
 
 	num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 
 	virtio_rmb();
 
-	if (nb_used == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (nb_used == 0 && virtqueue_full(rxvq))
 		return 0;
 
 	PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
author
#6 lore raw

Hi,
Sorry for the delay. I have been occupied on another critical issue.
I'll look at this today.
Tom

Quoted 48 lines · Huawei
Quoted 27 lines · Huawei
Quoted 18 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
  drivers/net/virtio/virtio_rxtx.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) · line 590

Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
  	if (likely(num > DESC_PER_CACHELINE))
  		num = num - ((rxvq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
 
-	if (num == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 5 lines
     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

     num == 0 && rxvq->vq_free_cnt == 0

?

Tom:
Any further progress?

Quoted 13 lines
Quoted 13 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
  		return 0;
 
  	num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 
  	virtio_rmb();
 
-	if (nb_used == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (nb_used == 0 && virtqueue_full(rxvq))
  		return 0;
 
  	PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
author
#7 lore raw
In reply to Xie, Huawei
Quoted 27 lines · Huawei
Quoted 18 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
  drivers/net/virtio/virtio_rxtx.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) · line 590

Quoted 6 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
  	if (likely(num > DESC_PER_CACHELINE))
  		num = num - ((rxvq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
 
-	if (num == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 4 lines
     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

     num == 0 && rxvq->vq_free_cnt == 0

Yes we could do that but I don't see a good reason to wait until the vq_free_cnt == vq_nentries before attempting the refill. The existing code will attempt refill even if only 1 packet was received and the free count is small. To me it seems safer to extend that to try refill even if no packet was received but the free count is non-zero.

Tom

Quoted 13 lines
Quoted 13 lines
drivers/net/virtio/virtio_rxtx.c +2 -1
  		return 0;
 
  	num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 
  	virtio_rmb();
 
-	if (nb_used == 0)
+	/* Refill free descriptors even if no pkts recvd */
+	if (nb_used == 0 && virtqueue_full(rxvq))
  		return 0;
 
  	PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
#8 lore raw
Quoted 36 lines · Tom Kiely
Quoted 29 lines · Huawei
Quoted 19 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
  drivers/net/virtio/virtio_rxtx.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf · line 592

Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
 **rx_pkts, uint16_t nb_pkts)
      if (likely(num > DESC_PER_CACHELINE))
          num = num - ((rxvq->vq_used_cons_idx + num) %
 DESC_PER_CACHELINE);
  -    if (num == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 4 lines
     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

     num == 0 && rxvq->vq_free_cnt == 0
Quoted 7 lines

Yes we could do that but I don't see a good reason to wait until the vq_free_cnt == vq_nentries
before attempting the refill. The existing code will attempt refill even if only 1 packet was received
and the free count is small. To me it seems safer to extend that to try refill even if no packet was received
but the free count is non-zero.

The existing code attempt to refill only if 1 packet was received.

If we want to refill even no packet was received, then the strict condition should be

    num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

The safer condition, what you want to use, should be

    num == 0 && !virtqueue_full(...)
rather than
    num == 0 && virtqueue_full(...)

We could simplify things a bit, just remove this check, if the following receiving code already takes care of the "num == 0" condition.

I find virtqueue_full is confusing, maybe we could change it to some other meaningful name.

Quoted 14 lines

Tom

Quoted 9 lines
Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
          return 0;
        num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
        virtio_rmb();
  -    if (nb_used == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (nb_used == 0 && virtqueue_full(rxvq))
          return 0;
        PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
#9 lore raw
Quoted 55 lines · Huawei
Quoted 36 lines · Tom Kiely
Quoted 29 lines · Huawei
Quoted 19 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
  drivers/net/virtio/virtio_rxtx.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf · line 592

Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
 **rx_pkts, uint16_t nb_pkts)
      if (likely(num > DESC_PER_CACHELINE))
          num = num - ((rxvq->vq_used_cons_idx + num) %
 DESC_PER_CACHELINE);
  -    if (num == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 4 lines
     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

     num == 0 && rxvq->vq_free_cnt == 0
Quoted 7 lines

Yes we could do that but I don't see a good reason to wait until the vq_free_cnt == vq_nentries
before attempting the refill. The existing code will attempt refill even if only 1 packet was received
and the free count is small. To me it seems safer to extend that to try refill even if no packet was received
but the free count is non-zero.

The existing code attempt to refill only if 1 packet was received.

If we want to refill even no packet was received, then the strict condition should be

    num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

The safer condition, what you want to use, should be

    num == 0 && !virtqueue_full(...)
rather than
    num == 0 && virtqueue_full(...)
Quoted 9 lines

We could simplify things a bit, just remove this check, if the following receiving code already takes care of the "num == 0" condition.

I find virtqueue_full is confusing, maybe we could change it to some other meaningful name.

Quoted 3 lines

Tom

Ping.

Tom and Huawei, what is the status of this patch? Will there be a V2?

/Bruce

#10 lore raw
In reply to Xie, Huawei
Quoted 50 lines · Huawei
Quoted 36 lines · Tom Kiely
Quoted 29 lines · Huawei
Quoted 19 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
  drivers/net/virtio/virtio_rxtx.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf · line 592

Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
 **rx_pkts, uint16_t nb_pkts)
      if (likely(num > DESC_PER_CACHELINE))
          num = num - ((rxvq->vq_used_cons_idx + num) %
 DESC_PER_CACHELINE);
  -    if (num == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 4 lines
     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

     num == 0 && rxvq->vq_free_cnt == 0
Quoted 7 lines

Yes we could do that but I don't see a good reason to wait until the vq_free_cnt == vq_nentries
before attempting the refill. The existing code will attempt refill even if only 1 packet was received
and the free count is small. To me it seems safer to extend that to try refill even if no packet was received
but the free count is non-zero.

The existing code attempt to refill only if 1 packet was received.

If we want to refill even no packet was received, then the strict condition should be

    num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries
Quoted 9 lines

The safer condition, what you want to use, should be

    num == 0 && !virtqueue_full(...)
rather than
    num == 0 && virtqueue_full(...)

We could simplify things a bit, just remove this check, if the following receiving code already takes care of the "num == 0" condition.

FWIW, I fixed this issue myself by just removing the if(num == 0) checks entirely. I didn't see any benefit in short-circuiting a loop which pretty much does nothing anyway when num == 0. Further, we only hit this case when there's no packets to receive, which means there's probably a few cycles to spare. This is even simpler.

Quoted 18 lines

I find virtqueue_full is confusing, maybe we could change it to some other meaningful name.

Quoted 14 lines

Tom

Quoted 9 lines
Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
          return 0;
        num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
        virtio_rmb();
  -    if (nb_used == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (nb_used == 0 && virtqueue_full(rxvq))
          return 0;
        PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
author
#11 lore raw

Hi,
Sorry I missed the last few messages until now. I'm happy with just
removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Quoted 79 lines · Kyle Larose
Quoted 49 lines · Huawei
Quoted 35 lines · Tom Kiely
Quoted 29 lines · Huawei
Quoted 19 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
   drivers/net/virtio/virtio_rxtx.c |    6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf · line 592

Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
 **rx_pkts, uint16_t nb_pkts)
       if (likely(num > DESC_PER_CACHELINE))
           num = num - ((rxvq->vq_used_cons_idx + num) %
 DESC_PER_CACHELINE);
   -    if (num == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 4 lines
      num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

      num == 0 && rxvq->vq_free_cnt == 0
Quoted 7 lines

Yes we could do that but I don't see a good reason to wait until the vq_free_cnt == vq_nentries
before attempting the refill. The existing code will attempt refill even if only 1 packet was received
and the free count is small. To me it seems safer to extend that to try refill even if no packet was received
but the free count is non-zero.

The existing code attempt to refill only if 1 packet was received.

If we want to refill even no packet was received, then the strict condition should be

     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries
Quoted 8 lines

The safer condition, what you want to use, should be

     num == 0 && !virtqueue_full(...)
rather than
     num == 0 && virtqueue_full(...)

We could simplify things a bit, just remove this check, if the following receiving code already takes care of the "num == 0" condition.

FWIW, I fixed this issue myself by just removing the if(num == 0) checks entirely. I didn't see any benefit in short-circuiting a loop which pretty much does nothing anyway when num == 0. Further, we only hit this case when there's no packets to receive, which means there's probably a few cycles to spare. This is even simpler.

Quoted 15 lines

I find virtqueue_full is confusing, maybe we could change it to some other meaningful name.

Quoted 12 lines

Tom

Quoted 9 lines
Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
           return 0;
         num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
         virtio_rmb();
   -    if (nb_used == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (nb_used == 0 && virtqueue_full(rxvq))
           return 0;
         PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
#12 lore raw
Quoted 7 lines · Tom Kiely

Hi,
Sorry I missed the last few messages until now. I'm happy with
just removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Quoted 66 lines
Quoted 65 lines · Kyle Larose
Quoted 49 lines · Huawei
Quoted 35 lines · Tom Kiely
Quoted 29 lines · Huawei
Quoted 19 lines · Tom Kiely

If all rx descriptors are processed while transient mbuf exhaustion is present, the rx ring ends up with no available descriptors. Thus no packets are received on that ring. Since descriptor refill is performed post rx descriptor processing, in this case no refill is ever subsequently performed resulting in permanent rx traffic drop.

---
   drivers/net/virtio/virtio_rxtx.c |    6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +0 -0
index 5770fa2..a95e234 100644

drivers/net/virtio/virtio_rxtx.c virtio_recv_pkts(void *rx_queue, struct rte_mbuf · line 592

Quoted 7 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -586,7 +586,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
 **rx_pkts, uint16_t nb_pkts)
       if (likely(num > DESC_PER_CACHELINE))
           num = num - ((rxvq->vq_used_cons_idx + num) %
 DESC_PER_CACHELINE);
   -    if (num == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (num == 0 && virtqueue_full(rxvq))

Should the return condition be that no used buffers and we have avail descs in avail ring, i.e,

Quoted 4 lines
      num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries

rather than

      num == 0 && rxvq->vq_free_cnt == 0
Quoted 7 lines

Yes we could do that but I don't see a good reason to wait until the vq_free_cnt == vq_nentries
before attempting the refill. The existing code will attempt refill even if only 1 packet was received
and the free count is small. To me it seems safer to extend that to try refill even if no packet was received
but the free count is non-zero.

The existing code attempt to refill only if 1 packet was received.

If we want to refill even no packet was received, then the strict condition should be

     num == 0 && rxvq->vq_free_cnt != rxvq->vq_nentries
Quoted 9 lines

The safer condition, what you want to use, should be

     num == 0 && !virtqueue_full(...)
rather than
     num == 0 && virtqueue_full(...)

We could simplify things a bit, just remove this check, if the following
receiving code already takes care of the "num == 0" condition.

FWIW, I fixed this issue myself by just removing the if(num == 0) checks entirely. I didn't see any benefit in short-circuiting a loop which pretty much does nothing anyway when num == 0. Further, we only hit this case when there's no packets to receive, which means there's probably a few cycles to spare. This is even simpler.

Yes, as i said, that is the simplest fix.

Quoted 18 lines
Quoted 16 lines
Quoted 16 lines

I find virtqueue_full is confusing, maybe we could change it to some other meaningful name.

Quoted 12 lines

Tom

Quoted 9 lines
Quoted 9 lines
drivers/net/virtio/virtio_rxtx.c +2 -0
           return 0;
         num = virtqueue_dequeue_burst_rx(rxvq, rcv_pkts, len, num);
@@ -683,7 +684,8 @@ virtio_recv_mergeable_pkts(void *rx_queue,
         virtio_rmb();
   -    if (nb_used == 0)
+    /* Refill free descriptors even if no pkts recvd */
+    if (nb_used == 0 && virtqueue_full(rxvq))
           return 0;
         PMD_RX_LOG(DEBUG, "used:%d\n", nb_used);
#13 lore raw
In reply to Tom Kiely
Quoted 6 lines · Tom Kiely

Hi,
Sorry I missed the last few messages until now. I'm happy with
just removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Could you please send the patch?

author
#14 lore raw

Sure.
Tom

Quoted 9 lines · Huawei
Quoted 6 lines · Tom Kiely

Hi,
Sorry I missed the last few messages until now. I'm happy with
just removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Could you please send the patch?

#15 lore raw
Quoted 4 lines · Tom Kiely

Sure.
Tom

Quoted 14 lines
Quoted 12 lines · Huawei
Quoted 7 lines · Tom Kiely

Hi,
Sorry I missed the last few messages until now. I'm happy with
just removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Could you please send the patch?

I should have replied to this earlier. I submitted a patch last week:
http://dpdk.org/dev/patchwork/patch/10904/

#16 lore raw
Quoted 16 lines · Kyle Larose
Quoted 15 lines · Tom Kiely

Sure.
Tom

Quoted 10 lines · Huawei
Quoted 7 lines · Tom Kiely

Hi,
Sorry I missed the last few messages until now. I'm happy with
just removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Could you please send the patch?

I should have replied to this earlier. I submitted a patch last week:
http://dpdk.org/dev/patchwork/patch/10904/

Thanks, Kyle. Unfortunately the patch you submitted is missing your signoff. Can you perhaps resubmit it as a V2 with the necessary sign-off as described in the contributors guide:
http://dpdk.org/doc/guides/contributing/patches.html#commit-messages-body

Huawei or Tom, could one of you guys perhaps review and ack the patch once it's submitted with a signoff?

Thanks,
/Bruce

#17 lore raw
Quoted 21 lines · Bruce Richardson
Quoted 20 lines · Kyle Larose
Quoted 18 lines · Tom Kiely

Sure.
Tom

Quoted 12 lines · Huawei
Quoted 7 lines · Tom Kiely

Hi,
Sorry I missed the last few messages until now. I'm happy with
just removing the "if". Kyle, when you say you fixed it, do you mean that you will push the patch or have already done so ?
Thanks,
Tom

Could you please send the patch?

Quoted 8 lines
Quoted 2 lines

I should have replied to this earlier. I submitted a patch last week:
http://dpdk.org/dev/patchwork/patch/10904/

Thanks, Kyle. Unfortunately the patch you submitted is missing your signoff. Can you perhaps resubmit it as a V2 with the necessary sign-off as described in the contributors guide:
http://dpdk.org/doc/guides/contributing/patches.html#commit-messages-body

Hey Bruce,

Thanks. I signed off, and resubmitted the patch. Hopefully I didn't make any other amateur mistakes this time!

Quoted 5 lines

Huawei or Tom, could one of you guys perhaps review and ack the patch once it's submitted with a signoff?

Thanks,
/Bruce