rust: Add cpu_relax() helper

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>
This commit is contained in:
FUJITA Tomonori 2025-08-21 09:20:54 +09:00 committed by Danilo Krummrich
parent 44d454fcff
commit 842aedc390
4 changed files with 24 additions and 0 deletions

View 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"

8
rust/helpers/processor.c Normal file
View file

@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/processor.h>
void rust_helper_cpu_relax(void)
{
cpu_relax();
}

View 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;

14
rust/kernel/processor.rs Normal file
View file

@ -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() }
}