@samitouri / QOSamiQemu / commits / 2c943949d7

vhost: move busyloop timeout initialization to vhost_virtqueue_init()

Let's all per-virtqueue initializations be in one place. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com> Reviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Lei Yang <leiyang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260420200339.708640-18-vsementsov@yandex-team.ru>

Vladimir Sementsov-Ogievskiy committed Apr 20, 2026 at 23:03 UTC 2c943949d76b9b273de1e4b0f42d3671b8240a37
1 file changed +12 -13
hw/virtio/vhost.c
+12 -13
@@ -1496,7 +1496,8 @@ static void vhost_virtqueue_error_notifier(EventNotifier *n)
1496 }
1497
1498 static int vhost_virtqueue_init(struct vhost_dev *dev,
1499 - struct vhost_virtqueue *vq, int n)
1499 + struct vhost_virtqueue *vq, int n,
1500 + bool busyloop_timeout)
1501 {
1502 int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, n);
1503 struct vhost_vring_file file = {
@@ -1533,6 +1534,14 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
1534 vhost_virtqueue_error_notifier);
1535 }
1536
1537 + if (busyloop_timeout) {
1538 + r = vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeout);
1539 + if (r < 0) {
1540 + VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout");
1541 + goto fail_err;
1542 + }
1543 + }
1544 +
1545 return 0;
1546
1547 fail_err:
@@ -1611,24 +1620,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
1620 }
1621
1622 for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) {
1614 - r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);
1623 + r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i,
1624 + busyloop_timeout);
1625 if (r < 0) {
1626 error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i);
1627 goto fail;
1628 }
1629 }
1630
1621 - if (busyloop_timeout) {
1622 - for (i = 0; i < hdev->nvqs; ++i) {
1623 - r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,
1624 - busyloop_timeout);
1625 - if (r < 0) {
1626 - error_setg_errno(errp, -r, "Failed to set busyloop timeout");
1627 - goto fail;
1628 - }
1629 - }
1630 - }
1631 -
1631 virtio_features_copy(hdev->_features_ex, features);
1632
1633 hdev->memory_listener = (MemoryListener) {