From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 44FC1255F33 for ; Mon, 14 Jul 2025 13:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752500584; cv=none; b=MeLaZgzsekMe2u8ItqA2zBjs4rC8xH7xUzeeVslbHGidhjfzyGFChDSSoZl4rCh3lskgsn4jNQ0nMUzfktU4Ig3sFfiesvwC0zov4BMv/4c/YCGqQ8JaTFcIyTuxwSdt/RJNdzbU+w5cvTPEDA+9Yh5nN69mW3bZSGxJu0ayK7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752500584; c=relaxed/simple; bh=WPxyElylVhF0iPQIfxiTW4zQCOTfAgY1wQytxJ2fMiY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d3KkAWgCzFD9whjt8NynJp/NAkoRr3qA67+AQyH3U6aiM1liJyC2IiGoEgASUaaE9hrFj/fpdkU/rB+E/CVlH4kAvAtUWy0KPtKNPK6zNXUpQZHoh5bcDGFYwKXtIFrRlOZbfz+nCfTGr4HVg5s2cCPepFt610boPzoUz/H2DA8= 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=msLrzced; arc=none smtp.client-ip=209.85.222.171 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="msLrzced" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7e32cf22fdfso58177585a.0 for ; Mon, 14 Jul 2025 06:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752500581; x=1753105381; 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=fjFmGdXaAaiu0Ffhi5wpwHapt3S54QcOxUCblcGZllY=; b=msLrzcedyg/VoZ/HJlOrDIDR7MjVgNKqR/BSF+7k3ckVdMXDvc+EX5OCuQxhOP2Z1B wok7dWZCUvCx/he+xneXZohkN8fsUHGI6vW01ccq3U/qAdv8nWJr4nbI/rVVEaRYstGC Cb4TuAjzi+wNs70AqGiEKL9gKrWOuWkmJ/Z7RZEf5JSpZxvtSTLZuDaFxC4nfHy5iR7P SOh830u3cJ7dP+x3pfTpsYKyftEJBnwZKyqDTEnWFZoBlQqLoitzkYESvu2OL6ZrU+n6 X0RkPhfdKVupFaT+R/W5df8z6ochYloK+3Nbwt9c6LlIW5dA/Dgyq/C1cvZSjPEfcKlj 3IMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752500581; x=1753105381; 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=fjFmGdXaAaiu0Ffhi5wpwHapt3S54QcOxUCblcGZllY=; b=rm0W4AfzWus7+cULRm0C5BSn+teaUApALc+d7gsBpIIeqpHr2vghIhEBkrGktZnxsY uO/fyE+0ORZtTdE3UzoYruIXZa0oGyfFdGTRIAd1bdIhi0c4FHKgFDg/ZvlaQQ4TqY5b rdPxMuFvhf34sMuS0dJj4+xkpXywPsW5U+xMKSF09J0bAzAgPMM+MEXM9CRyUp9HzuCN 0w8aWteWzRSMMJSTfv2+7mF4VzrPburmf6rYZhwTaET5oilp5YjuSAzeiSQ29zenQg3O X1+930f3zD6HNRJ18bjNCVTAbDPAkC5JLXr2oyb6g0twBHThJI7l+esVtxVTO2Q+ewbv XSMg== X-Forwarded-Encrypted: i=1; AJvYcCVDm34HR5RXmiI9UKksZBkZl6usUD1C+Wmq0/ZPo3XdONCmffPoy6pjSKUebQKzbLIi+6tS@lists.linux.dev X-Gm-Message-State: AOJu0Ywn70IWbjbWa0f1gi4yUC8CDpYqOvY05QUAWHulLwvwGHXlJWQG 9CbM6lWxrTRMXEGFzRpP1MbLNtiSNSJFY9Vq1yQTZWoKej0ZwMGjRPqj X-Gm-Gg: ASbGncvXzHV9GHhdeGtQAhKX8+5kwvICaBO+QuLeR2I6lNFWT0vWJ+spyyTMLwAYS9f NEXc176mqLLeKUC5pctg6fqXWisns63H2kdg5hT6OdMTMkXEOOCeve/yEAyVONzTU/Q7x/o34Sf z/TvdoyV3CGcwFg+WQtg3nuxyp27TY33KgC8svUwAWn2EyoV/u1bPwYfHo253IoRx8aJ+oJdtgz gx7L1WNrG5hSmkHF7XWjnVk6b42SGI2TkOcLKl0MI1okxsFIRsJp/PdmQNsyNYV2EZJGCyNnJdS 3OW5kM3GqRutePYTOADgzErFLTO43qsIDjHc0zR8Mgy8SJWDAe+Pc7QROB5qXagOER0JNN2C7BO uU3HsAPFi3Es5/rxcNjRPEMO6YJjuAbPNbthHSv8GGJDwyPt1B45ua17CLmGDMUC3Idf4NYTjzI MRvNLpP0e8dQbKNglqC+YgKNE= X-Google-Smtp-Source: AGHT+IGweO7G/7uSENn+QjmTqlnddwl29V+sT1o5JO9dLO+3x1eM5WrtlkMDznQvp7BWQT0CzFOjIQ== X-Received: by 2002:a05:620a:29d4:b0:7e3:3276:99f with SMTP id af79cd13be357-7e332760bdamr202722385a.53.1752500580777; Mon, 14 Jul 2025 06:43:00 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7dcdc0f7d1csm510687285a.39.2025.07.14.06.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 06:43:00 -0700 (PDT) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 78D0FF40066; Mon, 14 Jul 2025 09:42:59 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Mon, 14 Jul 2025 09:42:59 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdehvddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveeiudffiedv necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqh hunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddu jeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvg drnhgrmhgvpdhnsggprhgtphhtthhopedvjedpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtoheplhhoshhsihhnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqd hkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhsthdq fhhorhdqlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlkh hmmheslhhishhtshdrlhhinhhugidruggvvhdprhgtphhtthhopehlihhnuhigqdgrrhgt hhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehojhgvuggrsehkvghrnh gvlhdrohhrghdprhgtphhtthhopegrlhgvgidrghgrhihnohhrsehgmhgrihhlrdgtohhm pdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhnvghtpdhrtghpthhtohepsghjoh hrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 14 Jul 2025 09:42:58 -0400 (EDT) Date: Mon, 14 Jul 2025 06:42:57 -0700 From: Boqun Feng To: Benno Lossin Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, lkmm@lists.linux.dev, linux-arch@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Will Deacon , Peter Zijlstra , Mark Rutland , Wedson Almeida Filho , Viresh Kumar , Lyude Paul , Ingo Molnar , Mitchell Levy , "Paul E. McKenney" , Greg Kroah-Hartman , Linus Torvalds , Thomas Gleixner , Alan Stern Subject: Re: [PATCH v7 2/9] rust: sync: Add basic atomic operation mapping framework Message-ID: References: <20250714053656.66712-1-boqun.feng@gmail.com> <20250714053656.66712-3-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: lkmm@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: On Mon, Jul 14, 2025 at 12:03:11PM +0200, Benno Lossin wrote: [...] > > +declare_and_impl_atomic_methods!( > > + /// Basic atomic operations > > + pub trait AtomicHasBasicOps { > > I think we should drop the `Has` from the names. So this one can just be > `AtomicBasicOps`. Or how about `BasicAtomic`, or `AtomicBase`? > Actually, given your feedback to `ordering::Any` vs `core::any::Any`, I think it makes more sense to keep the current names ;-) These are only trait names to describe what operations do an `AtomicImpl` has, and they should be used only in atomic mod, so naming them a bit longer is not a problem. And by doing so, we free the better names `BasicAtomic` or `AtomicBase` for other future usages. Best I could do is `AtomicBasicOps` or `HasAtomicBasicOps`. > > + /// Atomic read (load). > > + /// > > + /// # Safety > > + /// - `ptr` is aligned to [`align_of::()`]. > > + /// - `ptr` is valid for reads. > > + /// > > + /// [`align_of::()`]: core::mem::align_of > > + unsafe fn read[acquire](ptr: *mut Self) -> Self { > > + bindings::#call(ptr.cast()) > > + } > > + > > + /// Atomic set (store). > > + /// > > + /// # Safety > > + /// - `ptr` is aligned to [`align_of::()`]. > > + /// - `ptr` is valid for writes. > > + /// > > + /// [`align_of::()`]: core::mem::align_of > > + unsafe fn set[release](ptr: *mut Self, v: Self) { > > + bindings::#call(ptr.cast(), v) > > + } > > + } > > +); > > + > > +declare_and_impl_atomic_methods!( > > + /// Exchange and compare-and-exchange atomic operations > > + pub trait AtomicHasXchgOps { > > Same here `AtomicXchgOps` or `AtomicExchangeOps` or `AtomicExchange`? > (I would prefer to not abbreviate it to `Xchg`) > The "Xchg" -> "Exchange" part seems fine to me. > > + /// Atomic exchange. > > + /// > > + /// Atomically updates `*ptr` to `v` and returns the old value. > > + /// > > + /// # Safety > > + /// - `ptr` is aligned to [`align_of::()`]. > > + /// - `ptr` is valid for reads and writes. > > + /// > > + /// [`align_of::()`]: core::mem::align_of > > + unsafe fn xchg[acquire, release, relaxed](ptr: *mut Self, v: Self) -> Self { > > + bindings::#call(ptr.cast(), v) > > + } > > + > > + /// Atomic compare and exchange. > > + /// > > + /// If `*ptr` == `*old`, atomically updates `*ptr` to `new`. Otherwise, `*ptr` is not > > + /// modified, `*old` is updated to the current value of `*ptr`. > > + /// > > + /// Return `true` if the update of `*ptr` occured, `false` otherwise. > > + /// > > + /// # Safety > > + /// - `ptr` is aligned to [`align_of::()`]. > > + /// - `ptr` is valid for reads and writes. > > + /// - `old` is aligned to [`align_of::()`]. > > + /// - `old` is valid for reads and writes. > > + /// > > + /// [`align_of::()`]: core::mem::align_of > > + unsafe fn try_cmpxchg[acquire, release, relaxed](ptr: *mut Self, old: *mut Self, new: Self) -> bool { > > + bindings::#call(ptr.cast(), old, new) > > + )} > > + } > > +); > > + > > +declare_and_impl_atomic_methods!( > > + /// Atomic arithmetic operations > > + pub trait AtomicHasArithmeticOps { > > Forgot to rename this one to `Add`? I think `AtomicAdd` sounds best for No, because at the `AtomicImpl` level, it's easy to know whether a type has all the arithmetic operations or none (also the `Delta` type should be known). But I don't have opinions on renaming it to `AtomicAddOps` or `HasAtomicAddOps`. Regards, Boqun > this one. > > --- > Cheers, > Benno > > > + /// Atomic add (wrapping). > > + /// > > + /// Atomically updates `*ptr` to `(*ptr).wrapping_add(v)`. > > + /// > > + /// # Safety > > + /// - `ptr` is aligned to `align_of::()`. > > + /// - `ptr` is valid for reads and writes. > > + /// > > + /// [`align_of::()`]: core::mem::align_of > > + unsafe fn add[](ptr: *mut Self, v: Self::Delta) { > > + bindings::#call(v, ptr.cast()) > > + } > > + > > + /// Atomic fetch and add (wrapping). > > + /// > > + /// Atomically updates `*ptr` to `(*ptr).wrapping_add(v)`, and returns the value of `*ptr` > > + /// before the update. > > + /// > > + /// # Safety > > + /// - `ptr` is aligned to `align_of::()`. > > + /// - `ptr` is valid for reads and writes. > > + /// > > + /// [`align_of::()`]: core::mem::align_of > > + unsafe fn fetch_add[acquire, release, relaxed](ptr: *mut Self, v: Self::Delta) -> Self { > > + bindings::#call(v, ptr.cast()) > > + } > > + } > > +); >