mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: "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>,
	"Andreas Hindborg" <a.hindborg@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>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: [PATCH v3 1/3] rust: add a wrapper for the `num_possible_cpus` C function
Date: Tue, 29 Sep 2026 19:56:48 +0200	[thread overview]
Message-ID: <20260929-cpu-helpers-v3-1-e968ce5ee613@kernel.org> (raw)
In-Reply-To: <20260929-cpu-helpers-v3-0-e968ce5ee613@kernel.org>

This function returns the maximum number of CPUs that can be online.

The wrapper is needed by the Rust null block driver.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 rust/helpers/helpers.c  | 1 +
 rust/helpers/num_cpus.c | 8 ++++++++
 rust/kernel/cpu.rs      | 7 +++++++
 3 files changed, 16 insertions(+)

diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 440fb7638e3c..89e38b08fd17 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -76,6 +76,7 @@
 #include "mm.c"
 #include "mutex.c"
 #include "net/genetlink.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 000000000000..54e8bacb46c3
--- /dev/null
+++ b/rust/helpers/num_cpus.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/cpumask.h>
+
+__rust_helper unsigned int rust_helper_num_possible_cpus(void)
+{
+	return num_possible_cpus();
+}
diff --git a/rust/kernel/cpu.rs b/rust/kernel/cpu.rs
index cb6c0338ef5a..b38b6914b12e 100644
--- a/rust/kernel/cpu.rs
+++ b/rust/kernel/cpu.rs
@@ -6,6 +6,13 @@
 
 use crate::{bindings, device::Device, error::Result, prelude::ENODEV};
 
+/// Returns the maximum number of CPUs that may be online on the system.
+#[inline]
+pub fn num_possible_cpus() -> u32 {
+    // SAFETY: FFI call with no additional requirements.
+    unsafe { bindings::num_possible_cpus() }
+}
+
 /// Returns the maximum number of possible CPUs in the current system configuration.
 #[inline]
 pub fn nr_cpu_ids() -> u32 {

-- 
2.54.0



  reply	other threads:[~2026-09-29 17:58 UTC|newest]

Thread overview: 8+ 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 ` Andreas Hindborg [this message]
2026-09-29 18:30   ` [PATCH v3 1/3] rust: add a wrapper for the `num_possible_cpus` C function 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-29 17:56 ` [PATCH v3 2/3] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
2026-09-29 17:56 ` [PATCH v3 3/3] rust: alloc: move `NumaNode` to the `numa` module Andreas Hindborg

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=20260929-cpu-helpers-v3-1-e968ce5ee613@kernel.org \
    --to=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

all inboxes | Powered by JetHome®