From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0070.outbound.protection.outlook.com [104.47.34.70]) by dpdk.org (Postfix) with ESMTP id CACBD5688 for ; Tue, 5 Sep 2017 12:49:18 +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=pxKHKDX+78xBpnsHtTkDGehB9ZFe3lwa3eNz7YS43fg=; b=mGRMIoL4lCQzxDm5S6OlJngCesDFNE6NMYBZvmmFYVHK92RHkvl/B2Pcrl74h8IHMheC2qEcp4McKN9P60ImByz/+ucdYJlMycbOPptpUqXnr0BjZjskcf9f8FZHcPIkXXri+x2f+cR1Otx1lcPumFa3srojA2FtGbJtuD9V54E= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from PBHAGAVATULA-LT.caveonetworks.com (111.93.218.67) by CY4PR07MB3461.namprd07.prod.outlook.com (10.171.252.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Tue, 5 Sep 2017 10:49:15 +0000 From: Pavan Nikhilesh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, stephen@networkplumber.org, Pavan Bhagavatula Date: Tue, 5 Sep 2017 16:18:52 +0530 Message-Id: <1504608532-18598-3-git-send-email-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504608532-18598-1-git-send-email-pbhagavatula@caviumnetworks.com> References: <1504608532-18598-1-git-send-email-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: MWHPR15CA0070.namprd15.prod.outlook.com (10.174.254.32) To CY4PR07MB3461.namprd07.prod.outlook.com (10.171.252.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6009e9d5-7f09-4315-9d37-08d4f44bc173 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:CY4PR07MB3461; X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3461; 3:xLcgo5bkcxs20jspsF2N8ibMDg1/Lza9QBbVYTd8RtiigbOuysuJOJmuhHIWidsEFgskR/m/YUOlaztUEOuGmuC5xnI4FdTP2NaIaAE2tJNOv4u5HC+KwNGtVMgv76QyAc4djhepuzuucZnT6Kbt/0Hsp6OI9M04+YFhNUKoeyMJPFCs4qIJDJzTMVY6cHmOQ78qVDheMPTYChX9fPOipf9c7To70xjsUgQLL1eb0OYBvZsHrLAR5f7HUCKt9RsC; 25:oI5BkEumSoT2qbzhgAtlHXbqhkeELjMFkHRzLHx2kLLeGZqXsp4uGXnUZXySz716t9oxvyNdTyw1JHgkKVZk3GTCslaJk2shytXmx78W4H2pAGmH9EOu6wea23DhuG+hUwyDgSrhBFZJ55qO3A1hRcCXnhRKWRYcNHro2ns1evk4JL0JAb6MePC7/PHuAhpAEue+Mp11fNZ9++TVsoRgTCo+dpcQs08SRTRAgYNPyMIzhlE+x6x3HqbJNt9Z4Da5AVtB2Ljx8qbgb9H8jBzNkiMAZGjrqRAlN2dLJpujshpND/Vr2QdxdF18W2fJmw04LN8FNNekGWuzmMFA2Ge3AQ==; 31:6L34gZC8Key7N4QfSbHwQR2kiQCdbBf448VHO6Ei5ejgsTYmyBXxdW5v1+aYR2645I/+S1ZaXlLqU74fl/98o+uwJ8gwx/WTGkuNQeFLjuYEZQyZcgEssfwqiQSkqYXEQ8yjd52QdDIPm6YRrRHYbZdhkiXREVUr8R5jKxkR8+sNKMcOmj2HoQ5PalMirs0Gx3avRB8lvB4qnI5NzMNiTFLKQ+cOFJkZZcMnI01iJAY= X-MS-TrafficTypeDiagnostic: CY4PR07MB3461: X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3461; 20:BFbb9wQ3g8TL0DbRTCayNrTgXg7aixY2xHxMCdXkbjiv216CSDok3zhiZiKhQGd1j0YlbN9ql+meiMISSD8JmGggBA4LiPjgV6x2Fe74Jo/OQf7uu/w6/iJsjmKSsvFdFv8vkPaIZFwEj6GxqE8Xbss66LBmdijqNVZbUfWMJd9xaq43iQ6cJ8sTHnAACxz/ChlavCSMeUUiYYBxfo8GU9Jc5CorRDxFhOmVmrzhOVeFdR3zQYjfvl2mRe6bi1Kb+EN7vOGqbq7/Jw48iVfQkGOVBeCFqMLLiueRFYyW9dJykUvWYwN7dW+zi8MgsTf19O6+OZDdPpPERwT+i9dZGyykA/iBfthuQ+uNeLO/8i9Uu5FMEcYJXfvFY47L0TWy3nYQWfKE+tguYklx5kqaUb+fWCl60hptbkiSJJE+dvGyof4q2h6+iDSBPSnSem8NRY1/J93w/EuKejGSLMums0rmsOzN25+y41R+0oh0q8nQrcyb/m+rwiW111BxOyQHL30/sDm7LACF2vhpR1go1G2IUIL9E9TD257nJezQPWT238nWap6WJwUBYj0cHIx97rOv0zVBhzUhcARZWVCkOr0ck4IzElNyhGCVjfHftaw=; 4:SrRNWhYjnzMAmSCQHr3rWACP+9OACWNUYKnrxn9/ZDugJbXu8BqX0xmoWUIdNey+saewhhENHcwTQkHdzjrLQwHkq4nIbQZi5OJa88gRxA0F1ymYnsmBEbGQLv2YXQbBeiqlauQLOHw0T4c8v+NqdBYNK1W0BnWM7Cd/N701xu2zJHMvLURnBy1kLmfmEiC7olfYH9DEbYbUu0HR5KZoLdyw6+avIhYECTH33JuBW69Ee4BW/DKWsWNqaRBI+6tl X-Exchange-Antispam-Report-Test: UriScan:; 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)(10201501046)(93006095)(100000703101)(100105400095)(3002001)(6041248)(20161123555025)(20161123560025)(20161123558100)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY4PR07MB3461; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY4PR07MB3461; X-Forefront-PRVS: 0421BF7135 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(199003)(189002)(50466002)(72206003)(69596002)(48376002)(305945005)(66066001)(97736004)(478600001)(107886003)(4326008)(110136004)(8936002)(53936002)(6512007)(81156014)(5660300001)(8676002)(68736007)(7736002)(25786009)(81166006)(36756003)(50226002)(42186005)(5003940100001)(105586002)(2361001)(33646002)(101416001)(53416004)(6116002)(189998001)(3846002)(2950100002)(6916009)(42882006)(2906002)(5009440100003)(50986999)(47776003)(6486002)(76176999)(6666003)(6506006)(106356001)(2351001)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR07MB3461; H:PBHAGAVATULA-LT.caveonetworks.com; 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; CY4PR07MB3461; 23:rwxI4GL+vcFbtYwFh9gyLq2ID0ervS9Hz6MH/5+/l?= =?us-ascii?Q?nJ7QTrbLaCEKepmT60i1sEJx+mDe9auUbdkl0Ytcq8p5pAMtzC/4TQYE107E?= =?us-ascii?Q?PS2er5KuN5/wRUNW0Bgl9RrYmk93/3LXzWJVfgEBXESlsWIaJaOv9QaSftUV?= =?us-ascii?Q?tJlV7Pu95i1hvvgdhEh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gmiL4dvI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2017 10:49:15.5917 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR07MB3461 Subject: [dpdk-dev] [PATCH v4 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: Tue, 05 Sep 2017 10:49:19 -0000 From: Pavan Bhagavatula This commit provides a set of tests for verifying the correctness and performance of both unsigned 32 and 64bit reciprocal based division. Signed-off-by: Pavan Nikhilesh --- test/test/Makefile | 2 + test/test/test_reciprocal_division.c | 109 +++++++++++++++++ test/test/test_reciprocal_division_perf.c | 193 ++++++++++++++++++++++++++++++ 3 files changed, 304 insertions(+) create mode 100644 test/test/test_reciprocal_division.c create mode 100644 test/test/test_reciprocal_division_perf.c diff --git a/test/test/Makefile b/test/test/Makefile index 42d9a49..6017862 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -94,6 +94,8 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c +SRCS-y += test_reciprocal_division.c +SRCS-y += test_reciprocal_division_perf.c SRCS-y += test_ring.c SRCS-y += 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 copyright + * 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 = 0; + uint32_t divisor_u32 = 0; + uint32_t dividend_u32; + uint32_t nresult_u32; + uint32_t rresult_u32; + uint64_t divisor_u64 = 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 = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u32 = rte_rand(); + reci_u32 = rte_reciprocal_value_u32(divisor_u32); + } + + dividend_u32 = rte_rand(); + nresult_u32 = dividend_u32 / divisor_u32; + rresult_u32 = rte_reciprocal_divide_u32(dividend_u32, + &reci_u32); + if (nresult_u32 != rresult_u32) { + printf("Division failed, expected %"PRIu32" " + "result %"PRIu32"", + nresult_u32, rresult_u32); + result = 1; + break; + } + } + + printf("Validating unsigned 64bit division.\n"); + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u64 = rte_rand(); + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + } + + dividend_u64 = rte_rand(); + nresult_u64 = dividend_u64 / divisor_u64; + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + if (nresult_u64 != rresult_u64) { + printf("Division failed, expected %"PRIu64" " + "result %"PRIu64"", + nresult_u64, rresult_u64); + result = 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..e69cf39 --- /dev/null +++ b/test/test/test_reciprocal_division_perf.c @@ -0,0 +1,193 @@ +/* + * 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 copyright + * 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 = 0; + uint32_t divisor_u32 = 0; + volatile uint32_t dividend_u32; + uint32_t nresult_u32; + uint32_t rresult_u32; + uint64_t divisor_u64 = 0; + volatile uint64_t dividend_u64; + uint64_t nresult_u64; + uint64_t rresult_u64; + uint64_t start_cyc; + uint64_t split_cyc; + uint64_t end_cyc; + uint64_t tot_cyc_n = 0; + uint64_t tot_cyc_r = 0; + uint64_t i; + struct rte_reciprocal_u32 reci_u32 = {0}; + struct rte_reciprocal_u64 reci_u64 = {0}; + + rte_srand(rte_rdtsc()); + + printf("Validating unsigned 32bit division.\n"); + + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u32 = rte_rand(); + reci_u32 = rte_reciprocal_value_u32(divisor_u32); + } + + dividend_u32 = rte_rand(); + + start_cyc = rte_rdtsc(); + nresult_u32 = dividend_u32 / divisor_u32; + split_cyc = rte_rdtsc(); + rresult_u32 = rte_reciprocal_divide_u32(dividend_u32, + &reci_u32); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_cyc; + if (nresult_u32 != rresult_u32) { + printf("Division failed, expected %"PRIu32" " + "result %"PRIu32"", + nresult_u32, rresult_u32); + result = 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 = 0; + tot_cyc_r = 0; + + printf("Validating unsigned 64bit division.\n"); + + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u64 = rte_rand(); + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + } + + dividend_u64 = rte_rand(); + + start_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + split_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_cyc; + if (nresult_u64 != rresult_u64) { + printf("Division failed, expected %"PRIu64" " + "result %"PRIu64"", + nresult_u64, rresult_u64); + result = 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); + + tot_cyc_n = 0; + tot_cyc_r = 0; + + printf("Validating unsigned 64bit division with 32bit divisor.\n"); + + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u64 = rte_rand() >> 32; + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + } + + dividend_u64 = rte_rand(); + + start_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + split_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_cyc; + if (nresult_u64 != rresult_u64) { + printf("Division failed, expected %"PRIu64" " + "result %"PRIu64"", + nresult_u64, rresult_u64); + result = 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); + + return result; +} + +REGISTER_TEST_COMMAND(reciprocal_division_perf, test_reciprocal_division_perf); -- 2.7.4