virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: MichaelS.Tsirkist@redhat.com, Christoph Hellwig <hch@infradead.org>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	virtualization <virtualization@lists.linux-foundation.org>
Subject: [PATCH 4 of 5] virtio: avoid modulus operation
Date: Thu, 03 Nov 2011 18:12:52 +1030	[thread overview]
Message-ID: <05de9ee25e222c5206f3.1320306172@localhost6.localdomain6> (raw)
In-Reply-To: <patchbomb.1320306168@localhost6.localdomain6>

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>
---
 drivers/virtio/virtio_ring.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1420,7 +1420,7 @@ __init void lguest_init(void)
 	add_preferred_console("hvc", 0, NULL);
 
 	/* Register our very early console. */
-	virtio_cons_early_init(early_put_chars);
+//	virtio_cons_early_init(early_put_chars);
 
 	/*
 	 * Last of all, we set the power management poweroff hook to point to
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -226,8 +226,8 @@ add_head:
 	vq->data[head] = data;
 
 	/* Put entry in available array (but don't update avail->idx until they
-	 * do sync).  FIXME: avoid modulus here? */
-	avail = (vq->vring.avail->idx + vq->num_added++) % vq->vring.num;
+	 * do sync). */
+	avail = ((vq->vring.avail->idx + vq->num_added++) & (vq->vring.num-1));
 	vq->vring.avail->ring[avail] = head;
 
 	pr_debug("Added buffer head %i to %p\n", head, vq);
@@ -317,6 +317,7 @@ void *virtqueue_get_buf(struct virtqueue
 	struct vring_virtqueue *vq = to_vvq(_vq);
 	void *ret;
 	unsigned int i;
+	u16 last_used;
 
 	START_USE(vq);
 
@@ -334,8 +335,9 @@ void *virtqueue_get_buf(struct virtqueue
 	/* Only get used array entries after they have been exposed by host. */
 	virtio_rmb();
 
-	i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id;
-	*len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len;
+	last_used = (vq->last_used_idx & (vq->vring.num - 1));
+	i = vq->vring.used->ring[last_used].id;
+	*len = vq->vring.used->ring[last_used].len;
 
 	if (unlikely(i >= vq->vring.num)) {
 		BAD_RING(vq, "id %u out of range\n", i);

  parent reply	other threads:[~2011-11-03  7:42 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <patchbomb.1320306168@localhost6.localdomain6>
2011-11-03  7:42 ` [PATCH 1 of 5] virtio: document functions better Rusty Russell
2011-11-03  7:49   ` Christoph Hellwig
2011-11-03  7:42 ` [PATCH 2 of 5] virtio: rename virtqueue_add_buf_gfp to virtqueue_add_buf Rusty Russell
2011-11-03  7:50   ` Christoph Hellwig
2011-11-03  7:42 ` [PATCH 3 of 5] virtio: support unlocked queue kick Rusty Russell
2011-11-03  7:52   ` Christoph Hellwig
     [not found]   ` <20111103075211.GD6993@infradead.org>
2011-11-04 10:09     ` Stefan Hajnoczi
2011-11-04 10:36     ` Rusty Russell
2011-11-03  7:42 ` Rusty Russell [this message]
2011-11-03  7:51   ` [PATCH 4 of 5] virtio: avoid modulus operation Pekka Enberg
     [not found]   ` <CAOJsxLEt6_y7jw0bRsaita4gfb2k+BAQMeRLs9PcHntGVSFvaQ@mail.gmail.com>
2011-11-03 10:18     ` Rusty Russell
2011-11-03  7:42 ` [PATCH 5 of 5] virtio: expose added descriptors immediately Rusty Russell
2011-11-13 21:03   ` Michael S. Tsirkin
2011-11-14  0:43     ` Rusty Russell
2011-11-14  6:56     ` Michael S. Tsirkin
2011-11-16  0:21       ` Rusty Russell
2011-11-16  7:18         ` Michael S. Tsirkin
2011-11-21  1:48           ` Rusty Russell
2011-11-21 11:57             ` Michael S. Tsirkin
2011-11-22  0:33               ` Rusty Russell
2011-11-22  6:29                 ` Michael S. Tsirkin
2011-11-23  1:19                   ` Rusty Russell
2011-11-23  8:30                     ` Michael S. Tsirkin
2012-07-01  9:20   ` RFD: virtio balloon API use (was Re: [PATCH 5 of 5] virtio: expose added descriptors immediately) Michael S. Tsirkin
2012-07-02  1:05     ` Rusty Russell
2012-07-02  7:25       ` Michael S. Tsirkin
2012-07-02 16:08         ` Rafael Aquini
2012-07-03  0:47           ` Rusty Russell
2012-07-03 16:26             ` Rafael Aquini
2012-07-04 10:55             ` Michael S. Tsirkin
2012-07-08 23:39               ` Rusty Russell
2012-07-04 10:55           ` Michael S. Tsirkin
2012-07-02  7:33       ` [PATCH RFC] virtio-balloon: fix add/get API use Michael S. Tsirkin
2012-07-04  3:27         ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05de9ee25e222c5206f3.1320306172@localhost6.localdomain6 \
    --to=rusty@rustcorp.com.au \
    --cc=MichaelS.Tsirkist@redhat.com \
    --cc=hch@infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).