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 36CBCA328D for ; Wed, 23 Oct 2019 05:10:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2336F1BEEF; Wed, 23 Oct 2019 05:10:07 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70041.outbound.protection.outlook.com [40.107.7.41]) by dpdk.org (Postfix) with ESMTP id 56D0E1BEED for ; Wed, 23 Oct 2019 05:10:06 +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=TWat5OQKSY/AcDTh3qDCFDR+k3d7z+NYLCtG6RzKT6M=; b=NWATaK61IqQHDr0Ar+9MpVc1KBNyN3N3XArlAllml1iAnvDmawgZfxld/uawT6havs3Fh1PFNLEFeDchfU5XqCeMb99meVdgNBw3Ee1mX3vx6USJvbp/y3dr4UsDkTMHPyLQZxo+IDHlhuDg0W/l9tGAupeDzHM3iBCS8hfc4Rc= Received: from DB6PR0801CA0050.eurprd08.prod.outlook.com (2603:10a6:4:2b::18) by AM0PR08MB4194.eurprd08.prod.outlook.com (2603:10a6:208:130::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.24; Wed, 23 Oct 2019 03:10:04 +0000 Received: from VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::207) by DB6PR0801CA0050.outlook.office365.com (2603:10a6:4:2b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.21 via Frontend Transport; Wed, 23 Oct 2019 03:10:04 +0000 Authentication-Results: spf=fail (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: Fail (protection.outlook.com: domain of arm.com does not designate 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT053.mail.protection.outlook.com (10.152.19.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.23 via Frontend Transport; Wed, 23 Oct 2019 03:10:04 +0000 Received: ("Tessian outbound 3fba803f6da3:v33"); Wed, 23 Oct 2019 03:10:02 +0000 X-CR-MTA-TID: 64aa7808 Received: from a16f77d82d58.3 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.4.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 13BAE50D-55AB-4F56-B436-462C321303D1.1; Wed, 23 Oct 2019 03:09:57 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2054.outbound.protection.outlook.com [104.47.4.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a16f77d82d58.3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384); Wed, 23 Oct 2019 03:09:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bLiDiI+pFT4PAascAJ2FiTowNLOgq5K21xRziLvnYvNjcvOhLgMSh7J8+ty/VO3XBimCfJY1RDOTyKxn/2upgki3R62dym13Xcqu/L+xv/1Sa0h8ATFTqaE+sY+A3NiQ7bvuxP2lwFWuahzBkKKGMltsimUe4BzTicYAtdbi+eXt6b10Ey5R99nsfIMykOHvNJ2ecERvPLIsbACIqtgA1DtD4k3WRI6lA+515BCKw54/p30tu91x7Jxzr869SM0pfo7rHxFU0AxGf0ku4szXixCignkwGsUhruPSxnMXPZTZSJZXtoH0mHQLu9/00yRYkEktFidtqyIZYx/Cy2xNyA== 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=TWat5OQKSY/AcDTh3qDCFDR+k3d7z+NYLCtG6RzKT6M=; b=FCe5FjFLp6ly6Btu2bnp5LTY0XsawZMh29ayyKcsYfYMlWKSm+m0NaRgug5FAvZ0pGfVDG9IwzOTgL3rsuvtwcWO2RF+E+DimEWuyUBQW9Sg+JrQupWFLDdl93xDQr0QwM7BLyOq/yF2HPYGNBk5gHugh5lguDG/8FPlio4kw0rPdofWLZsqs3LGV2zAVqjxgjleCWv+V7DjV9tDsPyg1oeOFhQ+UlJc0al+zpnjqNh0aOEB7nokMguS34kzNlnHL62BNKHOqQq/GqA0JsXBTiPW9EpYiXjT30g82proAErMzwsa31T59irknOKbiy5iyK/J0qGiZ72BE/3hiOkDkA== 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=TWat5OQKSY/AcDTh3qDCFDR+k3d7z+NYLCtG6RzKT6M=; b=NWATaK61IqQHDr0Ar+9MpVc1KBNyN3N3XArlAllml1iAnvDmawgZfxld/uawT6havs3Fh1PFNLEFeDchfU5XqCeMb99meVdgNBw3Ee1mX3vx6USJvbp/y3dr4UsDkTMHPyLQZxo+IDHlhuDg0W/l9tGAupeDzHM3iBCS8hfc4Rc= Received: from VE1PR08MB5149.eurprd08.prod.outlook.com (20.179.30.27) by VE1PR08MB5021.eurprd08.prod.outlook.com (20.179.30.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.24; Wed, 23 Oct 2019 03:09:55 +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.2367.022; Wed, 23 Oct 2019 03:09:55 +0000 From: Honnappa Nagarahalli To: "Joyce Kong (Arm Technology China)" , "dev@dpdk.org" CC: nd , "thomas@monjalon.net" , "jerinj@marvell.com" , "stephen@networkplumber.org" , "mb@smartsharesystems.com" , "Gavin Hu (Arm Technology China)" , "ravi1.kumar@amd.com" , "rmody@marvell.com" , "shshaikh@marvell.com" , "xuanziyang2@huawei.com" , "cloud.wangxiaoyun@huawei.com" , "zhouguoyang@huawei.com" , Honnappa Nagarahalli , nd Thread-Topic: [PATCH v2 1/6] lib/eal: implement the family of rte bit operation APIs Thread-Index: AQHViU1XujeUCY0EjUu0Ja6P4PMxx6dniONw Date: Wed, 23 Oct 2019 03:09:55 +0000 Message-ID: References: <1571125801-45773-1-git-send-email-joyce.kong@arm.com> <1571799298-18873-2-git-send-email-joyce.kong@arm.com> In-Reply-To: <1571799298-18873-2-git-send-email-joyce.kong@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 3ae3f942-4be5-4224-971d-c23bde882d3d.0 x-checkrecipientchecked: true Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Honnappa.Nagarahalli@arm.com; x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f8de21ee-9db4-4ffd-a278-08d75766804d X-MS-TrafficTypeDiagnostic: VE1PR08MB5021:|VE1PR08MB5021:|AM0PR08MB4194: x-ld-processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:4941;OLM:4941; x-forefront-prvs: 019919A9E4 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(396003)(136003)(346002)(376002)(39860400002)(366004)(51914003)(189003)(199004)(186003)(14454004)(64756008)(478600001)(11346002)(446003)(33656002)(81156014)(25786009)(81166006)(8936002)(8676002)(86362001)(2501003)(66476007)(66556008)(66946007)(486006)(66446008)(66066001)(52536014)(5660300002)(102836004)(14444005)(26005)(256004)(76116006)(6506007)(476003)(305945005)(6246003)(76176011)(71190400001)(7736002)(6116002)(7416002)(4326008)(3846002)(74316002)(55016002)(229853002)(9686003)(6436002)(99286004)(71200400001)(110136005)(316002)(7696005)(54906003)(2906002)(21314003); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB5021; H:VE1PR08MB5149.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A: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: lw3zeTeyrXCKe83aUfDfX32WDpVIXHxHJl1u1iG/llvM4haOxM8QUWKyCYXUeWeKZZvpnqyJRjA9QgRbwl81gWjgLTzR7ki3XlY8r0ghjURhEN3LJPNo2PIjOXFtHm34DQpXr6h4+MSC4ca9l1KXjd1KUcrka2yRFgypZtXciATFkHE76jmrjYBgItNaNqWOF4cBn4HsPeScvioe8JarmVgpg8EzFmvjbRdL+GOG0gWRa3atr6nwZf552bZ80NncadwTdhxrHDuR75IHvqxXF/wxVcdbWabmQhuTyQubEGDG3qTvuxN9hM7aRutxOGzPpK+AQwVVXwQi65UE8um6BYg3N29EhUyaTop02lhI+XauJS6lWa7syVJe8htS73YW3y+D0TZC92Wg3VLt3bE4h38FE/CeMfUtQgf2yzwiZImOWd3kA4HuDVRWZyYRL7W2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5021 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Honnappa.Nagarahalli@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT053.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)(396003)(136003)(346002)(376002)(39860400002)(1110001)(339900001)(51914003)(189003)(199004)(52536014)(11346002)(478600001)(86362001)(446003)(14454004)(356004)(33656002)(81156014)(81166006)(25786009)(8936002)(8676002)(26826003)(70206006)(70586007)(66066001)(126002)(76130400001)(486006)(2501003)(8746002)(186003)(50466002)(105606002)(102836004)(5660300002)(14444005)(336012)(26005)(6506007)(476003)(76176011)(6246003)(23726003)(99286004)(7736002)(97756001)(47776003)(74316002)(305945005)(6116002)(54906003)(110136005)(3846002)(4326008)(22756006)(229853002)(55016002)(36906005)(9686003)(316002)(46406003)(7696005)(2906002)(21314003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB4194; H:64aa7808-outbound-1.mta.getcheckrecipient.com; FPR:; SPF:Fail; 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: b83193f6-263b-4fe9-16fb-08d757667b0a NoDisclaimer: True X-Forefront-PRVS: 019919A9E4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ylg7sqa6PsR2WvZFWvA7hE/LqfVqYxrGxRh6tAju06TPHHke6Hg3c3e4osBLFvpBXxMfDze4yS12K9IA5kWtRrDxXXXIv9bAzrKqPMYbbJlRz92qT6IJ7tK9UrZcK18xyy1RZO3fK4Io7j/k9PFL8lNBswe+xLdm7kJwxPYoi0yxZhtuo6Gtdm/ueouvAb0RYPeF3PKuiaoiAtXaFp419iSM7OUdaR9WB3hJirfQ+LJjWa3G7N5T0vj5IpyFUuk7xcoKCDH1w9dqMoEJ90QVMfM/O4lKJYF1rQWbInR8RPaWntWTSIkCsPMt1rwBJce31B+vhHHRsd7+ZDVwtu2LyHrW+3dEgl7EXc1rv4xZIPBi66js7M5/FEzkl7bni+Ym4BWNcZHHB/VW6CaGIhgkgBCPlpAX8RHmrArpql8bh7uLhjALY7hD5YBfCJzosWN3 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2019 03:10:04.5135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8de21ee-9db4-4ffd-a278-08d75766804d 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: AM0PR08MB4194 Subject: Re: [dpdk-dev] [PATCH v2 1/6] lib/eal: implement the family of rte bit operation APIs 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" Hi Joyce, Thanks for the patch, few comments. >=20 > There are a lot functions of bit operations scattered and duplicated in P= MDs, > consolidating them into a common API family is necessary. Furthermore, th= e > bit operation is mostly applied to the IO devices, so use __ATOMIC_ACQ_RE= L > to ensure the ordering. The APIs are not taking memory ordering as a parameter. This presents the s= ame problem as the rte_atomic_xxx APIs. IMO, the APIs should take memory or= dering as a parameter. >=20 > Signed-off-by: Joyce Kong > Reviewed-by: Gavin Hu > --- > lib/librte_eal/common/Makefile | 1 + > lib/librte_eal/common/include/rte_io_bitops.h | 112 > ++++++++++++++++++++++++++ > lib/librte_eal/common/meson.build | 1 + > 3 files changed, 114 insertions(+) > create mode 100644 lib/librte_eal/common/include/rte_io_bitops.h >=20 > diff --git a/lib/librte_eal/common/Makefile > b/lib/librte_eal/common/Makefile index a00d4fc..3831313 100644 > --- a/lib/librte_eal/common/Makefile > +++ b/lib/librte_eal/common/Makefile > @@ -18,6 +18,7 @@ INC +=3D rte_malloc.h rte_keepalive.h rte_time.h INC += =3D > rte_service.h rte_service_component.h INC +=3D rte_bitmap.h rte_vfio.h > rte_hypervisor.h rte_test.h INC +=3D rte_reciprocal.h rte_fbarray.h rte_= uuid.h > +INC +=3D rte_io_bitops.h >=20 > GENERIC_INC :=3D rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.= h > GENERIC_INC +=3D rte_memcpy.h rte_cpuflags.h diff --git > a/lib/librte_eal/common/include/rte_io_bitops.h > b/lib/librte_eal/common/include/rte_io_bitops.h > new file mode 100644 > index 0000000..5f778b8 > --- /dev/null > +++ b/lib/librte_eal/common/include/rte_io_bitops.h > @@ -0,0 +1,112 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2019 Arm Limited > + */ > + > +#ifndef _RTE_IO_BITOPS_H_ > +#define _RTE_IO_BITOPS_H_ > + > +/** > + * @file > + * Bit Operations > + * > + * This file defines a generic API for bit operations. > + */ > + > +#include > + > +/** > + * Get a bit. > + * > + * @param nr > + * The bit to get. > + * @param addr > + * The address to count from. > + * @return > + * The value of the bit. > + */ > +static inline int32_t > +rte_io_get_bit(uint32_t nr, uint64_t *addr) { > + return __atomic_load_n(addr, __ATOMIC_ACQUIRE) & (1UL << nr); } Some use cases might need 'relaxed' memory order for this API. So, the user= of this API should be able to provide the memory order. > + > +/** > + * Set a bit to 1. > + * > + * @param nr > + * The bit to set. > + * @param addr > + * The address to count from. > + */ > +static inline void > +rte_io_set_bit(uint32_t nr, uint64_t *addr) { > + __atomic_fetch_or(addr, (1UL << nr), __ATOMIC_ACQ_REL); } Some use cases might need 'release' or 'relaxed' memory order. Similar requirements apply to other APIs too. > + > +/** > + * Set a bit to 0. > + * > + * @param nr > + * The bit to set. > + * @param addr > + * The address to count from. > + */ > +static inline void > +rte_io_clear_bit(int32_t nr, uint64_t *addr) { > + __atomic_fetch_and(addr, ~(1UL << nr), __ATOMIC_ACQ_REL); } > + > +/** > + * Test if a bit is 1. > + * > + * @param nr > + * The bit to test. > + * @param addr > + * The address to count from. > + * @return > + * 1 if the bit is 1; else 0. > + */ > +static inline int32_t > +rte_io_test_bit(int32_t nr, uint64_t *addr) { > + return (__atomic_load_n(addr, __ATOMIC_ACQUIRE) & (1UL << > nr)) !=3D 0; } > + > +/** > + * Set a bit to 1 and return its old value. > + * > + * @param nr > + * The bit to set. > + * @param addr > + * The address to count from. > + * @return > + * The old value of the bit. > + */ > +static inline int32_t > +rte_io_test_and_set_bit(int32_t nr, uint64_t *addr) { > + unsigned long mask =3D (1UL << nr); > + > + return __atomic_fetch_or(addr, mask, __ATOMIC_ACQ_REL) & > mask; } > + > +/** > + * Set a bit to 0 and return its old value. > + * > + * @param nr > + * The bit to set. > + * @param addr > + * The address to count from. > + * @return > + * The old value of the bit. > + */ > +static inline int32_t > +rte_io_test_and_clear_bit(int32_t nr, uint64_t *addr) { > + unsigned long mask =3D (1UL << nr); > + > + return __atomic_fetch_and(addr, ~mask, __ATOMIC_ACQ_REL) & > mask; } > +#endif /* _RTE_IO_BITOPS_H_ */ > diff --git a/lib/librte_eal/common/meson.build > b/lib/librte_eal/common/meson.build > index 386577c..0a65d04 100644 > --- a/lib/librte_eal/common/meson.build > +++ b/lib/librte_eal/common/meson.build > @@ -52,6 +52,7 @@ common_headers =3D files( > 'include/rte_alarm.h', > 'include/rte_branch_prediction.h', > 'include/rte_bus.h', > + 'include/rte_io_bitops.h', > 'include/rte_bitmap.h', > 'include/rte_class.h', > 'include/rte_common.h', > -- > 2.7.4