From patchwork Tue Sep 26 07:41:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xiaoyun" X-Patchwork-Id: 29188 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9A2CA1B1C5; Tue, 26 Sep 2017 09:44:24 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 717461B1C4 for ; Tue, 26 Sep 2017 09:44:23 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2017 00:44:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,440,1500966000"; d="scan'208";a="153375672" Received: from dpdk-lixiaoyun.sh.intel.com ([10.67.111.93]) by orsmga005.jf.intel.com with ESMTP; 26 Sep 2017 00:43:29 -0700 From: Xiaoyun Li To: bruce.richardson@intel.com, konstantin.ananyev@intel.com Cc: wenzhuo.lu@intel.com, helin.zhang@intel.com, dev@dpdk.org, Xiaoyun Li Date: Tue, 26 Sep 2017 15:41:29 +0800 Message-Id: <1506411689-94690-4-git-send-email-xiaoyun.li@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506411689-94690-1-git-send-email-xiaoyun.li@intel.com> References: <1506411689-94690-1-git-send-email-xiaoyun.li@intel.com> Subject: [dpdk-dev] [PATCH v3 3/3] efd: run-time dispatch over x86 EFD functions 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch dynamically selects x86 EFD functions at run-time. This patch uses function pointer and binds it to the relative function based on CPU flags at constructor time. Signed-off-by: Xiaoyun Li --- lib/librte_efd/rte_efd_x86.h | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/librte_efd/rte_efd_x86.h b/lib/librte_efd/rte_efd_x86.h index 34f37d7..93b6743 100644 --- a/lib/librte_efd/rte_efd_x86.h +++ b/lib/librte_efd/rte_efd_x86.h @@ -43,12 +43,29 @@ #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val) #endif +typedef efd_value_t +(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t *group_hash_idx, + const efd_lookuptbl_t *group_lookup_table, + const uint32_t hash_val_a, const uint32_t hash_val_b); + +static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr; + static inline efd_value_t efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx, const efd_lookuptbl_t *group_lookup_table, const uint32_t hash_val_a, const uint32_t hash_val_b) { -#ifdef RTE_MACHINE_CPUFLAG_AVX2 + return (*efd_lookup_internal_avx2_ptr)(group_hash_idx, + group_lookup_table, + hash_val_a, hash_val_b); +} + +#ifdef CC_SUPPORT_AVX2 +static inline efd_value_t +efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t *group_hash_idx, + const efd_lookuptbl_t *group_lookup_table, + const uint32_t hash_val_a, const uint32_t hash_val_b) +{ efd_value_t value = 0; uint32_t i = 0; __m256i vhash_val_a = _mm256_set1_epi32(hash_val_a); @@ -74,13 +91,31 @@ efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx, } return value; -#else +} +#endif + +static inline efd_value_t +efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t *group_hash_idx, + const efd_lookuptbl_t *group_lookup_table, + const uint32_t hash_val_a, const uint32_t hash_val_b) +{ RTE_SET_USED(group_hash_idx); RTE_SET_USED(group_lookup_table); RTE_SET_USED(hash_val_a); RTE_SET_USED(hash_val_b); /* Return dummy value, only to avoid compilation breakage */ return 0; -#endif +} +static void __attribute__((constructor)) +rte_efd_x86_init(void) +{ +#ifdef CC_SUPPORT_AVX2 + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2)) + efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_AVX2; + else + efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT; +#else + efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT; +#endif }