Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1159352lqs; Fri, 14 Jun 2024 18:33:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUbtYMLeDPWoInobRDji/4rKwUQvY3orsDV/FhvE6G72ig6lXd7qDkY9ijwx2TWolQW7KK8Fhn/bHFBXLBFa1DLE/vbidnau/vMD0Y06Q== X-Google-Smtp-Source: AGHT+IHYIb6P049bn2GoBGU8kG1fpealA4jY/IWB0GiWQqmsswNXu8mJPRH53BMhfv5o1LMnHXrk X-Received: by 2002:ad4:4381:0:b0:6b0:74cf:676c with SMTP id 6a1803df08f44-6b2afd94ae9mr43771526d6.63.1718415222091; Fri, 14 Jun 2024 18:33:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718415222; cv=pass; d=google.com; s=arc-20160816; b=fqfX5yMuM6f73wSnG2znAROfG+ORPsiUn75ql4zgSgbOOMV243aGeKpERQo/RbdQ4J 1QDHlNjSFMupG7yX1FNo5c7AnQLkafG7JyoQgWiqhrggBGOGuBOF4QqOTfw2zF3tZlAX t5nmkoQRHzWJqCJq4tuITkXUMxq9KoQcKwjpmOqEIyF4mKv6M76PfM4Fmnz8x8f6utsT N8QTVJZrlG3ToMvMuy8VQuB5U42lL91/YTAAWQHpJSzrkbi/yt0CjqKjQyx3vaw7bN5D z546YXGp/a6ub8WrfyUiiKC8YjccmpSWc3IjKfWd8KMfmUjvXqNB0Ohuz/DXu4kFISAD 0I1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=Nl32RvA7/8lBmewSY1/SnN35QBeCzByhM9oh3NCck0A=; fh=XmjTXUuptcciri8WyJPwCb5NLeO+Un3mL5az4KK/3Rc=; b=GUuQFkrLCCVRwbT8+jN8oU1Si1z96BQNkEf2s3XenbFBuccLzeMWgpYVshHUht6DuY UV92FZYOs5UE45YAIOViNZCij7jj7yYPHUCbpO2uOKPbZvN6BnaHARLziN7sG9gTZeYe 9ZkLcLI8pgo8gpSNd9i2WWWeFNlFppdd6AyIjDYGInhoem00Wf6aSHfuGk0gOxlkX3cg uBFA+eJQ9KB4MdZh85P4++AijreExqMs7b3c5ujPa+tVsUm/kx89snGf9GZmVviYZ2jJ xYKE6dDHGVVS4RKIvYIowfJIeMjAyc71ZcFo/u0leZ6vLNhPmzaHZhWL+P7Zo2c+uJJ8 C53g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KPe4HgZi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-215635-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215635-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b2a5b89686si50441436d6.572.2024.06.14.18.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 18:33:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215635-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KPe4HgZi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-215635-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215635-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BF9F01C2171C for ; Sat, 15 Jun 2024 01:33:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F001BDF44; Sat, 15 Jun 2024 01:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KPe4HgZi" Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A7218F70; Sat, 15 Jun 2024 01:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718415197; cv=none; b=oZJc94HPj+YW3lt6RDQZkifdiPioyhI3HtCVRSnrrV5OoNTH/7vmarkmH3P67VW3Jn17dlTzANANQ/qzxOf7gNoNfbrMaoonGTH2w5DQ4X8tKjSD/nEje/y9XuPaSC3V0rW9hW8y7e6w+WLL8vChBkPbg2R9M4PH1QzzG1eDfn4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718415197; c=relaxed/simple; bh=CN3bPCf2Y3zAyQDEccKddE9q4bieNSMv8+8LxuB+vW4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sNFxifjKI6AFpILWZu1kXOUIrH1ZNkXgsVdgsy3Ey4JSvKhv25SgqnNoa+EiyZwoyh/IsK5WzefeNUlFaSuS0wX4TkFu2TsnOFAH1d0d4R+0zo4Lgq583rLplUi57Wd8P7lPWGPmnqfdtXpvyjipU+Lkg0Nt2Iqt3iisTkZ34cs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KPe4HgZi; arc=none smtp.client-ip=209.85.219.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6b064841f81so21799936d6.1; Fri, 14 Jun 2024 18:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718415194; x=1719019994; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=Nl32RvA7/8lBmewSY1/SnN35QBeCzByhM9oh3NCck0A=; b=KPe4HgZi3DRF3ZueRGhlPSG9rioCIEw8d38MqeO9inr6YvOaj9jzsmRFM3//ACpIIM SacL+6YgXplOH4m4RTwzfUMpnF0mgnkoeX47l0gUBGPqmEoCLHzPpJo4Qm3WhfnYAfNe UtlrYRibfA5BhTK7Z91K0961YI+T/2B48JiA4hpvG0XKPAFD1z+lI4GhOphDjP5DronF oVXrxVuLt+mCn/uqeV0sbzgcoQ+Us7z0vH0OzhgWgWHvI7toHR+uKL2aOLxIUB02hMWq JN9+mFCGCgESX603X8Mx9gUHRri5Rko1iuKqPPTK9+1+nTwNpWrYybwqNLuq3/h9HrNt Hi5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718415194; x=1719019994; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nl32RvA7/8lBmewSY1/SnN35QBeCzByhM9oh3NCck0A=; b=cJnGUKkb07rAV2HAVMgkTw6/T6N57GUEN+oLiKu5WPE17AONC2KLbRCfulEjZCsyE5 6J0MFa/KqpMVlhuknuA7uyM8Klbn9Qn6KTNVHs11Uijj/gBJfrixx0S4AZhLIT9QqbeA HWVP83pCYKnmn8H1k8nac1qoRcdnYZhbovsxQy4ShP4PFSFC1lkxCeUmcZqDWDx8sWED 7W6TzBFDOows5nXZjkcVCi1wB0ELj5JOBeqrw++Xwft49DKr3Wl5qf4GPzRGBxlxzmJm qd2zXNcZXYJGsyG8Z0WiivZkLc6Ku8+fw2JKHMwjI49EJqw2CJhuQK9o8FyZnnDfNLoC OyNA== X-Forwarded-Encrypted: i=1; AJvYcCUmPXWVuYBas55ARjxDySNdZCAWFQ5bDg5ND40fr6k/ZeCfgxB1mBmSUeRpH03Y74IXaxPJsCV2gRtRApkhua+3BRzD+MGl6DDvEmuD3jVbx0qsX4UdgCTFZAcXAu4o/74+pdNYYysgiLq77YQnEm6nY7P01vpoeJc8CrUq9ndp9K/32MTzkdVomqLH0sWjb/AsBlibxxACm7OzvOTC5U4TfhswP/Kc9w== X-Gm-Message-State: AOJu0YxHZRwPGFbutIy064Az0zkcl8D3g7NmFnIeUURXrz8ayL5GJHqX /znes2qWD3Yc1rjDox+LVbJM7Y8oZ1uecr5DyVhO49SjcbTZe3Wv X-Received: by 2002:a05:6214:d89:b0:6a0:c903:7226 with SMTP id 6a1803df08f44-6b2afceb0edmr56977236d6.34.1718415194197; Fri, 14 Jun 2024 18:33:14 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c466ccsm25109666d6.71.2024.06.14.18.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 18:33:13 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfauth.nyi.internal (Postfix) with ESMTP id EDBEC120006A; Fri, 14 Jun 2024 21:33:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 14 Jun 2024 21:33:13 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvtddggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhepvefghfeuveekudetgfevudeuudejfeeltdfhgfehgeekkeeigfdukefh gfegleefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedt ieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfh higihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Jun 2024 21:33:10 -0400 (EDT) Date: Fri, 14 Jun 2024 18:33:10 -0700 From: Boqun Feng To: 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 , =?iso-8859-1?Q?Bj=F6rn?= 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: References: <20240612223025.1158537-1-boqun.feng@gmail.com> <20240612223025.1158537-3-boqun.feng@gmail.com> <20240613144432.77711a3a@eugeo> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 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, > > > > 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 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: struct Refcount { refcount: AtomicI32, data: UnsafeCell } but with atomic generic, people can leave that option open and do: struct Refcount { refcount: Atomic, data: UnsafeCell } 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`. 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. Regards, Boqun > because the underlying `Atomic` type is generic shouldn't change > this, right? > > --- > Cheers, > Benno >