From 3a47be9abbb64e44c85a689024a8de78a938e0c3 Mon Sep 17 00:00:00 2001 From: Elza Mathew Date: Mon, 6 Nov 2017 10:04:02 -0800 Subject: [PATCH] hash: select cuckoo function at run-time Compile-time function selection can potentially lead to lower performance on generic builds done by distros. Replaced compile time flag checks with run-time function selection. Signed-off-by: Elza Mathew Acked-by: Bruce Richardson --- lib/librte_hash/rte_cuckoo_hash.c | 10 +++++++++- lib/librte_hash/rte_cuckoo_hash.h | 6 ------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 8bd3e6fc45..9b1387b5e8 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -95,6 +95,7 @@ rte_hash_create(const struct rte_hash_parameters *params) unsigned num_key_slots; unsigned hw_trans_mem_support = 0; unsigned i; + rte_hash_function default_hash_func = (rte_hash_function)rte_jhash; hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list); @@ -238,6 +239,13 @@ rte_hash_create(const struct rte_hash_parameters *params) RTE_CACHE_LINE_SIZE, params->socket_id); } + /* Default hash function */ +#if defined(RTE_ARCH_X86) + default_hash_func = (rte_hash_function)rte_hash_crc; +#elif defined(RTE_ARCH_ARM64) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) + default_hash_func = (rte_hash_function)rte_hash_crc; +#endif /* Setup hash context */ snprintf(h->name, sizeof(h->name), "%s", params->name); h->entries = params->entries; @@ -249,7 +257,7 @@ rte_hash_create(const struct rte_hash_parameters *params) h->bucket_bitmask = h->num_buckets - 1; h->buckets = buckets; h->hash_func = (params->hash_func == NULL) ? - DEFAULT_HASH_FUNC : params->hash_func; + default_hash_func : params->hash_func; h->key_store = k; h->free_slots = r; h->hw_trans_mem_support = hw_trans_mem_support; diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h index 658471a714..7a54e55575 100644 --- a/lib/librte_hash/rte_cuckoo_hash.h +++ b/lib/librte_hash/rte_cuckoo_hash.h @@ -28,14 +28,8 @@ #define RETURN_IF_TRUE(cond, retval) #endif -/* Hash function used if none is specified */ -#if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32) #include -#define DEFAULT_HASH_FUNC rte_hash_crc -#else #include -#define DEFAULT_HASH_FUNC rte_jhash -#endif #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64) /* -- 2.20.1