From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B8BB8A04B5; Wed, 30 Sep 2020 15:14:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 321F21DBA3; Wed, 30 Sep 2020 15:08:48 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 700251DB69 for ; Wed, 30 Sep 2020 15:08:31 +0200 (CEST) IronPort-SDR: FV+b+4P7kMAuRCOiVVKgUFcw1+WSZogbbXOeRQJmkh0af7lDTioAra7QBjh4mVDQnRH++BK7we CxocF9TM+Mjg== X-IronPort-AV: E=McAfee;i="6000,8403,9759"; a="150223515" X-IronPort-AV: E=Sophos;i="5.77,322,1596524400"; d="scan'208";a="150223515" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2020 06:08:30 -0700 IronPort-SDR: GUzG9J+IIRnW/o3gdcIxhUIFJBYvgysAv/oJSiBiQaTNYyC/tO4ejejVoxTaAmdsVCfx2K2hED AxDIjaY6zCCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,322,1596524400"; d="scan'208";a="294603292" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by fmsmga008.fm.intel.com with ESMTP; 30 Sep 2020 06:08:29 -0700 From: Ciara Power To: dev@dpdk.org Cc: Ciara Power , Bruce Richardson , Vladimir Medvedkin , Jerin Jacob , Ruifeng Wang Date: Wed, 30 Sep 2020 14:04:14 +0100 Message-Id: <20200930130415.11211-19-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200930130415.11211-1-ciara.power@intel.com> References: <20200807155859.63888-1-ciara.power@intel.com> <20200930130415.11211-1-ciara.power@intel.com> Subject: [dpdk-dev] [PATCH v3 18/18] lpm: choose vector path at runtime 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" When choosing the vector path, max SIMD bitwidth is now checked to ensure a vector path is allowable. To do this, rather than the vector lookup functions being called directly from apps, a generic lookup function is called which will call the vector functions if suitable. Signed-off-by: Ciara Power --- lib/librte_lpm/rte_lpm.h | 57 ++++++++++++++++++++++++++------ lib/librte_lpm/rte_lpm_altivec.h | 2 +- lib/librte_lpm/rte_lpm_neon.h | 2 +- lib/librte_lpm/rte_lpm_sse.h | 2 +- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h index 03da2d37e0..edba7cafd5 100644 --- a/lib/librte_lpm/rte_lpm.h +++ b/lib/librte_lpm/rte_lpm.h @@ -397,8 +397,18 @@ rte_lpm_lookup_bulk_func(const struct rte_lpm *lpm, const uint32_t *ips, /* Mask four results. */ #define RTE_LPM_MASKX4_RES UINT64_C(0x00ffffff00ffffff) +#if defined(RTE_ARCH_ARM) || defined(RTE_ARCH_ARM64) +#include "rte_lpm_neon.h" +#elif defined(RTE_ARCH_PPC_64) +#include "rte_lpm_altivec.h" +#else +#include "rte_lpm_sse.h" +#endif + /** - * Lookup four IP addresses in an LPM table. + * Lookup four IP addresses in an LPM table individually by calling the + * lookup function for each ip. This is used when lookupx4 is called but + * the vector path is not suitable. * * @param lpm * LPM object handle @@ -417,16 +427,43 @@ rte_lpm_lookup_bulk_func(const struct rte_lpm *lpm, const uint32_t *ips, * if lookup would fail. */ static inline void -rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], - uint32_t defv); +rte_lpm_lookupx4_scalar(struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], + uint32_t defv) +{ + int i; + for (i = 0; i < 4; i++) + if (rte_lpm_lookup(lpm, ((uint32_t *) &ip)[i], &hop[i]) < 0) + hop[i] = defv; /* lookupx4 expected to set on failure */ +} -#if defined(RTE_ARCH_ARM) || defined(RTE_ARCH_ARM64) -#include "rte_lpm_neon.h" -#elif defined(RTE_ARCH_PPC_64) -#include "rte_lpm_altivec.h" -#else -#include "rte_lpm_sse.h" -#endif +/** + * Lookup four IP addresses in an LPM table. + * + * @param lpm + * LPM object handle + * @param ip + * Four IPs to be looked up in the LPM table + * @param hop + * Next hop of the most specific rule found for IP (valid on lookup hit only). + * This is an 4 elements array of two byte values. + * If the lookup was successful for the given IP, then least significant byte + * of the corresponding element is the actual next hop and the most + * significant byte is zero. + * If the lookup for the given IP failed, then corresponding element would + * contain default value, see description of then next parameter. + * @param defv + * Default value to populate into corresponding element of hop[] array, + * if lookup would fail. + */ +static inline void +rte_lpm_lookupx4(struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], + uint32_t defv) +{ + if (rte_get_max_simd_bitwidth() >= RTE_MAX_128_SIMD) + rte_lpm_lookupx4_vec(lpm, ip, hop, defv); + else + rte_lpm_lookupx4_scalar(lpm, ip, hop, defv); +} #ifdef __cplusplus } diff --git a/lib/librte_lpm/rte_lpm_altivec.h b/lib/librte_lpm/rte_lpm_altivec.h index 228c41b38e..82142d3351 100644 --- a/lib/librte_lpm/rte_lpm_altivec.h +++ b/lib/librte_lpm/rte_lpm_altivec.h @@ -16,7 +16,7 @@ extern "C" { #endif static inline void -rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], +rte_lpm_lookupx4_vec(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv) { vector signed int i24; diff --git a/lib/librte_lpm/rte_lpm_neon.h b/lib/librte_lpm/rte_lpm_neon.h index 6c131d3125..14b184515d 100644 --- a/lib/librte_lpm/rte_lpm_neon.h +++ b/lib/librte_lpm/rte_lpm_neon.h @@ -16,7 +16,7 @@ extern "C" { #endif static inline void -rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], +rte_lpm_lookupx4_vec(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv) { uint32x4_t i24; diff --git a/lib/librte_lpm/rte_lpm_sse.h b/lib/librte_lpm/rte_lpm_sse.h index 44770b6ff8..cb5477c6cf 100644 --- a/lib/librte_lpm/rte_lpm_sse.h +++ b/lib/librte_lpm/rte_lpm_sse.h @@ -15,7 +15,7 @@ extern "C" { #endif static inline void -rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], +rte_lpm_lookupx4_vec(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv) { __m128i i24; -- 2.17.1