diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:43 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:43 -0500 |
commit | 3b720b8c865098c49c1570b6b5c7832bcfa6e6c2 (patch) | |
tree | 7580908e53fb78ddc20945075d7f25408a6325fb /drivers/virtio | |
parent | 41f0377f73039ca6fe97a469d1941a89cd9757f1 (diff) |
virtio: avoid modulus operation.
Since we know vq->vring.num is a power of 2, modulus is lazy (it's asserted
in vring_new_virtqueue()).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/virtio')
-rw-r--r-- | drivers/virtio/virtio_ring.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index c56bbe799241..99dc9480f3fe 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c | |||
@@ -250,8 +250,8 @@ add_head: | |||
250 | vq->data[head] = data; | 250 | vq->data[head] = data; |
251 | 251 | ||
252 | /* Put entry in available array (but don't update avail->idx until they | 252 | /* Put entry in available array (but don't update avail->idx until they |
253 | * do sync). FIXME: avoid modulus here? */ | 253 | * do sync). */ |
254 | avail = (vq->vring.avail->idx + vq->num_added++) % vq->vring.num; | 254 | avail = ((vq->vring.avail->idx + vq->num_added++) & (vq->vring.num-1)); |
255 | vq->vring.avail->ring[avail] = head; | 255 | vq->vring.avail->ring[avail] = head; |
256 | 256 | ||
257 | pr_debug("Added buffer head %i to %p\n", head, vq); | 257 | pr_debug("Added buffer head %i to %p\n", head, vq); |
@@ -384,6 +384,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) | |||
384 | struct vring_virtqueue *vq = to_vvq(_vq); | 384 | struct vring_virtqueue *vq = to_vvq(_vq); |
385 | void *ret; | 385 | void *ret; |
386 | unsigned int i; | 386 | unsigned int i; |
387 | u16 last_used; | ||
387 | 388 | ||
388 | START_USE(vq); | 389 | START_USE(vq); |
389 | 390 | ||
@@ -401,8 +402,9 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) | |||
401 | /* Only get used array entries after they have been exposed by host. */ | 402 | /* Only get used array entries after they have been exposed by host. */ |
402 | virtio_rmb(vq); | 403 | virtio_rmb(vq); |
403 | 404 | ||
404 | i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id; | 405 | last_used = (vq->last_used_idx & (vq->vring.num - 1)); |
405 | *len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len; | 406 | i = vq->vring.used->ring[last_used].id; |
407 | *len = vq->vring.used->ring[last_used].len; | ||
406 | 408 | ||
407 | if (unlikely(i >= vq->vring.num)) { | 409 | if (unlikely(i >= vq->vring.num)) { |
408 | BAD_RING(vq, "id %u out of range\n", i); | 410 | BAD_RING(vq, "id %u out of range\n", i); |