]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
virtio: expose added descriptors immediately.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 14 Nov 2011 23:07:38 +0000 (10:07 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Mon, 14 Nov 2011 23:10:07 +0000 (10:10 +1100)
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@rustcorp.com.au>
drivers/virtio/virtio_ring.c

index 0f7473fb422246e41e3f1ec1b1604677baeb4eda..d604087884f142da124367b773fbc24d76756b11 100644 (file)
@@ -245,9 +245,19 @@ 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++;
+
+       /* If you haven't kicked in this long, you're probably doing something
+        * wrong. */
+       WARN_ON(vq->num_added > vq->vring.num);
+
        pr_debug("Added buffer head %i to %p\n", head, vq);
        END_USE(vq);
 
@@ -277,13 +287,10 @@ bool virtqueue_kick_prepare(struct virtqueue *_vq)
         * 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);