mempool: use memseg walk instead of iteration
authorAnatoly Burakov <anatoly.burakov@intel.com>
Wed, 11 Apr 2018 12:30:05 +0000 (13:30 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 11 Apr 2018 17:49:16 +0000 (19:49 +0200)
Reduce dependency on internal details of EAL memory subsystem, and
simplify code.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Tested-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
Tested-by: Hemant Agrawal <hemant.agrawal@nxp.com>
Tested-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
lib/librte_mempool/Makefile
lib/librte_mempool/meson.build
lib/librte_mempool/rte_mempool.c

index 24e735a..1f85d34 100644 (file)
@@ -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
index 712720f..89506c5 100644 (file)
@@ -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
index 4660cc2..9731d4c 100644 (file)
@@ -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;
 }