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 20C34A04DC; Mon, 19 Oct 2020 12:18:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 15159C9C0; Mon, 19 Oct 2020 12:18:08 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id E7249C8CC for ; Mon, 19 Oct 2020 12:18:00 +0200 (CEST) IronPort-SDR: 9AOWfz8Yo+6Pmq/Cm1tUFL56rYyCCPvTxWkfqVX4d+QOfoRr2nKXXsEftFc3yfH51TcJPsYCJ+ ZXfc60Q+5wSg== X-IronPort-AV: E=McAfee;i="6000,8403,9778"; a="228637584" X-IronPort-AV: E=Sophos;i="5.77,394,1596524400"; d="scan'208";a="228637584" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2020 03:17:58 -0700 IronPort-SDR: wky36uhHWSRDarJXhq2NqnG5VMVuLdn2+aj7VDj6Rt6oyv6Gz1GGl4rq8sfykNNCbkQ51ZJ/6f idP8Px7Kstgg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,394,1596524400"; d="scan'208";a="331847976" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by orsmga002.jf.intel.com with ESMTP; 19 Oct 2020 03:17:55 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: david.marchand@redhat.com, jerinj@marvell.com, mdr@ashroe.eu, thomas@monjalon.net, konstantin.ananyev@intel.com, bruce.richardson@intel.com, ciara.power@intel.com Date: Mon, 19 Oct 2020 11:17:45 +0100 Message-Id: <7f1a6154622b840cf40836d9bff8bc0eff6d8878.1603102577.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 v12 1/7] 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 Acked-by: Konstantin Ananyev --- lib/librte_fib/dir24_8.c | 84 +++++++++++++++++++++++--------------- lib/librte_fib/dir24_8.h | 2 +- lib/librte_fib/rte_fib.c | 21 +++++++++- lib/librte_fib/rte_fib.h | 32 +++++++++++++++ lib/librte_fib/rte_fib_version.map | 1 + 5 files changed, 106 insertions(+), 34 deletions(-) diff --git a/lib/librte_fib/dir24_8.c b/lib/librte_fib/dir24_8.c index c9dce3c..ff51f65 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) { @@ -252,35 +245,62 @@ dir24_8_lookup_bulk_uni(void *p, const uint32_t *ips, } } +static inline rte_fib_lookup_fn_t +get_scalar_fn(enum rte_fib_dir24_8_nh_sz nh_sz) +{ + switch (nh_sz) { + case RTE_FIB_DIR24_8_1B: + return dir24_8_lookup_bulk_1b; + case RTE_FIB_DIR24_8_2B: + return dir24_8_lookup_bulk_2b; + case RTE_FIB_DIR24_8_4B: + return dir24_8_lookup_bulk_4b; + case RTE_FIB_DIR24_8_8B: + return dir24_8_lookup_bulk_8b; + default: + return NULL; + } +} + +static inline rte_fib_lookup_fn_t +get_scalar_fn_inlined(enum rte_fib_dir24_8_nh_sz nh_sz) +{ + switch (nh_sz) { + case RTE_FIB_DIR24_8_1B: + return dir24_8_lookup_bulk_0; + case RTE_FIB_DIR24_8_2B: + return dir24_8_lookup_bulk_1; + case RTE_FIB_DIR24_8_4B: + return dir24_8_lookup_bulk_2; + case RTE_FIB_DIR24_8_8B: + return dir24_8_lookup_bulk_3; + default: + return NULL; + } +} + 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) { - switch (nh_sz) { - case RTE_FIB_DIR24_8_1B: - return dir24_8_lookup_bulk_1b; - case RTE_FIB_DIR24_8_2B: - return dir24_8_lookup_bulk_2b; - case RTE_FIB_DIR24_8_4B: - return dir24_8_lookup_bulk_4b; - case RTE_FIB_DIR24_8_8B: - return dir24_8_lookup_bulk_8b; - } - } else if (test_lookup == INLINE) { - switch (nh_sz) { - case RTE_FIB_DIR24_8_1B: - return dir24_8_lookup_bulk_0; - case RTE_FIB_DIR24_8_2B: - return dir24_8_lookup_bulk_1; - case RTE_FIB_DIR24_8_4B: - return dir24_8_lookup_bulk_2; - case RTE_FIB_DIR24_8_8B: - return dir24_8_lookup_bulk_3; - } - } else + if (dp == NULL) + return NULL; + + nh_sz = dp->nh_sz; + + switch (type) { + case RTE_FIB_DIR24_8_SCALAR_MACRO: + return get_scalar_fn(nh_sz); + case RTE_FIB_DIR24_8_SCALAR_INLINE: + return get_scalar_fn_inlined(nh_sz); + 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..b9f6efb 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,21 @@ rte_fib_get_rib(struct rte_fib *fib) { return (fib == NULL) ? NULL : fib->rib; } + +int +rte_fib_set_lookup_fn(struct rte_fib *fib, + enum rte_fib_dir24_8_lookup_type 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 84ee774..2097ee5 100644 --- a/lib/librte_fib/rte_fib.h +++ b/lib/librte_fib/rte_fib.h @@ -58,6 +58,21 @@ enum rte_fib_dir24_8_nh_sz { RTE_FIB_DIR24_8_8B }; +/** Type of lookup function implementation */ +enum rte_fib_dir24_8_lookup_type { + RTE_FIB_DIR24_8_SCALAR_MACRO, + /**< Macro based lookup function */ + RTE_FIB_DIR24_8_SCALAR_INLINE, + /**< + * Lookup implementation using inlined functions + * for different next hop sizes + */ + RTE_FIB_DIR24_8_SCALAR_UNI + /**< + * Unified lookup function for all next hop sizes + */ +}; + /** FIB configuration structure */ struct rte_fib_conf { enum rte_fib_type type; /**< Type of FIB struct */ @@ -196,6 +211,23 @@ __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, + enum rte_fib_dir24_8_lookup_type 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; -- 2.7.4