[dpdk-dev] [RFC 29/35] mempool: create the internal ring when populating

Olivier Matz olivier.matz at 6wind.com
Wed Mar 9 17:19:35 CET 2016


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 <olivier.matz at 6wind.com>
---
 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 0f4cb4e..2546740 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;
 }
 
@@ -374,6 +375,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)
@@ -698,9 +707,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 47743a6..e0549c6 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -234,6 +234,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.1.4



More information about the dev mailing list