[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 13/21] vhost: add vhost_svq_poll
From: |
Eugenio Pérez |
Subject: |
[PATCH v6 13/21] vhost: add vhost_svq_poll |
Date: |
Wed, 20 Jul 2022 08:59:38 +0200 |
It allows the Shadow Control VirtQueue to wait for the device to use the
available buffers.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.h | 1 +
hw/virtio/vhost-shadow-virtqueue.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/hw/virtio/vhost-shadow-virtqueue.h
b/hw/virtio/vhost-shadow-virtqueue.h
index dd78f4bec2..cf442f7dea 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -89,6 +89,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);
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 c3a75ca89e..cc2ee4780d 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -485,6 +485,33 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
} while (!vhost_svq_enable_notification(svq));
}
+/**
+ * Poll the SVQ for one device used buffer.
+ *
+ * This function race with main event loop SVQ polling, so extra
+ * synchronization is needed.
+ *
+ * Return the length written by the device.
+ */
+size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
+{
+ int64_t start_us = g_get_monotonic_time();
+ do {
+ uint32_t len;
+ VirtQueueElement *elem = vhost_svq_get_buf(svq, &len);
+ if (elem) {
+ return len;
+ }
+
+ if (unlikely(g_get_monotonic_time() - start_us > 10e6)) {
+ return 0;
+ }
+
+ /* Make sure we read new used_idx */
+ smp_rmb();
+ } while (true);
+}
+
/**
* Forward used buffers.
*
--
2.31.1
- [PATCH v6 04/21] vdpa: Avoid compiler to squash reads to used idx, (continued)
- [PATCH v6 04/21] vdpa: Avoid compiler to squash reads to used idx, Eugenio Pérez, 2022/07/20
- [PATCH v6 01/21] vhost: move descriptor translation to vhost_svq_vring_write_descs, Eugenio Pérez, 2022/07/20
- [PATCH v6 05/21] vhost: Reorder vhost_svq_kick, Eugenio Pérez, 2022/07/20
- [PATCH v6 06/21] vhost: Move vhost_svq_kick call to vhost_svq_add, Eugenio Pérez, 2022/07/20
- [PATCH v6 08/21] vhost: Decouple vhost_svq_add from VirtQueueElement, Eugenio Pérez, 2022/07/20
- [PATCH v6 03/21] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/07/20
- [PATCH v6 09/21] vhost: Add SVQDescState, Eugenio Pérez, 2022/07/20
- [PATCH v6 10/21] vhost: Track number of descs in SVQDescState, Eugenio Pérez, 2022/07/20
- [PATCH v6 12/21] vhost: Expose vhost_svq_add, Eugenio Pérez, 2022/07/20
- [PATCH v6 15/21] vdpa: Export vhost_vdpa_dma_map and unmap calls, Eugenio Pérez, 2022/07/20
- [PATCH v6 13/21] vhost: add vhost_svq_poll,
Eugenio Pérez <=
- [PATCH v6 11/21] vhost: add vhost_svq_push_elem, Eugenio Pérez, 2022/07/20
- [PATCH v6 14/21] vhost: Add svq avail_handler callback, Eugenio Pérez, 2022/07/20
- [PATCH v6 16/21] vhost-net-vdpa: add stubs for when no virtio-net device is present, Eugenio Pérez, 2022/07/20
- [PATCH v6 18/21] vdpa: Buffer CVQ support on shadow virtqueue, Eugenio Pérez, 2022/07/20
- [PATCH v6 17/21] vdpa: manual forward CVQ buffers, Eugenio Pérez, 2022/07/20
- [PATCH v6 19/21] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/07/20
- [PATCH v6 20/21] vdpa: Add device migration blocker, Eugenio Pérez, 2022/07/20
- [PATCH v6 21/21] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/07/20