]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: Add cpu_relax() helper
authorFUJITA Tomonori <fujita.tomonori@gmail.com>
Thu, 21 Aug 2025 00:20:54 +0000 (09:20 +0900)
committerDanilo Krummrich <dakr@kernel.org>
Thu, 21 Aug 2025 14:58:07 +0000 (16:58 +0200)
Add cpu_relax() helper in preparation for supporting
read_poll_timeout().

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Link: https://lore.kernel.org/r/20250821002055.3654160-2-fujita.tomonori@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/helpers/helpers.c
rust/helpers/processor.c [new file with mode: 0644]
rust/kernel/lib.rs
rust/kernel/processor.rs [new file with mode: 0644]

index 44b2005d50140d34a44ae37d01c2ddbae6aeaa32..a90a87cff38c7051968bbd6866e4037b25968a26 100644 (file)
@@ -35,6 +35,7 @@
 #include "pid_namespace.c"
 #include "platform.c"
 #include "poll.c"
+#include "processor.c"
 #include "property.c"
 #include "rbtree.c"
 #include "rcu.c"
diff --git a/rust/helpers/processor.c b/rust/helpers/processor.c
new file mode 100644 (file)
index 0000000..d41355e
--- /dev/null
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/processor.h>
+
+void rust_helper_cpu_relax(void)
+{
+       cpu_relax();
+}
index f8db761c5c95fc66e4c55f539b17fca613161ada..953a6cba501cbeae6359e866cf35ac7a5468949f 100644 (file)
@@ -111,6 +111,7 @@ pub mod pid_namespace;
 pub mod platform;
 pub mod prelude;
 pub mod print;
+pub mod processor;
 pub mod rbtree;
 pub mod regulator;
 pub mod revocable;
diff --git a/rust/kernel/processor.rs b/rust/kernel/processor.rs
new file mode 100644 (file)
index 0000000..85b49b3
--- /dev/null
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Processor related primitives.
+//!
+//! C header: [`include/linux/processor.h`](srctree/include/linux/processor.h)
+
+/// Lower CPU power consumption or yield to a hyperthreaded twin processor.
+///
+/// It also happens to serve as a compiler barrier.
+#[inline]
+pub fn cpu_relax() {
+    // SAFETY: Always safe to call.
+    unsafe { bindings::cpu_relax() }
+}