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 DDC0AC433E1 for ; Thu, 16 Jul 2020 18:22:53 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id AD2B22074B for ; Thu, 16 Jul 2020 18:22:52 +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="xfeyECZm"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="xfeyECZm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD2B22074B 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 E9A341BEA7; Thu, 16 Jul 2020 20:22:50 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70078.outbound.protection.outlook.com [40.107.7.78]) by dpdk.org (Postfix) with ESMTP id 63C0B1BEA5 for ; Thu, 16 Jul 2020 20:22:49 +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=WnZz9ggWkE0oVfbFgCAd7pfmzOynrut+WhTzpbCkYbk=; b=xfeyECZmwkrJRU1OnwyNiCS/6pwD8heXlXoVOs2uTWzIa9VBwEG4oMGhwVDZ81j7NLLWkTB5bMPzAHE2aOjUm79yY7NOXZIEZMBjTKaAqHQoadGwjJFLIBJhlYlagWjgBo64qB31ffCm69aa8T7hhDlroi4vN08Nhcyh/xitDvc= Received: from AM5PR0101CA0005.eurprd01.prod.exchangelabs.com (2603:10a6:206:16::18) by DB6PR0801MB1687.eurprd08.prod.outlook.com (2603:10a6:4:39::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Thu, 16 Jul 2020 18:22:47 +0000 Received: from AM5EUR03FT034.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:16:cafe::4f) by AM5PR0101CA0005.outlook.office365.com (2603:10a6:206:16::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Thu, 16 Jul 2020 18:22:47 +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 AM5EUR03FT034.mail.protection.outlook.com (10.152.16.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Thu, 16 Jul 2020 18:22:47 +0000 Received: ("Tessian outbound c4059ed8d7bf:v62"); Thu, 16 Jul 2020 18:22:46 +0000 X-CR-MTA-TID: 64aa7808 Received: from 985bc4802188.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 58F9E462-DD30-4B06-A911-970233D1EEE0.1; Thu, 16 Jul 2020 18:22:41 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 985bc4802188.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 16 Jul 2020 18:22:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M6IPVbH+iciqKV+IBeiXMAdtxDcocC2D7W/W8wNuUk23Z57KxxvftqRawtcBSCZKzhxJlFy5aD6sU0VCA3iAW/tH+QmQ7W+52oJeIeXskzZhfc6oGFLjSq8WUTTxKHU2gPsn06MO6gelvzD51LYv9B/wlW706hjPqXk6DvO6LdMtlQfdQmR1zv8ry4dGJL2UIQNRDaOdin4wsVdQvZ65kovFW+CQOEdgpCoGDqhDSA8Iu8L7i+YwL5JIPXCYJXRnEGI2y6jVQNHUG2m27wncID3Aakumaq5naQJqVzjli3ZXquWK1Olfud69+L5/JsCympCYL+T7+d9rfwWvYVcesw== 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=WnZz9ggWkE0oVfbFgCAd7pfmzOynrut+WhTzpbCkYbk=; b=f13zrv2iQCHeURiLxkJAdtoPPqrTjX9bXCh+4W3vBtWWlZey9QAYB5iY39Vi3Jjf583sngJSKSle0NyaHpq3RmpPwHbH2Vv4sA4csg4uyizv4uebtuzDH9wLbqvgy9KKVYaWVohGcw+JYS6ZacJZRCfXuEzp3GWluvktEkiv91aeTndGuoxVVYTDSK0O4tXtFdeD9zncH6ZuyfXWg+GTUYmsz9O5NDgnwoTKUORR+yrAEtX4JGde2N2LlNrDe8FSLw8FZjJ6rmH9qCmNmvip4VG7+quGjl7jDt7RRTZbWdo1VaxESutIFatWbJXpS30BPmJaXUI9ZO8ufhwDf+u48A== 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=WnZz9ggWkE0oVfbFgCAd7pfmzOynrut+WhTzpbCkYbk=; b=xfeyECZmwkrJRU1OnwyNiCS/6pwD8heXlXoVOs2uTWzIa9VBwEG4oMGhwVDZ81j7NLLWkTB5bMPzAHE2aOjUm79yY7NOXZIEZMBjTKaAqHQoadGwjJFLIBJhlYlagWjgBo64qB31ffCm69aa8T7hhDlroi4vN08Nhcyh/xitDvc= Received: from DB6PR0802MB2216.eurprd08.prod.outlook.com (2603:10a6:4:85::9) by DB6PR0801MB1976.eurprd08.prod.outlook.com (2603:10a6:4:74::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Thu, 16 Jul 2020 18:22:38 +0000 Received: from DB6PR0802MB2216.eurprd08.prod.outlook.com ([fe80::9d1d:207b:e89d:199d]) by DB6PR0802MB2216.eurprd08.prod.outlook.com ([fe80::9d1d:207b:e89d:199d%10]) with mapi id 15.20.3174.027; Thu, 16 Jul 2020 18:22:38 +0000 From: Honnappa Nagarahalli To: Phil Yang , "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 , Honnappa Nagarahalli , nd Thread-Topic: [PATCH v8 1/3] doc: add optimizations using C11 atomic built-ins Thread-Index: AQHWWy23VaFgQiEhjUmoeBzmSB444KkKhSFA Date: Thu, 16 Jul 2020 18:22:38 +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: <1594875225-5850-2-git-send-email-phil.yang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: b871eaee-f2d8-4a62-a651-20177d7d03cf.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: [70.112.90.121] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: df48d0c5-1a69-402d-8fdc-08d829b53d89 x-ms-traffictypediagnostic: DB6PR0801MB1976:|DB6PR0801MB1687: 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: d+114/UxaMB37lFOF4Otd+TzEDdhll9rsT7cQZIiZDgttyRONAtZ+FG8SgNyj2myPkgIggGpBSrWipLwwZu12T0Cm4gobAF4wm7NNpqGHX5Iqri84nNvD/VJkb6bQMfI8nNO9yJqWYAh04uMJ13WZkbPhUf1dm0MhUUEt/CHBANFzWp+WuD/5i3ey+VuudepKPWcGKjVkRY5ykEjmHBx/w5Zk3eP4Ql4aDCIzMaNDEgjfoor0AjsXPI40ZY+5X2aTCN8wpnKhci/am407cOhhHcL8kcQpKQ9aiVsoPMtZChIXCmtJeIOuBNcJ4OM13hU/VgjcGhnx7tdzjbRpqCoOQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0802MB2216.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(376002)(39860400002)(346002)(366004)(136003)(396003)(2906002)(52536014)(76116006)(478600001)(66946007)(8936002)(8676002)(33656002)(66476007)(66556008)(64756008)(66446008)(71200400001)(86362001)(5660300002)(54906003)(6506007)(7696005)(9686003)(55016002)(83380400001)(4326008)(26005)(316002)(186003)(110136005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: vnItAr23+ijbsY1l6bF9eKcRWWfRSY0Vt/EZl88XzdgTSP1VdUVYu2xo/Q2VeXjcnjWU6OfEoWUg7lRw8fzxRmBpM2/E85YFPUanDZZ8XQXdK3JQAGXEJsoFCeTIv0zA4AQwsfCodgREcRbtAYyxxNxsam3DkMNr+3H55ZttV3y5dkH0LfM1uKEolVYKhOVN00jjoweshv+4A8X1Da7pu421IexwasY4Sm/NXZ7oa2UfKlC3FFHV2z0PkTbBulLkijpEfClxB8jpblk3bygvWIQZELT8c/jSg+k0anMZ+QDc24XZYM48kIOP89ka9o5evEiHdH0ASZ1pe+oO+LZiuoAKkULnSA3un5JbQn8W1HPyjqHgGZCNsKKJiqxI2FAWX0TSAn/L9VbZSo5MpC1pMmsSjN+cLrvANysxjuK89QTG/nWoCgs3wQWaCYEgK+jLgFWZWWwa2/b8u7p150zzM/iq0/5TFggYDxAIyzhxcqH4/8AvF8wiVD5QnEpygp+z Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1976 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: AM5EUR03FT034.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)(396003)(376002)(346002)(39860400002)(136003)(46966005)(5660300002)(336012)(8676002)(186003)(86362001)(83380400001)(36906005)(82310400002)(6506007)(70586007)(54906003)(7696005)(47076004)(110136005)(26005)(70206006)(316002)(356005)(81166007)(2906002)(4326008)(52536014)(82740400003)(478600001)(55016002)(8936002)(9686003)(33656002); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 4f3a840b-e898-429f-969f-08d829b53899 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N2V2yiMvLqvxpsaRWkPyr0aLQvFc8B/Hka+KpiwbckZ58awKpxHDTb/w9XJhhAU2gLGDrbYuPNsLG+v5jPXWgE4JTEsbTTJTbjbZJpZCwiv0RbVGgSTawXU4JV6x3YJtcqXXQbPkLLF79uR//XkSGHSMVX6+/NS65ZWiPO1QcF5Tznm3YCrtm7uNLHUpa2dA6lwd98ImoUCPCsLQSRCujxG03cWGSgLzG4yd6oEIVbYVkJZTC+6DZIFy6xo49sAcnZ2RpATuxXZcD/u8NzCpaXUrh1p4LWgdxoQcNR1fm2kAZ/I6gBEjqqww33REt54m6EQqLbuar7h3YXmiqh9PG/fajQvDfGxq1LyMuruQfHjxv0+KfPVpJiX1kRmwO2Xf+I05HOVYJz5F3/E760luqw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2020 18:22:47.0600 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df48d0c5-1a69-402d-8fdc-08d829b53d89 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: AM5EUR03FT034.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1687 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" > Subject: [PATCH v8 1/3] doc: add optimizations using C11 atomic built-ins >=20 > Add information about possible optimizations using C11 atomic built-ins. >=20 > Signed-off-by: Phil Yang > Signed-off-by: Honnappa Nagarahalli Thanks for the changes, they look good now. David wanted to change 'built-ins' to 'builtins', otherwise Reviewed-by: Honnappa Nagarahalli > --- > doc/guides/prog_guide/writing_efficient_code.rst | 59 > +++++++++++++++++++++++- > 1 file changed, 58 insertions(+), 1 deletion(-) >=20 > 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 > --------------------------- >=20 > -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 of = the > following instruction. > This has a big impact on performance in a multicore environment. >=20 > @@ -176,6 +182,57 @@ It can often be replaced by other solutions like per= - > lcore variables. > Also, some locking techniques are more efficient than others. > For instance, the Read-Copy-Update (RCU) algorithm can frequently replac= e > simple rwlocks. >=20 > +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 counters > +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 allowed > +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 replace= d > 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 DP= DK. > + > +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 that > +the store to guard variable is observable only after the store to payloa= d 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 al= so > observable. > + > Coding Considerations > --------------------- >=20 > -- > 2.7.4