From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AA38C433E8 for ; Fri, 17 Jul 2020 04:44:58 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 07C672071A for ; Fri, 17 Jul 2020 04:44:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="lDOP7YuI"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="lDOP7YuI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07C672071A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 196FD1BEBC; Fri, 17 Jul 2020 06:44:57 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2052.outbound.protection.outlook.com [40.107.22.52]) by dpdk.org (Postfix) with ESMTP id D7C242C4F for ; Fri, 17 Jul 2020 06:44:55 +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=1869Imsv38Eg0gaGz95MGXoj9F3pEvYR/kxflQF3U3Q=; b=lDOP7YuI5XKaZQ58K8xKDcAroVJXAoiYr0KwcBR7gB8XBae3dzFZOdGfBkN9tlJNf/qnz5xEU0p56woEiqLMriiMGaHcru6ByJ9nCt4yvA9oqVTuxH49DNgU1u0EszCv9ZSUL/scfpmSfP41y8wDRN6K8jTK9qF2/7p34FZ1d1k= Received: from DB6PR07CA0070.eurprd07.prod.outlook.com (2603:10a6:6:2a::32) by AM4PR0802MB2260.eurprd08.prod.outlook.com (2603:10a6:200:5f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Fri, 17 Jul 2020 04:44:54 +0000 Received: from DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2a:cafe::f0) by DB6PR07CA0070.outlook.office365.com (2603:10a6:6:2a::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.13 via Frontend Transport; Fri, 17 Jul 2020 04:44:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (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=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 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 DB5EUR03FT020.mail.protection.outlook.com (10.152.20.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Fri, 17 Jul 2020 04:44:54 +0000 Received: ("Tessian outbound c4059ed8d7bf:v62"); Fri, 17 Jul 2020 04:44:53 +0000 X-CR-MTA-TID: 64aa7808 Received: from 82c38de4c78c.3 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 70337F75-795D-4D99-B7EA-DEB9794619C2.1; Fri, 17 Jul 2020 04:44:48 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 82c38de4c78c.3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 17 Jul 2020 04:44:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XqpFQy0p1QD07IqZTSPdsFLwLvXOiNl8+ZR8nYmXwtimd+5qCOpurbIVJCRVEfVehnfRyPnvfhLyWnQnEVWtebtDLKxNNmpSEQGebKpf6TpGKYECzqipONYn/LgCr4ufJUavw+z4tLgDu3pPYGKPiPRuPNqSVwVu1OXjqrIN7GFHPWnl5AqjzyA+IH5ShHyiv7g+QocX0iV+sa/TBg25nb9lrpkPJxbVNoJA20HW1qcFyDL3m6qnu8M0AwOLVYKhU9iSuNf3RzOqye0sP9Dy4/s1bCzTxQAe8iJY8yiGLL3KgIxA7zZ4khdAROKDq4+lv87j6s1yF2V9xKREIj92jw== 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=1869Imsv38Eg0gaGz95MGXoj9F3pEvYR/kxflQF3U3Q=; b=LVLClKtqvJIpIhChzPd8Ogky02zSBNXSYzExmWVOm9wQ436SYrKn5+GSZM7x1gjldMAxr7HDtYoXreSr7PSHDXwse4gn6tbZjg522Pk3RM9l0Z7x8q7cOaHbpLFWtK0ngKS2zhb+f5AnBWMH05hbQ7aTVZgz7M/rneKEbc9FRNrJw+aH+X6sl33TTpD57+jpR+NcbZFDtoMRnQIFBMkwplRCQajQbhzbV9ltyr3NThC12MVkNUQ4N6XiQohH4tQCrLIGp8ctPemq2+dQNVkVA6lmo6sPnreO1/T8O81F53HVV9K4vUOESYhEPTc4Ij2ztAwfqq4r94IDTfSKwJWs6g== 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=1869Imsv38Eg0gaGz95MGXoj9F3pEvYR/kxflQF3U3Q=; b=lDOP7YuI5XKaZQ58K8xKDcAroVJXAoiYr0KwcBR7gB8XBae3dzFZOdGfBkN9tlJNf/qnz5xEU0p56woEiqLMriiMGaHcru6ByJ9nCt4yvA9oqVTuxH49DNgU1u0EszCv9ZSUL/scfpmSfP41y8wDRN6K8jTK9qF2/7p34FZ1d1k= Received: from VE1PR08MB4640.eurprd08.prod.outlook.com (2603:10a6:802:b2::11) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.23; Fri, 17 Jul 2020 04:44:47 +0000 Received: from VE1PR08MB4640.eurprd08.prod.outlook.com ([fe80::c2e:9ccb:a690:6863]) by VE1PR08MB4640.eurprd08.prod.outlook.com ([fe80::c2e:9ccb:a690:6863%6]) with mapi id 15.20.3174.026; Fri, 17 Jul 2020 04:44:47 +0000 From: Phil Yang To: Honnappa Nagarahalli , "thomas@monjalon.net" , "john.mcnamara@intel.com" , "drc@linux.vnet.ibm.com" , "dev@dpdk.org" CC: "david.marchand@redhat.com" , "jerinj@marvell.com" , "konstantin.ananyev@intel.com" , Ola Liljedahl , "bruce.richardson@intel.com" , Ruifeng Wang , nd , Marko Kovacevic , nd , nd Thread-Topic: [PATCH v8 1/3] doc: add optimizations using C11 atomic built-ins Thread-Index: AQHWW54cadhRlhrT30eOvFY1Vy3/0qkLMl1Q Date: Fri, 17 Jul 2020 04:44:47 +0000 Message-ID: References: <1594621423-14796-1-git-send-email-phil.yang@arm.com> <1594875225-5850-1-git-send-email-phil.yang@arm.com> <1594875225-5850-2-git-send-email-phil.yang@arm.com> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 2a85bf6c-cf06-4605-8f36-0e770cbae67a.0 x-checkrecipientchecked: true Authentication-Results-Original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; x-originating-ip: [203.126.0.111] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6ae56512-5b05-415e-5471-08d82a0c2624 x-ms-traffictypediagnostic: VI1PR0802MB2288:|AM4PR0802MB2260: x-ld-processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 5ECieDTtB3DsOinvns5hvG2eOF1mMagT+c9kYr5w+OehfD05AGyfWtYbgExcVxKHp5srUVMF86uj72iSgVeRm0QeLus9yO1MDlnY9iwaVmNgDfZ97fM2UIVoDSnucDmfaA5Bui2qnXcdGeRkhmWVBPtQjoojqUlL3pStUB6GDAhEacW4rKpKXrwPjXwJCAwLPcewIXlJmdVi+PkVQk00iCsKQhfgqpOaBq4CARyArm2+giXWb7dS7v1Pja0mn04LJlT9hJfsdYSo/kT4xYm4Lcy096D8LZcrlca5PL1rbIRH/6+72PlrIgaMIUmEEjl21b6qYN1QTQaTsMZSqhYFRg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR08MB4640.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(136003)(376002)(366004)(39860400002)(396003)(52536014)(83380400001)(110136005)(478600001)(55016002)(86362001)(66446008)(66556008)(5660300002)(66946007)(71200400001)(76116006)(54906003)(66476007)(9686003)(2906002)(64756008)(26005)(6506007)(8936002)(4326008)(7696005)(186003)(8676002)(316002)(33656002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: YJ8zdAYdloBwhL1IxVfo9OgCv564xWJ798U3C5CRB5L1VgEyIyoEP0hGCw2tkJzfkdCt0+MxRA4/+qBdmlyLGjRVDffwPdHwSFRNMnjwVdD39q4/R9A2Pq4PU05AZI8nYMurv5QwiwvymYYx3jja0ZrwlxgKrDiZoXR4jDGrQ0FsOERqtSokXz1bdhYJNquc9pxMltNWGiake2P2jUaIdxlbERPXTzVyYMY7ctDv0klK9KUWY2gxDm0RtgRwnkuI8MAtP2ggf6OYhwRXjaiSKNeEo8vrSq/LHKXh2Tse+QDdIWBDAJoHoknYdGZejN5B5H54SAnZHar1rZvc1Rj+t2mXI1S9przii9CUl+B95SH/RrbqMKe6fhAuS+4tEKhqmSiAqwa3/9tvKYjW2D5N460WPiDa/6MfJp8CGyJaVQacBAjBUTgptcMphtt9SMOdngMj0+UeB8OL+/scHhBW12yqo2kHDsiDlSe2O4Xjxzo= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 Original-Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(136003)(396003)(39860400002)(346002)(376002)(46966005)(2906002)(86362001)(8936002)(47076004)(82740400003)(478600001)(110136005)(54906003)(26005)(7696005)(8676002)(4326008)(186003)(336012)(6506007)(70586007)(55016002)(9686003)(316002)(70206006)(33656002)(5660300002)(83380400001)(82310400002)(356005)(52536014)(81166007); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: e85a9954-6117-4676-87cc-08d82a0c2245 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o2GDGQscohycAhCAL3/5QNT4uVkz/ScnmA3+YbotictPtfTg9C+JQxs/uCt96UQRuW+/NCPaKJbKBPdckSgh2ecs2KzRiCpJAYTq23Sk2IG5PAC2WEYpIrsewWX+nHk5VRdPlGa5SnWOju134QcDF6bQyS+GQJWtOG7fTT4fw3ZnrMR0cnykF9CQzWjgbTp83sLYePYOVSw6FLNUIyxXwh25A30caHrGhkz40yOXKIl+trXNnzbItP+o5jzWmwGJVPKkB7DziLYAZ/0ClOoEmvd7yz3M0d0MVLA0VA7Ea5JLI2UMPcJ9YcvlNp5IkVkl1kJTwngtwNVBLczes/una1BR+fN2XfWx06a1AMENc9M0nWWDmszma36liCwNv6AbRsBtLcKcXUAJXvfAxMSoRQ== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2020 04:44:54.0624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ae56512-5b05-415e-5471-08d82a0c2624 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-AuthSource: DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2260 Subject: Re: [dpdk-dev] [PATCH v8 1/3] doc: add optimizations using C11 atomic built-ins 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" Honnappa Nagarahalli writes: >=20 > > Subject: [PATCH v8 1/3] doc: add optimizations using C11 atomic built-i= ns > > > > Add information about possible optimizations using C11 atomic built-ins= . > > > > Signed-off-by: Phil Yang > > Signed-off-by: Honnappa Nagarahalli >=20 > Thanks for the changes, they look good now. >=20 > David wanted to change 'built-ins' to 'builtins', otherwise > Reviewed-by: Honnappa Nagarahalli Will do in the next version. Thanks. >=20 > > --- > > doc/guides/prog_guide/writing_efficient_code.rst | 59 > > +++++++++++++++++++++++- > > 1 file changed, 58 insertions(+), 1 deletion(-) > > > > diff --git a/doc/guides/prog_guide/writing_efficient_code.rst > > b/doc/guides/prog_guide/writing_efficient_code.rst > > index 849f63e..53a1ca1 100644 > > --- a/doc/guides/prog_guide/writing_efficient_code.rst > > +++ b/doc/guides/prog_guide/writing_efficient_code.rst > > @@ -167,7 +167,13 @@ but with the added cost of lower throughput. > > Locks and Atomic Operations > > --------------------------- > > > > -Atomic operations imply a lock prefix before the instruction, > > +This section describes some key considerations when using locks and > > +atomic operations in the DPDK environment. > > + > > +Locks > > +~~~~~ > > + > > +On x86, atomic operations imply a lock prefix before the instruction, > > causing the processor's LOCK# signal to be asserted during execution o= f > the > > following instruction. > > This has a big impact on performance in a multicore environment. > > > > @@ -176,6 +182,57 @@ It can often be replaced by other solutions like p= er- > > lcore variables. > > Also, some locking techniques are more efficient than others. > > For instance, the Read-Copy-Update (RCU) algorithm can frequently > replace > > simple rwlocks. > > > > +Atomic Operations: Use C11 Atomic Built-ins > > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > + > > +DPDK generic rte_atomic operations are implemented by __sync built-ins= . > > +These __sync built-ins result in full barriers on aarch64, which are > > +unnecessary in many use cases. They can be replaced by __atomic > > +built-ins that conform to the C11 memory model and provide finer > memory > > order control. > > + > > +So replacing the rte_atomic operations with __atomic built-ins might > > +improve performance for aarch64 machines. > > + > > +Some typical optimization cases are listed below: > > + > > +Atomicity > > +^^^^^^^^^ > > + > > +Some use cases require atomicity alone, the ordering of the memory > > +operations does not matter. For example, the packet statistics counter= s > > +need to be incremented atomically but do not need any particular > memory > > ordering. > > +So, RELAXED memory ordering is sufficient. > > + > > +One-way Barrier > > +^^^^^^^^^^^^^^^ > > + > > +Some use cases allow for memory reordering in one way while requiring > > +memory ordering in the other direction. > > + > > +For example, the memory operations before the spinlock lock are allowe= d > > +to move to the critical section, but the memory operations in the > > +critical section are not allowed to move above the lock. In this case, > > +the full memory barrier in the compare-and-swap operation can be > replaced > > with ACQUIRE memory order. > > +On the other hand, the memory operations after the spinlock unlock are > > +allowed to move to the critical section, but the memory operations in > > +the critical section are not allowed to move below the unlock. So the > > +full barrier in the store operation can use RELEASE memory order. > > + > > +Reader-Writer Concurrency > > +^^^^^^^^^^^^^^^^^^^^^^^^^ > > + > > +Lock-free reader-writer concurrency is one of the common use cases in > DPDK. > > + > > +The payload or the data that the writer wants to communicate to the > > +reader, can be written with RELAXED memory order. However, the guard > > +variable should be written with RELEASE memory order. This ensures tha= t > > +the store to guard variable is observable only after the store to payl= oad is > > observable. > > + > > +Correspondingly, on the reader side, the guard variable should be read > > +with ACQUIRE memory order. The payload or the data the writer > > +communicated, can be read with RELAXED memory order. This ensures > that, > > +if the store to guard variable is observable, the store to payload is = also > > observable. > > + > > Coding Considerations > > --------------------- > > > > -- > > 2.7.4