qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jan Kiszka <jan.kiszka@siemens.de>,
	Luigi Rizzo <rizzo@iet.unipi.it>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [Qemu-devel] [PATCH 1/3] net: notify iothread after flushing queue
Date: Thu,  9 Aug 2012 16:45:55 +0200	[thread overview]
Message-ID: <1344523557-28266-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1344523557-28266-1-git-send-email-pbonzini@redhat.com>

virtio-net has code to flush the queue and notify the iothread
whenever new receive buffers are added by the guest.  That is
fine, and indeed we need to do the same in all other drivers.
However, notifying the iothread should be work for the network
subsystem.  And since we are at it we can add a little smartness:
if some of the queued packets already could not be delivered,
there is no need to notify the iothread.

Reported-by: Luigi Rizzo <rizzo@iet.unipi.it>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Jan Kiszka <jan.kiszka@siemens.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/virtio-net.c | 4 ----
 net.c           | 7 ++++++-
 net/queue.c     | 5 +++--
 net/queue.h     | 2 +-
 4 file modificati, 10 inserzioni(+), 8 rimozioni(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index b1998b2..6490743 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -447,10 +447,6 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
     VirtIONet *n = to_virtio_net(vdev);
 
     qemu_flush_queued_packets(&n->nic->nc);
-
-    /* We now have RX buffers, signal to the IO thread to break out of the
-     * select to re-poll the tap file descriptor */
-    qemu_notify_event();
 }
 
 static int virtio_net_can_receive(NetClientState *nc)
diff --git a/net.c b/net.c
index 60043dd..76a8336 100644
--- a/net.c
+++ b/net.c
@@ -357,7 +357,12 @@ void qemu_flush_queued_packets(NetClientState *nc)
 {
     nc->receive_disabled = 0;
 
-    qemu_net_queue_flush(nc->send_queue);
+    if (qemu_net_queue_flush(nc->send_queue)) {
+        /* We emptied the queue successfully, signal to the IO thread to repoll
+         * the file descriptor (for tap, for example).
+         */
+        qemu_notify_event();
+    }
 }
 
 static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
diff --git a/net/queue.c b/net/queue.c
index e8030aa..f3f0098 100644
--- a/net/queue.c
+++ b/net/queue.c
@@ -228,7 +228,7 @@ void qemu_net_queue_purge(NetQueue *queue, NetClientState *from)
     }
 }
 
-void qemu_net_queue_flush(NetQueue *queue)
+bool qemu_net_queue_flush(NetQueue *queue)
 {
     while (!QTAILQ_EMPTY(&queue->packets)) {
         NetPacket *packet;
@@ -244,7 +244,7 @@ void qemu_net_queue_flush(NetQueue *queue)
                                      packet->size);
         if (ret == 0) {
             QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
-            break;
+            return 0;
         }
 
         if (packet->sent_cb) {
@@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue)
 
         g_free(packet);
     }
+    return 1;
 }
diff --git a/net/queue.h b/net/queue.h
index 9d44a9b..fc02b33 100644
--- a/net/queue.h
+++ b/net/queue.h
@@ -53,6 +53,6 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue,
                                 NetPacketSent *sent_cb);
 
 void qemu_net_queue_purge(NetQueue *queue, NetClientState *from);
-void qemu_net_queue_flush(NetQueue *queue);
+bool qemu_net_queue_flush(NetQueue *queue);
 
 #endif /* QEMU_NET_QUEUE_H */
-- 
1.7.11.2

  reply	other threads:[~2012-08-09 14:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-09 14:45 [Qemu-devel] [PATCH 0/3] net: add missing queue flush for e1000 and xen Paolo Bonzini
2012-08-09 14:45 ` Paolo Bonzini [this message]
2012-08-09 17:55   ` [Qemu-devel] [PATCH 1/3] net: notify iothread after flushing queue Blue Swirl
2012-08-10  6:59     ` Stefan Hajnoczi
2012-08-09 14:45 ` [Qemu-devel] [PATCH 2/3] e1000: flush queue whenever can_receive can go from false to true Paolo Bonzini
2012-08-09 14:45 ` [Qemu-devel] [PATCH 3/3] xen: flush queue when getting an event Paolo Bonzini
2012-08-09 15:16 ` [Qemu-devel] [PATCH 0/3] net: add missing queue flush for e1000 and xen Stefan Hajnoczi
2012-08-09 15:18   ` Stefano Stabellini
2012-08-30  2:32 ` Amos Kong
  -- strict thread matches above, loose matches on Subject: below --
2012-08-10 13:27 [Qemu-devel] [PULL 0/3] Net patches Stefan Hajnoczi
2012-08-10 13:27 ` [Qemu-devel] [PATCH 1/3] net: notify iothread after flushing queue Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1344523557-28266-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jan.kiszka@siemens.de \
    --cc=qemu-devel@nongnu.org \
    --cc=rizzo@iet.unipi.it \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=stefano.stabellini@eu.citrix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).