From patchwork Fri Sep 6 19:05:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 173289 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1128323ilq; Fri, 6 Sep 2019 12:06:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDcVSKfOw9IrukeBEv/+6vCAFWPR2YWCqKotub/t9ecaWi/IDxpqXEwi2BtbrF0O71r7xl X-Received: by 2002:a50:ace1:: with SMTP id x88mr11246009edc.300.1567796761394; Fri, 06 Sep 2019 12:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567796761; cv=none; d=google.com; s=arc-20160816; b=sgBTP9kqClWnIRSULmEY0ogTwRJzDxiDmhUL6hDRgMBnd9aRejniXccCSAGTvGzco+ C0kzOhe8H+gCrhzTyTF2yzs1N/2+vYv1WyO30Pj9ogjbkshT/ihOVQgER9sRsOU4JzVo 35jwHfNmDQELeE6rSKwhPmBbuKsuAIDkvgYiWI24PSkw/fbohpEkPgQRD6vahtYm5jJe cPmQA86c45Dt7ujSBVx428MynR9/VRg4Y4YGuTNUVCJif0CERaPVV0FMrzYKZ4IZWENC MnMWl3iX+aoTUA+iVXGxqPKCsQulLNxMlzT3uKHS0A5lwuIIcTEJ+4W3+BXoHmivJ/+C p4aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=N5lktTgugmdnQLvpNfSrJ5IM/HMiQ9xNj+hKbzXuPh0=; b=f5jweRNu+cJJ/1ThJJSegTCaf8mzryV5wQgvgDffZ2+RfYAkiFy7DMz2zmDh7OtKsK b9T8PRW1oRTSlteht42xqG482GyaCH/3biEXqLKk2S5PrRDcXPf0apnTLZT32dnQ24db tJPbUw0jd7te8aaq/OZC9M6hhDwl5GCeoOXthgldX3cbzlyotKHFwgXfcT8PhkZLDtPc J9admqlmdOuznhijhEDcm/hcPZ6M9+2MBsS8aOTUVaujkuD4QUyLsdoS8Y6thYH/TcaG Egl/99WAytvWcOGleLEmYhsW15iNxLf0Z3poZvnwTE2Jeei5dOWtD5syMuLWI+7f52WH DuXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id i55si4526649eda.88.2019.09.06.12.06.01; Fri, 06 Sep 2019 12:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BD5821BE99; Fri, 6 Sep 2019 21:06:00 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id EFD1B1BE97 for ; Fri, 6 Sep 2019 21:05:58 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D9E028; Fri, 6 Sep 2019 12:05:58 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A0B23F59C; Fri, 6 Sep 2019 12:05:58 -0700 (PDT) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, jerinj@marvell.com, Honnappa Nagarahalli Date: Fri, 6 Sep 2019 14:05:05 -0500 Message-Id: <20190906190510.11146-2-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190906190510.11146-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 1/6] lib/ring: apis to support configurable element size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Current APIs assume ring elements to be pointers. However, in many use cases, the size can be different. The new APIs rte_ring_get_memsize_elem and rte_ring_create_elem help reduce code duplication while creating rte_ring templates. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Dharmik Thakkar Reviewed-by: Gavin Hu Reviewed-by: Ruifeng Wang --- lib/librte_ring/Makefile | 2 +- lib/librte_ring/meson.build | 3 ++ lib/librte_ring/rte_ring.c | 34 +++++++++---- lib/librte_ring/rte_ring.h | 72 ++++++++++++++++++++++++++++ lib/librte_ring/rte_ring_version.map | 2 + 5 files changed, 104 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/lib/librte_ring/Makefile b/lib/librte_ring/Makefile index 21a36770d..4c8410229 100644 --- a/lib/librte_ring/Makefile +++ b/lib/librte_ring/Makefile @@ -6,7 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk # library name LIB = librte_ring.a -CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 +CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -DALLOW_EXPERIMENTAL_API LDLIBS += -lrte_eal EXPORT_MAP := rte_ring_version.map diff --git a/lib/librte_ring/meson.build b/lib/librte_ring/meson.build index ab8b0b469..74219840a 100644 --- a/lib/librte_ring/meson.build +++ b/lib/librte_ring/meson.build @@ -6,3 +6,6 @@ sources = files('rte_ring.c') headers = files('rte_ring.h', 'rte_ring_c11_mem.h', 'rte_ring_generic.h') + +# rte_ring_create_elem and rte_ring_get_memsize_elem are experimental +allow_experimental_apis = true diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c index d9b308036..879feb9f6 100644 --- a/lib/librte_ring/rte_ring.c +++ b/lib/librte_ring/rte_ring.c @@ -46,23 +46,32 @@ 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_elem(unsigned count, size_t esize) { 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); + "Requested number of elements is invalid, must be " + "power of 2, and do not exceed the limit %u\n", + RTE_RING_SZ_MASK); + return -EINVAL; } - sz = sizeof(struct rte_ring) + count * sizeof(void *); + sz = sizeof(struct rte_ring) + count * esize; sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE); return sz; } +/* return the size of memory occupied by a ring */ +ssize_t +rte_ring_get_memsize(unsigned count) +{ + return rte_ring_get_memsize_elem(count, sizeof(void *)); +} + void rte_ring_reset(struct rte_ring *r) { @@ -114,10 +123,10 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count, return 0; } -/* create the ring */ +/* create the ring for a given element size */ struct rte_ring * -rte_ring_create(const char *name, unsigned count, int socket_id, - unsigned flags) +rte_ring_create_elem(const char *name, unsigned count, size_t esize, + int socket_id, unsigned flags) { char mz_name[RTE_MEMZONE_NAMESIZE]; struct rte_ring *r; @@ -135,7 +144,7 @@ rte_ring_create(const char *name, unsigned count, int socket_id, if (flags & RING_F_EXACT_SZ) count = rte_align32pow2(count + 1); - ring_size = rte_ring_get_memsize(count); + ring_size = rte_ring_get_memsize_elem(count, esize); if (ring_size < 0) { rte_errno = ring_size; return NULL; @@ -182,6 +191,15 @@ rte_ring_create(const char *name, unsigned count, int socket_id, return r; } +/* create the ring */ +struct rte_ring * +rte_ring_create(const char *name, unsigned count, int socket_id, + unsigned flags) +{ + return rte_ring_create_elem(name, count, sizeof(void *), socket_id, + flags); +} + /* free the ring */ void rte_ring_free(struct rte_ring *r) diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 2a9f768a1..bbc1202d3 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -122,6 +122,29 @@ struct rte_ring { #define __IS_SC 1 #define __IS_MC 0 +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Calculate the memory size needed for a ring with given element size + * + * This function returns the number of bytes needed for a ring, given + * the number of elements in it and the size of the element. This value + * is the sum of the size of the structure rte_ring and the size of the + * memory needed for storing the elements. The value is aligned to a cache + * line size. + * + * @param count + * The number of elements in the ring (must be a power of 2). + * @param esize + * The size of elements in the ring (recommended to be a power of 2). + * @return + * - The memory size needed for the ring on success. + * - -EINVAL if count is not a power of 2. + */ +__rte_experimental +ssize_t rte_ring_get_memsize_elem(unsigned count, size_t esize); + /** * Calculate the memory size needed for a ring * @@ -175,6 +198,54 @@ ssize_t rte_ring_get_memsize(unsigned count); int rte_ring_init(struct rte_ring *r, const char *name, unsigned count, unsigned flags); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Create a new ring named *name* that stores elements with given size. + * + * This function uses ``memzone_reserve()`` to allocate memory. Then it + * calls rte_ring_init() to initialize an empty ring. + * + * The new ring size is set to *count*, which must be a power of + * two. Water marking is disabled by default. The real usable ring size + * is *count-1* instead of *count* to differentiate a free ring from an + * empty ring. + * + * The ring is added in RTE_TAILQ_RING list. + * + * @param name + * The name of the ring. + * @param count + * The number of elements in the ring (must be a power of 2). + * @param esize + * The size of elements in the ring (recommended to be a power of 2). + * @param socket_id + * The *socket_id* argument is the socket identifier in case of + * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA + * constraint for the reserved zone. + * @param flags + * An OR of the following: + * - RING_F_SP_ENQ: If this flag is set, the default behavior when + * using ``rte_ring_enqueue()`` or ``rte_ring_enqueue_bulk()`` + * is "single-producer". Otherwise, it is "multi-producers". + * - RING_F_SC_DEQ: If this flag is set, the default behavior when + * using ``rte_ring_dequeue()`` or ``rte_ring_dequeue_bulk()`` + * is "single-consumer". Otherwise, it is "multi-consumers". + * @return + * On success, the pointer to the new allocated ring. NULL on error with + * rte_errno set appropriately. Possible errno values include: + * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure + * - E_RTE_SECONDARY - function was called from a secondary process instance + * - EINVAL - count provided is not a power of 2 + * - ENOSPC - the maximum number of memzones has already been allocated + * - EEXIST - a memzone with the same name already exists + * - ENOMEM - no appropriate memory area found in which to create memzone + */ +__rte_experimental +struct rte_ring *rte_ring_create_elem(const char *name, unsigned count, + size_t esize, int socket_id, unsigned flags); + /** * Create a new ring named *name* in memory. * @@ -216,6 +287,7 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned count, */ struct rte_ring *rte_ring_create(const char *name, unsigned count, int socket_id, unsigned flags); + /** * De-allocate all memory used by the ring. * diff --git a/lib/librte_ring/rte_ring_version.map b/lib/librte_ring/rte_ring_version.map index 510c1386e..e410a7503 100644 --- a/lib/librte_ring/rte_ring_version.map +++ b/lib/librte_ring/rte_ring_version.map @@ -21,6 +21,8 @@ DPDK_2.2 { EXPERIMENTAL { global: + rte_ring_create_elem; + rte_ring_get_memsize_elem; rte_ring_reset; }; From patchwork Fri Sep 6 19:05:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 173290 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1128544ilq; Fri, 6 Sep 2019 12:06:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLplv7fJk5VZuoYo6+P5j9rWvKAOHG8g6CVPqdbK248NMVkdGG8MzQMSJ1BMIOxj7pqPd4 X-Received: by 2002:aa7:c40c:: with SMTP id j12mr11456130edq.80.1567796771637; Fri, 06 Sep 2019 12:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567796771; cv=none; d=google.com; s=arc-20160816; b=PL68SX+HXQvPfDYGQ3OVKl7EmmWWoCYbKrBAryv/FFkJ3/0S0xiBH/cOhwE30HO4jn 6POQqNow+p+60/u4d2dM/rr2Ziy6J8jU0Kkkr4mkw9eoQLEw+2xFgOfUdn+g0QOqtk6S 4lAIpy+kaMruAq8AFZ5vW3syO2jNoA8MTzVpeZy7+WkT/qtbrM1dIrEzyC12yyzZAaFj ypcpjqsfRoLq4B/b9QAM3KH7jRmOH0VTZHwORmPuCIqmkDyktvBKiaS0d/+npY1ZpzmZ FWaAEWmfFxpHtRLFVh3N0EVxcPNV5n5YhaK7gw32evBFuNg1LVP7UVv65qVdO6G8RQdU bj0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=9iMCCdhcSa3J++qXdm2ZgIF087EnCBSr0WTQOr4+Mq4=; b=lfgcVVRjj6iO7TLxINgtw+mbwnST9qX0yGhDPrfD/IYWnh/ZRyAcri6wKdXl7Lg7zy v8jD1okgB3DohryNBxkMGVudXoxvY+nfua5VUO7/N8S3adJtTAsFCIZutggo5EnPWAmL w32w4BRDZ9jMtEKgn00+crmMSfFTwwfzf7V3dYz/OeexP4BidbLQ/jWgT/HXbphipD4S qtchr8e2AxTpml/pX6MkKMhUrMr33wefmwJ1RynD8z69vmdmbq72PP335cPy69xSsUGQ YoIQZ+A3DM3/QszIj46MZbw7ulreO8il57Zl12gKS9q8NsipjwCGnc++ycWCTZkc2ZoU h1wQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id hb6si3245162ejb.1.2019.09.06.12.06.11; Fri, 06 Sep 2019 12:06:11 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BEF221BEBF; Fri, 6 Sep 2019 21:06:03 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id C5ABE1BE97 for ; Fri, 6 Sep 2019 21:05:59 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5AD7E1576; Fri, 6 Sep 2019 12:05:59 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 443C53F59C; Fri, 6 Sep 2019 12:05:59 -0700 (PDT) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, jerinj@marvell.com, Honnappa Nagarahalli Date: Fri, 6 Sep 2019 14:05:06 -0500 Message-Id: <20190906190510.11146-3-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190906190510.11146-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 2/6] lib/ring: add template to support different element sizes X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list 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 templates to support creating ring APIs with different ring element sizes. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Dharmik Thakkar Reviewed-by: Gavin Hu Reviewed-by: Ruifeng Wang --- lib/librte_ring/Makefile | 4 +- lib/librte_ring/meson.build | 4 +- lib/librte_ring/rte_ring_template.c | 46 ++++ lib/librte_ring/rte_ring_template.h | 330 ++++++++++++++++++++++++++++ 4 files changed, 382 insertions(+), 2 deletions(-) create mode 100644 lib/librte_ring/rte_ring_template.c create mode 100644 lib/librte_ring/rte_ring_template.h -- 2.17.1 diff --git a/lib/librte_ring/Makefile b/lib/librte_ring/Makefile index 4c8410229..818898110 100644 --- a/lib/librte_ring/Makefile +++ b/lib/librte_ring/Makefile @@ -19,6 +19,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h \ rte_ring_generic.h \ - rte_ring_c11_mem.h + rte_ring_c11_mem.h \ + rte_ring_template.h \ + rte_ring_template.c include $(RTE_SDK)/mk/rte.lib.mk diff --git a/lib/librte_ring/meson.build b/lib/librte_ring/meson.build index 74219840a..e4e208a7c 100644 --- a/lib/librte_ring/meson.build +++ b/lib/librte_ring/meson.build @@ -5,7 +5,9 @@ version = 2 sources = files('rte_ring.c') headers = files('rte_ring.h', 'rte_ring_c11_mem.h', - 'rte_ring_generic.h') + 'rte_ring_generic.h', + 'rte_ring_template.h', + 'rte_ring_template.c') # rte_ring_create_elem and rte_ring_get_memsize_elem are experimental allow_experimental_apis = true diff --git a/lib/librte_ring/rte_ring_template.c b/lib/librte_ring/rte_ring_template.c new file mode 100644 index 000000000..1ca593f95 --- /dev/null +++ b/lib/librte_ring/rte_ring_template.c @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2019 Arm Limited + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rte_ring.h" + +/* return the size of memory occupied by a ring */ +ssize_t +__RTE_RING_CONCAT(rte_ring_get_memsize)(unsigned count) +{ + return rte_ring_get_memsize_elem(count, RTE_RING_TMPLT_ELEM_SIZE); +} + +/* create the ring */ +struct rte_ring * +__RTE_RING_CONCAT(rte_ring_create)(const char *name, unsigned count, + int socket_id, unsigned flags) +{ + return rte_ring_create_elem(name, count, RTE_RING_TMPLT_ELEM_SIZE, + socket_id, flags); +} diff --git a/lib/librte_ring/rte_ring_template.h b/lib/librte_ring/rte_ring_template.h new file mode 100644 index 000000000..5002a7485 --- /dev/null +++ b/lib/librte_ring/rte_ring_template.h @@ -0,0 +1,330 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2019 Arm Limited + */ + +#ifndef _RTE_RING_TEMPLATE_H_ +#define _RTE_RING_TEMPLATE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Ring API suffix name - used to append to API names */ +#ifndef RTE_RING_TMPLT_API_SUFFIX +#error RTE_RING_TMPLT_API_SUFFIX not defined +#endif + +/* Ring's element size in bits, should be a power of 2 */ +#ifndef RTE_RING_TMPLT_ELEM_SIZE +#error RTE_RING_TMPLT_ELEM_SIZE not defined +#endif + +/* Type of ring elements */ +#ifndef RTE_RING_TMPLT_ELEM_TYPE +#error RTE_RING_TMPLT_ELEM_TYPE not defined +#endif + +#define _rte_fuse(a, b) a##_##b +#define __rte_fuse(a, b) _rte_fuse(a, b) +#define __RTE_RING_CONCAT(a) __rte_fuse(a, RTE_RING_TMPLT_API_SUFFIX) + +/* Calculate the memory size needed for a ring */ +RTE_RING_TMPLT_EXPERIMENTAL +ssize_t __RTE_RING_CONCAT(rte_ring_get_memsize)(unsigned count); + +/* Create a new ring named *name* in memory. */ +RTE_RING_TMPLT_EXPERIMENTAL +struct rte_ring * +__RTE_RING_CONCAT(rte_ring_create)(const char *name, unsigned count, + int socket_id, unsigned flags); + +/** + * @internal Enqueue several objects on the ring + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(__rte_ring_do_enqueue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const *obj_table, unsigned int n, + enum rte_ring_queue_behavior behavior, unsigned int is_sp, + unsigned int *free_space) +{ + uint32_t prod_head, prod_next; + uint32_t free_entries; + + n = __rte_ring_move_prod_head(r, is_sp, n, behavior, + &prod_head, &prod_next, &free_entries); + if (n == 0) + goto end; + + ENQUEUE_PTRS(r, &r[1], prod_head, obj_table, n, + RTE_RING_TMPLT_ELEM_TYPE); + + update_tail(&r->prod, prod_head, prod_next, is_sp, 1); +end: + if (free_space != NULL) + *free_space = free_entries - n; + return n; +} + +/** + * @internal Dequeue several objects from the ring + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(__rte_ring_do_dequeue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + enum rte_ring_queue_behavior behavior, unsigned int is_sc, + unsigned int *available) +{ + uint32_t cons_head, cons_next; + uint32_t entries; + + n = __rte_ring_move_cons_head(r, (int)is_sc, n, behavior, + &cons_head, &cons_next, &entries); + if (n == 0) + goto end; + + DEQUEUE_PTRS(r, &r[1], cons_head, obj_table, n, + RTE_RING_TMPLT_ELEM_TYPE); + + update_tail(&r->cons, cons_head, cons_next, is_sc, 0); + +end: + if (available != NULL) + *available = entries - n; + return n; +} + + +/** + * Enqueue several objects on the ring (multi-producers safe). + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(rte_ring_mp_enqueue_bulk)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const *obj_table, unsigned int n, + unsigned int *free_space) +{ + return __RTE_RING_CONCAT(__rte_ring_do_enqueue)(r, obj_table, n, + RTE_RING_QUEUE_FIXED, __IS_MP, free_space); +} + +/** + * Enqueue several objects on a ring (NOT multi-producers safe). + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(rte_ring_sp_enqueue_bulk)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const *obj_table, unsigned int n, + unsigned int *free_space) +{ + return __RTE_RING_CONCAT(__rte_ring_do_enqueue)(r, obj_table, n, + RTE_RING_QUEUE_FIXED, __IS_SP, free_space); +} + +/** + * Enqueue several objects on a ring. + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(rte_ring_enqueue_bulk)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const *obj_table, unsigned int n, + unsigned int *free_space) +{ + return __RTE_RING_CONCAT(__rte_ring_do_enqueue)(r, obj_table, n, + RTE_RING_QUEUE_FIXED, r->prod.single, free_space); +} + +/** + * Enqueue one object on a ring (multi-producers safe). + */ +static __rte_always_inline int +__RTE_RING_CONCAT(rte_ring_mp_enqueue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const obj) +{ + return __RTE_RING_CONCAT(rte_ring_mp_enqueue_bulk)(r, &obj, 1, NULL) ? + 0 : -ENOBUFS; +} + +/** + * Enqueue one object on a ring (NOT multi-producers safe). + */ +static __rte_always_inline int +__RTE_RING_CONCAT(rte_ring_sp_enqueue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const obj) +{ + return __RTE_RING_CONCAT(rte_ring_sp_enqueue_bulk)(r, &obj, 1, NULL) ? + 0 : -ENOBUFS; +} + +/** + * Enqueue one object on a ring. + */ +static __rte_always_inline int +__RTE_RING_CONCAT(rte_ring_enqueue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const *obj) +{ + return __RTE_RING_CONCAT(rte_ring_enqueue_bulk)(r, obj, 1, NULL) ? + 0 : -ENOBUFS; +} + +/** + * Dequeue several objects from a ring (multi-consumers safe). + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(rte_ring_mc_dequeue_bulk)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + unsigned int *available) +{ + return __RTE_RING_CONCAT(__rte_ring_do_dequeue)(r, obj_table, n, + RTE_RING_QUEUE_FIXED, __IS_MC, available); +} + +/** + * Dequeue several objects from a ring (NOT multi-consumers safe). + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(rte_ring_sc_dequeue_bulk)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + unsigned int *available) +{ + return __RTE_RING_CONCAT(__rte_ring_do_dequeue)(r, obj_table, n, + RTE_RING_QUEUE_FIXED, __IS_SC, available); +} + +/** + * Dequeue several objects from a ring. + */ +static __rte_always_inline unsigned int +__RTE_RING_CONCAT(rte_ring_dequeue_bulk)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + unsigned int *available) +{ + return __RTE_RING_CONCAT(__rte_ring_do_dequeue)(r, obj_table, n, + RTE_RING_QUEUE_FIXED, r->cons.single, available); +} + +/** + * Dequeue one object from a ring (multi-consumers safe). + */ +static __rte_always_inline int +__RTE_RING_CONCAT(rte_ring_mc_dequeue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_p) +{ + return __RTE_RING_CONCAT(rte_ring_mc_dequeue_bulk)(r, obj_p, 1, NULL) ? + 0 : -ENOENT; +} + +/** + * Dequeue one object from a ring (NOT multi-consumers safe). + */ +static __rte_always_inline int +__RTE_RING_CONCAT(rte_ring_sc_dequeue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_p) +{ + return __RTE_RING_CONCAT(rte_ring_sc_dequeue_bulk)(r, obj_p, 1, NULL) ? + 0 : -ENOENT; +} + +/** + * Dequeue one object from a ring. + */ +static __rte_always_inline int +__RTE_RING_CONCAT(rte_ring_dequeue)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_p) +{ + return __RTE_RING_CONCAT(rte_ring_dequeue_bulk)(r, obj_p, 1, NULL) ? + 0 : -ENOENT; +} + +/** + * Enqueue several objects on the ring (multi-producers safe). + */ +static __rte_always_inline unsigned +__RTE_RING_CONCAT(rte_ring_mp_enqueue_burst)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, + unsigned int n, unsigned int *free_space) +{ + return __RTE_RING_CONCAT(__rte_ring_do_enqueue)(r, obj_table, n, + RTE_RING_QUEUE_VARIABLE, __IS_MP, free_space); +} + +/** + * Enqueue several objects on a ring (NOT multi-producers safe). + */ +static __rte_always_inline unsigned +__RTE_RING_CONCAT(rte_ring_sp_enqueue_burst)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, + unsigned int n, unsigned int *free_space) +{ + return __RTE_RING_CONCAT(__rte_ring_do_enqueue)(r, obj_table, n, + RTE_RING_QUEUE_VARIABLE, __IS_SP, free_space); +} + +/** + * Enqueue several objects on a ring. + */ +static __rte_always_inline unsigned +__RTE_RING_CONCAT(rte_ring_enqueue_burst)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE const *obj_table, unsigned int n, + unsigned int *free_space) +{ + return __RTE_RING_CONCAT(__rte_ring_do_enqueue)(r, obj_table, n, + RTE_RING_QUEUE_VARIABLE, r->prod.single, free_space); +} + +/** + * Dequeue several objects from a ring (multi-consumers safe). When the request + * objects are more than the available objects, only dequeue the actual number + * of objects + */ +static __rte_always_inline unsigned +__RTE_RING_CONCAT(rte_ring_mc_dequeue_burst)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + unsigned int *available) +{ + return __RTE_RING_CONCAT(__rte_ring_do_dequeue)(r, obj_table, n, + RTE_RING_QUEUE_VARIABLE, __IS_MC, available); +} + +/** + * Dequeue several objects from a ring (NOT multi-consumers safe).When the + * request objects are more than the available objects, only dequeue the + * actual number of objects + */ +static __rte_always_inline unsigned +__RTE_RING_CONCAT(rte_ring_sc_dequeue_burst)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + unsigned int *available) +{ + return __RTE_RING_CONCAT(__rte_ring_do_dequeue)(r, obj_table, n, + RTE_RING_QUEUE_VARIABLE, __IS_SC, available); +} + +/** + * Dequeue multiple objects from a ring up to a maximum number. + */ +static __rte_always_inline unsigned +__RTE_RING_CONCAT(rte_ring_dequeue_burst)(struct rte_ring *r, + RTE_RING_TMPLT_ELEM_TYPE *obj_table, unsigned int n, + unsigned int *available) +{ + return __RTE_RING_CONCAT(__rte_ring_do_dequeue)(r, obj_table, n, + RTE_RING_QUEUE_VARIABLE, + r->cons.single, available); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_RING_TEMPLATE_H_ */ From patchwork Fri Sep 6 19:05:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 173291 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1128737ilq; Fri, 6 Sep 2019 12:06:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMYZDMRSpXSqR7MhpXEre31lbp6ll2KbMnareTV48BiojDIu6bL/dnpFPY3PFanJ4bd+pH X-Received: by 2002:aa7:d40c:: with SMTP id z12mr11480419edq.30.1567796781057; Fri, 06 Sep 2019 12:06:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567796781; cv=none; d=google.com; s=arc-20160816; b=PuO5/gxTMsSXkt6ZtMWTwU7TAeKoISCZh++vLfG+cSn7Jv/kdW2aXpSrzgZ/PhZ7vv CZQ+oXAE3aDxYcuVc8sq5GwGEYsPTg0Sam1YvixpCRsY3Sh/ARi80mJkhtx4aFjEdLo7 JkNXAVV1XJawW7zeKzvZnnjokG5QjHNW0CsB20aHZGVTG/SiQqtQIpuLy90F2NdCd1Tp fROCbszQdfy1ByD7vNUeO6NTFjkhByEA4nhM4SS7ww5lm+gm+0kQ8xZtX3yjPOzBRr4O w9g1Y1Wq/NqE/wVJqQwWfbL8L0kF/EjIwL4YclBnarxo6objo7VSJls3BZCw4dz87Zjt 5HJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=M1yMDIqdkzcayLkzOGG0R74fOR+cUEAk0uq0QvV2fkA=; b=Bz9pZZn1jAAmUiDqhQp+LgED2YY7ttxzl5+jeqSqesT73x9uB0oG8dBcmq8uLDA4Xj fmPAR3O0OqqNITfEG69uzpOEG5C2qMHo5OJldaY8EXWv6i/SI/wzk5WCKL/goi8MBnYm bZ2f4EJVV5QyZGLumEwV0MSlE80+EH7k5wtO3H4OWDr40SfCxv4Y859WvBrqVf3WAQsz 0CuNHkrgJ7TXECAoegYxoExVnu2/9CFlg4iciw9cp6esOUFnRQtpY0fWMNxm5l5GG/vX sxAoVA6YLhpPTmBfk5MKPnyQOdacaRMrhNDoHBCcLr+bVCwQgEEfSYim1KH7/enT1vrE Cb2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id jz22si3278962ejb.195.2019.09.06.12.06.20; Fri, 06 Sep 2019 12:06:21 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D2CC61BEDD; Fri, 6 Sep 2019 21:06:05 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 0FD0E1BEA7 for ; Fri, 6 Sep 2019 21:06:00 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4274128; Fri, 6 Sep 2019 12:06:00 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 30E243F59C; Fri, 6 Sep 2019 12:06:00 -0700 (PDT) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, jerinj@marvell.com, Honnappa Nagarahalli Date: Fri, 6 Sep 2019 14:05:07 -0500 Message-Id: <20190906190510.11146-4-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190906190510.11146-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 3/6] tools/checkpatch: relax constraints on __rte_experimental X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Relax the constraints on __rte_experimental usage, allow redefining to macros. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- devtools/checkpatches.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 560e6ce93..090c9b08a 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -99,9 +99,14 @@ check_experimental_tags() { # ret = 1; } if ($1 != "+__rte_experimental" || $2 != "") { - print "__rte_experimental must appear alone on the line" \ - " immediately preceding the return type of a function." - ret = 1; + # code such as "#define XYZ __rte_experimental" is + # allowed + if ($1 != "+#define") { + print "__rte_experimental must appear alone " \ + "on the line immediately preceding the " \ + "return type of a function." + ret = 1; + } } } END { From patchwork Fri Sep 6 19:05:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 173292 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1128921ilq; Fri, 6 Sep 2019 12:06:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyv3HM/c95DfEyTSDRgBLndDy0K+IDzZOqIwFc1/ZCb3656NJjgQ6G+93qvTsqnO/sFCCpb X-Received: by 2002:a17:906:2892:: with SMTP id o18mr48021ejd.29.1567796789042; Fri, 06 Sep 2019 12:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567796789; cv=none; d=google.com; s=arc-20160816; b=Bcl1g01+qX0a51cfS77qSDlGOgyH9C00rU/29yVK+YCqJK3C7jy+qPWaV+Le9CkaUC nw/b1UYB9j9yrm8rb/IHblAFFLOxil/l+DfM5KMa+K8MvnL5SJu3k1PsdSIXriPLPkG6 bwzGgTP4EcVLaXc+Jk+myJ4Qnta8CSZ5ACXJ/o6HINmuhQUIjPxEU228y8gO3bK7NuNE DxWCNQutKNkF/Rpd+zh71YrV2A9GGQ0bsLCFUJ2yrIrhTjS/wp6hRzkuVhMxeksBFyHt bAH4cS4sQD/v7DVAiAuC5hmm5DVi4RBDrCRgHjMo6HQNocnHx+PU9cRt+bkKWAQ0cmXs 1eFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=1ESO9kazWZW9VQWbx0wOx0pj7fwfQAvx3hKNu0GLge0=; b=wHuLR4Ie1achlqH5hIDIT2fbjrlNrq/j1/JKuYrvs9WF8GQsFUY1yUNy8aXxueLuKz +nwa0V6IvO1krRdFJxUGNgv5lA2kJOovJLcfMab6ss3+ZaaWksIizOjsZpxRoWI8GYac u5ZfTYdVn6VFAQWCvQYwANKpT8FkgHX6OStRrjtaPz617+eU3JPuR4yIQbMU4z23mq/w AtvtPLE9uGcW75FKCDrH129LBFduFhL7ca0vpC5dqPYdBaiuiCCwxXGUcwqPIJF3pd7p NvCYjmXuJUOb86MiONvXjn+3kxokLsYEPEawHFWw2IwvGc02aaHTTOMITRWNaMxDugF9 HAQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id p14si4085137eda.411.2019.09.06.12.06.28; Fri, 06 Sep 2019 12:06:29 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 23E541BF0C; Fri, 6 Sep 2019 21:06:08 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id C391E1BEAE for ; Fri, 6 Sep 2019 21:06:01 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3F5A31596; Fri, 6 Sep 2019 12:06:01 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2CB603F59C; Fri, 6 Sep 2019 12:06:01 -0700 (PDT) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, jerinj@marvell.com, Honnappa Nagarahalli Date: Fri, 6 Sep 2019 14:05:08 -0500 Message-Id: <20190906190510.11146-5-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190906190510.11146-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 4/6] lib/ring: add ring APIs to support 32b ring elements X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list 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 ring APIs to support 32b ring elements using templates. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Dharmik Thakkar Reviewed-by: Gavin Hu Reviewed-by: Ruifeng Wang --- lib/librte_ring/Makefile | 3 ++- lib/librte_ring/meson.build | 4 +++- lib/librte_ring/rte_ring_32.c | 19 +++++++++++++++ lib/librte_ring/rte_ring_32.h | 36 ++++++++++++++++++++++++++++ lib/librte_ring/rte_ring_version.map | 2 ++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 lib/librte_ring/rte_ring_32.c create mode 100644 lib/librte_ring/rte_ring_32.h -- 2.17.1 diff --git a/lib/librte_ring/Makefile b/lib/librte_ring/Makefile index 818898110..3102bb64d 100644 --- a/lib/librte_ring/Makefile +++ b/lib/librte_ring/Makefile @@ -14,10 +14,11 @@ EXPORT_MAP := rte_ring_version.map LIBABIVER := 2 # all source are stored in SRCS-y -SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c +SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c rte_ring_32.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h \ + rte_ring_32.h \ rte_ring_generic.h \ rte_ring_c11_mem.h \ rte_ring_template.h \ diff --git a/lib/librte_ring/meson.build b/lib/librte_ring/meson.build index e4e208a7c..81ea53ed7 100644 --- a/lib/librte_ring/meson.build +++ b/lib/librte_ring/meson.build @@ -2,8 +2,10 @@ # Copyright(c) 2017 Intel Corporation version = 2 -sources = files('rte_ring.c') +sources = files('rte_ring.c', + 'rte_ring_32.c') headers = files('rte_ring.h', + 'rte_ring_32.h', 'rte_ring_c11_mem.h', 'rte_ring_generic.h', 'rte_ring_template.h', diff --git a/lib/librte_ring/rte_ring_32.c b/lib/librte_ring/rte_ring_32.c new file mode 100644 index 000000000..09e90cec1 --- /dev/null +++ b/lib/librte_ring/rte_ring_32.c @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2019 Arm Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include diff --git a/lib/librte_ring/rte_ring_32.h b/lib/librte_ring/rte_ring_32.h new file mode 100644 index 000000000..5270a9bc7 --- /dev/null +++ b/lib/librte_ring/rte_ring_32.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2019 Arm Limited + */ + +#ifndef _RTE_RING_32_H_ +#define _RTE_RING_32_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RTE_RING_TMPLT_API_SUFFIX 32 +#define RTE_RING_TMPLT_ELEM_SIZE sizeof(uint32_t) +#define RTE_RING_TMPLT_ELEM_TYPE uint32_t +#define RTE_RING_TMPLT_EXPERIMENTAL __rte_experimental + +#include + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_RING_32_H_ */ diff --git a/lib/librte_ring/rte_ring_version.map b/lib/librte_ring/rte_ring_version.map index e410a7503..9efba91bb 100644 --- a/lib/librte_ring/rte_ring_version.map +++ b/lib/librte_ring/rte_ring_version.map @@ -21,7 +21,9 @@ DPDK_2.2 { EXPERIMENTAL { global: + rte_ring_create_32; rte_ring_create_elem; + rte_ring_get_memsize_32; rte_ring_get_memsize_elem; rte_ring_reset; From patchwork Fri Sep 6 19:05:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 173293 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1129161ilq; Fri, 6 Sep 2019 12:06:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYbvGF4K0yefjNwXUoyYt/DeGAfx7e+OmR0Rfidl06rqjW4oS4X6ci9mZYnLzfBzKEUtcg X-Received: by 2002:aa7:de11:: with SMTP id h17mr11080470edv.74.1567796800234; Fri, 06 Sep 2019 12:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567796800; cv=none; d=google.com; s=arc-20160816; b=whk3oUdl/43tOqdo+tjTUcZ6ytsRm7732mpzWLoVZNoz7ghdtzoUtyvnc0GtQIZFeW 0jMEtXExAEWYpnVB47966eolpJKY2Gwpk3z7BzMDo7EeaZAP74GNTIAuBFA14W7jL/2/ IJjx2yI5Cjqfy/JlP009pYK485kmpFZOTheeO8Jk65MFVHe+VwsP+sPRo9crOB1rhH6i 30RObQES4Da5IwX8GpFZv5FHbFoLs4yWH4jjNDHHonV8oDt0ozmBVQo8iXXc27Oue663 afIbvvTRT3EetWNlKbQeVS839rzLZgkgRnnsgbLe8UqfTWEg52NB2s7U4TzhEy3Qs8Y7 SIWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=chhw6/G4nouaRZP+LuUe3TflWrIt0TajQ6/QdonLNUE=; b=VZ/mQWv+o+smX7jB6Mr1QQ7zSLK9nOWu8VwXqtJK8CDLxayAlAAhEznx02VIutb/dz eTXn3qkKiqBu1B5aC+qSWmNZAMiNhSCg6/XmpZPVTzKVQdYh3zON3YHiyLAt2Na1HIf8 Bzf2rhhlRpuyFR+95h9Ir7BQEJrjwfLOzo7ldPFRRhjoUwiYY8dIYWfNRWX057xWXggl ZMeWvpr2YJitlAKyOQZbXtXq4ZG7XSRkuRGAr5tK6NMnmKrRcLyZVN6vGyFV9PB+LGcA J254jfXuh2fzSeqCTzJwT5LqzgRfhik+2KJF2GvNi/RCvvicRASMewiiAlKHkrQuhfvL JAgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id ck26si3459752ejb.285.2019.09.06.12.06.40; Fri, 06 Sep 2019 12:06:40 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 714231BF62; Fri, 6 Sep 2019 21:06:10 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 8E30B1BEAF for ; Fri, 6 Sep 2019 21:06:02 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 158F21597; Fri, 6 Sep 2019 12:06:02 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 017053F59C; Fri, 6 Sep 2019 12:06:02 -0700 (PDT) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, jerinj@marvell.com, Honnappa Nagarahalli Date: Fri, 6 Sep 2019 14:05:09 -0500 Message-Id: <20190906190510.11146-6-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190906190510.11146-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 5/6] lib/hash: use ring with 32b element size to save memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The freelist and external bucket indices are 32b. Using rings that use 32b element sizes will save memory. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Dharmik Thakkar Reviewed-by: Gavin Hu Reviewed-by: Ruifeng Wang --- lib/librte_hash/rte_cuckoo_hash.c | 55 ++++++++++++++----------------- lib/librte_hash/rte_cuckoo_hash.h | 2 +- 2 files changed, 26 insertions(+), 31 deletions(-) -- 2.17.1 diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 87a4c01f2..a0cd3360a 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -213,7 +213,7 @@ rte_hash_create(const struct rte_hash_parameters *params) snprintf(ring_name, sizeof(ring_name), "HT_%s", params->name); /* Create ring (Dummy slot index is not enqueued) */ - r = rte_ring_create(ring_name, rte_align32pow2(num_key_slots), + r = rte_ring_create_32(ring_name, rte_align32pow2(num_key_slots), params->socket_id, 0); if (r == NULL) { RTE_LOG(ERR, HASH, "memory allocation failed\n"); @@ -227,7 +227,7 @@ rte_hash_create(const struct rte_hash_parameters *params) if (ext_table_support) { snprintf(ext_ring_name, sizeof(ext_ring_name), "HT_EXT_%s", params->name); - r_ext = rte_ring_create(ext_ring_name, + r_ext = rte_ring_create_32(ext_ring_name, rte_align32pow2(num_buckets + 1), params->socket_id, 0); @@ -295,7 +295,7 @@ rte_hash_create(const struct rte_hash_parameters *params) * for next bucket */ for (i = 1; i <= num_buckets; i++) - rte_ring_sp_enqueue(r_ext, (void *)((uintptr_t) i)); + rte_ring_sp_enqueue_32(r_ext, i); if (readwrite_concur_lf_support) { ext_bkt_to_free = rte_zmalloc(NULL, sizeof(uint32_t) * @@ -434,7 +434,7 @@ rte_hash_create(const struct rte_hash_parameters *params) /* Populate free slots ring. Entry zero is reserved for key misses. */ for (i = 1; i < num_key_slots; i++) - rte_ring_sp_enqueue(r, (void *)((uintptr_t) i)); + rte_ring_sp_enqueue_32(r, i); te->data = (void *) h; TAILQ_INSERT_TAIL(hash_list, te, next); @@ -598,13 +598,12 @@ rte_hash_reset(struct rte_hash *h) tot_ring_cnt = h->entries; for (i = 1; i < tot_ring_cnt + 1; i++) - rte_ring_sp_enqueue(h->free_slots, (void *)((uintptr_t) i)); + rte_ring_sp_enqueue_32(h->free_slots, i); /* Repopulate the free ext bkt ring. */ if (h->ext_table_support) { for (i = 1; i <= h->num_buckets; i++) - rte_ring_sp_enqueue(h->free_ext_bkts, - (void *)((uintptr_t) i)); + rte_ring_sp_enqueue_32(h->free_ext_bkts, i); } if (h->use_local_cache) { @@ -623,13 +622,13 @@ rte_hash_reset(struct rte_hash *h) static inline void enqueue_slot_back(const struct rte_hash *h, struct lcore_cache *cached_free_slots, - void *slot_id) + uint32_t slot_id) { if (h->use_local_cache) { cached_free_slots->objs[cached_free_slots->len] = slot_id; cached_free_slots->len++; } else - rte_ring_sp_enqueue(h->free_slots, slot_id); + rte_ring_sp_enqueue_32(h->free_slots, slot_id); } /* Search a key from bucket and update its data. @@ -923,8 +922,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, uint32_t prim_bucket_idx, sec_bucket_idx; struct rte_hash_bucket *prim_bkt, *sec_bkt, *cur_bkt; struct rte_hash_key *new_k, *keys = h->key_store; - void *slot_id = NULL; - void *ext_bkt_id = NULL; + uint32_t slot_id = 0; + uint32_t ext_bkt_id = 0; uint32_t new_idx, bkt_id; int ret; unsigned n_slots; @@ -968,7 +967,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, /* Try to get a free slot from the local cache */ if (cached_free_slots->len == 0) { /* Need to get another burst of free slots from global ring */ - n_slots = rte_ring_mc_dequeue_burst(h->free_slots, + n_slots = rte_ring_mc_dequeue_burst_32(h->free_slots, cached_free_slots->objs, LCORE_CACHE_SIZE, NULL); if (n_slots == 0) { @@ -982,13 +981,12 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, cached_free_slots->len--; slot_id = cached_free_slots->objs[cached_free_slots->len]; } else { - if (rte_ring_sc_dequeue(h->free_slots, &slot_id) != 0) { + if (rte_ring_sc_dequeue_32(h->free_slots, &slot_id) != 0) return -ENOSPC; - } } - new_k = RTE_PTR_ADD(keys, (uintptr_t)slot_id * h->key_entry_size); - new_idx = (uint32_t)((uintptr_t) slot_id); + new_k = RTE_PTR_ADD(keys, slot_id * h->key_entry_size); + new_idx = slot_id; /* The store to application data (by the application) at *data should * not leak after the store of pdata in the key store. i.e. pdata is * the guard variable. Release the application data to the readers. @@ -1078,12 +1076,12 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, /* Failed to get an empty entry from extendable buckets. Link a new * extendable bucket. We first get a free bucket from ring. */ - if (rte_ring_sc_dequeue(h->free_ext_bkts, &ext_bkt_id) != 0) { + if (rte_ring_sc_dequeue_32(h->free_ext_bkts, &ext_bkt_id) != 0) { ret = -ENOSPC; goto failure; } - bkt_id = (uint32_t)((uintptr_t)ext_bkt_id) - 1; + bkt_id = ext_bkt_id - 1; /* Use the first location of the new bucket */ (h->buckets_ext[bkt_id]).sig_current[0] = short_sig; /* Store to signature and key should not leak after @@ -1373,7 +1371,7 @@ remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned i) /* Cache full, need to free it. */ if (cached_free_slots->len == LCORE_CACHE_SIZE) { /* Need to enqueue the free slots in global ring. */ - n_slots = rte_ring_mp_enqueue_burst(h->free_slots, + n_slots = rte_ring_mp_enqueue_burst_32(h->free_slots, cached_free_slots->objs, LCORE_CACHE_SIZE, NULL); ERR_IF_TRUE((n_slots == 0), @@ -1383,11 +1381,10 @@ remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned i) } /* Put index of new free slot in cache. */ cached_free_slots->objs[cached_free_slots->len] = - (void *)((uintptr_t)bkt->key_idx[i]); + bkt->key_idx[i]; cached_free_slots->len++; } else { - rte_ring_sp_enqueue(h->free_slots, - (void *)((uintptr_t)bkt->key_idx[i])); + rte_ring_sp_enqueue_32(h->free_slots, bkt->key_idx[i]); } } @@ -1551,7 +1548,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, */ h->ext_bkt_to_free[ret] = index; else - rte_ring_sp_enqueue(h->free_ext_bkts, (void *)(uintptr_t)index); + rte_ring_sp_enqueue_32(h->free_ext_bkts, index); } __hash_rw_writer_unlock(h); return ret; @@ -1614,7 +1611,7 @@ rte_hash_free_key_with_position(const struct rte_hash *h, uint32_t index = h->ext_bkt_to_free[position]; if (index) { /* Recycle empty ext bkt to free list. */ - rte_ring_sp_enqueue(h->free_ext_bkts, (void *)(uintptr_t)index); + rte_ring_sp_enqueue_32(h->free_ext_bkts, index); h->ext_bkt_to_free[position] = 0; } } @@ -1625,19 +1622,17 @@ rte_hash_free_key_with_position(const struct rte_hash *h, /* Cache full, need to free it. */ if (cached_free_slots->len == LCORE_CACHE_SIZE) { /* Need to enqueue the free slots in global ring. */ - n_slots = rte_ring_mp_enqueue_burst(h->free_slots, + n_slots = rte_ring_mp_enqueue_burst_32(h->free_slots, cached_free_slots->objs, LCORE_CACHE_SIZE, NULL); RETURN_IF_TRUE((n_slots == 0), -EFAULT); cached_free_slots->len -= n_slots; } /* Put index of new free slot in cache. */ - cached_free_slots->objs[cached_free_slots->len] = - (void *)((uintptr_t)key_idx); + cached_free_slots->objs[cached_free_slots->len] = key_idx; cached_free_slots->len++; } else { - rte_ring_sp_enqueue(h->free_slots, - (void *)((uintptr_t)key_idx)); + rte_ring_sp_enqueue_32(h->free_slots, key_idx); } return 0; diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h index fb19bb27d..345de6bf9 100644 --- a/lib/librte_hash/rte_cuckoo_hash.h +++ b/lib/librte_hash/rte_cuckoo_hash.h @@ -124,7 +124,7 @@ const rte_hash_cmp_eq_t cmp_jump_table[NUM_KEY_CMP_CASES] = { struct lcore_cache { unsigned len; /**< Cache len */ - void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */ + uint32_t objs[LCORE_CACHE_SIZE]; /**< Cache objects */ } __rte_cache_aligned; /* Structure that stores key-value pair */ From patchwork Fri Sep 6 19:05:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 173294 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp1129308ilq; Fri, 6 Sep 2019 12:06:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1p3siSGR69daRCJHFVGgDAn0i0T0/X1PidBFZ8W2Fro9TU1q4zTh19unSqr3NSiaupLEU X-Received: by 2002:a17:906:b34a:: with SMTP id cd10mr8876178ejb.300.1567796807924; Fri, 06 Sep 2019 12:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567796807; cv=none; d=google.com; s=arc-20160816; b=XX+J2+zcyZF07WcGx/JiITkZ3HPt7UyvhOl7YCdEUIW5BjhabK4zQVpSu/VHtUcU3x mhCQWCKnBi7/2uzWQP4FpQXR/D5JPxIvZGFQln1WqQPkAcP4eCTH/cl6uA+c/opQ4zvz /E12pomo12ht+V1f/r2qS4HFM+Z42+9z/V2hRoSjVjQket6Vw4eBcTP1JIiR9tVd3OJO ezdMk05f+eG7qA6z4Ri5kNHZixsTsDXs24tALoiD77QV4TJa/0flfRGDUKJm9YR+1x8e 8Jxa3wBSM+bHzpQ9OGtsvTGzMgUPw4KqlIocRq9j99Usg6YsN+eyiJMLO689xA06k+tz 9SVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=N5azophg0p4AciwWhjypWwXIgV/OowSG600oOpg7qRw=; b=LvuUfa+OqxMFDNUOg83WArvnfN9SbX8mzY50xus7bnXlrtSWUo2KI3sEHyYdoejF19 Zp+MJWAfF8p9fQwYsciNiCaHCuuxCvTe0jiizffMB9/s4ue7z/l7mFb95W0coVleTCe6 WQ94Qh+IvEMzuAIccctRCuPg1bUozQStdy5P49aBNQb59dy8POFo6XI7+BjFkkFx0kE+ Ik481szlmvPvsiS/RizGZku6KjlCRBzMPu1jRrzUy+HZ7QgTSIfOLeboV8pCn4opoPfq jzu7IPCWvO5iYVJDjPNNmLpMHazVBeSJ/oUI5aSwy+edb8dwnLOXynOAxpC2+Nc3KifI +VEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id d20si3273160edr.195.2019.09.06.12.06.47; Fri, 06 Sep 2019 12:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 585981BF80; Fri, 6 Sep 2019 21:06:12 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 6EE411BEAE for ; Fri, 6 Sep 2019 21:06:03 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EB6381576; Fri, 6 Sep 2019 12:06:02 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DAA2C3F59C; Fri, 6 Sep 2019 12:06:02 -0700 (PDT) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, jerinj@marvell.com, Honnappa Nagarahalli Date: Fri, 6 Sep 2019 14:05:10 -0500 Message-Id: <20190906190510.11146-7-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190906190510.11146-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v2 6/6] lib/eventdev: use ring templates for event rings X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use rte_ring templates to define ring APIs for 128b ring element type. However, the generic 128b ring APIs are not defined. Doing so, results in changes to 'struct rte_event' which results in API changes. Suggested-by: Jerin Jacob Kollanukkaran Suggested-by: Pavan Nikhilesh Bhagavatula Signed-off-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- lib/librte_eventdev/Makefile | 2 + lib/librte_eventdev/meson.build | 2 + lib/librte_eventdev/rte_event_ring.c | 146 +--------------------- lib/librte_eventdev/rte_event_ring.h | 41 +----- lib/librte_eventdev/rte_event_ring_128b.c | 19 +++ lib/librte_eventdev/rte_event_ring_128b.h | 44 +++++++ 6 files changed, 78 insertions(+), 176 deletions(-) create mode 100644 lib/librte_eventdev/rte_event_ring_128b.c create mode 100644 lib/librte_eventdev/rte_event_ring_128b.h -- 2.17.1 diff --git a/lib/librte_eventdev/Makefile b/lib/librte_eventdev/Makefile index cd3ff8040..4c76bbdf3 100644 --- a/lib/librte_eventdev/Makefile +++ b/lib/librte_eventdev/Makefile @@ -24,6 +24,7 @@ LDLIBS += -lrte_mbuf -lrte_cryptodev -lpthread # library source files SRCS-y += rte_eventdev.c +SRCS-y += rte_event_ring_128b.c SRCS-y += rte_event_ring.c SRCS-y += rte_event_eth_rx_adapter.c SRCS-y += rte_event_timer_adapter.c @@ -35,6 +36,7 @@ SYMLINK-y-include += rte_eventdev.h SYMLINK-y-include += rte_eventdev_pmd.h SYMLINK-y-include += rte_eventdev_pmd_pci.h SYMLINK-y-include += rte_eventdev_pmd_vdev.h +SYMLINK-y-include += rte_event_ring_128b.h SYMLINK-y-include += rte_event_ring.h SYMLINK-y-include += rte_event_eth_rx_adapter.h SYMLINK-y-include += rte_event_timer_adapter.h diff --git a/lib/librte_eventdev/meson.build b/lib/librte_eventdev/meson.build index 19541f23f..8a0fd7332 100644 --- a/lib/librte_eventdev/meson.build +++ b/lib/librte_eventdev/meson.build @@ -11,6 +11,7 @@ else endif sources = files('rte_eventdev.c', + 'rte_event_ring_128b.c', 'rte_event_ring.c', 'rte_event_eth_rx_adapter.c', 'rte_event_timer_adapter.c', @@ -20,6 +21,7 @@ headers = files('rte_eventdev.h', 'rte_eventdev_pmd.h', 'rte_eventdev_pmd_pci.h', 'rte_eventdev_pmd_vdev.h', + 'rte_event_ring_128b.h', 'rte_event_ring.h', 'rte_event_eth_rx_adapter.h', 'rte_event_timer_adapter.h', diff --git a/lib/librte_eventdev/rte_event_ring.c b/lib/librte_eventdev/rte_event_ring.c index 50190de01..479db53ea 100644 --- a/lib/librte_eventdev/rte_event_ring.c +++ b/lib/librte_eventdev/rte_event_ring.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2017 Intel Corporation + * Copyright(c) 2019 Arm Limited */ #include @@ -11,13 +12,6 @@ #include #include "rte_event_ring.h" -TAILQ_HEAD(rte_event_ring_list, rte_tailq_entry); - -static struct rte_tailq_elem rte_event_ring_tailq = { - .name = RTE_TAILQ_EVENT_RING_NAME, -}; -EAL_REGISTER_TAILQ(rte_event_ring_tailq) - int rte_event_ring_init(struct rte_event_ring *r, const char *name, unsigned int count, unsigned int flags) @@ -35,150 +29,20 @@ struct rte_event_ring * rte_event_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags) { - char mz_name[RTE_MEMZONE_NAMESIZE]; - struct rte_event_ring *r; - struct rte_tailq_entry *te; - const struct rte_memzone *mz; - ssize_t ring_size; - int mz_flags = 0; - struct rte_event_ring_list *ring_list = NULL; - const unsigned int requested_count = count; - int ret; - - ring_list = RTE_TAILQ_CAST(rte_event_ring_tailq.head, - rte_event_ring_list); - - /* for an exact size ring, round up from count to a power of two */ - if (flags & RING_F_EXACT_SZ) - count = rte_align32pow2(count + 1); - else if (!rte_is_power_of_2(count)) { - rte_errno = EINVAL; - return NULL; - } - - ring_size = sizeof(*r) + (count * sizeof(struct rte_event)); - - ret = snprintf(mz_name, sizeof(mz_name), "%s%s", - RTE_RING_MZ_PREFIX, name); - if (ret < 0 || ret >= (int)sizeof(mz_name)) { - rte_errno = ENAMETOOLONG; - return NULL; - } - - te = rte_zmalloc("RING_TAILQ_ENTRY", sizeof(*te), 0); - if (te == NULL) { - RTE_LOG(ERR, RING, "Cannot reserve memory for tailq\n"); - rte_errno = ENOMEM; - return NULL; - } - - rte_mcfg_tailq_write_lock(); - - /* - * reserve a memory zone for this ring. If we can't get rte_config or - * we are secondary process, the memzone_reserve function will set - * rte_errno for us appropriately - hence no check in this this function - */ - mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags); - if (mz != NULL) { - r = mz->addr; - /* Check return value in case rte_ring_init() fails on size */ - int err = rte_event_ring_init(r, name, requested_count, flags); - if (err) { - RTE_LOG(ERR, RING, "Ring init failed\n"); - if (rte_memzone_free(mz) != 0) - RTE_LOG(ERR, RING, "Cannot free memzone\n"); - rte_free(te); - rte_mcfg_tailq_write_unlock(); - return NULL; - } - - te->data = (void *) r; - r->r.memzone = mz; - - TAILQ_INSERT_TAIL(ring_list, te, next); - } else { - r = NULL; - RTE_LOG(ERR, RING, "Cannot reserve memory\n"); - rte_free(te); - } - rte_mcfg_tailq_write_unlock(); - - return r; + return (struct rte_event_ring *)rte_ring_create_event_128b(name, count, + socket_id, flags); } struct rte_event_ring * rte_event_ring_lookup(const char *name) { - struct rte_tailq_entry *te; - struct rte_event_ring *r = NULL; - struct rte_event_ring_list *ring_list; - - ring_list = RTE_TAILQ_CAST(rte_event_ring_tailq.head, - rte_event_ring_list); - - rte_mcfg_tailq_read_lock(); - - TAILQ_FOREACH(te, ring_list, next) { - r = (struct rte_event_ring *) te->data; - if (strncmp(name, r->r.name, RTE_RING_NAMESIZE) == 0) - break; - } - - rte_mcfg_tailq_read_unlock(); - - if (te == NULL) { - rte_errno = ENOENT; - return NULL; - } - - return r; + return (struct rte_event_ring *)rte_ring_lookup(name); } /* free the ring */ void rte_event_ring_free(struct rte_event_ring *r) { - struct rte_event_ring_list *ring_list = NULL; - struct rte_tailq_entry *te; - - if (r == NULL) - return; - - /* - * Ring was not created with rte_event_ring_create, - * therefore, there is no memzone to free. - */ - if (r->r.memzone == NULL) { - RTE_LOG(ERR, RING, - "Cannot free ring (not created with rte_event_ring_create()"); - return; - } - - if (rte_memzone_free(r->r.memzone) != 0) { - RTE_LOG(ERR, RING, "Cannot free memory\n"); - return; - } - - ring_list = RTE_TAILQ_CAST(rte_event_ring_tailq.head, - rte_event_ring_list); - rte_mcfg_tailq_write_lock(); - - /* find out tailq entry */ - TAILQ_FOREACH(te, ring_list, next) { - if (te->data == (void *) r) - break; - } - - if (te == NULL) { - rte_mcfg_tailq_write_unlock(); - return; - } - - TAILQ_REMOVE(ring_list, te, next); - - rte_mcfg_tailq_write_unlock(); - - rte_free(te); + rte_ring_free(&r->r); } diff --git a/lib/librte_eventdev/rte_event_ring.h b/lib/librte_eventdev/rte_event_ring.h index 827a3209e..4553c0076 100644 --- a/lib/librte_eventdev/rte_event_ring.h +++ b/lib/librte_eventdev/rte_event_ring.h @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2016-2017 Intel Corporation + * Copyright(c) 2019 Arm Limited */ /** @@ -20,8 +21,7 @@ #include #include #include "rte_eventdev.h" - -#define RTE_TAILQ_EVENT_RING_NAME "RTE_EVENT_RING" +#include "rte_event_ring_128b.h" /** * Generic ring structure for passing rte_event objects from core to core. @@ -88,22 +88,8 @@ rte_event_ring_enqueue_burst(struct rte_event_ring *r, const struct rte_event *events, unsigned int n, uint16_t *free_space) { - uint32_t prod_head, prod_next; - uint32_t free_entries; - - n = __rte_ring_move_prod_head(&r->r, r->r.prod.single, n, - RTE_RING_QUEUE_VARIABLE, - &prod_head, &prod_next, &free_entries); - if (n == 0) - goto end; - - ENQUEUE_PTRS(&r->r, &r[1], prod_head, events, n, struct rte_event); - - update_tail(&r->r.prod, prod_head, prod_next, r->r.prod.single, 1); -end: - if (free_space != NULL) - *free_space = free_entries - n; - return n; + return rte_ring_enqueue_burst_event_128b(&r->r, events, n, + (uint32_t *)free_space); } /** @@ -129,23 +115,8 @@ rte_event_ring_dequeue_burst(struct rte_event_ring *r, struct rte_event *events, unsigned int n, uint16_t *available) { - uint32_t cons_head, cons_next; - uint32_t entries; - - n = __rte_ring_move_cons_head(&r->r, r->r.cons.single, n, - RTE_RING_QUEUE_VARIABLE, - &cons_head, &cons_next, &entries); - if (n == 0) - goto end; - - DEQUEUE_PTRS(&r->r, &r[1], cons_head, events, n, struct rte_event); - - update_tail(&r->r.cons, cons_head, cons_next, r->r.cons.single, 0); - -end: - if (available != NULL) - *available = entries - n; - return n; + return rte_ring_dequeue_burst_event_128b(&r->r, events, n, + (uint32_t *)available); } /* diff --git a/lib/librte_eventdev/rte_event_ring_128b.c b/lib/librte_eventdev/rte_event_ring_128b.c new file mode 100644 index 000000000..5e4105a2f --- /dev/null +++ b/lib/librte_eventdev/rte_event_ring_128b.c @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2019 Arm Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include diff --git a/lib/librte_eventdev/rte_event_ring_128b.h b/lib/librte_eventdev/rte_event_ring_128b.h new file mode 100644 index 000000000..3079d7b49 --- /dev/null +++ b/lib/librte_eventdev/rte_event_ring_128b.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2019 Arm Limited + */ + +#ifndef _RTE_EVENT_RING_128_H_ +#define _RTE_EVENT_RING_128_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "rte_eventdev.h" + +/* Event ring will use its own template. Otherwise, the 'struct rte_event' + * needs to change to 'union rte_event' to include a standard 128b data type + * such as __int128_t which results in API changes. + * + * The RTE_RING_TMPLT_API_SUFFIX cannot be just '128b' as that will be + * used for standard 128b element type APIs defined by the rte_ring library. + */ +#define RTE_RING_TMPLT_API_SUFFIX event_128b +#define RTE_RING_TMPLT_ELEM_SIZE sizeof(struct rte_event) +#define RTE_RING_TMPLT_ELEM_TYPE struct rte_event +#define RTE_RING_TMPLT_EXPERIMENTAL + +#include + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_EVENT_RING_128_H_ */