From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5Cie-0002M5-FL for qemu-devel@nongnu.org; Fri, 11 Nov 2016 09:22:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5CiZ-0000K9-Ca for qemu-devel@nongnu.org; Fri, 11 Nov 2016 09:22:16 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36496) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c5CiZ-0000Io-1l for qemu-devel@nongnu.org; Fri, 11 Nov 2016 09:22:11 -0500 Received: by mail-pg0-x244.google.com with SMTP id x23so2026319pgx.3 for ; Fri, 11 Nov 2016 06:22:09 -0800 (PST) Date: Fri, 11 Nov 2016 22:17:02 +0800 Message-ID: From: jack MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="--_com.android.email_3671971354762760" Subject: Re: [Qemu-devel] virtIO question List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu ----_com.android.email_3671971354762760 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" thanks,but i really do not found when the driver will add mutiple buffers then call kick function,this is the key problem . æ�¥è‡ª é…æ—� MX5 -------- 原始邮件 -------- å�‘件人:Stefan Hajnoczi 时间:周五 11月11æ—¥ 20:03 收件人:zhunxun@gmail.com 抄é€�:qemu 主题: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 notiï¬�cations 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. ----_com.android.email_3671971354762760 Content-Type: application/octet-stream; name="signature.asc" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc"; size=465 Cgrop6PnoIHpgq7ku7bml7blh7rplJk= ----_com.android.email_3671971354762760--