From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 0C11E1B254 for ; Tue, 7 Nov 2017 01:13:30 +0100 (CET) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP; 06 Nov 2017 16:13:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,355,1505804400"; d="scan'208";a="172820793" Received: from ar11-dell-r730-21.jf.intel.com ([10.166.189.20]) by fmsmga006.fm.intel.com with ESMTP; 06 Nov 2017 16:13:29 -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:02 -0800 Message-Id: <1509991442-26391-1-git-send-email-elza.mathew@intel.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH 1/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:31 -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_cuckoo_hash.c | 10 +++++++++- lib/librte_hash/rte_cuckoo_hash.h | 6 ------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index e69b911..078d9c8 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -125,6 +125,7 @@ struct rte_hash * unsigned num_key_slots; unsigned hw_trans_mem_support = 0; unsigned i; + rte_hash_function default_hash_func = (rte_hash_function)rte_jhash; hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list); @@ -268,6 +269,13 @@ struct rte_hash * RTE_CACHE_LINE_SIZE, params->socket_id); } + /* Default hash function */ +#if defined(RTE_ARCH_X86) + default_hash_func = (rte_hash_function)rte_hash_crc; +#elif defined(RTE_ARCH_ARM64) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) + default_hash_func = (rte_hash_function)rte_hash_crc; +#endif /* Setup hash context */ snprintf(h->name, sizeof(h->name), "%s", params->name); h->entries = params->entries; @@ -279,7 +287,7 @@ struct rte_hash * h->bucket_bitmask = h->num_buckets - 1; h->buckets = buckets; h->hash_func = (params->hash_func == NULL) ? - DEFAULT_HASH_FUNC : params->hash_func; + default_hash_func : params->hash_func; h->key_store = k; h->free_slots = r; h->hw_trans_mem_support = hw_trans_mem_support; diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h index f75392d..b4fd9b1 100644 --- a/lib/librte_hash/rte_cuckoo_hash.h +++ b/lib/librte_hash/rte_cuckoo_hash.h @@ -57,14 +57,8 @@ #define RETURN_IF_TRUE(cond, retval) #endif -/* Hash function used if none is specified */ -#if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32) #include -#define DEFAULT_HASH_FUNC rte_hash_crc -#else #include -#define DEFAULT_HASH_FUNC rte_jhash -#endif #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64) /* -- 1.9.1