b6a9f6520a3b9f567ed29457713198f5ce2a26db
[packages/centos6/qemu.git] / 0186-net-notify-iothread-after-flushing-queue.patch
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
5
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.
13
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)
21
22 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
23 ---
24  hw/virtio-net.c | 4 ----
25  net.c           | 7 ++++++-
26  net/queue.c     | 5 +++--
27  net/queue.h     | 2 +-
28  4 files changed, 10 insertions(+), 8 deletions(-)
29
30 diff --git a/hw/virtio-net.c b/hw/virtio-net.c
31 index b1998b2..6490743 100644
32 --- a/hw/virtio-net.c
33 +++ b/hw/virtio-net.c
34 @@ -447,10 +447,6 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
35      VirtIONet *n = to_virtio_net(vdev);
36  
37      qemu_flush_queued_packets(&n->nic->nc);
38 -
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();
42  }
43  
44  static int virtio_net_can_receive(NetClientState *nc)
45 diff --git a/net.c b/net.c
46 index 60043dd..76a8336 100644
47 --- a/net.c
48 +++ b/net.c
49 @@ -357,7 +357,12 @@ void qemu_flush_queued_packets(NetClientState *nc)
50  {
51      nc->receive_disabled = 0;
52  
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).
57 +         */
58 +        qemu_notify_event();
59 +    }
60  }
61  
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
65 --- a/net/queue.c
66 +++ b/net/queue.c
67 @@ -228,7 +228,7 @@ void qemu_net_queue_purge(NetQueue *queue, NetClientState *from)
68      }
69  }
70  
71 -void qemu_net_queue_flush(NetQueue *queue)
72 +bool qemu_net_queue_flush(NetQueue *queue)
73  {
74      while (!QTAILQ_EMPTY(&queue->packets)) {
75          NetPacket *packet;
76 @@ -244,7 +244,7 @@ void qemu_net_queue_flush(NetQueue *queue)
77                                       packet->size);
78          if (ret == 0) {
79              QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
80 -            break;
81 +            return false;
82          }
83  
84          if (packet->sent_cb) {
85 @@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
86  
87          g_free(packet);
88      }
89 +    return true;
90  }
91 diff --git a/net/queue.h b/net/queue.h
92 index 9d44a9b..fc02b33 100644
93 --- a/net/queue.h
94 +++ b/net/queue.h
95 @@ -53,6 +53,6 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue,
96                                  NetPacketSent *sent_cb);
97  
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);
101  
102  #endif /* QEMU_NET_QUEUE_H */
103 -- 
104 1.7.12.1
105