mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06:00
vhost: add vhost_svq_poll
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>
This commit is contained in:
parent
d0291f3f28
commit
3f44d13dda
2 changed files with 28 additions and 0 deletions
|
@ -485,6 +485,33 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
|
||||||
} while (!vhost_svq_enable_notification(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.
|
* Forward used buffers.
|
||||||
*
|
*
|
||||||
|
|
|
@ -89,6 +89,7 @@ void vhost_svq_push_elem(VhostShadowVirtqueue *svq,
|
||||||
int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,
|
int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,
|
||||||
size_t out_num, const struct iovec *in_sg, size_t in_num,
|
size_t out_num, const struct iovec *in_sg, size_t in_num,
|
||||||
VirtQueueElement *elem);
|
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_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
|
||||||
void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd);
|
void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue