From: Elza Mathew Date: Mon, 6 Nov 2017 18:04:49 +0000 (-0800) Subject: hash: select fbk function at run-time X-Git-Tag: spdx-start~134 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c43cb3b184ca416c2a2ecd66668edb797cbcd25c;hp=3a47be9abbb64e44c85a689024a8de78a938e0c3;p=dpdk.git hash: select fbk 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 --- diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index 4aff40e677..c9b470d7e2 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -84,6 +84,7 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) sizeof(*ht) + (sizeof(ht->t[0]) * params->entries); uint32_t i; struct rte_fbk_hash_list *fbk_hash_list; + rte_fbk_hash_fn default_hash_func = (rte_fbk_hash_fn)rte_jhash_1word; fbk_hash_list = RTE_TAILQ_CAST(rte_fbk_hash_tailq.head, rte_fbk_hash_list); @@ -131,6 +132,14 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) goto exit; } + /* Default hash function */ +#if defined(RTE_ARCH_X86) + default_hash_func = (rte_fbk_hash_fn)rte_hash_crc_4byte; +#elif defined(RTE_ARCH_ARM64) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) + default_hash_func = (rte_fbk_hash_fn)rte_hash_crc_4byte; +#endif + /* Set up hash table context. */ snprintf(ht->name, sizeof(ht->name), "%s", params->name); ht->entries = params->entries; @@ -147,7 +156,7 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) ht->init_val = params->init_val; } else { - ht->hash_func = RTE_FBK_HASH_FUNC_DEFAULT; + ht->hash_func = default_hash_func; ht->init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT; } diff --git a/lib/librte_hash/rte_fbk_hash.h b/lib/librte_hash/rte_fbk_hash.h index 09158781b4..c4d6976d2b 100644 --- a/lib/librte_hash/rte_fbk_hash.h +++ b/lib/librte_hash/rte_fbk_hash.h @@ -26,16 +26,8 @@ extern "C" { #include #include -#ifndef RTE_FBK_HASH_FUNC_DEFAULT -#if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32) #include -/** Default four-byte key hash function if none is specified. */ -#define RTE_FBK_HASH_FUNC_DEFAULT rte_hash_crc_4byte -#else #include -#define RTE_FBK_HASH_FUNC_DEFAULT rte_jhash_1word -#endif -#endif #ifndef RTE_FBK_HASH_INIT_VAL_DEFAULT /** Initialising value used when calculating hash. */