From a4673d4a813c9ab6355041b763ae1d3da5602736 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Wed, 18 May 2016 13:04:49 +0200 Subject: [PATCH] mempool: create the internal ring when populating Instead of creating the internal ring at mempool creation, do it when populating the mempool with the first memory chunk. The objective here is to simplify the change of external handler when it will be introduced. For instance, this will be possible: mp = rte_mempool_create_empty(...) rte_mempool_set_ext_handler(mp, my_handler) rte_mempool_populate_default() Signed-off-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 12 +++++++++--- lib/librte_mempool/rte_mempool.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index f141139faa..8be3c74c6f 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -326,6 +326,7 @@ rte_mempool_ring_create(struct rte_mempool *mp) return -rte_errno; mp->ring = r; + mp->flags |= MEMPOOL_F_RING_CREATED; return 0; } @@ -375,6 +376,14 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, unsigned i = 0; size_t off; struct rte_mempool_memhdr *memhdr; + int ret; + + /* create the internal ring if not already done */ + if ((mp->flags & MEMPOOL_F_RING_CREATED) == 0) { + ret = rte_mempool_ring_create(mp); + if (ret < 0) + return ret; + } /* mempool is already populated */ if (mp->populated_size >= mp->size) @@ -702,9 +711,6 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, STAILQ_INIT(&mp->elt_list); STAILQ_INIT(&mp->mem_list); - if (rte_mempool_ring_create(mp) < 0) - goto exit_unlock; - /* * local_cache pointer is set even if cache_size is zero. * The local_cache points to just past the elt_pa[] array. diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 8c35b45b6a..2a40aa7a78 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -235,6 +235,7 @@ struct rte_mempool { #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002 /**< Do not align objs on cache lines.*/ #define MEMPOOL_F_SP_PUT 0x0004 /**< Default put is "single-producer".*/ #define MEMPOOL_F_SC_GET 0x0008 /**< Default get is "single-consumer".*/ +#define MEMPOOL_F_RING_CREATED 0x0010 /**< Internal: ring is created */ /** * @internal When debug is enabled, store some statistics. -- 2.20.1