[PATCH 19.11] examples/vhost: fix retry logic on Rx path
Yuan Wang
yuanx.wang at intel.com
Fri Jul 15 17:31:35 CEST 2022
[ upstream commit 1907ce4baec392a750fbeba5e946920b2f00ae73 ]
drain_eth_rx() uses rte_vhost_avail_entries() to calculate
the available entries to determine if a retry is required.
However, this function only works with split rings, and
calculating packed rings will return the wrong value and cause
unnecessary retries resulting in a significant performance penalty.
This patch fix that by using the difference between tx/rx burst
as the retry condition.
Fixes: be800696c26e ("examples/vhost: use burst enqueue and dequeue from lib")
Signed-off-by: Yuan Wang <yuanx.wang at intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia at intel.com>
---
examples/vhost/main.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 073668022..ca6e9a332 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1051,24 +1051,6 @@ drain_eth_rx(struct vhost_dev *vdev)
if (!rx_count)
return;
- /*
- * When "enable_retry" is set, here we wait and retry when there
- * is no enough free slots in the queue to hold @rx_count packets,
- * to diminish packet loss.
- */
- if (enable_retry &&
- unlikely(rx_count > rte_vhost_avail_entries(vdev->vid,
- VIRTIO_RXQ))) {
- uint32_t retry;
-
- for (retry = 0; retry < burst_rx_retry_num; retry++) {
- rte_delay_us(burst_rx_delay_time);
- if (rx_count <= rte_vhost_avail_entries(vdev->vid,
- VIRTIO_RXQ))
- break;
- }
- }
-
if (builtin_net_driver) {
enqueue_count = vs_enqueue_pkts(vdev, VIRTIO_RXQ,
pkts, rx_count);
@@ -1076,6 +1058,28 @@ drain_eth_rx(struct vhost_dev *vdev)
enqueue_count = rte_vhost_enqueue_burst(vdev->vid, VIRTIO_RXQ,
pkts, rx_count);
}
+
+ /* Retry if necessary */
+ if (enable_retry && unlikely(enqueue_count < rx_count)) {
+ uint32_t retry = 0;
+
+ while (enqueue_count < rx_count &&
+ retry++ < burst_rx_retry_num) {
+ rte_delay_us(burst_rx_delay_time);
+ if (builtin_net_driver) {
+ enqueue_count += vs_enqueue_pkts(vdev,
+ VIRTIO_RXQ, &pkts[enqueue_count],
+ rx_count - enqueue_count);
+ } else {
+ enqueue_count += rte_vhost_enqueue_burst(
+ vdev->vid,
+ VIRTIO_RXQ,
+ &pkts[enqueue_count],
+ rx_count - enqueue_count);
+ }
+ }
+ }
+
if (enable_stats) {
rte_atomic64_add(&vdev->stats.rx_total_atomic, rx_count);
rte_atomic64_add(&vdev->stats.rx_atomic, enqueue_count);
--
2.25.1
More information about the stable
mailing list