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 1/2] rust: add a wrapper for the `num_possible_cpus` C function
Date: Sun, 15 Feb 2026 21:10:15 +0100 [thread overview]
Message-ID: <20260215-cpu-helpers-v1-1-fab13d817a5e@kernel.org> (raw)
In-Reply-To: <20260215-cpu-helpers-v1-0-fab13d817a5e@kernel.org>
This function returns the max number of CPUs that can be online.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
rust/helpers/helpers.c | 1 +
rust/helpers/num_cpus.c | 8 ++++++++
rust/kernel/lib.rs | 6 ++++++
3 files changed, 15 insertions(+)
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 79c72762ad9c4..a19d6562fcb3a 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -35,6 +35,7 @@
#include "maple_tree.c"
#include "mm.c"
#include "mutex.c"
+#include "num_cpus.c"
#include "of.c"
#include "page.c"
#include "pci.c"
diff --git a/rust/helpers/num_cpus.c b/rust/helpers/num_cpus.c
new file mode 100644
index 0000000000000..daddacb0418d8
--- /dev/null
+++ b/rust/helpers/num_cpus.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/cpumask.h>
+
+unsigned int rust_helper_num_possible_cpus(void)
+{
+ return num_possible_cpus();
+}
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index f812cf1200428..7040e105dd3b9 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -366,3 +366,9 @@ pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::f
c"<Location::file_as_c_str() not supported>"
}
}
+
+/// Returns maximum number of CPUs that may be online on the system.
+pub fn num_possible_cpus() -> u32 {
+ // SAFETY: FFI call with no additional requirements.
+ unsafe { bindings::num_possible_cpus() }
+}
--
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 ` Andreas Hindborg [this message]
2026-02-16 8:23 ` [PATCH 1/2] rust: add a wrapper for the `num_possible_cpus` C function Dirk Behme
2026-02-15 20:10 ` [PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
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-1-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
all inboxes | Powered by JetHome®