[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 20/63] vhost: Add count argument to vhost_svq_poll()
|
From: |
Michael S. Tsirkin |
|
Subject: |
[PULL 20/63] vhost: Add count argument to vhost_svq_poll() |
|
Date: |
Wed, 4 Oct 2023 04:44:10 -0400 |
From: Hawkins Jiawei <yin31149@gmail.com>
Next patches in this series will no longer perform an
immediate poll and check of the device's used buffers
for each CVQ state load command. Instead, they will
send CVQ state load commands in parallel by polling
multiple pending buffers at once.
To achieve this, this patch refactoring vhost_svq_poll()
to accept a new argument `num`, which allows vhost_svq_poll()
to wait for the device to use multiple elements,
rather than polling for a single element.
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Acked-by: Eugenio Pérez <eperezma@redhat.com>
Message-Id:
<950b3bfcfc5d446168b9d6a249d554a013a691d4.1693287885.git.yin31149@gmail.com>
---
hw/virtio/vhost-shadow-virtqueue.h | 2 +-
hw/virtio/vhost-shadow-virtqueue.c | 36 ++++++++++++++++++------------
net/vhost-vdpa.c | 2 +-
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/hw/virtio/vhost-shadow-virtqueue.h
b/hw/virtio/vhost-shadow-virtqueue.h
index 6efe051a70..5bce67837b 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -119,7 +119,7 @@ void vhost_svq_push_elem(VhostShadowVirtqueue *svq,
int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,
size_t out_num, const struct iovec *in_sg, size_t in_num,
VirtQueueElement *elem);
-size_t vhost_svq_poll(VhostShadowVirtqueue *svq);
+size_t vhost_svq_poll(VhostShadowVirtqueue *svq, size_t num);
void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd);
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index 49e5aed931..e731b1d2ea 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -514,29 +514,37 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
}
/**
- * Poll the SVQ for one device used buffer.
+ * Poll the SVQ to wait for the device to use the specified number
+ * of elements and return the total length written by the device.
*
* This function race with main event loop SVQ polling, so extra
* synchronization is needed.
*
- * Return the length written by the device.
+ * @svq: The svq
+ * @num: The number of elements that need to be used
*/
-size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
+size_t vhost_svq_poll(VhostShadowVirtqueue *svq, size_t num)
{
- int64_t start_us = g_get_monotonic_time();
- uint32_t len = 0;
+ size_t len = 0;
+ uint32_t r;
- do {
- if (vhost_svq_more_used(svq)) {
- break;
- }
+ while (num--) {
+ int64_t start_us = g_get_monotonic_time();
- if (unlikely(g_get_monotonic_time() - start_us > 10e6)) {
- return 0;
- }
- } while (true);
+ do {
+ if (vhost_svq_more_used(svq)) {
+ break;
+ }
+
+ if (unlikely(g_get_monotonic_time() - start_us > 10e6)) {
+ return len;
+ }
+ } while (true);
+
+ vhost_svq_get_buf(svq, &r);
+ len += r;
+ }
- vhost_svq_get_buf(svq, &len);
return len;
}
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 90beda42e0..5808d1b60c 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -645,7 +645,7 @@ static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s,
size_t out_len,
* descriptor. Also, we need to take the answer before SVQ pulls by itself,
* when BQL is released
*/
- return vhost_svq_poll(svq);
+ return vhost_svq_poll(svq, 1);
}
static ssize_t vhost_vdpa_net_load_cmd(VhostVDPAState *s, uint8_t class,
--
MST
- [PULL 09/63] hw/virtio: add config support to vhost-user-device, (continued)
- [PULL 09/63] hw/virtio: add config support to vhost-user-device, Michael S. Tsirkin, 2023/10/04
- [PULL 08/63] virtio: add vhost-user-base and a generic vhost-user-device, Michael S. Tsirkin, 2023/10/04
- [PULL 14/63] virtio: don't zero out memory region cache for indirect descriptors, Michael S. Tsirkin, 2023/10/04
- [PULL 13/63] vdpa: Allow VIRTIO_NET_F_CTRL_VLAN in SVQ, Michael S. Tsirkin, 2023/10/04
- [PULL 10/63] virtio-net: do not reset vlan filtering at set_features, Michael S. Tsirkin, 2023/10/04
- [PULL 15/63] vdpa: use first queue SVQ state for CVQ default, Michael S. Tsirkin, 2023/10/04
- [PULL 17/63] vdpa: rename vhost_vdpa_net_load to vhost_vdpa_net_cvq_load, Michael S. Tsirkin, 2023/10/04
- [PULL 19/63] vdpa: remove net cvq migration blocker, Michael S. Tsirkin, 2023/10/04
- [PULL 12/63] vdpa: Restore vlan filtering state, Michael S. Tsirkin, 2023/10/04
- [PULL 16/63] vdpa: export vhost_vdpa_set_vring_ready, Michael S. Tsirkin, 2023/10/04
- [PULL 20/63] vhost: Add count argument to vhost_svq_poll(),
Michael S. Tsirkin <=
- [PULL 22/63] qmp: update virtio feature maps, vhost-user-gpio introspection, Michael S. Tsirkin, 2023/10/04
- [PULL 24/63] vhost-user: strip superfluous whitespace, Michael S. Tsirkin, 2023/10/04
- [PULL 26/63] vhost-user: factor out "vhost_user_write_sync", Michael S. Tsirkin, 2023/10/04
- [PULL 25/63] vhost-user: tighten "reply_supported" scope in "set_vring_addr", Michael S. Tsirkin, 2023/10/04
- [PULL 18/63] vdpa: move vhost_vdpa_set_vring_ready to the caller, Michael S. Tsirkin, 2023/10/04
- [PULL 23/63] vhost-user: move VhostUserProtocolFeature definition to header file, Michael S. Tsirkin, 2023/10/04
- [PULL 27/63] vhost-user: flatten "enforce_reply" into "vhost_user_write_sync", Michael S. Tsirkin, 2023/10/04
- [PULL 21/63] qmp: remove virtio_list, search QOM tree instead, Michael S. Tsirkin, 2023/10/04
- [PULL 28/63] vhost-user: hoist "write_sync", "get_features", "get_u64", Michael S. Tsirkin, 2023/10/04
- [PULL 30/63] vhost-user: call VHOST_USER_SET_VRING_ENABLE synchronously, Michael S. Tsirkin, 2023/10/04