From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Cc: Olivier Matz <olivier.matz@6wind.com>
Subject: [dpdk-dev] [PATCH 2/2] mempool: fold memory size calculation helper
Date: Wed, 11 Jul 2018 11:59:10 +0100 [thread overview]
Message-ID: <1531306750-9844-2-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1531306750-9844-1-git-send-email-arybchenko@solarflare.com>
rte_mempool_calc_mem_size_helper() was introduced to avoid
code duplication and used in deprecated rte_mempool_mem_size() and
rte_mempool_op_calc_mem_size_default(). Now the first one is removed
and it is better to fold the helper into the second one to make it
more readable.
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
lib/librte_mempool/rte_mempool.c | 25 --------------------
lib/librte_mempool/rte_mempool.h | 22 -----------------
lib/librte_mempool/rte_mempool_ops_default.c | 25 +++++++++++++++++---
3 files changed, 22 insertions(+), 50 deletions(-)
diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index d48e53c7e..52bc97a75 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -225,31 +225,6 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
return sz->total_size;
}
-
-/*
- * Internal function to calculate required memory chunk size.
- */
-size_t
-rte_mempool_calc_mem_size_helper(uint32_t elt_num, size_t total_elt_sz,
- uint32_t pg_shift)
-{
- size_t obj_per_page, pg_num, pg_sz;
-
- if (total_elt_sz == 0)
- return 0;
-
- if (pg_shift == 0)
- return total_elt_sz * elt_num;
-
- pg_sz = (size_t)1 << pg_shift;
- obj_per_page = pg_sz / total_elt_sz;
- if (obj_per_page == 0)
- return RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * elt_num;
-
- pg_num = (elt_num + obj_per_page - 1) / obj_per_page;
- return pg_num << pg_shift;
-}
-
/* free a memchunk allocated with rte_memzone_reserve() */
static void
rte_mempool_memchunk_mz_free(__rte_unused struct rte_mempool_memhdr *memhdr,
diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index 5d1602555..7c9cd9a2f 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -487,28 +487,6 @@ ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
uint32_t obj_num, uint32_t pg_shift,
size_t *min_chunk_size, size_t *align);
-/**
- * @internal Helper function to calculate memory size required to store
- * specified number of objects in assumption that the memory buffer will
- * be aligned at page boundary.
- *
- * Note that if object size is bigger than page size, then it assumes
- * that pages are grouped in subsets of physically continuous pages big
- * enough to store at least one object.
- *
- * @param elt_num
- * Number of elements.
- * @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. If set to 0, ignore page boundaries.
- * @return
- * Required memory size aligned at page boundary.
- */
-size_t rte_mempool_calc_mem_size_helper(uint32_t elt_num, size_t total_elt_sz,
- uint32_t pg_shift);
-
/**
* Function to be called for each populated object.
*
diff --git a/lib/librte_mempool/rte_mempool_ops_default.c b/lib/librte_mempool/rte_mempool_ops_default.c
index fd63ca137..4e2bfc82d 100644
--- a/lib/librte_mempool/rte_mempool_ops_default.c
+++ b/lib/librte_mempool/rte_mempool_ops_default.c
@@ -12,12 +12,31 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
size_t *min_chunk_size, size_t *align)
{
size_t total_elt_sz;
+ size_t obj_per_page, pg_num, pg_sz;
size_t mem_size;
total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
-
- mem_size = rte_mempool_calc_mem_size_helper(obj_num, total_elt_sz,
- pg_shift);
+ if (total_elt_sz == 0) {
+ mem_size = 0;
+ } else if (pg_shift == 0) {
+ mem_size = total_elt_sz * obj_num;
+ } else {
+ pg_sz = (size_t)1 << pg_shift;
+ obj_per_page = pg_sz / total_elt_sz;
+ if (obj_per_page == 0) {
+ /*
+ * Note that if object size is bigger than page size,
+ * then it is assumed that pages are grouped in subsets
+ * of physically continuous pages big enough to store
+ * at least one object.
+ */
+ mem_size =
+ RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * obj_num;
+ } else {
+ pg_num = (obj_num + obj_per_page - 1) / obj_per_page;
+ mem_size = pg_num << pg_shift;
+ }
+ }
*min_chunk_size = RTE_MAX((size_t)1 << pg_shift, total_elt_sz);
--
2.17.1
next prev parent reply other threads:[~2018-07-11 10:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-11 10:59 [dpdk-dev] [PATCH 1/2] mempool: remove deprecated functions Andrew Rybchenko
2018-07-11 10:59 ` Andrew Rybchenko [this message]
2018-07-26 21:34 ` Thomas Monjalon
2018-07-27 13:45 ` Andrew Rybchenko
2018-07-27 14:38 ` Thomas Monjalon
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=1531306750-9844-2-git-send-email-arybchenko@solarflare.com \
--to=arybchenko@solarflare.com \
--cc=dev@dpdk.org \
--cc=olivier.matz@6wind.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).