virtio-blk: Configure all host notifiers in a single MR transaction

This allows the virtio-blk-pci device to batch the setup of all its
host notifiers. This significantly improves boot time of VMs with a
high number of vCPUs, e.g. from 3m26.186s down to 0m58.023s for a
pseries machine with 384 vCPUs.

Note that memory_region_transaction_commit() must be called before
virtio_bus_cleanup_host_notifier() because the latter might close
ioeventfds that the transaction still assumes to be around when it
commits.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <20210407143501.244343-3-groug@kaod.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Greg Kurz 2021-04-07 16:34:59 +02:00 committed by Michael S. Tsirkin
parent 570fe439e5
commit d0267da614
1 changed files with 25 additions and 0 deletions

View File

@ -198,19 +198,30 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
goto fail_guest_notifiers; goto fail_guest_notifiers;
} }
memory_region_transaction_begin();
/* Set up virtqueue notify */ /* Set up virtqueue notify */
for (i = 0; i < nvqs; i++) { for (i = 0; i < nvqs; i++) {
r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, true); r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, true);
if (r != 0) { if (r != 0) {
int j = i;
fprintf(stderr, "virtio-blk failed to set host notifier (%d)\n", r); fprintf(stderr, "virtio-blk failed to set host notifier (%d)\n", r);
while (i--) { while (i--) {
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
}
memory_region_transaction_commit();
while (j--) {
virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
} }
goto fail_host_notifiers; goto fail_host_notifiers;
} }
} }
memory_region_transaction_commit();
s->starting = false; s->starting = false;
vblk->dataplane_started = true; vblk->dataplane_started = true;
trace_virtio_blk_data_plane_start(s); trace_virtio_blk_data_plane_start(s);
@ -246,8 +257,15 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
return 0; return 0;
fail_aio_context: fail_aio_context:
memory_region_transaction_begin();
for (i = 0; i < nvqs; i++) { for (i = 0; i < nvqs; i++) {
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
}
memory_region_transaction_commit();
for (i = 0; i < nvqs; i++) {
virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
} }
fail_host_notifiers: fail_host_notifiers:
@ -312,8 +330,15 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
aio_context_release(s->ctx); aio_context_release(s->ctx);
memory_region_transaction_begin();
for (i = 0; i < nvqs; i++) { for (i = 0; i < nvqs; i++) {
virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
}
memory_region_transaction_commit();
for (i = 0; i < nvqs; i++) {
virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
} }