This is a performance optimization to eliminate vmexits during polling. It also avoids spurious ioeventfd processing after polling ends.
Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com> --- hw/virtio/virtio.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 66dd968..8f420cf 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2057,6 +2057,13 @@ static void virtio_queue_host_notifier_aio_read(EventNotifier *n) } } +static void virtio_queue_host_notifier_aio_poll_begin(EventNotifier *n) +{ + VirtQueue *vq = container_of(n, VirtQueue, host_notifier); + + virtio_queue_set_notification(vq, 0); +} + static bool virtio_queue_host_notifier_aio_poll(void *opaque) { EventNotifier *n = opaque; @@ -2070,6 +2077,16 @@ static bool virtio_queue_host_notifier_aio_poll(void *opaque) return true; } +static void virtio_queue_host_notifier_aio_poll_end(EventNotifier *n) +{ + VirtQueue *vq = container_of(n, VirtQueue, host_notifier); + + virtio_queue_set_notification(vq, 1); + + /* Handle any buffers that snuck in after we finished polling */ + virtio_queue_host_notifier_aio_poll(n); +} + void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx, VirtIOHandleOutput handle_output) { @@ -2078,6 +2095,9 @@ void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx, aio_set_event_notifier(ctx, &vq->host_notifier, true, virtio_queue_host_notifier_aio_read, virtio_queue_host_notifier_aio_poll); + aio_set_event_notifier_poll(ctx, &vq->host_notifier, + virtio_queue_host_notifier_aio_poll_begin, + virtio_queue_host_notifier_aio_poll_end); } else { aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL); /* Test and clear notifier before after disabling event, -- 2.7.4