hw/virtio/virtio.c: fix the vring_avail_event error
PATCH 1/1 hw/virtio/virtio.c: fix the vring_avail_event error
The event idx in virtio is an effective way to reduce the number of interrupts and exits of the guest. When the guest puts an request into the virtio ring, it doesn't exit immediately to inform the backend. Instead, the guest checks the "avail" event idx to determine the notification.
In virtqueue_pop, when a request is poped, the current avail event idx should be set to the number of vq->last_avail_idx.
--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio.c +1 -1
@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) i = head =virtqueue_get_head (vq, vq->last_avail_idx++);if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event (vq, vq->last_avail_idx); }if (vring_desc_flags (vdev, desc_pa, i) &VRING_DESC_F_INDIRECT ) {
Signature · 1 line
1.7.12.4
Quoted 10 lines · Bin Wu
The event idx in virtio is an effective way to reduce the number of interrupts and exits of the guest. When the guest puts an request into the virtio ring, it doesn't exit immediately to inform the backend. Instead, the guest checks the "avail" event idx to determine the notification.
In
virtqueue_pop, when a request is poped, the current avail event idx should be set to the number ofvq->last_avail_idx.Signed-off-by Bin Wu <[email protected]>
Does this fix some observable bug? Improve efficiency for some workload?
Quoted 19 lines
--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio.c +1
-1@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) i = head =virtqueue_get_head (vq, vq->last_avail_idx++);if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event (vq, vq->last_avail_idx); }if (vring_desc_flags (vdev, desc_pa, i) &VRING_DESC_F_INDIRECT ) {Signature · 1 line
1.7.12.4
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Bin Wu
The event idx in virtio is an effective way to reduce the number of interrupts and exits of the guest. When the guest puts an request into the virtio ring, it doesn't exit immediately to inform the backend. Instead, the guest checks the "avail" event idx to determine the notification.
Quoted 7 lines
Quoted 4 lines
In
virtqueue_pop, when a request is poped, the current avail event idx should be set to the number ofvq->last_avail_idx.Signed-off-by Bin Wu <[email protected]>Does this fix some observable bug? Improve efficiency for some workload?
Improve efficiency, I test as follows:
(1)create a suse11sp3 VM with a virtio-blk test disk;
(2)use libaio library to submit 32 IOs concurrently (invoke io_sumbmit 32 times) in the VM;
(3)modify the virtio-blk driver in the guest to record the host notification times;
without this patch, virtio-blk may notify the host between 10 and 30 times; with this patch, virtio-blk just notify the host once during every test:)
Quoted 22 lines
Quoted 19 lines
--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio.c +1
-1@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) i = head =virtqueue_get_head (vq, vq->last_avail_idx++);if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event (vq, vq->last_avail_idx); }if (vring_desc_flags (vdev, desc_pa, i) &VRING_DESC_F_INDIRECT ) {Signature · 1 line
1.7.12.4.
Signature · 1 line
Bin Wu
Quoted 19 lines · Bin Wu
The event idx in virtio is an effective way to reduce the number of interrupts and exits of the guest. When the guest puts an request into the virtio ring, it doesn't exit immediately to inform the backend. Instead, the guest checks the "avail" event idx to determine the notification.
In
virtqueue_pop, when a request is poped, the current avail event idx should be set to the number ofvq->last_avail_idx.Signed-off-by Bin Wu <[email protected]>--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio.c +0
-0
hw/virtio/virtio.c int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) · line 473
Quoted 6 lines
hw/virtio/virtio.c +1
-1@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) i = head =virtqueue_get_head (vq, vq->last_avail_idx++);if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event (vq, vq->last_avail_idx); }
hw/virtio/dataplane/vring.c:
if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
vring_avail_event(&vring->vr) = vring->vr.avail->idx;
}This is equivalent to the virtio.c code you are replacing, so it should be updated too.
Stefan
Quoted 29 lines · Stefan Hajnoczi
Quoted 19 lines · Bin Wu
The event idx in virtio is an effective way to reduce the number of interrupts and exits of the guest. When the guest puts an request into the virtio ring, it doesn't exit immediately to inform the backend. Instead, the guest checks the "avail" event idx to determine the notification.
In
virtqueue_pop, when a request is poped, the current avail event idx should be set to the number ofvq->last_avail_idx.Signed-off-by Bin Wu <[email protected]>--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio.c +0
-0hw/virtio/virtio.c int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) · line 473
Quoted 6 lines
hw/virtio/virtio.c +1
-1@@ -469,7 +469,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) i = head =virtqueue_get_head (vq, vq->last_avail_idx++);if (vdev->guest_features & (1 <<VIRTIO_RING_F_EVENT_IDX )) { -vring_avail_event (vq,vring_avail_idx (vq)); +vring_avail_event (vq, vq->last_avail_idx); }
hw/virtio/dataplane/vring.c:
Quoted 9 lines
if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) { vring_avail_event(&vring->vr) = vring->vr.avail->idx; }This is equivalent to the
virtio.ccode you are replacing, so it should be updated too.Stefan
Thanks, stefan. I'll send another patch later.
Signature · 1 line
Bin Wu