[PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` C function

Andreas Hindborg posted 2 patches 1 month, 2 weeks ago
[PATCH 2/2] rust: add a wrapper for the `nr_online_nodes` C function
Posted by Andreas Hindborg 1 month, 2 weeks ago
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