From: Stephen Hemminger Date: Fri, 2 May 2014 23:42:54 +0000 (-0700) Subject: mempool: add iterator function X-Git-Tag: spdx-start~10818 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=356cb732d5381140f42ef8b55492339579854986;p=dpdk.git 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 --- 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