From: Rusty Russell <rusty@rustcorp.com.au>
To: habanero@linux.vnet.ibm.com, Shirley Ma <mashirle@us.ibm.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Krishna Kumar2 <krkumar2@in.ibm.com>,
David Miller <davem@davemloft.net>,
kvm@vger.kernel.org, netdev@vger.kernel.org, steved@us.ibm.com,
Tom Lendacky <tahm@linux.vnet.ibm.com>
Subject: Re: Network performance with small packets
Date: Thu, 10 Mar 2011 12:19:42 +1030 [thread overview]
Message-ID: <87fwqv4udl.fsf@rustcorp.com.au> (raw)
In-Reply-To: <1299637278.13202.61.camel@localhost.localdomain>
On Tue, 08 Mar 2011 20:21:18 -0600, Andrew Theurer <habanero@linux.vnet.ibm.com> wrote:
> On Tue, 2011-03-08 at 13:57 -0800, Shirley Ma wrote:
> > On Wed, 2011-02-09 at 11:07 +1030, Rusty Russell wrote:
> > > I've finally read this thread... I think we need to get more serious
> > > with our stats gathering to diagnose these kind of performance issues.
> > >
> > > This is a start; it should tell us what is actually happening to the
> > > virtio ring(s) without significant performance impact...
> >
> > Should we also add similar stat on vhost vq as well for monitoring
> > vhost_signal & vhost_notify?
>
> Tom L has started using Rusty's patches and found some interesting
> results, sent yesterday:
> http://marc.info/?l=kvm&m=129953710930124&w=2
Hmm, I'm not subscribed to kvm@ any more, so I didn't get this, so
replying here:
> Also, it looks like vhost is sending a lot of notifications for
> packets it has received before the guest can get scheduled to disable
> notifications and begin processing the packets resulting in some lock
> contention in the guest (and high interrupt rates).
Yes, this is a virtio design flaw, but one that should be fixable.
We have room at the end of the ring, which we can put a "last_used"
count. Then we can tell if wakeups are redundant, before the guest
updates the flag.
Here's an old patch where I played with implementing this:
virtio: put last_used and last_avail index into ring itself.
Generally, the other end of the virtio ring doesn't need to see where
you're up to in consuming the ring. However, to completely understand
what's going on from the outside, this information must be exposed.
For example, if you want to save and restore a virtio_ring, but you're
not the consumer because the kernel is using it directly.
Fortunately, we have room to expand: the ring is always a whole number
of pages and there's hundreds of bytes of padding after the avail ring
and the used ring, whatever the number of descriptors (which must be a
power of 2).
We add a feature bit so the guest can tell the host that it's writing
out the current value there, if it wants to use that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/virtio/virtio_ring.c | 23 +++++++++++++++--------
include/linux/virtio_ring.h | 12 +++++++++++-
2 files changed, 26 insertions(+), 9 deletions(-)
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
@@ -71,9 +71,6 @@ struct vring_virtqueue
/* Number we've added since last sync. */
unsigned int num_added;
- /* Last used index we've seen. */
- u16 last_used_idx;
-
/* How to notify other side. FIXME: commonalize hcalls! */
void (*notify)(struct virtqueue *vq);
@@ -278,12 +275,13 @@ static void detach_buf(struct vring_virt
static inline bool more_used(const struct vring_virtqueue *vq)
{
- return vq->last_used_idx != vq->vring.used->idx;
+ return vring_last_used(&vq->vring) != vq->vring.used->idx;
}
static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len)
{
struct vring_virtqueue *vq = to_vvq(_vq);
+ struct vring_used_elem *u;
void *ret;
unsigned int i;
@@ -300,8 +298,11 @@ static void *vring_get_buf(struct virtqu
return NULL;
}
- i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id;
- *len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len;
+ u = &vq->vring.used->ring[vring_last_used(&vq->vring) % vq->vring.num];
+ i = u->id;
+ *len = u->len;
+ /* Make sure we don't reload i after doing checks. */
+ rmb();
if (unlikely(i >= vq->vring.num)) {
BAD_RING(vq, "id %u out of range\n", i);
@@ -315,7 +316,8 @@ static void *vring_get_buf(struct virtqu
/* detach_buf clears data, so grab it now. */
ret = vq->data[i];
detach_buf(vq, i);
- vq->last_used_idx++;
+ vring_last_used(&vq->vring)++;
+
END_USE(vq);
return ret;
}
@@ -402,7 +404,6 @@ struct virtqueue *vring_new_virtqueue(un
vq->vq.name = name;
vq->notify = notify;
vq->broken = false;
- vq->last_used_idx = 0;
vq->num_added = 0;
list_add_tail(&vq->vq.list, &vdev->vqs);
#ifdef DEBUG
@@ -413,6 +414,10 @@ struct virtqueue *vring_new_virtqueue(un
vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC);
+ /* We publish indices whether they offer it or not: if not, it's junk
+ * space anyway. But calling this acknowledges the feature. */
+ virtio_has_feature(vdev, VIRTIO_RING_F_PUBLISH_INDICES);
+
/* No callback? Tell other side not to bother us. */
if (!callback)
vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
@@ -443,6 +448,8 @@ void vring_transport_features(struct vir
switch (i) {
case VIRTIO_RING_F_INDIRECT_DESC:
break;
+ case VIRTIO_RING_F_PUBLISH_INDICES:
+ break;
default:
/* We don't understand this bit. */
clear_bit(i, vdev->features);
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -29,6 +29,9 @@
/* We support indirect buffer descriptors */
#define VIRTIO_RING_F_INDIRECT_DESC 28
+/* We publish our last-seen used index at the end of the avail ring. */
+#define VIRTIO_RING_F_PUBLISH_INDICES 29
+
/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
struct vring_desc
{
@@ -87,6 +90,7 @@ struct vring {
* __u16 avail_flags;
* __u16 avail_idx;
* __u16 available[num];
+ * __u16 last_used_idx;
*
* // Padding to the next align boundary.
* char pad[];
@@ -95,6 +99,7 @@ struct vring {
* __u16 used_flags;
* __u16 used_idx;
* struct vring_used_elem used[num];
+ * __u16 last_avail_idx;
* };
*/
static inline void vring_init(struct vring *vr, unsigned int num, void *p,
@@ -111,9 +116,14 @@ static inline unsigned vring_size(unsign
{
return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num)
+ align - 1) & ~(align - 1))
- + sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num;
+ + sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num + 2;
}
+/* We publish the last-seen used index at the end of the available ring, and
+ * vice-versa. These are at the end for backwards compatibility. */
+#define vring_last_used(vr) ((vr)->avail->ring[(vr)->num])
+#define vring_last_avail(vr) (*(__u16 *)&(vr)->used->ring[(vr)->num])
+
#ifdef __KERNEL__
#include <linux/irqreturn.h>
struct virtio_device;
next prev parent reply other threads:[~2011-03-10 1:49 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-25 21:09 Network performance with small packets Steve Dobbelstein
2011-01-26 15:17 ` Michael S. Tsirkin
2011-01-27 18:44 ` Shirley Ma
2011-01-27 19:00 ` Michael S. Tsirkin
2011-01-27 19:09 ` Shirley Ma
2011-01-27 19:31 ` Michael S. Tsirkin
2011-01-27 19:45 ` Shirley Ma
2011-01-27 20:05 ` Michael S. Tsirkin
2011-01-27 20:15 ` Shirley Ma
2011-01-28 18:29 ` Steve Dobbelstein
2011-01-28 22:51 ` Steve Dobbelstein
2011-02-01 15:52 ` [PATCHv2 dontapply] vhost-net tx tuning Michael S. Tsirkin
2011-02-01 23:07 ` Sridhar Samudrala
2011-02-01 23:27 ` Shirley Ma
2011-02-02 4:36 ` Michael S. Tsirkin
2011-01-27 21:02 ` Network performance with small packets David Miller
2011-01-27 21:30 ` Shirley Ma
2011-01-28 12:16 ` Michael S. Tsirkin
2011-02-01 0:24 ` Steve Dobbelstein
2011-02-01 1:30 ` Sridhar Samudrala
2011-02-01 5:56 ` Michael S. Tsirkin
2011-02-01 21:09 ` Shirley Ma
2011-02-01 21:24 ` Michael S. Tsirkin
2011-02-01 21:32 ` Shirley Ma
2011-02-01 21:42 ` Michael S. Tsirkin
2011-02-01 21:53 ` Shirley Ma
2011-02-01 21:56 ` Michael S. Tsirkin
2011-02-01 22:59 ` Shirley Ma
2011-02-02 4:40 ` Michael S. Tsirkin
2011-02-02 6:05 ` Shirley Ma
2011-02-02 6:19 ` Shirley Ma
2011-02-02 6:29 ` Michael S. Tsirkin
2011-02-02 7:14 ` Shirley Ma
2011-02-02 7:33 ` Shirley Ma
2011-02-02 10:49 ` Michael S. Tsirkin
2011-02-02 15:42 ` Shirley Ma
2011-02-02 15:48 ` Michael S. Tsirkin
2011-02-02 17:12 ` Shirley Ma
2011-02-02 18:20 ` Michael S. Tsirkin
2011-02-02 18:26 ` Shirley Ma
2011-02-02 10:48 ` Michael S. Tsirkin
2011-02-02 6:34 ` Krishna Kumar2
2011-02-02 7:03 ` Shirley Ma
2011-02-02 7:37 ` Krishna Kumar2
2011-02-02 10:48 ` Michael S. Tsirkin
2011-02-02 15:39 ` Shirley Ma
2011-02-02 15:47 ` Michael S. Tsirkin
2011-02-02 17:10 ` Shirley Ma
2011-02-02 17:32 ` Michael S. Tsirkin
2011-02-02 18:11 ` Shirley Ma
2011-02-02 18:27 ` Michael S. Tsirkin
2011-02-02 19:29 ` Shirley Ma
2011-02-02 20:17 ` Michael S. Tsirkin
2011-02-02 21:03 ` Shirley Ma
2011-02-02 21:20 ` Michael S. Tsirkin
2011-02-02 21:41 ` Shirley Ma
2011-02-03 5:59 ` Michael S. Tsirkin
2011-02-03 6:09 ` Shirley Ma
2011-02-03 6:16 ` Michael S. Tsirkin
2011-02-03 5:05 ` Shirley Ma
2011-02-03 6:13 ` Michael S. Tsirkin
2011-02-03 15:58 ` Shirley Ma
2011-02-03 16:20 ` Michael S. Tsirkin
2011-02-03 17:18 ` Shirley Ma
2011-02-01 5:54 ` Michael S. Tsirkin
2011-02-01 17:23 ` Michael S. Tsirkin
[not found] ` <1296590943.26937.797.camel@localhost.localdomain>
[not found] ` <20110201201715.GA30050@redhat.com>
2011-02-01 20:25 ` Shirley Ma
2011-02-01 21:21 ` Michael S. Tsirkin
2011-02-01 21:28 ` Shirley Ma
2011-02-01 21:41 ` Michael S. Tsirkin
2011-02-02 4:39 ` Krishna Kumar2
2011-02-02 4:42 ` Michael S. Tsirkin
2011-02-09 0:37 ` Rusty Russell
2011-02-09 0:53 ` Michael S. Tsirkin
2011-02-09 1:39 ` Rusty Russell
2011-02-09 1:55 ` Michael S. Tsirkin
2011-02-09 7:43 ` Stefan Hajnoczi
2011-03-08 21:57 ` Shirley Ma
2011-03-09 2:21 ` Andrew Theurer
2011-03-09 15:42 ` Shirley Ma
2011-03-10 1:49 ` Rusty Russell [this message]
2011-04-12 20:01 ` Michael S. Tsirkin
2011-04-14 11:28 ` Rusty Russell
2011-04-14 12:40 ` Michael S. Tsirkin
2011-04-14 16:03 ` Michael S. Tsirkin
2011-04-19 0:33 ` Rusty Russell
2011-02-02 18:38 ` Michael S. Tsirkin
2011-02-02 19:15 ` Steve Dobbelstein
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=87fwqv4udl.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=davem@davemloft.net \
--cc=habanero@linux.vnet.ibm.com \
--cc=krkumar2@in.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=mashirle@us.ibm.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=steved@us.ibm.com \
--cc=tahm@linux.vnet.ibm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.