From patchwork Fri Sep 14 08:46:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 183842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 022B62C0080 for ; Fri, 14 Sep 2012 18:47:48 +1000 (EST) Received: from localhost ([::1]:39633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYw-0004SP-13 for incoming@patchwork.ozlabs.org; Fri, 14 Sep 2012 04:47:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYZ-0004RD-AS for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCRYV-0000sJ-Au for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:23 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:48553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCRYV-0000s8-0C for qemu-devel@nongnu.org; Fri, 14 Sep 2012 04:47:19 -0400 Received: by wgbdr1 with SMTP id dr1so370149wgb.10 for ; Fri, 14 Sep 2012 01:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=a4VEazlHWkl9zKwB9NA6H1nygWtA1bN1KB4CHUYVrYg=; b=fAARL8LKLRuxqZACMKPdiwVWX9WpkItlTto8ZJRI6+6HB9StGSNOHY2OrXYFOhXx8i Z3B5GCVT4+SiiSGynomLKSlFtxptKUcC+RIC/P9mk24iRXfKjbFTZq+BvTjM2gx14Iqm UhLIeoHkSlG03lw8njTUTXEo2sU+1GdGBOhGGmYsT5+Cj01yMjo3Jb0VEpHee0O9Ea50 6mtAtRMZ9E26syipEFpnRRMt3bz7is45LHHk80lqP46y2I1FjEYQClPRbkEdujsQwJGo KOB/m4PymDo1m8hjk6LmsfGFL8IznGULrf/wI11rgYB2pnj1xzS7tcaGRqk6OvXSB8V6 9aSA== Received: by 10.216.139.143 with SMTP id c15mr1118204wej.154.1347612438088; Fri, 14 Sep 2012 01:47:18 -0700 (PDT) Received: from localhost ([109.224.133.37]) by mx.google.com with ESMTPS id cu1sm17859292wib.6.2012.09.14.01.47.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Sep 2012 01:47:17 -0700 (PDT) From: Stefan Hajnoczi To: Anthony Liguori Date: Fri, 14 Sep 2012 09:46:48 +0100 Message-Id: <1347612420-5704-2-git-send-email-stefanha@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1347612420-5704-1-git-send-email-stefanha@gmail.com> References: <1347612420-5704-1-git-send-email-stefanha@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.53 Cc: Paolo Bonzini , Jan Kiszka , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 01/13] net: notify iothread after flushing queue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini 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 Cc: Stefan Hajnoczi Cc: Jan Kiszka Signed-off-by: Paolo Bonzini Reviewed-by: Amos Kong Signed-off-by: Stefan Hajnoczi --- hw/virtio-net.c | 4 ---- net.c | 7 ++++++- net/queue.c | 5 +++-- net/queue.h | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) 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 e5d25d4..d9ba1e5 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..6e64091 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 false; } if (packet->sent_cb) { @@ -253,4 +253,5 @@ void qemu_net_queue_flush(NetQueue *queue) g_free(packet); } + return true; } 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 */