From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <huawei.xie@intel.com>
Received: from mga01.intel.com (mga01.intel.com [192.55.52.88])
 by dpdk.org (Postfix) with ESMTP id E7FD65A13
 for <dev@dpdk.org>; Thu, 24 Dec 2015 02:33:46 +0100 (CET)
Received: from orsmga003.jf.intel.com ([10.7.209.27])
 by fmsmga101.fm.intel.com with ESMTP; 23 Dec 2015 17:33:45 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.20,471,1444719600"; d="scan'208";a="713839661"
Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205])
 by orsmga003.jf.intel.com with ESMTP; 23 Dec 2015 17:33:45 -0800
Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by
 fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Wed, 23 Dec 2015 17:33:45 -0800
Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by
 fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Wed, 23 Dec 2015 17:33:45 -0800
Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.190]) by
 shsmsx102.ccr.corp.intel.com ([169.254.2.158]) with mapi id 14.03.0248.002;
 Thu, 24 Dec 2015 09:33:43 +0800
From: "Xie, Huawei" <huawei.xie@intel.com>
To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>, Stephen Hemminger
 <stephen@networkplumber.org>
Thread-Topic: [dpdk-dev] [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_bulk
 API
Thread-Index: AdE96x9IC+XUeUndTwaFsXBlWnxwsw==
Date: Thu, 24 Dec 2015 01:33:42 +0000
Message-ID: <C37D651A908B024F974696C65296B57B4C55976D@SHSMSX101.ccr.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>
 <2601191342CEEE43887BDE71AB97725836AD8261@irsmsx105.ger.corp.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: "dev@dpdk.org" <dev@dpdk.org>, "dprovan@bivio.net" <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 <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 24 Dec 2015 01:33:47 -0000

On 12/24/2015 2:49 AM, Ananyev, Konstantin wrote:=0A=
>=0A=
>> -----Original Message-----=0A=
>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen Hemminger=
=0A=
>> Sent: Wednesday, December 23, 2015 6:38 PM=0A=
>> To: Xie, Huawei=0A=
>> Cc: dev@dpdk.org; dprovan@bivio.net=0A=
>> Subject: Re: [dpdk-dev] [PATCH v3 1/2] mbuf: provide rte_pktmbuf_alloc_b=
ulk API=0A=
>>=0A=
>> On Wed, 23 Dec 2015 00:17:53 +0800=0A=
>> Huawei Xie <huawei.xie@intel.com> wrote:=0A=
>>=0A=
>>> +=0A=
>>> +	rc =3D rte_mempool_get_bulk(pool, (void **)mbufs, count);=0A=
>>> +	if (unlikely(rc))=0A=
>>> +		return rc;=0A=
>>> +=0A=
>>> +	switch (count % 4) {=0A=
>>> +	case 0: while (idx !=3D count) {=0A=
>>> +			RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0);=0A=
>>> +			rte_mbuf_refcnt_set(mbufs[idx], 1);=0A=
>>> +			rte_pktmbuf_reset(mbufs[idx]);=0A=
>>> +			idx++;=0A=
>>> +	case 3:=0A=
>>> +			RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0);=0A=
>>> +			rte_mbuf_refcnt_set(mbufs[idx], 1);=0A=
>>> +			rte_pktmbuf_reset(mbufs[idx]);=0A=
>>> +			idx++;=0A=
>>> +	case 2:=0A=
>>> +			RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0);=0A=
>>> +			rte_mbuf_refcnt_set(mbufs[idx], 1);=0A=
>>> +			rte_pktmbuf_reset(mbufs[idx]);=0A=
>>> +			idx++;=0A=
>>> +	case 1:=0A=
>>> +			RTE_MBUF_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) =3D=3D 0);=0A=
>>> +			rte_mbuf_refcnt_set(mbufs[idx], 1);=0A=
>>> +			rte_pktmbuf_reset(mbufs[idx]);=0A=
>>> +			idx++;=0A=
>>> +	}=0A=
>>> +	}=0A=
>>> +	return 0;=0A=
>>> +}=0A=
>> Since function will not work if count can not be 0 (otherwise rte_mempoo=
l_get_bulk will fail),=0A=
> As I understand, rte_mempool_get_bulk() will work correctly and return 0,=
 if count=3D=3D0.=0A=
> That's why Huawei prefers while() {}, instead of do {} while() - to avoid=
 extra check for=0A=
> (count !=3D 0) at the start. =0A=
> Konstantin=0A=
=0A=
Yes.=0A=
=0A=
>=0A=
>=0A=
>> why not:=0A=
>> 	1. Document that assumption=0A=
>> 	2. Use that assumption to speed up code.=0A=
>>=0A=
>>=0A=
>>=0A=
>> 	switch(count % 4) {=0A=
>> 		do {=0A=
>> 			case 0:=0A=
>> 			...=0A=
>> 			case 1:=0A=
>> 			...=0A=
>> 		} while (idx !=3D count);=0A=
>> 	}=0A=
>>=0A=
>> Also you really need to add a big block comment about this loop, to expl=
ain=0A=
>> what it does and why.=0A=
=0A=
Since we change duff's implementation a bit, and for people who don't=0A=
know duff's device, we could add comment.=0A=
Is comment like this enough?=0A=
Use Duff's device to unroll the loop a bit to gain more performance=0A=
Use while() rather than do {} while() as count could be zero.=0A=
=0A=
=0A=