All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Tiwei Bie <tiwei.bie@intel.com>
Cc: virtio@lists.oasis-open.org, virtio-dev@lists.oasis-open.org,
	Cornelia Huck <cohuck@redhat.com>,
	Halil Pasic <pasic@linux.vnet.ibm.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"Dhanoa, Kully" <kully.dhanoa@intel.com>
Subject: [virtio] Re: [PATCH v8 08/16] packed virtqueues: more efficient virtqueue layout
Date: Sun, 25 Feb 2018 20:49:10 +0200	[thread overview]
Message-ID: <20180225204425-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20180224051706.fjemv3etmswgyqjz@debian>

On Sat, Feb 24, 2018 at 01:17:08PM +0800, Tiwei Bie wrote:
> On Fri, Feb 16, 2018 at 09:24:12AM +0200, Michael S. Tsirkin wrote:
> [...]
> > +\subsection{Scatter-Gather Support}
> > +\label{sec:Packed Virtqueues / Scatter-Gather Support}
> > +
> > +Some drivers need an ability to supply a list of multiple buffer
> > +elements (also known as a scatter/gather list) with a request.
> > +Two optional features support this: descriptor
> > +chaining and indirect descriptors.
> > +
> > +If neither feature has been negotiated, each buffer is
> > +physically-contigious, either read-only or write-only and is
> > +described completely by a single descriptor.
> 
> Based on the updates in "Descriptor Chaining" section
> and the below note in cover letter:
> 
> - dropped _F_DESC_LIST, 1.0 includes this unconditionally, we
>   can do same
> 
> Descriptor chaining is always available.

That's right - I should fix this.

> > +
> [...]
> > +\subsection{Event Suppression Structure Format}\label{sec:Basic
> > +Facilities of a Virtio Device / Packed Virtqueues / Event Suppression Structure
> > +Format}
> > +
> > +The following structure is used to reduce the number of
> > +notifications sent between driver and device.
> > +
> > +\begin{lstlisting}
> > +__le16 desc_event_off : 15; /* Descriptor Event Offset */
> > +int    desc_event_wrap : 1; /* Descriptor Event Wrap Counter */
> 
> Is this `int` a typo?

It's a single bit so I think it does not matter.
What type would you like me to use instead?

> > +__le16 desc_event_flags : 2; /* Descriptor Event Flags */
> > +\end{lstlisting}
> [...]
> > +\subsubsection{Implementation Example}\label{sec:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Implementation Example}
> > +
> > +Below is an example driver code. It does not attempt to reduce
> > +the number of device interrupts, neither does it support
> > +the VIRTIO_F_RING_EVENT_IDX feature.
> > +
> > +\begin{lstlisting}
> > +
> > +first = vq->next_avail;
> > +id = alloc_id(vq);
> > +
> > +for (each buffer element b) {
> > +        vq->desc[vq->next_avail].address = get_addr(b);
> > +        vq->desc[vq->next_avail].len = get_len(b);
> > +        init_desc(vq->next_avail, b);
> > +        avail = vq->avail_wrap_count;
> > +        used = !vq->avail_wrap_count;
> > +        f = get_flags(b) | (avail << VIRTQ_DESC_F_AVAIL) | (used << VIRTQ_DESC_F_USED);
> 
> In this version, above two flags are defined as:
> 
> #define VIRTQ_DESC_F_AVAIL     (1 << 7)
> #define VIRTQ_DESC_F_USED      (1 << 15)
> 
> So we couldn't use them to shift the bit like this.

You are right. I guess we should change all flags to be bit numbers.

> > +	/* Don't mark the 1st descriptor available until all of them are ready. */
> > +        if (vq->next_avail == first) {
> > +                flags = f;
> > +        } else {
> > +                vq->desc[vq->next_avail].flags = f;
> > +        }
> > +
> > +	vq->next_avail++;
> > +
> > +	if (vq->next_avail >= vq->size) {
> > +		vq->next_avail = 0;
> > +		vq->avail_wrap_count \^= 1;
> > +	}
> 
> Maybe it's better to not mix using tab and space in
> this example code.

I'm not sure it matters for latex but I agree we should be
consistent.

> > +
> > +
> > +}
> > +/* ID included in the last descriptor in the list */
> > +vq->desc[vq->next_avail].id = id;
> 
> Maybe it should be something like this:
> 
> vq->desc[prev].id = id;
> 
> Otherwise, the other fields (e.g. flags) of this desc (the
> vq->desc[vq->next_avail]) also need to be updated.
> 
> > +write_memory_barrier();
> > +vq->desc[first].flags = flags;
> > +
> > +memory_barrier();
> > +
> > +if (vq->device_event.flags != 0x2) {
> 
> Maybe it should be:
> 
> if (vq->device_event.flags != 0x1) {
> 
> As the flags definitions in this version are:
> 
> 00b enable events
> 01b disable events
> 10b enable events for a specific descriptor
>     (as specified by Descriptor Ring Change Event Offset/Wrap Counter).
>     Only valid if VIRTIO_F_RING_EVENT_IDX has been negotiated.
> 11b reserved

I'll recheck it and reply to above two separately.


> > +        notify_device(vq);
> > +}
> > +
> > +\end{lstlisting}
> > +
> > +
> > +\drivernormative{\paragraph}{Notifying The Device}{Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Notifying The Device}
> > +The driver MUST perform a suitable memory barrier before reading
> > +the Driver Event Suppression structure, to avoid missing a notification.
> > +
> > +\subsection{Receiving Used Buffers From The Device}\label{sec:Basic Facilities of a Virtio Device / Packed Virtqueues / Receiving Used Buffers From The Device}
> > +
> > +Once the device has used buffers referred to by a descriptor (read from or written to them, or
> > +parts of both, depending on the nature of the virtqueue and the
> > +device), it interrupts the driver
> > +as detailed in section \ref{sec:Basic
> > +Facilities of a Virtio Device / Packed Virtqueues / Event
> > +Suppression Structure Format}.
> > +
> > +\begin{note}
> > +For optimal performance, a driver MAY disable interrupts while processing
> > +the used buffers, but beware the problem of missing interrupts between
> > +emptying the ring and reenabling interrupts.  This is usually handled by
> > +re-checking for more used buffers after interrups are re-enabled:
> > +\end{note}
> > +
> > +\begin{lstlisting}
> > +vq->driver_event.flags = 0x2;
> 
> If my understanding is correct, this is to disable interrupt.
> So maybe it should be:
> 
> vq->driver_event.flags = 0x1;

I'll check.

> > +
> > +for (;;) {
> > +        struct virtq_desc *d = vq->desc[vq->next_used];
> > +
> > +        flags = d->flags;
> > +        bool avail = flags & (1 << VIRTQ_DESC_F_AVAIL);
> > +        bool used = flags & (1 << VIRTQ_DESC_F_USED);
> 
> We couldn't use them to shift the bit like this in this version.
> 
> > +
> > +        if (avail != used) {
> > +                vq->driver_event.flags = 0x1;
> 
> If my understanding is correct, this is to enable interrupt.
> So maybe it should be:
> 
> vq->driver_event.flags = 0x0;
> 
> > +                memory_barrier();
> > +
> > +                flags = d->flags;
> > +                bool avail = flags & (1 << VIRTQ_DESC_F_AVAIL);
> > +                bool used = flags & (1 << VIRTQ_DESC_F_USED);
> 
> We couldn't use them to shift the bit like this in this version.
> 
> > +                if (avail != used) {
> > +                        break;
> > +                }
> > +
> > +                vq->driver_event.flags = 0x2;
> 
> If my understanding is correct, this is to disable interrupt.
> So maybe it should be:
> 
> vq->driver_event.flags = 0x1;


Thanks for all the comments, will address.

> > +        }
> > +
> > +	read_memory_barrier();
> > +        process_buffer(d);
> > +        vq->next_used++;
> > +        if (vq->next_used >= vq->size) {
> > +                vq->next_used = 0;
> > +        }
> > +}
> > +\end{lstlisting}
> > -- 
> > MST
> > 

---------------------------------------------------------------------
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 


  reply	other threads:[~2018-02-25 18:49 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     ` Michael S. Tsirkin [this message]
2018-02-26 10:51       ` 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
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=20180225204425-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=cohuck@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 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.