From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id A54467CC0 for ; Mon, 4 Sep 2017 11:18:41 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 04 Sep 2017 02:18:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,474,1498546800"; d="scan'208";a="147229589" Received: from irsmsx108.ger.corp.intel.com ([163.33.3.3]) by fmsmga005.fm.intel.com with ESMTP; 04 Sep 2017 02:18:39 -0700 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.28]) by IRSMSX108.ger.corp.intel.com ([169.254.11.167]) with mapi id 14.03.0319.002; Mon, 4 Sep 2017 10:18:38 +0100 From: "Burakov, Anatoly" To: Pavan Nikhilesh , "dev@dpdk.org" CC: "Dumitrescu, Cristian" , "stephen@networkplumber.org" Thread-Topic: [dpdk-dev] [PATCH v3 3/3] test: add tests for reciprocal based division Thread-Index: AQHTJLF1Pu1TntHSSUG/3pKihtZIxKKkc4lQ Date: Mon, 4 Sep 2017 09:18:37 +0000 Message-ID: References: <1504442189-4384-1-git-send-email-pbhagavatula@caviumnetworks.com> <1504442189-4384-3-git-send-email-pbhagavatula@caviumnetworks.com> In-Reply-To: <1504442189-4384-3-git-send-email-pbhagavatula@caviumnetworks.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYmY4ZmNkZGUtMDkxNS00M2FhLTljZGUtYWZhOTEwYTA1MmM1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IlhPcjZQV3ZsQ0UyY0wwanlCSGp2SDQzUkJWUW1ka1haS21NWHc0Z09rYlU9In0= dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 3/3] test: add tests for reciprocal based division 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: Mon, 04 Sep 2017 09:18:42 -0000 Hi Pavan, > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pavan Nikhilesh > Sent: Sunday, September 3, 2017 1:36 PM > To: dev@dpdk.org > Cc: Dumitrescu, Cristian ; > stephen@networkplumber.org; Pavan Nikhilesh > > Subject: [dpdk-dev] [PATCH v3 3/3] test: add tests for reciprocal based > division >=20 > This commit provides a set of tests for verifying the correctness and > performance of both unsigned 32 and 64bit reciprocal based division. >=20 > Signed-off-by: Pavan Nikhilesh > --- > test/test/Makefile | 2 + > test/test/test_reciprocal_division.c | 109 ++++++++++++++++++ > test/test/test_reciprocal_division_perf.c | 181 > ++++++++++++++++++++++++++++++ > 3 files changed, 292 insertions(+) > create mode 100644 test/test/test_reciprocal_division.c > create mode 100644 test/test/test_reciprocal_division_perf.c >=20 > diff --git a/test/test/Makefile b/test/test/Makefile index 42d9a49..60178= 62 > 100644 > --- a/test/test/Makefile > +++ b/test/test/Makefile > @@ -94,6 +94,8 @@ SRCS-y +=3D test_cycles.c SRCS-y +=3D test_spinlock.c > SRCS-y +=3D test_memory.c SRCS-y +=3D test_memzone.c > +SRCS-y +=3D test_reciprocal_division.c > +SRCS-y +=3D test_reciprocal_division_perf.c >=20 > SRCS-y +=3D test_ring.c > SRCS-y +=3D test_ring_perf.c > diff --git a/test/test/test_reciprocal_division.c > b/test/test/test_reciprocal_division.c > new file mode 100644 > index 0000000..771ea64 > --- /dev/null > +++ b/test/test/test_reciprocal_division.c > @@ -0,0 +1,109 @@ > +/* > + * BSD LICENSE > + * > + * Copyright (C) Cavium, Inc. 2017. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Cavium, Inc nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND > CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT > NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND > FITNESS FOR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE > COPYRIGHT > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, > INCIDENTAL, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT > NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS > OF USE, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED > AND ON ANY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF > THE USE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH > DAMAGE. > + */ > + > +#include "test.h" > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +#define MAX_ITERATIONS 1000000 > +#define DIVIDE_ITER 100 > + > +static int > +test_reciprocal_division(void) > +{ > + int i; > + int result =3D 0; > + uint32_t divisor_u32 =3D 0; > + uint32_t dividend_u32; > + uint32_t nresult_u32; > + uint32_t rresult_u32; > + uint64_t divisor_u64 =3D 0; > + uint64_t dividend_u64; > + uint64_t nresult_u64; > + uint64_t rresult_u64; > + struct rte_reciprocal_u32 reci_u32; > + struct rte_reciprocal_u64 reci_u64; > + > + rte_srand(rte_rdtsc()); > + printf("Validating unsigned 32bit division.\n"); > + for (i =3D 0; i < MAX_ITERATIONS; i++) { > + /* Change divisor every DIVIDE_ITER iterations. */ > + if (i % DIVIDE_ITER =3D=3D 0) { > + divisor_u32 =3D rte_rand(); > + reci_u32 =3D rte_reciprocal_value_u32(divisor_u32); > + } > + > + dividend_u32 =3D rte_rand(); > + nresult_u32 =3D dividend_u32 / divisor_u32; > + rresult_u32 =3D rte_reciprocal_divide_u32(dividend_u32, > + &reci_u32); > + if (nresult_u32 !=3D rresult_u32) { > + printf("Division failed, expected %"PRIu32" " > + "result %"PRIu32"", > + nresult_u32, rresult_u32); > + result =3D 1; > + break; > + } > + } > + > + printf("Validating unsigned 64bit division.\n"); > + for (i =3D 0; i < MAX_ITERATIONS; i++) { > + /* Change divisor every DIVIDE_ITER iterations. */ > + if (i % DIVIDE_ITER =3D=3D 0) { > + divisor_u64 =3D rte_rand(); > + reci_u64 =3D rte_reciprocal_value_u64(divisor_u64); > + } > + > + dividend_u64 =3D rte_rand(); > + nresult_u64 =3D dividend_u64 / divisor_u64; > + rresult_u64 =3D rte_reciprocal_divide_u64(dividend_u64, > + &reci_u64); > + if (nresult_u64 !=3D rresult_u64) { > + printf("Division failed, expected %"PRIu64" " > + "result %"PRIu64"", > + nresult_u64, rresult_u64); > + result =3D 1; > + break; > + } > + } > + > + return result; > +} > + > +REGISTER_TEST_COMMAND(reciprocal_division, test_reciprocal_division); > diff --git a/test/test/test_reciprocal_division_perf.c > b/test/test/test_reciprocal_division_perf.c > new file mode 100644 > index 0000000..31f069d > --- /dev/null > +++ b/test/test/test_reciprocal_division_perf.c > @@ -0,0 +1,181 @@ > +/* > + * BSD LICENSE > + * > + * Copyright (C) Cavium, Inc. 2017. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Cavium, Inc nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND > CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT > NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND > FITNESS FOR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE > COPYRIGHT > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, > INCIDENTAL, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT > NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS > OF USE, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED > AND ON ANY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF > THE USE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH > DAMAGE. > + */ > + > +#include "test.h" > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +#define MAX_ITERATIONS 1000000 > +#define DIVIDE_ITER 100 > + > +static int > +test_reciprocal_division_perf(void) > +{ > + int result =3D 0; > + uint32_t divisor_u32 =3D 0; > + uint32_t dividend_u32; > + uint32_t nresult_u32; > + uint32_t rresult_u32; > + uint64_t divisor_u64 =3D 0; > + uint64_t dividend_u64; > + uint64_t nresult_u64; > + uint64_t rresult_u64; > + uint64_t cur_cyc; > + uint64_t tot_cyc_n =3D 0; > + uint64_t tot_cyc_r =3D 0; > + uint64_t i; > + struct rte_reciprocal_u32 reci_u32 =3D {0}; > + struct rte_reciprocal_u64 reci_u64 =3D {0}; > + > + rte_srand(rte_rdtsc()); > + printf("Validating unsigned 32bit division.\n"); > + for (i =3D 0; i < MAX_ITERATIONS; i++) { > + /* Change divisor every DIVIDE_ITER iterations. */ > + if (i % DIVIDE_ITER =3D=3D 0) { > + divisor_u32 =3D rte_rand(); > + reci_u32 =3D rte_reciprocal_value_u32(divisor_u32); > + } > + > + dividend_u32 =3D rte_rand(); > + cur_cyc =3D rte_rdtsc(); > + nresult_u32 =3D dividend_u32 / divisor_u32; > + tot_cyc_n +=3D rte_rdtsc() - cur_cyc; > + > + cur_cyc =3D rte_rdtsc(); Is there any particular reason for calling rte_rdtsc() twice in a row? Inst= ead of, say, doing something like this: start =3D rdtsc(); // do something split =3D rdtsc(); // do something else end =3D rdtsc(); // figure out which cycle value goes where > + rresult_u32 =3D rte_reciprocal_divide_u32(dividend_u32, > + &reci_u32); > + tot_cyc_r +=3D rte_rdtsc() - cur_cyc; > + if (nresult_u32 !=3D rresult_u32) { > + printf("Division failed, expected %"PRIu32" " > + "result %"PRIu32"", > + nresult_u32, rresult_u32); > + result =3D 1; > + break; > + } > + } > + printf("32bit Division results:\n"); > + printf("Total number of cycles normal division : %"PRIu64"\n", > + tot_cyc_n); > + printf("Total number of cycles reciprocal division : %"PRIu64"\n", > + tot_cyc_r); > + printf("Cycles per division(normal) : %3.2f\n", > + ((double)tot_cyc_n)/i); > + printf("Cycles per division(normal) : %3.2f\n\n", > + ((double)tot_cyc_r)/i); > + > + tot_cyc_n =3D 0; > + tot_cyc_r =3D 0; > + printf("Validating unsigned 64bit division.\n"); > + > + for (i =3D 0; i < MAX_ITERATIONS; i++) { > + /* Change divisor every DIVIDE_ITER iterations. */ > + if (i % DIVIDE_ITER =3D=3D 0) { > + divisor_u64 =3D rte_rand(); > + reci_u64 =3D rte_reciprocal_value_u64(divisor_u64); > + } > + > + dividend_u64 =3D rte_rand(); > + cur_cyc =3D rte_rdtsc(); > + nresult_u64 =3D dividend_u64 / divisor_u64; > + tot_cyc_n +=3D rte_rdtsc() - cur_cyc; > + > + cur_cyc =3D rte_rdtsc(); Same as above > + rresult_u64 =3D rte_reciprocal_divide_u64(dividend_u64, > + &reci_u64); > + tot_cyc_r +=3D rte_rdtsc() - cur_cyc; > + if (nresult_u64 !=3D rresult_u64) { > + printf("Division failed, expected %"PRIu64" " > + "result %"PRIu64"", > + nresult_u64, rresult_u64); > + result =3D 1; > + break; > + } > + } > + printf("64bit Division results:\n"); > + printf("Total number of cycles normal division : %"PRIu64"\n", > + tot_cyc_n); > + printf("Total number of cycles reciprocal division : %"PRIu64"\n", > + tot_cyc_r); > + printf("Cycles per division(normal) : %3.2f\n", > + ((double)tot_cyc_n)/i); > + printf("Cycles per division(normal) : %3.2f\n\n", > + ((double)tot_cyc_r)/i); > + > + printf("Validating unsigned 64bit division with 32bit divisor.\n"); > + for (i =3D 0; i < MAX_ITERATIONS; i++) { > + /* Change divisor every DIVIDE_ITER iterations. */ > + if (i % DIVIDE_ITER =3D=3D 0) { > + divisor_u64 =3D rte_rand() >> 32; > + reci_u64 =3D rte_reciprocal_value_u64(divisor_u64); > + } > + > + dividend_u64 =3D rte_rand(); > + cur_cyc =3D rte_rdtsc(); > + nresult_u64 =3D dividend_u64 / divisor_u64; > + tot_cyc_n +=3D rte_rdtsc() - cur_cyc; > + > + cur_cyc =3D rte_rdtsc(); > + rresult_u64 =3D rte_reciprocal_divide_u64(dividend_u64, > + &reci_u64); > + tot_cyc_r +=3D rte_rdtsc() - cur_cyc; > + if (nresult_u64 !=3D rresult_u64) { > + printf("Division failed, expected %"PRIu64" " > + "result %"PRIu64"", > + nresult_u64, rresult_u64); > + result =3D 1; > + break; > + } > + } > + printf("64bit Division results:\n"); > + printf("Total number of cycles normal division : %"PRIu64"\n", > + tot_cyc_n); > + printf("Total number of cycles reciprocal division : %"PRIu64"\n", > + tot_cyc_r); > + printf("Cycles per division(normal) : %3.2f\n", > + ((double)tot_cyc_n)/i); > + printf("Cycles per division(normal) : %3.2f\n", > + ((double)tot_cyc_r)/i); > + > + tot_cyc_n =3D 0; > + tot_cyc_r =3D 0; > + > + return result; > +} > + > +REGISTER_TEST_COMMAND(reciprocal_division_perf, > +test_reciprocal_division_perf); > -- > 2.7.4