From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Longpeng(Mike)" <longpeng2@huawei.com>
Cc: jasowang@redhat.com, pbonzini@redhat.com,
arei.gonglei@huawei.com, yechuan@huawei.com, eperezma@redhat.com,
alex.williamson@redhat.com, mtosatti@redhat.com, clg@redhat.com,
qemu-devel@nongnu.org
Subject: Re: [PATCH v1 1/3] virtio-pci: submit msi route changes in batch
Date: Tue, 28 Feb 2023 05:17:14 -0500 [thread overview]
Message-ID: <20230228051619-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230228093937.2515-2-longpeng2@huawei.com>
On Tue, Feb 28, 2023 at 05:39:35PM +0800, Longpeng(Mike) wrote:
> From: Longpeng <longpeng2@huawei.com>
>
> The kvm_irqchip_commit_routes() is a time-intensive operation, it needs
> scan and update all irqfds that are already assigned during each invocation,
> so more vectors means need more time to process them.
I think the real reason is it's the write side of RCU.
> For virtio-pci, we
> can just submit once when enabling vectors of a virtio-pci device.
>
> This can reduce the downtime when migrating a VM with vhost-vdpa devices.
>
> Signed-off-by: Longpeng <longpeng2@huawei.com>
> ---
> hw/virtio/virtio-pci.c | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 247325c193..22e76e3902 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -49,6 +49,19 @@
> * configuration space */
> #define VIRTIO_PCI_CONFIG_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
>
> +/* Protected by the BQL */
> +static KVMRouteChange virtio_pci_route_change;
> +
> +static inline void virtio_pci_begin_route_changes(void)
> +{
> + virtio_pci_route_change = kvm_irqchip_begin_route_changes(kvm_state);
> +}
> +
> +static inline void virtio_pci_commit_route_changes(void)
> +{
> + kvm_irqchip_commit_route_changes(&virtio_pci_route_change);
> +}
> +
> static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
> VirtIOPCIProxy *dev);
> static void virtio_pci_reset(DeviceState *qdev);
> @@ -790,12 +803,11 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
> int ret;
>
> if (irqfd->users == 0) {
> - KVMRouteChange c = kvm_irqchip_begin_route_changes(kvm_state);
> - ret = kvm_irqchip_add_msi_route(&c, vector, &proxy->pci_dev);
> + ret = kvm_irqchip_add_msi_route(&virtio_pci_route_change, vector,
> + &proxy->pci_dev);
> if (ret < 0) {
> return ret;
> }
> - kvm_irqchip_commit_route_changes(&c);
> irqfd->virq = ret;
> }
> irqfd->users++;
> @@ -903,12 +915,18 @@ static int kvm_virtio_pci_vector_vq_use(VirtIOPCIProxy *proxy, int nvqs)
> int ret = 0;
> VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
>
> + virtio_pci_begin_route_changes();
> +
> for (queue_no = 0; queue_no < nvqs; queue_no++) {
> if (!virtio_queue_get_num(vdev, queue_no)) {
> + virtio_pci_commit_route_changes();
> return -1;
> }
> ret = kvm_virtio_pci_vector_use_one(proxy, queue_no);
> }
> +
> + virtio_pci_commit_route_changes();
> +
> return ret;
> }
>
> --
> 2.23.0
next prev parent reply other threads:[~2023-02-28 10:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 9:39 [PATCH v1 0/3] virtio-pci: optimize set_guest_notifier Longpeng(Mike) via
2023-02-28 9:39 ` [PATCH v1 1/3] virtio-pci: submit msi route changes in batch Longpeng(Mike) via
2023-02-28 10:17 ` Michael S. Tsirkin [this message]
2023-02-28 11:20 ` longpeng2--- via
2023-02-28 11:39 ` longpeng2--- via
2023-02-28 12:09 ` Michael S. Tsirkin
2023-02-28 10:18 ` Michael S. Tsirkin
2023-02-28 11:24 ` longpeng2--- via
2023-02-28 9:39 ` [PATCH v1 2/3] kvm-irqchip: use KVMRouteChange API to update msi route Longpeng(Mike) via
2023-02-28 9:39 ` [PATCH v1 3/3] virtio-pci: defer to commit kvm irq routing when enable msi/msix Longpeng(Mike) via
2023-02-28 10:40 ` Michael S. Tsirkin
2023-02-28 11:07 ` Daniel P. Berrangé
2023-02-28 12:29 ` Michael S. Tsirkin
2023-02-28 13:05 ` Daniel P. Berrangé
2023-02-28 11:10 ` longpeng2--- via
2023-02-28 11:36 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230228051619-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=clg@redhat.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=longpeng2@huawei.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yechuan@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).