hash: select default hash by looking at SSE flags

Signed-off-by: Intel
This commit is contained in:
Intel 2012-12-20 00:00:00 +01:00 committed by Thomas Monjalon
parent 3569fcf1c4
commit 18d5e8d78c
6 changed files with 40 additions and 33 deletions

View File

@ -46,15 +46,18 @@
#include <rte_random.h>
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_hash.h>
#include <rte_hash_crc.h>
#include <rte_jhash.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_fbk_hash.h>
#include <rte_ip.h>
#include <rte_string_fns.h>
#include <rte_hash.h>
#include <rte_fbk_hash.h>
#include <rte_jhash.h>
#ifdef RTE_MACHINE_CPUFLAG_SSE4_2
#include <rte_hash_crc.h>
#endif
#include <cmdline_parse.h>
#include "test.h"

View File

@ -86,8 +86,6 @@
#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
#include <rte_hash.h>
#include <rte_hash_crc.h>
#include <rte_jhash.h>
#elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
#include <rte_lpm.h>
#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 <rte_hash_crc.h>
#define DEFAULT_HASH_FUNC rte_hash_crc
#else
#include <rte_jhash.h>
#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,
};

View File

@ -86,8 +86,6 @@
#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
#include <rte_hash.h>
#include <rte_hash_crc.h>
#include <rte_jhash.h>
#elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
#include <rte_lpm.h>
#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 <rte_hash_crc.h>
#define DEFAULT_HASH_FUNC rte_hash_crc
#else
#include <rte_jhash.h>
#define DEFAULT_HASH_FUNC rte_jhash
#endif
struct ipv4_5tuple {
uint32_t ip_dst;
uint32_t ip_src;

View File

@ -43,7 +43,6 @@
#include <rte_memzone.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_hash_crc.h>
#include <rte_eal_memconfig.h>
#include <rte_malloc.h>
#include <rte_common.h>
@ -54,8 +53,6 @@
#include <rte_log.h>
#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;
}

View File

@ -48,7 +48,6 @@
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>
#include <rte_hash_crc.h>
#ifdef __cplusplus
extern "C" {
@ -57,8 +56,14 @@ extern "C" {
#include <string.h>
#ifndef RTE_FBK_HASH_FUNC_DEFAULT
#ifdef RTE_MACHINE_CPUFLAG_SSE4_2
#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
@ -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. */
}
/**

View File

@ -57,8 +57,6 @@
#include <rte_log.h>
#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 <rte_hash_crc.h>
#define DEFAULT_HASH_FUNC rte_hash_crc
#else
#include <rte_jhash.h>
#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;
}