aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2012-11-30 00:02:56 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2012-11-29 17:25:02 -0600
commite1f7b4812eab992de46c98b3726745afb042a7f0 (patch)
tree288ec43f0807224674026579208dc46748bcaf32 /hw/virtio.c
parent044d003db9b6a588be2c9d0ec9de694ba3848551 (diff)
virtio: limit avail bytes lookahead
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 <mst@redhat.com> Reported-by: Edivaldo de Araujo Pereira <edivaldoapereira@yahoo.com.br> Tested-by: Edivaldo de Araujo Pereira <edivaldoapereira@yahoo.com.br> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio.c')
-rw-r--r--hw/virtio.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/hw/virtio.c b/hw/virtio.c
index ec8b7d8463..f40a8c5571 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,