diff mbox series

[RFC,8/8] virtio-scsi: Use virtio_bus_set_host_notifiers()

Message ID 20210325150735.1098387-9-groug@kaod.org (mailing list archive)
State New, archived
Headers show
Series virtio: Improve boot time of virtio-scsi-pci and virtio-blk-pci | expand

Commit Message

Greg Kurz March 25, 2021, 3:07 p.m. UTC
This allows the virtio-scsi-pci device to batch additions and deletions
of host notifiers. This significantly improves boot time of VMs with a
high number of vCPUs, e.g. from 6m13.969s down to 1m4.268s for a pseries
machine with 384 vCPUs.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/scsi/virtio-scsi-dataplane.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

Comments

Stefan Hajnoczi March 29, 2021, 5:28 p.m. UTC | #1
On Thu, Mar 25, 2021 at 04:07:35PM +0100, Greg Kurz wrote:
> This allows the virtio-scsi-pci device to batch additions and deletions
> of host notifiers. This significantly improves boot time of VMs with a
> high number of vCPUs, e.g. from 6m13.969s down to 1m4.268s for a pseries
> machine with 384 vCPUs.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>  hw/scsi/virtio-scsi-dataplane.c | 28 +++++++++++++---------------
>  1 file changed, 13 insertions(+), 15 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox series

Patch

diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c
index 11b53ab767be..eec2b6e19a5b 100644
--- a/hw/scsi/virtio-scsi-dataplane.c
+++ b/hw/scsi/virtio-scsi-dataplane.c
@@ -141,6 +141,7 @@  int virtio_scsi_dataplane_start(VirtIODevice *vdev)
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
     VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
 
     if (s->dataplane_started ||
         s->dataplane_starting ||
@@ -171,12 +172,9 @@  int virtio_scsi_dataplane_start(VirtIODevice *vdev)
 
     vq_init_count++;
 
-    for (i = 0; i < vs->conf.num_queues; i++) {
-        rc = virtio_scsi_set_host_notifier(s, vs->cmd_vqs[i], i + 2);
-        if (rc) {
-            goto fail_host_notifiers;
-        }
-        vq_init_count++;
+    rc = virtio_bus_set_host_notifiers(bus, vs->conf.num_queues, 2, true);
+    if (rc) {
+        goto fail_host_notifiers;
     }
 
     aio_context_acquire(s->ctx);
@@ -196,10 +194,13 @@  int virtio_scsi_dataplane_start(VirtIODevice *vdev)
     return 0;
 
 fail_host_notifiers:
-    for (i = 0; i < vq_init_count; i++) {
-        virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
-        virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
-    }
+    /*
+     * Only host notifiers for ctrl_vq and event_vq can be set at
+     * this point. Notifiers for cmd_vqs[] have been reverted by
+     * virtio_bus_set_host_notifiers() already.
+     */
+    assert(vq_init_count <= 2);
+    virtio_bus_set_host_notifiers(bus, vq_init_count, 0, false);
     k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);
 fail_guest_notifiers:
     s->dataplane_fenced = true;
@@ -215,7 +216,6 @@  void virtio_scsi_dataplane_stop(VirtIODevice *vdev)
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
     VirtIOSCSI *s = VIRTIO_SCSI(vdev);
-    int i;
 
     if (!s->dataplane_started || s->dataplane_stopping) {
         return;
@@ -235,10 +235,8 @@  void virtio_scsi_dataplane_stop(VirtIODevice *vdev)
 
     blk_drain_all(); /* ensure there are no in-flight requests */
 
-    for (i = 0; i < vs->conf.num_queues + 2; i++) {
-        virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
-        virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
-    }
+    virtio_bus_set_host_notifiers(VIRTIO_BUS(qbus), vs->conf.num_queues + 2, 0,
+                                  false);
 
     /* Clean up guest notifier (irq) */
     k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);