From: "Michael S. Tsirkin" <mst@redhat.com>
To: Rusty Russell <rusty@rustcorp.com.au>,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, kvm@vger.kernel.org,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCHv2-RFC 1/2] virtio: support layout with avail ring before idx
Date: Wed, 26 May 2010 22:50:38 +0300 [thread overview]
Message-ID: <8a6f96c73a72f04ed7c142e631ca59ee45b4b23b.1274903330.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1274903328.git.mst@redhat.com>
This adds an (unused) option to put available ring
before control (avail index, flags). This avoids cache line
sharing between control and ring, and also
makes it possible to extend avail control without
incurring extra cache misses.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
drivers/virtio/virtio_ring.c | 4 ++--
include/linux/virtio_ring.h | 30 ++++++++++++++++++++++++------
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 1ca8890..2241342 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -224,7 +224,7 @@ add_head:
/* Put entry in available array (but don't update avail->idx until they
* do sync). FIXME: avoid modulus here? */
avail = (vq->vring.avail->idx + vq->num_added++) % vq->vring.num;
- vq->vring.avail->ring[avail] = head;
+ vq->vring.avail_ring[avail] = head;
pr_debug("Added buffer head %i to %p\n", head, vq);
END_USE(vq);
@@ -425,7 +425,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
if (!vq)
return NULL;
- vring_init(&vq->vring, num, pages, vring_align);
+ vring_init(&vq->vring, num, pages, vring_align, false);
vq->vq.callback = callback;
vq->vq.vdev = vdev;
vq->vq.name = name;
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index e4d144b..c5f3ee7 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -47,6 +47,11 @@ struct vring_avail {
__u16 ring[];
};
+struct vring_avail_ctrl {
+ __u16 flags;
+ __u16 idx;
+};
+
/* u32 is used here for ids for padding reasons. */
struct vring_used_elem {
/* Index of start of used descriptor chain. */
@@ -66,7 +71,9 @@ struct vring {
struct vring_desc *desc;
- struct vring_avail *avail;
+ struct vring_avail_ctrl *avail;
+
+ __u16 *avail_ring;
struct vring_used *used;
};
@@ -79,11 +86,18 @@ struct vring {
* // The actual descriptors (16 bytes each)
* struct vring_desc desc[num];
*
- * // A ring of available descriptor heads with free-running index.
+ * // A ring of available descriptor heads with a control structure
+ * // including a free-running index.
+ * // The ring can come either after (legacy) or before the control.
* __u16 avail_flags;
* __u16 avail_idx;
* __u16 available[num];
*
+ * or
+ *
+ * __u16 available[num];
+ * __u16 avail_flags;
+ * __u16 avail_idx;
* // Padding to the next align boundary.
* char pad[];
*
@@ -94,13 +108,17 @@ struct vring {
* };
*/
static inline void vring_init(struct vring *vr, unsigned int num, void *p,
- unsigned long align)
+ unsigned long align, bool avail_ring_first)
{
+ struct vring_avail *avail = p + num * sizeof(struct vring_desc);
vr->num = num;
vr->desc = p;
- vr->avail = p + num*sizeof(struct vring_desc);
- vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + align-1)
- & ~(align - 1));
+ vr->avail_ring = avail_ring_first ? (void*)avail : &avail->ring;
+ vr->avail = avail_ring_first ? (void *)&vr->avail_ring[num] : p;
+ vr->used = (void *)ALIGN((unsigned long)&avail->ring[num], align);
+ /* Verify that avail fits before used. */
+ BUG_ON((unsigned long)(vr->avail + 1) > (unsigned long)vr->used);
+ BUG_ON((unsigned long)(&vr->avail_ring[num]) > (unsigned long)vr->used);
}
static inline unsigned vring_size(unsigned int num, unsigned long align)
--
1.7.1.12.g42b7f
next prev parent reply other threads:[~2010-05-26 19:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-26 19:50 [Qemu-devel] [PATCHv2-RFC 0/2] virtio: put last seen used index into ring itself Michael S. Tsirkin
2010-05-26 19:50 ` Michael S. Tsirkin [this message]
2010-05-26 19:50 ` [Qemu-devel] [PATCHv2-RFC 2/2] virtio: publish used idx Michael S. Tsirkin
2010-05-27 12:07 ` [Qemu-devel] Re: [PATCHv2-RFC 0/2] virtio: put last seen used index into ring itself Avi Kivity
2010-05-27 13:59 ` Michael S. Tsirkin
2010-05-28 9:56 ` Jes Sorensen
2010-05-30 11:22 ` Michael S. Tsirkin
2010-05-31 7:36 ` Jes Sorensen
2010-05-31 13:29 ` Michael S. Tsirkin
2010-05-31 7:46 ` Rusty Russell
2010-05-31 12:20 ` Michael S. Tsirkin
2010-06-02 20:39 ` Jes Sorensen
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=8a6f96c73a72f04ed7c142e631ca59ee45b4b23b.1274903330.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=rusty@rustcorp.com.au \
--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).