[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <f3831c1617c86a51d875.1320306173@localhost6.localdomain6>
Date: Thu, 03 Nov 2011 18:12:53 +1030
From: Rusty Russell <rusty@...tcorp.com.au>
To: MichaelS.Tsirkist@...hat.com, Christoph Hellwig <hch@...radead.org>
Cc: virtualization <virtualization@...ts.linux-foundation.org>,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 5 of 5] virtio: expose added descriptors immediately
A virtio driver does virtqueue_add_buf() multiple times before finally
calling virtqueue_kick(); previously we only exposed the added buffers
in the virtqueue_kick() call. This means we don't need a memory
barrier in virtqueue_add_buf(), but it reduces concurrency as the
device (ie. host) can't see the buffers until the kick.
Signed-off-by: Rusty Russell <rusty@...tcorp.com.au>
---
drivers/virtio/virtio_ring.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
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
@@ -227,9 +227,15 @@ add_head:
/* Put entry in available array (but don't update avail->idx until they
* do sync). */
- avail = ((vq->vring.avail->idx + vq->num_added++) & (vq->vring.num-1));
+ avail = (vq->vring.avail->idx & (vq->vring.num-1));
vq->vring.avail->ring[avail] = head;
+ /* Descriptors and available array need to be set before we expose the
+ * new available array entries. */
+ virtio_wmb();
+ vq->vring.avail->idx++;
+ vq->num_added++;
+
pr_debug("Added buffer head %i to %p\n", head, vq);
END_USE(vq);
@@ -248,13 +254,10 @@ bool virtqueue_kick_prepare(struct virtq
* new available array entries. */
virtio_wmb();
- old = vq->vring.avail->idx;
- new = vq->vring.avail->idx = old + vq->num_added;
+ old = vq->vring.avail->idx - vq->num_added;
+ new = vq->vring.avail->idx;
vq->num_added = 0;
- /* Need to update avail index before checking if we should notify */
- virtio_mb();
-
if (vq->event) {
needs_kick = vring_need_event(vring_avail_event(&vq->vring),
new, old);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists