From: Anatoly Burakov Date: Wed, 11 Apr 2018 12:30:05 +0000 (+0100) Subject: mempool: use memseg walk instead of iteration X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=8f7335c1be7ae44fb751cc39fd22b7833468be1b;p=dpdk.git mempool: use memseg walk instead of iteration Reduce dependency on internal details of EAL memory subsystem, and simplify code. Signed-off-by: Anatoly Burakov Tested-by: Santosh Shukla Tested-by: Hemant Agrawal Tested-by: Gowrishankar Muthukrishnan --- diff --git a/lib/librte_mempool/Makefile b/lib/librte_mempool/Makefile index 24e735a3c2..1f85d34002 100644 --- a/lib/librte_mempool/Makefile +++ b/lib/librte_mempool/Makefile @@ -13,6 +13,9 @@ EXPORT_MAP := rte_mempool_version.map LIBABIVER := 3 +# memseg walk is not yet part of stable API +CFLAGS += -DALLOW_EXPERIMENTAL_API + # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool.c SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += rte_mempool_ops.c diff --git a/lib/librte_mempool/meson.build b/lib/librte_mempool/meson.build index 712720ff93..89506c5268 100644 --- a/lib/librte_mempool/meson.build +++ b/lib/librte_mempool/meson.build @@ -5,3 +5,6 @@ version = 3 sources = files('rte_mempool.c', 'rte_mempool_ops.c') headers = files('rte_mempool.h') deps += ['ring'] + +# memseg walk is not yet part of stable API +allow_experimental_apis = true diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 4660cc2f1f..9731d4c8bf 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -99,23 +99,23 @@ static unsigned optimize_object_size(unsigned obj_size) return new_obj_size * RTE_MEMPOOL_ALIGN; } +static int +find_min_pagesz(const struct rte_memseg *ms, void *arg) +{ + size_t *min = arg; + + if (ms->hugepage_sz < *min) + *min = ms->hugepage_sz; + + return 0; +} + static size_t get_min_page_size(void) { - const struct rte_mem_config *mcfg = - rte_eal_get_configuration()->mem_config; - int i; size_t min_pagesz = SIZE_MAX; - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - const struct rte_memseg *ms = &mcfg->memseg[i]; - - if (ms->addr == NULL) - continue; - - if (ms->hugepage_sz < min_pagesz) - min_pagesz = ms->hugepage_sz; - } + rte_memseg_walk(find_min_pagesz, &min_pagesz); return min_pagesz == SIZE_MAX ? (size_t) getpagesize() : min_pagesz; }