From 18d5e8d78c25c74da0af78465d2853b20ed4ca82 Mon Sep 17 00:00:00 2001 From: Intel Date: Thu, 20 Dec 2012 00:00:00 +0100 Subject: [PATCH] hash: select default hash by looking at SSE flags Signed-off-by: Intel --- app/test/test_hash.c | 11 +++++++---- examples/l3fwd-vf/main.c | 13 ++++++++++--- examples/l3fwd/main.c | 11 +++++++++-- lib/librte_hash/rte_fbk_hash.c | 11 ----------- lib/librte_hash/rte_fbk_hash.h | 11 ++++++++--- lib/librte_hash/rte_hash.c | 16 ++++++---------- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/app/test/test_hash.c b/app/test/test_hash.c index 7d8cb2ab51..b54fc95f96 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -46,15 +46,18 @@ #include #include #include -#include -#include -#include #include #include -#include #include #include +#include +#include +#include + +#ifdef RTE_MACHINE_CPUFLAG_SSE4_2 +#include +#endif #include #include "test.h" diff --git a/examples/l3fwd-vf/main.c b/examples/l3fwd-vf/main.c index efb250e197..9e2d9abc8d 100644 --- a/examples/l3fwd-vf/main.c +++ b/examples/l3fwd-vf/main.c @@ -86,8 +86,6 @@ #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) #include -#include -#include #elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM) #include #else @@ -224,6 +222,15 @@ static struct rte_mempool * pktmbuf_pool[NB_SOCKETS]; #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) + +#ifdef RTE_MACHINE_CPUFLAG_SSE4_2 +#include +#define DEFAULT_HASH_FUNC rte_hash_crc +#else +#include +#define DEFAULT_HASH_FUNC rte_jhash +#endif + struct ipv4_5tuple { uint32_t ip_dst; uint32_t ip_src; @@ -253,7 +260,7 @@ struct rte_hash_parameters l3fwd_hash_params = { .entries = L3FWD_HASH_ENTRIES, .bucket_entries = 4, .key_len = sizeof(struct ipv4_5tuple), - .hash_func = rte_hash_crc, + .hash_func = DEFAULT_HASH_FUNC, .hash_func_init_val = 0, .socket_id = SOCKET0, }; diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index b63f3cc30a..0fcc0c3631 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -86,8 +86,6 @@ #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) #include -#include -#include #elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM) #include #else @@ -225,6 +223,15 @@ static struct rte_mempool * pktmbuf_pool[NB_SOCKETS]; #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) + +#ifdef RTE_MACHINE_CPUFLAG_SSE4_2 +#include +#define DEFAULT_HASH_FUNC rte_hash_crc +#else +#include +#define DEFAULT_HASH_FUNC rte_jhash +#endif + struct ipv4_5tuple { uint32_t ip_dst; uint32_t ip_src; diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index cff5a8fb47..915831e984 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -54,8 +53,6 @@ #include #include "rte_fbk_hash.h" -#include "rte_jhash.h" -#include "rte_hash_crc.h" TAILQ_HEAD(rte_fbk_hash_list, rte_fbk_hash_table); @@ -174,14 +171,6 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) ht->init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT; } - if (ht->hash_func == rte_hash_crc_4byte && - !rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_2)) { - RTE_LOG(WARNING, HASH, "CRC32 instruction requires SSE4.2, " - "which is not supported on this system. " - "Falling back to software hash\n."); - ht->hash_func = rte_jhash_1word; - } - TAILQ_INSERT_TAIL(fbk_hash_list, ht, next); return ht; } diff --git a/lib/librte_hash/rte_fbk_hash.h b/lib/librte_hash/rte_fbk_hash.h index 48c90c7222..45d2c6f88c 100644 --- a/lib/librte_hash/rte_fbk_hash.h +++ b/lib/librte_hash/rte_fbk_hash.h @@ -48,7 +48,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { @@ -57,8 +56,14 @@ extern "C" { #include #ifndef RTE_FBK_HASH_FUNC_DEFAULT +#ifdef RTE_MACHINE_CPUFLAG_SSE4_2 +#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 @@ -96,7 +101,7 @@ union rte_fbk_hash_entry { uint16_t value; /**< Value returned by lookup. */ uint32_t key; /**< Key used to find value. */ } entry; /**< For accessing each entry part. */ -} ; +}; @@ -178,7 +183,7 @@ rte_fbk_hash_add_key(struct rte_fbk_hash_table *ht, } } - return -ENOSPC; /* No space in bucket. */ + return -ENOSPC; /* No space in bucket. */ } /** diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index e558cd97c1..c8569710fe 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -57,8 +57,6 @@ #include #include "rte_hash.h" -#include "rte_jhash.h" -#include "rte_hash_crc.h" TAILQ_HEAD(rte_hash_list, rte_hash); @@ -73,7 +71,13 @@ TAILQ_HEAD(rte_hash_list, rte_hash); #endif /* Hash function used if none is specified */ +#ifdef RTE_MACHINE_CPUFLAG_SSE4_2 +#include #define DEFAULT_HASH_FUNC rte_hash_crc +#else +#include +#define DEFAULT_HASH_FUNC rte_jhash +#endif /* Signature bucket size is a multiple of this value */ #define SIG_BUCKET_ALIGNMENT 16 @@ -244,14 +248,6 @@ rte_hash_create(const struct rte_hash_parameters *params) h->hash_func = (params->hash_func == NULL) ? DEFAULT_HASH_FUNC : params->hash_func; - if (h->hash_func == rte_hash_crc && - !rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_2)) { - RTE_LOG(WARNING, HASH, "CRC32 instruction requires SSE4.2, " - "which is not supported on this system. " - "Falling back to software hash\n."); - h->hash_func = rte_jhash; - } - TAILQ_INSERT_TAIL(hash_list, h, next); return h; } -- 2.20.1