[dpdk-dev] [PATCH RFCv3 18/19] ring: add object size parameter to memory size calculation
Bruce Richardson
bruce.richardson at intel.com
Tue Feb 7 15:12:56 CET 2017
Add in an extra parameter for the ring element size to the function
which calculates the amount of memory needed for a ring.
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
lib/librte_ring/rte_ring.c | 6 +++---
lib/librte_ring/rte_ring.h | 5 ++++-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c
index 13887ab..eb2a96d 100644
--- a/lib/librte_ring/rte_ring.c
+++ b/lib/librte_ring/rte_ring.c
@@ -101,7 +101,7 @@ EAL_REGISTER_TAILQ(rte_ring_tailq)
/* return the size of memory occupied by a ring */
ssize_t
-rte_ring_get_memsize(unsigned count)
+rte_ring_get_memsize(unsigned int count, size_t obj_size)
{
ssize_t sz;
@@ -113,7 +113,7 @@ rte_ring_get_memsize(unsigned count)
return -EINVAL;
}
- sz = sizeof(struct rte_ring) + count * sizeof(void *);
+ sz = sizeof(struct rte_ring) + (count * obj_size);
sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE);
return sz;
}
@@ -164,7 +164,7 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
- ring_size = rte_ring_get_memsize(count);
+ ring_size = rte_ring_get_memsize(count, sizeof(void *));
if (ring_size < 0) {
rte_errno = ring_size;
return NULL;
diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h
index d708c90..9d5eade 100644
--- a/lib/librte_ring/rte_ring.h
+++ b/lib/librte_ring/rte_ring.h
@@ -177,11 +177,14 @@ struct rte_ring {
*
* @param count
* The number of elements in the ring (must be a power of 2).
+ * @param obj_size
+ * The size of the objects to be stored in the ring, normally for
+ * rte_rings this should be sizeof(void *)
* @return
* - The memory size needed for the ring on success.
* - -EINVAL if count is not a power of 2.
*/
-ssize_t rte_ring_get_memsize(unsigned count);
+ssize_t rte_ring_get_memsize(unsigned int count, size_t obj_size);
/**
* Initialize a ring structure.
--
2.9.3
More information about the dev
mailing list