From: peili.dev@gmail.com
To: qemu-devel@nongnu.org
Cc: eperezma@redhat.com, Pei Li <peili.dev@gmail.com>
Subject: [PATCH 1/2] Reduce vdpa initialization / startup overhead
Date: Tue, 18 Apr 2023 18:56:37 -0400 [thread overview]
Message-ID: <20230418225638.1467969-1-peili.dev@gmail.com> (raw)
From: Pei Li <peili.dev@gmail.com>
Currently, part of the vdpa initialization / startup process
needs to trigger many ioctls per vq, which is very inefficient
and causing unnecessary context switch between user mode and
kernel mode.
This patch creates an additional ioctl() command, namely
VHOST_VDPA_GET_VRING_GROUP_BATCH, that will batching
commands of VHOST_VDPA_GET_VRING_GROUP into a single
ioctl() call.
Signed-off-by: Pei Li <peili.dev@gmail.com>
---
hw/virtio/vhost-vdpa.c | 31 +++++++++++++++-----
include/standard-headers/linux/vhost_types.h | 3 ++
| 7 +++++
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index bc6bad23d5..6d45ff8539 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -679,7 +679,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev)
uint64_t f = 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 |
0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH |
0x1ULL << VHOST_BACKEND_F_IOTLB_ASID |
- 0x1ULL << VHOST_BACKEND_F_SUSPEND;
+ 0x1ULL << VHOST_BACKEND_F_SUSPEND |
+ 0x1ULL << VHOST_BACKEND_F_IOCTL_BATCH;
int r;
if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) {
@@ -731,14 +732,28 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx)
static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev)
{
- int i;
+ int i, nvqs = dev->nvqs;
+ uint64_t backend_features = dev->backend_cap;
+
trace_vhost_vdpa_set_vring_ready(dev);
- for (i = 0; i < dev->nvqs; ++i) {
- struct vhost_vring_state state = {
- .index = dev->vq_index + i,
- .num = 1,
- };
- vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state);
+
+ if (!(backend_features & BIT_ULL(VHOST_BACKEND_F_IOCTL_BATCH))) {
+ for (i = 0; i < nvqs; ++i) {
+ struct vhost_vring_state state = {
+ .index = dev->vq_index + i,
+ .num = 1,
+ };
+ vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state);
+ }
+ } else {
+ struct vhost_vring_state states[nvqs + 1];
+ states[0].num = nvqs;
+ for (i = 1; i <= nvqs; ++i) {
+ states[i].index = dev->vq_index + i - 1;
+ states[i].num = 1;
+ }
+
+ vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE_BATCH, &states[0]);
}
return 0;
}
diff --git a/include/standard-headers/linux/vhost_types.h b/include/standard-headers/linux/vhost_types.h
index c41a73fe36..068d0e1ceb 100644
--- a/include/standard-headers/linux/vhost_types.h
+++ b/include/standard-headers/linux/vhost_types.h
@@ -164,4 +164,7 @@ struct vhost_vdpa_iova_range {
/* Device can be suspended */
#define VHOST_BACKEND_F_SUSPEND 0x4
+/* IOCTL requests can be batched */
+#define VHOST_BACKEND_F_IOCTL_BATCH 0x6
+
#endif
--git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h
index f9f115a7c7..4c9ddd0a0e 100644
--- a/linux-headers/linux/vhost.h
+++ b/linux-headers/linux/vhost.h
@@ -180,4 +180,11 @@
*/
#define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D)
+/* Batch version of VHOST_VDPA_SET_VRING_ENABLE
+ *
+ * Enable/disable the ring while batching the commands.
+ */
+#define VHOST_VDPA_SET_VRING_ENABLE_BATCH _IOW(VHOST_VIRTIO, 0x7F, \
+ struct vhost_vring_state)
+
#endif
--
2.25.1
next reply other threads:[~2023-04-19 0:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 22:56 peili.dev [this message]
2023-04-18 22:56 ` [PATCH 2/2] Reduce vdpa initialization / startup overhead peili.dev
2023-04-19 15:33 ` [PATCH 1/2] " Eugenio Perez Martin
2023-04-20 4:18 ` Jason Wang
2023-04-20 5:25 ` Pei Li
2023-04-20 8:14 ` Jason Wang
2023-04-20 8:59 ` Eugenio Perez Martin
2023-07-18 10:55 ` Michael S. Tsirkin
2023-07-21 10:39 ` Eugenio Perez Martin
2023-07-21 20:57 ` Si-Wei Liu
2023-07-18 10:32 ` vdpa: use io_uring passthrough command for IOCTLs [was Re: [PATCH 1/2] Reduce vdpa initialization / startup overhead] Stefano Garzarella
2023-07-26 8:10 ` Jason Wang
2023-07-18 10:53 ` [PATCH 1/2] Reduce vdpa initialization / startup overhead 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=20230418225638.1467969-1-peili.dev@gmail.com \
--to=peili.dev@gmail.com \
--cc=eperezma@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).