[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87ms4o3ane.fsf@t14s.mail-host-address-is-not-set>
Date: Fri, 14 Nov 2025 16:18:45 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: Mitchell Levy <levymitchell0@...il.com>, Miguel Ojeda
<ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng
<boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn
Roy Baron
<bjorn3_gh@...tonmail.com>, Alice Ryhl <aliceryhl@...gle.com>, Trevor
Gross <tmgross@...ch.edu>, Andrew Morton <akpm@...ux-foundation.org>,
Dennis Zhou <dennis@...nel.org>, Tejun Heo <tj@...nel.org>, Christoph
Lameter <cl@...ux.com>, Danilo Krummrich <dakr@...nel.org>, Benno Lossin
<lossin@...nel.org>, Yury Norov <yury.norov@...il.com>, Viresh Kumar
<viresh.kumar@...aro.org>
Cc: Tyler Hicks <code@...icks.com>, Allen Pais <apais@...ux.microsoft.com>,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-mm@...ck.org, Mitchell Levy <levymitchell0@...il.com>
Subject: Re: [PATCH v4 7/9] rust: percpu: Support non-zeroable types for
DynamicPerCpu
"Mitchell Levy" <levymitchell0@...il.com> writes:
> Add functionality to `PerCpuPtr` to compute pointers to per-CPU variable
> slots on other CPUs. Use this facility to initialize per-CPU variables
> on all possible CPUs when a dynamic per-CPU variable is created with a
> non-zeroable type. Since `RefCell` and other `Cell`-like types fall into
> this category, `impl CheckedPerCpu` on `DynamicPerCpu` for these
> `InteriorMutable` types since they can now be used. Add examples of
> these usages to `samples/rust/rust_percpu.rs`. Add a test to ensure
> dynamic per-CPU variables properly drop their contents, done here since
> non-trivially dropped types often aren't `Zeroable`.
>
> Signed-off-by: Mitchell Levy <levymitchell0@...il.com>
> ---
> rust/kernel/percpu/dynamic.rs | 44 +++++++++++++++++
> samples/rust/rust_percpu.rs | 109 +++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 146 insertions(+), 7 deletions(-)
>
> diff --git a/rust/kernel/percpu/dynamic.rs b/rust/kernel/percpu/dynamic.rs
> index 1863f31a2817..a74c8841aeb2 100644
> --- a/rust/kernel/percpu/dynamic.rs
> +++ b/rust/kernel/percpu/dynamic.rs
> @@ -89,6 +89,36 @@ pub fn new_zero(flags: Flags) -> Option<Self> {
> }
> }
>
> +impl<T: Clone> DynamicPerCpu<T> {
> + /// Allocates a new per-CPU variable
> + ///
> + /// # Arguments
> + /// * `val` - The initial value of the per-CPU variable on all CPUs.
> + /// * `flags` - Flags used to allocate an [`Arc`] that keeps track of the underlying
> + /// [`PerCpuAllocation`].
> + pub fn new_with(val: &T, flags: Flags) -> Option<Self> {
It would be great to be able to pass a closure here that can be used to
populate the value. Then the value does not have to be `Clone`.
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists