diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 0d9707c3479..ae1b6ec0f55 100755 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -386,7 +386,7 @@ rte_eal_memzone_init(void) } rte_rwlock_write_unlock(&mcfg->mlock); - + rte_sort_mempool_ops(); return ret; } diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index f81152af965..a22850b1507 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -909,6 +909,12 @@ rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, */ int rte_mempool_register_ops(const struct rte_mempool_ops *ops); +/** + * Sort global array rte_mempool_ops_table.ops[] . + * Used by rte_eal_memzone_init() + */ +int rte_sort_mempool_ops(void); + /** * Macro to statically register the ops of a mempool handler. * Note that the rte_mempool_register_ops fails silently here when diff --git a/lib/librte_mempool/rte_mempool_ops.c b/lib/librte_mempool/rte_mempool_ops.c old mode 100644 new mode 100755 index 22c5251eb06..8e10488a471 --- a/lib/librte_mempool/rte_mempool_ops.c +++ b/lib/librte_mempool/rte_mempool_ops.c @@ -68,6 +68,37 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h) return ops_index; } + +int rte_sort_mempool_ops(void) +{ + /* same with rte_mempool_ops.name */ + static const char *memops_name[RTE_MEMPOOL_MAX_OPS_IDX] = { + "ring_mp_mc", "ring_sp_sc", "ring_mp_sc", "ring_sp_mc", + "stack", "lf_stack", "octeontx2_npa", "octeontx_fpavf", + "dpaa2", "dpaa", "bucket", + }; + struct rte_mempool_ops_table tmp_mempool_ops_table = { + .sl = rte_mempool_ops_table.sl, + .num_ops = rte_mempool_ops_table.num_ops + }; + uint32_t i = 0, j= 0; + struct rte_mempool_ops *ops = NULL; + for (i = 0; i < 16; i++) { + const char* name = memops_name[i]; + if(name && strlen(name)) { + for(j = 0; j < rte_mempool_ops_table.num_ops; j++) { + if(strcmp(name, rte_mempool_ops_table.ops[j].name)) + continue; + ops = &rte_mempool_ops_table.ops[j]; + memcpy(&tmp_mempool_ops_table.ops[i], ops, sizeof(*ops)); + break; + } + } + } + memcpy(&rte_mempool_ops_table, &tmp_mempool_ops_table, sizeof(tmp_mempool_ops_table)); + return 0; +} + /* wrapper to allocate an external mempool's private (pool) data. */ int rte_mempool_ops_alloc(struct rte_mempool *mp)