static int fbk_hash_perf_test(void) { struct rte_fbk_hash_params params = { .name = "fbk_hash_test", .entries = ENTRIES, .entries_per_bucket = 4, .socket_id = rte_socket_id(), }; struct rte_fbk_hash_table *handle = NULL; uint32_t *keys = NULL; unsigned indexes[TEST_SIZE]; uint64_t lookup_time = 0; unsigned added = 0; unsigned value = 0; uint32_t key; uint16_t val; unsigned i, j; handle = rte_fbk_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(); key = ((uint64_t)key << 32) | (uint64_t)rte_rand(); val = (uint16_t)rte_rand(); if (rte_fbk_hash_add_key(handle, key, val) == 0) { keys[added] = key; added++; } if (added > (LOAD_FACTOR * ENTRIES)) break; } for (i = 0; i < TEST_ITERATIONS; i++) { uint64_t begin; uint64_t end; /* 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++) value += rte_fbk_hash_lookup(handle, keys[indexes[j]]); end = rte_rdtsc(); lookup_time += (double)(end - begin); } printf("\n\n *** FBK Hash function performance test results ***\n"); /* * The use of the 'value' variable ensures that the hash lookup is not * being optimised out by the compiler. */ if (value != 0) printf("Number of ticks per lookup = %g\n", (double)lookup_time / ((double)TEST_ITERATIONS * (double)TEST_SIZE)); rte_fbk_hash_free(handle); return 0; } static int test_hash_perf(void) { unsigned with_pushes; for (with_pushes = 0; with_pushes <= 1; with_pushes++) { if (with_pushes == 0) printf("\nALL ELEMENTS IN PRIMARY LOCATION\n"); else printf("\nELEMENTS IN PRIMARY OR SECONDARY LOCATION\n"); if (run_all_tbl_perf_tests(with_pushes) < 0) return -1; } if (fbk_hash_perf_test() < 0) return -1; return 0; }
static int fbk_hash_perf_test(void) { struct rte_fbk_hash_params params = { .name = "fbk_hash_test", .entries = ENTRIES, .entries_per_bucket = 4, .socket_id = rte_socket_id(), }; struct rte_fbk_hash_table *handle; uint32_t keys[ENTRIES] = {0}; unsigned indexes[TEST_SIZE]; uint64_t lookup_time = 0; unsigned added = 0; unsigned value = 0; unsigned i, j; handle = rte_fbk_hash_create(¶ms); RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation failed"); /* Generate random keys and values. */ for (i = 0; i < ENTRIES; i++) { uint32_t key = (uint32_t)rte_rand(); key = ((uint64_t)key << 32) | (uint64_t)rte_rand(); uint16_t val = (uint16_t)rte_rand(); if (rte_fbk_hash_add_key(handle, key, val) == 0) { keys[added] = key; added++; } if (added > (LOAD_FACTOR * ENTRIES)) { break; } } for (i = 0; i < TEST_ITERATIONS; i++) { uint64_t begin; uint64_t end; /* 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++) { value += rte_fbk_hash_lookup(handle, keys[indexes[j]]); } end = rte_rdtsc(); lookup_time += (double)(end - begin); } printf("\n\n *** FBK Hash function performance test results ***\n"); /* * The use of the 'value' variable ensures that the hash lookup is not * being optimised out by the compiler. */ if (value != 0) printf("Number of ticks per lookup = %g\n", (double)lookup_time / ((double)TEST_ITERATIONS * (double)TEST_SIZE)); rte_fbk_hash_free(handle); return 0; } /* * Do all unit and performance tests. */ int test_hash_perf(void) { if (run_all_tbl_perf_tests() < 0) return -1; run_hash_func_tests(); if (fbk_hash_perf_test() < 0) return -1; return 0; } #else /* RTE_LIBRTE_HASH */ int test_hash_perf(void) { printf("The Hash library is not included in this build\n"); return 0; }