From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeTEm-0000YJ-CB for qemu-devel@nongnu.org; Fri, 30 Nov 2012 11:14:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TeTEf-0002HJ-Tn for qemu-devel@nongnu.org; Fri, 30 Nov 2012 11:14:48 -0500 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:35689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeTEf-0002CA-4b for qemu-devel@nongnu.org; Fri, 30 Nov 2012 11:14:41 -0500 Received: from /spool/local by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 30 Nov 2012 21:44:32 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id EF4BBE0045 for ; Fri, 30 Nov 2012 21:43:59 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qAUGETTC30539894 for ; Fri, 30 Nov 2012 21:44:29 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qAULiKWv031222 for ; Sat, 1 Dec 2012 08:44:20 +1100 From: Anthony Liguori In-Reply-To: <20121129220256.GA14799@redhat.com> References: <20121129220256.GA14799@redhat.com> Date: Fri, 30 Nov 2012 10:14:21 -0600 Message-ID: <87k3t36pb6.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCHv2] virtio: limit avail bytes lookahead List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , qemu-devel@nongnu.org, stefanha@redhat.com, edivaldoapereira@yahoo.com.br Cc: Amit Shah "Michael S. Tsirkin" writes: > 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. > Reported as bugzilla 1066055 in launchpad. > > To fix, add parameters limiting lookahead, and > use in virtqueue_avail_bytes. > > Signed-off-by: Michael S. Tsirkin > Reported-by: Edivaldo de Araujo Pereira > Tested-by: Edivaldo de Araujo Pereira > Reviewed-by: Stefan Hajnoczi > --- > > Anthony says he wants to test this, I only compiled this patch. I tested it and it works. Applied. Thanks. Regards, Anthony Liguori > > hw/virtio-rng.c | 12 +++++++++--- > hw/virtio-serial-bus.c | 2 +- > hw/virtio.c | 15 ++++++++------- > hw/virtio.h | 3 ++- > 4 files changed, 20 insertions(+), 12 deletions(-) > > diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c > index df329f2..a73ef8e 100644 > --- a/hw/virtio-rng.c > +++ b/hw/virtio-rng.c > @@ -43,11 +43,11 @@ static bool is_guest_ready(VirtIORNG *vrng) > return false; > } > > -static size_t get_request_size(VirtQueue *vq) > +static size_t get_request_size(VirtQueue *vq, unsigned quota) > { > unsigned int in, out; > > - virtqueue_get_avail_bytes(vq, &in, &out); > + virtqueue_get_avail_bytes(vq, &in, &out, quota, 0); > return in; > } > > @@ -84,12 +84,18 @@ static void chr_read(void *opaque, const void *buf, size_t size) > static void virtio_rng_process(VirtIORNG *vrng) > { > size_t size; > + unsigned quota; > > if (!is_guest_ready(vrng)) { > return; > } > > - size = get_request_size(vrng->vq); > + if (vrng->quota_remaining < 0) { > + quota = 0; > + } else { > + quota = MIN((uint64_t)vrng->quota_remaining, (uint64_t)UINT32_MAX); > + } > + size = get_request_size(vrng->vq, quota); > size = MIN(vrng->quota_remaining, size); > if (size) { > rng_backend_request_entropy(vrng->rng, size, chr_read, vrng); > diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c > index efa8a81..155da58 100644 > --- a/hw/virtio-serial-bus.c > +++ b/hw/virtio-serial-bus.c > @@ -306,7 +306,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, 4096, 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 df8d0f7..7c17f7b 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); > > -- > MST