[dpdk-dev,RFCv3,18/19] ring: add object size parameter to memory size calculation
Checks
Commit Message
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@intel.com>
---
lib/librte_ring/rte_ring.c | 6 +++---
lib/librte_ring/rte_ring.h | 5 ++++-
2 files changed, 7 insertions(+), 4 deletions(-)
@@ -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;
@@ -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.