[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 13/20] vhost: add vhost_svq_poll
From: |
Eugenio Pérez |
Subject: |
[PATCH v5 13/20] vhost: add vhost_svq_poll |
Date: |
Tue, 19 Jul 2022 11:56:22 +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 v5 04/20] vdpa: Avoid compiler to squash reads to used idx, (continued)
- [PATCH v5 04/20] vdpa: Avoid compiler to squash reads to used idx, Eugenio Pérez, 2022/07/19
- [PATCH v5 03/20] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/07/19
- [PATCH v5 06/20] vhost: Move vhost_svq_kick call to vhost_svq_add, Eugenio Pérez, 2022/07/19
- [PATCH v5 05/20] vhost: Reorder vhost_svq_kick, Eugenio Pérez, 2022/07/19
- [PATCH v5 07/20] vhost: Check for queue full at vhost_svq_add, Eugenio Pérez, 2022/07/19
- [PATCH v5 08/20] vhost: Decouple vhost_svq_add from VirtQueueElement, Eugenio Pérez, 2022/07/19
- [PATCH v5 12/20] vhost: Expose vhost_svq_add, Eugenio Pérez, 2022/07/19
- [PATCH v5 09/20] vhost: Add SVQDescState, Eugenio Pérez, 2022/07/19
- [PATCH v5 11/20] vhost: add vhost_svq_push_elem, Eugenio Pérez, 2022/07/19
- [PATCH v5 10/20] vhost: Track number of descs in SVQDescState, Eugenio Pérez, 2022/07/19
- [PATCH v5 13/20] vhost: add vhost_svq_poll,
Eugenio Pérez <=
- [PATCH v5 16/20] vdpa: manual forward CVQ buffers, Eugenio Pérez, 2022/07/19
- [PATCH v5 15/20] vdpa: Export vhost_vdpa_dma_map and unmap calls, Eugenio Pérez, 2022/07/19
- [PATCH v5 14/20] vhost: Add svq avail_handler callback, Eugenio Pérez, 2022/07/19
- [PATCH v5 17/20] vdpa: Buffer CVQ support on shadow virtqueue, Eugenio Pérez, 2022/07/19
- [PATCH v5 18/20] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/07/19
- [PATCH v5 19/20] vdpa: Add device migration blocker, Eugenio Pérez, 2022/07/19
- [PATCH v5 20/20] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/07/19
- Re: [PATCH v5 00/20] vdpa net devices Rx filter change notification with Shadow VQ, Eugenio Perez Martin, 2022/07/19