[Lguest] [PATCH 1/2] lguest: Split add_used() into two logical steps

Mark McLoughlin markmc at redhat.com
Thu Oct 9 06:35:07 EST 2008


Split add_used() into two logical steps - adding an buffer
to the used ring and notifying the other side of used buffers.

Signed-off-by: Mark McLoughlin <markmc at redhat.com>
---
 Documentation/lguest/lguest.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
index 7228369..2ddf0c6 100644
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -750,21 +750,35 @@ static unsigned get_vq_desc(struct virtqueue *vq,
 	return head;
 }
 
-/* After we've used one of their buffers, we tell them about it.  We'll then
- * want to send them an interrupt, using trigger_irq(). */
-static void add_used(struct virtqueue *vq, unsigned int head, int len)
+/* After we've used one of their buffers, we add it to the used list */
+static void add_used(struct virtqueue *vq, unsigned int head, int len, int idx)
 {
 	struct vring_used_elem *used;
 
+	idx += vq->vring.used->idx;
+
 	/* The virtqueue contains a ring of used buffers.  Get a pointer to the
 	 * next entry in that used ring. */
-	used = &vq->vring.used->ring[vq->vring.used->idx % vq->vring.num];
+	used = &vq->vring.used->ring[idx % vq->vring.num];
 	used->id = head;
 	used->len = len;
+}
+
+/* Next we need to tell them about the buffers we've used.  We'll then want to
+ * send them an interrupt, using trigger_irq(). */
+static void flush_used(struct virtqueue *vq, unsigned int count)
+{
 	/* Make sure buffer is written before we update index. */
 	wmb();
-	vq->vring.used->idx++;
-	vq->inflight--;
+	vq->vring.used->idx += count;
+	vq->inflight -= count;
+}
+
+/* Usually, you only use a single buffer at a time */
+static void add_used_and_flush(struct virtqueue *vq, unsigned int head, int len)
+{
+	add_used(vq, head, len, 0);
+	flush_used(vq, 1);
 }
 
 /* This actually sends the interrupt for this virtqueue */
@@ -786,7 +800,7 @@ static void trigger_irq(int fd, struct virtqueue *vq)
 static void add_used_and_trigger(int fd, struct virtqueue *vq,
 				 unsigned int head, int len)
 {
-	add_used(vq, head, len);
+	add_used_and_flush(vq, head, len);
 	trigger_irq(fd, vq);
 }
 
@@ -1677,7 +1691,7 @@ static bool service_io(struct device *dev)
 
 	/* We can't trigger an IRQ, because we're not the Launcher.  It does
 	 * that when we tell it we're done. */
-	add_used(dev->vq, head, wlen);
+	add_used_and_flush(dev->vq, head, wlen);
 	return true;
 }
 
-- 
1.5.4.3




More information about the Lguest mailing list