[PATCH 2/3] Add support for VRING_USED_F_NOTIFY_ON_FULL

Anthony Liguori
2008-01-07T21:41:29Z

This patch adds support for VRING_USED_F_NOTIFY_ON_FULL. When this bit is
set, virtio ring notifications will be suppressed unless the virtio ring is
full.

Signed-off-by: Anthony Liguori <aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 1302ac4..ee7936f 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -146,7 +146,9 @@ static void vring_kick(struct virtqueue *_vq)
/* Need to update avail index before checking if we should notify */
mb();

- if (!(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY))
+ if (!(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY) &&
+ (!(vq->vring.used->flags & VRING_USED_F_NOTIFY_ON_FULL) ||
+ (vq->num_free == 0)))
/* Prod other side to tell it about changes. */
vq->notify(&vq->vq);

diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index ea3be89..ae6092e 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -17,8 +17,13 @@

/* This means don't notify other side when buffer added. */
#define VRING_USED_F_NO_NOTIFY 1
+/* Don't notify the other side unless the buffer is full */
+#define VRING_USED_F_NOTIFY_ON_FULL 2
+
/* This means don't interrupt guest when buffer consumed. */
#define VRING_AVAIL_F_NO_INTERRUPT 1
+/* Don't notify the other side unless the buffer is full */
+#define VRING_AVAIL_F_NOTIFY_ON_FULL 2

/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
struct vring_desc