From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id A25381B26D for ; Tue, 7 Nov 2017 01:13:45 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2017 16:13:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,355,1505804400"; d="scan'208";a="332923331" Received: from ar11-dell-r730-21.jf.intel.com ([10.166.189.20]) by fmsmga004.fm.intel.com with ESMTP; 06 Nov 2017 16:13:44 -0800 From: Elza Mathew To: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org Date: Mon, 6 Nov 2017 10:04:49 -0800 Message-Id: <1509991489-26442-1-git-send-email-elza.mathew@intel.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH 2/3] hash: run-time function selection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Nov 2017 00:13:46 -0000 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 --- lib/librte_hash/rte_fbk_hash.c | 11 ++++++++++- lib/librte_hash/rte_fbk_hash.h | 8 -------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index 55c9f35..7c4e194 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -114,6 +114,7 @@ struct rte_fbk_hash_table * 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); @@ -161,6 +162,14 @@ struct rte_fbk_hash_table * 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; @@ -177,7 +186,7 @@ struct rte_fbk_hash_table * 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 c39c097..1b1b7df 100644 --- a/lib/librte_hash/rte_fbk_hash.h +++ b/lib/librte_hash/rte_fbk_hash.h @@ -54,16 +54,8 @@ #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. */ -- 1.9.1