[dpdk-dev] [PATCH 3/5] mempool: add walk iterator

Stephen Hemminger stephen at networkplumber.org
Sat May 3 01:42:54 CEST 2014


Add function to iterate over mempool.
Useful for diagnostic code that wants to look at mempool usage patterns.

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>


--- a/lib/librte_mempool/rte_mempool.c	2014-05-02 16:31:13.279574637 -0700
+++ b/lib/librte_mempool/rte_mempool.c	2014-05-02 16:31:13.279574637 -0700
@@ -857,3 +857,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);
+}
--- a/lib/librte_mempool/rte_mempool.h	2014-05-02 16:31:13.279574637 -0700
+++ b/lib/librte_mempool/rte_mempool.h	2014-05-02 16:31:13.279574637 -0700
@@ -1374,6 +1374,17 @@ size_t rte_mempool_xmem_size(uint32_t el
 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



More information about the dev mailing list