From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0066.outbound.protection.outlook.com [104.47.42.66]) by dpdk.org (Postfix) with ESMTP id 46FC1100F for ; Wed, 6 Sep 2017 16:42:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=mMrH9rIwcSJ0MKHjc8c3YjUbFX/yotd/syTB1uHsBF8=; b=YiRu6Dw4yNSzV/mXgSQswVwFnXEVIWvJva4IVHb0BLMgmjFc3K4rJ1XZTNlND5D9ZaRIHpg3yK+Md0rgpXgyAUx8KMizyLIS4SOVYV0cmyQYv8MixVaeYj/8x4XpD3Ov3W6qMrQo1D6wF/dXaarZZ4qA2068Sev8J88Lr8Nd5Go= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from PBHAGAVATULA-LT (111.93.218.67) by DM5PR07MB3467.namprd07.prod.outlook.com (10.164.153.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Wed, 6 Sep 2017 14:41:57 +0000 Date: Wed, 6 Sep 2017 20:11:34 +0530 From: Pavan Nikhilesh Bhagavatula To: Kevin Traynor , stephen@networkplumber.org, cristian.dumitrescu@intel.com Cc: dev@dpdk.org Message-ID: <20170906144133.GA21468@PBHAGAVATULA-LT> References: <1504693294-2100-1-git-send-email-pbhagavatula@caviumnetworks.com> <1504693294-2100-2-git-send-email-pbhagavatula@caviumnetworks.com> <11668986-444f-4238-147f-4baa82d15285@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <11668986-444f-4238-147f-4baa82d15285@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: PN1PR01CA0109.INDPRD01.PROD.OUTLOOK.COM (10.174.144.25) To DM5PR07MB3467.namprd07.prod.outlook.com (10.164.153.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60d83a9b-9666-466c-02a7-08d4f5356e2e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM5PR07MB3467; X-Microsoft-Exchange-Diagnostics: 1; DM5PR07MB3467; 3:EkpyB1sXTfWHnovHDyer6Ug9HaimtXCB78TwFe96+fhC40GxEFbKJ+nQ0jYHJGpnRfgJ40fsxgQn5+UMQ3uTp3o/jQ9atDOpKHytgBXGLtei1d4lxE3RHUzSQ1wu6TdMdTti80D5evKyhNb5eQIis+V95h/+yUCQfehj7tEOjVrXrezlbREvf/qkxzaZBrlcRwFPhdHrP3kwvFey7gXBjP+sGfy0HBEE1H7xSmv2+oyvLCkY1dm9Mr8wqJosXukE; 25:Sv1V9dwX+PxgmiPn6NtVbtGNMt7WviREB4uXvkefuBXQB5iLiE+zEBF0QLvwZy7eIFj7E66LZRnvyRI/eMsYu0Vu1h1JymExRQmLKRRYo363gq9qfnxlOFIvBBEnJi57nsaOCdm2k/n9368JJBOMmHGjyuFYLzAg5nX5XmGQpBEXluPLfuh4Sw8mjrLMQLStU8py/rmitxJTebFW4PafpqoM9nsAHXBWSFsakPLf2nex3bHn35Er2IOYh2C0cfuZQ9FXrDkbf2PB6q5h77Dq6qPAsYM1mWm4T7CG8DUSg47qhv/w/Oj8vteBRWKFjYyoQNqSP0Sl/HgdTsDnYOB5tg==; 31:s/yfdM4wDK02d0w1VXdwad1Dk67fIS1PCRcTZVFAldFoGPiZhRbdLoVr+1fadbs9ySpLoF4/VX1QAfJq9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6406AbioD4heV6fsNi2ntzUZ+8XbK0e03jKl54V4joXe6yo+TERK75RAkgUVIIVEfZnXfC4rY85BVyWe2c= X-Exchange-Antispam-Report-Test: UriScan:(278428928389397); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(20161123564025)(20161123560025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR07MB3467; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR07MB3467; X-Forefront-PRVS: 0422860ED4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(24454002)(199003)(189002)(377454003)(53936002)(6496005)(4001350100001)(72206003)(50466002)(106356001)(478600001)(4326008)(105586002)(55016002)(6306002)(189998001)(42186005)(25786009)(83506001)(53376002)(68736007)(110136004)(9686003)(6246003)(1076002)(33656002)(101416001)(8936002)(66066001)(81156014)(81166006)(8676002)(54356999)(5009440100003)(33716001)(76176999)(229853002)(7736002)(2906002)(53546010)(23726003)(50986999)(3846002)(2950100002)(6666003)(97736004)(42882006)(305945005)(6116002)(966005)(47776003)(5660300001)(18370500001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR07MB3467; H:PBHAGAVATULA-LT; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR07MB3467; 23:80vD0oGt7bXy2igPJj016szGz67N/jDInnpixoPjN?= =?us-ascii?Q?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3GxD9hWSJG0O5vXlnlyLN8LO6EposyTC/wTHBrRIIkYaUd0e894TA2QoCtlMjRGvR+8h6mjqHE=; 7:JpjJ/wUJFwuF7WYHEIrchTtGLsJeUvzgtnR2khtv8e1lOvpEdS7OPQiB9LowRP1zaGa3mKAwAaqvjjx+aElWb/M6B3qiDkkBefNSXMvtBE/qKkXxnpHVHU8SZkdRaDw1ns4kwH/F64fWBb2H1UOj+jYvqbabLKU6nkPTZgS1Cr0WwEWpeeeAU2cJS+R2i/TInnb00sFCZdyMia+U4Qah6BJKIBTIEOVL2vUplyTY6Po= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2017 14:41:57.9944 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR07MB3467 Subject: Re: [dpdk-dev] [PATCH v6 2/3] eal: add u64 bit variant for reciprocal X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Sep 2017 14:42:03 -0000 On Wed, Sep 06, 2017 at 01:28:24PM +0100, Kevin Traynor wrote: > On 09/06/2017 11:21 AM, Pavan Nikhilesh wrote: > > From: Pavan Bhagavatula > > > > Currently, rte_reciprocal only supports unsigned 32bit divisors. This > > commit adds support for unsigned 64bit divisors. > > > > Rename unsigned 32bit specific functions appropriately and update > > librte_sched accordingly. > > > > Signed-off-by: Pavan Nikhilesh > > --- > > lib/librte_eal/bsdapp/eal/rte_eal_version.map | 3 +- > > lib/librte_eal/common/include/rte_reciprocal.h | 109 ++++++++++++++++++++-- > > lib/librte_eal/common/rte_reciprocal.c | 116 +++++++++++++++++++++--- > > lib/librte_eal/linuxapp/eal/rte_eal_version.map | 3 +- > > lib/librte_sched/Makefile | 4 +- > > lib/librte_sched/rte_sched.c | 9 +- > > 6 files changed, 219 insertions(+), 25 deletions(-) > > > > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > > index 90d7258..59a85bb 100644 > > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map > > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map > > @@ -241,6 +241,7 @@ EXPERIMENTAL { > > DPDK_17.11 { > > global: > > > > - rte_reciprocal_value; > > + rte_reciprocal_value_u32; > > + rte_reciprocal_value_u64; > > > > } DPDK_17.08; > > diff --git a/lib/librte_eal/common/include/rte_reciprocal.h b/lib/librte_eal/common/include/rte_reciprocal.h > > index b6d752f..85599e6 100644 > > --- a/lib/librte_eal/common/include/rte_reciprocal.h > > +++ b/lib/librte_eal/common/include/rte_reciprocal.h > > Hi Pavan, sorry for commenting late but the license in v1 of this file > states it cannot be removed. It is not included in later versions - can > you explain why? > Hi Kevin, I have misinterpreted this mail http://dpdk.org/ml/archives/dev/2017-August/073781.html, any suggestion on how to proceed on this further? Thanks, Pavan > +/* > + * libdivide > + * Copyright (C) 2010 ridiculous_fish > + * This software is provided 'as-is', without any express or implied > + * warranty. In no event will the authors be held liable for any damages > + * arising from the use of this software. > + * Permission is granted to anyone to use this software for any purpose, > + * including commercial applications, and to alter it and redistribute it > + * freely, subject to the following restrictions: > + * > + * 1. The origin of this software must not be misrepresented; you must not > + * claim that you wrote the original software. If you use this software > + * in a product, an acknowledgment in the product documentation would be > + * appreciated but is not required. > + * > + * 2. Altered source versions must be plainly marked as such, and must > not be > + * misrepresented as being the original software. > + * > + * 3. This notice may not be removed or altered from any source > distribution. > + * > + * libdivide@ridiculousfish.com > + * > + */ > + > > > > > @@ -22,22 +22,117 @@ > > #ifndef _RTE_RECIPROCAL_H_ > > #define _RTE_RECIPROCAL_H_ > > > > -#include > > +#include > > > > -struct rte_reciprocal { > > +/** > > + * Unsigned 32-bit divisor structure. > > + */ > > +struct rte_reciprocal_u32 { > > uint32_t m; > > uint8_t sh1, sh2; > > }; > > > > +/** > > + * Unsigned 64-bit divisor structure. > > + */ > > +struct rte_reciprocal_u64 { > > + uint64_t m; > > + uint8_t sh1; > > +}; > > + > > +/** > > + * Divide given unsigned 32-bit integer with pre calculated divisor. > > + * > > + * @param a > > + * The 32-bit dividend. > > + * @param R > > + * The pointer to pre calculated divisor reciprocal structure. > > + * > > + * @return > > + * The result of the division > > + */ > > static inline uint32_t > > -rte_reciprocal_divide(uint32_t a, struct rte_reciprocal R) > > +rte_reciprocal_divide_u32(uint32_t a, struct rte_reciprocal_u32 *R) > > { > > - uint32_t t = (uint32_t)(((uint64_t)a * R.m) >> 32); > > + uint32_t t = (((uint64_t)a * R->m) >> 32); > > > > - return (t + ((a - t) >> R.sh1)) >> R.sh2; > > + return (t + ((a - t) >> R->sh1)) >> R->sh2; > > } > > > > -struct rte_reciprocal > > -rte_reciprocal_value(uint32_t d); > > +static inline uint64_t > > +mullhi_u64(uint64_t x, uint64_t y) > > +{ > > +#ifdef __SIZEOF_INT128__ > > + __uint128_t xl = x; > > + __uint128_t rl = xl * y; > > + > > + return (rl >> 64); > > +#else > > + uint64_t u0, u1, v0, v1, k, t; > > + uint64_t w1, w2; > > + uint64_t whi; > > + > > + u1 = x >> 32; u0 = x & 0xFFFFFFFF; > > + v1 = y >> 32; v0 = y & 0xFFFFFFFF; > > + > > + t = u0*v0; > > + k = t >> 32; > > + > > + t = u1*v0 + k; > > + w1 = t & 0xFFFFFFFF; > > + w2 = t >> 32; > > + > > + t = u0*v1 + w1; > > + k = t >> 32; > > + > > + whi = u1*v1 + w2 + k; > > + > > + return whi; > > +#endif > > +} > > + > > +/** > > + * Divide given unsigned 64-bit integer with pre calculated divisor. > > + * > > + * @param a > > + * The 64-bit dividend. > > + * @param R > > + * The pointer to pre calculated divisor reciprocal structure. > > + * > > + * @return > > + * The result of the division > > + */ > > +static inline uint64_t > > +rte_reciprocal_divide_u64(uint64_t a, struct rte_reciprocal_u64 *R) > > +{ > > + uint64_t q = mullhi_u64(R->m, a); > > + uint64_t t = ((a - q) >> 1) + q; > > + > > + return t >> R->sh1; > > +} > > + > > +/** > > + * Generate pre calculated divisor structure. > > + * > > + * @param d > > + * The unsigned 32-bit divisor. > > + * > > + * @return > > + * Divisor structure. > > + */ > > +struct rte_reciprocal_u32 > > +rte_reciprocal_value_u32(uint32_t d); > > + > > +/** > > + * Generate pre calculated divisor structure. > > + * > > + * @param d > > + * The unsigned 64-bit divisor. > > + * > > + * @return > > + * Divisor structure. > > + */ > > +struct rte_reciprocal_u64 > > +rte_reciprocal_value_u64(uint64_t d); > > > > #endif /* _RTE_RECIPROCAL_H_ */ > > diff --git a/lib/librte_eal/common/rte_reciprocal.c b/lib/librte_eal/common/rte_reciprocal.c > > index 7ab99b4..2024e62 100644 > > --- a/lib/librte_eal/common/rte_reciprocal.c > > +++ b/lib/librte_eal/common/rte_reciprocal.c > > @@ -31,18 +31,13 @@ > > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > */ > > > > -#include > > -#include > > - > > -#include > > - > > -#include "rte_reciprocal.h" > > +#include > > > > /* find largest set bit. > > * portable and slow but does not matter for this usage. > > */ > > static inline int > > -fls(uint32_t x) > > +fls_u32(uint32_t x) > > { > > int b; > > > > @@ -54,14 +49,14 @@ fls(uint32_t x) > > return 0; > > } > > > > -struct rte_reciprocal > > -rte_reciprocal_value(uint32_t d) > > +struct rte_reciprocal_u32 > > +rte_reciprocal_value_u32(uint32_t d) > > { > > - struct rte_reciprocal R; > > + struct rte_reciprocal_u32 R; > > uint64_t m; > > int l; > > > > - l = fls(d - 1); > > + l = fls_u32(d - 1); > > m = ((1ULL << 32) * ((1ULL << l) - d)); > > m /= d; > > > > @@ -72,3 +67,102 @@ rte_reciprocal_value(uint32_t d) > > > > return R; > > } > > + > > +/* Code taken from Hacker's Delight: > > + * http://www.hackersdelight.org/HDcode/divlu.c. > > + * License permits inclusion here per: > > + * http://www.hackersdelight.org/permissions.htm > > + */ > > +static inline uint64_t > > +divide_128_div_64_to_64(uint64_t u1, uint64_t u0, uint64_t v, uint64_t *r) > > +{ > > + const uint64_t b = (1ULL << 32); /* Number base (16 bits). */ > > + uint64_t un1, un0, /* Norm. dividend LSD's. */ > > + vn1, vn0, /* Norm. divisor digits. */ > > + q1, q0, /* Quotient digits. */ > > + un64, un21, un10, /* Dividend digit pairs. */ > > + rhat; /* A remainder. */ > > + int s; /* Shift amount for norm. */ > > + > > + /* If overflow, set rem. to an impossible value. */ > > + if (u1 >= v) { > > + if (r != NULL) > > + *r = (uint64_t) -1; > > + return (uint64_t) -1; > > + } > > + > > + /* Count leading zeros. */ > > + s = __builtin_clzll(v); > > + if (s > 0) { > > + v = v << s; > > + un64 = (u1 << s) | ((u0 >> (64 - s)) & (-s >> 31)); > > + un10 = u0 << s; > > + } else { > > + > > + un64 = u1 | u0; > > + un10 = u0; > > + } > > + > > + vn1 = v >> 32; > > + vn0 = v & 0xFFFFFFFF; > > + > > + un1 = un10 >> 32; > > + un0 = un10 & 0xFFFFFFFF; > > + > > + q1 = un64/vn1; > > + rhat = un64 - q1*vn1; > > +again1: > > + if (q1 >= b || q1*vn0 > b*rhat + un1) { > > + q1 = q1 - 1; > > + rhat = rhat + vn1; > > + if (rhat < b) > > + goto again1; > > + } > > + > > + un21 = un64*b + un1 - q1*v; > > + > > + q0 = un21/vn1; > > + rhat = un21 - q0*vn1; > > +again2: > > + if (q0 >= b || q0*vn0 > b*rhat + un0) { > > + q0 = q0 - 1; > > + rhat = rhat + vn1; > > + if (rhat < b) > > + goto again2; > > + } > > + > > + if (r != NULL) > > + *r = (un21*b + un0 - q0*v) >> s; > > + return q1*b + q0; > > +} > > + > > +struct rte_reciprocal_u64 > > +rte_reciprocal_value_u64(uint64_t d) > > +{ > > + struct rte_reciprocal_u64 R; > > + > > + const uint32_t fld = 63 - __builtin_clzll(d); > > + > > + if ((d & (d - 1)) == 0) { > > + R.m = 0; > > + R.sh1 = (fld - 1) | 0x40; > > + } else { > > + uint64_t rem; > > + uint64_t multiplier; > > + uint8_t more; > > + > > + multiplier = divide_128_div_64_to_64(1ULL << fld, 0, d, &rem); > > + multiplier += multiplier; > > + > > + const uint64_t twice_rem = rem + rem; > > + if (twice_rem >= d || twice_rem < rem) > > + multiplier += 1; > > + more = fld; > > + R.m = 1 + multiplier; > > + R.sh1 = more | 0x40; > > + } > > + > > + R.sh1 &= 0x3F; > > + > > + return R; > > +} > > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > > index 2070cba..2671627 100644 > > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map > > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > > @@ -246,6 +246,7 @@ EXPERIMENTAL { > > DPDK_17.11 { > > global: > > > > - rte_reciprocal_value; > > + rte_reciprocal_value_u32; > > + rte_reciprocal_value_u64; > > > > } DPDK_17.08; > > diff --git a/lib/librte_sched/Makefile b/lib/librte_sched/Makefile > > index 569656b..a2fd6f3 100644 > > --- a/lib/librte_sched/Makefile > > +++ b/lib/librte_sched/Makefile > > @@ -54,6 +54,8 @@ LIBABIVER := 1 > > SRCS-$(CONFIG_RTE_LIBRTE_SCHED) += rte_sched.c rte_red.c rte_approx.c > > > > # install includes > > -SYMLINK-$(CONFIG_RTE_LIBRTE_SCHED)-include := rte_sched.h rte_bitmap.h rte_sched_common.h rte_red.h rte_approx.h > > +SYMLINK-$(CONFIG_RTE_LIBRTE_SCHED)-include := rte_sched.h rte_bitmap.h > > +SYMLINK-$(CONFIG_RTE_LIBRTE_SCHED)-include += rte_sched_common.h rte_red.h > > +SYMLINK-$(CONFIG_RTE_LIBRTE_SCHED)-include += rte_approx.h > > > > include $(RTE_SDK)/mk/rte.lib.mk > > diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c > > index 3b8ccaa..7bb6d51 100644 > > --- a/lib/librte_sched/rte_sched.c > > +++ b/lib/librte_sched/rte_sched.c > > @@ -228,7 +228,7 @@ struct rte_sched_port { > > uint64_t time_cpu_cycles; /* Current CPU time measured in CPU cyles */ > > uint64_t time_cpu_bytes; /* Current CPU time measured in bytes */ > > uint64_t time; /* Current NIC TX time measured in bytes */ > > - struct rte_reciprocal inv_cycles_per_byte; /* CPU cycles per byte */ > > + struct rte_reciprocal_u32 inv_cycles_per_byte; /* CPU cycles per byte */ > > > > /* Scheduling loop detection */ > > uint32_t pipe_loop; > > @@ -677,7 +677,7 @@ rte_sched_port_config(struct rte_sched_port_params *params) > > > > cycles_per_byte = (rte_get_tsc_hz() << RTE_SCHED_TIME_SHIFT) > > / params->rate; > > - port->inv_cycles_per_byte = rte_reciprocal_value(cycles_per_byte); > > + port->inv_cycles_per_byte = rte_reciprocal_value_u32(cycles_per_byte); > > > > /* Scheduling loop detection */ > > port->pipe_loop = RTE_SCHED_PIPE_INVALID; > > @@ -2147,8 +2147,9 @@ rte_sched_port_time_resync(struct rte_sched_port *port) > > uint64_t bytes_diff; > > > > /* Compute elapsed time in bytes */ > > - bytes_diff = rte_reciprocal_divide(cycles_diff << RTE_SCHED_TIME_SHIFT, > > - port->inv_cycles_per_byte); > > + bytes_diff = rte_reciprocal_divide_u32( > > + cycles_diff << RTE_SCHED_TIME_SHIFT, > > + &port->inv_cycles_per_byte); > > > > /* Advance port time */ > > port->time_cpu_cycles = cycles; > > >