Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1244462lqs; Sat, 15 Jun 2024 00:09:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6nGzHt033QJSqAvKNO9gY/HXZSUqY2rRVgQ5Bh232QEZWxIH8rjnS52DRcBzxgwPoidlLpTEOpcNhkF4uJWQof/bC1HdnAmMkiXEqug== X-Google-Smtp-Source: AGHT+IGZLkdOd346LaeCknsro5FH9JubW6wDz4t/cRtgTYiTmNqN3rqcsZIPf1jT1GcujfNqCWE5 X-Received: by 2002:a17:907:a581:b0:a6f:76db:7c60 with SMTP id a640c23a62f3a-a6f76db8412mr51901266b.24.1718435390691; Sat, 15 Jun 2024 00:09:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718435390; cv=pass; d=google.com; s=arc-20160816; b=IMmv4UfaQ8LIzuzP44T48Qa5x7yzXyn69V5z06eggO6DDW8SpSo2bBur3jEKXPa5Zz rkaMqLPmQ1rw/kFxakDsnF7UAhGWlnV5Ie4YJvuXxZVAOSdvhuU+SGd12uKp4fljISCi KSHRHf1wTnwbwlhpR+c/AiAHauqIrF4H3bYNlytDAEqtn7RlS/TjNlE/HIDHOaHElbSH FkIycKOzbNBFLfBBNOQ27iETb3Ia9kz7c0dHVe/oMsWNHBBaKR/Bt2Vv2BJOEf8LwZ90 tJnYxwexP4wCGNTibkYnmwGS0APjkzvTaG4B9szFoaOvqkdf/iT1MREczoP5CrM7lsL4 HZhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=VZAtgC22c+KKhYQxrDN1MaUsBpanAgCvr8LCqwklF+A=; fh=1kT5UWgMMIJZNSDll1bn+M0pgFI5y8CP8IBdNb9h1dM=; b=irNNWgU0pfFTBDuAS5YqidjFlGGpOJF9irO2LHtFP/LpzpL/rn8ZruY0XH8JBQs64j +qJzyWFnstuzAvOkTajAOj63Dk9wabR9fpv/DYUitoSUX7P86JUvPbC3o/EV6bM+4gGE 9XjBzrE/nXXsFFT2e9Q+XMKq9rxOLnHsmQUW2wJqMsHumtsKOhg0SWlzCFl+NH2tA6py HtI6AzAVS1XDnERGiVmvAuptgctLBnAhurMm2vvBdpLsoPTYrWRc6+tXnMgRsQvtkrND u6np6tQfIP0mN4NR4IzllrwApz2dSEVyCMKxGZ0jyDTMSixDyJ+tcycDQJI7LCwHzK9S /c8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=al09To6l; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-215739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d21681si238932566b.127.2024.06.15.00.09.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 00:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=al09To6l; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-215739-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3E8FC1F220F5 for ; Sat, 15 Jun 2024 07:09:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B36FA1755A; Sat, 15 Jun 2024 07:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="al09To6l" Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B00C979F0 for ; Sat, 15 Jun 2024 07:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718435383; cv=none; b=uiTDsEZJM5MVF2FvE4U+dT0EERZPdpV9QENLdoHxQWYz2DHRjUAMMJH46rCbDToPIMxzhfq9PpexSCn4ZXe7osNIaChqss8OL5pjEWVjonxKgQndUmIDzHvp5XCdiHbIxGG2gAiy7JGYXcM8Yi1nmoNLPchopRTS2S6D4yRprsM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718435383; c=relaxed/simple; bh=InMc+8IWJ3kDnz0Ha0kfcXNeCtlY2AtkImdW3XBWYi0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J4TBTS8vtMZa1Z+uONZz9+ZN9CS1FJ8+914WxMB+2CSNXMOJH+xLikVyQenl5wa4SKvcgBY4eOrimz9W1WbY+HCLM/2MghplxCbmxcLptdM79ACuOkYeuAwlH6yxFy1fDtPk/cMA+UjaO2bbVAk1n0mPq9bX0QYhzYJPhJTUWLc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=al09To6l; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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.