From nobody Mon Apr 29 16:43:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517235879166948.5106189844673; Mon, 29 Jan 2018 06:24:39 -0800 (PST) Received: from localhost ([::1]:41083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egAMQ-0004zH-CC for importer@patchew.org; Mon, 29 Jan 2018 09:24:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egAJ9-0002fl-95 for qemu-devel@nongnu.org; Mon, 29 Jan 2018 09:21:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egAJ7-0007Wy-Bn for qemu-devel@nongnu.org; Mon, 29 Jan 2018 09:21:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1egAJ7-0007Wb-3t for qemu-devel@nongnu.org; Mon, 29 Jan 2018 09:21:13 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A2865B309 for ; Mon, 29 Jan 2018 14:21:12 +0000 (UTC) Received: from wolverine.usersys.redhat.com (unknown [10.35.7.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id D05415C476; Mon, 29 Jan 2018 14:21:10 +0000 (UTC) From: Gal Hammer To: qemu-devel@nongnu.org Date: Mon, 29 Jan 2018 16:20:56 +0200 Message-Id: <1517235657-22547-2-git-send-email-ghammer@redhat.com> In-Reply-To: <1517235657-22547-1-git-send-email-ghammer@redhat.com> References: <1517235657-22547-1-git-send-email-ghammer@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 29 Jan 2018 14:21:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/2] virtio: remove event notifier cleanup call on de-assign X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gal Hammer , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The virtio_bus_set_host_notifier function no longer calls event_notifier_cleanup when a event notifier is removed. The commit updates the code to match the new behavior and calls virtio_bus_cleanup_host_notifier after the notifier was de-assign and no longer in use. This change is a preparation to allow executing the virtio_bus_set_host_notifier function in a memory region transaction. Signed-off-by: Gal Hammer Reviewed-by: Greg Kurz Tested-by: Greg Kurz --- hw/block/dataplane/virtio-blk.c | 2 ++ hw/scsi/virtio-scsi-dataplane.c | 2 ++ hw/virtio/vhost.c | 2 ++ hw/virtio/virtio-bus.c | 14 ++++++++++---- hw/virtio/virtio.c | 2 ++ include/hw/virtio/virtio-bus.h | 2 ++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index f6fc639..2cb9909 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -192,6 +192,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) fprintf(stderr, "virtio-blk failed to set host notifier (%d)\n= ", r); while (i--) { virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); } goto fail_guest_notifiers; } @@ -267,6 +268,7 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) =20 for (i =3D 0; i < nvqs; i++) { virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); } =20 /* Clean up guest notifier (irq) */ diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index add4b3f..1c33322 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -175,6 +175,7 @@ fail_vrings: aio_context_release(s->ctx); for (i =3D 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); } k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false); fail_guest_notifiers: @@ -213,6 +214,7 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) =20 for (i =3D 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); } =20 /* Clean up guest notifier (irq) */ diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 386aef8..2ee1f37 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1416,6 +1416,7 @@ fail_vq: error_report("vhost VQ %d notifier cleanup error: %d", i, -r); } assert (e >=3D 0); + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index = + i); } virtio_device_release_ioeventfd(vdev); fail: @@ -1439,6 +1440,7 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hd= ev, VirtIODevice *vdev) error_report("vhost VQ %d notifier cleanup failed: %d", i, -r); } assert (r >=3D 0); + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index = + i); } virtio_device_release_ioeventfd(vdev); } diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 3042232..f9bc9ea 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -283,20 +283,26 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus,= int n, bool assign) r =3D k->ioeventfd_assign(proxy, notifier, n, true); if (r < 0) { error_report("%s: unable to assign ioeventfd: %d", __func__, r= ); - goto cleanup_event_notifier; + virtio_bus_cleanup_host_notifier(bus, n); } - return 0; } else { k->ioeventfd_assign(proxy, notifier, n, false); } =20 -cleanup_event_notifier: + return r; +} + +void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n) +{ + VirtIODevice *vdev =3D virtio_bus_get_device(bus); + VirtQueue *vq =3D virtio_get_queue(vdev, n); + EventNotifier *notifier =3D virtio_queue_get_host_notifier(vq); + /* Test and clear notifier after disabling event, * in case poll callback didn't have time to run. */ virtio_queue_host_notifier_read(notifier); event_notifier_cleanup(notifier); - return r; } =20 static char *virtio_bus_get_dev_path(DeviceState *dev) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d6002ee..3667cd6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2608,6 +2608,7 @@ assign_error: event_notifier_set_handler(&vq->host_notifier, NULL); r =3D virtio_bus_set_host_notifier(qbus, n, false); assert(r >=3D 0); + virtio_bus_cleanup_host_notifier(qbus, n); } return err; } @@ -2634,6 +2635,7 @@ static void virtio_device_stop_ioeventfd_impl(VirtIOD= evice *vdev) event_notifier_set_handler(&vq->host_notifier, NULL); r =3D virtio_bus_set_host_notifier(qbus, n, false); assert(r >=3D 0); + virtio_bus_cleanup_host_notifier(qbus, n); } } =20 diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index a63c1d2..ced3d2d 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -148,5 +148,7 @@ int virtio_bus_grab_ioeventfd(VirtioBusState *bus); void virtio_bus_release_ioeventfd(VirtioBusState *bus); /* Switch from/to the generic ioeventfd handler */ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign); +/* Tell the bus that the ioeventfd handler is no longer required. */ +void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n); =20 #endif /* VIRTIO_BUS_H */ --=20 2.7.5 From nobody Mon Apr 29 16:43:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151723576898118.09489682302069; Mon, 29 Jan 2018 06:22:48 -0800 (PST) Received: from localhost ([::1]:41003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egAKc-0003Qv-2X for importer@patchew.org; Mon, 29 Jan 2018 09:22:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egAJA-0002gY-Bu for qemu-devel@nongnu.org; Mon, 29 Jan 2018 09:21:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egAJ9-0007XV-8H for qemu-devel@nongnu.org; Mon, 29 Jan 2018 09:21:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1egAJ9-0007XI-1q for qemu-devel@nongnu.org; Mon, 29 Jan 2018 09:21:15 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 495CC7AEBA for ; Mon, 29 Jan 2018 14:21:14 +0000 (UTC) Received: from wolverine.usersys.redhat.com (unknown [10.35.7.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF5E018986; Mon, 29 Jan 2018 14:21:12 +0000 (UTC) From: Gal Hammer To: qemu-devel@nongnu.org Date: Mon, 29 Jan 2018 16:20:57 +0200 Message-Id: <1517235657-22547-3-git-send-email-ghammer@redhat.com> In-Reply-To: <1517235657-22547-1-git-send-email-ghammer@redhat.com> References: <1517235657-22547-1-git-send-email-ghammer@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 29 Jan 2018 14:21:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/2] virtio: improve virtio devices initialization time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gal Hammer , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The loading time of a VM is quite significant when its virtio devices use a large amount of virt-queues (e.g. a virtio-serial device with max_ports=3D511). Most of the time is spend in the creation of all the required event notifiers (ioeventfd and memory regions). This patch pack all the changes to the memory regions in a single memory transaction. Reported-by: Sitong Liu Reported-by: Xiaoling Gao Signed-off-by: Gal Hammer Reported-by: Sitong Liu Reported-by: Xiaoling Gao Reviewed-by: Greg Kurz Tested-by: Greg Kurz --- hw/virtio/virtio.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 3667cd6..006d3d1 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2572,8 +2572,9 @@ static Property virtio_properties[] =3D { static int virtio_device_start_ioeventfd_impl(VirtIODevice *vdev) { VirtioBusState *qbus =3D VIRTIO_BUS(qdev_get_parent_bus(DEVICE(vdev))); - int n, r, err; + int i, n, r, err; =20 + memory_region_transaction_begin(); for (n =3D 0; n < VIRTIO_QUEUE_MAX; n++) { VirtQueue *vq =3D &vdev->vq[n]; if (!virtio_queue_get_num(vdev, n)) { @@ -2596,9 +2597,11 @@ static int virtio_device_start_ioeventfd_impl(VirtIO= Device *vdev) } event_notifier_set(&vq->host_notifier); } + memory_region_transaction_commit(); return 0; =20 assign_error: + i =3D n; /* save n for a second iteration after transaction is committ= ed. */ while (--n >=3D 0) { VirtQueue *vq =3D &vdev->vq[n]; if (!virtio_queue_get_num(vdev, n)) { @@ -2608,7 +2611,14 @@ assign_error: event_notifier_set_handler(&vq->host_notifier, NULL); r =3D virtio_bus_set_host_notifier(qbus, n, false); assert(r >=3D 0); - virtio_bus_cleanup_host_notifier(qbus, n); + } + memory_region_transaction_commit(); + + while (--i >=3D 0) { + if (!virtio_queue_get_num(vdev, i)) { + continue; + } + virtio_bus_cleanup_host_notifier(qbus, i); } return err; } @@ -2626,6 +2636,7 @@ static void virtio_device_stop_ioeventfd_impl(VirtIOD= evice *vdev) VirtioBusState *qbus =3D VIRTIO_BUS(qdev_get_parent_bus(DEVICE(vdev))); int n, r; =20 + memory_region_transaction_begin(); for (n =3D 0; n < VIRTIO_QUEUE_MAX; n++) { VirtQueue *vq =3D &vdev->vq[n]; =20 @@ -2635,6 +2646,13 @@ static void virtio_device_stop_ioeventfd_impl(VirtIO= Device *vdev) event_notifier_set_handler(&vq->host_notifier, NULL); r =3D virtio_bus_set_host_notifier(qbus, n, false); assert(r >=3D 0); + } + memory_region_transaction_commit(); + + for (n =3D 0; n < VIRTIO_QUEUE_MAX; n++) { + if (!virtio_queue_get_num(vdev, n)) { + continue; + } virtio_bus_cleanup_host_notifier(qbus, n); } } --=20 2.7.5