From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 25C4B3989 for ; Wed, 7 May 2014 14:35:24 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 07 May 2014 05:35:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,1003,1389772800"; d="scan'208";a="535164966" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by fmsmga002.fm.intel.com with ESMTP; 07 May 2014 05:35:29 -0700 Received: from irsmsx107.ger.corp.intel.com (163.33.3.99) by IRSMSX104.ger.corp.intel.com (163.33.3.159) with Microsoft SMTP Server (TLS) id 14.3.123.3; Wed, 7 May 2014 13:35:27 +0100 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.70]) by IRSMSX107.ger.corp.intel.com ([169.254.10.172]) with mapi id 14.03.0123.003; Wed, 7 May 2014 13:35:26 +0100 From: "Ananyev, Konstantin" To: Olivier Matz , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH 1/2] ring: introduce rte_ring_get_memsize() Thread-Index: AQHPaekJOFzyKW11aUGiSu7hoy9zaJs1DOQQ Date: Wed, 7 May 2014 12:35:26 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772580EFA3F27@IRSMSX105.ger.corp.intel.com> References: <1399462711-12815-1-git-send-email-olivier.matz@6wind.com> <1399462711-12815-2-git-send-email-olivier.matz@6wind.com> In-Reply-To: <1399462711-12815-2-git-send-email-olivier.matz@6wind.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 1/2] ring: introduce rte_ring_get_memsize() X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 12:35:25 -0000 Hi Oliver, 2 nits from me: 1. ssize_t rte_ring_get_memsize(unsigned count) Can you use usual syntax for functions definitions in DPDK: ssize_t rte_ring_get_memsize(unsigned count) 2. sz =3D (sz + CACHE_LINE_MASK) & (~CACHE_LINE_MASK); Use RTE_ALIGN(sz, CACHE_LINE_SIZE) instead? Konstantin -----Original Message----- From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Olivier Matz Sent: Wednesday, May 07, 2014 12:39 PM To: dev@dpdk.org Subject: [dpdk-dev] [PATCH 1/2] ring: introduce rte_ring_get_memsize() Add a function that returns the amount of memory occupied by a rte_ring structure and its object table. This commit prepares the next one that will allow to allocate a ring dynamically. Signed-off-by: Olivier Matz --- lib/librte_ring/rte_ring.c | 29 ++++++++++++++++++++++------- lib/librte_ring/rte_ring.h | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c index 0d43a55..4aa500f 100644 --- a/lib/librte_ring/rte_ring.c +++ b/lib/librte_ring/rte_ring.c @@ -94,6 +94,24 @@ TAILQ_HEAD(rte_ring_list, rte_ring); /* true if x is a power of 2 */ #define POWEROF2(x) ((((x)-1) & (x)) =3D=3D 0) =20 +/* return the size of memory occupied by a ring */ +ssize_t rte_ring_get_memsize(unsigned count) +{ + ssize_t sz; + + /* count must be a power of 2 */ + if ((!POWEROF2(count)) || (count > RTE_RING_SZ_MASK )) { + RTE_LOG(ERR, RING, + "Requested size is invalid, must be power of 2, and " + "do not exceed the size limit %u\n", RTE_RING_SZ_MASK); + return -EINVAL; + } + + sz =3D sizeof(struct rte_ring) + count * sizeof(void *); + sz =3D (sz + CACHE_LINE_MASK) & (~CACHE_LINE_MASK); + return sz; +} + /* create the ring */ struct rte_ring * rte_ring_create(const char *name, unsigned count, int socket_id, @@ -102,7 +120,7 @@ rte_ring_create(const char *name, unsigned count, int s= ocket_id, char mz_name[RTE_MEMZONE_NAMESIZE]; struct rte_ring *r; const struct rte_memzone *mz; - size_t ring_size; + ssize_t ring_size; int mz_flags =3D 0; struct rte_ring_list* ring_list =3D NULL; =20 @@ -129,16 +147,13 @@ rte_ring_create(const char *name, unsigned count, int= socket_id, return NULL;=09 } =20 - /* count must be a power of 2 */ - if ((!POWEROF2(count)) || (count > RTE_RING_SZ_MASK )) { - rte_errno =3D EINVAL; - RTE_LOG(ERR, RING, "Requested size is invalid, must be power of 2, and " - "do not exceed the size limit %u\n", RTE_RING_SZ_MASK); + ring_size =3D rte_ring_get_memsize(count); + if (ring_size < 0) { + rte_errno =3D ring_size; return NULL; } =20 rte_snprintf(mz_name, sizeof(mz_name), "%s%s", RTE_RING_MZ_PREFIX, name); - ring_size =3D count * sizeof(void *) + sizeof(struct rte_ring); =20 rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); =20 diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 775ea79..e8493f2 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -199,6 +199,22 @@ struct rte_ring { #endif =20 /** + * Calculate the memory size needed for a ring + * + * This function returns the number of bytes needed for a ring, given + * the number of elements in it. This value is the sum of the size of + * the structure rte_ring and the size of the memory needed by the + * objects pointers. The value is aligned to a cache line size. + * + * @param count + * The number of elements in the ring (must be a power of 2). + * @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); + +/** * Create a new ring named *name* in memory. * * This function uses ``memzone_reserve()`` to allocate memory. Its size i= s --=20 1.9.2