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 BD6E32BAD for ; Thu, 3 Mar 2016 17:30:46 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 03 Mar 2016 08:30:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,532,1449561600"; d="scan'208";a="59227560" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga004.fm.intel.com with ESMTP; 03 Mar 2016 08:30:45 -0800 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 3 Mar 2016 08:30:45 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 3 Mar 2016 08:30:45 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.136]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.18]) with mapi id 14.03.0248.002; Fri, 4 Mar 2016 00:30:43 +0800 From: "Xie, Huawei" To: Yuanhan Liu , "dev@dpdk.org" Thread-Topic: [PATCH v2 1/7] vhost: refactor rte_vhost_dequeue_burst Thread-Index: AdF1agd9clXhimYJTx2/yKoyh8rOiw== Date: Thu, 3 Mar 2016 16:30:42 +0000 Message-ID: References: <1449122773-25510-1-git-send-email-yuanhan.liu@linux.intel.com> <1455803352-5518-1-git-send-email-yuanhan.liu@linux.intel.com> <1455803352-5518-2-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 Cc: Victor Kaplansky , "Michael S. Tsirkin" Subject: Re: [dpdk-dev] [PATCH v2 1/7] vhost: refactor rte_vhost_dequeue_burst 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: Thu, 03 Mar 2016 16:30:47 -0000 On 2/18/2016 9:48 PM, Yuanhan Liu wrote:=0A= > + mbuf_avail =3D 0;=0A= > + mbuf_offset =3D 0;=0A= > + while (desc_avail || (desc->flags & VRING_DESC_F_NEXT) !=3D 0) {=0A= > + /* This desc reachs to its end, get the next one */=0A= > + if (desc_avail =3D=3D 0) {=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= > +=0A= > + PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);=0A= > + }=0A= > +=0A= > + /*=0A= > + * This mbuf reachs to its end, get a new one=0A= > + * to hold more data.=0A= > + */=0A= > + if (mbuf_avail =3D=3D 0) {=0A= > + cur =3D rte_pktmbuf_alloc(mbuf_pool);=0A= > + if (unlikely(!cur)) {=0A= > + RTE_LOG(ERR, VHOST_DATA, "Failed to "=0A= > + "allocate memory for mbuf.\n");=0A= > + if (head)=0A= > + rte_pktmbuf_free(head);=0A= > + return NULL;=0A= > + }=0A= =0A= We could always allocate the head mbuf before the loop, then we save the=0A= following branch and make the code more streamlined.=0A= It reminds me that this change prevents the possibility of mbuf bulk=0A= allocation, one solution is we pass the head mbuf from an additional=0A= parameter.=0A= Btw, put unlikely before the check of mbuf_avail and checks elsewhere.=0A= =0A= > + if (!head) {=0A= > + head =3D cur;=0A= > + } else {=0A= > + prev->next =3D cur;=0A= > + prev->data_len =3D mbuf_offset;=0A= > + head->nb_segs +=3D 1;=0A= > + }=0A= > + head->pkt_len +=3D mbuf_offset;=0A= > + prev =3D cur;=0A= > +=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= =0A=