From: Stefan Hajnoczi <stefanha@redhat.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
"Michael S. Tsirkin" <mst@redhat.com>,
kvm@vger.kernel.org, netdev@vger.kernel.org,
Jason Wang <jasowang@redhat.com>
Subject: Re: [PATCH v1] vhost: cache avail index in vhost_enable_notify()
Date: Tue, 25 Jan 2022 16:32:16 +0000 [thread overview]
Message-ID: <YfAmEDPXO0P0Q027@stefanha-x1.localdomain> (raw)
In-Reply-To: <20220125111422.tmsnk575jo7ckt46@steredhat>
[-- Attachment #1: Type: text/plain, Size: 2790 bytes --]
On Tue, Jan 25, 2022 at 12:14:22PM +0100, Stefano Garzarella wrote:
> On Mon, Jan 24, 2022 at 11:31:49AM +0000, Stefan Hajnoczi wrote:
> > On Fri, Jan 14, 2022 at 10:05:08AM +0100, Stefano Garzarella wrote:
> > > In vhost_enable_notify() we enable the notifications and we read
> > > the avail index to check if new buffers have become available in
> > > the meantime.
> > >
> > > We are not caching the avail index, so when the device will call
> > > vhost_get_vq_desc(), it will find the old value in the cache and
> > > it will read the avail index again.
> >
> > I think this wording is clearer because we do keep a cached the avail
> > index value, but the issue is we don't update it:
> > s/We are not caching the avail index/We do not update the cached avail
> > index value/
>
> I'll fix in v3.
> It seems I forgot to CC you on v2: https://lore.kernel.org/virtualization/20220121153108.187291-1-sgarzare@redhat.com/
>
> >
> > >
> > > It would be better to refresh the cache every time we read avail
> > > index, so let's change vhost_enable_notify() caching the value in
> > > `avail_idx` and compare it with `last_avail_idx` to check if there
> > > are new buffers available.
> > >
> > > Anyway, we don't expect a significant performance boost because
> > > the above path is not very common, indeed vhost_enable_notify()
> > > is often called with unlikely(), expecting that avail index has
> > > not been updated.
> > >
> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> > > ---
> > > v1:
> > > - improved the commit description [MST, Jason]
> > > ---
> > > drivers/vhost/vhost.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> > > index 59edb5a1ffe2..07363dff559e 100644
> > > --- a/drivers/vhost/vhost.c
> > > +++ b/drivers/vhost/vhost.c
> > > @@ -2543,8 +2543,9 @@ bool vhost_enable_notify(struct vhost_dev
> > > *dev, struct vhost_virtqueue *vq)
> > > &vq->avail->idx, r);
> > > return false;
> > > }
> > > + vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
> > >
> > > - return vhost16_to_cpu(vq, avail_idx) != vq->avail_idx;
> > > + return vq->avail_idx != vq->last_avail_idx;
> >
> > vhost_vq_avail_empty() has a fast path that's missing in
> > vhost_enable_notify():
> >
> > if (vq->avail_idx != vq->last_avail_idx)
> > return false;
>
> Yep, I thought about that, but devices usually call vhost_enable_notify()
> right when vq->avail_idx == vq->last_avail_idx, so I don't know if it's an
> extra check for a branch that will never be taken.
>
> Do you think it is better to add that check? (maybe with unlikely())
You're right. It's probably fine to omit it.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2022-01-25 16:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-14 9:05 [PATCH v1] vhost: cache avail index in vhost_enable_notify() Stefano Garzarella
2022-01-14 12:45 ` Michael S. Tsirkin
2022-01-14 13:38 ` Stefano Garzarella
2022-01-14 13:40 ` Michael S. Tsirkin
2022-01-20 15:08 ` Stefano Garzarella
2022-01-20 16:55 ` Michael S. Tsirkin
2022-01-24 11:31 ` Stefan Hajnoczi
2022-01-25 11:14 ` Stefano Garzarella
2022-01-25 16:32 ` Stefan Hajnoczi [this message]
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=YfAmEDPXO0P0Q027@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sgarzare@redhat.com \
--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).