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 409CD8E69 for ; Wed, 18 May 2016 13:05:15 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id E78BF29BA7; Wed, 18 May 2016 13:03:37 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: bruce.richardson@intel.com, stephen@networkplumber.org, keith.wiles@intel.com Date: Wed, 18 May 2016 13:04:32 +0200 Message-Id: <1463569496-31086-12-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1463569496-31086-1-git-send-email-olivier.matz@6wind.com> References: <1460629199-32489-1-git-send-email-olivier.matz@6wind.com> <1463569496-31086-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v3 11/35] mempool: use the list to initialize objects 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, 18 May 2016 11:05:15 -0000 Before this patch, the mempool elements were initialized at the time they were added to the mempool. This patch changes this to do the initialization of all objects once the mempool is populated, using rte_mempool_obj_iter() introduced in previous commits. Thanks to this modification, we are getting closer to a new API that would allow us to do: mempool_init() mempool_populate(mem1) mempool_populate(mem2) mempool_populate(mem3) mempool_init_obj() Signed-off-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 6847fc4..3c7507f 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -136,8 +136,7 @@ typedef void (*rte_mempool_obj_iter_t)(void * /*obj_iter_arg*/, uint32_t /*obj_index */); static void -mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, - rte_mempool_obj_cb_t *obj_init, void *obj_init_arg) +mempool_add_elem(struct rte_mempool *mp, void *obj) { struct rte_mempool_objhdr *hdr; struct rte_mempool_objtlr *tlr __rte_unused; @@ -154,9 +153,6 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, tlr = __mempool_get_trailer(obj); tlr->cookie = RTE_MEMPOOL_TRAILER_COOKIE; #endif - /* call the initializer */ - if (obj_init) - obj_init(mp, obj_init_arg, obj, obj_idx); /* enqueue in ring */ rte_ring_sp_enqueue(mp->ring, obj); @@ -251,37 +247,27 @@ rte_mempool_obj_iter(struct rte_mempool *mp, * Populate mempool with the objects. */ -struct mempool_populate_arg { - struct rte_mempool *mp; - rte_mempool_obj_cb_t *obj_init; - void *obj_init_arg; -}; - static void -mempool_obj_populate(void *arg, void *start, void *end, uint32_t idx) +mempool_obj_populate(void *arg, void *start, void *end, + __rte_unused uint32_t idx) { - struct mempool_populate_arg *pa = arg; + struct rte_mempool *mp = arg; - mempool_add_elem(pa->mp, start, idx, pa->obj_init, pa->obj_init_arg); - pa->mp->elt_va_end = (uintptr_t)end; + mempool_add_elem(mp, start); + mp->elt_va_end = (uintptr_t)end; } static void -mempool_populate(struct rte_mempool *mp, size_t num, size_t align, - rte_mempool_obj_cb_t *obj_init, void *obj_init_arg) +mempool_populate(struct rte_mempool *mp, size_t num, size_t align) { uint32_t elt_sz; - struct mempool_populate_arg arg; elt_sz = mp->elt_size + mp->header_size + mp->trailer_size; - arg.mp = mp; - arg.obj_init = obj_init; - arg.obj_init_arg = obj_init_arg; mp->size = rte_mempool_obj_mem_iter((void *)mp->elt_va_start, num, elt_sz, align, mp->elt_pa, mp->pg_num, mp->pg_shift, - mempool_obj_populate, &arg); + mempool_obj_populate, mp); } /* get the header, trailer and total size of a mempool element. */ @@ -651,7 +637,11 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, if (mp_init) mp_init(mp, mp_init_arg); - mempool_populate(mp, n, 1, obj_init, obj_init_arg); + mempool_populate(mp, n, 1); + + /* call the initializer */ + if (obj_init) + rte_mempool_obj_iter(mp, obj_init, obj_init_arg); te->data = (void *) mp; -- 2.8.0.rc3