aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio-rng.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-rng.c
parent044d003db9b6a588be2c9d0ec9de694ba3848551 (diff)
downloadqemu-e1f7b4812eab992de46c98b3726745afb042a7f0.zip
qemu-e1f7b4812eab992de46c98b3726745afb042a7f0.tar.gz
qemu-e1f7b4812eab992de46c98b3726745afb042a7f0.tar.bz2
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-rng.c')
-rw-r--r--hw/virtio-rng.c12
1 files changed, 9 insertions, 3 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);