From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 6029F47D0 for ; Wed, 1 Jun 2016 08:24:22 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP; 31 May 2016 23:24:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,399,1459839600"; d="scan'208";a="978452338" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga001.fm.intel.com with ESMTP; 31 May 2016 23:24:21 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 31 May 2016 23:24:21 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 31 May 2016 23:24:20 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.150]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.107]) with mapi id 14.03.0248.002; Wed, 1 Jun 2016 14:24:18 +0800 From: "Xie, Huawei" To: Yuanhan Liu , "dev@dpdk.org" Thread-Topic: [PATCH 2/3] vhost: optimize dequeue for small packets Thread-Index: AdG7zjn+DVRyUoDVRFOTVpGyu8m8xQ== Date: Wed, 1 Jun 2016 06:24:18 +0000 Message-ID: References: <1462236378-7604-1-git-send-email-yuanhan.liu@linux.intel.com> <1462236378-7604-3-git-send-email-yuanhan.liu@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 2/3] vhost: optimize dequeue for small packets X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2016 06:24:22 -0000 On 5/3/2016 8:42 AM, Yuanhan Liu wrote:=0A= > Both current kernel virtio driver and DPDK virtio driver use at least=0A= > 2 desc buffer for Tx: the first for storing the header, and the others=0A= > for storing the data.=0A= =0A= Tx could prepend some space for virtio net header whenever possible, so=0A= that it could use only one descriptor.=0A= =0A= Another thing is this doesn't reduce the check because you also add a check= .=0A= =0A= =0A= >=0A= > Therefore, we could fetch the first data desc buf before the main loop,= =0A= > and do the copy first before the check of "are we done yet?". This=0A= > could save one check for small packets, that just have one data desc=0A= > buffer and need one mbuf to store it.=0A= >=0A= > Signed-off-by: Yuanhan Liu =0A= > ---=0A= > lib/librte_vhost/vhost_rxtx.c | 52 ++++++++++++++++++++++++++++++-------= ------=0A= > 1 file changed, 36 insertions(+), 16 deletions(-)=0A= >=0A= > diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.= c=0A= > index 2c3b810..34d6ed1 100644=0A= > --- a/lib/librte_vhost/vhost_rxtx.c=0A= > +++ b/lib/librte_vhost/vhost_rxtx.c=0A= > @@ -753,18 +753,48 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vh= ost_virtqueue *vq,=0A= > return -1;=0A= > =0A= > desc_addr =3D gpa_to_vva(dev, desc->addr);=0A= > - rte_prefetch0((void *)(uintptr_t)desc_addr);=0A= > -=0A= > - /* Retrieve virtio net header */=0A= > hdr =3D (struct virtio_net_hdr *)((uintptr_t)desc_addr);=0A= > - desc_avail =3D desc->len - dev->vhost_hlen;=0A= > - desc_offset =3D dev->vhost_hlen;=0A= > + rte_prefetch0(hdr);=0A= > +=0A= > + /*=0A= > + * Both current kernel virio driver and DPDK virtio driver=0A= > + * use at least 2 desc bufferr for Tx: the first for storing=0A= > + * the header, and others for storing the data.=0A= > + */=0A= > + if (likely(desc->len =3D=3D dev->vhost_hlen)) {=0A= > + desc =3D &vq->desc[desc->next];=0A= > +=0A= > + desc_addr =3D gpa_to_vva(dev, desc->addr);=0A= > + rte_prefetch0((void *)(uintptr_t)desc_addr);=0A= > +=0A= > + desc_offset =3D 0;=0A= > + desc_avail =3D desc->len;=0A= > + nr_desc +=3D 1;=0A= > +=0A= > + PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);=0A= > + } else {=0A= > + desc_avail =3D desc->len - dev->vhost_hlen;=0A= > + desc_offset =3D dev->vhost_hlen;=0A= > + }=0A= > =0A= > mbuf_offset =3D 0;=0A= > mbuf_avail =3D m->buf_len - RTE_PKTMBUF_HEADROOM;=0A= > - while (desc_avail !=3D 0 || (desc->flags & VRING_DESC_F_NEXT) !=3D 0) {= =0A= > + while (1) {=0A= > + cpy_len =3D RTE_MIN(desc_avail, mbuf_avail);=0A= > + rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *, mbuf_offset),=0A= > + (void *)((uintptr_t)(desc_addr + desc_offset)),=0A= > + cpy_len);=0A= > +=0A= > + mbuf_avail -=3D cpy_len;=0A= > + mbuf_offset +=3D cpy_len;=0A= > + desc_avail -=3D cpy_len;=0A= > + desc_offset +=3D cpy_len;=0A= > +=0A= > /* This desc reaches to its end, get the next one */=0A= > if (desc_avail =3D=3D 0) {=0A= > + if ((desc->flags & VRING_DESC_F_NEXT) =3D=3D 0)=0A= > + break;=0A= > +=0A= > if (unlikely(desc->next >=3D vq->size ||=0A= > ++nr_desc >=3D vq->size))=0A= > return -1;=0A= > @@ -800,16 +830,6 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vho= st_virtqueue *vq,=0A= > mbuf_offset =3D 0;=0A= > mbuf_avail =3D cur->buf_len - RTE_PKTMBUF_HEADROOM;=0A= > }=0A= > -=0A= > - cpy_len =3D RTE_MIN(desc_avail, mbuf_avail);=0A= > - rte_memcpy(rte_pktmbuf_mtod_offset(cur, void *, mbuf_offset),=0A= > - (void *)((uintptr_t)(desc_addr + desc_offset)),=0A= > - cpy_len);=0A= > -=0A= > - mbuf_avail -=3D cpy_len;=0A= > - mbuf_offset +=3D cpy_len;=0A= > - desc_avail -=3D cpy_len;=0A= > - desc_offset +=3D cpy_len;=0A= > }=0A= > =0A= > prev->data_len =3D mbuf_offset;=0A= =0A=