From nobody Mon Feb 9 07:56:33 2026 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518118262040868.1135342064163; Thu, 8 Feb 2018 11:31:02 -0800 (PST) Received: from localhost ([::1]:39377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejruP-0008Vv-4n for importer@patchew.org; Thu, 08 Feb 2018 14:31:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejrbS-0008Kp-UE for qemu-devel@nongnu.org; Thu, 08 Feb 2018 14:11:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejrbR-0001Ku-Q6 for qemu-devel@nongnu.org; Thu, 08 Feb 2018 14:11:26 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51004 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ejrbR-0001Kl-Jw for qemu-devel@nongnu.org; Thu, 08 Feb 2018 14:11:25 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F7848182D11; Thu, 8 Feb 2018 19:11:14 +0000 (UTC) Received: from redhat.com (ovpn-120-144.rdu2.redhat.com [10.10.120.144]) by smtp.corp.redhat.com (Postfix) with SMTP id 60A581007D62; Thu, 8 Feb 2018 19:11:10 +0000 (UTC) Date: Thu, 8 Feb 2018 21:11:10 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1518116908-10852-4-git-send-email-mst@redhat.com> References: <1518116908-10852-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1518116908-10852-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 08 Feb 2018 19:11:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 08 Feb 2018 19:11:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/26] 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 , Peter Maydell , Greg Kurz 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 Content-Type: text/plain; charset="utf-8" From: Gal Hammer 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 Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin 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 MST