From: Jason Wang <jasowang@redhat.com>
To: "Longpeng (Mike,
Cloud Infrastructure Service Product Dept.)"
<longpeng2@huawei.com>
Cc: stefanha@redhat.com, mst@redhat.com, sgarzare@redhat.com,
cohuck@redhat.com, pbonzini@redhat.com, arei.gonglei@huawei.com,
yechuan@huawei.com, huangzhichao@huawei.com,
qemu-devel@nongnu.org
Subject: Re: [PATCH] vhost: configure all host notifiers in a single MR transaction
Date: Tue, 29 Nov 2022 10:55:17 +0800 [thread overview]
Message-ID: <CACGkMEuKa9P+n5Yv7iHpg0ZDqRSnXBzCSBDt+pdnsmSPuA181A@mail.gmail.com> (raw)
In-Reply-To: <45e851db-7633-8942-4baf-5ca608c9dd61@huawei.com>
On Mon, Nov 28, 2022 at 5:08 PM Longpeng (Mike, Cloud Infrastructure
Service Product Dept.) <longpeng2@huawei.com> wrote:
>
>
>
> 在 2022/11/21 12:01, Jason Wang 写道:
> > On Fri, Nov 18, 2022 at 10:49 PM Longpeng(Mike) <longpeng2@huawei.com> wrote:
> >>
> >> From: Longpeng <longpeng2@huawei.com>
> >>
> >> This allows the vhost device to batch the setup of all its host notifiers.
> >> This significantly reduces the device starting time, e.g. the vhost-vDPA
> >> generic device [1] start time reduce from 376ms to 9.1ms for a VM with
> >> 64 vCPUs and 3 vDPA device(64vq per device).
> >
> > Great, I think we need to do this for host_notifiers_mr as well. This
> > helps for the case when the notification area could be mapped directly
> > to guests.
> >
> Batch and commit once for host_notifiers_mrs can reduce the cost from
> 423ms to 32ms, testing on vdpasim_blk (3 devices and 64 vqs per device)
> with doorbell passthrough support.
> I'll append a patch in the next version.
Great.
Thanks
>
> >>
> >> [1] https://www.mail-archive.com/qemu-devel@nongnu.org/msg921541.html
> >>
> >> Signed-off-by: Longpeng <longpeng2@huawei.com>
> >> ---
> >> hw/virtio/vhost.c | 39 ++++++++++++++++++++++++++++++++++++++-
> >> 1 file changed, 38 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> >> index d1c4c20b8c..bf82d9b176 100644
> >> --- a/hw/virtio/vhost.c
> >> +++ b/hw/virtio/vhost.c
> >> @@ -1507,6 +1507,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
> >> int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
> >> {
> >> BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> >> + int vq_init_count = 0;
> >> int i, r, e;
> >>
> >> /* We will pass the notifiers to the kernel, make sure that QEMU
> >> @@ -1518,6 +1519,12 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
> >> goto fail;
> >> }
> >>
> >> + /*
> >> + * Batch all the host notifiers in a single transaction to avoid
> >> + * quadratic time complexity in address_space_update_ioeventfds().
> >> + */
> >> + memory_region_transaction_begin();
> >> +
> >> for (i = 0; i < hdev->nvqs; ++i) {
> >> r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
> >> true);
> >> @@ -1525,19 +1532,33 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
> >> error_report("vhost VQ %d notifier binding failed: %d", i, -r);
> >> goto fail_vq;
> >> }
> >> +
> >> + vq_init_count++;
> >> }
> >
> > Nit, the name needs some tweak, it's actually the number of the host
> > notifiers that is initialized. And we can count it out of the loop.
> >
> Ok, I will refer to virtio_device_start_ioeventfd_impl().
>
> >>
> >> + memory_region_transaction_commit();
> >> +
> >> return 0;
> >> fail_vq:
> >> - while (--i >= 0) {
> >> + for (i = 0; i < vq_init_count; i++) {
> >
> > It looks to me there's no need for this change.
> >
> > Others look good.
> >
> > Thanks
> >
> >> e = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
> >> false);
> >> if (e < 0) {
> >> error_report("vhost VQ %d notifier cleanup error: %d", i, -r);
> >> }
> >> assert (e >= 0);
> >> + }
> >> +
> >> + /*
> >> + * The transaction expects the ioeventfds to be open when it
> >> + * commits. Do it now, before the cleanup loop.
> >> + */
> >> + memory_region_transaction_commit();
> >> +
> >> + for (i = 0; i < vq_init_count; i++) {
> >> virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i);
> >> }
> >> +
> >> virtio_device_release_ioeventfd(vdev);
> >> fail:
> >> return r;
> >> @@ -1553,6 +1574,12 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
> >> BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> >> int i, r;
> >>
> >> + /*
> >> + * Batch all the host notifiers in a single transaction to avoid
> >> + * quadratic time complexity in address_space_update_ioeventfds().
> >> + */
> >> + memory_region_transaction_begin();
> >> +
> >> for (i = 0; i < hdev->nvqs; ++i) {
> >> r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i,
> >> false);
> >> @@ -1560,8 +1587,18 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
> >> error_report("vhost VQ %d notifier cleanup failed: %d", i, -r);
> >> }
> >> assert (r >= 0);
> >> + }
> >> +
> >> + /*
> >> + * The transaction expects the ioeventfds to be open when it
> >> + * commits. Do it now, before the cleanup loop.
> >> + */
> >> + memory_region_transaction_commit();
> >> +
> >> + for (i = 0; i < hdev->nvqs; ++i) {
> >> virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i);
> >> }
> >> +
> >> virtio_device_release_ioeventfd(vdev);
> >> }
> >>
> >> --
> >> 2.23.0
> >>
> >
> > .
>
prev parent reply other threads:[~2022-11-29 2:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 14:49 [PATCH] vhost: configure all host notifiers in a single MR transaction Longpeng(Mike) via
2022-11-18 18:28 ` Stefan Hajnoczi
2022-11-21 4:01 ` Jason Wang
2022-11-28 9:08 ` longpeng2--- via
2022-11-29 2:55 ` Jason Wang [this message]
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=CACGkMEuKa9P+n5Yv7iHpg0ZDqRSnXBzCSBDt+pdnsmSPuA181A@mail.gmail.com \
--to=jasowang@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=cohuck@redhat.com \
--cc=huangzhichao@huawei.com \
--cc=longpeng2@huawei.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--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).