hash: select fbk function at run-time
authorElza Mathew <elza.mathew@intel.com>
Mon, 6 Nov 2017 18:04:49 +0000 (10:04 -0800)
committerThomas Monjalon <thomas@monjalon.net>
Sat, 20 Jan 2018 14:35:16 +0000 (15:35 +0100)
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 <elza.mathew@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
lib/librte_hash/rte_fbk_hash.c
lib/librte_hash/rte_fbk_hash.h

index 4aff40e..c9b470d 100644 (file)
@@ -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;
        }
 
index 0915878..c4d6976 100644 (file)
@@ -26,16 +26,8 @@ extern "C" {
 #include <string.h>
 
 #include <rte_config.h>
-#ifndef RTE_FBK_HASH_FUNC_DEFAULT
-#if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32)
 #include <rte_hash_crc.h>
-/** Default four-byte key hash function if none is specified. */
-#define RTE_FBK_HASH_FUNC_DEFAULT              rte_hash_crc_4byte
-#else
 #include <rte_jhash.h>
-#define RTE_FBK_HASH_FUNC_DEFAULT              rte_jhash_1word
-#endif
-#endif
 
 #ifndef RTE_FBK_HASH_INIT_VAL_DEFAULT
 /** Initialising value used when calculating hash. */