Discussion of the implementations of VIRTIO specification
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: virtio@lists.oasis-open.org, virtio-dev@lists.oasis-open.org
Cc: Cornelia Huck <cohuck@redhat.com>,
	Halil Pasic <pasic@linux.vnet.ibm.com>,
	Tiwei Bie <tiwei.bie@intel.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"Dhanoa, Kully" <kully.dhanoa@intel.com>
Subject: [virtio] Re: [PATCH v9 10/16] packed virtqueues: more efficient virtqueue layout
Date: Wed, 7 Mar 2018 15:47:40 +0200	[thread overview]
Message-ID: <20180307154220-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1519860484-7936-11-git-send-email-mst@redhat.com>

On Thu, Mar 01, 2018 at 01:31:34AM +0200, Michael S. Tsirkin wrote:
> Performance analysis of this is in my kvm forum 2016 presentation.  The
> idea is to have a r/w descriptor in a ring structure, replacing the used
> and available ring, index and descriptor buffer.
> 
> This is also easier for devices to implement than the 1.0 layout.
> Several more enhancements will be necessary to actually make this
> efficient for devices to use.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Acked-by: Cornelia Huck <cohuck@redhat.com>

OK so it's been almost a week and no more comments, but I went
over it myself again and found a bug in the pseudocode. It did
not handle out of order used buffers correctly.  The right thing
to do is to record the number of descriptors - not the id - in a
driver-specific data structure.

As it's just a pseudocode change, I assume it's not a reason for
more delay.  Will include in the final version which I plan to
start voting on early next week.


diff --git a/packed-ring.tex b/packed-ring.tex
index 12bab67..99912c3 100644
--- a/packed-ring.tex
+++ b/packed-ring.tex
@@ -594,12 +594,15 @@ the VIRTIO_F_RING_EVENT_IDX feature.
 
 \begin{lstlisting}
 /* Note: vq->avail_wrap_count is initialized to 1 */
-/* Note: vq->ids is an array same size as the ring */
+/* Note: vq->sgs is an array same size as the ring */
 
-first = vq->next_avail;
 id = alloc_id(vq);
 
+first = vq->next_avail;
+sgs = 0;
 for (each buffer element b) {
+        sgs++;
+
         vq->ids[vq->next_avail] = -1;
         vq->desc[vq->next_avail].address = get_addr(b);
         vq->desc[vq->next_avail].len = get_len(b);
@@ -607,9 +610,9 @@ for (each buffer element b) {
         avail = vq->avail_wrap_count ? VIRTQ_DESC_F_AVAIL : 0;
         used = !vq->avail_wrap_count ? VIRTQ_DESC_F_USED : 0;
         f = get_flags(b) | avail | used;
-	if (b is not the last buffer element) {
-		f |= VIRTQ_DESC_F_NEXT;
-	}
+        if (b is not the last buffer element) {
+                f |= VIRTQ_DESC_F_NEXT;
+        }
 
         /* Don't mark the 1st descriptor available until all of them are ready. */
         if (vq->next_avail == first) {
@@ -626,11 +629,10 @@ for (each buffer element b) {
                 vq->next_avail = 0;
                 vq->avail_wrap_count \^= 1;
         }
-
-
 }
+vq->sgs[id] = sgs;
 /* ID included in the last descriptor in the list */
-vq->ids[last] = vq->desc[last].id = id;
+vq->desc[last].id = id;
 write_memory_barrier();
 vq->desc[first].flags = flags;
 
@@ -689,15 +691,17 @@ for (;;) {
 
         read_memory_barrier();
 
-	/* skip descriptors until we find the correct ID */
-        do {
-		found = vq->ids[vq->next_used] == d->id;
-                vq->next_used++;
-                if (vq->next_used >= vq->size) {
-                        vq->next_used = 0;
-                        vq->used_wrap_count \^= 1;
-                }
-        } while (!found);
+        /* skip descriptors until the next buffer */
+        id = d->id;
+        assert(id < vq->size);
+        sgs = vq->sgs[id];
+        vq->next_used += sgs;
+        if (vq->next_used >= vq->size) {
+                vq->next_used -= vq->size;
+                vq->used_wrap_count \^= 1;
+        }
+
+        free_id(vq, id);
 
         process_buffer(d);
 }

---------------------------------------------------------------------
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-03-07 13:47 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 23:31 [virtio] [PATCH v9 00/16] packed ring layout spec Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 01/16] introduction: document bitfield notation Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 02/16] content: move 1.0 queue format out to a separate section Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 03/16] content: move ring text out to a separate file Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 04/16] content: move virtqueue operation description Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 05/16] content: len -> used length, used ring -> vq Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 06/16] content: generalize transport ring part naming Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 07/16] content: generalize rest of text Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 08/16] split-ring: generalize text Michael S. Tsirkin
2018-03-07 11:00   ` [virtio] " Cornelia Huck
2018-03-09 22:56     ` Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 09/16] split-ring: typo: aligment Michael S. Tsirkin
2018-03-07 10:56   ` [virtio] " Cornelia Huck
2018-02-28 23:31 ` [virtio] [PATCH v9 10/16] packed virtqueues: more efficient virtqueue layout Michael S. Tsirkin
2018-03-07 13:47   ` Michael S. Tsirkin [this message]
2018-02-28 23:31 ` [virtio] [PATCH v9 11/16] content: in-order buffer use Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 13/16] split-ring: in order feature Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 12/16] packed-ring: add in order support Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 14/16] VIRTIO_F_NOTIFICATION_DATA: extra data to devices Michael S. Tsirkin
2018-03-07 11:11   ` [virtio] " Cornelia Huck
2018-03-07 14:09     ` Michael S. Tsirkin
2018-03-07 14:49       ` Cornelia Huck
2018-03-07 15:10         ` Michael S. Tsirkin
2018-03-07 15:13           ` Cornelia Huck
2018-03-07 16:05         ` Halil Pasic
2018-03-07 16:14           ` Cornelia Huck
2018-03-07 19:53             ` Michael S. Tsirkin
2018-03-08 13:03               ` [virtio] Re: [virtio-dev] " Halil Pasic
2018-03-08 16:19                 ` Michael S. Tsirkin
2018-03-09  8:16                   ` Cornelia Huck
2018-03-09 12:25                   ` Halil Pasic
2018-03-09 16:52                     ` Michael S. Tsirkin
2018-03-07 19:27           ` Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH v9 15/16] makediff: update to show diff from master Michael S. Tsirkin
2018-02-28 23:31 ` [virtio] [PATCH dont commit v9 16/16] REVISION: set to 1.1 packed wd09 Michael S. Tsirkin
2018-03-09 17:06 ` [virtio] Re: [PATCH v9 00/16] packed ring layout spec Michael S. Tsirkin

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=20180307154220-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox