* [PATCH 0/2] rust: add a few helpers
@ 2026-02-15 20:10 Andreas Hindborg
2026-02-15 20:10 ` [PATCH 1/2] rust: add a wrapper for the `num_possible_cpus` C function Andreas Hindborg
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Andreas Hindborg @ 2026-02-15 20:10 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: linux-kernel, rust-for-linux, Andreas Hindborg
This series adds two helpers for obtaining information about the number
of numa domans and cpu count of the system.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
Andreas Hindborg (2):
rust: add a wrapper for the `num_possible_cpus` C function
rust: add a wrapper for the `nr_online_nodes` C function
rust/helpers/helpers.c | 1 +
rust/helpers/num_cpus.c | 8 ++++++++
rust/kernel/lib.rs | 17 +++++++++++++++++
3 files changed, 26 insertions(+)
---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20260215-cpu-helpers-08efb2572487
Best regards,
--
Andreas Hindborg <a.hindborg@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] rust: add a wrapper for the `num_possible_cpus` C function
2026-02-15 20:10 [PATCH 0/2] rust: add a few helpers Andreas Hindborg
@ 2026-02-15 20:10 ` Andreas Hindborg
2026-02-16 8:23 ` Dirk Behme
2026-02-15 20:10 ` [PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Andreas Hindborg @ 2026-02-15 20:10 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: linux-kernel, rust-for-linux, Andreas Hindborg
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` C function
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-15 20:10 ` Andreas Hindborg
2026-02-15 20:14 ` [PATCH 0/2] rust: add a few helpers Miguel Ojeda
2026-02-16 8:39 ` Alice Ryhl
3 siblings, 0 replies; 7+ messages in thread
From: Andreas Hindborg @ 2026-02-15 20:10 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: linux-kernel, rust-for-linux, Andreas Hindborg
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] rust: add a few helpers
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-15 20:10 ` [PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` " Andreas Hindborg
@ 2026-02-15 20:14 ` Miguel Ojeda
2026-02-15 21:06 ` Andreas Hindborg
2026-02-16 8:39 ` Alice Ryhl
3 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2026-02-15 20:14 UTC (permalink / raw)
To: Andreas Hindborg
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
linux-kernel, rust-for-linux
On Sun, Feb 15, 2026 at 9:10 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
> rust/kernel/lib.rs | 17 +++++++++++++++++
Please avoid adding things to the root of the crate.
Also, for both patches, please mention for what it will be used for.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] rust: add a few helpers
2026-02-15 20:14 ` [PATCH 0/2] rust: add a few helpers Miguel Ojeda
@ 2026-02-15 21:06 ` Andreas Hindborg
0 siblings, 0 replies; 7+ messages in thread
From: Andreas Hindborg @ 2026-02-15 21:06 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
linux-kernel, rust-for-linux
"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com> writes:
> On Sun, Feb 15, 2026 at 9:10 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>
>> rust/kernel/lib.rs | 17 +++++++++++++++++
>
> Please avoid adding things to the root of the crate.
Ok, I'll move them.
>
> Also, for both patches, please mention for what it will be used for.
The are for rust null block. I have sent a few today already without
this mention. I can send a follow up email for each with the details.
Best regards,
Andreas Hindborg
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] rust: add a wrapper for the `num_possible_cpus` C function
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
0 siblings, 0 replies; 7+ messages in thread
From: Dirk Behme @ 2026-02-16 8:23 UTC (permalink / raw)
To: Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
Danilo Krummrich
Cc: linux-kernel, rust-for-linux
On 15.02.2026 21:10, Andreas Hindborg wrote:
> 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)
Should we add `__rust_helper` here?
Thanks
Dirk
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] rust: add a few helpers
2026-02-15 20:10 [PATCH 0/2] rust: add a few helpers Andreas Hindborg
` (2 preceding siblings ...)
2026-02-15 20:14 ` [PATCH 0/2] rust: add a few helpers Miguel Ojeda
@ 2026-02-16 8:39 ` Alice Ryhl
3 siblings, 0 replies; 7+ messages in thread
From: Alice Ryhl @ 2026-02-16 8:39 UTC (permalink / raw)
To: Andreas Hindborg
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Trevor Gross, Danilo Krummrich, linux-kernel,
rust-for-linux
On Sun, Feb 15, 2026 at 09:10:14PM +0100, Andreas Hindborg wrote:
> This series adds two helpers for obtaining information about the number
> of numa domans and cpu count of the system.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
I'd make both #[inline].
Alice
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-16 8:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox