rust: add a wrapper for the `num_possible_cpus` C function
Subsystems (3)
Andreas Hindborg
reviewerPATCH v4 1/1 rust: add a wrapper for the `num_possible_cpus` C function
This function returns the maximum number of CPUs that can be online.
---
The Rust null block driver needs this wrapper to put an upper bound on the number of submit and poll queues it sets up: it never needs more queues than the number of CPUs that can come online.
This patch was part of the rust: add a few helpers series up to v3. It is independent of the other two patches in that series, so it is sent on its own from v4 on.
Changes in v4:
- Move the C helper into rust/helpers/cpumask.c and the Rust wrapper into kernel::cpumask, to mirror the C side (Miguel, Yury).
- Put __rust_helper on a line of its own for greppability (Yury).
- Document that the return value counts possible CPUs and does not bound CPU IDs (Peter).
- Split this patch out of the rust: add a few helpers series, as it is independent of the remaining patches (Miguel).
- Rebase on v7.3.
- Link to v3: https://msgid.link/[email protected]
--- rust/helpers/cpumask.c | 6 ++++++ rust/kernel/cpumask.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+)
rust/helpers/cpumask.c +6 -0
@@ -81,3 +81,9 @@ void rust_helper_free_cpumask_var(cpumask_var_t mask)free_cpumask_var (mask); }#endif + +__rust_helper +unsigned int rust_helper_num_possible_cpus(void) +{ +return num_possible_cpus (); +}
rust/kernel/cpumask.rs +13 -0
@@ -16,6 +16,19 @@use core::ops::{Deref ,DerefMut }; +/// Returns the maximum number of CPUs that may be online on the system. +/// +/// This is a count of CPUs, not a bound on CPU IDs. Possible CPUs need not occupy a contiguous +/// range of IDs, so a CPU ID must be bounded by [`nr_cpu_ids()`] instead. That is, +/// `num_possible_cpus() <= nr_cpu_ids()`. +/// +/// [`nr_cpu_ids()`]: crate::cpu::nr_cpu_ids +#[inline] +pub fn num_possible_cpus () ->u32 { +// SAFETY: FFI call with no additional requirements. +unsafe { bindings::num_possible_cpus () } +} +/// A CPU Mask. /// /// Rust abstraction for the C `struct cpumask`.
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261028-num-cpus-e51694605371
Best regards,
Signature · 1 line
Andreas Hindborg <[email protected]>
Quoted 54 lines · Andreas Hindborg
This function returns the maximum number of CPUs that can be online.
Reviewed-by Alice Ryhl <[email protected]>Reviewed-by Gary Guo <[email protected]>Assisted-by LLMSigned-off-by Andreas Hindborg <[email protected]>---
The Rust null block driver needs this wrapper to put an upper bound on the number of submit and poll queues it sets up: it never needs more queues than the number of CPUs that can come online.This patch was part of the
rust: add a few helpersseries up to v3. It is independent of the other two patches in that series, so it is sent on its own from v4 on.Changes in v4:
- Move the C helper intorust/helpers/cpumask.cand the Rust wrapper intokernel::cpumask, to mirror the C side (Miguel, Yury).
- Put__rust_helperon a line of its own for greppability (Yury).
- Document that the return value counts possible CPUs and does not bound CPU IDs (Peter).
- Split this patch out of therust: add a few helpersseries, as it is independent of the remaining patches (Miguel).
- Rebase on v7.3.
- Link to v3: https://msgid.link/[email protected]--- rust/helpers/cpumask.c | 6 ++++++ rust/kernel/cpumask.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+)rust/helpers/cpumask.c +6
-0@@ -81,3 +81,9 @@ void rust_helper_free_cpumask_var(cpumask_var_t mask)free_cpumask_var (mask); }#endif + +__rust_helper +unsigned int rust_helper_num_possible_cpus(void) +{ +return num_possible_cpus (); +}rust/kernel/cpumask.rs +2
-0@@ -16,6 +16,19 @@use core::ops::{Deref ,DerefMut }; +/// Returns the maximum number of CPUs that may be online on the system. +///
rust/kernel/cpumask.rs line 30
Quoted 10 lines
rust/kernel/cpumask.rs +10
-0+/// This is a count of CPUs, not a bound on CPU IDs. Possible CPUs need not occupy a contiguous +/// range of IDs, so a CPU ID must be bounded by [`nr_cpu_ids()`] instead. That is, +/// `num_possible_cpus() <= nr_cpu_ids()`. +/// +/// [`nr_cpu_ids()`]: crate::cpu::nr_cpu_ids +#[inline] +pub fn num_possible_cpus () ->u32 { +// SAFETY: FFI call with no additional requirements. +unsafe { bindings::num_possible_cpus () } +}
Signature · 1 line
viresh