mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
vhost: Add count argument to vhost_svq_poll()
Next patches in this series will no longer perform an immediate poll and check of the device's used buffers for each CVQ state load command. Instead, they will send CVQ state load commands in parallel by polling multiple pending buffers at once. To achieve this, this patch refactoring vhost_svq_poll() to accept a new argument `num`, which allows vhost_svq_poll() to wait for the device to use multiple elements, rather than polling for a single element. Signed-off-by: Hawkins Jiawei <yin31149@gmail.com> Acked-by: Eugenio Pérez <eperezma@redhat.com> Message-Id: <950b3bfcfc5d446168b9d6a249d554a013a691d4.1693287885.git.yin31149@gmail.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
f13f5f6412
commit
b0de17a2e2
3 changed files with 24 additions and 16 deletions
|
@ -514,29 +514,37 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
|
|||
}
|
||||
|
||||
/**
|
||||
* Poll the SVQ for one device used buffer.
|
||||
* Poll the SVQ to wait for the device to use the specified number
|
||||
* of elements and return the total length written by the device.
|
||||
*
|
||||
* This function race with main event loop SVQ polling, so extra
|
||||
* synchronization is needed.
|
||||
*
|
||||
* Return the length written by the device.
|
||||
* @svq: The svq
|
||||
* @num: The number of elements that need to be used
|
||||
*/
|
||||
size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
|
||||
size_t vhost_svq_poll(VhostShadowVirtqueue *svq, size_t num)
|
||||
{
|
||||
int64_t start_us = g_get_monotonic_time();
|
||||
uint32_t len = 0;
|
||||
size_t len = 0;
|
||||
uint32_t r;
|
||||
|
||||
do {
|
||||
if (vhost_svq_more_used(svq)) {
|
||||
break;
|
||||
}
|
||||
while (num--) {
|
||||
int64_t start_us = g_get_monotonic_time();
|
||||
|
||||
if (unlikely(g_get_monotonic_time() - start_us > 10e6)) {
|
||||
return 0;
|
||||
}
|
||||
} while (true);
|
||||
do {
|
||||
if (vhost_svq_more_used(svq)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(g_get_monotonic_time() - start_us > 10e6)) {
|
||||
return len;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
vhost_svq_get_buf(svq, &r);
|
||||
len += r;
|
||||
}
|
||||
|
||||
vhost_svq_get_buf(svq, &len);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue