From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 632883B5 for ; Wed, 17 Dec 2014 02:05:42 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 16 Dec 2014 17:05:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,590,1413270000"; d="scan'208";a="648834576" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by fmsmga002.fm.intel.com with ESMTP; 16 Dec 2014 17:05:32 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.144]) by IRSMSX103.ger.corp.intel.com ([169.254.3.113]) with mapi id 14.03.0195.001; Wed, 17 Dec 2014 01:05:31 +0000 From: "Ananyev, Konstantin" To: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] Minor fixes in rte_common.h file. Thread-Index: AQHQFmApWiU3vD4qnEqmyF8/gKxH9pyNVVuAgAUdrICAAAhSMIAAMXOAgABNlKCAAAAioA== Date: Wed, 17 Dec 2014 01:05:31 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258213C14CB@IRSMSX105.ger.corp.intel.com> References: <20141213103921.GA1162@localhost.localdomain> <2601191342CEEE43887BDE71AB977258213C1316@IRSMSX105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB977258213C1499@IRSMSX105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB977258213C1499@IRSMSX105.ger.corp.intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] Minor fixes in rte_common.h file. 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, 17 Dec 2014 01:05:43 -0000 >=20 > From: Ravi Kerur [mailto:rkerur@gmail.com] > Sent: Tuesday, December 16, 2014 8:14 PM > To: Ananyev, Konstantin > Cc: Neil Horman; dev@dpdk.org > Subject: Re: [dpdk-dev] [PATCH] Minor fixes in rte_common.h file. >=20 >=20 >=20 > On Tue, Dec 16, 2014 at 9:23 AM, Ananyev, Konstantin wrote: >=20 >=20 > > -----Original Message----- > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ravi Kerur > > Sent: Tuesday, December 16, 2014 4:47 PM > > To: Neil Horman > > Cc: dev@dpdk.org > > Subject: Re: [dpdk-dev] [PATCH] Minor fixes in rte_common.h file. > > > > On Sat, Dec 13, 2014 at 2:39 AM, Neil Horman wr= ote: > > > > > > On Fri, Dec 12, 2014 at 03:04:34PM -0800, r k wrote: > > > > Subject: [PATCH] Minor fixes in rte_common.h file. > > > > > > > > Fix rte_is_power_of_2 since 0 is not. > > > > Avoid branching instructions in RTE_MAX and RTE_MIN. > > > > > > > > Signed-off-by: Ravi Kerur > > > > --- > > > >=A0 lib/librte_eal/common/include/rte_common.h | 6 +++--- > > > >=A0 lib/librte_pmd_e1000/igb_pf.c=A0 =A0 =A0 =A0 =A0 =A0 =A0 | 4 ++-= - > > > >=A0 lib/librte_pmd_ixgbe/ixgbe_pf.c=A0 =A0 =A0 =A0 =A0 =A0 | 4 ++-- > > > >=A0 3 files changed, 7 insertions(+), 7 deletions(-) > > > > > > > > diff --git a/lib/librte_eal/common/include/rte_common.h > > > > b/lib/librte_eal/common/include/rte_common.h > > > > index 921b91f..e163f35 100644 > > > > --- a/lib/librte_eal/common/include/rte_common.h > > > > +++ b/lib/librte_eal/common/include/rte_common.h > > > > @@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error;=A0 = static > > > > inline int=A0 rte_is_power_of_2(uint32_t n)=A0 { > > > > -=A0 =A0 =A0 =A0return ((n-1) & n) =3D=3D 0; > > > > +=A0 =A0 =A0 =A0return n && !(n & (n - 1)); > > > >=A0 } > > > > > > > >=A0 /** > > > > @@ -259,7 +259,7 @@ rte_align64pow2(uint64_t v)=A0 #define RTE_MIN(= a, b) > > > ({ \ > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0typeof (a) _a =3D (a); \ > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0typeof (b) _b =3D (b); \ > > > > -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_a < _b ? _a : _b; \ > > > > +=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _b ^ ((_a ^ _b) & -(_a < _b)); \ > > > Are you sure this is actually faster than the branch version?=A0 What= about > > > using > > > a cmov instead? > > > > > > > > i am pretty sure modified code is faster than branching. I remembe= r > > cmov had performance issues esp. on Pentuim-4 not sure how new intel cp= u's > > perform. > I also think most modern compilers are smart enough to avoid any branchin= g here and will use cmov instead. > And we are way ahead of Pentium 4 times these days. > Konstantin >=20 > Konstantin, =A0Can you please elaborate, is it something done automat= ically with Intel's icc compiler? My understanding is branch > prediction can be influenced only by using compiler builtin i.e. __builti= n_expect() , without this compiler will generate regular > instructions(cmp/jump instructions). I wrote small program and compiled w= ith gcc -02/-03, don't see cmov instruction. I am saying that there is probably no need to modify these macros. On IA , for constructions like: "_a < _b ? _a : _b;" modern compilers in many cases will avoid any branches and emit cmov instea= d. $ cat tcmv1.c #include #include #define RTE_MIN(a, b) ({ \ typeof (a) _a =3D (a); \ typeof (b) _b =3D (b); \ _a < _b ? _a : _b; \ }) int fxmini32(int a, int b) { return RTE_MIN(a, b); } int fxminu64(uint64_t a, uint64_t b) { return RTE_MIN(a, b); } $gcc -O3 -m64 -S tcmv1.c $ cat tcmv1.s .file "tcmv1.c" .text .p2align 4,,15 .globl fxmini32 .type fxmini32, @function fxmini32: .LFB0: .cfi_startproc cmpl %esi, %edi movl %esi, %eax cmovle %edi, %eax ret .cfi_endproc .LFE0: .size fxmini32, .-fxmini32 .p2align 4,,15 .globl fxminu64 .type fxminu64, @function fxminu64: .LFB1: .cfi_startproc cmpq %rsi, %rdi movq %rsi, %rax cmovbe %rdi, %rax ret .cfi_endproc gcc version 4.8.3 clang produces similar code. Konstantin >=20 > > > > >=A0 =A0 =A0 =A0 =A0}) > > > > > > > >=A0 /** > > > > @@ -268,7 +268,7 @@ rte_align64pow2(uint64_t v)=A0 #define RTE_MAX(= a, b) > > > ({ \ > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0typeof (a) _a =3D (a); \ > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0typeof (b) _b =3D (b); \ > > > > -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_a > _b ? _a : _b; \ > > > > +=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_a ^ ((_a ^ _b) & -(_a < _b)); \ > > > Same as above > > > > > > Same as above. > > > > > >=A0 =A0 =A0 =A0 =A0}) > > > > > > > >=A0 /*********** Other general functions / macros ********/ diff --g= it > > > > a/lib/librte_pmd_e1000/igb_pf.c b/lib/librte_pmd_e1000/igb_pf.c ind= ex > > > > bc3816a..546499c 100644 > > > > --- a/lib/librte_pmd_e1000/igb_pf.c > > > > +++ b/lib/librte_pmd_e1000/igb_pf.c > > > > @@ -321,11 +321,11 @@ igb_vf_set_mac_addr(struct rte_eth_dev *dev, > > > uint32_t > > > > vf, uint32_t *msgbuf)=A0 static int=A0 igb_vf_set_multicast(struct > > > rte_eth_dev > > > > *dev, __rte_unused uint32_t vf, uint32_t *msgbuf)=A0 { > > > > -=A0 =A0 =A0 =A0int i; > > > > +=A0 =A0 =A0 =A0int16_t i; > > > >=A0 =A0 =A0 =A0 =A0uint32_t vector_bit; > > > >=A0 =A0 =A0 =A0 =A0uint32_t vector_reg; > > > >=A0 =A0 =A0 =A0 =A0uint32_t mta_reg; > > > > -=A0 =A0 =A0 =A0int entries =3D (msgbuf[0] & E1000_VT_MSGINFO_MASK)= >> > > > > +=A0 =A0 =A0 =A0int32_t entries =3D (msgbuf[0] & E1000_VT_MSGINFO_M= ASK) >> > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0E1000_VT_MSGINFO_SHIFT; > > > NAK, this has nothing to do with the included changelog > > > > > > > It does, it causes compilation errors such as > > > > /root/dpdk-new/dpdk/lib/librte_pmd_e1000/igb_pf.c: In function > > \u2018igb_pf_mbx_process\u2019: > > /root/dpdk-new/dpdk/lib/librte_pmd_e1000/igb_pf.c:350:23: error: array > > subscript is above array bounds [-Werror=3Darray-bounds] > >=A0 =A0 vfinfo->vf_mc_hashes[i] =3D hash_list[i]; > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^ > > cc1: all warnings being treated as errors > > > > Also it is always better to use explicit int definitions esp. for 64bit > > systems. > > > > > > > > > > > > >=A0 =A0 =A0 =A0 =A0uint16_t *hash_list =3D (uint16_t *)&msgbuf[1]; > > > >=A0 =A0 =A0 =A0 =A0struct e1000_hw *hw =3D > > > > E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private); > > > > diff --git a/lib/librte_pmd_ixgbe/ixgbe_pf.c > > > > b/lib/librte_pmd_ixgbe/ixgbe_pf.c index 51da1fd..426caf9 100644 > > > > --- a/lib/librte_pmd_ixgbe/ixgbe_pf.c > > > > +++ b/lib/librte_pmd_ixgbe/ixgbe_pf.c > > > > @@ -390,7 +390,7 @@ ixgbe_vf_set_multicast(struct rte_eth_dev *dev, > > > > __rte_unused uint32_t vf, uint32 > > > >=A0 =A0 =A0 =A0 =A0struct ixgbe_hw *hw =3D > > > > IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private); > > > >=A0 =A0 =A0 =A0 =A0struct ixgbe_vf_info *vfinfo =3D > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*(IXGBE_DEV_PRIVATE_TO_P_VFDATA(d= ev->data->dev_private)); > > > > -=A0 =A0 =A0 =A0int nb_entries =3D (msgbuf[0] & IXGBE_VT_MSGINFO_MA= SK) >> > > > > +=A0 =A0 =A0 =A0int32_t nb_entries =3D (msgbuf[0] & IXGBE_VT_MSGINF= O_MASK) >> > > > >=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0IXGBE_VT_MSGINFO_SHIFT; > > > ditto > > > >=A0 =A0 =A0 =A0 =A0uint16_t *hash_list =3D (uint16_t *)&msgbuf[1]; > > > >=A0 =A0 =A0 =A0 =A0uint32_t mta_idx; > > > > @@ -399,7 +399,7 @@ ixgbe_vf_set_multicast(struct rte_eth_dev *dev, > > > > __rte_unused uint32_t vf, uint32 > > > >=A0 =A0 =A0 =A0 =A0const uint32_t IXGBE_MTA_BIT_SHIFT =3D 5; > > > >=A0 =A0 =A0 =A0 =A0const uint32_t IXGBE_MTA_BIT_MASK =3D (0x1 << IXG= BE_MTA_BIT_SHIFT) > > > - > > > > 1; > > > >=A0 =A0 =A0 =A0 =A0uint32_t reg_val; > > > > -=A0 =A0 =A0 =A0int i; > > > > +=A0 =A0 =A0 =A0int16_t i; > > > ditto > > > > > > Same as above. > > > > > > > > > >=A0 =A0 =A0 =A0 =A0/* only so many hash values supported */ > > > >=A0 =A0 =A0 =A0 =A0nb_entries =3D RTE_MIN(nb_entries, IXGBE_MAX_VF_M= C_ENTRIES); > > > > -- > > > > 1.9.1 > > > > > > >