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 D65A7C27C4F for ; Sat, 15 Jun 2024 07:10:03 +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:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:From: To:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VZAtgC22c+KKhYQxrDN1MaUsBpanAgCvr8LCqwklF+A=; b=PnqrzubIDAeSYW6JyiTeAu1Wma STN+GljgxH85qpModiG9NMgQdqVLUD2DGmeYftBjuu0Iu0FGFSRW3mvekKQKf8zOD/m7n9SnVfEqd pvxxftrzD3OqSGn1muVbhI8N9ckRJGLrit9npvYToEty0sPkEC1RfYF/0qEzWt1cT/rnsBz9YqUWq Ywq2QS71IIXijAhVavbIyJ2HwkvZq7LWNPw9MVpJN6//Pn21LlseWZksngzks3VP1O1T/nfb6cZDs ZUQiEKWShchnOuR0ZMiSlXpBTBJe8NXpt/w2gKUGRDrB33HjpPpkI8nY9i2auQYpE+cpgg4yRou9l lVx5oMNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sINXo-00000004rfZ-3oiZ; Sat, 15 Jun 2024 07:09:48 +0000 Received: from mail-4322.protonmail.ch ([185.70.43.22]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sINXl-00000004rea-2GbM for linux-arm-kernel@lists.infradead.org; Sat, 15 Jun 2024 07:09:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1718435377; x=1718694577; bh=VZAtgC22c+KKhYQxrDN1MaUsBpanAgCvr8LCqwklF+A=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=al09To6lFGef0pLt+lAgVXExOeTE7RV2cHxyTFfnDiKPM6HH0JIcwLretKPKvEDkB Ix5L9JkKTfEIK/ZiCrif3IzTEpvAcFVkwOusL1PGEWCsRjs5OgZw5uwSSV8AHjS2gS 8BelcQduzkOZafPBwRjgQpWTmpW1VAeHoLwsail/AbQQ88Dig1tIsWm54EGO/Y2RBb EIcJR5Ko7JSuwBCJdqXbfz+OV2AqT4C/OypMsZWUPvIy++By/GMQj0b2jKMiaBCwwz wmwF3X0uK2onzKhp8BdJZZlkZGlY0gIM2nsS1K0i7NkxaIQWOpwPxeqrvrJWbpXgPA IZu3dEYfErRTg== Date: Sat, 15 Jun 2024 07:09:30 +0000 To: Boqun Feng From: Benno Lossin Cc: Miguel Ojeda , Gary Guo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , 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 , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , torvalds@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, Trevor Gross , dakr@redhat.com Subject: Re: [RFC 2/2] rust: sync: Add atomic support Message-ID: In-Reply-To: References: <20240612223025.1158537-1-boqun.feng@gmail.com> <20240612223025.1158537-3-boqun.feng@gmail.com> <20240613144432.77711a3a@eugeo> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 0fe548fbc11fa01208724021192655e59f7fc5d2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240615_000946_241525_DED7A770 X-CRM114-Status: GOOD ( 26.82 ) 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 15.06.24 03:33, Boqun Feng wrote: > On Fri, Jun 14, 2024 at 09:22:24PM +0000, Benno Lossin wrote: >> On 14.06.24 16:33, Boqun Feng wrote: >>> On Fri, Jun 14, 2024 at 11:59:58AM +0200, Miguel Ojeda wrote: >>>> On Thu, Jun 13, 2024 at 9:05=E2=80=AFPM 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, >>> >>> The truth is I don't know ;-) I don't have much data on which one is >>> better. Personally, I think AtomicI32 and AtomicI64 make the users have >>> to think about size, alignment, etc, and I think that's important for >>> atomic users and people who review their code, because before one uses >>> atomics, one should ask themselves: why don't I use a lock? Atomics >>> provide the ablities to do low level stuffs and when doing low level >>> stuffs, you want to be more explicit than ergonomic. >> >> How would this be different with `Atomic` and `Atomic`? Just >=20 > The difference is that with Atomic{I32,I64} APIs, one has to choose (and > think about) the size when using atomics, and cannot leave that option > open. It's somewhere unconvenient, but as I said, atomics variables are > different. For example, if someone is going to implement a reference > counter struct, they can define as follow: >=20 > =09struct Refcount { > =09 refcount: AtomicI32, > =09 data: UnsafeCell > =09} >=20 > but with atomic generic, people can leave that option open and do: >=20 > =09struct Refcount { > =09 refcount: Atomic, > =09 data: UnsafeCell > =09} >=20 > while it provides configurable options for experienced users, but it > also provides opportunities for sub-optimal types, e.g. Refcount: > on ll/sc architectures, because `data` and `refcount` can be in the same > machine-word, the accesses of `refcount` are affected by the accesses of > `data`. I think this is a non-issue. We have two options of counteracting this: 1. We can just point this out in reviews and force people to use `Atomic` with a concrete type. In cases where there really is the need to be generic, we can have it. 2. We can add a private trait in the bounds for the generic, nobody outside of the module can access it and thus they need to use a concrete type: // needs a better name trait Integer {} impl Integer for i32 {} impl Integer for i64 {} pub struct Atomic { /* ... */ } And then in the other module, you can't do this (with compiler error): pub struct Refcount { // ^^^^^^^ not found in this scope // note: trait `crate::atomic::Integer` exists = but is inaccessible refcount: Atomic, data: UnsafeCell, } I think that we can start with approach 2 and if we find a use-case where generics are really unavoidable, we can either put it in the same module as `Atomic`, or change the access of `Integer`. --- Cheers, Benno > The point I'm trying to make here is: when you are using atomics, you > care about performance a lot (otherwise, why don't you use a lock?), and > because of that, you should care about the size of the atomics, because > it may affect the performance significantly.