From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (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 6DB01C2C6 for ; Fri, 14 Jun 2024 14:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718374716; cv=none; b=iSzwtV5xsQ082UBVLb5o/U/Zcx5/KdoqhvHXFQ9CQaOp+CKVex0YWiCAsh9knP7lhVMaqDFBPNeo80Dkjz9Gwqr24db1qDeb3SSQie2GIpEgcgireiQ2RY8X/NR+n2P/Vv09Wzr8GFH+I/p648YTsk6hs9+VSp4bk3kyO97r+eU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718374716; c=relaxed/simple; bh=AzsmAzBa3FyhGwMJs7CFC6ijvLpC7MBVBXc1nB27RF8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mi8una/Vv/1K0S0ybV4V1fZ8os133RsAfgRj+gB3aqgV/5UUK97KZcT0flH7A4Z1xX1UlZKSsr5/o8S80f/xDv5w1/5TCqjUJ1WVKcH8g9Bi0N+hrJvRwLm86nKZ4tW9ryfXeLpEHMvR8FmYnJNCWHRMmBChRHsp+nfVP9wSEfg= 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=B1+joMPm; arc=none smtp.client-ip=209.85.161.47 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B1+joMPm" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5bad217c51aso1185468eaf.1 for ; Fri, 14 Jun 2024 07:18:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718374714; x=1718979514; darn=lists.linux.dev; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=+sjDmlk8xndLaxRABwpUKDEvjWtvENBQR7ofiVHlQf8=; b=B1+joMPm9ZeZcwDCPGBg100u/OdaCQqAD0gAayUAE3iQBHVIYvZmGMfcL5q1vQRaeQ 0/geKot9cz+Z0sOk0At9HbW5/adxKLyoKiVRSCFAur8LtYZjkW6ZmizXC732RG6ypUKv l/Cj7IUoIp+FHR2qMYsMVRyCrLOVhU4xw5P4jlkDP0nS/O/PLYUB57MWAAhfoMy3pcO9 AGZf4aNxMZpbxah5riAUuI/herpT6DakDTEyKwd9GAJto/45eLN475l/++PIYPnL3g7C sVGaH2ijVLOygftvxfc+oHuBpiTVsL5yyB17ad8zvaBxFU+zSB5dk4dFQe6wzrjG4Xo1 zzig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718374714; x=1718979514; h=in-reply-to: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=+sjDmlk8xndLaxRABwpUKDEvjWtvENBQR7ofiVHlQf8=; b=qesKiV2br875+P0BUKsbbRNb5lp2VGXMMxnPi+Cu+n7nb/kmm25y28zYY8SuNRHPut TwCo1MtswoVoW8xfCREyeN1oBW4du/O3OvtfqiRWpp1gq1Vd3EejCNRtbgrk0RRYDCJy A7faIHMYsICa1HYckWvSvyyoXF8sCYYFUoDcAxBnXIDSTZj88ZCu8oZZgvDYiOjqeKwC wNusEoZAholOc9jEF+lAEPdCUhBCGKUNFNhFPRRfH4hbxOK6L4grFm8leh+NyGQCTI+E ub60OsYSf/Wc0ZOjiJ652Wq1eT5wrWHCefb1Xrlcsa58x1Mrtwi6VyHd0WtfjO1YJbOt XNtw== X-Forwarded-Encrypted: i=1; AJvYcCVzlakkKqOb+ZRNu+PYAo7KrqAcTS7AnKN9R38EJ2ZWjOF1gDu/6FLnCB1xebUuJvbhZLv3+tI6OO3AmbDYR31tEFfgqQ== X-Gm-Message-State: AOJu0YyFzjX/6Eob5g96uvmIB3O1BfGK9bQTCJROFrhrQBxl7KiTL7Ff lJDpCNIOfL4vqU9w+JO2FoRNA6UJbpqp51E7zWHC3+uNKGLDXSf/ X-Google-Smtp-Source: AGHT+IHksCM6QMMN5oCKowkEIaoVhI9skWX8S0kfwKK9ws9t3YFTdPmgNyYWeEUIfdx/qQgRrfSgkw== X-Received: by 2002:a4a:344e:0:b0:5bd:b100:8ab1 with SMTP id 006d021491bc7-5bdb1008d1bmr1669345eaf.7.1718374714251; Fri, 14 Jun 2024 07:18:34 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c1ff4fsm18535236d6.47.2024.06.14.07.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 07:18:33 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfauth.nyi.internal (Postfix) with ESMTP id B89AD1200068; Fri, 14 Jun 2024 10:18:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 14 Jun 2024 10:18:32 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeduledgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Jun 2024 10:18:31 -0400 (EDT) Date: Fri, 14 Jun 2024 07:18:30 -0700 From: Boqun Feng To: Peter Zijlstra Cc: 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 , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , 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> <20240614095124.GN8774@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240614095124.GN8774@noisy.programming.kicks-ass.net> On Fri, Jun 14, 2024 at 11:51:24AM +0200, Peter Zijlstra wrote: > On Thu, Jun 13, 2024 at 09:30:26AM -0700, Boqun Feng wrote: > > > We can always add a layer on top of what we have here to provide the > > generic `Atomic`. However, I personally don't think generic > > `Atomic` is a good idea, for a few reasons: > > > > * I'm not sure it will bring benefits to users, the current atomic > > users in kernel are pretty specific on the size of atomic they > > use, so they want to directly use AtomicI32 or AtomicI64 in > > their type definitions rather than use a `Atomic` where their > > users can provide type later. > > > > * I can also see the future where we have different APIs on > > different types of atomics, for example, we could have a: > > > > impl AtomicI64 { > > pub fn split(&self) -> (&AtomicI32, &AtomicI32) > > } > > > > which doesn't exist for AtomicI32. Note this is not a UB because > > we write our atomic implementation in asm, so it's perfectly > > fine for mix-sized atomics. > > > > So let's start with some basic and simple until we really have a need > > for generic `Atomic`. Thoughts? > > Not on the generic thing, but on the lack of long. atomic_long_t is > often used when we have pointers with extra bits on. Then you want a > number type in order to be able to manipulate the low bits. I mentioned my plan on AtomicPtr, but I think I should have clarified this more. My plan is: pub struct AtomicIsize { #[cfg(CONFIG_64BIT)] inner: AtomicI64 #[cfg(not(CONFIG_64BIT))] inner: AtomicI32 } i.e. building AtomicIsize (Rust's atomic_long_t) based on AtomicI64 and AtomicI32. And we can a AtomicPtr type on it: pub struct AtomicPtr { inner: AtomicIsize, _type: PhantomData<*mut T> } Of course, I need to do some code generating work for AtomicIsize and AtomicPtr, I plan to do that in Rust not in scripts, this will keep the rust/kernel/sync/atomic/impl.rs relatively small (i.e. the Rust/C interface is smaller). I can include this part in the next version, if you want to see it. Regards, Boqun