From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 1BEBA5A87 for ; Wed, 23 Dec 2015 19:49:25 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 23 Dec 2015 10:49:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,470,1444719600"; d="scan'208";a="622884630" Received: from irsmsx154.ger.corp.intel.com ([163.33.192.96]) by FMSMGA003.fm.intel.com with ESMTP; 23 Dec 2015 10:49:25 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.203]) by IRSMSX154.ger.corp.intel.com ([169.254.12.98]) with mapi id 14.03.0248.002; Wed, 23 Dec 2015 18:49:23 +0000 From: "Ananyev, Konstantin" To: Stephen Hemminger , "Xie, Huawei" Thread-Topic: [dpdk-dev] [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_bulk API Thread-Index: AQHRPbEKKcXwq+/bFkaX04Rkm1mqo57Y6B/Q Date: Wed, 23 Dec 2015 18:49:22 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725836AD8261@irsmsx105.ger.corp.intel.com> References: <1450055682-51953-1-git-send-email-huawei.xie@intel.com> <1450801074-29361-1-git-send-email-huawei.xie@intel.com> <1450801074-29361-2-git-send-email-huawei.xie@intel.com> <20151223103744.28551da7@xeon-e3> In-Reply-To: <20151223103744.28551da7@xeon-e3> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" , "dprovan@bivio.net" Subject: Re: [dpdk-dev] [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_bulk API 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, 23 Dec 2015 18:49:26 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen Hemminger > Sent: Wednesday, December 23, 2015 6:38 PM > To: Xie, Huawei > Cc: dev@dpdk.org; dprovan@bivio.net > Subject: Re: [dpdk-dev] [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_bu= lk API >=20 > On Wed, 23 Dec 2015 00:17:53 +0800 > Huawei Xie wrote: >=20 > > + > > + rc =3D rte_mempool_get_bulk(pool, (void **)mbufs, count); > > + if (unlikely(rc)) > > + return rc; > > + > > + switch (count % 4) { > > + case 0: while (idx !=3D count) { > > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0); > > + rte_mbuf_refcnt_set(mbufs[idx], 1); > > + rte_pktmbuf_reset(mbufs[idx]); > > + idx++; > > + case 3: > > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0); > > + rte_mbuf_refcnt_set(mbufs[idx], 1); > > + rte_pktmbuf_reset(mbufs[idx]); > > + idx++; > > + case 2: > > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0); > > + rte_mbuf_refcnt_set(mbufs[idx], 1); > > + rte_pktmbuf_reset(mbufs[idx]); > > + idx++; > > + case 1: > > + RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0); > > + rte_mbuf_refcnt_set(mbufs[idx], 1); > > + rte_pktmbuf_reset(mbufs[idx]); > > + idx++; > > + } > > + } > > + return 0; > > +} >=20 > Since function will not work if count can not be 0 (otherwise rte_mempool= _get_bulk will fail), As I understand, rte_mempool_get_bulk() will work correctly and return 0, i= f count=3D=3D0. That's why Huawei prefers while() {}, instead of do {} while() - to avoid e= xtra check for (count !=3D 0) at the start.=20 Konstantin > why not: > 1. Document that assumption > 2. Use that assumption to speed up code. >=20 >=20 >=20 > switch(count % 4) { > do { > case 0: > ... > case 1: > ... > } while (idx !=3D count); > } >=20 > Also you really need to add a big block comment about this loop, to expla= in > what it does and why.