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 <stephen@networkplumber.org>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
Stephen Hemminger 2014-05-02 16:42:54 -07:00 committed by Thomas Monjalon
parent 58f8a1d2e3
commit 356cb732d5
2 changed files with 32 additions and 0 deletions

View File

@ -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);
}

View File

@ -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