[PATCH 17/33] vhost: move busyloop timeout initialization to vhost_virtqueue_init()

Vladimir Sementsov-Ogievskiy posted 33 patches 3 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, Jason Wang <jasowang@redhat.com>, Fam Zheng <fam@euphon.net>, "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH 17/33] vhost: move busyloop timeout initialization to vhost_virtqueue_init()
Posted by Vladimir Sementsov-Ogievskiy 3 months ago
Let's all per-virtqueue initializations be in one place.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/virtio/vhost.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index a3620c82d8..a8f8b85012 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1489,7 +1489,8 @@ static void vhost_virtqueue_error_notifier(EventNotifier *n)
 }
 
 static int vhost_virtqueue_init(struct vhost_dev *dev,
-                                struct vhost_virtqueue *vq, int n)
+                                struct vhost_virtqueue *vq, int n,
+                                bool busyloop_timeout)
 {
     int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, n);
     struct vhost_vring_file file = {
@@ -1526,6 +1527,14 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
                                    vhost_virtqueue_error_notifier);
     }
 
+    if (busyloop_timeout) {
+        r = vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeout);
+        if (r < 0) {
+            VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout");
+            goto fail_err;
+        }
+    }
+
     return 0;
 
 fail_err:
@@ -1589,24 +1598,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
     }
 
     for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) {
-        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);
+        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i,
+                                 busyloop_timeout);
         if (r < 0) {
             error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i);
             goto fail;
         }
     }
 
-    if (busyloop_timeout) {
-        for (i = 0; i < hdev->nvqs; ++i) {
-            r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,
-                                                     busyloop_timeout);
-            if (r < 0) {
-                error_setg_errno(errp, -r, "Failed to set busyloop timeout");
-                goto fail;
-            }
-        }
-    }
-
     hdev->_features = features;
 
     hdev->memory_listener = (MemoryListener) {
-- 
2.48.1
Re: [PATCH 17/33] vhost: move busyloop timeout initialization to vhost_virtqueue_init()
Posted by Raphael Norwitz 1 month ago
Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>

On Wed, Aug 13, 2025 at 12:56 PM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> Let's all per-virtqueue initializations be in one place.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/vhost.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index a3620c82d8..a8f8b85012 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1489,7 +1489,8 @@ static void vhost_virtqueue_error_notifier(EventNotifier *n)
>  }
>
>  static int vhost_virtqueue_init(struct vhost_dev *dev,
> -                                struct vhost_virtqueue *vq, int n)
> +                                struct vhost_virtqueue *vq, int n,
> +                                bool busyloop_timeout)
>  {
>      int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, n);
>      struct vhost_vring_file file = {
> @@ -1526,6 +1527,14 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
>                                     vhost_virtqueue_error_notifier);
>      }
>
> +    if (busyloop_timeout) {
> +        r = vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeout);
> +        if (r < 0) {
> +            VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout");
> +            goto fail_err;
> +        }
> +    }
> +
>      return 0;
>
>  fail_err:
> @@ -1589,24 +1598,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
>      }
>
>      for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) {
> -        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);
> +        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i,
> +                                 busyloop_timeout);
>          if (r < 0) {
>              error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i);
>              goto fail;
>          }
>      }
>
> -    if (busyloop_timeout) {
> -        for (i = 0; i < hdev->nvqs; ++i) {
> -            r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,
> -                                                     busyloop_timeout);
> -            if (r < 0) {
> -                error_setg_errno(errp, -r, "Failed to set busyloop timeout");
> -                goto fail;
> -            }
> -        }
> -    }
> -
>      hdev->_features = features;
>
>      hdev->memory_listener = (MemoryListener) {
> --
> 2.48.1
>
>