From patchwork Tue May 19 12:12:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70429 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A8130A0093; Tue, 19 May 2020 14:13:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3B5E61D603; Tue, 19 May 2020 14:13:11 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 2592A1D17A for ; Tue, 19 May 2020 14:13:08 +0200 (CEST) IronPort-SDR: UDyakGzUoIbeG6blDHe2dGHQgosGGJzZokn+KLpIzKQQvwAfOaxQaQOcfANMFIUw+zDjNKcTuG foZ+xL6HPsXw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:08 -0700 IronPort-SDR: ey3Vb5f01eWyZs/GpQ0XWlgJsoBkizanCV/cwKVgmED8w9t6Q2qmTZt2OhlEuvTtOdWToCQGKL ZwQ5N829xiAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938419" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:07 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:12:56 +0100 Message-Id: <895e07b9a83234251f3a6b6a43dc360ee9b7edc6.1589890262.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 1/8] eal: introduce zmm type for AVX 512-bit 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" New data type to manipulate 512 bit AVX values. Signed-off-by: Vladimir Medvedkin Acked-by: Konstantin Ananyev --- lib/librte_eal/x86/include/rte_vect.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/librte_eal/x86/include/rte_vect.h b/lib/librte_eal/x86/include/rte_vect.h index df5a607..ffe4f7d 100644 --- a/lib/librte_eal/x86/include/rte_vect.h +++ b/lib/librte_eal/x86/include/rte_vect.h @@ -90,6 +90,26 @@ __extension__ ({ \ }) #endif /* (defined(__ICC) && __ICC < 1210) */ +#ifdef __AVX512F__ + +typedef __m512i __x86_zmm_t; + +#define ZMM_SIZE (sizeof(__x86_zmm_t)) +#define ZMM_MASK (ZMM_SIZE - 1) + +typedef union __rte_x86_zmm { + __x86_zmm_t z; + ymm_t y[ZMM_SIZE / sizeof(ymm_t)]; + xmm_t x[ZMM_SIZE / sizeof(xmm_t)]; + uint8_t u8[ZMM_SIZE / sizeof(uint8_t)]; + uint16_t u16[ZMM_SIZE / sizeof(uint16_t)]; + uint32_t u32[ZMM_SIZE / sizeof(uint32_t)]; + uint64_t u64[ZMM_SIZE / sizeof(uint64_t)]; + double pd[ZMM_SIZE / sizeof(double)]; +} __attribute__((__aligned__(ZMM_SIZE))) __rte_x86_zmm_t; + +#endif /* __AVX512F__ */ + #ifdef __cplusplus } #endif From patchwork Tue May 19 12:12:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70430 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 98C47A0093; Tue, 19 May 2020 14:13:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E15031D60D; Tue, 19 May 2020 14:13:12 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id D39EC1D5FB for ; Tue, 19 May 2020 14:13:09 +0200 (CEST) IronPort-SDR: vU68R6JJV/4kb47v+YOaBnpUbOPX7SPdK6YbiK0gq7RE2F5wH15CtUk7mkwc3YcbeS1z1e5xEJ 4dC0VolgcmQw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:09 -0700 IronPort-SDR: OT47df6YXiULlEwdZpB3bC3SrQrfQjmJlGu0UO6JSjNh3xUdR5FhGqo95qmxhqlBfRznbjGnQt 1CSjpF6jOKOQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938422" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:08 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:12:57 +0100 Message-Id: <87d7acac82dfae763a998c3004f79417b3b3fced.1589890262.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 2/8] fib: make lookup function type configurable 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" Add type argument to dir24_8_get_lookup_fn() Now it supports 3 different lookup implementations: RTE_FIB_DIR24_8_SCALAR_MACRO RTE_FIB_DIR24_8_SCALAR_INLINE RTE_FIB_DIR24_8_SCALAR_UNI Add new rte_fib_set_lookup_fn() - user can change lookup function type runtime. Signed-off-by: Vladimir Medvedkin --- lib/librte_fib/dir24_8.c | 32 ++++++++++++++++++++------------ lib/librte_fib/dir24_8.h | 2 +- lib/librte_fib/rte_fib.c | 20 +++++++++++++++++++- lib/librte_fib/rte_fib.h | 22 ++++++++++++++++++++++ lib/librte_fib/rte_fib_version.map | 1 + 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/lib/librte_fib/dir24_8.c b/lib/librte_fib/dir24_8.c index c9dce3c..825d061 100644 --- a/lib/librte_fib/dir24_8.c +++ b/lib/librte_fib/dir24_8.c @@ -45,13 +45,6 @@ struct dir24_8_tbl { #define ROUNDUP(x, y) RTE_ALIGN_CEIL(x, (1 << (32 - y))) -enum lookup_type { - MACRO, - INLINE, - UNI -}; -enum lookup_type test_lookup = MACRO; - static inline void * get_tbl24_p(struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz) { @@ -253,11 +246,18 @@ dir24_8_lookup_bulk_uni(void *p, const uint32_t *ips, } rte_fib_lookup_fn_t -dir24_8_get_lookup_fn(struct rte_fib_conf *fib_conf) +dir24_8_get_lookup_fn(void *p, enum rte_fib_dir24_8_lookup_type type) { - enum rte_fib_dir24_8_nh_sz nh_sz = fib_conf->dir24_8.nh_sz; + enum rte_fib_dir24_8_nh_sz nh_sz; + struct dir24_8_tbl *dp = p; - if (test_lookup == MACRO) { + if (dp == NULL) + return NULL; + + nh_sz = dp->nh_sz; + + switch (type) { + case RTE_FIB_DIR24_8_SCALAR_MACRO: switch (nh_sz) { case RTE_FIB_DIR24_8_1B: return dir24_8_lookup_bulk_1b; @@ -267,8 +267,10 @@ dir24_8_get_lookup_fn(struct rte_fib_conf *fib_conf) return dir24_8_lookup_bulk_4b; case RTE_FIB_DIR24_8_8B: return dir24_8_lookup_bulk_8b; + default: + return NULL; } - } else if (test_lookup == INLINE) { + case RTE_FIB_DIR24_8_SCALAR_INLINE: switch (nh_sz) { case RTE_FIB_DIR24_8_1B: return dir24_8_lookup_bulk_0; @@ -278,9 +280,15 @@ dir24_8_get_lookup_fn(struct rte_fib_conf *fib_conf) return dir24_8_lookup_bulk_2; case RTE_FIB_DIR24_8_8B: return dir24_8_lookup_bulk_3; + default: + return NULL; } - } else + case RTE_FIB_DIR24_8_SCALAR_UNI: return dir24_8_lookup_bulk_uni; + default: + return NULL; + } + return NULL; } diff --git a/lib/librte_fib/dir24_8.h b/lib/librte_fib/dir24_8.h index 1ec437c..53c5dd2 100644 --- a/lib/librte_fib/dir24_8.h +++ b/lib/librte_fib/dir24_8.h @@ -22,7 +22,7 @@ void dir24_8_free(void *p); rte_fib_lookup_fn_t -dir24_8_get_lookup_fn(struct rte_fib_conf *conf); +dir24_8_get_lookup_fn(void *p, enum rte_fib_dir24_8_lookup_type type); int dir24_8_modify(struct rte_fib *fib, uint32_t ip, uint8_t depth, diff --git a/lib/librte_fib/rte_fib.c b/lib/librte_fib/rte_fib.c index e090808..59120b5 100644 --- a/lib/librte_fib/rte_fib.c +++ b/lib/librte_fib/rte_fib.c @@ -107,7 +107,8 @@ init_dataplane(struct rte_fib *fib, __rte_unused int socket_id, fib->dp = dir24_8_create(dp_name, socket_id, conf); if (fib->dp == NULL) return -rte_errno; - fib->lookup = dir24_8_get_lookup_fn(conf); + fib->lookup = dir24_8_get_lookup_fn(fib->dp, + RTE_FIB_DIR24_8_SCALAR_MACRO); fib->modify = dir24_8_modify; return 0; default: @@ -317,3 +318,20 @@ rte_fib_get_rib(struct rte_fib *fib) { return (fib == NULL) ? NULL : fib->rib; } + +int +rte_fib_set_lookup_fn(struct rte_fib *fib, int type) +{ + rte_fib_lookup_fn_t fn; + + switch (fib->type) { + case RTE_FIB_DIR24_8: + fn = dir24_8_get_lookup_fn(fib->dp, type); + if (fn == NULL) + return -EINVAL; + fib->lookup = fn; + return 0; + default: + return -EINVAL; + } +} diff --git a/lib/librte_fib/rte_fib.h b/lib/librte_fib/rte_fib.h index af3bbf0..db35685 100644 --- a/lib/librte_fib/rte_fib.h +++ b/lib/librte_fib/rte_fib.h @@ -51,6 +51,12 @@ enum rte_fib_dir24_8_nh_sz { RTE_FIB_DIR24_8_8B }; +enum rte_fib_dir24_8_lookup_type { + RTE_FIB_DIR24_8_SCALAR_MACRO, + RTE_FIB_DIR24_8_SCALAR_INLINE, + RTE_FIB_DIR24_8_SCALAR_UNI +}; + /** FIB configuration structure */ struct rte_fib_conf { enum rte_fib_type type; /**< Type of FIB struct */ @@ -189,6 +195,22 @@ __rte_experimental struct rte_rib * rte_fib_get_rib(struct rte_fib *fib); +/** + * Set lookup function based on type + * + * @param fib + * FIB object handle + * @param type + * type of lookup function + * + * @return + * -EINVAL on failure + * 0 on success + */ +__rte_experimental +int +rte_fib_set_lookup_fn(struct rte_fib *fib, int type); + #ifdef __cplusplus } #endif diff --git a/lib/librte_fib/rte_fib_version.map b/lib/librte_fib/rte_fib_version.map index 9527417..216af66 100644 --- a/lib/librte_fib/rte_fib_version.map +++ b/lib/librte_fib/rte_fib_version.map @@ -9,6 +9,7 @@ EXPERIMENTAL { rte_fib_lookup_bulk; rte_fib_get_dp; rte_fib_get_rib; + rte_fib_set_lookup_fn; rte_fib6_add; rte_fib6_create; From patchwork Tue May 19 12:12:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70431 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 18D17A0093; Tue, 19 May 2020 14:13:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5BBCC1D616; Tue, 19 May 2020 14:13:15 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 88A6C1D608 for ; Tue, 19 May 2020 14:13:11 +0200 (CEST) IronPort-SDR: o9RuQM/b/eBDVUHkn0NESpcc9dT7NJGTEAqSj3DFlRXAh+UmgNTZSB8is6wsuf+O5dGCIQBmHC vNk0FKiOM7eg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:10 -0700 IronPort-SDR: wMUij0QCEiiY7UdyB7khNSO61ikWKVX/qRp+BPpR0CdX3ebUYzh6wfT72IU23/F/RdOLUT5MMX Hb+0B3uAiMcw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938425" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:09 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:12:58 +0100 Message-Id: <4095cebec2712a48ac7dd967b143114fe21d33de.1589890262.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/8] fib: move lookup definition into the header file 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" Move dir24_8 table layout and lookup defenition into the private header file. This is necessary for implementing a vectorized lookup function in a separate .с file. Signed-off-by: Vladimir Medvedkin Acked-by: Konstantin Ananyev --- lib/librte_fib/dir24_8.c | 225 +---------------------------------------------- lib/librte_fib/dir24_8.h | 224 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+), 224 deletions(-) diff --git a/lib/librte_fib/dir24_8.c b/lib/librte_fib/dir24_8.c index 825d061..9d74653 100644 --- a/lib/librte_fib/dir24_8.c +++ b/lib/librte_fib/dir24_8.c @@ -11,240 +11,17 @@ #include #include -#include #include #include -#include -#include #include +#include #include "dir24_8.h" #define DIR24_8_NAMESIZE 64 -#define DIR24_8_TBL24_NUM_ENT (1 << 24) -#define DIR24_8_TBL8_GRP_NUM_ENT 256U -#define DIR24_8_EXT_ENT 1 -#define DIR24_8_TBL24_MASK 0xffffff00 - -#define BITMAP_SLAB_BIT_SIZE_LOG2 6 -#define BITMAP_SLAB_BIT_SIZE (1 << BITMAP_SLAB_BIT_SIZE_LOG2) -#define BITMAP_SLAB_BITMASK (BITMAP_SLAB_BIT_SIZE - 1) - -struct dir24_8_tbl { - uint32_t number_tbl8s; /**< Total number of tbl8s */ - uint32_t rsvd_tbl8s; /**< Number of reserved tbl8s */ - uint32_t cur_tbl8s; /**< Current number of tbl8s */ - enum rte_fib_dir24_8_nh_sz nh_sz; /**< Size of nexthop entry */ - uint64_t def_nh; /**< Default next hop */ - uint64_t *tbl8; /**< tbl8 table. */ - uint64_t *tbl8_idxes; /**< bitmap containing free tbl8 idxes*/ - /* tbl24 table. */ - __extension__ uint64_t tbl24[0] __rte_cache_aligned; -}; - #define ROUNDUP(x, y) RTE_ALIGN_CEIL(x, (1 << (32 - y))) -static inline void * -get_tbl24_p(struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz) -{ - return (void *)&((uint8_t *)dp->tbl24)[(ip & - DIR24_8_TBL24_MASK) >> (8 - nh_sz)]; -} - -static inline uint8_t -bits_in_nh(uint8_t nh_sz) -{ - return 8 * (1 << nh_sz); -} - -static inline uint64_t -get_max_nh(uint8_t nh_sz) -{ - return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1); -} - -static inline uint32_t -get_tbl24_idx(uint32_t ip) -{ - return ip >> 8; -} - -static inline uint32_t -get_tbl8_idx(uint32_t res, uint32_t ip) -{ - return (res >> 1) * DIR24_8_TBL8_GRP_NUM_ENT + (uint8_t)ip; -} - -static inline uint64_t -lookup_msk(uint8_t nh_sz) -{ - return ((1ULL << ((1 << (nh_sz + 3)) - 1)) << 1) - 1; -} - -static inline uint8_t -get_psd_idx(uint32_t val, uint8_t nh_sz) -{ - return val & ((1 << (3 - nh_sz)) - 1); -} - -static inline uint32_t -get_tbl_idx(uint32_t val, uint8_t nh_sz) -{ - return val >> (3 - nh_sz); -} - -static inline uint64_t -get_tbl24(struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz) -{ - return ((dp->tbl24[get_tbl_idx(get_tbl24_idx(ip), nh_sz)] >> - (get_psd_idx(get_tbl24_idx(ip), nh_sz) * - bits_in_nh(nh_sz))) & lookup_msk(nh_sz)); -} - -static inline uint64_t -get_tbl8(struct dir24_8_tbl *dp, uint32_t res, uint32_t ip, uint8_t nh_sz) -{ - return ((dp->tbl8[get_tbl_idx(get_tbl8_idx(res, ip), nh_sz)] >> - (get_psd_idx(get_tbl8_idx(res, ip), nh_sz) * - bits_in_nh(nh_sz))) & lookup_msk(nh_sz)); -} - -static inline int -is_entry_extended(uint64_t ent) -{ - return (ent & DIR24_8_EXT_ENT) == DIR24_8_EXT_ENT; -} - -#define LOOKUP_FUNC(suffix, type, bulk_prefetch, nh_sz) \ -static void dir24_8_lookup_bulk_##suffix(void *p, const uint32_t *ips, \ - uint64_t *next_hops, const unsigned int n) \ -{ \ - struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; \ - uint64_t tmp; \ - uint32_t i; \ - uint32_t prefetch_offset = \ - RTE_MIN((unsigned int)bulk_prefetch, n); \ - \ - for (i = 0; i < prefetch_offset; i++) \ - rte_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); \ - for (i = 0; i < (n - prefetch_offset); i++) { \ - rte_prefetch0(get_tbl24_p(dp, \ - ips[i + prefetch_offset], nh_sz)); \ - tmp = ((type *)dp->tbl24)[ips[i] >> 8]; \ - if (unlikely(is_entry_extended(tmp))) \ - tmp = ((type *)dp->tbl8)[(uint8_t)ips[i] + \ - ((tmp >> 1) * DIR24_8_TBL8_GRP_NUM_ENT)]; \ - next_hops[i] = tmp >> 1; \ - } \ - for (; i < n; i++) { \ - tmp = ((type *)dp->tbl24)[ips[i] >> 8]; \ - if (unlikely(is_entry_extended(tmp))) \ - tmp = ((type *)dp->tbl8)[(uint8_t)ips[i] + \ - ((tmp >> 1) * DIR24_8_TBL8_GRP_NUM_ENT)]; \ - next_hops[i] = tmp >> 1; \ - } \ -} \ - -LOOKUP_FUNC(1b, uint8_t, 5, 0) -LOOKUP_FUNC(2b, uint16_t, 6, 1) -LOOKUP_FUNC(4b, uint32_t, 15, 2) -LOOKUP_FUNC(8b, uint64_t, 12, 3) - -static inline void -dir24_8_lookup_bulk(struct dir24_8_tbl *dp, const uint32_t *ips, - uint64_t *next_hops, const unsigned int n, uint8_t nh_sz) -{ - uint64_t tmp; - uint32_t i; - uint32_t prefetch_offset = RTE_MIN(15U, n); - - for (i = 0; i < prefetch_offset; i++) - rte_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); - for (i = 0; i < (n - prefetch_offset); i++) { - rte_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], - nh_sz)); - tmp = get_tbl24(dp, ips[i], nh_sz); - if (unlikely(is_entry_extended(tmp))) - tmp = get_tbl8(dp, tmp, ips[i], nh_sz); - - next_hops[i] = tmp >> 1; - } - for (; i < n; i++) { - tmp = get_tbl24(dp, ips[i], nh_sz); - if (unlikely(is_entry_extended(tmp))) - tmp = get_tbl8(dp, tmp, ips[i], nh_sz); - - next_hops[i] = tmp >> 1; - } -} - -static void -dir24_8_lookup_bulk_0(void *p, const uint32_t *ips, - uint64_t *next_hops, const unsigned int n) -{ - struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; - - dir24_8_lookup_bulk(dp, ips, next_hops, n, 0); -} - -static void -dir24_8_lookup_bulk_1(void *p, const uint32_t *ips, - uint64_t *next_hops, const unsigned int n) -{ - struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; - - dir24_8_lookup_bulk(dp, ips, next_hops, n, 1); -} - -static void -dir24_8_lookup_bulk_2(void *p, const uint32_t *ips, - uint64_t *next_hops, const unsigned int n) -{ - struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; - - dir24_8_lookup_bulk(dp, ips, next_hops, n, 2); -} - -static void -dir24_8_lookup_bulk_3(void *p, const uint32_t *ips, - uint64_t *next_hops, const unsigned int n) -{ - struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; - - dir24_8_lookup_bulk(dp, ips, next_hops, n, 3); -} - -static void -dir24_8_lookup_bulk_uni(void *p, const uint32_t *ips, - uint64_t *next_hops, const unsigned int n) -{ - struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; - uint64_t tmp; - uint32_t i; - uint32_t prefetch_offset = RTE_MIN(15U, n); - uint8_t nh_sz = dp->nh_sz; - - for (i = 0; i < prefetch_offset; i++) - rte_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); - for (i = 0; i < (n - prefetch_offset); i++) { - rte_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], - nh_sz)); - tmp = get_tbl24(dp, ips[i], nh_sz); - if (unlikely(is_entry_extended(tmp))) - tmp = get_tbl8(dp, tmp, ips[i], nh_sz); - - next_hops[i] = tmp >> 1; - } - for (; i < n; i++) { - tmp = get_tbl24(dp, ips[i], nh_sz); - if (unlikely(is_entry_extended(tmp))) - tmp = get_tbl8(dp, tmp, ips[i], nh_sz); - - next_hops[i] = tmp >> 1; - } -} - rte_fib_lookup_fn_t dir24_8_get_lookup_fn(void *p, enum rte_fib_dir24_8_lookup_type type) { diff --git a/lib/librte_fib/dir24_8.h b/lib/librte_fib/dir24_8.h index 53c5dd2..56d0389 100644 --- a/lib/librte_fib/dir24_8.h +++ b/lib/librte_fib/dir24_8.h @@ -6,6 +6,9 @@ #ifndef _DIR24_8_H_ #define _DIR24_8_H_ +#include +#include + /** * @file * DIR24_8 algorithm @@ -15,6 +18,227 @@ extern "C" { #endif +#define DIR24_8_TBL24_NUM_ENT (1 << 24) +#define DIR24_8_TBL8_GRP_NUM_ENT 256U +#define DIR24_8_EXT_ENT 1 +#define DIR24_8_TBL24_MASK 0xffffff00 + +#define BITMAP_SLAB_BIT_SIZE_LOG2 6 +#define BITMAP_SLAB_BIT_SIZE (1 << BITMAP_SLAB_BIT_SIZE_LOG2) +#define BITMAP_SLAB_BITMASK (BITMAP_SLAB_BIT_SIZE - 1) + +struct dir24_8_tbl { + uint32_t number_tbl8s; /**< Total number of tbl8s */ + uint32_t rsvd_tbl8s; /**< Number of reserved tbl8s */ + uint32_t cur_tbl8s; /**< Current number of tbl8s */ + enum rte_fib_dir24_8_nh_sz nh_sz; /**< Size of nexthop entry */ + uint64_t def_nh; /**< Default next hop */ + uint64_t *tbl8; /**< tbl8 table. */ + uint64_t *tbl8_idxes; /**< bitmap containing free tbl8 idxes*/ + /* tbl24 table. */ + __extension__ uint64_t tbl24[0] __rte_cache_aligned; +}; + +static inline void * +get_tbl24_p(struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz) +{ + return (void *)&((uint8_t *)dp->tbl24)[(ip & + DIR24_8_TBL24_MASK) >> (8 - nh_sz)]; +} + +static inline uint8_t +bits_in_nh(uint8_t nh_sz) +{ + return 8 * (1 << nh_sz); +} + +static inline uint64_t +get_max_nh(uint8_t nh_sz) +{ + return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1); +} + +static inline uint32_t +get_tbl24_idx(uint32_t ip) +{ + return ip >> 8; +} + +static inline uint32_t +get_tbl8_idx(uint32_t res, uint32_t ip) +{ + return (res >> 1) * DIR24_8_TBL8_GRP_NUM_ENT + (uint8_t)ip; +} + +static inline uint64_t +lookup_msk(uint8_t nh_sz) +{ + return ((1ULL << ((1 << (nh_sz + 3)) - 1)) << 1) - 1; +} + +static inline uint8_t +get_psd_idx(uint32_t val, uint8_t nh_sz) +{ + return val & ((1 << (3 - nh_sz)) - 1); +} + +static inline uint32_t +get_tbl_idx(uint32_t val, uint8_t nh_sz) +{ + return val >> (3 - nh_sz); +} + +static inline uint64_t +get_tbl24(struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz) +{ + return ((dp->tbl24[get_tbl_idx(get_tbl24_idx(ip), nh_sz)] >> + (get_psd_idx(get_tbl24_idx(ip), nh_sz) * + bits_in_nh(nh_sz))) & lookup_msk(nh_sz)); +} + +static inline uint64_t +get_tbl8(struct dir24_8_tbl *dp, uint32_t res, uint32_t ip, uint8_t nh_sz) +{ + return ((dp->tbl8[get_tbl_idx(get_tbl8_idx(res, ip), nh_sz)] >> + (get_psd_idx(get_tbl8_idx(res, ip), nh_sz) * + bits_in_nh(nh_sz))) & lookup_msk(nh_sz)); +} + +static inline int +is_entry_extended(uint64_t ent) +{ + return (ent & DIR24_8_EXT_ENT) == DIR24_8_EXT_ENT; +} + +#define LOOKUP_FUNC(suffix, type, bulk_prefetch, nh_sz) \ +static inline void dir24_8_lookup_bulk_##suffix(void *p, const uint32_t *ips, \ + uint64_t *next_hops, const unsigned int n) \ +{ \ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; \ + uint64_t tmp; \ + uint32_t i; \ + uint32_t prefetch_offset = \ + RTE_MIN((unsigned int)bulk_prefetch, n); \ + \ + for (i = 0; i < prefetch_offset; i++) \ + rte_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); \ + for (i = 0; i < (n - prefetch_offset); i++) { \ + rte_prefetch0(get_tbl24_p(dp, \ + ips[i + prefetch_offset], nh_sz)); \ + tmp = ((type *)dp->tbl24)[ips[i] >> 8]; \ + if (unlikely(is_entry_extended(tmp))) \ + tmp = ((type *)dp->tbl8)[(uint8_t)ips[i] + \ + ((tmp >> 1) * DIR24_8_TBL8_GRP_NUM_ENT)]; \ + next_hops[i] = tmp >> 1; \ + } \ + for (; i < n; i++) { \ + tmp = ((type *)dp->tbl24)[ips[i] >> 8]; \ + if (unlikely(is_entry_extended(tmp))) \ + tmp = ((type *)dp->tbl8)[(uint8_t)ips[i] + \ + ((tmp >> 1) * DIR24_8_TBL8_GRP_NUM_ENT)]; \ + next_hops[i] = tmp >> 1; \ + } \ +} \ + +LOOKUP_FUNC(1b, uint8_t, 5, 0) +LOOKUP_FUNC(2b, uint16_t, 6, 1) +LOOKUP_FUNC(4b, uint32_t, 15, 2) +LOOKUP_FUNC(8b, uint64_t, 12, 3) + +static inline void +dir24_8_lookup_bulk(struct dir24_8_tbl *dp, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n, uint8_t nh_sz) +{ + uint64_t tmp; + uint32_t i; + uint32_t prefetch_offset = RTE_MIN(15U, n); + + for (i = 0; i < prefetch_offset; i++) + rte_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); + for (i = 0; i < (n - prefetch_offset); i++) { + rte_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], + nh_sz)); + tmp = get_tbl24(dp, ips[i], nh_sz); + if (unlikely(is_entry_extended(tmp))) + tmp = get_tbl8(dp, tmp, ips[i], nh_sz); + + next_hops[i] = tmp >> 1; + } + for (; i < n; i++) { + tmp = get_tbl24(dp, ips[i], nh_sz); + if (unlikely(is_entry_extended(tmp))) + tmp = get_tbl8(dp, tmp, ips[i], nh_sz); + + next_hops[i] = tmp >> 1; + } +} + +static inline void +dir24_8_lookup_bulk_0(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + + dir24_8_lookup_bulk(dp, ips, next_hops, n, 0); +} + +static inline void +dir24_8_lookup_bulk_1(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + + dir24_8_lookup_bulk(dp, ips, next_hops, n, 1); +} + +static inline void +dir24_8_lookup_bulk_2(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + + dir24_8_lookup_bulk(dp, ips, next_hops, n, 2); +} + +static inline void +dir24_8_lookup_bulk_3(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + + dir24_8_lookup_bulk(dp, ips, next_hops, n, 3); +} + +static inline void +dir24_8_lookup_bulk_uni(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + uint64_t tmp; + uint32_t i; + uint32_t prefetch_offset = RTE_MIN(15U, n); + uint8_t nh_sz = dp->nh_sz; + + for (i = 0; i < prefetch_offset; i++) + rte_prefetch0(get_tbl24_p(dp, ips[i], nh_sz)); + for (i = 0; i < (n - prefetch_offset); i++) { + rte_prefetch0(get_tbl24_p(dp, ips[i + prefetch_offset], + nh_sz)); + tmp = get_tbl24(dp, ips[i], nh_sz); + if (unlikely(is_entry_extended(tmp))) + tmp = get_tbl8(dp, tmp, ips[i], nh_sz); + + next_hops[i] = tmp >> 1; + } + for (; i < n; i++) { + tmp = get_tbl24(dp, ips[i], nh_sz); + if (unlikely(is_entry_extended(tmp))) + tmp = get_tbl8(dp, tmp, ips[i], nh_sz); + + next_hops[i] = tmp >> 1; + } +} + void * dir24_8_create(const char *name, int socket_id, struct rte_fib_conf *conf); From patchwork Tue May 19 12:12:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70432 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E91CAA0093; Tue, 19 May 2020 14:13:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0B8131D61F; Tue, 19 May 2020 14:13:17 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 8FDBF1D60B for ; Tue, 19 May 2020 14:13:12 +0200 (CEST) IronPort-SDR: nA9mjvs34Z4K/3g3Elicgw53614MU+CR/2d6vVsll5mHEUbQM7okwQkfs91f0cB16qLDvVuRpq 8FLtIDrKlMNg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:12 -0700 IronPort-SDR: V8FZRphNpeTcAc2Ofq37qEhFnKu0lNsZ0ZoDbxqc1xG/g0VHELm8OpQrlPyEfidoZmmNQMBB5X BylHsi2VlsYw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938429" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:10 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:12:59 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 4/8] fib: introduce AVX512 lookup 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" Add new lookup implementation for DIR24_8 algorithm using AVX512 instruction set Signed-off-by: Vladimir Medvedkin Acked-by: Konstantin Ananyev --- lib/librte_fib/Makefile | 14 ++++ lib/librte_fib/dir24_8.c | 24 ++++++ lib/librte_fib/dir24_8_avx512.c | 165 ++++++++++++++++++++++++++++++++++++++++ lib/librte_fib/dir24_8_avx512.h | 24 ++++++ lib/librte_fib/meson.build | 11 +++ lib/librte_fib/rte_fib.h | 3 +- 6 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 lib/librte_fib/dir24_8_avx512.c create mode 100644 lib/librte_fib/dir24_8_avx512.h diff --git a/lib/librte_fib/Makefile b/lib/librte_fib/Makefile index 1dd2a49..3958da1 100644 --- a/lib/librte_fib/Makefile +++ b/lib/librte_fib/Makefile @@ -19,4 +19,18 @@ SRCS-$(CONFIG_RTE_LIBRTE_FIB) := rte_fib.c rte_fib6.c dir24_8.c trie.c # install this header file SYMLINK-$(CONFIG_RTE_LIBRTE_FIB)-include := rte_fib.h rte_fib6.h +CC_AVX512F_SUPPORT=$(shell $(CC) -mavx512f -dM -E - &1 | \ +grep -q __AVX512F__ && echo 1) + +CC_AVX512DQ_SUPPORT=$(shell $(CC) -mavx512dq -dM -E - &1 | \ +grep -q __AVX512DQ__ && echo 1) + +ifeq ($(CC_AVX512F_SUPPORT), 1) + ifeq ($(CC_AVX512DQ_SUPPORT), 1) + SRCS-$(CONFIG_RTE_LIBRTE_FIB) += dir24_8_avx512.c + CFLAGS_dir24_8_avx512.o += -mavx512f + CFLAGS_dir24_8_avx512.o += -mavx512dq + CFLAGS_dir24_8.o += -DCC_DIR24_8_AVX512_SUPPORT + endif +endif include $(RTE_SDK)/mk/rte.lib.mk diff --git a/lib/librte_fib/dir24_8.c b/lib/librte_fib/dir24_8.c index 9d74653..0a1c53f 100644 --- a/lib/librte_fib/dir24_8.c +++ b/lib/librte_fib/dir24_8.c @@ -18,6 +18,12 @@ #include #include "dir24_8.h" +#ifdef CC_DIR24_8_AVX512_SUPPORT + +#include "dir24_8_avx512.h" + +#endif /* CC_DIR24_8_AVX512_SUPPORT */ + #define DIR24_8_NAMESIZE 64 #define ROUNDUP(x, y) RTE_ALIGN_CEIL(x, (1 << (32 - y))) @@ -62,6 +68,24 @@ dir24_8_get_lookup_fn(void *p, enum rte_fib_dir24_8_lookup_type type) } case RTE_FIB_DIR24_8_SCALAR_UNI: return dir24_8_lookup_bulk_uni; +#ifdef CC_DIR24_8_AVX512_SUPPORT + case RTE_FIB_DIR24_8_VECTOR: + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) <= 0) + return NULL; + + switch (nh_sz) { + case RTE_FIB_DIR24_8_1B: + return rte_dir24_8_vec_lookup_bulk_1b; + case RTE_FIB_DIR24_8_2B: + return rte_dir24_8_vec_lookup_bulk_2b; + case RTE_FIB_DIR24_8_4B: + return rte_dir24_8_vec_lookup_bulk_4b; + case RTE_FIB_DIR24_8_8B: + return rte_dir24_8_vec_lookup_bulk_8b; + default: + return NULL; + } +#endif default: return NULL; } diff --git a/lib/librte_fib/dir24_8_avx512.c b/lib/librte_fib/dir24_8_avx512.c new file mode 100644 index 0000000..43dba28 --- /dev/null +++ b/lib/librte_fib/dir24_8_avx512.c @@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ + +#include +#include + +#include "dir24_8.h" +#include "dir24_8_avx512.h" + +static __rte_always_inline void +dir24_8_vec_lookup_x16(void *p, const uint32_t *ips, + uint64_t *next_hops, int size) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + __mmask16 msk_ext; + __mmask16 exp_msk = 0x5555; + __m512i ip_vec, idxes, res, bytes; + const __m512i zero = _mm512_set1_epi32(0); + const __m512i lsb = _mm512_set1_epi32(1); + const __m512i lsbyte_msk = _mm512_set1_epi32(0xff); + __m512i tmp1, tmp2, res_msk; + __m256i tmp256; + /* used to mask gather values if size is 1/2 (8/16 bit next hops) */ + if (size == sizeof(uint8_t)) + res_msk = _mm512_set1_epi32(UINT8_MAX); + else if (size == sizeof(uint16_t)) + res_msk = _mm512_set1_epi32(UINT16_MAX); + + ip_vec = _mm512_loadu_si512(ips); + /* mask 24 most significant bits */ + idxes = _mm512_srli_epi32(ip_vec, 8); + + /** + * lookup in tbl24 + * Put it inside branch to make compiler happy with -O0 + */ + if (size == sizeof(uint8_t)) { + res = _mm512_i32gather_epi32(idxes, (const int *)dp->tbl24, 1); + res = _mm512_and_epi32(res, res_msk); + } else if (size == sizeof(uint16_t)) { + res = _mm512_i32gather_epi32(idxes, (const int *)dp->tbl24, 2); + res = _mm512_and_epi32(res, res_msk); + } else + res = _mm512_i32gather_epi32(idxes, (const int *)dp->tbl24, 4); + + /* get extended entries indexes */ + msk_ext = _mm512_test_epi32_mask(res, lsb); + + if (msk_ext != 0) { + idxes = _mm512_srli_epi32(res, 1); + idxes = _mm512_slli_epi32(idxes, 8); + bytes = _mm512_and_epi32(ip_vec, lsbyte_msk); + idxes = _mm512_maskz_add_epi32(msk_ext, idxes, bytes); + if (size == sizeof(uint8_t)) { + idxes = _mm512_mask_i32gather_epi32(zero, msk_ext, + idxes, (const int *)dp->tbl8, 1); + idxes = _mm512_and_epi32(idxes, res_msk); + } else if (size == sizeof(uint16_t)) { + idxes = _mm512_mask_i32gather_epi32(zero, msk_ext, + idxes, (const int *)dp->tbl8, 2); + idxes = _mm512_and_epi32(idxes, res_msk); + } else + idxes = _mm512_mask_i32gather_epi32(zero, msk_ext, + idxes, (const int *)dp->tbl8, 4); + + res = _mm512_mask_blend_epi32(msk_ext, res, idxes); + } + + res = _mm512_srli_epi32(res, 1); + tmp1 = _mm512_maskz_expand_epi32(exp_msk, res); + tmp256 = _mm512_extracti32x8_epi32(res, 1); + tmp2 = _mm512_maskz_expand_epi32(exp_msk, + _mm512_castsi256_si512(tmp256)); + _mm512_storeu_si512(next_hops, tmp1); + _mm512_storeu_si512(next_hops + 8, tmp2); +} + +static __rte_always_inline void +dir24_8_vec_lookup_x8_8b(void *p, const uint32_t *ips, + uint64_t *next_hops) +{ + struct dir24_8_tbl *dp = (struct dir24_8_tbl *)p; + const __m512i zero = _mm512_set1_epi32(0); + const __m512i lsbyte_msk = _mm512_set1_epi64(0xff); + const __m512i lsb = _mm512_set1_epi64(1); + __m512i res, idxes, bytes; + __m256i idxes_256, ip_vec; + __mmask8 msk_ext; + + ip_vec = _mm256_loadu_si256((const void *)ips); + /* mask 24 most significant bits */ + idxes_256 = _mm256_srli_epi32(ip_vec, 8); + + /* lookup in tbl24 */ + res = _mm512_i32gather_epi64(idxes_256, (const void *)dp->tbl24, 8); + + /* get extended entries indexes */ + msk_ext = _mm512_test_epi64_mask(res, lsb); + + if (msk_ext != 0) { + bytes = _mm512_cvtepi32_epi64(ip_vec); + idxes = _mm512_srli_epi64(res, 1); + idxes = _mm512_slli_epi64(idxes, 8); + bytes = _mm512_and_epi64(bytes, lsbyte_msk); + idxes = _mm512_maskz_add_epi64(msk_ext, idxes, bytes); + idxes = _mm512_mask_i64gather_epi64(zero, msk_ext, idxes, + (const void *)dp->tbl8, 8); + + res = _mm512_mask_blend_epi64(msk_ext, res, idxes); + } + + res = _mm512_srli_epi64(res, 1); + _mm512_storeu_si512(next_hops, res); +} + +void +rte_dir24_8_vec_lookup_bulk_1b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 16); i++) + dir24_8_vec_lookup_x16(p, ips + i * 16, next_hops + i * 16, + sizeof(uint8_t)); + + dir24_8_lookup_bulk_1b(p, ips + i * 16, next_hops + i * 16, + n - i * 16); +} + +void +rte_dir24_8_vec_lookup_bulk_2b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 16); i++) + dir24_8_vec_lookup_x16(p, ips + i * 16, next_hops + i * 16, + sizeof(uint16_t)); + + dir24_8_lookup_bulk_2b(p, ips + i * 16, next_hops + i * 16, + n - i * 16); +} + +void +rte_dir24_8_vec_lookup_bulk_4b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 16); i++) + dir24_8_vec_lookup_x16(p, ips + i * 16, next_hops + i * 16, + sizeof(uint32_t)); + + dir24_8_lookup_bulk_4b(p, ips + i * 16, next_hops + i * 16, + n - i * 16); +} + +void +rte_dir24_8_vec_lookup_bulk_8b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 8); i++) + dir24_8_vec_lookup_x8_8b(p, ips + i * 8, next_hops + i * 8); + + dir24_8_lookup_bulk_8b(p, ips + i * 8, next_hops + i * 8, n - i * 8); +} diff --git a/lib/librte_fib/dir24_8_avx512.h b/lib/librte_fib/dir24_8_avx512.h new file mode 100644 index 0000000..1d3c2b9 --- /dev/null +++ b/lib/librte_fib/dir24_8_avx512.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ + +#ifndef _DIR248_AVX512_H_ +#define _DIR248_AVX512_H_ + +void +rte_dir24_8_vec_lookup_bulk_1b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_2b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_4b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_8b(void *p, const uint32_t *ips, + uint64_t *next_hops, const unsigned int n); + +#endif /* _DIR248_AVX512_H_ */ diff --git a/lib/librte_fib/meson.build b/lib/librte_fib/meson.build index 771828f..0963f3c 100644 --- a/lib/librte_fib/meson.build +++ b/lib/librte_fib/meson.build @@ -5,3 +5,14 @@ sources = files('rte_fib.c', 'rte_fib6.c', 'dir24_8.c', 'trie.c') headers = files('rte_fib.h', 'rte_fib6.h') deps += ['rib'] + +if dpdk_conf.has('RTE_ARCH_X86') and cc.has_argument('-mavx512f') + if cc.has_argument('-mavx512dq') + dir24_8_avx512_tmp = static_library('dir24_8_avx512_tmp', + 'dir24_8_avx512.c', + dependencies: static_rte_eal, + c_args: cflags + ['-mavx512f'] + ['-mavx512dq']) + objs += dir24_8_avx512_tmp.extract_objects('dir24_8_avx512.c') + cflags += '-DCC_DIR24_8_AVX512_SUPPORT' + endif +endif diff --git a/lib/librte_fib/rte_fib.h b/lib/librte_fib/rte_fib.h index db35685..2919d13 100644 --- a/lib/librte_fib/rte_fib.h +++ b/lib/librte_fib/rte_fib.h @@ -54,7 +54,8 @@ enum rte_fib_dir24_8_nh_sz { enum rte_fib_dir24_8_lookup_type { RTE_FIB_DIR24_8_SCALAR_MACRO, RTE_FIB_DIR24_8_SCALAR_INLINE, - RTE_FIB_DIR24_8_SCALAR_UNI + RTE_FIB_DIR24_8_SCALAR_UNI, + RTE_FIB_DIR24_8_VECTOR }; /** FIB configuration structure */ From patchwork Tue May 19 12:13:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70433 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 80667A0093; Tue, 19 May 2020 14:13:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0AB121D61A; Tue, 19 May 2020 14:13:19 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 1BFAE1D610 for ; Tue, 19 May 2020 14:13:13 +0200 (CEST) IronPort-SDR: 3UfuoT3OM0VGdbSHPZhTYN2w44DUvfZ6SeIQE8J+yEvCDoHJO03SK38qRWNWyJDS8OwGt/jjdL oCKHs4d7sLMw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:13 -0700 IronPort-SDR: TQitZJgjw2vZ0FzLiwKz7FIpDCHas+pHH1jKNFj+tGVv5W6Q811HmYcta1LsUQIzAIlfdZi5wG VfTjei2Ij7qg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938433" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:12 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:13:00 +0100 Message-Id: <87e3d89091d87ccdf01672211962189264fb9d0d.1589890263.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 5/8] fib6: make lookup function type configurable 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" Add type argument to trie_get_lookup_fn() Now it only supports RTE_FIB6_TRIE_SCALAR Add new rte_fib6_set_lookup_fn() - user can change lookup function type runtime. Signed-off-by: Vladimir Medvedkin --- lib/librte_fib/rte_fib6.c | 19 ++++++++++++++++++- lib/librte_fib/rte_fib6.h | 20 ++++++++++++++++++++ lib/librte_fib/rte_fib_version.map | 1 + lib/librte_fib/trie.c | 25 ++++++++++++++----------- lib/librte_fib/trie.h | 2 +- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/lib/librte_fib/rte_fib6.c b/lib/librte_fib/rte_fib6.c index a1f0db8..9eff712 100644 --- a/lib/librte_fib/rte_fib6.c +++ b/lib/librte_fib/rte_fib6.c @@ -107,7 +107,7 @@ init_dataplane(struct rte_fib6 *fib, __rte_unused int socket_id, fib->dp = trie_create(dp_name, socket_id, conf); if (fib->dp == NULL) return -rte_errno; - fib->lookup = rte_trie_get_lookup_fn(conf); + fib->lookup = trie_get_lookup_fn(fib->dp, RTE_FIB6_TRIE_SCALAR); fib->modify = trie_modify; return 0; default: @@ -319,3 +319,20 @@ rte_fib6_get_rib(struct rte_fib6 *fib) { return (fib == NULL) ? NULL : fib->rib; } + +int +rte_fib6_set_lookup_fn(struct rte_fib6 *fib, int type) +{ + rte_fib6_lookup_fn_t fn; + + switch (fib->type) { + case RTE_FIB6_TRIE: + fn = trie_get_lookup_fn(fib->dp, type); + if (fn == NULL) + return -EINVAL; + fib->lookup = fn; + return 0; + default: + return -EINVAL; + } +} diff --git a/lib/librte_fib/rte_fib6.h b/lib/librte_fib/rte_fib6.h index 66c71c8..b70369a 100644 --- a/lib/librte_fib/rte_fib6.h +++ b/lib/librte_fib/rte_fib6.h @@ -52,6 +52,10 @@ enum rte_fib_trie_nh_sz { RTE_FIB6_TRIE_8B }; +enum rte_fib_trie_lookup_type { + RTE_FIB6_TRIE_SCALAR +}; + /** FIB configuration structure */ struct rte_fib6_conf { enum rte_fib6_type type; /**< Type of FIB struct */ @@ -194,6 +198,22 @@ __rte_experimental struct rte_rib6 * rte_fib6_get_rib(struct rte_fib6 *fib); +/** + * Set lookup function based on type + * + * @param fib + * FIB object handle + * @param type + * type of lookup function + * + * @return + * -EINVAL on failure + * 0 on success + */ +__rte_experimental +int +rte_fib6_set_lookup_fn(struct rte_fib6 *fib, int type); + #ifdef __cplusplus } #endif diff --git a/lib/librte_fib/rte_fib_version.map b/lib/librte_fib/rte_fib_version.map index 216af66..9d1e181 100644 --- a/lib/librte_fib/rte_fib_version.map +++ b/lib/librte_fib/rte_fib_version.map @@ -19,6 +19,7 @@ EXPERIMENTAL { rte_fib6_lookup_bulk; rte_fib6_get_dp; rte_fib6_get_rib; + rte_fib6_set_lookup_fn; local: *; }; diff --git a/lib/librte_fib/trie.c b/lib/librte_fib/trie.c index 2ae2add..63c519a 100644 --- a/lib/librte_fib/trie.c +++ b/lib/librte_fib/trie.c @@ -59,13 +59,6 @@ enum edge { REDGE }; -enum lookup_type { - MACRO, - INLINE, - UNI -}; -static enum lookup_type test_lookup = MACRO; - static inline uint32_t get_tbl24_idx(const uint8_t *ip) { @@ -154,11 +147,18 @@ LOOKUP_FUNC(4b, uint32_t, 2) LOOKUP_FUNC(8b, uint64_t, 3) rte_fib6_lookup_fn_t -rte_trie_get_lookup_fn(struct rte_fib6_conf *conf) +trie_get_lookup_fn(void *p, enum rte_fib_trie_lookup_type type) { - enum rte_fib_trie_nh_sz nh_sz = conf->trie.nh_sz; + enum rte_fib_trie_nh_sz nh_sz; + struct rte_trie_tbl *dp = p; - if (test_lookup == MACRO) { + if (dp == NULL) + return NULL; + + nh_sz = dp->nh_sz; + + switch (type) { + case RTE_FIB6_TRIE_SCALAR: switch (nh_sz) { case RTE_FIB6_TRIE_2B: return rte_trie_lookup_bulk_2b; @@ -166,9 +166,12 @@ rte_trie_get_lookup_fn(struct rte_fib6_conf *conf) return rte_trie_lookup_bulk_4b; case RTE_FIB6_TRIE_8B: return rte_trie_lookup_bulk_8b; + default: + return NULL; } + default: + return NULL; } - return NULL; } diff --git a/lib/librte_fib/trie.h b/lib/librte_fib/trie.h index bb750c5..0d5ef9a 100644 --- a/lib/librte_fib/trie.h +++ b/lib/librte_fib/trie.h @@ -22,7 +22,7 @@ void trie_free(void *p); rte_fib6_lookup_fn_t -rte_trie_get_lookup_fn(struct rte_fib6_conf *fib_conf); +trie_get_lookup_fn(void *p, enum rte_fib_trie_lookup_type type); int trie_modify(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], From patchwork Tue May 19 12:13:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70434 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D140BA0093; Tue, 19 May 2020 14:14:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 636671D62F; Tue, 19 May 2020 14:13:20 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id D6B661D610 for ; Tue, 19 May 2020 14:13:14 +0200 (CEST) IronPort-SDR: xossGtgoGFhS6E/q77OYeh65VcW6NUCQlV/QprkFSVYbCBg86hzEyWr2RllOlE4XMDLFtMCMw8 0byz4QFwToqw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:14 -0700 IronPort-SDR: kmvQarF1+tG82c2IQvqEqZ2Wl31tl6mGThZW/zSzWlX0HCaNIUkpOpYWm7+iP6CKfHCDnX988m HDjBJrrJCDrw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938438" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:13 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:13:01 +0100 Message-Id: <8d95ebdbfbe8af73e02661ecf28c9edac3719fd9.1589890263.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 6/8] fib6: move lookup definition into the header file 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" Move trie table layout and lookup defenition into the private header file. This is necessary for implementing a vectorized lookup function in a separate .с file. Signed-off-by: Vladimir Medvedkin Acked-by: Konstantin Ananyev --- lib/librte_fib/trie.c | 121 -------------------------------------------------- lib/librte_fib/trie.h | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 121 deletions(-) diff --git a/lib/librte_fib/trie.c b/lib/librte_fib/trie.c index 63c519a..136e938 100644 --- a/lib/librte_fib/trie.c +++ b/lib/librte_fib/trie.c @@ -11,141 +11,20 @@ #include #include -#include #include #include -#include #include #include #include "trie.h" -/* @internal Total number of tbl24 entries. */ -#define TRIE_TBL24_NUM_ENT (1 << 24) - -/* Maximum depth value possible for IPv6 LPM. */ -#define TRIE_MAX_DEPTH 128 - -/* @internal Number of entries in a tbl8 group. */ -#define TRIE_TBL8_GRP_NUM_ENT 256ULL - -/* @internal Total number of tbl8 groups in the tbl8. */ -#define TRIE_TBL8_NUM_GROUPS 65536 - -/* @internal bitmask with valid and valid_group fields set */ -#define TRIE_EXT_ENT 1 - #define TRIE_NAMESIZE 64 -#define BITMAP_SLAB_BIT_SIZE_LOG2 6 -#define BITMAP_SLAB_BIT_SIZE (1ULL << BITMAP_SLAB_BIT_SIZE_LOG2) -#define BITMAP_SLAB_BITMASK (BITMAP_SLAB_BIT_SIZE - 1) - -struct rte_trie_tbl { - uint32_t number_tbl8s; /**< Total number of tbl8s */ - uint32_t rsvd_tbl8s; /**< Number of reserved tbl8s */ - uint32_t cur_tbl8s; /**< Current cumber of tbl8s */ - uint64_t def_nh; /**< Default next hop */ - enum rte_fib_trie_nh_sz nh_sz; /**< Size of nexthop entry */ - uint64_t *tbl8; /**< tbl8 table. */ - uint32_t *tbl8_pool; /**< bitmap containing free tbl8 idxes*/ - uint32_t tbl8_pool_pos; - /* tbl24 table. */ - __extension__ uint64_t tbl24[0] __rte_cache_aligned; -}; - enum edge { LEDGE, REDGE }; -static inline uint32_t -get_tbl24_idx(const uint8_t *ip) -{ - return ip[0] << 16|ip[1] << 8|ip[2]; -} - -static inline void * -get_tbl24_p(struct rte_trie_tbl *dp, const uint8_t *ip, uint8_t nh_sz) -{ - uint32_t tbl24_idx; - - tbl24_idx = get_tbl24_idx(ip); - return (void *)&((uint8_t *)dp->tbl24)[tbl24_idx << nh_sz]; -} - -static inline uint8_t -bits_in_nh(uint8_t nh_sz) -{ - return 8 * (1 << nh_sz); -} - -static inline uint64_t -get_max_nh(uint8_t nh_sz) -{ - return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1); -} - -static inline uint64_t -lookup_msk(uint8_t nh_sz) -{ - return ((1ULL << ((1 << (nh_sz + 3)) - 1)) << 1) - 1; -} - -static inline uint8_t -get_psd_idx(uint32_t val, uint8_t nh_sz) -{ - return val & ((1 << (3 - nh_sz)) - 1); -} - -static inline uint32_t -get_tbl_pos(uint32_t val, uint8_t nh_sz) -{ - return val >> (3 - nh_sz); -} - -static inline uint64_t -get_tbl_val_by_idx(uint64_t *tbl, uint32_t idx, uint8_t nh_sz) -{ - return ((tbl[get_tbl_pos(idx, nh_sz)] >> (get_psd_idx(idx, nh_sz) * - bits_in_nh(nh_sz))) & lookup_msk(nh_sz)); -} - -static inline void * -get_tbl_p_by_idx(uint64_t *tbl, uint64_t idx, uint8_t nh_sz) -{ - return (uint8_t *)tbl + (idx << nh_sz); -} - -static inline int -is_entry_extended(uint64_t ent) -{ - return (ent & TRIE_EXT_ENT) == TRIE_EXT_ENT; -} - -#define LOOKUP_FUNC(suffix, type, nh_sz) \ -static void rte_trie_lookup_bulk_##suffix(void *p, \ - uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], \ - uint64_t *next_hops, const unsigned int n) \ -{ \ - struct rte_trie_tbl *dp = (struct rte_trie_tbl *)p; \ - uint64_t tmp; \ - uint32_t i, j; \ - \ - for (i = 0; i < n; i++) { \ - tmp = ((type *)dp->tbl24)[get_tbl24_idx(&ips[i][0])]; \ - j = 3; \ - while (is_entry_extended(tmp)) { \ - tmp = ((type *)dp->tbl8)[ips[i][j++] + \ - ((tmp >> 1) * TRIE_TBL8_GRP_NUM_ENT)]; \ - } \ - next_hops[i] = tmp >> 1; \ - } \ -} -LOOKUP_FUNC(2b, uint16_t, 1) -LOOKUP_FUNC(4b, uint32_t, 2) -LOOKUP_FUNC(8b, uint64_t, 3) - rte_fib6_lookup_fn_t trie_get_lookup_fn(void *p, enum rte_fib_trie_lookup_type type) { diff --git a/lib/librte_fib/trie.h b/lib/librte_fib/trie.h index 0d5ef9a..663c7a9 100644 --- a/lib/librte_fib/trie.h +++ b/lib/librte_fib/trie.h @@ -10,11 +10,128 @@ * @file * RTE IPv6 Longest Prefix Match (LPM) */ +#include +#include #ifdef __cplusplus extern "C" { #endif +/* @internal Total number of tbl24 entries. */ +#define TRIE_TBL24_NUM_ENT (1 << 24) +/* Maximum depth value possible for IPv6 LPM. */ +#define TRIE_MAX_DEPTH 128 +/* @internal Number of entries in a tbl8 group. */ +#define TRIE_TBL8_GRP_NUM_ENT 256ULL +/* @internal Total number of tbl8 groups in the tbl8. */ +#define TRIE_TBL8_NUM_GROUPS 65536 +/* @internal bitmask with valid and valid_group fields set */ +#define TRIE_EXT_ENT 1 + +#define BITMAP_SLAB_BIT_SIZE_LOG2 6 +#define BITMAP_SLAB_BIT_SIZE (1ULL << BITMAP_SLAB_BIT_SIZE_LOG2) +#define BITMAP_SLAB_BITMASK (BITMAP_SLAB_BIT_SIZE - 1) + +struct rte_trie_tbl { + uint32_t number_tbl8s; /**< Total number of tbl8s */ + uint32_t rsvd_tbl8s; /**< Number of reserved tbl8s */ + uint32_t cur_tbl8s; /**< Current cumber of tbl8s */ + uint64_t def_nh; /**< Default next hop */ + enum rte_fib_trie_nh_sz nh_sz; /**< Size of nexthop entry */ + uint64_t *tbl8; /**< tbl8 table. */ + uint32_t *tbl8_pool; /**< bitmap containing free tbl8 idxes*/ + uint32_t tbl8_pool_pos; + /* tbl24 table. */ + __extension__ uint64_t tbl24[0] __rte_cache_aligned; +}; + +static inline uint32_t +get_tbl24_idx(const uint8_t *ip) +{ + return ip[0] << 16|ip[1] << 8|ip[2]; +} + +static inline void * +get_tbl24_p(struct rte_trie_tbl *dp, const uint8_t *ip, uint8_t nh_sz) +{ + uint32_t tbl24_idx; + + tbl24_idx = get_tbl24_idx(ip); + return (void *)&((uint8_t *)dp->tbl24)[tbl24_idx << nh_sz]; +} + +static inline uint8_t +bits_in_nh(uint8_t nh_sz) +{ + return 8 * (1 << nh_sz); +} + +static inline uint64_t +get_max_nh(uint8_t nh_sz) +{ + return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1); +} + +static inline uint64_t +lookup_msk(uint8_t nh_sz) +{ + return ((1ULL << ((1 << (nh_sz + 3)) - 1)) << 1) - 1; +} + +static inline uint8_t +get_psd_idx(uint32_t val, uint8_t nh_sz) +{ + return val & ((1 << (3 - nh_sz)) - 1); +} + +static inline uint32_t +get_tbl_pos(uint32_t val, uint8_t nh_sz) +{ + return val >> (3 - nh_sz); +} + +static inline uint64_t +get_tbl_val_by_idx(uint64_t *tbl, uint32_t idx, uint8_t nh_sz) +{ + return ((tbl[get_tbl_pos(idx, nh_sz)] >> (get_psd_idx(idx, nh_sz) * + bits_in_nh(nh_sz))) & lookup_msk(nh_sz)); +} + +static inline void * +get_tbl_p_by_idx(uint64_t *tbl, uint64_t idx, uint8_t nh_sz) +{ + return (uint8_t *)tbl + (idx << nh_sz); +} + +static inline int +is_entry_extended(uint64_t ent) +{ + return (ent & TRIE_EXT_ENT) == TRIE_EXT_ENT; +} + +#define LOOKUP_FUNC(suffix, type, nh_sz) \ +static inline void rte_trie_lookup_bulk_##suffix(void *p, \ + uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], \ + uint64_t *next_hops, const unsigned int n) \ +{ \ + struct rte_trie_tbl *dp = (struct rte_trie_tbl *)p; \ + uint64_t tmp; \ + uint32_t i, j; \ + \ + for (i = 0; i < n; i++) { \ + tmp = ((type *)dp->tbl24)[get_tbl24_idx(&ips[i][0])]; \ + j = 3; \ + while (is_entry_extended(tmp)) { \ + tmp = ((type *)dp->tbl8)[ips[i][j++] + \ + ((tmp >> 1) * TRIE_TBL8_GRP_NUM_ENT)]; \ + } \ + next_hops[i] = tmp >> 1; \ + } \ +} +LOOKUP_FUNC(2b, uint16_t, 1) +LOOKUP_FUNC(4b, uint32_t, 2) +LOOKUP_FUNC(8b, uint64_t, 3) + void * trie_create(const char *name, int socket_id, struct rte_fib6_conf *conf); From patchwork Tue May 19 12:13:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70435 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD41AA0093; Tue, 19 May 2020 14:14:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A3F9F1D635; Tue, 19 May 2020 14:13:21 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id A249E1D61A for ; Tue, 19 May 2020 14:13:16 +0200 (CEST) IronPort-SDR: WL2EeFxFQ6a04+1dGai+r2pxPBbfik9FBwjdI2fZO/5fyZ9h3rDeGVSfldo1XUU7UHMYxy75XK GVDwFZjWxyow== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:15 -0700 IronPort-SDR: nQ+SM1uqBg1mjOkJmWuLC5dee47annDKT+DjhExGl53iYEwTThQT3NocDhV5OoTNTyEGFudnvH jDHV4N+ziYTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938442" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:14 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:13:02 +0100 Message-Id: <99bcffd72d5678e58289830c43ce2bf3829d310a.1589890263.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 7/8] fib6: introduce AVX512 lookup 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" Add new lookup implementation for FIB6 trie algorithm using AVX512 instruction set Signed-off-by: Vladimir Medvedkin Acked-by: Konstantin Ananyev --- lib/librte_fib/Makefile | 10 ++ lib/librte_fib/meson.build | 9 ++ lib/librte_fib/rte_fib6.h | 3 +- lib/librte_fib/trie.c | 21 ++++ lib/librte_fib/trie_avx512.c | 269 +++++++++++++++++++++++++++++++++++++++++++ lib/librte_fib/trie_avx512.h | 20 ++++ 6 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 lib/librte_fib/trie_avx512.c create mode 100644 lib/librte_fib/trie_avx512.h diff --git a/lib/librte_fib/Makefile b/lib/librte_fib/Makefile index 3958da1..761c7c8 100644 --- a/lib/librte_fib/Makefile +++ b/lib/librte_fib/Makefile @@ -25,12 +25,22 @@ grep -q __AVX512F__ && echo 1) CC_AVX512DQ_SUPPORT=$(shell $(CC) -mavx512dq -dM -E - &1 | \ grep -q __AVX512DQ__ && echo 1) +CC_AVX512BW_SUPPORT=$(shell $(CC) -mavx512bw -dM -E - &1 | \ +grep -q __AVX512BW__ && echo 1) + ifeq ($(CC_AVX512F_SUPPORT), 1) ifeq ($(CC_AVX512DQ_SUPPORT), 1) SRCS-$(CONFIG_RTE_LIBRTE_FIB) += dir24_8_avx512.c CFLAGS_dir24_8_avx512.o += -mavx512f CFLAGS_dir24_8_avx512.o += -mavx512dq CFLAGS_dir24_8.o += -DCC_DIR24_8_AVX512_SUPPORT + ifeq ($(CC_AVX512BW_SUPPORT), 1) + SRCS-$(CONFIG_RTE_LIBRTE_FIB) += trie_avx512.c + CFLAGS_trie_avx512.o += -mavx512f + CFLAGS_trie_avx512.o += -mavx512dq + CFLAGS_trie_avx512.o += -mavx512bw + CFLAGS_trie.o += -DCC_TRIE_AVX512_SUPPORT + endif endif endif include $(RTE_SDK)/mk/rte.lib.mk diff --git a/lib/librte_fib/meson.build b/lib/librte_fib/meson.build index 0963f3c..98adf11 100644 --- a/lib/librte_fib/meson.build +++ b/lib/librte_fib/meson.build @@ -14,5 +14,14 @@ if dpdk_conf.has('RTE_ARCH_X86') and cc.has_argument('-mavx512f') c_args: cflags + ['-mavx512f'] + ['-mavx512dq']) objs += dir24_8_avx512_tmp.extract_objects('dir24_8_avx512.c') cflags += '-DCC_DIR24_8_AVX512_SUPPORT' + if cc.has_argument('-mavx512bw') + trie_avx512_tmp = static_library('trie_avx512_tmp', + 'trie_avx512.c', + dependencies: static_rte_eal, + c_args: cflags + ['-mavx512f'] + \ + ['-mavx512dq'] + ['-mavx512bw']) + objs += trie_avx512_tmp.extract_objects('trie_avx512.c') + cflags += '-DCC_TRIE_AVX512_SUPPORT' + endif endif endif diff --git a/lib/librte_fib/rte_fib6.h b/lib/librte_fib/rte_fib6.h index b70369a..c55efdf 100644 --- a/lib/librte_fib/rte_fib6.h +++ b/lib/librte_fib/rte_fib6.h @@ -53,7 +53,8 @@ enum rte_fib_trie_nh_sz { }; enum rte_fib_trie_lookup_type { - RTE_FIB6_TRIE_SCALAR + RTE_FIB6_TRIE_SCALAR, + RTE_FIB6_TRIE_VECTOR }; /** FIB configuration structure */ diff --git a/lib/librte_fib/trie.c b/lib/librte_fib/trie.c index 136e938..ee6864e 100644 --- a/lib/librte_fib/trie.c +++ b/lib/librte_fib/trie.c @@ -18,6 +18,12 @@ #include #include "trie.h" +#ifdef CC_TRIE_AVX512_SUPPORT + +#include "trie_avx512.h" + +#endif /* CC_TRIE_AVX512_SUPPORT */ + #define TRIE_NAMESIZE 64 enum edge { @@ -48,6 +54,21 @@ trie_get_lookup_fn(void *p, enum rte_fib_trie_lookup_type type) default: return NULL; } +#ifdef CC_TRIE_AVX512_SUPPORT + case RTE_FIB6_TRIE_VECTOR: + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) <= 0) + return NULL; + switch (nh_sz) { + case RTE_FIB6_TRIE_2B: + return rte_trie_vec_lookup_bulk_2b; + case RTE_FIB6_TRIE_4B: + return rte_trie_vec_lookup_bulk_4b; + case RTE_FIB6_TRIE_8B: + return rte_trie_vec_lookup_bulk_8b; + default: + return NULL; + } +#endif default: return NULL; } diff --git a/lib/librte_fib/trie_avx512.c b/lib/librte_fib/trie_avx512.c new file mode 100644 index 0000000..b1c9e4e --- /dev/null +++ b/lib/librte_fib/trie_avx512.c @@ -0,0 +1,269 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ + +#include +#include + +#include "trie.h" +#include "trie_avx512.h" + +static __rte_always_inline void +transpose_x16(uint8_t ips[16][RTE_FIB6_IPV6_ADDR_SIZE], + __m512i *first, __m512i *second, __m512i *third, __m512i *fourth) +{ + __m512i tmp1, tmp2, tmp3, tmp4; + __m512i tmp5, tmp6, tmp7, tmp8; + const __rte_x86_zmm_t perm_idxes = { + .u32 = { 0, 4, 8, 12, 2, 6, 10, 14, + 1, 5, 9, 13, 3, 7, 11, 15 + }, + }; + + /* load all ip addresses */ + tmp1 = _mm512_loadu_si512(&ips[0][0]); + tmp2 = _mm512_loadu_si512(&ips[4][0]); + tmp3 = _mm512_loadu_si512(&ips[8][0]); + tmp4 = _mm512_loadu_si512(&ips[12][0]); + + /* transpose 4 byte chunks of 16 ips */ + tmp5 = _mm512_unpacklo_epi32(tmp1, tmp2); + tmp7 = _mm512_unpackhi_epi32(tmp1, tmp2); + tmp6 = _mm512_unpacklo_epi32(tmp3, tmp4); + tmp8 = _mm512_unpackhi_epi32(tmp3, tmp4); + + tmp1 = _mm512_unpacklo_epi32(tmp5, tmp6); + tmp3 = _mm512_unpackhi_epi32(tmp5, tmp6); + tmp2 = _mm512_unpacklo_epi32(tmp7, tmp8); + tmp4 = _mm512_unpackhi_epi32(tmp7, tmp8); + + /* first 4-byte chunks of ips[] */ + *first = _mm512_permutexvar_epi32(perm_idxes.z, tmp1); + /* second 4-byte chunks of ips[] */ + *second = _mm512_permutexvar_epi32(perm_idxes.z, tmp3); + /* third 4-byte chunks of ips[] */ + *third = _mm512_permutexvar_epi32(perm_idxes.z, tmp2); + /* fourth 4-byte chunks of ips[] */ + *fourth = _mm512_permutexvar_epi32(perm_idxes.z, tmp4); +} + +static __rte_always_inline void +transpose_x8(uint8_t ips[8][RTE_FIB6_IPV6_ADDR_SIZE], + __m512i *first, __m512i *second) +{ + __m512i tmp1, tmp2, tmp3, tmp4; + const __rte_x86_zmm_t perm_idxes = { + .u64 = { 0, 2, 4, 6, 1, 3, 5, 7 + }, + }; + + tmp1 = _mm512_loadu_si512(&ips[0][0]); + tmp2 = _mm512_loadu_si512(&ips[4][0]); + + tmp3 = _mm512_unpacklo_epi64(tmp1, tmp2); + *first = _mm512_permutexvar_epi64(perm_idxes.z, tmp3); + tmp4 = _mm512_unpackhi_epi64(tmp1, tmp2); + *second = _mm512_permutexvar_epi64(perm_idxes.z, tmp4); +} + +static __rte_always_inline void +trie_vec_lookup_x16(void *p, uint8_t ips[16][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, int size) +{ + struct rte_trie_tbl *dp = (struct rte_trie_tbl *)p; + const __m512i zero = _mm512_set1_epi32(0); + const __m512i lsb = _mm512_set1_epi32(1); + const __m512i two_lsb = _mm512_set1_epi32(3); + __m512i first, second, third, fourth; /*< IPv6 four byte chunks */ + __m512i idxes, res, shuf_idxes; + __m512i tmp, tmp2, bytes, byte_chunk, base_idxes; + /* used to mask gather values if size is 2 (16 bit next hops) */ + const __m512i res_msk = _mm512_set1_epi32(UINT16_MAX); + const __rte_x86_zmm_t bswap = { + .u8 = { 2, 1, 0, 255, 6, 5, 4, 255, + 10, 9, 8, 255, 14, 13, 12, 255, + 2, 1, 0, 255, 6, 5, 4, 255, + 10, 9, 8, 255, 14, 13, 12, 255, + 2, 1, 0, 255, 6, 5, 4, 255, + 10, 9, 8, 255, 14, 13, 12, 255, + 2, 1, 0, 255, 6, 5, 4, 255, + 10, 9, 8, 255, 14, 13, 12, 255 + }, + }; + const __mmask64 k = 0x1111111111111111; + int i = 3; + __mmask16 msk_ext, new_msk; + __mmask16 exp_msk = 0x5555; + + transpose_x16(ips, &first, &second, &third, &fourth); + + /* get_tbl24_idx() for every 4 byte chunk */ + idxes = _mm512_shuffle_epi8(first, bswap.z); + + /** + * lookup in tbl24 + * Put it inside branch to make compiller happy with -O0 + */ + if (size == sizeof(uint16_t)) { + res = _mm512_i32gather_epi32(idxes, (const int *)dp->tbl24, 2); + res = _mm512_and_epi32(res, res_msk); + } else + res = _mm512_i32gather_epi32(idxes, (const int *)dp->tbl24, 4); + + + /* get extended entries indexes */ + msk_ext = _mm512_test_epi32_mask(res, lsb); + + tmp = _mm512_srli_epi32(res, 1); + + /* idxes to retrieve bytes */ + shuf_idxes = _mm512_setr_epi32(3, 7, 11, 15, + 19, 23, 27, 31, + 35, 39, 43, 47, + 51, 55, 59, 63); + + base_idxes = _mm512_setr_epi32(0, 4, 8, 12, + 16, 20, 24, 28, + 32, 36, 40, 44, + 48, 52, 56, 60); + + /* traverse down the trie */ + while (msk_ext) { + idxes = _mm512_maskz_slli_epi32(msk_ext, tmp, 8); + byte_chunk = (i < 8) ? + ((i >= 4) ? second : first) : + ((i >= 12) ? fourth : third); + bytes = _mm512_maskz_shuffle_epi8(k, byte_chunk, shuf_idxes); + idxes = _mm512_maskz_add_epi32(msk_ext, idxes, bytes); + if (size == sizeof(uint16_t)) { + tmp = _mm512_mask_i32gather_epi32(zero, msk_ext, + idxes, (const int *)dp->tbl8, 2); + tmp = _mm512_and_epi32(tmp, res_msk); + } else + tmp = _mm512_mask_i32gather_epi32(zero, msk_ext, + idxes, (const int *)dp->tbl8, 4); + new_msk = _mm512_test_epi32_mask(tmp, lsb); + res = _mm512_mask_blend_epi32(msk_ext ^ new_msk, res, tmp); + tmp = _mm512_srli_epi32(tmp, 1); + msk_ext = new_msk; + + shuf_idxes = _mm512_maskz_add_epi8(k, shuf_idxes, lsb); + shuf_idxes = _mm512_and_epi32(shuf_idxes, two_lsb); + shuf_idxes = _mm512_maskz_add_epi8(k, shuf_idxes, base_idxes); + i++; + } + + res = _mm512_srli_epi32(res, 1); + tmp = _mm512_maskz_expand_epi32(exp_msk, res); + __m256i tmp256; + tmp256 = _mm512_extracti32x8_epi32(res, 1); + tmp2 = _mm512_maskz_expand_epi32(exp_msk, + _mm512_castsi256_si512(tmp256)); + _mm512_storeu_si512(next_hops, tmp); + _mm512_storeu_si512(next_hops + 8, tmp2); +} + +static void +trie_vec_lookup_x8_8b(void *p, uint8_t ips[8][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops) +{ + struct rte_trie_tbl *dp = (struct rte_trie_tbl *)p; + const __m512i zero = _mm512_set1_epi32(0); + const __m512i lsb = _mm512_set1_epi32(1); + const __m512i three_lsb = _mm512_set1_epi32(7); + __m512i first, second; /*< IPv6 eight byte chunks */ + __m512i idxes, res, shuf_idxes; + __m512i tmp, bytes, byte_chunk, base_idxes; + const __rte_x86_zmm_t bswap = { + .u8 = { 2, 1, 0, 255, 255, 255, 255, 255, + 10, 9, 8, 255, 255, 255, 255, 255, + 2, 1, 0, 255, 255, 255, 255, 255, + 10, 9, 8, 255, 255, 255, 255, 255, + 2, 1, 0, 255, 255, 255, 255, 255, + 10, 9, 8, 255, 255, 255, 255, 255, + 2, 1, 0, 255, 255, 255, 255, 255, + 10, 9, 8, 255, 255, 255, 255, 255 + }, + }; + const __mmask64 k = 0x101010101010101; + int i = 3; + __mmask8 msk_ext, new_msk; + + transpose_x8(ips, &first, &second); + + /* get_tbl24_idx() for every 4 byte chunk */ + idxes = _mm512_shuffle_epi8(first, bswap.z); + + /* lookup in tbl24 */ + res = _mm512_i64gather_epi64(idxes, (const void *)dp->tbl24, 8); + /* get extended entries indexes */ + msk_ext = _mm512_test_epi64_mask(res, lsb); + + tmp = _mm512_srli_epi64(res, 1); + + /* idxes to retrieve bytes */ + shuf_idxes = _mm512_setr_epi64(3, 11, 19, 27, 35, 43, 51, 59); + + base_idxes = _mm512_setr_epi64(0, 8, 16, 24, 32, 40, 48, 56); + + /* traverse down the trie */ + while (msk_ext) { + idxes = _mm512_maskz_slli_epi64(msk_ext, tmp, 8); + byte_chunk = (i < 8) ? first : second; + bytes = _mm512_maskz_shuffle_epi8(k, byte_chunk, shuf_idxes); + idxes = _mm512_maskz_add_epi64(msk_ext, idxes, bytes); + tmp = _mm512_mask_i64gather_epi64(zero, msk_ext, + idxes, (const void *)dp->tbl8, 8); + new_msk = _mm512_test_epi64_mask(tmp, lsb); + res = _mm512_mask_blend_epi64(msk_ext ^ new_msk, res, tmp); + tmp = _mm512_srli_epi64(tmp, 1); + msk_ext = new_msk; + + shuf_idxes = _mm512_maskz_add_epi8(k, shuf_idxes, lsb); + shuf_idxes = _mm512_and_epi64(shuf_idxes, three_lsb); + shuf_idxes = _mm512_maskz_add_epi8(k, shuf_idxes, base_idxes); + i++; + } + + res = _mm512_srli_epi64(res, 1); + _mm512_storeu_si512(next_hops, res); +} + +void +rte_trie_vec_lookup_bulk_2b(void *p, uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 16); i++) { + trie_vec_lookup_x16(p, (uint8_t (*)[16])&ips[i * 16][0], + next_hops + i * 16, sizeof(uint16_t)); + } + rte_trie_lookup_bulk_2b(p, (uint8_t (*)[16])&ips[i * 16][0], + next_hops + i * 16, n - i * 16); +} + +void +rte_trie_vec_lookup_bulk_4b(void *p, uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 16); i++) { + trie_vec_lookup_x16(p, (uint8_t (*)[16])&ips[i * 16][0], + next_hops + i * 16, sizeof(uint32_t)); + } + rte_trie_lookup_bulk_4b(p, (uint8_t (*)[16])&ips[i * 16][0], + next_hops + i * 16, n - i * 16); +} + +void +rte_trie_vec_lookup_bulk_8b(void *p, uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, const unsigned int n) +{ + uint32_t i; + for (i = 0; i < (n / 8); i++) { + trie_vec_lookup_x8_8b(p, (uint8_t (*)[16])&ips[i * 8][0], + next_hops + i * 8); + } + rte_trie_lookup_bulk_8b(p, (uint8_t (*)[16])&ips[i * 8][0], + next_hops + i * 8, n - i * 8); +} diff --git a/lib/librte_fib/trie_avx512.h b/lib/librte_fib/trie_avx512.h new file mode 100644 index 0000000..ef8c7f0 --- /dev/null +++ b/lib/librte_fib/trie_avx512.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ + +#ifndef _TRIE_AVX512_H_ +#define _TRIE_AVX512_H_ + +void +rte_trie_vec_lookup_bulk_2b(void *p, uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, const unsigned int n); + +void +rte_trie_vec_lookup_bulk_4b(void *p, uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, const unsigned int n); + +void +rte_trie_vec_lookup_bulk_8b(void *p, uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], + uint64_t *next_hops, const unsigned int n); + +#endif /* _TRIE_AVX512_H_ */ From patchwork Tue May 19 12:13:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 70436 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 33302A0093; Tue, 19 May 2020 14:14:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 170C31D63B; Tue, 19 May 2020 14:13:23 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 8CFC71D61A for ; Tue, 19 May 2020 14:13:17 +0200 (CEST) IronPort-SDR: 13vefN0C2sv/wUcLiGt7zD0Frc+qDpbUnVeuZBOzM42GwMJyfHgH69PC4HatcTGY98xc619ixE ZkSfcwrhm6tw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2020 05:13:16 -0700 IronPort-SDR: fO4P/df+OCDw0BP/iZDps3WIIjnMihnXFRLNuPPynxqATAI6IHWh9+GPqiA6yr64P47sKni6IY /VtXx9C2Tx9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,410,1583222400"; d="scan'208";a="288938446" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 19 May 2020 05:13:15 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com Date: Tue, 19 May 2020 13:13:03 +0100 Message-Id: <3c4fa9b50d256092d6b898bf56268d6263bae01e.1589890263.git.vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 8/8] app/testfib: add support for different lookup 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" Added -v option to switch between different lookup implementations to measure their performance and correctness. Signed-off-by: Vladimir Medvedkin --- app/test-fib/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/app/test-fib/main.c b/app/test-fib/main.c index 6e80d65..b72e8c4 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -99,6 +99,7 @@ static struct { uint8_t ent_sz; uint8_t rnd_lookup_ips_ratio; uint8_t print_fract; + uint8_t lookup_fn; } config = { .routes_file = NULL, .lookup_ips_file = NULL, @@ -110,7 +111,8 @@ static struct { .tbl8 = DEFAULT_LPM_TBL8, .ent_sz = 4, .rnd_lookup_ips_ratio = 0, - .print_fract = 10 + .print_fract = 10, + .lookup_fn = 0 }; struct rt_rule_4 { @@ -636,7 +638,11 @@ print_usage(void) "1/2/4/8 (default 4)>]\n" "[-g ]\n" "[-w ]\n" - "[-u ]\n", + "[-u ]\n" + "[-v ]\n", config.prgname); } @@ -679,7 +685,7 @@ parse_opts(int argc, char **argv) int opt; char *endptr; - while ((opt = getopt(argc, argv, "f:t:n:d:l:r:c6ab:e:g:w:u:s")) != + while ((opt = getopt(argc, argv, "f:t:n:d:l:r:c6ab:e:g:w:u:sv:")) != -1) { switch (opt) { case 'f': @@ -767,6 +773,22 @@ parse_opts(int argc, char **argv) rte_exit(-EINVAL, "Invalid option -g\n"); } break; + case 'v': + if ((strcmp(optarg, "s1") == 0) || + (strcmp(optarg, "s") == 0)) + break; + else if (strcmp(optarg, "v") == 0) { + config.lookup_fn = 1; + break; + } else if (strcmp(optarg, "s2") == 0) { + config.lookup_fn = 2; + break; + } else if (strcmp(optarg, "s3") == 0) { + config.lookup_fn = 3; + break; + } + print_usage(); + rte_exit(-EINVAL, "Invalid option -v %s\n", optarg); default: print_usage(); rte_exit(-EINVAL, "Invalid options\n"); @@ -844,6 +866,24 @@ run_v4(void) return -rte_errno; } + if (config.lookup_fn != 0) { + if (config.lookup_fn == 1) + ret = rte_fib_set_lookup_fn(fib, + RTE_FIB_DIR24_8_VECTOR); + else if (config.lookup_fn == 2) + ret = rte_fib_set_lookup_fn(fib, + RTE_FIB_DIR24_8_SCALAR_INLINE); + else if (config.lookup_fn == 3) + ret = rte_fib_set_lookup_fn(fib, + RTE_FIB_DIR24_8_SCALAR_UNI); + else + ret = -EINVAL; + if (ret != 0) { + printf("Can not init lookup function\n"); + return ret; + } + } + for (k = config.print_fract, i = 0; k > 0; k--) { start = rte_rdtsc_precise(); for (j = 0; j < (config.nb_routes - i) / k; j++) { @@ -1023,6 +1063,18 @@ run_v6(void) return -rte_errno; } + if (config.lookup_fn != 0) { + if (config.lookup_fn == 1) + ret = rte_fib6_set_lookup_fn(fib, + RTE_FIB6_TRIE_VECTOR); + else + ret = -EINVAL; + if (ret != 0) { + printf("Can not init lookup function\n"); + return ret; + } + } + for (k = config.print_fract, i = 0; k > 0; k--) { start = rte_rdtsc_precise(); for (j = 0; j < (config.nb_routes - i) / k; j++) {