1 From 7d797af90c5293b518a072da9b23ec14a1a917f7 Mon Sep 17 00:00:00 2001
2 From: Paolo Bonzini <pbonzini@redhat.com>
3 Date: Thu, 9 Aug 2012 16:45:55 +0200
4 Subject: [PATCH] net: notify iothread after flushing queue
6 virtio-net has code to flush the queue and notify the iothread
7 whenever new receive buffers are added by the guest. That is
8 fine, and indeed we need to do the same in all other drivers.
9 However, notifying the iothread should be work for the network
10 subsystem. And since we are at it we can add a little smartness:
11 if some of the queued packets already could not be delivered,
12 there is no need to notify the iothread.
14 Reported-by: Luigi Rizzo <rizzo@iet.unipi.it>
15 Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
16 Cc: Jan Kiszka <jan.kiszka@siemens.de>
17 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
18 Reviewed-by: Amos Kong <akong@redhat.com>
19 Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
20 (cherry picked from commit 987a9b4800003567b1a47a379255e886a77d57ea)
22 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
24 hw/virtio-net.c | 4 ----
28 4 files changed, 10 insertions(+), 8 deletions(-)
30 diff --git a/hw/virtio-net.c b/hw/virtio-net.c
31 index b1998b2..6490743 100644
34 @@ -447,10 +447,6 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
35 VirtIONet *n = to_virtio_net(vdev);
37 qemu_flush_queued_packets(&n->nic->nc);
39 - /* We now have RX buffers, signal to the IO thread to break out of the
40 - * select to re-poll the tap file descriptor */
41 - qemu_notify_event();
44 static int virtio_net_can_receive(NetClientState *nc)
45 diff --git a/net.c b/net.c
46 index 60043dd..76a8336 100644
49 @@ -357,7 +357,12 @@ void qemu_flush_queued_packets(NetClientState *nc)
51 nc->receive_disabled = 0;
53 - qemu_net_queue_flush(nc->send_queue);
54 + if (qemu_net_queue_flush(nc->send_queue)) {
55 + /* We emptied the queue successfully, signal to the IO thread to repoll
56 + * the file descriptor (for tap, for example).
58 + qemu_notify_event();
62 static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
63 diff --git a/net/queue.c b/net/queue.c
64 index e8030aa..6e64091 100644
67 @@ -228,7 +228,7 @@ void qemu_net_queue_purge(NetQueue *queue, NetClientState *from)
71 -void qemu_net_queue_flush(NetQueue *queue)
72 +bool qemu_net_queue_flush(NetQueue *queue)
74 while (!QTAILQ_EMPTY(&queue->packets)) {
76 @@ -244,7 +244,7 @@ void qemu_net_queue_flush(NetQueue *queue)
79 QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
84 if (packet->sent_cb) {
85 @@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
91 diff --git a/net/queue.h b/net/queue.h
92 index 9d44a9b..fc02b33 100644
95 @@ -53,6 +53,6 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue,
96 NetPacketSent *sent_cb);
98 void qemu_net_queue_purge(NetQueue *queue, NetClientState *from);
99 -void qemu_net_queue_flush(NetQueue *queue);
100 +bool qemu_net_queue_flush(NetQueue *queue);
102 #endif /* QEMU_NET_QUEUE_H */