From patchwork Wed Aug 28 14:46: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: 172392 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1016094ocp; Wed, 28 Aug 2019 07:46:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+Ufu5ZS+WYrB50JZlfd1yYtSLgG8eRfSftidXg7fJVmJa0ydbLHv6LLU41oa9gnhn4q+6 X-Received: by 2002:aa7:c353:: with SMTP id j19mr4506887edr.292.1567003599469; Wed, 28 Aug 2019 07:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567003599; cv=none; d=google.com; s=arc-20160816; b=m0A5sdjDDBvuzN0QvRpQscXEPesMnvLWGvMn0dPRXVJEgR9vcOrNZ7hmguSWoiukml EkRSDWYpY3tlwaKXMgtBQrpxHU3TkoyHANaeWPKg4plE6QcGLbXQmjwsXsjF7pKN7ROB oVDdAYQ6EDonyo4NP62+tYB6cIEPLeZL4MXCxAg+yxPUYjzve/Gya6e0eJC/4UhCw4bi j30a1t1xvfnu6FVRSXtnPfA66UUbxwDq6G6hWQRYGdXFTJfNq7X3MXtRihlnm2541pGt hOXSl6EF2bDGxz60qpUI2W/oYifToipGCU+/jkplHf0rptmwDM7XjCeDvyQogVrA/Ccp XRuA== 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=apCnlfT4VdvY0z4S2KtKW784z5SCeFFtCLaVX6Yw5I4HI+luR+XRNkyOR2Kah6C4YF BzxPOVA2/NxQMVZNBKUZ5fiH3d7Og8ZqZx3eoK90iKLXWKhucwSPXCEZDafi8Upc5iQ4 ZoOCpHKcFVabjj6qu93WTqezOOBFNvIuKA5jYVU2ZMrHYjG0ZKPeM4phaBb7/yDD78NI EBJOTrkYqsmlxtFdsgxkpijOaQvqNVOnk4MHxLSffiXiXqADsvCx1M9eHtGjAJMizkpZ 08LUBq3eDO0GKLN9dFHLJKaAHbPvRIs6p02s03qibB3nleIK7HsWK6p+SEb5h9Pd5kCT Nk/A== 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 k9si1419680ejz.41.2019.08.28.07.46.39; Wed, 28 Aug 2019 07:46:39 -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 58B621BEC9; Wed, 28 Aug 2019 16:46:37 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id CA4B82952 for ; Wed, 28 Aug 2019 16:46:35 +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 2351428; Wed, 28 Aug 2019 07:46:35 -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 147623F246; Wed, 28 Aug 2019 07:46:35 -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, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, gavin.hu@arm.com, ruifeng.wang@arm.com, nd@arm.com Date: Wed, 28 Aug 2019 09:46:10 -0500 Message-Id: <20190828144614.25284-2-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH 1/5] 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 Wed Aug 28 14:46:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 172393 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1016251ocp; Wed, 28 Aug 2019 07:46:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwLP38yrf5dUIDw0KAzBy3bVQjtRtpF1pqOCAATFDsQGu7NHhg+ldqVm03MPjcRjZ0mJPf X-Received: by 2002:a17:906:185b:: with SMTP id w27mr3507020eje.203.1567003607044; Wed, 28 Aug 2019 07:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567003607; cv=none; d=google.com; s=arc-20160816; b=hswNxYhrmb2SWoPoWyFqLq9cNHnna7OzI0GMLCe/KPnChDWpWAhJz1KPnmO7yDJe0/ XpUS7RR3D0rv1Wk58ER6PfVy/T+wp6hzym1D0gH6uVMkvitABikLgTavta+BNQc48my2 of+U3hVJY/U5aOBX7p4Lm3L+mh7rlQx5uj+WCjjkap0ATdrH9P1n+P46lqFiZwzX27nS qhyoBaFkbP8H7c1COlyRbONmr1Rh3X251ptI8LLD21YKwDdtxAFiRAzLTjQ6zYCJyPzm iIyK1bowI744HZN2IuTmFaXY6lv9HxWg9Ppay45CY0wo/QUUs1ZksvNimXB8FZ5xHCGB rs2A== 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=YE0xLBhdUSbcqZSeWiTBt6N3FhWOYjuxFo9GA5h5eFs=; b=bIJKgwRpRBFf3a43oujZsZizSMDCpVX3oFzTCXdzcpt+ut6caZPGL+7wfF6yxwby8Z R7tJM9wuWVOHgOULfF+hC61X/rZKtIwBxDeNGXh5vOP6tWgZh67zZjAf+OAiDYqqmq6t qBKUHWzSiuE4P5BTz2lzLtdIXrDyiNmW4EKf0oDKGjo9FkxMdYTBt4WFoSYWE8eeQ2PH Y1IAR1jZuZUH3qK7TL5N85b65fexCuUlO1fXwKmFFd7dNxO9XzSlrBrS8UEU0QMTwvY/ dDMI2GXqIMkHkGBahMbsuwZNt3HWQH4KrmZnvlU0Hv8n6DBzHkF8XH2FNlQ1LbpVo/JA Vtzw== 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 s47si1424941edb.351.2019.08.28.07.46.46; Wed, 28 Aug 2019 07:46: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 E35551BF36; Wed, 28 Aug 2019 16:46:39 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 2D65A2952 for ; Wed, 28 Aug 2019 16:46:37 +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 AD85D360; Wed, 28 Aug 2019 07:46:36 -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 967A23F246; Wed, 28 Aug 2019 07:46:36 -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, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, gavin.hu@arm.com, ruifeng.wang@arm.com, nd@arm.com Date: Wed, 28 Aug 2019 09:46:11 -0500 Message-Id: <20190828144614.25284-3-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH 2/5] 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..b9b14dfbb --- /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 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 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 *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 *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 Wed Aug 28 14:46:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 172394 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1016524ocp; Wed, 28 Aug 2019 07:47:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwLR0ST/kbpL57Iji8nPph1CZO4pPH1xRDVUECXUZTXxsuoFqf449rDuTnXXJkahRHi6KK X-Received: by 2002:a50:ef04:: with SMTP id m4mr4482981eds.155.1567003619998; Wed, 28 Aug 2019 07:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567003619; cv=none; d=google.com; s=arc-20160816; b=YXG1G48xykVUDBh8TlvD8ITA+7rOZ4EHGXGnRvxl6cUjwFiFAhj/Rc/pHIyv+ggUO8 x3K6AZHg/erZ+Fa0T9PAzRn9XetSOgz0psMkIud5M69XvcTO/ZmYaLrVyv8eby4swRM7 5vu2I1JjsWhNGs73L4SnjrwIb/wBx9ezkbzkqpj1kr8ervbQcIIpIh81hLACrzRVgB36 KqCbpfhH5ENGcWFS3LwPM2KCwqDG+k3qIh0iO0G2i6eneSiPZGDDodi20KNIVsJ/Sx1B EI2HuwAu8ZfU5DjwWSeJ0tWE9mMeQQ4qe5n6QqT/uPDEJXayP60QM2XsxLIWjFPEagtZ 87Gg== 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=G9vQ57iBfEx3aKo1NMtQUGESs3j/UM71KTlwgBPWY4WSHydRRodTYu1dm/D3iABJWB KBGSfbsu05+AEy59URR8eql/6oAlRFc5L3MbDaGi5fjYQUqgzrncGgwflWLTNEmiv6rO pFLI3qbWO0meaqI3n8a1wqkARgTvHRuEBY8dCuuLsF4aPWOZXg8FU66/ts/5SAgrv9Xx Xx3lw/aCaptRHjtelpFfnE9oGOy2QplwfcDjyraNrBtwfjtdxcmEIzQKHdRbJ6uGMV+F T1pC7hEug++Hctden9EtrJNGRv3lnEjsnGHOoUC3HEflqIfUsuqNYHbdg2IR0UDyw90J /Peg== 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 jp21si1370673ejb.216.2019.08.28.07.46.59; Wed, 28 Aug 2019 07:46:59 -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 9E88D1BFD7; Wed, 28 Aug 2019 16:46:42 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 429E21BEEE for ; Wed, 28 Aug 2019 16:46:39 +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 D28CD1570; Wed, 28 Aug 2019 07:46:38 -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 C08ED3F246; Wed, 28 Aug 2019 07:46:38 -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, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, gavin.hu@arm.com, ruifeng.wang@arm.com, nd@arm.com Date: Wed, 28 Aug 2019 09:46:12 -0500 Message-Id: <20190828144614.25284-4-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH 3/5] 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 Wed Aug 28 14:46:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 172395 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1016662ocp; Wed, 28 Aug 2019 07:47:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzy4Y5YJF196+HdKlA1vWsKDY0dGLv0Pdakq/M7tNyWPnrkJaNSh6zc7lPff5Nq16tCZHRM X-Received: by 2002:a17:906:cc81:: with SMTP id oq1mr3601507ejb.124.1567003627921; Wed, 28 Aug 2019 07:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567003627; cv=none; d=google.com; s=arc-20160816; b=e7yZU5dCzsVhNStSK+gw8Y607gpJm76FGGUeIoDlKig8Xsue8CqlLxPbJeM7TfhcHd NnMjbfDXXyUgsk+9CDsnMbj6irFwYMnnxx6/KQmHwFas5ReXABQAHl4th0mk5ci36D0i wH1op3qzL15Trv3IkqMUBdcDmL5z1lAE3/vaQZifZNUk8hd/qm1u3pLtqgzrY3FTkj+m Lh10f6uMWtDh/2FIOYDwQJevaLTSBvqZY5/12m8NP/lb9wAYHMFeutHhAE+hAUmfXFHY A7BAIpKVneJgHmncJsKOOcK8pj8do8iaht/xyD71EL5YMeHO70iulomfw0xsqdg+TWbA ITFQ== 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=AR09njDVqCUtutygqHBX6O3wUGvT11yyeHiNKkBpq0gfvDSHdrh65RVgkofZM20z3g VDlrdYooeewAIhomuigiYQioPAiUt3f70Wkhg52HG2kNSMvyCNXLHWqo69msouB4r1hA FijNGRsCy1/HfAt9dttnDtaR5mz/fW+a7gq+7txw+M9dNpy/4gsq7bYz/cgzcGpU45AA 3VZpGTUSFEIy/gSRwGoOoh70UgbsVzYYjdFF2Qc9vWli5z0BcjgccH8UvJ7QHxMjSreU UXpqWkrZn4xGggXQnoOgGUkjP+5s0ZRlFIc8Pd6pK/d4+JUMlrbsG6RLG7fBTFMTnNIw H07Q== 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 f50si1363416eda.231.2019.08.28.07.47.07; Wed, 28 Aug 2019 07:47:07 -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 E19021C013; Wed, 28 Aug 2019 16:46:44 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 71A441BEEE for ; Wed, 28 Aug 2019 16:46:40 +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 01A4315AB; Wed, 28 Aug 2019 07:46:40 -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 E251E3F246; Wed, 28 Aug 2019 07:46:39 -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, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, gavin.hu@arm.com, ruifeng.wang@arm.com, nd@arm.com Date: Wed, 28 Aug 2019 09:46:13 -0500 Message-Id: <20190828144614.25284-5-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH 4/5] 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 Wed Aug 28 14:46:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 172396 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1016877ocp; Wed, 28 Aug 2019 07:47:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFSfIGecerIRD/JcP1vqZV+YKARSZXnfhE4OOZVmqYJnD68hpqy/lOEbjNIE1IDFGgxKvu X-Received: by 2002:a05:6402:125a:: with SMTP id l26mr4564304edw.192.1567003636179; Wed, 28 Aug 2019 07:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567003636; cv=none; d=google.com; s=arc-20160816; b=A88hMHHmX6f3QvWRg5kQt3uJTOIQWESoCHSzPB1cCrhWkidwaHJyhl0ivieYWH2jm9 Sq1q8tjcNvopT5PaEZpczDF1bcyQ7SM2U2D+bXoep9gECYBpFuV0CWw41BNsyrf6ppir oU7TWmAA45Lm/TlzYoKXLgY+APfL5JH67kMmQLzUAtCBc7SV+yplPnmgKwfqGaBy4BCU T3p1IGhQC7uJemOs47xEaMgNqMSLlOalgv9qAx5JY3OdHsJOWq4Wh3boUlCRQ+kLBNE+ vXmA3VXx+0GLQVmk5aMnH2RMCuGKqYEtRBui8ehNAd8SUQOK7Fe3Kj7Ax0IBhJtDkJW7 hHvQ== 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=KyjrzDglREJapUriqYhnh+PdzcshucXpNBS9MIjtfJ2ANBtAC4HKwJq0+wVNmZaxdY nAxB6Bz/I81LvjYt0xFTlxSR0ywfypZQFSDLU8LfzL49hDVVKHZ5Tlsyy5dSjWC21hDa rUeMJjx/8UmmYF9do7jD//xr8gLqY7FMoZd0W/s6rC8zHt6dFcxJrt++QAcZL7LhB4Sd 5EJucuvJyhPK6N3BF/6LT5sJCL3PoDmmfDQnioY4bgdI/6OPgicnP1L5kMwNV+Sk09em Q0bwQOpYCVTU5QYXqPNO3Qem+DibslXXjoQcpqQUlawZmXvqlufbA2tasDNT28P80Fx+ jvSQ== 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 x9si1313368ejb.384.2019.08.28.07.47.15; Wed, 28 Aug 2019 07:47:16 -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 D990B1C069; Wed, 28 Aug 2019 16:46:46 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 72E211BEEE for ; Wed, 28 Aug 2019 16:46:41 +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 F3C4815AD; Wed, 28 Aug 2019 07:46:40 -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 DEAA93F246; Wed, 28 Aug 2019 07:46:40 -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, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, gavin.hu@arm.com, ruifeng.wang@arm.com, nd@arm.com Date: Wed, 28 Aug 2019 09:46:14 -0500 Message-Id: <20190828144614.25284-6-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH 5/5] 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 */