[dpdk-dev] [PATCH v2 4/4] test: add k32v64 perf tests

Vladimir Medvedkin vladimir.medvedkin at intel.com
Wed Apr 8 20:19:57 CEST 2020


Add performance tests for rte_k32v64_hash

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin at intel.com>
---
 app/test/test_hash_perf.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c
index a438eae..0a02445 100644
--- a/app/test/test_hash_perf.c
+++ b/app/test/test_hash_perf.c
@@ -12,8 +12,10 @@
 #include <rte_hash_crc.h>
 #include <rte_jhash.h>
 #include <rte_fbk_hash.h>
+#include <rte_k32v64_hash.h>
 #include <rte_random.h>
 #include <rte_string_fns.h>
+#include <rte_hash_crc.h>
 
 #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,
@@ -669,6 +673,82 @@ fbk_hash_perf_test(void)
 }
 
 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 = NULL;
+	unsigned int indexes[TEST_SIZE];
+	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;
+	int ret = 0;
+
+	handle = rte_k32v64_hash_create(&params);
+	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++;
+		}
+	}
+
+	for (i = 0; i < TEST_ITERATIONS; i++) {
+
+		/* Generate random indexes into keys[] array. */
+		for (j = 0; j < TEST_SIZE; j++)
+			indexes[j] = rte_rand() % added;
+
+		begin = rte_rdtsc();
+		/* Do lookups */
+
+		for (j = 0; j < TEST_SIZE; j++)
+			ret += rte_k32v64_hash_lookup(handle,
+				keys[indexes[j]],
+				rte_hash_crc_4byte(keys[indexes[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));
+
+	rte_k32v64_hash_free(handle);
+
+	return 0;
+}
+
+static int
 test_hash_perf(void)
 {
 	unsigned int with_pushes, with_locks;
@@ -695,6 +775,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



More information about the dev mailing list