Rust for Linux List
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3 2/3] rust: add a wrapper for the `nr_online_nodes` C function
Date: Mon, 12 Oct 2026 12:12:21 -0400	[thread overview]
Message-ID: <as0G5Sgm-mREu3RO@yury> (raw)
In-Reply-To: <20260929-cpu-helpers-v3-2-e968ce5ee613@kernel.org>

On Tue, Sep 29, 2026 at 07:56:49PM +0200, Andreas Hindborg wrote:
> This function returns the number of online NUMA nodes.
> 
> The wrapper is needed by the Rust null block driver.
> 
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>

Reviewed-by: Yury Norov <ynorov@nvidia.com>

> ---
>  rust/kernel/lib.rs  |  1 +
>  rust/kernel/numa.rs | 29 +++++++++++++++++++++++++++++
>  2 files changed, 30 insertions(+)
> 
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index 4d5c96ddc49c..a7b1c9cf454f 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -105,6 +105,7 @@
>  #[cfg(CONFIG_NET)]
>  pub mod net;
>  pub mod num;
> +pub mod numa;
>  pub mod of;
>  #[cfg(CONFIG_PM_OPP)]
>  pub mod opp;
> diff --git a/rust/kernel/numa.rs b/rust/kernel/numa.rs
> new file mode 100644
> index 000000000000..164e622d325f
> --- /dev/null
> +++ b/rust/kernel/numa.rs
> @@ -0,0 +1,29 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! NUMA topology utilities.
> +//!
> +//! C header: [`include/linux/nodemask.h`](srctree/include/linux/nodemask.h)
> +
> +use crate::bindings;
> +#[cfg(CONFIG_NUMA)]
> +use crate::sync::atomic::{
> +    Atomic,
> +    Relaxed, //
> +};
> +
> +/// Returns the number of online NUMA nodes.
> +#[inline]
> +pub fn num_online_nodes() -> u32 {
> +    #[cfg(CONFIG_NUMA)]
> +    {
> +        // SAFETY: `nr_online_nodes` is a global variable that is valid for the lifetime of the
> +        // kernel. The C side updates it with plain writes during node hotplug and reads it with
> +        // plain reads. A relaxed load is the Rust equivalent of `READ_ONCE()`, which is the best
> +        // we can do on the reader side.
> +        unsafe { Atomic::from_ptr(&raw mut bindings::nr_online_nodes) }.load(Relaxed)
> +    }
> +    #[cfg(not(CONFIG_NUMA))]
> +    {
> +        bindings::nr_online_nodes
> +    }
> +}
> 
> -- 
> 2.54.0
> 
> 

  parent reply	other threads:[~2026-10-12 16:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 17:56 [PATCH v3 0/3] rust: add a few helpers Andreas Hindborg
2026-09-29 17:56 ` [PATCH v3 1/3] rust: add a wrapper for the `num_possible_cpus` C function Andreas Hindborg
2026-09-29 18:30   ` Miguel Ojeda
2026-09-30  7:46     ` Andreas Hindborg
2026-09-30 10:25       ` Miguel Ojeda
2026-09-30 11:34         ` Andreas Hindborg
2026-09-30 11:38           ` Miguel Ojeda
2026-10-01 20:15             ` Miguel Ojeda
2026-10-02  8:33               ` Andreas Hindborg
2026-10-02  9:07                 ` Miguel Ojeda
2026-10-12 15:34                   ` Yury Norov
2026-10-13  7:24                     ` Andreas Hindborg
2026-10-02  9:24   ` Peter Zijlstra
2026-10-03 12:03     ` Andreas Hindborg
2026-10-12 15:37       ` Peter Zijlstra
2026-09-29 17:56 ` [PATCH v3 2/3] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
2026-09-30 15:14   ` Gary Guo
2026-10-12 15:04   ` Miguel Ojeda
2026-10-12 15:20     ` Yury Norov
2026-10-12 16:12   ` Yury Norov [this message]
2026-09-29 17:56 ` [PATCH v3 3/3] rust: alloc: move `NumaNode` to the `numa` module Andreas Hindborg
2026-09-30 15:12   ` Gary Guo
2026-10-12 15:50   ` Yury Norov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=as0G5Sgm-mREu3RO@yury \
    --to=ynorov@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox