All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, stephen@networkplumber.org
Subject: [PATCH 02/36] mempool: replace elt_size by total_elt_size
Date: Thu, 14 Apr 2016 12:19:25 +0200	[thread overview]
Message-ID: <1460629199-32489-3-git-send-email-olivier.matz@6wind.com> (raw)
In-Reply-To: <1460629199-32489-1-git-send-email-olivier.matz@6wind.com>

In some mempool functions, we use the size of the elements as arguments or in
variables. There is a confusion between the size including or not including
the header and trailer.

To avoid this confusion:
- update the API documentation
- rename the variables and argument names as "elt_size" when the size does not
  include the header and trailer, or else as "total_elt_size".

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 lib/librte_mempool/rte_mempool.c | 21 +++++++++++----------
 lib/librte_mempool/rte_mempool.h | 19 +++++++++++--------
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index ce78476..90b5b1b 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -156,13 +156,13 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx,
  *
  * Given the pointer to the memory, and its topology in physical memory
  * (the physical addresses table), iterate through the "elt_num" objects
- * of size "total_elt_sz" aligned at "align". For each object in this memory
+ * of size "elt_sz" aligned at "align". For each object in this memory
  * chunk, invoke a callback. It returns the effective number of objects
  * in this memory. */
 uint32_t
-rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align,
-	const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
-	rte_mempool_obj_iter_t obj_iter, void *obj_iter_arg)
+rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t total_elt_sz,
+	size_t align, const phys_addr_t paddr[], uint32_t pg_num,
+	uint32_t pg_shift, rte_mempool_obj_iter_t obj_iter, void *obj_iter_arg)
 {
 	uint32_t i, j, k;
 	uint32_t pgn, pgf;
@@ -178,7 +178,7 @@ rte_mempool_obj_iter(void *vaddr, uint32_t elt_num, size_t elt_sz, size_t align,
 	while (i != elt_num && j != pg_num) {
 
 		start = RTE_ALIGN_CEIL(va, align);
-		end = start + elt_sz;
+		end = start + total_elt_sz;
 
 		/* index of the first page for the next element. */
 		pgf = (end >> pg_shift) - (start >> pg_shift);
@@ -255,6 +255,7 @@ mempool_populate(struct rte_mempool *mp, size_t num, size_t align,
 		mempool_obj_populate, &arg);
 }
 
+/* get the header, trailer and total size of a mempool element. */
 uint32_t
 rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
 	struct rte_mempool_objsz *sz)
@@ -332,17 +333,17 @@ 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 elt_sz, uint32_t pg_shift)
+rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift)
 {
 	size_t n, pg_num, pg_sz, sz;
 
 	pg_sz = (size_t)1 << pg_shift;
 
-	if ((n = pg_sz / elt_sz) > 0) {
+	if ((n = pg_sz / total_elt_sz) > 0) {
 		pg_num = (elt_num + n - 1) / n;
 		sz = pg_num << pg_shift;
 	} else {
-		sz = RTE_ALIGN_CEIL(elt_sz, pg_sz) * elt_num;
+		sz = RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * elt_num;
 	}
 
 	return sz;
@@ -362,7 +363,7 @@ mempool_lelem_iter(void *arg, __rte_unused void *start, void *end,
  * given memory footprint to store required number of elements.
  */
 ssize_t
-rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
+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 n;
@@ -373,7 +374,7 @@ rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
 	va = (uintptr_t)vaddr;
 	uv = va;
 
-	if ((n = rte_mempool_obj_iter(vaddr, elt_num, elt_sz, 1,
+	if ((n = rte_mempool_obj_iter(vaddr, elt_num, total_elt_sz, 1,
 			paddr, pg_num, pg_shift, mempool_lelem_iter,
 			&uv)) != elt_num) {
 		return -(ssize_t)n;
diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index bd78df5..ca4657f 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -1289,7 +1289,7 @@ struct rte_mempool *rte_mempool_lookup(const char *name);
  * calculates header, trailer, body and total sizes of the mempool object.
  *
  * @param elt_size
- *   The size of each element.
+ *   The size of each element, without header and trailer.
  * @param flags
  *   The flags used for the mempool creation.
  *   Consult rte_mempool_create() for more information about possible values.
@@ -1315,14 +1315,15 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
  *
  * @param elt_num
  *   Number of elements.
- * @param elt_sz
- *   The size of each element.
+ * @param total_elt_sz
+ *   The size of each element, including header and trailer, as returned
+ *   by rte_mempool_calc_obj_size().
  * @param pg_shift
  *   LOG2 of the physical pages size.
  * @return
  *   Required memory size aligned at page boundary.
  */
-size_t rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz,
+size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz,
 	uint32_t pg_shift);
 
 /**
@@ -1336,8 +1337,9 @@ size_t rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz,
  *   Will be used to store mempool objects.
  * @param elt_num
  *   Number of elements.
- * @param elt_sz
- *   The size of each element.
+ * @param total_elt_sz
+ *   The size of each element, including header and trailer, as returned
+ *   by rte_mempool_calc_obj_size().
  * @param paddr
  *   Array of physical addresses of the pages that comprises given memory
  *   buffer.
@@ -1351,8 +1353,9 @@ size_t rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz,
  *   buffer is too small, return a negative value whose absolute value
  *   is the actual number of elements that can be stored in that buffer.
  */
-ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
-	const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift);
+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);
 
 /**
  * Walk list of all memory pools
-- 
2.1.4

  parent reply	other threads:[~2016-04-14 10:20 UTC|newest]

Thread overview: 150+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-09 16:19 [RFC 00/35] mempool: rework memory allocation Olivier Matz
2016-03-09 16:19 ` [RFC 01/35] mempool: fix comments and style Olivier Matz
2016-03-09 16:19 ` [RFC 02/35] mempool: replace elt_size by total_elt_size Olivier Matz
2016-03-09 16:19 ` [RFC 03/35] mempool: uninline function to check cookies Olivier Matz
2016-03-09 16:19 ` [RFC 04/35] mempool: use sizeof to get the size of header and trailer Olivier Matz
2016-03-09 16:19 ` [RFC 05/35] mempool: rename mempool_obj_ctor_t as mempool_obj_cb_t Olivier Matz
2016-03-09 16:19 ` [RFC 06/35] mempool: update library version Olivier Matz
2016-03-09 16:19 ` [RFC 07/35] mempool: list objects when added in the mempool Olivier Matz
2016-03-09 16:19 ` [RFC 08/35] mempool: remove const attribute in mempool_walk Olivier Matz
2016-03-09 16:19 ` [RFC 09/35] mempool: use the list to iterate the mempool elements Olivier Matz
2016-03-09 16:19 ` [RFC 10/35] eal: introduce RTE_DECONST macro Olivier Matz
2016-03-09 18:53   ` Stephen Hemminger
2016-03-09 20:47     ` Olivier MATZ
2016-03-09 21:01       ` Stephen Hemminger
2016-03-10  8:11         ` Olivier MATZ
2016-03-11 21:47           ` Stephen Hemminger
2016-03-09 21:22       ` Bruce Richardson
2016-03-10  8:29         ` Olivier MATZ
2016-03-10  9:26           ` Bruce Richardson
2016-03-10 10:05             ` Olivier MATZ
2016-03-09 16:19 ` [RFC 11/35] mempool: use the list to audit all elements Olivier Matz
2016-03-09 16:19 ` [RFC 12/35] mempool: use the list to initialize mempool objects Olivier Matz
2016-03-09 16:19 ` [RFC 13/35] mempool: create the internal ring in a specific function Olivier Matz
2016-03-09 16:19 ` [RFC 14/35] mempool: store physaddr in mempool objects Olivier Matz
2016-03-09 16:19 ` [RFC 15/35] mempool: remove MEMPOOL_IS_CONTIG() Olivier Matz
2016-03-09 16:19 ` [RFC 16/35] mempool: store memory chunks in a list Olivier Matz
2016-03-09 16:19 ` [RFC 17/35] mempool: new function to iterate the memory chunks Olivier Matz
2016-03-09 16:19 ` [RFC 18/35] mempool: simplify xmem_usage Olivier Matz
2016-03-09 16:19 ` [RFC 19/35] mempool: introduce a free callback for memory chunks Olivier Matz
2016-03-09 16:19 ` [RFC 20/35] mempool: make page size optional when getting xmem size Olivier Matz
2016-03-09 16:19 ` [RFC 21/35] mempool: default allocation in several memory chunks Olivier Matz
2016-03-09 16:19 ` [RFC 22/35] eal: lock memory when using no-huge Olivier Matz
2016-03-09 16:19 ` [RFC 23/35] mempool: support no-hugepage mode Olivier Matz
2016-03-09 16:19 ` [RFC 24/35] mempool: replace mempool physaddr by a memzone pointer Olivier Matz
2016-03-09 16:19 ` [RFC 25/35] mempool: introduce a function to free a mempool Olivier Matz
2016-03-09 16:19 ` [RFC 26/35] mempool: introduce a function to create an empty mempool Olivier Matz
2016-03-09 16:19 ` [RFC 27/35] eal/xen: return machine address without knowing memseg id Olivier Matz
2016-03-09 16:19 ` [RFC 28/35] mempool: rework support of xen dom0 Olivier Matz
2016-03-09 16:19 ` [RFC 29/35] mempool: create the internal ring when populating Olivier Matz
2016-03-09 16:19 ` [RFC 30/35] mempool: populate a mempool with anonymous memory Olivier Matz
2016-03-09 16:19 ` [RFC 31/35] test-pmd: remove specific anon mempool code Olivier Matz
2016-03-09 16:19 ` [RFC 32/35] mempool: make mempool populate and free api public Olivier Matz
2016-03-09 16:19 ` [RFC 33/35] mem: avoid memzone/mempool/ring name truncation Olivier Matz
2016-03-09 16:19 ` [RFC 34/35] mempool: new flag when phys contig mem is not needed Olivier Matz
2016-03-09 16:19 ` [RFC 35/35] mempool: update copyright Olivier Matz
2016-03-09 18:52   ` Stephen Hemminger
2016-03-10 14:57     ` Panu Matilainen
2016-03-09 16:44 ` [RFC 00/35] mempool: rework memory allocation Olivier MATZ
2016-03-17  9:05 ` [PATCH] doc: mempool ABI deprecation notice for 16.07 Olivier Matz
2016-04-04 14:38   ` Thomas Monjalon
2016-04-05  9:27     ` Hunt, David
2016-04-05 14:08       ` Wiles, Keith
2016-04-05 15:17         ` Thomas Monjalon
2016-04-14 10:19 ` [PATCH 00/36] mempool: rework memory allocation Olivier Matz
2016-04-14 10:19   ` [PATCH 01/36] mempool: fix comments and style Olivier Matz
2016-04-14 14:15     ` Wiles, Keith
2016-04-14 10:19   ` Olivier Matz [this message]
2016-04-14 14:18     ` [PATCH 02/36] mempool: replace elt_size by total_elt_size Wiles, Keith
2016-04-14 10:19   ` [PATCH 03/36] mempool: uninline function to check cookies Olivier Matz
2016-04-14 10:19   ` [PATCH 04/36] mempool: use sizeof to get the size of header and trailer Olivier Matz
2016-04-14 10:19   ` [PATCH 05/36] mempool: rename mempool_obj_ctor_t as mempool_obj_cb_t Olivier Matz
2016-04-14 10:19   ` [PATCH 06/36] mempool: update library version Olivier Matz
2016-04-15 12:38     ` Olivier Matz
2016-04-14 10:19   ` [PATCH 07/36] mempool: list objects when added in the mempool Olivier Matz
2016-04-14 10:19   ` [PATCH 08/36] mempool: remove const attribute in mempool_walk Olivier Matz
2016-04-14 10:19   ` [PATCH 09/36] mempool: remove const qualifier in dump and audit Olivier Matz
2016-04-14 10:19   ` [PATCH 10/36] mempool: use the list to iterate the mempool elements Olivier Matz
2016-04-14 15:33     ` Wiles, Keith
2016-04-15  7:31       ` Olivier Matz
2016-04-15 13:19         ` Wiles, Keith
2016-05-11 10:02     ` [PATCH v2 " Olivier Matz
2016-04-14 10:19   ` [PATCH 11/36] mempool: use the list to audit all elements Olivier Matz
2016-04-14 10:19   ` [PATCH 12/36] mempool: use the list to initialize mempool objects Olivier Matz
2016-04-14 10:19   ` [PATCH 13/36] mempool: create the internal ring in a specific function Olivier Matz
2016-04-14 10:19   ` [PATCH 14/36] mempool: store physaddr in mempool objects Olivier Matz
2016-04-14 15:40     ` Wiles, Keith
2016-04-15  7:34       ` Olivier Matz
2016-04-14 10:19   ` [PATCH 15/36] mempool: remove MEMPOOL_IS_CONTIG() Olivier Matz
2016-04-14 10:19   ` [PATCH 16/36] mempool: store memory chunks in a list Olivier Matz
2016-04-14 10:19   ` [PATCH 17/36] mempool: new function to iterate the memory chunks Olivier Matz
2016-04-14 10:19   ` [PATCH 18/36] mempool: simplify xmem_usage Olivier Matz
2016-04-14 10:19   ` [PATCH 19/36] mempool: introduce a free callback for memory chunks Olivier Matz
2016-04-14 10:19   ` [PATCH 20/36] mempool: make page size optional when getting xmem size Olivier Matz
2016-04-14 10:19   ` [PATCH 21/36] mempool: default allocation in several memory chunks Olivier Matz
2016-04-14 10:19   ` [PATCH 22/36] eal: lock memory when using no-huge Olivier Matz
2016-04-14 10:19   ` [PATCH 23/36] mempool: support no-hugepage mode Olivier Matz
2016-04-14 10:19   ` [PATCH 24/36] mempool: replace mempool physaddr by a memzone pointer Olivier Matz
2016-04-14 10:19   ` [PATCH 25/36] mempool: introduce a function to free a mempool Olivier Matz
2016-04-14 10:19   ` [PATCH 26/36] mempool: introduce a function to create an empty mempool Olivier Matz
2016-04-14 15:57     ` Wiles, Keith
2016-04-15  7:42       ` Olivier Matz
2016-04-15 13:26         ` Wiles, Keith
2016-04-14 10:19   ` [PATCH 27/36] eal/xen: return machine address without knowing memseg id Olivier Matz
2016-04-14 10:19   ` [PATCH 28/36] mempool: rework support of xen dom0 Olivier Matz
2016-04-14 10:19   ` [PATCH 29/36] mempool: create the internal ring when populating Olivier Matz
2016-04-14 10:19   ` [PATCH 30/36] mempool: populate a mempool with anonymous memory Olivier Matz
2016-04-14 10:19   ` [PATCH 31/36] mempool: make mempool populate and free api public Olivier Matz
2016-04-14 10:19   ` [PATCH 32/36] test-pmd: remove specific anon mempool code Olivier Matz
2016-04-14 10:19   ` [PATCH 33/36] mem: avoid memzone/mempool/ring name truncation Olivier Matz
2016-04-14 10:19   ` [PATCH 34/36] mempool: new flag when phys contig mem is not needed Olivier Matz
2016-04-14 10:19   ` [PATCH 35/36] app/test: rework mempool test Olivier Matz
2016-04-14 10:19   ` [PATCH 36/36] mempool: update copyright Olivier Matz
2016-04-14 13:50   ` [PATCH 00/36] mempool: rework memory allocation Wiles, Keith
2016-04-14 14:01     ` Olivier MATZ
2016-04-14 14:03       ` Wiles, Keith
2016-04-14 14:20       ` Hunt, David
2016-05-18 11:04   ` [PATCH v3 00/35] " Olivier Matz
2016-05-18 11:04     ` [PATCH v3 01/35] mempool: rework comments and style Olivier Matz
2016-05-18 11:04     ` [PATCH v3 02/35] mempool: rename element size variables Olivier Matz
2016-05-18 11:04     ` [PATCH v3 03/35] mempool: uninline function to check cookies Olivier Matz
2016-05-18 11:04     ` [PATCH v3 04/35] mempool: use sizeof to get the size of header and trailer Olivier Matz
2016-05-18 11:04     ` [PATCH v3 05/35] mempool: rename object constructor typedef Olivier Matz
2016-05-18 11:04     ` [PATCH v3 06/35] mempool: list objects when added Olivier Matz
2016-05-18 11:04     ` [PATCH v3 07/35] mempool: remove const qualifier when browsing pools Olivier Matz
2016-05-18 11:04     ` [PATCH v3 08/35] mempool: remove const qualifier in dump and audit Olivier Matz
2016-05-18 11:04     ` [PATCH v3 09/35] mempool: use the list to iterate the elements Olivier Matz
2016-05-18 11:04     ` [PATCH v3 10/35] mempool: use the list to audit all elements Olivier Matz
2016-05-18 11:04     ` [PATCH v3 11/35] mempool: use the list to initialize objects Olivier Matz
2016-05-18 11:04     ` [PATCH v3 12/35] mempool: create internal ring in a specific function Olivier Matz
2016-05-18 11:04     ` [PATCH v3 13/35] mempool: store physical address in objects Olivier Matz
2016-05-25 17:51       ` Jain, Deepak K
2016-05-25 19:41         ` Olivier Matz
2016-05-18 11:04     ` [PATCH v3 14/35] mempool: remove macro to check if contiguous Olivier Matz
2016-05-18 11:04     ` [PATCH v3 15/35] mempool: store memory chunks in a list Olivier Matz
2016-05-18 11:04     ` [PATCH v3 16/35] mempool: add function to iterate the memory chunks Olivier Matz
2016-05-18 11:04     ` [PATCH v3 17/35] mempool: simplify the memory usage calculation Olivier Matz
2016-05-18 11:04     ` [PATCH v3 18/35] mempool: introduce a free callback for memory chunks Olivier Matz
2016-05-18 11:04     ` [PATCH v3 19/35] mempool: get memory size with unspecified page size Olivier Matz
2016-05-18 11:04     ` [PATCH v3 20/35] mempool: allocate in several memory chunks by default Olivier Matz
2016-06-01  3:37       ` Ferruh Yigit
2016-05-18 11:04     ` [PATCH v3 21/35] eal: lock memory when not using hugepages Olivier Matz
2016-05-18 11:04     ` [PATCH v3 22/35] mempool: support no hugepage mode Olivier Matz
2016-05-18 11:04     ` [PATCH v3 23/35] mempool: replace physical address by a memzone pointer Olivier Matz
2016-05-18 11:04     ` [PATCH v3 24/35] mempool: introduce a function to free a pool Olivier Matz
2016-05-18 11:04     ` [PATCH v3 25/35] mempool: introduce a function to create an empty pool Olivier Matz
2016-05-18 11:04     ` [PATCH v3 26/35] eal/xen: return machine address without knowing memseg id Olivier Matz
2016-05-18 11:04     ` [PATCH v3 27/35] mempool: rework support of Xen dom0 Olivier Matz
2016-05-18 11:04     ` [PATCH v3 28/35] mempool: create the internal ring when populating Olivier Matz
2016-05-18 11:04     ` [PATCH v3 29/35] mempool: populate with anonymous memory Olivier Matz
2016-05-18 11:04     ` [PATCH v3 30/35] mempool: make mempool populate and free api public Olivier Matz
2016-05-18 11:04     ` [PATCH v3 31/35] app/testpmd: remove anonymous mempool code Olivier Matz
2016-05-18 11:04     ` [PATCH v3 32/35] mem: avoid memzone/mempool/ring name truncation Olivier Matz
2016-05-18 11:04     ` [PATCH v3 33/35] mempool: add flag for removing phys contiguous constraint Olivier Matz
2016-05-18 11:04     ` [PATCH v3 34/35] app/test: rework mempool test Olivier Matz
2016-05-18 11:04     ` [PATCH v3 35/35] doc: update release notes about mempool allocation Olivier Matz
2016-05-19 12:47     ` [PATCH v3 00/35] mempool: rework memory allocation Thomas Monjalon
2016-05-20  8:42       ` Panu Matilainen
2016-05-20  9:09         ` Thomas Monjalon
2016-05-23  7:43           ` Olivier Matz
2016-06-13 10:27             ` Olivier Matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1460629199-32489-3-git-send-email-olivier.matz@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.