From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"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>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Andreas Hindborg <a.hindborg@kernel.org>
Subject: [PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` C function
Date: Sun, 15 Feb 2026 21:10:16 +0100 [thread overview]
Message-ID: <20260215-cpu-helpers-v1-2-fab13d817a5e@kernel.org> (raw)
In-Reply-To: <20260215-cpu-helpers-v1-0-fab13d817a5e@kernel.org>
This function returns the number of online numa nodes.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
rust/kernel/lib.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 7040e105dd3b9..4e9f97f03adf2 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -372,3 +372,14 @@ pub fn num_possible_cpus() -> u32 {
// SAFETY: FFI call with no additional requirements.
unsafe { bindings::num_possible_cpus() }
}
+
+/// Returns the number of online numa nodes.
+pub fn num_online_nodes() -> u32 {
+ // NOTE: In some configurations, we can read this variable without an unsafe block.
+ // SAFETY: When numa is enabled, this is a global mutable static. We do as C and just read it,
+ // even though it might race.
+ #[allow(unused_unsafe)]
+ unsafe {
+ bindings::nr_online_nodes
+ }
+}
--
2.51.2
next prev parent reply other threads:[~2026-02-15 20:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-15 20:10 [PATCH 0/2] rust: add a few helpers Andreas Hindborg
2026-02-15 20:10 ` [PATCH 1/2] rust: add a wrapper for the `num_possible_cpus` C function Andreas Hindborg
2026-02-16 8:23 ` Dirk Behme
2026-02-15 20:10 ` Andreas Hindborg [this message]
2026-02-15 20:14 ` [PATCH 0/2] rust: add a few helpers Miguel Ojeda
2026-02-15 21:06 ` Andreas Hindborg
2026-02-16 8:39 ` Alice Ryhl
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=20260215-cpu-helpers-v1-2-fab13d817a5e@kernel.org \
--to=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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