* [PATCH 19.11] examples/vhost: fix retry logic on Rx path
@ 2022-07-15 15:31 Yuan Wang
2022-08-03 9:51 ` Christian Ehrhardt
0 siblings, 1 reply; 2+ messages in thread
From: Yuan Wang @ 2022-07-15 15:31 UTC (permalink / raw)
To: christian.ehrhardt, stable
Cc: maxime.coquelin, chenbo.xia, jiayu.hu, cheng1.jiang, qiming.yang,
Yuan Wang
[ 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@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 19.11] examples/vhost: fix retry logic on Rx path
2022-07-15 15:31 [PATCH 19.11] examples/vhost: fix retry logic on Rx path Yuan Wang
@ 2022-08-03 9:51 ` Christian Ehrhardt
0 siblings, 0 replies; 2+ messages in thread
From: Christian Ehrhardt @ 2022-08-03 9:51 UTC (permalink / raw)
To: Yuan Wang
Cc: stable, maxime.coquelin, chenbo.xia, jiayu.hu, cheng1.jiang, qiming.yang
On Fri, Jul 15, 2022 at 9:43 AM Yuan Wang <yuanx.wang@intel.com> wrote:
>
> [ upstream commit 1907ce4baec392a750fbeba5e946920b2f00ae73 ]
Thank you,
your patch was in time, but sadly a few fell through the cracks on my side.
(and many more just arrived too late).
Your patch is applied to the WIP branch now, but currently testing of
-rc1 is going on which I do not want to disrupt.
If we need an -rc2 anyway or generally have the time to do an -rc2
without too much disruption it will be in 19.11.13, otherwise it is
already queued for 19.11.14
> 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@intel.com>
> Reviewed-by: Chenbo Xia <chenbo.xia@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
>
--
Christian Ehrhardt
Senior Staff Engineer, Ubuntu Server
Canonical Ltd
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-03 9:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 15:31 [PATCH 19.11] examples/vhost: fix retry logic on Rx path Yuan Wang
2022-08-03 9:51 ` Christian Ehrhardt
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).