From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce Richardson Subject: [PATCH RFCv3 18/19] ring: add object size parameter to memory size calculation Date: Tue, 7 Feb 2017 14:12:56 +0000 Message-ID: <1486476777-24768-19-git-send-email-bruce.richardson@intel.com> References: <20170125121456.GA24344@bricha3-MOBL3.ger.corp.intel.com> Cc: thomas.monjalon@6wind.com, keith.wiles@intel.com, konstantin.ananyev@intel.com, stephen@networkplumber.org, dev@dpdk.org, Bruce Richardson To: olivier.matz@6wind.com Return-path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 535AFF94B for ; Tue, 7 Feb 2017 15:14:34 +0100 (CET) In-Reply-To: <20170125121456.GA24344@bricha3-MOBL3.ger.corp.intel.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" 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 --- 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