All of lore.kernel.org
 help / color / mirror / Atom feed
From: "zhunxun@gmail.com" <zhunxun@gmail.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: qemu <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] virtIO question
Date: Sat, 12 Nov 2016 16:43:21 +0800	[thread overview]
Message-ID: <201611121643189598926@gmail.com> (raw)
In-Reply-To: 20161111120347.GB8930@stefanha-x1.localdomain

Thanks,the expression is not the key problem,I just write it wrong,the key problem is that what I get from the code is everytime dirver add a sg ,it will call virtqueue_kick,such as network driver,in start_xmit function ,it called xmit_skb generate a sg list and add it to the queue,then called virtqueue_kick ,why it handle like this??can you explain it to me??thank you very much!!!



zhunxun@gmail.com
 
From: Stefan Hajnoczi
Date: 2016-11-11 20:03
To: zhunxun@gmail.com
CC: qemu
Subject: Re: Re: [Qemu-devel] virtIO question
On Thu, Nov 10, 2016 at 08:16:38PM +0800, zhunxun@gmail.com wrote:
> From this point of view ,I think it make sense well, thank you very much!
>  but I have another question about notify mechanism between virtIO driver and qemu.
> according the source code of Linux and qemu,
> when driver add a sg buffer to send queue named sq,
> sq->vq->vring.avail->idx++
> vq->num_added++
> and then use virtqueue_kick_prepare to make sure if need notify qemu.
> it (new_idx-event_idx)<(new_idx-old_idx)
 
This expression is wrong.  The specification and Linux code both say:
 
  (u16)(new_idx - event_idx - 1) < (u16)(new_idx - old_idx)
 
Both the (u16) and the -1 matter.  Maybe that's why you are confused by
this?
 
> if it is true,then notify other side.
> However,every time driver add a sg,then virtqueue_kick_prepare is called,and vq->num_added  is reseted to 0,so in fact ,I think vq->num_added is always 0 or 1。
 
A driver may add multiple buffers to the virtqueue by calling
virtqueue_add_sgs() or similar functions multiple times before kicking.
Therefore vq->num_added > 1 is possible.
 
> as to qemu side,every time when pop a elem from virtqueue,it set VRingUsed.ring[vring.num] to the lastest VRingAvail.idx, this according the arithmetic ((new_idx-event_idx)<(new_idx-old_idx)),it seems that this mechanism does not make sense
 
You are basically asking "how does event_idx work?".  The specification
says:
 
  "The driver can ask the device to delay interrupts until an entry with
  an index specified by the “used_event” field is written in the used ring
  (equivalently, until the idx field in the used ring will reach the
  value used_event + 1)."
 
and:
 
  "The device can ask the driver to delay notifications until an entry
  with an index specified by the “avail_event” field is written in the
  available ring (equivalently, until the idx field in the used ring will
  reach the value avail_event + 1)."
 
Whenever the device or driver wants to notify, it first checks if the
index update crossed the event index set by the other side.

  reply	other threads:[~2016-11-12  8:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-05 10:50 [Qemu-devel] virtIO question zhunxun
2016-11-05 14:46 ` jitendra kumar khasdev
2016-11-05 15:04   ` Peter Maydell
2016-11-05 15:11     ` jitendra kumar khasdev
2016-11-09 10:58       ` zhunxun
2016-11-10 10:32         ` Stefan Hajnoczi
2016-11-10 12:16           ` zhunxun
2016-11-11 12:03             ` Stefan Hajnoczi
2016-11-12  8:43               ` zhunxun [this message]
2016-11-14 14:06                 ` Stefan Hajnoczi
2016-11-14  7:14               ` zhunxun
2016-11-05 15:23 jack
2016-11-11 14:17 jack
2016-11-14 12:36 zhunxun
2016-11-14 16:36 ` Stefan Hajnoczi

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=201611121643189598926@gmail.com \
    --to=zhunxun@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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.