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 DC80BA04F3; Thu, 2 Jan 2020 17:42:40 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 226C61C0DA; Thu, 2 Jan 2020 17:42:40 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 3B36B1C0D7 for ; Thu, 2 Jan 2020 17:42:38 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2020 08:42:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,387,1571727600"; d="scan'208";a="270356474" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 02 Jan 2020 08:42:36 -0800 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 2 Jan 2020 08:42:36 -0800 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 2 Jan 2020 08:42:36 -0800 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 2 Jan 2020 08:42:36 -0800 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.170) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 2 Jan 2020 08:42:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y1BBhS0aHDwPp1j9FwKfk4VCstMSISeXuruezXrvRj15AATUvdCdbk2OjP5BrSzCqxbZGwJbGuCntDgDpeim+ImqWjD8ncQuVApy7wWrz3ysLJRE6jx5izp0puh4cV0wDT6IyaFpgLPUE4E8Fojyb2vCQMxSGRlCyq0P2VMTVnJ1tijfErRPm29yZs4X/hpWobJPAsAYDUt0FW9Qzx/bSsFrF7qu0K/CdDJvgl7kROHIhLisMTo9x0FamxcunsyHcVa+hA8u13lxBjKI0auy0kyELHgT2TjUSqOobst49gjMnr29V2FBv5yjAJTchs/38lHnuOFh3fiE0ak9ko5iuQ== 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=DTJ2+7DVMtzktcwrOMgO4ZaKDThWaI8fJIxFKYQJ2e4=; b=AkRhbWWeOL0IZauyWL9wswQbGnK4ALF7cu9Dl1920Jw5Nsc9UBrrGWaJjLJad9FOA8fioiYEajcYg172v/Ba1wKtQ475+qRvaR4HFlfLaiayoASUSW2waKBg4p1moLUjZLsDXecFeq/JyM+ka7vEKyYc9LeF+vhEwHIlnr5T7MINk3uazGvqBwk5eYnAsz0LABzsGQKRXA0RCtuJR6ACoFoxmyPq7MXuJWGDS5wiXcAFPHXuHSPH9zi9vEHGhdUnAX9BNne7XM42YXp7yVgCKwzMOD8SsEfu3tm1pdwuIYZklaOUC+5WZhfJ2DejAaIlJF/d6RmP0gog/vbXuFgyrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DTJ2+7DVMtzktcwrOMgO4ZaKDThWaI8fJIxFKYQJ2e4=; b=ywNa1GT+MVek67CJB6N8dlc7NCxBvqRPv6SLwEURVmwVfNfg88u3lZ7T1fsRNjDY5qHB5cACnQ9GtOBn58QD078CQaeYQUQTlePRksjNwxwOqweLXOkcvLyaX6dA12zbWgmhb7mDJdGd5DJ/EnP3w/oP1HwOOFB/enYOF2ztfGQ= Received: from SN6PR11MB2558.namprd11.prod.outlook.com (52.135.94.19) by SN6PR11MB3183.namprd11.prod.outlook.com (52.135.112.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.12; Thu, 2 Jan 2020 16:42:31 +0000 Received: from SN6PR11MB2558.namprd11.prod.outlook.com ([fe80::4d86:362a:13c3:8386]) by SN6PR11MB2558.namprd11.prod.outlook.com ([fe80::4d86:362a:13c3:8386%7]) with mapi id 15.20.2602.012; Thu, 2 Jan 2020 16:42:31 +0000 From: "Ananyev, Konstantin" To: Honnappa Nagarahalli , "olivier.matz@6wind.com" , "sthemmin@microsoft.com" , "jerinj@marvell.com" , "Richardson, Bruce" , "david.marchand@redhat.com" , "pbhagavatula@marvell.com" CC: "dev@dpdk.org" , "dharmik.thakkar@arm.com" , "ruifeng.wang@arm.com" , "gavin.hu@arm.com" , "nd@arm.com" Thread-Topic: [PATCH v7 02/17] lib/ring: apis to support configurable element size Thread-Index: AQHVtvB22uIJex5+gEyRiFOc8yhYEqfXpo/w Date: Thu, 2 Jan 2020 16:42:31 +0000 Message-ID: References: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> <20191220044524.32910-1-honnappa.nagarahalli@arm.com> <20191220044524.32910-3-honnappa.nagarahalli@arm.com> In-Reply-To: <20191220044524.32910-3-honnappa.nagarahalli@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzBhY2M5ZDYtMDI0YS00MDk3LTgxZmQtOTJkOWMwMWNkOTgxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibVE1YlZ6TkNwWXQrNFZzUEpqMUVjTjZDR282MUlcL0c4YlwvOXpnR1FLYWYzVW93VUxsSzA5Y1wvZVYySDhBRFRuMiJ9 dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 x-ctpclassification: CTP_NT authentication-results: spf=none (sender IP is ) smtp.mailfrom=konstantin.ananyev@intel.com; x-originating-ip: [192.198.151.189] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0629c272-c0e6-4d89-3e2a-08d78fa2c340 x-ms-traffictypediagnostic: SN6PR11MB3183: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 0270ED2845 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(136003)(396003)(346002)(376002)(39860400002)(189003)(199004)(66556008)(66476007)(26005)(64756008)(66446008)(54906003)(86362001)(186003)(316002)(2906002)(66946007)(76116006)(9686003)(81156014)(81166006)(110136005)(6506007)(478600001)(7696005)(71200400001)(33656002)(8936002)(5660300002)(7416002)(8676002)(4326008)(52536014)(55016002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR11MB3183; H:SN6PR11MB2558.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fmVB28ziObD9i1c9NoMPksway3su1i0bCEe03OSdtTKZVJCLj8LpcqTG4Y8BgPp8zv6HCQlXJXhDjyQDI+FVoaRTK68WU+yUVBLY3mBILzUjeraNWt2CZldNQPYbl5zvb1HZsYPsOfAq+uyJCUMp2GwS/UOTEdu+BE3OmxeR1DcCnJZh0A9eFbL/d+8furzH2vab5PeDnESDFeg9K0HU3RBKUyYuwef05F3UFepEIhaTx6Q3zoF2Akes4aazv2IUBM7bci66EgQpR+zWovJoDHwWenQEKRMnZp6Tz/lG3WQgxJ8/130jVQoHdImSJfsapwgmF6HKfABXWlp4VdwBLa9YFgKeYi5udIzjz586UNE6CELqbjMmIvZUYRZBcnPG0SNNhQfbUarCLPGUTP6h+Oju12nc8p74SEn5nwNzW5HLLgW/4cXEmdJYEmdIni1A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 0629c272-c0e6-4d89-3e2a-08d78fa2c340 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Jan 2020 16:42:31.7896 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: k3AHG3VE3EWLSycjAO8inFbQhX/lDWVMg9We4Vku1N3Mdis98vv2qHCtoaO6j9ZDLtIheYVM1nGAqovPhQmH2sFMzperivloHK4VTOVRaP4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3183 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v7 02/17] 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" > diff --git a/lib/librte_ring/rte_ring_elem.h b/lib/librte_ring/rte_ring_e= lem.h > new file mode 100644 > index 000000000..fc7fe127c > --- /dev/null > +++ b/lib/librte_ring/rte_ring_elem.h > @@ -0,0 +1,1002 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * > + * Copyright (c) 2019 Arm Limited > + * Copyright (c) 2010-2017 Intel Corporation > + * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org > + * All rights reserved. > + * Derived from FreeBSD's bufring.h > + * Used as BSD-3 Licensed with permission from Kip Macy. > + */ > + > +#ifndef _RTE_RING_ELEM_H_ > +#define _RTE_RING_ELEM_H_ > + > +/** > + * @file > + * RTE Ring with user defined element size > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "rte_ring.h" > + > +/** > + * @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 cac= he > + * line size. > + * > + * @param esize > + * The size of ring element, in bytes. It must be a multiple of 4. > + * @param count > + * The number of elements in the ring (must be a power of 2). > + * @return > + * - The memory size needed for the ring on success. > + * - -EINVAL - esize is not a multiple of 4 or count provided is not a > + * power of 2. > + */ > +__rte_experimental > +ssize_t rte_ring_get_memsize_elem(unsigned int esize, unsigned int count= ); > + > +/** > + * @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 esize > + * The size of ring element, in bytes. It must be a multiple of 4. > + * @param count > + * The number of elements in the ring (must 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 wi= th > + * rte_errno set appropriately. Possible errno values include: > + * - E_RTE_NO_CONFIG - function could not get pointer to rte_config s= tructure > + * - E_RTE_SECONDARY - function was called from a secondary process i= nstance > + * - EINVAL - esize is not a multiple of 4 or count provided is not a > + * power of 2. > + * - ENOSPC - the maximum number of memzones has already been allocat= ed > + * - EEXIST - a memzone with the same name already exists > + * - ENOMEM - no appropriate memory area found in which to create mem= zone > + */ > +__rte_experimental > +struct rte_ring *rte_ring_create_elem(const char *name, unsigned int esi= ze, > + unsigned int count, int socket_id, unsigned int flags); > + > +static __rte_always_inline void > +enqueue_elems_32(struct rte_ring *r, uint32_t idx, > + const void *obj_table, uint32_t n) > +{ > + unsigned int i; > + const uint32_t size =3D r->size; > + uint32_t *ring =3D (uint32_t *)&r[1]; > + const uint32_t *obj =3D (const uint32_t *)obj_table; > + if (likely(idx + n < size)) { > + for (i =3D 0; i < (n & ~0x7); i +=3D 8, idx +=3D 8) { > + ring[idx] =3D obj[i]; > + ring[idx + 1] =3D obj[i + 1]; > + ring[idx + 2] =3D obj[i + 2]; > + ring[idx + 3] =3D obj[i + 3]; > + ring[idx + 4] =3D obj[i + 4]; > + ring[idx + 5] =3D obj[i + 5]; > + ring[idx + 6] =3D obj[i + 6]; > + ring[idx + 7] =3D obj[i + 7]; > + } > + switch (n & 0x7) { > + case 7: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 6: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 5: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 4: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 3: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 2: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 1: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + } > + } else { > + for (i =3D 0; idx < size; i++, idx++) > + ring[idx] =3D obj[i]; > + /* Start at the beginning */ > + for (idx =3D 0; i < n; i++, idx++) > + ring[idx] =3D obj[i]; > + } > +} > + > +static __rte_always_inline void > +enqueue_elems_64(struct rte_ring *r, uint32_t prod_head, > + const void *obj_table, uint32_t n) > +{ > + unsigned int i; > + const uint32_t size =3D r->size; > + uint32_t idx =3D prod_head & r->mask; > + uint64_t *ring =3D (uint64_t *)&r[1]; > + const uint64_t *obj =3D (const uint64_t *)obj_table; > + if (likely(idx + n < size)) { > + for (i =3D 0; i < (n & ~0x3); i +=3D 4, idx +=3D 4) { > + ring[idx] =3D obj[i]; > + ring[idx + 1] =3D obj[i + 1]; > + ring[idx + 2] =3D obj[i + 2]; > + ring[idx + 3] =3D obj[i + 3]; > + } > + switch (n & 0x3) { > + case 3: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 2: > + ring[idx++] =3D obj[i++]; /* fallthrough */ > + case 1: > + ring[idx++] =3D obj[i++]; > + } > + } else { > + for (i =3D 0; idx < size; i++, idx++) > + ring[idx] =3D obj[i]; > + /* Start at the beginning */ > + for (idx =3D 0; i < n; i++, idx++) > + ring[idx] =3D obj[i]; > + } > +} > + > +static __rte_always_inline void > +enqueue_elems_128(struct rte_ring *r, uint32_t prod_head, > + const void *obj_table, uint32_t n) > +{ > + unsigned int i; > + const uint32_t size =3D r->size; > + uint32_t idx =3D prod_head & r->mask; > + __uint128_t *ring =3D (__uint128_t *)&r[1]; > + const __uint128_t *obj =3D (const __uint128_t *)obj_table; > + if (likely(idx + n < size)) { > + for (i =3D 0; i < (n & ~0x1); i +=3D 2, idx +=3D 2) { > + ring[idx] =3D obj[i]; > + ring[idx + 1] =3D obj[i + 1]; AFAIK, that implies 16B aligned obj_table... Would it always be the case? =20 > + } > + switch (n & 0x1) { > + case 1: > + ring[idx++] =3D obj[i++]; > + } > + } else { > + for (i =3D 0; idx < size; i++, idx++) > + ring[idx] =3D obj[i]; > + /* Start at the beginning */ > + for (idx =3D 0; i < n; i++, idx++) > + ring[idx] =3D obj[i]; > + } > +} > + > +/* the actual enqueue of elements on the ring. > + * Placed here since identical code needed in both > + * single and multi producer enqueue functions. > + */ > +static __rte_always_inline void > +enqueue_elems(struct rte_ring *r, uint32_t prod_head, const void *obj_ta= ble, > + uint32_t esize, uint32_t num) > +{ > + uint32_t idx, nr_idx, nr_num; > + > + /* 8B and 16B copies implemented individually to retain > + * the current performance. > + */ > + if (esize =3D=3D 8) > + enqueue_elems_64(r, prod_head, obj_table, num); > + else if (esize =3D=3D 16) > + enqueue_elems_128(r, prod_head, obj_table, num); > + else { > + /* Normalize to uint32_t */ > + uint32_t scale =3D esize / sizeof(uint32_t); > + nr_num =3D num * scale; > + idx =3D prod_head & r->mask; > + nr_idx =3D idx * scale; > + enqueue_elems_32(r, nr_idx, obj_table, nr_num); > + } > +} > +