From nobody Fri Mar 29 07:48:44 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 1515665940932800.6931050401989; Thu, 11 Jan 2018 02:19:00 -0800 (PST) Received: from localhost ([::1]:60022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZZwq-0002hw-4P for importer@patchew.org; Thu, 11 Jan 2018 05:19:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZZvX-0001u8-Oq for qemu-devel@nongnu.org; Thu, 11 Jan 2018 05:17:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZZvS-0001AS-RI for qemu-devel@nongnu.org; Thu, 11 Jan 2018 05:17:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZZvS-00017B-KD for qemu-devel@nongnu.org; Thu, 11 Jan 2018 05:17:34 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CC018763C for ; Thu, 11 Jan 2018 10:17:23 +0000 (UTC) Received: from wolverine.usersys.redhat.com (unknown [10.35.7.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38FFC608F0; Thu, 11 Jan 2018 10:17:19 +0000 (UTC) From: Gal Hammer To: qemu-devel@nongnu.org Date: Thu, 11 Jan 2018 12:16:56 +0200 Message-Id: <1515665816-10313-1-git-send-email-ghammer@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 11 Jan 2018 10:17:28 +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] 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 uses 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 --- hw/virtio/virtio.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ad564b0..8d8d93d 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2574,6 +2574,7 @@ static int virtio_device_start_ioeventfd_impl(VirtIOD= evice *vdev) VirtioBusState *qbus =3D VIRTIO_BUS(qdev_get_parent_bus(DEVICE(vdev))); int 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,6 +2597,7 @@ static int virtio_device_start_ioeventfd_impl(VirtIOD= evice *vdev) } event_notifier_set(&vq->host_notifier); } + memory_region_transaction_commit(); return 0; =20 assign_error: @@ -2609,6 +2611,7 @@ assign_error: r =3D virtio_bus_set_host_notifier(qbus, n, false); assert(r >=3D 0); } + memory_region_transaction_commit(); return err; } =20 @@ -2625,6 +2628,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 @@ -2632,6 +2636,13 @@ static void virtio_device_stop_ioeventfd_impl(VirtIO= Device *vdev) continue; } event_notifier_set_handler(&vq->host_notifier, NULL); + } + memory_region_transaction_commit(); + + for (n =3D 0; n < VIRTIO_QUEUE_MAX; n++) { + if (!virtio_queue_get_num(vdev, n)) { + continue; + } r =3D virtio_bus_set_host_notifier(qbus, n, false); assert(r >=3D 0); } --=20 2.7.5