fib: add lookup runtime selection

Add type argument to dir24_8_get_lookup_fn()
Now it supports 3 different lookup implementations:
 RTE_FIB_LOOKUP_DIR24_8_SCALAR_MACRO
 RTE_FIB_LOOKUP_DIR24_8_SCALAR_INLINE
 RTE_FIB_LOOKUP_DIR24_8_SCALAR_UNI

Add new rte_fib_select_lookup() - user can change lookup
function type runtime.

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
This commit is contained in:
Vladimir Medvedkin 2020-10-27 15:11:24 +00:00 committed by David Marchand
parent 4f66d3be56
commit a5b0d25d81
5 changed files with 106 additions and 35 deletions

View File

@ -45,13 +45,6 @@ struct dir24_8_tbl {
#define ROUNDUP(x, y) RTE_ALIGN_CEIL(x, (1 << (32 - y))) #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 * static inline void *
get_tbl24_p(struct dir24_8_tbl *dp, uint32_t ip, uint8_t nh_sz) 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,
} }
} }
rte_fib_lookup_fn_t static inline rte_fib_lookup_fn_t
dir24_8_get_lookup_fn(struct rte_fib_conf *fib_conf) get_scalar_fn(enum rte_fib_dir24_8_nh_sz nh_sz)
{ {
enum rte_fib_dir24_8_nh_sz nh_sz = fib_conf->dir24_8.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;
}
}
if (test_lookup == MACRO) { static inline rte_fib_lookup_fn_t
switch (nh_sz) { get_scalar_fn_inlined(enum rte_fib_dir24_8_nh_sz nh_sz)
case RTE_FIB_DIR24_8_1B: {
return dir24_8_lookup_bulk_1b; switch (nh_sz) {
case RTE_FIB_DIR24_8_2B: case RTE_FIB_DIR24_8_1B:
return dir24_8_lookup_bulk_2b; return dir24_8_lookup_bulk_0;
case RTE_FIB_DIR24_8_4B: case RTE_FIB_DIR24_8_2B:
return dir24_8_lookup_bulk_4b; return dir24_8_lookup_bulk_1;
case RTE_FIB_DIR24_8_8B: case RTE_FIB_DIR24_8_4B:
return dir24_8_lookup_bulk_8b; return dir24_8_lookup_bulk_2;
} case RTE_FIB_DIR24_8_8B:
} else if (test_lookup == INLINE) { return dir24_8_lookup_bulk_3;
switch (nh_sz) { default:
case RTE_FIB_DIR24_8_1B: return NULL;
return dir24_8_lookup_bulk_0; }
case RTE_FIB_DIR24_8_2B: }
return dir24_8_lookup_bulk_1;
case RTE_FIB_DIR24_8_4B: rte_fib_lookup_fn_t
return dir24_8_lookup_bulk_2; dir24_8_get_lookup_fn(void *p, enum rte_fib_lookup_type type)
case RTE_FIB_DIR24_8_8B: {
return dir24_8_lookup_bulk_3; enum rte_fib_dir24_8_nh_sz nh_sz;
} struct dir24_8_tbl *dp = p;
} else
if (dp == NULL)
return NULL;
nh_sz = dp->nh_sz;
switch (type) {
case RTE_FIB_LOOKUP_DIR24_8_SCALAR_MACRO:
return get_scalar_fn(nh_sz);
case RTE_FIB_LOOKUP_DIR24_8_SCALAR_INLINE:
return get_scalar_fn_inlined(nh_sz);
case RTE_FIB_LOOKUP_DIR24_8_SCALAR_UNI:
return dir24_8_lookup_bulk_uni; return dir24_8_lookup_bulk_uni;
default:
return NULL;
}
return NULL; return NULL;
} }

View File

@ -22,7 +22,7 @@ void
dir24_8_free(void *p); dir24_8_free(void *p);
rte_fib_lookup_fn_t 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_lookup_type type);
int int
dir24_8_modify(struct rte_fib *fib, uint32_t ip, uint8_t depth, dir24_8_modify(struct rte_fib *fib, uint32_t ip, uint8_t depth,

View File

@ -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); fib->dp = dir24_8_create(dp_name, socket_id, conf);
if (fib->dp == NULL) if (fib->dp == NULL)
return -rte_errno; return -rte_errno;
fib->lookup = dir24_8_get_lookup_fn(conf); fib->lookup = dir24_8_get_lookup_fn(fib->dp,
RTE_FIB_LOOKUP_DIR24_8_SCALAR_MACRO);
fib->modify = dir24_8_modify; fib->modify = dir24_8_modify;
return 0; return 0;
default: default:
@ -317,3 +318,21 @@ rte_fib_get_rib(struct rte_fib *fib)
{ {
return (fib == NULL) ? NULL : fib->rib; return (fib == NULL) ? NULL : fib->rib;
} }
int
rte_fib_select_lookup(struct rte_fib *fib,
enum rte_fib_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;
}
}

View File

@ -57,6 +57,21 @@ enum rte_fib_dir24_8_nh_sz {
RTE_FIB_DIR24_8_8B RTE_FIB_DIR24_8_8B
}; };
/** Type of lookup function implementation */
enum rte_fib_lookup_type {
RTE_FIB_LOOKUP_DIR24_8_SCALAR_MACRO,
/**< Macro based lookup function */
RTE_FIB_LOOKUP_DIR24_8_SCALAR_INLINE,
/**<
* Lookup implementation using inlined functions
* for different next hop sizes
*/
RTE_FIB_LOOKUP_DIR24_8_SCALAR_UNI,
/**<
* Unified lookup function for all next hop sizes
*/
};
/** FIB configuration structure */ /** FIB configuration structure */
struct rte_fib_conf { struct rte_fib_conf {
enum rte_fib_type type; /**< Type of FIB struct */ enum rte_fib_type type; /**< Type of FIB struct */
@ -195,6 +210,22 @@ __rte_experimental
struct rte_rib * struct rte_rib *
rte_fib_get_rib(struct rte_fib *fib); 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
* 0 on success
* -EINVAL on failure
*/
__rte_experimental
int
rte_fib_select_lookup(struct rte_fib *fib, enum rte_fib_lookup_type type);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -9,6 +9,7 @@ EXPERIMENTAL {
rte_fib_lookup_bulk; rte_fib_lookup_bulk;
rte_fib_get_dp; rte_fib_get_dp;
rte_fib_get_rib; rte_fib_get_rib;
rte_fib_select_lookup;
rte_fib6_add; rte_fib6_add;
rte_fib6_create; rte_fib6_create;