From 356cb732d5381140f42ef8b55492339579854986 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 2 May 2014 16:42:54 -0700 Subject: [PATCH] mempool: add iterator function Add function to iterate over mempool. Useful for diagnostic code that wants to look at mempool usage patterns. Signed-off-by: Stephen Hemminger Acked-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 21 +++++++++++++++++++++ lib/librte_mempool/rte_mempool.h | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index f6cbc7c441..9a297e6bba 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -856,3 +856,24 @@ rte_mempool_lookup(const char *name) return mp; } + +void rte_mempool_walk(void (*func)(const struct rte_mempool *, void *), + void *arg) +{ + struct rte_mempool *mp = NULL; + struct rte_mempool_list *mempool_list; + + if ((mempool_list = + RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) { + rte_errno = E_RTE_NO_TAILQ; + return; + } + + rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK); + + TAILQ_FOREACH(mp, mempool_list, next) { + (*func)(mp, arg); + } + + rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK); +} diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 9739d7cce0..3fe569290e 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -1380,6 +1380,17 @@ size_t rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz, ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz, const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift); +/** + * Walk list of all memory pools + * + * @param func + * Iterator function + * @param arg + * Argument passed to iterator + */ +void rte_mempool_walk(void (*func)(const struct rte_mempool *, void *arg), + void *arg); + #ifdef __cplusplus } #endif -- 2.20.1