From mboxrd@z Thu Jan 1 00:00:00 1970 From: Santosh Shukla Subject: [PATCH v2 4/6] mempool: add mempool arg in xmem size and usage Date: Thu, 13 Jul 2017 09:32:53 +0000 Message-ID: <20170713093255.13986-5-santosh.shukla@caviumnetworks.com> References: <20170621173248.1313-1-santosh.shukla@caviumnetworks.com> <20170713093255.13986-1-santosh.shukla@caviumnetworks.com> Mime-Version: 1.0 Content-Type: text/plain Cc: jerin.jacob@caviumnetworks.com, hemant.agrawal@nxp.com, Santosh Shukla To: thomas@monjalon.net, dev@dpdk.org, olivier.matz@6wind.com Return-path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0075.outbound.protection.outlook.com [104.47.32.75]) by dpdk.org (Postfix) with ESMTP id 3C3C65A98 for ; Thu, 13 Jul 2017 11:34:07 +0200 (CEST) In-Reply-To: <20170713093255.13986-1-santosh.shukla@caviumnetworks.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" xmem_size and xmem_usage need to know the status of mp->flag. Following patch will make use of that. Signed-off-by: Santosh Shukla --- v1 -- v2: - added new mempool param in xmem_size/usage, Per deprecation notice [1] and discussion based on thread [2] [1] http://dpdk.org/dev/patchwork/patch/26872/ [2] http://dpdk.org/dev/patchwork/patch/25605/ drivers/net/xenvirt/rte_mempool_gntalloc.c | 5 +++-- lib/librte_mempool/rte_mempool.c | 10 ++++++---- lib/librte_mempool/rte_mempool.h | 8 ++++++-- test/test/test_mempool.c | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/net/xenvirt/rte_mempool_gntalloc.c b/drivers/net/xenvirt/rte_mempool_gntalloc.c index 73e82f808..ee0bda459 100644 --- a/drivers/net/xenvirt/rte_mempool_gntalloc.c +++ b/drivers/net/xenvirt/rte_mempool_gntalloc.c @@ -114,7 +114,7 @@ _create_mempool(const char *name, unsigned elt_num, unsigned elt_size, pg_shift = rte_bsf32(pg_sz); rte_mempool_calc_obj_size(elt_size, flags, &objsz); - sz = rte_mempool_xmem_size(elt_num, objsz.total_size, pg_shift); + sz = rte_mempool_xmem_size(elt_num, objsz.total_size, pg_shift, NULL); pg_num = sz >> pg_shift; pa_arr = calloc(pg_num, sizeof(pa_arr[0])); @@ -162,7 +162,8 @@ _create_mempool(const char *name, unsigned elt_num, unsigned elt_size, * Check that allocated size is big enough to hold elt_num * objects and a calcualte how many bytes are actually required. */ - usz = rte_mempool_xmem_usage(va, elt_num, objsz.total_size, pa_arr, pg_num, pg_shift); + usz = rte_mempool_xmem_usage(va, elt_num, objsz.total_size, pa_arr, + pg_num, pg_shift, NULL); if (usz < 0) { mp = NULL; i = pg_num; diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 65a98c046..a6975aeda 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -238,7 +238,8 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, * Calculate maximum amount of memory required to store given number of objects. */ size_t -rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift) +rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift, + __rte_unused const struct rte_mempool *mp) { size_t obj_per_page, pg_num, pg_sz; @@ -264,13 +265,14 @@ rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift) ssize_t rte_mempool_xmem_usage(__rte_unused void *vaddr, uint32_t elt_num, size_t total_elt_sz, const phys_addr_t paddr[], uint32_t pg_num, - uint32_t pg_shift) + uint32_t pg_shift, __rte_unused const struct rte_mempool *mp) { uint32_t elt_cnt = 0; phys_addr_t start, end; uint32_t paddr_idx; size_t pg_sz = (size_t)1 << pg_shift; + /* if paddr is NULL, assume contiguous memory */ if (paddr == NULL) { start = 0; @@ -556,7 +558,7 @@ rte_mempool_populate_default(struct rte_mempool *mp) total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size; for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) { - size = rte_mempool_xmem_size(n, total_elt_sz, pg_shift); + size = rte_mempool_xmem_size(n, total_elt_sz, pg_shift, mp); ret = snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id); @@ -613,7 +615,7 @@ get_anon_size(const struct rte_mempool *mp) pg_sz = getpagesize(); pg_shift = rte_bsf32(pg_sz); total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size; - size = rte_mempool_xmem_size(mp->size, total_elt_sz, pg_shift); + size = rte_mempool_xmem_size(mp->size, total_elt_sz, pg_shift, mp); return size; } diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index ca5634eaf..a4bfdb56e 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -1497,11 +1497,13 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, * by rte_mempool_calc_obj_size(). * @param pg_shift * LOG2 of the physical pages size. If set to 0, ignore page boundaries. + * @param mp + * A pointer to the mempool structure. * @return * Required memory size aligned at page boundary. */ size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, - uint32_t pg_shift); + uint32_t pg_shift, const struct rte_mempool *mp); /** * Get the size of memory required to store mempool elements. @@ -1524,6 +1526,8 @@ size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, * Number of elements in the paddr array. * @param pg_shift * LOG2 of the physical pages size. + * @param mp + * A pointer to the mempool structure. * @return * On success, the number of bytes needed to store given number of * objects, aligned to the given page size. If the provided memory @@ -1532,7 +1536,7 @@ size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, */ ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t total_elt_sz, const phys_addr_t paddr[], uint32_t pg_num, - uint32_t pg_shift); + uint32_t pg_shift, const struct rte_mempool *mp); /** * Walk list of all memory pools diff --git a/test/test/test_mempool.c b/test/test/test_mempool.c index 47dc3ac5f..1eb81081c 100644 --- a/test/test/test_mempool.c +++ b/test/test/test_mempool.c @@ -485,10 +485,10 @@ test_mempool_xmem_misc(void) elt_num = MAX_KEEP; total_size = rte_mempool_calc_obj_size(MEMPOOL_ELT_SIZE, 0, NULL); - sz = rte_mempool_xmem_size(elt_num, total_size, MEMPOOL_PG_SHIFT_MAX); + sz = rte_mempool_xmem_size(elt_num, total_size, MEMPOOL_PG_SHIFT_MAX, NULL); usz = rte_mempool_xmem_usage(NULL, elt_num, total_size, 0, 1, - MEMPOOL_PG_SHIFT_MAX); + MEMPOOL_PG_SHIFT_MAX, NULL); if (sz != (size_t)usz) { printf("failure @ %s: rte_mempool_xmem_usage(%u, %u) " -- 2.13.0