[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/24] vhost: add vhost_svq_poll
From: |
Jason Wang |
Subject: |
[PULL 13/24] vhost: add vhost_svq_poll |
Date: |
Tue, 19 Jul 2022 21:16:26 +0800 |
From: Eugenio Pérez <eperezma@redhat.com>
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>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.c | 27 +++++++++++++++++++++++++++
hw/virtio/vhost-shadow-virtqueue.h | 1 +
2 files changed, 28 insertions(+)
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index c3a75ca..cc2ee47 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -486,6 +486,33 @@ static void vhost_svq_flush(VhostShadowVirtqueue *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.
*
* @n: hdev call event notifier, the one that device set to notify svq.
diff --git a/hw/virtio/vhost-shadow-virtqueue.h
b/hw/virtio/vhost-shadow-virtqueue.h
index dd78f4b..cf442f7 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);
--
2.7.4
- [PULL 02/24] virtio-net: Expose MAC_TABLE_ENTRIES, (continued)
- [PULL 02/24] virtio-net: Expose MAC_TABLE_ENTRIES, Jason Wang, 2022/07/19
- [PULL 03/24] virtio-net: Expose ctrl virtqueue logic, Jason Wang, 2022/07/19
- [PULL 04/24] vdpa: Avoid compiler to squash reads to used idx, Jason Wang, 2022/07/19
- [PULL 05/24] vhost: Reorder vhost_svq_kick, Jason Wang, 2022/07/19
- [PULL 06/24] vhost: Move vhost_svq_kick call to vhost_svq_add, Jason Wang, 2022/07/19
- [PULL 07/24] vhost: Check for queue full at vhost_svq_add, Jason Wang, 2022/07/19
- [PULL 08/24] vhost: Decouple vhost_svq_add from VirtQueueElement, Jason Wang, 2022/07/19
- [PULL 09/24] vhost: Add SVQDescState, Jason Wang, 2022/07/19
- [PULL 10/24] vhost: Track number of descs in SVQDescState, Jason Wang, 2022/07/19
- [PULL 12/24] vhost: Expose vhost_svq_add, Jason Wang, 2022/07/19
- [PULL 13/24] vhost: add vhost_svq_poll,
Jason Wang <=
- [PULL 11/24] vhost: add vhost_svq_push_elem, Jason Wang, 2022/07/19
- [PULL 15/24] vdpa: Export vhost_vdpa_dma_map and unmap calls, Jason Wang, 2022/07/19
- [PULL 14/24] vhost: Add svq avail_handler callback, Jason Wang, 2022/07/19
- [PULL 16/24] vdpa: manual forward CVQ buffers, Jason Wang, 2022/07/19
- [PULL 17/24] vdpa: Buffer CVQ support on shadow virtqueue, Jason Wang, 2022/07/19
- [PULL 19/24] vdpa: Add device migration blocker, Jason Wang, 2022/07/19
- [PULL 18/24] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Jason Wang, 2022/07/19
- [PULL 20/24] vdpa: Add x-svq to NetdevVhostVDPAOptions, Jason Wang, 2022/07/19
- [PULL 22/24] net/colo: Fix a "double free" crash to clear the conn_list, Jason Wang, 2022/07/19
- [PULL 24/24] net/colo.c: fix segmentation fault when packet is not parsed correctly, Jason Wang, 2022/07/19