virtio: Do not notify virtqueue if no element was pushed back.
PATCH 1/1 virtio: Do not notify virtqueue if no element was pushed back.
--- hw/char/virtio-serial-bus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/char/virtio-serial-bus.c +5 -1
@@ -105,6 +105,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, VirtIODevice *vdev) {VirtIOSerialPortClass *vsc; +bool elem_pushed = false;assert (port);assert (virtio_queue_ready (vq));
@@ -145,9 +146,12 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,break ; }virtqueue_push (vq, &port->elem,0 ); + elem_pushed = true; port->elem.out_num =0 ; } -virtio_notify (vdev, vq); +if (elem_pushed) { +virtio_notify (vdev, vq); + } }static void flush_queued_data (VirtIOSerialPort *port)
Signature · 1 line
1.8.1.4
Quoted 22 lines · Gal Hammer
Signed-off-by Gal Hammer <[email protected]>--- hw/char/virtio-serial-bus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/char/virtio-serial-bus.c +1
-0@@ -105,6 +105,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, VirtIODevice *vdev) {VirtIOSerialPortClass *vsc; +bool elem_pushed = false;assert (port);assert (virtio_queue_ready (vq));@@ -145,9 +146,12 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,break ; }virtqueue_push (vq, &port->elem,0 );
hw/char/virtio-serial-bus.c static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, · line 157
Quoted 10 lines
hw/char/virtio-serial-bus.c +4
-1+ elem_pushed = true; port->elem.out_num =0 ; } -virtio_notify (vdev, vq); +if (elem_pushed) { +virtio_notify (vdev, vq); + } }static void flush_queued_data (VirtIOSerialPort *port)
I could be missing something, but it looks good to me.
BTW the subject should say: "virtio-serial: ...", not generic "virtio: ...".
How did you catch this? Is this a performance problem, or did it expose a guest driver bug? (The guest driver should be prepared for spurious wakeups.)
Quoted 31 lines · Laszlo Ersek
Quoted 30 lines · Gal Hammer
Signed-off-by Gal Hammer <[email protected]>--- hw/char/virtio-serial-bus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/char/virtio-serial-bus.c +5
-1@@ -105,6 +105,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, VirtIODevice *vdev) {VirtIOSerialPortClass *vsc; +bool elem_pushed = false;assert (port);assert (virtio_queue_ready (vq));@@ -145,9 +146,12 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,break ; }virtqueue_push (vq, &port->elem,0 ); + elem_pushed = true; port->elem.out_num =0 ; } -virtio_notify (vdev, vq); +if (elem_pushed) { +virtio_notify (vdev, vq); + } }
Quoted 4 lines
hw/char/virtio-serial-bus.c static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, · line 157
Quoted 2 lines
hw/char/virtio-serial-bus.c +0
-0static void flush_queued_data (VirtIOSerialPort *port)I could be missing something, but it looks good to me.
Thanks.
Quoted 1 line
BTW the subject should say: "virtio-serial: ...", not generic "virtio: ...".
OK. I can change that.
Quoted 3 lines
How did you catch this? Is this a performance problem, or did it expose a guest driver bug? (The guest driver should be prepared for spurious wakeups.)
I had a bug in the Windows' driver that caused a buffer duplication when the char device didn't read the whole message. It was found when working with SPICE client over WAN (i.e. slow connection) and trying to copy&paste a large image.
The driver was fixed. However I still think that this is needed although I'm not sure if there is a major performance penalty because of this redundant notification.
Gal.
Quoted 2 lines
Reviewed-by Laszlo Ersek <[email protected]>