[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 12/19] vhost: add vhost_svq_poll
From: |
Eugenio Pérez |
Subject: |
[PATCH v4 12/19] vhost: add vhost_svq_poll |
Date: |
Mon, 18 Jul 2022 12:29:42 +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 406a823c81..3c26781cf7 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -484,6 +484,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 v4 03/19] virtio-net: Expose ctrl virtqueue logic, (continued)
- [PATCH v4 03/19] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/07/18
- [PATCH v4 06/19] vhost: Check for queue full at vhost_svq_add, Eugenio Pérez, 2022/07/18
- [PATCH v4 02/19] virtio-net: Expose MAC_TABLE_ENTRIES, Eugenio Pérez, 2022/07/18
- [PATCH v4 04/19] vhost: Reorder vhost_svq_kick, Eugenio Pérez, 2022/07/18
- [PATCH v4 05/19] vhost: Move vhost_svq_kick call to vhost_svq_add, Eugenio Pérez, 2022/07/18
- [PATCH v4 08/19] vhost: Add SVQDescState, Eugenio Pérez, 2022/07/18
- [PATCH v4 11/19] vhost: Expose vhost_svq_add, Eugenio Pérez, 2022/07/18
- [PATCH v4 10/19] vhost: add vhost_svq_push_elem, Eugenio Pérez, 2022/07/18
- [PATCH v4 07/19] vhost: Decouple vhost_svq_add from VirtQueueElement, Eugenio Pérez, 2022/07/18
- [PATCH v4 14/19] vdpa: Export vhost_vdpa_dma_map and unmap calls, Eugenio Pérez, 2022/07/18
- [PATCH v4 12/19] vhost: add vhost_svq_poll,
Eugenio Pérez <=
- [PATCH v4 13/19] vhost: Add svq avail_handler callback, Eugenio Pérez, 2022/07/18
- [PATCH v4 09/19] vhost: Track number of descs in SVQDescState, Eugenio Pérez, 2022/07/18
- [PATCH v4 15/19] vdpa: manual forward CVQ buffers, Eugenio Pérez, 2022/07/18
- [PATCH v4 16/19] vdpa: Buffer CVQ support on shadow virtqueue, Eugenio Pérez, 2022/07/18
- [PATCH v4 17/19] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/07/18
- [PATCH v4 18/19] vdpa: Add device migration blocker, Eugenio Pérez, 2022/07/18