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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F720C27C6E for ; Sat, 15 Jun 2024 03:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OKYJ3/LUSIlGYTS/uyyuzaatAkkwzL7NvAPAeJ56rxw=; b=i/7I3/U+D9t3SYdoJ3fuCFMV3D 5oDwJGqht3dmE93LwILcImwJBXhsBFGbAXyTpjljpV1oBo26WpJaD92Da2DU5wg6v8rcZWkJvcaEw tzglNpmzUi/wO05v2u33SY6Ss7B9E3cH1qiGq9e4H77D3qGXRVAQSwfHkAAFj4KGiZdGjaFndsiRQ WRknZ6nklmDRiXnk2Kf5Hn15GjqMduzHFVxw+HTWVHCOe+6IDrvP2+3+IWstpdkIZoLUb8dT+6REN YGEl7fnuxfB5wIoyockAbE9pctTc/ZxabMx8yw+mQ35vqwZfyeMKIhf43ioHJzM4YUnCXLNlc1PGW 1Vqi9MJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sIJkR-00000004Xac-1Ke5; Sat, 15 Jun 2024 03:06:35 +0000 Received: from mail-bn8nam12on2062c.outbound.protection.outlook.com ([2a01:111:f403:2418::62c] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sIJkO-00000004Xa4-1c5L for linux-arm-kernel@lists.infradead.org; Sat, 15 Jun 2024 03:06:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MmTMh4w4etlJhdB2wLUp+81CVmVSIMl6L8aWkDI0orc+L2E2YEIyUv5hkSE8r6Oe8xMaeg0KkkhWKevZvJvO8wI7/aZHnCtL8TrLY9FlF5FgxbAuN1zRaiQp0EITD38F/tD7x988s08rnfiUfFs+XoXzIgFQltRaRvEym4DM0htnIccyIQiO9KUZ/MBNdYhIdXdI8FcHS60a6rynGPhoqkUcNEDWm24MeLgE8QZHUsj2nfnIxPRIjRHY0oEHKDFBKTWZ9VzEvJBYibtQizLzAUsucfOyfO1nPBkt7k4HGkQjTskvt1QjbfA93yLroMTVcKnhcksvySeiOn6jP65Kiw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OKYJ3/LUSIlGYTS/uyyuzaatAkkwzL7NvAPAeJ56rxw=; b=BCBN5aPiz2B2lZGLE/vbZKpGFzvp3xdgoJBGLLcc317OWq1vzUddxbp6I9FJKuOViyFTZY57Zxn7nPpREyLuDqIkQmY919RxGXyi5ocWGefwderhLGtP/qp/wKKs7OBSF7/V42bbtEVMhxp56zvh8bNJUlbn6I+EjOsnUwcz4rzw5vZTeq007bQdXnjOWkmqAJHjvDYMaOgaICgj/7GevGdLB+k5wg+TDy6tySqpcHtDM9x4xP5d8c6bDoAWjjMlwFEKJL1ylZcgtXKFlrgRuRnBWHMhNre+rkrq5OFXhGJxQ4Bws+kYSnWhC8aEdf9sx5tQNhooVEy9iTl5YooovA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=gmail.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OKYJ3/LUSIlGYTS/uyyuzaatAkkwzL7NvAPAeJ56rxw=; b=E9N8rHE0I8OV6E7I3KM0K2UF3JxlI0Wve2WEcOlYqsYyyNv8M8VsfxPphupALt+LlHg+N3O/O0s4xjhMTfC6PbYQFNykYJ07sE9LDfDCnvjvq/1aSdvWxoAByUP6oT1ARfx1XNLc7d+xDIn7M2H77HVWY1HkAXNxtH3vka8urtxuBO2VL8JS/Tb3U+TBgLsPm1tBk7PoGY2qmHoShBzdGrKYGBL1M8edGdmhVCVMS8BNnTMamkNrStcTmzx7HY2NmXCdVlgGU3e7puEfKgOXjVwLa9GUzOZU4nTaVhQMdrtMxgJIHajpnhZ39M3LtxJBmqRSiJynOzeJWpPkR3dOsA== Received: from BYAPR06CA0030.namprd06.prod.outlook.com (2603:10b6:a03:d4::43) by MN2PR12MB4392.namprd12.prod.outlook.com (2603:10b6:208:264::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Sat, 15 Jun 2024 02:51:21 +0000 Received: from SJ5PEPF000001F2.namprd05.prod.outlook.com (2603:10b6:a03:d4:cafe::58) by BYAPR06CA0030.outlook.office365.com (2603:10b6:a03:d4::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.26 via Frontend Transport; Sat, 15 Jun 2024 02:51:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ5PEPF000001F2.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Sat, 15 Jun 2024 02:51:21 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 14 Jun 2024 19:51:15 -0700 Received: from [10.110.48.28] (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 14 Jun 2024 19:51:13 -0700 Message-ID: <9b8981b1-3b7f-4b79-8f3f-b1635f1d905f@nvidia.com> Date: Fri, 14 Jun 2024 19:51:13 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 2/2] rust: sync: Add atomic support To: Boqun Feng CC: Miguel Ojeda , Gary Guo , , , , , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , "Alice Ryhl" , Alan Stern , "Andrea Parri" , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , "Akira Yokosawa" , Daniel Lustig , "Joel Fernandes" , Nathan Chancellor , Nick Desaulniers , , "Greg Kroah-Hartman" , , Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Catalin Marinas , , , , Trevor Gross , References: <20240612223025.1158537-1-boqun.feng@gmail.com> <20240612223025.1158537-3-boqun.feng@gmail.com> <20240613144432.77711a3a@eugeo> <79239550-dd6e-4738-acea-e7df50176487@nvidia.com> Content-Language: en-US From: John Hubbard In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001F2:EE_|MN2PR12MB4392:EE_ X-MS-Office365-Filtering-Correlation-Id: a8b07a1e-054a-4bd4-3af7-08dc8ce609e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|36860700010|376011|7416011|1800799021|82310400023; X-Microsoft-Antispam-Message-Info: =?utf-8?B?T3k5ZnNjMXJSbENlV3k5VnJ0bHlmMm5hR2MrZEJRY3FhY21FZ2RYRFlFZ1hG?= =?utf-8?B?WXd2cEJsY3RqUGdTeml2VVBkWC94Wk82NUNVVlFpUkRPUnhleVlaTk9SS3Ux?= =?utf-8?B?QmpKOTkwU3UrZzhIWFN5aHNXbHV0blpKSWxwSG5TeGtnTml1QkdhcTl3OTJR?= =?utf-8?B?LzQ3TnFucGw5NTQzMC94OXBHMFZpVTUrK0xLU1E1TlNubVlrVnc3UStFSDI1?= =?utf-8?B?cnNIN0xiTHdtOUs1ejBIcjV1cFAvZXdDd2NzZ0lBa1FRT2NOeUJoUHN1RTdp?= =?utf-8?B?cnZRZlZGTWNVWS9LR3ROK3gvenNQK0RUclYwNHlpbVI5cVovb1pCVmIzWEF4?= =?utf-8?B?R0gzN0JGWDhmQUhmVmlmVWhMcTJPNHpjRHByM0V0eEpqWkRrd202dHNMSUh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sanlrZGNBTnBJK3diM1prUDlMbzNU?= =?utf-8?B?Wll2UlNtUmNvc1NuUkpSaUphTlQxUHVyWUlneVVTYmE2UDkwUUlOditiTUtr?= =?utf-8?B?TmNWR0xZRmhZaG9HWWlhUi9lMVpUWkdWNnIxakcwcnNnVHZ5ZkJEc2ZNdUJk?= =?utf-8?B?TE53UGkrVTY4L1lGWUg0R3Y1aXcxcDBOSmJYa1B2bCtXcW8raVUwYkxWYlJC?= =?utf-8?B?ZG9JM2VGS2o1eVFNWW5xbWpRMUVIaUdLc0JGQ256RDBVZnFPbXZuQ3ZYWXk5?= =?utf-8?B?QlpDc3BSRmxHNTdvSmZmSENRVlNrYU5qazdFd2RGOUd6MjVDeW8zNHN6UUVM?= =?utf-8?B?bENOUU90SzBFMGVUWkkvNEY5OWlNQW9OZjdFT1pEa1IyZFViRnpySlpSQ2dh?= =?utf-8?B?R0ZlNS9xdVlZMXM2Zkh0YUxFM3hBUkNrMUtVZmt0b1JSaC9iKzNrNjdtNXFi?= =?utf-8?B?REtNaHZ5UGtrQ1hoWldmMzIxeDByM1JmMlJxWnR0WTM2TXRxUmdYcmZSbno2?= =?utf-8?B?M2FFNkdWYlZVbDQzV1VialBWekg1LzZyUlNocGliY1Jva1lIaWYxWlNrMHBq?= =?utf-8?B?N1E0SzJwT1pYRVBIbFVOUm1KTTRjVHplWklFK3Ewa1JwdWc9PQ==?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230037)(36860700010)(376011)(7416011)(1800799021)(82310400023);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2024 02:51:21.4473 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8b07a1e-054a-4bd4-3af7-08dc8ce609e8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001F2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4392 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_200632_526784_2DEBEC0D X-CRM114-Status: GOOD ( 29.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 6/14/24 7:39 PM, Boqun Feng wrote: > On Fri, Jun 14, 2024 at 06:28:00PM -0700, John Hubbard wrote: >> On 6/14/24 6:24 PM, Boqun Feng wrote: >>> On Fri, Jun 14, 2024 at 06:03:37PM -0700, John Hubbard wrote: >>>> On 6/14/24 2:59 AM, Miguel Ojeda wrote: >>>>> On Thu, Jun 13, 2024 at 9:05 PM Boqun Feng wrote: >>>>>> >>>>>> Does this make sense? >>>>> >>>>> Implementation-wise, if you think it is simpler or more clear/elegant >>>>> to have the extra lower level layer, then that sounds fine. >>>>> >>>>> However, I was mainly talking about what we would eventually expose to >>>>> users, i.e. do we want to provide `Atomic` to begin with? If yes, >>>>> then we could make the lower layer private already. >>>>> >>>>> We can defer that extra layer/work if needed even if we go for >>>>> `Atomic`, but it would be nice to understand if we have consensus >>>>> for an eventual user-facing API, or if someone has any other opinion >>>>> or concerns on one vs. the other. >>>> >>>> Well, here's one: >>>> >>>> The reason that we have things like atomic64_read() in the C code is >>>> because C doesn't have generics. >>>> >>>> In Rust, we should simply move directly to Atomic, as there are, >>>> after all, associated benefits. And it's very easy to see the connection >>> >>> What are the associated benefits you are referring to? Rust std doesn't >>> use Atomic, that somewhat proves that we don't need it. >> Just the stock things that a generic provides: less duplicated code, > > It's still a bit handwavy, sorry. > > Admittedly, I haven't looked into too much Rust concurrent code, maybe > it's even true for C code ;-) So I took a look at the crate that Gary > mentioned (the one provides generic atomic APIs): > > https://crates.io/crates/atomic > > there's a "Dependent" tab where you can see the other crates that > depends on it. With a quick look, I haven't found any Rust concurrent > project I'm aware of (no crossbeam, no tokio, no futures). On the other > hand, there is a non-generic based atomic library: > > https://crates.io/crates/portable-atomic > > which has more projects depend on it, and there are some Rust concurrent > projects that I'm aware of: futures, async-task etc. Note that people > can get the non-generic based atomic API from Rust std library, and > the "portable-atomic" crate is only 2-year old, while "atomic" crate is > 8-year old. > > More interestingly, the same author of "atomic" crate, who is an expert > in concurrent areas, has another project (there are a lot projects from > the author, but this is the one I'm mostly aware of) "parking_lot", > which "provides implementations of Mutex, RwLock, Condvar and Once that > are smaller, faster and more flexible than those in the Rust standard > library, as well as a ReentrantMutex type which supports recursive > locking.", and it doesn't use the "atomic" crate either. > > These data could mean nothing, there are multiple reasons affecting the > popularity of a library. But all the above seems to suggests that you > don't really need generic on atomic, at least for a lot of meaningful > concurent code. > > > So if we were to make a decision right now, I don't see that generic > atomics are winning. Of course, as I said previously, we can always add That does seem to be the case: the non-generic flavor looks more popular so far. > them if we have learned more and have the consensus. Yes, I suppose waiting might be better. I expected the Atomic to be more popular than it actually is... thanks, -- John Hubbard NVIDIA