public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm@vger.kernel.org, Mark McLoughlin <markmc@redhat.com>
Subject: [PATCH 03/12] kvm: qemu: Add VIRTIO_F_NOTIFY_ON_EMPTY
Date: Mon, 11 Aug 2008 21:12:06 +0100	[thread overview]
Message-ID: <1218485535-877-4-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1218485535-877-3-git-send-email-markmc@redhat.com>

Set the VIRTIO_F_NOTIFY_ON_EMPTY feature bit so the
guest can rely on us notifying them when the queue
is empty.

Also, only notify when the available queue is empty
*and* when we've finished with all the buffers we
had detached. Right now, when the queue is empty,
we notify the guest for every used buffer.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 qemu/hw/virtio.c |    6 +++++-
 qemu/hw/virtio.h |    5 +++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/qemu/hw/virtio.c b/qemu/hw/virtio.c
index 3429ac8..e035e4e 100644
--- a/qemu/hw/virtio.c
+++ b/qemu/hw/virtio.c
@@ -138,6 +138,7 @@ void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
     /* Make sure buffer is written before we update index. */
     wmb();
     vq->vring.used->idx++;
+    vq->inuse--;
 }
 
 int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
@@ -187,6 +188,8 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
 
     elem->index = head;
 
+    vq->inuse++;
+
     return elem->in_num + elem->out_num;
 }
 
@@ -275,6 +278,7 @@ static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
     switch (addr) {
     case VIRTIO_PCI_HOST_FEATURES:
 	ret = vdev->get_features(vdev);
+	ret |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY);
 	break;
     case VIRTIO_PCI_GUEST_FEATURES:
 	ret = vdev->features;
@@ -431,7 +435,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
 {
     /* Always notify when queue is empty */
-    if (vq->vring.avail->idx != vq->last_avail_idx &&
+    if ((vq->inuse || vq->vring.avail->idx != vq->last_avail_idx) &&
 	(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
 	return;
 
diff --git a/qemu/hw/virtio.h b/qemu/hw/virtio.h
index 61f5038..1adaed3 100644
--- a/qemu/hw/virtio.h
+++ b/qemu/hw/virtio.h
@@ -30,6 +30,10 @@
 /* We've given up on this device. */
 #define VIRTIO_CONFIG_S_FAILED		0x80
 
+/* We notify when the ring is completely used, even if the guest is supressing
+ * callbacks */
+#define VIRTIO_F_NOTIFY_ON_EMPTY        24
+
 /* from Linux's linux/virtio_ring.h */
 
 /* This marks a buffer as continuing via the next field. */
@@ -86,6 +90,7 @@ struct VirtQueue
     VRing vring;
     uint32_t pfn;
     uint16_t last_avail_idx;
+    int inuse;
     void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq);
 };
 
-- 
1.5.4.1


  reply	other threads:[~2008-08-11 20:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-11 20:12 [PATCH 0/12] virtio_net perf patches Mark McLoughlin
2008-08-11 20:12 ` [PATCH 01/12] kvm: qemu: Fix virtio_net tx timer Mark McLoughlin
2008-08-11 20:12   ` [PATCH 02/12] kvm: qemu: Remove virtio_net tx ring-full heuristic Mark McLoughlin
2008-08-11 20:12     ` Mark McLoughlin [this message]
2008-08-11 20:12       ` [PATCH 04/12] kvm: qemu: Disable recv notifications until avail buffers exhausted Mark McLoughlin
2008-08-11 20:12         ` [PATCH 05/12] kvm: qemu: Add support for partial csums and GSO Mark McLoughlin
2008-08-11 20:12           ` [PATCH 06/12] kvm: qemu: Rename tap_readv() to tap_receive_iov() Mark McLoughlin
2008-08-11 20:12             ` [PATCH 07/12] kvm: qemu: Move some code around for the next commit Mark McLoughlin
2008-08-11 20:12               ` [PATCH 08/12] kvm: qemu: Don't require all drivers to use virtio_net_hdr Mark McLoughlin
2008-08-11 20:12                 ` [PATCH 09/12] kvm: qemu: Actually enable GSO support Mark McLoughlin
2008-08-11 20:12                   ` [PATCH 10/12] kvm: qemu: Add a -net tap,fd=X,vnet_hdr=on option Mark McLoughlin
2008-08-11 20:12                     ` [PATCH 11/12] kvm: qemu: Increase size of virtio_net rings Mark McLoughlin
2008-08-11 20:12                       ` [PATCH 12/12] kvm: qemu: Drop the mutex while reading from tapfd Mark McLoughlin
2008-08-11 20:30                     ` [PATCH 10/12] kvm: qemu: Add a -net tap,fd=X,vnet_hdr=on option Anthony Liguori
2008-08-12 17:41                 ` [PATCH 08/12] kvm: qemu: Don't require all drivers to use virtio_net_hdr Mark McLoughlin
2008-08-13  9:13                   ` Avi Kivity
2008-08-11 20:30 ` [PATCH 0/12] virtio_net perf patches Anthony Liguori
2008-08-12 18:12   ` Mark McLoughlin
2008-08-12 18:28     ` Anthony Liguori
2008-08-12 23:39     ` Herbert Xu
2008-08-12 13:51 ` Avi Kivity
2008-08-12 14:55   ` Avi Kivity
2008-08-13 14:39   ` [PATCH 1/1] kvm: qemu: Handle tap fds with IFF_VNET_HDR Mark McLoughlin
2008-08-13 16:24     ` Avi Kivity
2008-08-13 16:28       ` Daniel P. Berrange
2008-08-20 17:04       ` [PATCH] " Mark McLoughlin
2008-08-20 17:09         ` Mark McLoughlin
2008-08-20 17:27           ` Avi Kivity
2008-08-20 17:49         ` Anthony Liguori
2008-08-20 17:51           ` Avi Kivity
2008-08-20 18:01             ` Anthony Liguori
2008-08-21  9:30             ` Mark McLoughlin
2008-08-21 13:55               ` Avi Kivity
2008-08-21 13:58                 ` Anthony Liguori
2008-08-20 18:11           ` Daniel P. Berrange

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=1218485535-877-4-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --cc=avi@qumranet.com \
    --cc=kvm@vger.kernel.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