From patchwork Thu Aug 9 14:45:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 176134 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 6FEB42C00E0 for ; Fri, 10 Aug 2012 00:46:41 +1000 (EST) Received: from localhost ([::1]:35600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzU0V-0003rS-JR for incoming@patchwork.ozlabs.org; Thu, 09 Aug 2012 10:46:39 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzU0H-0003M3-Hu for qemu-devel@nongnu.org; Thu, 09 Aug 2012 10:46:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzU0B-0000jN-4s for qemu-devel@nongnu.org; Thu, 09 Aug 2012 10:46:25 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:60799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzU0B-0000bU-01 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 10:46:19 -0400 Received: by mail-gh0-f173.google.com with SMTP id r17so492701ghr.4 for ; Thu, 09 Aug 2012 07:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=mrQl2Cs0+tWPUrIZXNv96Di1GvfxGRXeQcXiswNJETc=; b=Bqh9AgH2B5O6Qq+bUkEgUwyI9RWY52Ha6OKsVokVDS4CvoZoFSy6TT+RVrV8hog+Rb qp/UUYCnjzVN16Cm7i1Y4AQyiPknQdDcjlX+06iGFxYTqCSHRPiw5fJRu57gvrAnZT/E 4DDOxUaYSGLlPdiMVNe3W2FpwabkYgRVKOZRXTWpqoGmA7rTYgekL12QMavh6wBytPlf cYEB7bx+PSc6KakbxuzBEK9SMBqB+5rdww3Ntgcz8kprQjnrsrXWGkp8iS433l4hDsLe 4/M8Lwc74RqbOFf/W8SWXlg2/udgRyeZ7OnEntZSdP3hPqF8O1FbLOXwVhjW1M84tlH8 COBg== Received: by 10.66.78.42 with SMTP id y10mr42283868paw.31.1344523578367; Thu, 09 Aug 2012 07:46:18 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id qx8sm1265153pbc.63.2012.08.09.07.46.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Aug 2012 07:46:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2012 16:45:55 +0200 Message-Id: <1344523557-28266-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1344523557-28266-1-git-send-email-pbonzini@redhat.com> References: <1344523557-28266-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.173 Cc: Jan Kiszka , Luigi Rizzo , Stefan Hajnoczi , Stefano Stabellini Subject: [Qemu-devel] [PATCH 1/3] 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 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 --- 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 */