From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 064BFA0563; Wed, 15 Apr 2020 20:18:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9BDA51D9E1; Wed, 15 Apr 2020 20:17:43 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 7399E1D9CB for ; Wed, 15 Apr 2020 20:17:37 +0200 (CEST) IronPort-SDR: gzf6riDXXPWRHVQy9pGYobfEhjMDDS3K+uptRsOhiPbnJRyyo/3lpYX951ijZKGQUIOlK9l/DY 3Uv3QdMYhK2w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2020 11:17:37 -0700 IronPort-SDR: jxFFw4t32nWjQHR8i95SVAXbO2pN5OykAAS8i9MhTIc7F4FTHwHrMzXD/fcahfiUiCqfzczs7E vAwqmHCYsrTQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,388,1580803200"; d="scan'208";a="277702382" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 15 Apr 2020 11:17:35 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com Date: Wed, 15 Apr 2020 19:17:27 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 4/4] test: add k32v64 perf tests 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add performance tests for rte_k32v64_hash Signed-off-by: Vladimir Medvedkin --- app/test/test_hash_perf.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c index a438eae..f45a8d9 100644 --- a/app/test/test_hash_perf.c +++ b/app/test/test_hash_perf.c @@ -12,8 +12,10 @@ #include #include #include +#include #include #include +#include #include "test.h" @@ -29,6 +31,8 @@ #define NUM_SHUFFLES 10 #define BURST_SIZE 16 +#define CRC_INIT_VAL 0xdeadbeef + enum operations { ADD = 0, LOOKUP, @@ -668,6 +672,129 @@ fbk_hash_perf_test(void) return 0; } +static uint32_t * +shuf_arr(uint32_t *arr, int n, int l) +{ + int i, j; + uint32_t tmp; + uint32_t *ret_arr; + + ret_arr = rte_zmalloc(NULL, l * sizeof(uint32_t), 0); + for (i = 0; i < n; i++) { + j = rte_rand() % n; + tmp = arr[j]; + arr[j] = arr[i]; + arr[i] = tmp; + } + for (i = 0; i < l; i++) + ret_arr[i] = arr[i % n]; + + return ret_arr; +} + +static int +k32v64_hash_perf_test(void) +{ + struct rte_k32v64_hash_params params = { + .name = "k32v64_hash_test", + .entries = ENTRIES * 2, + .socket_id = rte_socket_id(), + }; + struct rte_k32v64_hash_table *handle = NULL; + uint32_t *keys; + uint32_t *lookup_keys; + uint64_t tmp_val; + uint64_t lookup_time = 0; + uint64_t begin; + uint64_t end; + unsigned int added = 0; + uint32_t key; + uint16_t val; + unsigned int i, j, k; + int ret = 0; + uint32_t hashes[64]; + uint64_t vals[64]; + + handle = rte_k32v64_hash_create(¶ms); + if (handle == NULL) { + printf("Error creating table\n"); + return -1; + } + + keys = rte_zmalloc(NULL, ENTRIES * sizeof(*keys), 0); + if (keys == NULL) { + printf("fbk hash: memory allocation for key store failed\n"); + return -1; + } + + /* Generate random keys and values. */ + for (i = 0; i < ENTRIES; i++) { + key = (uint32_t)rte_rand(); + val = rte_rand(); + + if (rte_k32v64_hash_add(handle, key, rte_hash_crc_4byte(key, + CRC_INIT_VAL), val) == 0) { + keys[added] = key; + added++; + } + } + + lookup_keys = shuf_arr(keys, added, TEST_SIZE); + + for (i = 0; i < TEST_ITERATIONS; i++) { + + begin = rte_rdtsc(); + /* Do lookups */ + + for (j = 0; j < TEST_SIZE; j++) + ret += rte_k32v64_hash_lookup(handle, lookup_keys[j], + rte_hash_crc_4byte(lookup_keys[j], + CRC_INIT_VAL), &tmp_val); + + end = rte_rdtsc(); + lookup_time += (double)(end - begin); + } + + printf("\n\n *** K32V64 Hash function performance test results ***\n"); + if (ret == 0) + printf("Number of ticks per lookup = %g\n", + (double)lookup_time / + ((double)TEST_ITERATIONS * (double)TEST_SIZE)); + + lookup_time = 0; + for (i = 0; i < TEST_ITERATIONS; i++) { + + begin = rte_rdtsc(); + /* Do lookups */ + + for (j = 0; j < TEST_SIZE; j += 64) { + for (k = 0; k < 64; k++) { + hashes[k] = + rte_hash_crc_4byte(lookup_keys[j + k], + CRC_INIT_VAL); + } + + ret += rte_k32v64_hash_bulk_lookup(handle, + &lookup_keys[j], hashes, vals, 64); + } + + end = rte_rdtsc(); + lookup_time += (double)(end - begin); + } + + printf("\n\n *** K32V64 Hash function performance test results ***\n"); + if (ret != 0) + printf("Number of ticks per bulk lookup = %g\n", + (double)lookup_time / + ((double)TEST_ITERATIONS * (double)TEST_SIZE)); + + rte_free(keys); + rte_free(lookup_keys); + rte_k32v64_hash_free(handle); + + return 0; +} + static int test_hash_perf(void) { @@ -695,6 +822,9 @@ test_hash_perf(void) if (fbk_hash_perf_test() < 0) return -1; + if (k32v64_hash_perf_test() < 0) + return -1; + return 0; } -- 2.7.4