From: "Michael S. Tsirkin" <mst@redhat.com>
To: Halil Pasic <pasic@linux.vnet.ibm.com>
Cc: Jens Freimann <jfreimann@redhat.com>,
virtio@lists.oasis-open.org, virtio-dev@lists.oasis-open.org,
Cornelia Huck <cohuck@redhat.com>,
Tiwei Bie <tiwei.bie@intel.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Dhanoa, Kully" <kully.dhanoa@intel.com>
Subject: Re: [virtio] Re: [virtio-dev] Re: [PATCH v8 08/16] packed virtqueues: more efficient virtqueue layout
Date: Thu, 1 Mar 2018 00:01:54 +0200 [thread overview]
Message-ID: <20180301000046-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <19c6b2bd-b8ec-9365-a820-2974ee591e7a@linux.vnet.ibm.com>
On Tue, Feb 27, 2018 at 12:29:11PM +0100, Halil Pasic wrote:
>
>
> On 02/27/2018 11:23 AM, Jens Freimann wrote:
> > On Mon, Feb 26, 2018 at 11:05:14PM +0200, Michael S. Tsirkin wrote:
> >> On Mon, Feb 26, 2018 at 06:19:21PM +0100, Halil Pasic wrote:
> >>> > + vq->driver_event.flags = 0x1;
> >>> > + memory_barrier();
> >>> > +
> >>> > + flags = d->flags;
> >>> > + bool avail = flags & (1 << VIRTQ_DESC_F_AVAIL);
> >>> > + bool used = flags & (1 << VIRTQ_DESC_F_USED);
> >>> > + if (avail != used) {
> >>> > + break;
> >>> > + }
> >>> > +
> >>> > + vq->driver_event.flags = 0x2;
> >>> > + }
> >>> > +
> >>> > + read_memory_barrier();
> >>>
> >>> Now with the condition avail != used a freshly (that is zero initialized)
> >>> ring would appear all used. And we would do process_buffer(d) for the
> >>> whole ring if this code happens to get executed. Do we have to make
> >>> sure that this does not happen?
> >>
> >> I'll have to think about this.
> >
> > With the wrap counter initialized to 1 descriptors would not be seen
> > as used.
>
> Looking at the code... In vhost:
>
> +static bool desc_is_avail(struct vhost_virtqueue *vq,
> + struct vring_desc_packed *desc)
> +{
> + if (vq->used_wrap_counter)
> + if ((desc->flags & DESC_AVAIL) && !(desc->flags & DESC_USED))
> + return true;
> + if (vq->used_wrap_counter == false)
> + if (!(desc->flags & DESC_AVAIL) && (desc->flags & DESC_USED))
> + return true;
> +
> + return false;
> +}
>
> Here the bit pattern corresponding to available depends on the
> value of the wrap counter. I kind of anticipated this, but I could not
> find it defined in this spec.
>
> OTOH in guest:
>
> +static inline bool more_used_packed(const struct vring_virtqueue *vq)
> +{
> + u16 last_used, flags;
> + bool avail, used;
> +
> + if (vq->vq.num_free == vq->vring.num)
> + return false;
> +
> + last_used = vq->last_used_idx;
> + flags = virtio16_to_cpu(vq->vq.vdev,
> + vq->vring_packed.desc[last_used].flags);
> + avail = flags & VRING_DESC_F_AVAIL(1);
> + used = flags & VRING_DESC_F_USED(1);
> +
> + return avail == used;
> +}
>
> if the next to be used descriptor is actually used does not depend on
> any wrap counter, but has vq->vq.num_free == vq->vring.num as an extra
> condition. This extra condition is basically 'there are outstanding
> descriptors' and those are obviously either 'available' or yet to be observed
> 'used' descriptors. Right after initialization is covered by this extra
> condition. And obviously if the descriptor in question is still available
> flags & VRING_DESC_F_AVAIL(1) != flags & VRING_DESC_F_USED(1) holds, so
> with the extra condition we are right there where we want to be.
>
> But I could not find the extra condition in the spec.
>
> With that said, I also want to point out that I don't understand
> your statement Jens. I don't see a way to express the condition corresponding
> to more_used_packed() using the driver wrap counter (avail_wrap_count).
> Of course a wrap counter that wraps when last_used wraps could be used
> to (but no such counter is mentioned here AFAIU).
I added such a counter in the pseudo-code.
> >>
> >>
> >>> I was under the impression that this whole wrap counter exercise is
> >>> to be able to distinguish these cases.
> >>>
> >>> BTW tools/virtio/ringtest/ring.c has a single flag bit to indicate
> >>> available/used and does not have these wrap counters AFAIR.
> >>
> >> A single flag is fine if there's not s/g support and all descriptors are
> >> written out. Wrap counters are needed if we are to support skipping
> >> descriptors because of s/g or in order.
> >>
> >>
> >>> Also for split virtqueues a descriptor has three possible states:
> >>> * available
> >>> * used
> >>> * free
> >>>
> >>> I wonder if it's the same for packed, and if, how do I recognize
> >>> free descriptors (that is descriptors that are neither available
> >>> nor used.
> >>
> >> I'll think about this.
> >>
> >>> I'm pretty much confused on how this scheme with the available
> >>> and used wrap counters (or device and driver wrap counters is
> >>> supposed to work). A working implementation in C would really help
> >>> me to understand this.
> >>
> >> DPDK based implementation has been posted.
> >
> > vhost and guest drivers have also been posted.
> > guest: https://lkml.org/lkml/2018/2/23/242
> > vhost: https://lkml.org/lkml/2018/2/13/1102
> >
>
> Thanks a lot. I've already found vhost myself but you saved me
> some searching with the other one ;).
>
> > regards,
> > Jens
> >>
> >>> > + process_buffer(d);
> >>> > + vq->next_used++;
> >>> > + if (vq->next_used >= vq->size) {
> >>> > + vq->next_used = 0;
> >>> > + }
> >>> > +}
> >>> > +\end{lstlisting}
> >>> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
> >> For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this mail list, you must leave the OASIS TC that
> generates this mail. Follow this link to all your TCs in OASIS at:
> https://www.oasis-open.org/apps/org/workgroup/portal/my_workgroups.php
---------------------------------------------------------------------
To unsubscribe from this mail list, you must leave the OASIS TC that
generates this mail. Follow this link to all your TCs in OASIS at:
https://www.oasis-open.org/apps/org/workgroup/portal/my_workgroups.php
next prev parent reply other threads:[~2018-02-28 22:01 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1518765602-8739-1-git-send-email-mst@redhat.com>
2018-02-16 7:21 ` [PATCH v8 01/16] content: move 1.0 queue format out to a separate section Michael S. Tsirkin
2018-02-16 7:21 ` [PATCH v8 02/16] content: move ring text out to a separate file Michael S. Tsirkin
2018-02-16 7:21 ` [PATCH v8 03/16] content: move virtqueue operation description Michael S. Tsirkin
2018-02-16 7:22 ` [PATCH v8 04/16] content: replace mentions of len with used length Michael S. Tsirkin
2018-02-16 16:35 ` [virtio] " Cornelia Huck
2018-02-16 7:22 ` [PATCH v8 05/16] content: generalize transport ring part naming Michael S. Tsirkin
2018-02-16 7:24 ` [PATCH v8 08/16] packed virtqueues: more efficient virtqueue layout Michael S. Tsirkin
2018-02-16 17:01 ` [virtio] " Cornelia Huck
2018-02-24 5:17 ` [virtio-dev] " Tiwei Bie
2018-02-25 18:49 ` [virtio] " Michael S. Tsirkin
2018-02-26 10:51 ` [virtio-dev] " Tiwei Bie
2018-02-26 20:38 ` [virtio] " Michael S. Tsirkin
2018-02-27 1:49 ` Tiwei Bie
2018-02-27 20:17 ` [virtio] " Michael S. Tsirkin
2018-02-28 9:19 ` Tiwei Bie
2018-02-28 15:20 ` [virtio] " Michael S. Tsirkin
2018-02-28 16:09 ` Cornelia Huck
2018-02-28 20:35 ` Michael S. Tsirkin
2018-02-26 17:19 ` [virtio] " Halil Pasic
2018-02-26 21:05 ` Michael S. Tsirkin
2018-02-27 10:23 ` [virtio-dev] " Jens Freimann
2018-02-27 11:29 ` [virtio] " Halil Pasic
2018-02-28 13:42 ` Jens Freimann
2018-02-28 13:59 ` [virtio] " Halil Pasic
2018-02-28 15:40 ` Michael S. Tsirkin
2018-02-28 16:29 ` Halil Pasic
2018-02-28 22:03 ` Michael S. Tsirkin
2018-02-28 22:01 ` Michael S. Tsirkin [this message]
2018-02-27 11:53 ` [virtio] " Halil Pasic
2018-02-27 14:11 ` Michael S. Tsirkin
2018-02-27 17:03 ` Halil Pasic
2018-02-28 13:25 ` [virtio-dev] " Jens Freimann
2018-02-28 22:10 ` [virtio] " Michael S. Tsirkin
2018-02-16 7:24 ` [PATCH v8 09/16] content: in-order buffer use Michael S. Tsirkin
2018-02-16 7:25 ` [PATCH v8 10/16] packed-ring: add in order support Michael S. Tsirkin
2018-02-16 7:25 ` [PATCH v8 11/16] split-ring: in order feature Michael S. Tsirkin
2018-02-16 7:25 ` [PATCH v8 12/16] makediff: update to show diff from master Michael S. Tsirkin
2018-02-16 16:45 ` [virtio] " Cornelia Huck
2018-02-16 7:26 ` [PATCH v8 13/16] REVISION: set to 1.1 wd07 Michael S. Tsirkin
2018-02-16 7:26 ` [PATCH v8 14/16] VIRTIO_F_NOTIFICATION_DATA: extra data to devices Michael S. Tsirkin
2018-02-16 17:00 ` [virtio] " Cornelia Huck
2018-02-16 7:26 ` [PATCH v8 15/16] conformance: link the new conformance clause Michael S. Tsirkin
2018-02-16 16:46 ` [virtio] " Cornelia Huck
2018-02-16 7:27 ` [PATCH v8 16/16] REVISION: set for packed-wd07.pdf Michael S. Tsirkin
2018-02-16 16:47 ` [virtio] " Cornelia Huck
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=20180301000046-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=cohuck@redhat.com \
--cc=jfreimann@redhat.com \
--cc=kully.dhanoa@intel.com \
--cc=pasic@linux.vnet.ibm.com \
--cc=stefanha@redhat.com \
--cc=tiwei.bie@intel.com \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtio@lists.oasis-open.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