From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id EC03437B2 for ; Wed, 9 Mar 2016 17:22:14 +0100 (CET) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id E4BFA249A0 for ; Wed, 9 Mar 2016 17:21:31 +0100 (CET) From: Olivier Matz To: dev@dpdk.org Date: Wed, 9 Mar 2016 17:19:19 +0100 Message-Id: <1457540381-20274-14-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457540381-20274-1-git-send-email-olivier.matz@6wind.com> References: <1457540381-20274-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [RFC 13/35] mempool: create the internal ring in a specific function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2016 16:22:15 -0000 This makes the code of rte_mempool_create() clearer, and it will make the introduction of external mempool handler easier (in another patch series). Indeed, this function contains the specific part when a ring is used, but it could be replaced by something else in the future. This commit also adds a socket_id field in the mempool structure that is used by this new function. Signed-off-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 55 +++++++++++++++++++++++++--------------- lib/librte_mempool/rte_mempool.h | 1 + 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 4145e2e..d533484 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -431,6 +431,35 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size, MEMPOOL_PG_SHIFT_MAX); } +/* create the internal ring */ +static int +rte_mempool_ring_create(struct rte_mempool *mp) +{ + int rg_flags = 0; + char rg_name[RTE_RING_NAMESIZE]; + struct rte_ring *r; + + snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, mp->name); + + /* ring flags */ + if (mp->flags & MEMPOOL_F_SP_PUT) + rg_flags |= RING_F_SP_ENQ; + if (mp->flags & MEMPOOL_F_SC_GET) + rg_flags |= RING_F_SC_DEQ; + + /* Allocate the ring that will be used to store objects. + * Ring functions will return appropriate errors if we are + * running as a secondary process etc., so no checks made + * in this function for that condition. */ + r = rte_ring_create(rg_name, rte_align32pow2(mp->size + 1), + mp->socket_id, rg_flags); + if (r == NULL) + return -rte_errno; + + mp->ring = r; + return 0; +} + /* * Create the mempool over already allocated chunk of memory. * That external memory buffer can consists of physically disjoint pages. @@ -447,15 +476,12 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift) { char mz_name[RTE_MEMZONE_NAMESIZE]; - char rg_name[RTE_RING_NAMESIZE]; struct rte_mempool_list *mempool_list; struct rte_mempool *mp = NULL; struct rte_tailq_entry *te = NULL; - struct rte_ring *r = NULL; const struct rte_memzone *mz; size_t mempool_size; int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY; - int rg_flags = 0; void *obj; struct rte_mempool_objsz objsz; void *startaddr; @@ -498,12 +524,6 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, if (flags & MEMPOOL_F_NO_CACHE_ALIGN) flags |= MEMPOOL_F_NO_SPREAD; - /* ring flags */ - if (flags & MEMPOOL_F_SP_PUT) - rg_flags |= RING_F_SP_ENQ; - if (flags & MEMPOOL_F_SC_GET) - rg_flags |= RING_F_SC_DEQ; - /* calculate mempool object sizes. */ if (!rte_mempool_calc_obj_size(elt_size, flags, &objsz)) { rte_errno = EINVAL; @@ -512,15 +532,6 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK); - /* allocate the ring that will be used to store objects */ - /* Ring functions will return appropriate errors if we are - * running as a secondary process etc., so no checks made - * in this function for that condition */ - snprintf(rg_name, sizeof(rg_name), RTE_MEMPOOL_MZ_FORMAT, name); - r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags); - if (r == NULL) - goto exit_unlock; - /* * reserve a memory zone for this mempool: private data is * cache-aligned @@ -589,7 +600,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, memset(mp, 0, sizeof(*mp)); snprintf(mp->name, sizeof(mp->name), "%s", name); mp->phys_addr = mz->phys_addr; - mp->ring = r; + mp->socket_id = socket_id; mp->size = n; mp->flags = flags; mp->elt_size = objsz.elt_size; @@ -600,6 +611,9 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, mp->private_data_size = private_data_size; STAILQ_INIT(&mp->elt_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. @@ -651,7 +665,8 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, exit_unlock: rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK); - rte_ring_free(r); + if (mp != NULL) + rte_ring_free(mp->ring); rte_free(te); return NULL; diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index ca37120..5b760f0 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -188,6 +188,7 @@ struct rte_mempool { struct rte_ring *ring; /**< Ring to store objects. */ phys_addr_t phys_addr; /**< Phys. addr. of mempool struct. */ int flags; /**< Flags of the mempool. */ + int socket_id; /**< Socket id passed at mempool creation. */ uint32_t size; /**< Size of the mempool. */ uint32_t cache_size; /**< Size of per-lcore local cache. */ uint32_t cache_flushthresh; -- 2.1.4