From: Rusty Russell <rusty@rustcorp.com.au>
To: MichaelS.Tsirkist@redhat.com, Christoph Hellwig <hch@infradead.org>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
virtualization <virtualization@lists.linux-foundation.org>
Subject: [PATCH 3 of 5] virtio: support unlocked queue kick
Date: Thu, 03 Nov 2011 18:12:51 +1030 [thread overview]
Message-ID: <c0db93dbb414ab6dbcde.1320306171@localhost6.localdomain6> (raw)
In-Reply-To: <patchbomb.1320306168@localhost6.localdomain6>
Based on patch by Christoph for virtio_blk speedup:
Split virtqueue_kick to be able to do the actual notification
outside the lock protecting the virtqueue. This patch was
originally done by Stefan Hajnoczi, but I can't find the
original one anymore and had to recreated it from memory.
Pointers to the original or corrections for the commit message
are welcome.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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
@@ -237,10 +237,12 @@ add_head:
}
EXPORT_SYMBOL_GPL(virtqueue_add_buf);
-void virtqueue_kick(struct virtqueue *_vq)
+bool virtqueue_kick_prepare(struct virtqueue *_vq)
{
struct vring_virtqueue *vq = to_vvq(_vq);
u16 new, old;
+ bool needs_kick;
+
START_USE(vq);
/* Descriptors and available array need to be set before we expose the
* new available array entries. */
@@ -253,13 +255,30 @@ void virtqueue_kick(struct virtqueue *_v
/* Need to update avail index before checking if we should notify */
virtio_mb();
- if (vq->event ?
- vring_need_event(vring_avail_event(&vq->vring), new, old) :
- !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY))
- /* Prod other side to tell it about changes. */
- vq->notify(&vq->vq);
+ if (vq->event) {
+ needs_kick = vring_need_event(vring_avail_event(&vq->vring),
+ new, old);
+ } else {
+ needs_kick = (!(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY));
+ }
+ END_USE(vq);
+ return needs_kick;
+}
+EXPORT_SYMBOL_GPL(virtqueue_kick_prepare);
- END_USE(vq);
+void virtqueue_notify(struct virtqueue *_vq)
+{
+ struct vring_virtqueue *vq = to_vvq(_vq);
+
+ /* Prod other side to tell it about changes. */
+ vq->notify(_vq);
+}
+EXPORT_SYMBOL_GPL(virtqueue_notify);
+
+void virtqueue_kick(struct virtqueue *vq)
+{
+ if (virtqueue_kick_prepare(vq))
+ virtqueue_notify(vq);
}
EXPORT_SYMBOL_GPL(virtqueue_kick);
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -62,6 +62,27 @@ int virtqueue_add_buf(struct virtqueue *
void virtqueue_kick(struct virtqueue *vq);
/**
+ * virtqueue_kick_prepare - first half of split virtqueue_kick call.
+ * @vq: the struct virtqueue
+ *
+ * Instead of virtqueue_kick(), you can do:
+ * if (virtqueue_kick_prepare(vq))
+ * virtqueue_notify(vq);
+ *
+ * This is sometimes useful because the virtqueue_kick_prepare() needs
+ * to be serialized, but the actual virtqueue_notify() call does not.
+ */
+bool virtqueue_kick_prepare(struct virtqueue *vq);
+
+/**
+ * virtqueue_notify - second half of split virtqueue_kick call.
+ * @vq: the struct virtqueue
+ *
+ * This does not need to be serialized.
+ */
+void virtqueue_notify(struct virtqueue *vq);
+
+/**
* virtqueue_get_buf - get the next used buffer
* @vq: the struct virtqueue we're talking about.
* @len: the length written into the buffer
next prev parent reply other threads:[~2011-11-03 7:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <patchbomb.1320306168@localhost6.localdomain6>
2011-11-03 7:42 ` [PATCH 1 of 5] virtio: document functions better Rusty Russell
2011-11-03 7:49 ` Christoph Hellwig
2011-11-03 7:42 ` [PATCH 2 of 5] virtio: rename virtqueue_add_buf_gfp to virtqueue_add_buf Rusty Russell
2011-11-03 7:50 ` Christoph Hellwig
2011-11-03 7:42 ` Rusty Russell [this message]
2011-11-03 7:52 ` [PATCH 3 of 5] virtio: support unlocked queue kick Christoph Hellwig
[not found] ` <20111103075211.GD6993@infradead.org>
2011-11-04 10:09 ` Stefan Hajnoczi
2011-11-04 10:36 ` Rusty Russell
2011-11-03 7:42 ` [PATCH 4 of 5] virtio: avoid modulus operation Rusty Russell
2011-11-03 7:51 ` Pekka Enberg
[not found] ` <CAOJsxLEt6_y7jw0bRsaita4gfb2k+BAQMeRLs9PcHntGVSFvaQ@mail.gmail.com>
2011-11-03 10:18 ` Rusty Russell
2011-11-03 7:42 ` [PATCH 5 of 5] virtio: expose added descriptors immediately Rusty Russell
2011-11-13 21:03 ` Michael S. Tsirkin
2011-11-14 0:43 ` Rusty Russell
2011-11-14 6:56 ` Michael S. Tsirkin
2011-11-16 0:21 ` Rusty Russell
2011-11-16 7:18 ` Michael S. Tsirkin
2011-11-21 1:48 ` Rusty Russell
2011-11-21 11:57 ` Michael S. Tsirkin
2011-11-22 0:33 ` Rusty Russell
2011-11-22 6:29 ` Michael S. Tsirkin
2011-11-23 1:19 ` Rusty Russell
2011-11-23 8:30 ` Michael S. Tsirkin
2012-07-01 9:20 ` RFD: virtio balloon API use (was Re: [PATCH 5 of 5] virtio: expose added descriptors immediately) Michael S. Tsirkin
2012-07-02 1:05 ` Rusty Russell
2012-07-02 7:25 ` Michael S. Tsirkin
2012-07-02 16:08 ` Rafael Aquini
2012-07-03 0:47 ` Rusty Russell
2012-07-03 16:26 ` Rafael Aquini
2012-07-04 10:55 ` Michael S. Tsirkin
2012-07-08 23:39 ` Rusty Russell
2012-07-04 10:55 ` Michael S. Tsirkin
2012-07-02 7:33 ` [PATCH RFC] virtio-balloon: fix add/get API use Michael S. Tsirkin
2012-07-04 3:27 ` Rusty Russell
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=c0db93dbb414ab6dbcde.1320306171@localhost6.localdomain6 \
--to=rusty@rustcorp.com.au \
--cc=MichaelS.Tsirkist@redhat.com \
--cc=hch@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.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;
as well as URLs for NNTP newsgroup(s).