From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5AYk-0001Hx-IW for qemu-devel@nongnu.org; Fri, 11 Nov 2016 07:03:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5AYh-0005TF-B9 for qemu-devel@nongnu.org; Fri, 11 Nov 2016 07:03:54 -0500 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:35159) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c5AYh-0005Sl-4f for qemu-devel@nongnu.org; Fri, 11 Nov 2016 07:03:51 -0500 Received: by mail-wm0-x22b.google.com with SMTP id a197so421735229wmd.0 for ; Fri, 11 Nov 2016 04:03:50 -0800 (PST) Date: Fri, 11 Nov 2016 12:03:47 +0000 From: Stefan Hajnoczi Message-ID: <20161111120347.GB8930@stefanha-x1.localdomain> References: <201611051850530152761@gmail.com> <201611091858142738325@gmail.com> <20161110103253.GC17332@stefanha-x1.localdomain> <2016111020163477037720@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="NDin8bjvE/0mNLFQ" Content-Disposition: inline In-Reply-To: <2016111020163477037720@gmail.com> Subject: Re: [Qemu-devel] virtIO question List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "zhunxun@gmail.com" Cc: qemu --NDin8bjvE/0mNLFQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 alw= ays 0 or 1=E3=80=82 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 VRingUse= d.ring[vring.num] to the lastest VRingAvail.idx, this according the arithme= tic ((new_idx-event_idx)<(new_idx-old_idx)),it seems that this mechanism do= es 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 =E2=80=9Cused_event=E2=80=9D field is written i= n 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=EF=AC=81cations until an ent= ry with an index specified by the =E2=80=9Cavail_event=E2=80=9D field is wri= tten 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. --NDin8bjvE/0mNLFQ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJYJbOjAAoJEJykq7OBq3PIt/cH/iMYhT4S7cFFu0zIIklrHF7f gAXHtLP4c0NaL8TcFYFe+7zY5Jt8+KmQh8atkjQnIaIqowKDVCRF2DUA6KGUQ/rq mMvS5x45VRK7xxtMv5EsOcvJzom9kz+HrBTyJQCe/owAuHClnvQUCvbymKkBVW3x 1Ih6F/Yq27jT8TFimxf05rWKoHrAxC3ZsAg3mRY+fi3rCZ9AT5JC3c9lxB39FZDd aojoAkpQiNHn6maDxO4lYKE2MxSYMCiw4mEhkmGQyHOQf3VQHWHkxnkTAf6GyUQ4 Lx1WKZ2itfPL6uhUTho8gwfzgSG9gUQlSmGADpHWy1wLOnzFL8HucErKvvnuJXE= =Fkb9 -----END PGP SIGNATURE----- --NDin8bjvE/0mNLFQ--