From: Olivier Matz Date: Wed, 18 May 2016 11:04:37 +0000 (+0200) Subject: mempool: add function to iterate the memory chunks X-Git-Tag: spdx-start~6885 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b18e19a892b11f13699c02d0ea82744d9b79aaaf;p=dpdk.git mempool: add function to iterate the memory chunks In the same model than rte_mempool_obj_iter(), introduce rte_mempool_mem_iter() to iterate the memory chunks attached to the mempool. Signed-off-by: Olivier Matz --- diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 926031896e..cbf5f2b15a 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -246,6 +246,22 @@ rte_mempool_obj_iter(struct rte_mempool *mp, return n; } +/* call mem_cb() for each mempool memory chunk */ +uint32_t +rte_mempool_mem_iter(struct rte_mempool *mp, + rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg) +{ + struct rte_mempool_memhdr *hdr; + unsigned n = 0; + + STAILQ_FOREACH(hdr, &mp->mem_list, next) { + mem_cb(mp, mem_cb_arg, hdr, n); + n++; + } + + return n; +} + /* get the header, trailer and total size of a mempool element. */ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 690928ef00..65455d1953 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -335,6 +335,15 @@ typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp, void *opaque, void *obj, unsigned obj_idx); typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */ +/** + * A memory callback function for mempool. + * + * Used by rte_mempool_mem_iter(). + */ +typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp, + void *opaque, struct rte_mempool_memhdr *memhdr, + unsigned mem_idx); + /** * A mempool constructor callback function. * @@ -605,6 +614,24 @@ rte_dom0_mempool_create(const char *name, unsigned n, unsigned elt_size, uint32_t rte_mempool_obj_iter(struct rte_mempool *mp, rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg); +/** + * Call a function for each mempool memory chunk + * + * Iterate across all memory chunks attached to a rte_mempool and call + * the callback function on it. + * + * @param mp + * A pointer to an initialized mempool. + * @param mem_cb + * A function pointer that is called for each memory chunk. + * @param mem_cb_arg + * An opaque pointer passed to the callback function. + * @return + * Number of memory chunks iterated. + */ +uint32_t rte_mempool_mem_iter(struct rte_mempool *mp, + rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg); + /** * Dump the status of the mempool to the console. * diff --git a/lib/librte_mempool/rte_mempool_version.map b/lib/librte_mempool/rte_mempool_version.map index 72bc967994..7de9f8c5ad 100644 --- a/lib/librte_mempool/rte_mempool_version.map +++ b/lib/librte_mempool/rte_mempool_version.map @@ -22,6 +22,7 @@ DPDK_16.07 { rte_mempool_check_cookies; rte_mempool_obj_iter; + rte_mempool_mem_iter; local: *; } DPDK_2.0;