From patchwork Thu Nov 1 16:07:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 196268 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 426AA2C034B for ; Fri, 2 Nov 2012 03:05:24 +1100 (EST) Received: from localhost ([::1]:33847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTxGk-0003gd-7z for incoming@patchwork.ozlabs.org; Thu, 01 Nov 2012 12:05:22 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTxGd-0003gH-0C for qemu-devel@nongnu.org; Thu, 01 Nov 2012 12:05:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTxGT-0002vS-BL for qemu-devel@nongnu.org; Thu, 01 Nov 2012 12:05:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24543) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTxGT-0002u8-2p for qemu-devel@nongnu.org; Thu, 01 Nov 2012 12:05:05 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qA1G509q006417 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 1 Nov 2012 12:05:00 -0400 Received: from redhat.com (vpn1-6-225.ams2.redhat.com [10.36.6.225]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id qA1G4uM5006315; Thu, 1 Nov 2012 12:04:56 -0400 Date: Thu, 1 Nov 2012 18:07:21 +0200 From: "Michael S. Tsirkin" To: Amit Shah Message-ID: <20121101160721.GA9176@redhat.com> References: <20121022111824.GA6916@amit.redhat.com> <1350913800.90009.YahooMailClassic@web163904.mail.gq1.yahoo.com> <20121023125503.GG19977@stefanha-thinkpad.redhat.com> <20121101091918.GA19405@amit.redhat.com> <20121101120410.GC3993@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20121101120410.GC3993@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Stefan Hajnoczi , Edivaldo de Araujo Pereira , qemu-devel@nongnu.org, Anthony Liguori , Bug 1066055 <1066055@bugs.launchpad.net> Subject: [Qemu-devel] [PATCH] virtio: limit avail bytes lookahead 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 Commit 0d8d7690850eb0cf2b2b60933cf47669a6b6f18f introduced a regression in virtio-net performance because it looks into the ring aggressively while we really only care about a single packet worth of buffers. To fix, add parameters limiting lookahead, and use in virtqueue_avail_bytes. Signed-off-by: Michael S. Tsirkin Reported-by: Edivaldo de Araujo Pereira Acked-by: Amit Shah Reviewed-by: Stefan Hajnoczi --- Edivaldo could you please confirm this fixes regression? diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index d20bd8b..a761cdc 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -297,7 +297,7 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port) if (use_multiport(port->vser) && !port->guest_connected) { return 0; } - virtqueue_get_avail_bytes(vq, &bytes, NULL); + virtqueue_get_avail_bytes(vq, &bytes, NULL, UINT_MAX, 0); return bytes; } diff --git a/hw/virtio.c b/hw/virtio.c index ec8b7d8..f40a8c5 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -336,7 +336,8 @@ static unsigned virtqueue_next_desc(hwaddr desc_pa, } void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, - unsigned int *out_bytes) + unsigned int *out_bytes, + unsigned max_in_bytes, unsigned max_out_bytes) { unsigned int idx; unsigned int total_bufs, in_total, out_total; @@ -385,6 +386,9 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, } else { out_total += vring_desc_len(desc_pa, i); } + if (in_total >= max_in_bytes && out_total >= max_out_bytes) { + goto done; + } } while ((i = virtqueue_next_desc(desc_pa, i, max)) != max); if (!indirect) @@ -392,6 +396,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, else total_bufs++; } +done: if (in_bytes) { *in_bytes = in_total; } @@ -405,12 +410,8 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes, { unsigned int in_total, out_total; - virtqueue_get_avail_bytes(vq, &in_total, &out_total); - if ((in_bytes && in_bytes < in_total) - || (out_bytes && out_bytes < out_total)) { - return 1; - } - return 0; + virtqueue_get_avail_bytes(vq, &in_total, &out_total, in_bytes, out_bytes); + return in_bytes <= in_total && out_bytes <= out_total; } void virtqueue_map_sg(struct iovec *sg, hwaddr *addr, diff --git a/hw/virtio.h b/hw/virtio.h index ac482be..1278328 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -150,7 +150,8 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem); int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes, unsigned int out_bytes); void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes, - unsigned int *out_bytes); + unsigned int *out_bytes, + unsigned max_in_bytes, unsigned max_out_bytes); void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);