Patchwork virtio: limit avail bytes lookahead

login
register
mail settings
Submitter Michael S. Tsirkin
Date Nov. 28, 2012, 9:53 p.m.
Message ID <20121128215308.GA23360@redhat.com>
Download mbox | patch
Permalink /patch/202562/
State New
Headers show

Comments

Michael S. Tsirkin - Nov. 28, 2012, 9:53 p.m.
On Tue, Nov 27, 2012 at 06:25:04PM +0200, Michael S. Tsirkin wrote:
> On Thu, Nov 01, 2012 at 06:07:21PM +0200, Michael S. Tsirkin wrote:
> > 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 <mst@redhat.com>
> > Reported-by: Edivaldo de Araujo Pereira <edivaldoapereira@yahoo.com.br>
> 
> Ping.
> Anthony - going to apply this?

virtio rng was added since so naturally build broke.
Here's a patch on top to fix it up. I never used virtio rng before so
could not test at this hour, but it does fix the build.

I'll take a look at how to test it tomorrow but any
info would be appreciated.
Amit could you pls review?

--
Amit Shah - Nov. 29, 2012, 1:04 p.m.
On (Wed) 28 Nov 2012 [23:53:08], Michael S. Tsirkin wrote:
> On Tue, Nov 27, 2012 at 06:25:04PM +0200, Michael S. Tsirkin wrote:
> > On Thu, Nov 01, 2012 at 06:07:21PM +0200, Michael S. Tsirkin wrote:
> > > 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 <mst@redhat.com>
> > > Reported-by: Edivaldo de Araujo Pereira <edivaldoapereira@yahoo.com.br>
> > 
> > Ping.
> > Anthony - going to apply this?
> 
> virtio rng was added since so naturally build broke.
> Here's a patch on top to fix it up. I never used virtio rng before so
> could not test at this hour, but it does fix the build.
> 
> I'll take a look at how to test it tomorrow but any
> info would be appreciated.
> Amit could you pls review?

Looks fine, I assume you will send a v2 of the patch to Anthony?

		Amit
Michael S. Tsirkin - Nov. 29, 2012, 2:10 p.m.
On Thu, Nov 29, 2012 at 06:34:46PM +0530, Amit Shah wrote:
> On (Wed) 28 Nov 2012 [23:53:08], Michael S. Tsirkin wrote:
> > On Tue, Nov 27, 2012 at 06:25:04PM +0200, Michael S. Tsirkin wrote:
> > > On Thu, Nov 01, 2012 at 06:07:21PM +0200, Michael S. Tsirkin wrote:
> > > > 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 <mst@redhat.com>
> > > > Reported-by: Edivaldo de Araujo Pereira <edivaldoapereira@yahoo.com.br>
> > > 
> > > Ping.
> > > Anthony - going to apply this?
> > 
> > virtio rng was added since so naturally build broke.
> > Here's a patch on top to fix it up. I never used virtio rng before so
> > could not test at this hour, but it does fix the build.
> > 
> > I'll take a look at how to test it tomorrow but any
> > info would be appreciated.
> > Amit could you pls review?
> 
> Looks fine, I assume you will send a v2 of the patch to Anthony?
> 
> 		Amit


Anthony volunteered to test this so there will only be v2 if he sees
problems.
Anthony Liguori - Nov. 29, 2012, 7:02 p.m.
"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Thu, Nov 29, 2012 at 06:34:46PM +0530, Amit Shah wrote:
>> On (Wed) 28 Nov 2012 [23:53:08], Michael S. Tsirkin wrote:
>> > On Tue, Nov 27, 2012 at 06:25:04PM +0200, Michael S. Tsirkin wrote:
>> > > On Thu, Nov 01, 2012 at 06:07:21PM +0200, Michael S. Tsirkin wrote:
>> > > > 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 <mst@redhat.com>
>> > > > Reported-by: Edivaldo de Araujo Pereira <edivaldoapereira@yahoo.com.br>
>> > > 
>> > > Ping.
>> > > Anthony - going to apply this?
>> > 
>> > virtio rng was added since so naturally build broke.
>> > Here's a patch on top to fix it up. I never used virtio rng before so
>> > could not test at this hour, but it does fix the build.
>> > 
>> > I'll take a look at how to test it tomorrow but any
>> > info would be appreciated.
>> > Amit could you pls review?
>> 
>> Looks fine, I assume you will send a v2 of the patch to Anthony?
>> 
>> 		Amit
>
>
> Anthony volunteered to test this so there will only be v2 if he sees
> problems.

I need a Signed-off-by so why don't you just go ahead and send a v2 and
I'll test that.

Regards,

Anthony Liguori
Michael S. Tsirkin - Nov. 29, 2012, 10:39 p.m.
> I need a Signed-off-by so why don't you just go ahead and send a v2 and
> I'll test that.

OK I sent a v2 which is this fixup + the original patch smashed
together.

Patch

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);