From 58f8a1d2e30e0ee6a83e1cdb2b73990b55e5f06c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 2 May 2014 16:42:55 -0700 Subject: [PATCH] memzone: add iterator function When doing diagnostic function, it is useful to have a ability to iterate over all memzones. Signed-off-by: Stephen Hemminger Acked-by: Olivier Matz --- lib/librte_eal/common/eal_common_memzone.c | 17 +++++++++++++++++ lib/librte_eal/common/include/rte_memzone.h | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 2a69c4954e..3918688db6 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -505,3 +505,20 @@ rte_eal_memzone_init(void) return 0; } + +/* Walk all reserved memory zones */ +void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *), + void *arg) +{ + struct rte_mem_config *mcfg; + unsigned i; + + mcfg = rte_eal_get_configuration()->mem_config; + + rte_rwlock_read_lock(&mcfg->mlock); + for (i=0; imemzone[i].addr != NULL) + (*func)(&mcfg->memzone[i], arg); + } + rte_rwlock_read_unlock(&mcfg->mlock); +} diff --git a/lib/librte_eal/common/include/rte_memzone.h b/lib/librte_eal/common/include/rte_memzone.h index 100233b85c..3a000e2867 100644 --- a/lib/librte_eal/common/include/rte_memzone.h +++ b/lib/librte_eal/common/include/rte_memzone.h @@ -252,6 +252,17 @@ const struct rte_memzone *rte_memzone_lookup(const char *name); */ void rte_memzone_dump(FILE *); +/** + * Walk list of all memzones + * + * @param func + * Iterator function + * @param arg + * Argument passed to iterator + */ +void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *arg), + void *arg); + #ifdef __cplusplus } #endif -- 2.20.1