From: Olivier Matz Date: Wed, 18 May 2016 11:04:27 +0000 (+0200) Subject: mempool: list objects when added X-Git-Tag: spdx-start~6895 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b1bedacb074b1ad750a5b307866f90f0829ca9bd;p=dpdk.git mempool: list objects when added Introduce a list entry in object header so they can be listed and browsed. The objective is to introduce a more simple way to browse the elements of a mempool. The next commits will update rte_mempool_obj_iter() to use this list, and remove the previous complex implementation. Signed-off-by: Olivier Matz --- diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index ca609f0d2e..c29a4c7f4c 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -138,6 +138,7 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, /* set mempool ptr in header */ hdr = RTE_PTR_SUB(obj, sizeof(*hdr)); hdr->mp = mp; + STAILQ_INSERT_TAIL(&mp->elt_list, hdr, next); #ifdef RTE_LIBRTE_MEMPOOL_DEBUG hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE2; @@ -587,6 +588,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, mp->cache_size = cache_size; mp->cache_flushthresh = CALC_CACHE_FLUSHTHRESH(cache_size); mp->private_data_size = private_data_size; + STAILQ_INIT(&mp->elt_list); /* * local_cache pointer is set even if cache_size is zero. diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index d35833a0e0..acc75f8ef1 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -150,17 +150,24 @@ struct rte_mempool_objsz { * Mempool object header structure * * Each object stored in mempools are prefixed by this header structure, - * it allows to retrieve the mempool pointer from the object. When debug - * is enabled, a cookie is also added in this structure preventing - * corruptions and double-frees. + * it allows to retrieve the mempool pointer from the object and to + * iterate on all objects attached to a mempool. When debug is enabled, + * a cookie is also added in this structure preventing corruptions and + * double-frees. */ struct rte_mempool_objhdr { + STAILQ_ENTRY(rte_mempool_objhdr) next; /**< Next in list. */ struct rte_mempool *mp; /**< The mempool owning the object. */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG uint64_t cookie; /**< Debug cookie. */ #endif }; +/** + * A list of object headers type + */ +STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr); + /** * Mempool object trailer structure * @@ -194,6 +201,8 @@ struct rte_mempool { struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */ + struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */ + #ifdef RTE_LIBRTE_MEMPOOL_DEBUG /** Per-lcore statistics. */ struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];