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 D9658A04BA; Wed, 7 Oct 2020 18:12:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9C5591BDDB; Wed, 7 Oct 2020 18:11:07 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id D08C01BBD6 for ; Wed, 7 Oct 2020 18:11:04 +0200 (CEST) IronPort-SDR: TMlT6wR2OXHFEkUmJ/FJykTGfkuuduIgJRsC8zrdEntUigd4fhV+Q5q0DRrUKJ8epVaAmV6xro HUQ00Y9x4u6g== X-IronPort-AV: E=McAfee;i="6000,8403,9767"; a="182477178" X-IronPort-AV: E=Sophos;i="5.77,347,1596524400"; d="scan'208";a="182477178" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2020 09:11:01 -0700 IronPort-SDR: XQMBvRDUwEYFDwK5+oSNqp6FXN/y1WfPBg9GfTx08CpWzfzE85b8gFmO8Jdu+g+jgbyDswBMJR xA6ZAjMXNQPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,347,1596524400"; d="scan'208";a="342953104" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga004.fm.intel.com with ESMTP; 07 Oct 2020 09:10:59 -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: Wed, 7 Oct 2020 17:10:39 +0100 Message-Id: <0500a04b9c68f0437caf1b99e9430f6208211f75.1602086562.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 v9 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 Acked-by: Konstantin Ananyev --- lib/librte_fib/rte_fib6.c | 20 +++++++++++++++- lib/librte_fib/rte_fib6.h | 23 +++++++++++++++++++ lib/librte_fib/rte_fib_version.map | 1 + lib/librte_fib/trie.c | 47 +++++++++++++++++++++++--------------- lib/librte_fib/trie.h | 2 +- 5 files changed, 72 insertions(+), 21 deletions(-) diff --git a/lib/librte_fib/rte_fib6.c b/lib/librte_fib/rte_fib6.c index a1f0db8..566cd5f 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,21 @@ rte_fib6_get_rib(struct rte_fib6 *fib) { return (fib == NULL) ? NULL : fib->rib; } + +int +rte_fib6_set_lookup_fn(struct rte_fib6 *fib, + enum rte_fib_trie_lookup_type 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 bbfcf23..cc817ad 100644 --- a/lib/librte_fib/rte_fib6.h +++ b/lib/librte_fib/rte_fib6.h @@ -53,12 +53,18 @@ enum rte_fib6_op { RTE_FIB6_DEL, }; +/** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */ enum rte_fib_trie_nh_sz { RTE_FIB6_TRIE_2B = 1, RTE_FIB6_TRIE_4B, RTE_FIB6_TRIE_8B }; +/** Type of lookup function implementation */ +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 */ @@ -201,6 +207,23 @@ __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, + enum rte_fib_trie_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 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..fc14670 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) { @@ -153,22 +146,38 @@ LOOKUP_FUNC(2b, uint16_t, 1) LOOKUP_FUNC(4b, uint32_t, 2) LOOKUP_FUNC(8b, uint64_t, 3) +static inline rte_fib6_lookup_fn_t +get_scalar_fn(enum rte_fib_trie_nh_sz nh_sz) +{ + switch (nh_sz) { + case RTE_FIB6_TRIE_2B: + return rte_trie_lookup_bulk_2b; + case RTE_FIB6_TRIE_4B: + return rte_trie_lookup_bulk_4b; + case RTE_FIB6_TRIE_8B: + return rte_trie_lookup_bulk_8b; + default: + return NULL; + } +} + 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) { - switch (nh_sz) { - case RTE_FIB6_TRIE_2B: - return rte_trie_lookup_bulk_2b; - case RTE_FIB6_TRIE_4B: - return rte_trie_lookup_bulk_4b; - case RTE_FIB6_TRIE_8B: - return rte_trie_lookup_bulk_8b; - } + if (dp == NULL) + return NULL; + + nh_sz = dp->nh_sz; + + switch (type) { + case RTE_FIB6_TRIE_SCALAR: + return get_scalar_fn(nh_sz); + 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], -- 2.7.4