From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1F520A2F18 for ; Thu, 3 Oct 2019 05:33:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DE6321BFB6; Thu, 3 Oct 2019 05:33:54 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40076.outbound.protection.outlook.com [40.107.4.76]) by dpdk.org (Postfix) with ESMTP id ABF221BFAE for ; Thu, 3 Oct 2019 05:33:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9n5horO7mxFVgBIAcmiIv6cSsuF0dBGKxFDcPrRetuo=; b=dnCkzuFcJR/qiyArU6ZikT6LH4hKTlMPSjc25HtolZLNjTwEdgopqy4yiMGovIOPxSWF8vKkDy80nLAwcHUl7wVdMMaUN4g3EK88Va2bYksagRSiOaVNAQ5USQ6alhKVT/5A/6WbpyDBqQIY2hmiNmjQ/2FVeNci6uxscOy6GQ4= Received: from AM6PR08CA0002.eurprd08.prod.outlook.com (2603:10a6:20b:b2::14) by VI1PR08MB3790.eurprd08.prod.outlook.com (2603:10a6:803:be::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Thu, 3 Oct 2019 03:33:50 +0000 Received: from AM5EUR03FT059.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::203) by AM6PR08CA0002.outlook.office365.com (2603:10a6:20b:b2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2305.17 via Frontend Transport; Thu, 3 Oct 2019 03:33:49 +0000 Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dpdk.org; dmarc=none action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT059.mail.protection.outlook.com (10.152.17.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2305.15 via Frontend Transport; Thu, 3 Oct 2019 03:33:48 +0000 Received: ("Tessian outbound 0cf06bf5c60e:v33"); Thu, 03 Oct 2019 03:33:46 +0000 X-CR-MTA-TID: 64aa7808 Received: from e116cf7eb986.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.9.53]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id C36714F0-F6A5-4535-83BD-752FB64CEA3F.1; Thu, 03 Oct 2019 03:33:41 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2053.outbound.protection.outlook.com [104.47.9.53]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e116cf7eb986.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 03 Oct 2019 03:33:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AQEryH6lLQ+dY+7THOlb6M/Yo90/uUwJVFrbbJlg9iRip21eLvifN6yM021XlA7KoTiX4mEvevc5tvGx8UNoQ0rDJgnOAguwrC4hByfooZId1QFAYuLCLMUhogjno47ng3nutaWEiXtowXFLQp0W1vPMigvpUEIyw8NOEzBRTQ0LVc6ZlOrTyrW0In9sN3sNMTsP8VB4Uuu/rwnXqbAthnSOt+zXJ+8PHWaghOHcAhA8WMuad2kodu/RgpvIbEHKB+EPMhH6ysjykhnMQfhyCt9h20ezpv+lPU/iVjnBAQZel85uzCh/Z68+coASa3jhGu39X1eJrVjlAp9er9SV/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9n5horO7mxFVgBIAcmiIv6cSsuF0dBGKxFDcPrRetuo=; b=N9Z19rFD+PsF5InmFiz+me0o7K6zZzxyb/xFKaYtY8+x+vgJMG3jvjTLv3jpUdgKwrSB/+N3oMaRnv2X14a6Nqai2w+e32oWYW2o3SgGF+3hH7l7KDNxnJoOMyJoaZtybVfSwyFPKsWx8X4l7ZUaLF8F19TKrCunp4lXdutDGt1JU9ueQgiOD4GVJrjTAwb+3JfEAJ1gA5DdZg+fuFLYtAji6Yv3D4rVKMREyhl1pTvoYyW2R48IFkojSjh8TkV6gy4xO/hHfykVypl4q6ueorYL08HyKIkvm/40AeR6P+yHKOLD6fs1h5H9VAIRQcuPIKWCjVtwBf4VYIbk7Qd0bA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9n5horO7mxFVgBIAcmiIv6cSsuF0dBGKxFDcPrRetuo=; b=dnCkzuFcJR/qiyArU6ZikT6LH4hKTlMPSjc25HtolZLNjTwEdgopqy4yiMGovIOPxSWF8vKkDy80nLAwcHUl7wVdMMaUN4g3EK88Va2bYksagRSiOaVNAQ5USQ6alhKVT/5A/6WbpyDBqQIY2hmiNmjQ/2FVeNci6uxscOy6GQ4= Received: from VE1PR08MB5149.eurprd08.prod.outlook.com (20.179.30.27) by VE1PR08MB4719.eurprd08.prod.outlook.com (10.255.113.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.20; Thu, 3 Oct 2019 03:33:37 +0000 Received: from VE1PR08MB5149.eurprd08.prod.outlook.com ([fe80::8c82:8d9c:c78d:22a6]) by VE1PR08MB5149.eurprd08.prod.outlook.com ([fe80::8c82:8d9c:c78d:22a6%7]) with mapi id 15.20.2305.023; Thu, 3 Oct 2019 03:33:37 +0000 From: Honnappa Nagarahalli To: "Ananyev, Konstantin" , "olivier.matz@6wind.com" , "Wang, Yipeng1" , "Gobriel, Sameh" , "Richardson, Bruce" , "De Lara Guarch, Pablo" CC: "dev@dpdk.org" , Dharmik Thakkar , "Gavin Hu (Arm Technology China)" , "Ruifeng Wang (Arm Technology China)" , nd , nd , nd Thread-Topic: [dpdk-dev] [PATCH 2/5] lib/ring: add template to support different element sizes Thread-Index: AQHVeNjpHH4E8KSmr0+S7oLedx6nO6dHCD0AgAE7iAA= Date: Thu, 3 Oct 2019 03:33:37 +0000 Message-ID: References: <20190828144614.25284-1-honnappa.nagarahalli@arm.com> <20190828144614.25284-3-honnappa.nagarahalli@arm.com> <2601191342CEEE43887BDE71AB977258019196E21E@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB977258019196FAC9@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB977258019196FAC9@irsmsx105.ger.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 83ddbf95-c2e6-478b-8826-c042b3426bdd.0 x-checkrecipientchecked: true Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Honnappa.Nagarahalli@arm.com; x-originating-ip: [70.112.89.188] x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: 7bfd2dea-2a39-4cc3-6b73-08d747b28099 X-MS-Office365-Filtering-HT: Tenant X-MS-TrafficTypeDiagnostic: VE1PR08MB4719:|VE1PR08MB4719:|VI1PR08MB3790: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:506;OLM:506; x-forefront-prvs: 01792087B6 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(346002)(136003)(39860400002)(366004)(396003)(376002)(51914003)(199004)(189003)(55016002)(6116002)(305945005)(14444005)(26005)(54906003)(8936002)(66066001)(7736002)(316002)(2906002)(186003)(110136005)(6246003)(446003)(74316002)(86362001)(476003)(6436002)(256004)(3846002)(4326008)(486006)(6506007)(76176011)(9686003)(2501003)(14454004)(81166006)(81156014)(7696005)(33656002)(30864003)(99286004)(71190400001)(71200400001)(66556008)(64756008)(66446008)(52536014)(76116006)(66476007)(66946007)(478600001)(25786009)(5660300002)(229853002)(102836004)(11346002)(921003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB4719; H:VE1PR08MB5149.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: rJ2CfWAZk78IID3ya2naS2OOtBYUAl0/RwhUsMvSOZocegYvqKF/TkmAlI+aFsnoq2eqgMosKOun92TZ4iuD0s2IQB7Jbxycvznu3uXzd5UwG7uXa0k6IswkiuRnCyNe+PwApoMhVTe6S1fSYNm2gFYs2po6jqPRHdqV0fEyzVQaA6lEw5Pr6R8rOU1pg0mGVJS5TmLk0F/oqyLl5xEppF5I3IumGMJYXNRUK7cnNt1l4eGbpAW+8iUXd4hCmlgPD31crX5aENUSZgxWuHlj9MggoQ1LtY3NvCdryXvjhitscsa7c9EqCfQTltLg5ShdmROGTWGp5wkjZG3tU/wRKS+Xxq71io1arUCc2oOv0NAysox2rLfNMVcux4yb8C1COU2YqjU7wfg+duav2BDiDhXVSHTxqzAR+iAaj2TtQqw= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4719 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Honnappa.Nagarahalli@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT059.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; IPV:CAL; SCL:-1; CTRY:IE; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(376002)(136003)(396003)(346002)(39860400002)(51914003)(189003)(199004)(2906002)(76130400001)(47776003)(4326008)(66066001)(22756006)(229853002)(54906003)(336012)(5660300002)(97756001)(76176011)(6246003)(2501003)(102836004)(6506007)(7696005)(3846002)(14444005)(6116002)(23726003)(26005)(110136005)(50466002)(74316002)(305945005)(7736002)(86362001)(33656002)(52536014)(55016002)(99286004)(9686003)(476003)(70586007)(14454004)(36906005)(8746002)(8936002)(486006)(446003)(63350400001)(46406003)(70206006)(126002)(356004)(186003)(316002)(11346002)(25786009)(81166006)(81156014)(26826003)(478600001)(30864003)(921003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB3790; H:64aa7808-outbound-1.mta.getcheckrecipient.com; FPR:; SPF:TempError; LANG:en; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; MX:1; A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: b915760d-e527-4f52-3ef9-08d747b27a12 NoDisclaimer: True X-Forefront-PRVS: 01792087B6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c686Pi/T7xW6BD2ILkGjwvlnYovPAb7mSe3uOoO0xR2/NebhArcsv63WvxAv+3Njh4I3iSbkxsObuDLdgJJCcYfkXcy6ZZBMxHkhNOcq+SOwZ1j8B6LGqIoeHUXUASTutwRO2Txv1TtqifJs+Jj4ncFyAvRlbr++n34ZUgT5CD7yIB0QQpYTyXQYSg4VQvyE2NU+fthOVghUYyRzVNTUS7ntUlBuL9Xc8t5Uo+HKK25ynkBjGz9bKzci/s6zLY1j1VnLvwUUNZTWy1BLzleDBHkfhWvXiX48Y6aQulIHT8grUS3bcoDemPM1KiYYdItF3Wm8UOxvUhZ6zag8Nwz41QgVXprd1pQM+HYn3fqgYiJb7GTqyVbkt9MrmXRlyX0CqmOCD5IrOw8HCxsq7pjringVNf06BSo66PhhhWWlmE8= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2019 03:33:48.2232 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bfd2dea-2a39-4cc3-6b73-08d747b28099 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3790 Subject: Re: [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 > > > > > > > > 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) :=3D rte_ring.c # > > > > install includes SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include :=3D > > > > 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 =3D 2 > > > > sources =3D files('rte_ring.c') > > > > headers =3D 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 =3D 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); > > > > > > > > > Just an idea - probably same thing can be achieved in a different way= . > > > Instead of all these defines - replace ENQUEUE_PTRS/DEQUEUE_PTRS > > > macros with static inline functions and then make all internal functi= ons, > i.e. > > > __rte_ring_do_dequeue() > > > to accept enqueue/dequeue function pointer as a parameter. > > > Then let say default rte_ring_mc_dequeue_bulk will do: > > > > > > rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, > > > unsigned int n, unsigned int *available) { > > > return __rte_ring_do_dequeue(r, obj_table, n, > RTE_RING_QUEUE_FIXED, > > > __IS_MC, available, dequeue_ptr_default); } > > > > > > Then if someone will like to define ring functions forelt_size=3D=3DX= , > > > all he would need to do: > > > 1. define his own enqueue/dequeuer functions. > > > 2. do something like: > > > rte_ring_mc_dequeue_bulk(struct rte_ring *r, void **obj_table, > > > unsigned int n, unsigned int *available) { > > > return __rte_ring_do_dequeue(r, obj_table, n, > RTE_RING_QUEUE_FIXED, > > > __IS_MC, available, dequeue_X); } > > > > > > Konstantin > > Thanks for the feedback/idea. The goal of this patch was to make it > > simple enough to define APIs to store any element size without code > duplication. >=20 > Well, then if we store elt_size inside the ring, it should be easy enough= to add > to the API generic functions that would use memcpy(or rte_memcpy) for > enqueue/dequeue. > Yes, it might be slower than existing (8B per elem), but might be still > acceptable. The element size will be a constant in most use cases. If we keep the eleme= nt size as a parameter, it allows the compiler to do any loop unrolling and= auto-vectorization optimizations on copying. Storing the element size will result in additional memory access. >=20 > >With this patch, the user has to write ~4 lines of code to get APIs for > >any element size. I would like to keep the goal still the same. > > > > If we have to avoid the macro-fest, the main problem that needs to be > > addressed is - how to represent different sizes of element types in a g= eneric > way? IMO, we can do this by defining the element type to be a multiple of > uint32_t (I do not think we need to go to uint16_t). > > > > For ex: > > rte_ring_mp_enqueue_bulk_objs(struct rte_ring *r, > > uint32_t *obj_table, unsigned int num_objs, > > unsigned int n, > > enum rte_ring_queue_behavior behavior, unsigned int is_= sp, > > unsigned int *free_space) { } > > > > This approach would ensure that we have generic enough APIs and they > > can be used for elements of any size. But the element itself needs to b= e a > multiple of 32b - I think this should not be a concern. > > > > The API suffix definitely needs to be better, any suggestions? >=20 > > > > > > > > > > > > + > > > > +/** > > > > + * @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 =3D __rte_ring_move_prod_head(r, is_sp, n, behavior, > > > > + &prod_head, &prod_next, &free_entries); > > > > + if (n =3D=3D 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 !=3D NULL) > > > > + *free_space =3D 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 =3D __rte_ring_move_cons_head(r, (int)is_sc, n, behavior, > > > > + &cons_head, &cons_next, &entries); > > > > + if (n =3D=3D 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 !=3D NULL) > > > > + *available =3D 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_ */ > > > > -- > > > > 2.17.1