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 41ED71BBE for ; Thu, 14 Apr 2016 12:20:24 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id BEA4628F39; Thu, 14 Apr 2016 12:19:40 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: bruce.richardson@intel.com, stephen@networkplumber.org Date: Thu, 14 Apr 2016 12:19:35 +0200 Message-Id: <1460629199-32489-13-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1460629199-32489-1-git-send-email-olivier.matz@6wind.com> References: <1457540381-20274-1-git-send-email-olivier.matz@6wind.com> <1460629199-32489-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH 12/36] mempool: use the list to initialize mempool 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: Thu, 14 Apr 2016 10:20:24 -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 2266f38..5d957b1 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -135,8 +135,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; @@ -153,9 +152,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); @@ -249,37 +245,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. */ @@ -648,7 +634,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.1.4