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>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/helpers/helpers.c | 1 +
rust/helpers/processor.c | 8 ++++++++
rust/kernel/lib.rs | 1 +
rust/kernel/processor.rs | 14 ++++++++++++++
4 files changed, 24 insertions(+)
create mode 100644 rust/helpers/processor.c
create mode 100644 rust/kernel/processor.rs
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 7cf7fe95e41d..04598665e7c8 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -34,6 +34,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
index 000000000000..d41355e14d6e
--- /dev/null
+++ b/rust/helpers/processor.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/processor.h>
+
+void rust_helper_cpu_relax(void)
+{
+ cpu_relax();
+}
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index ed53169e795c..c098c47c1817 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -110,6 +110,7 @@
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
index 000000000000..85b49b3614dd
--- /dev/null
+++ b/rust/kernel/processor.rs
@@ -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() }
+}
--
2.43.0
PaX/Grsecurity did everything you are attempting to do, 20 years ago, and applied to all running programs on the system, and the kernel. Ofcourse it went proprietary and you cowards didn't even sue. (And yes you could have, and could still do it) Pieces of fucking shit. On Sun, Aug 17, 2025 at 12:49 AM FUJITA Tomonori <fujita.tomonori@gmail.com> wrote: > > 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> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> > --- > rust/helpers/helpers.c | 1 + > rust/helpers/processor.c | 8 ++++++++ > rust/kernel/lib.rs | 1 + > rust/kernel/processor.rs | 14 ++++++++++++++ > 4 files changed, 24 insertions(+) > create mode 100644 rust/helpers/processor.c > create mode 100644 rust/kernel/processor.rs > > diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c > index 7cf7fe95e41d..04598665e7c8 100644 > --- a/rust/helpers/helpers.c > +++ b/rust/helpers/helpers.c > @@ -34,6 +34,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 > index 000000000000..d41355e14d6e > --- /dev/null > +++ b/rust/helpers/processor.c > @@ -0,0 +1,8 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include <linux/processor.h> > + > +void rust_helper_cpu_relax(void) > +{ > + cpu_relax(); > +} > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index ed53169e795c..c098c47c1817 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -110,6 +110,7 @@ > 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 > index 000000000000..85b49b3614dd > --- /dev/null > +++ b/rust/kernel/processor.rs > @@ -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() } > +} > -- > 2.43.0 > >
Thanks for taking over our C project and running all the C hackers out, and making it uncompilable on old systems. Thanks. Really great thing this opensource, these days. "this is a RUST project now" On Sun, Aug 17, 2025 at 12:49 AM FUJITA Tomonori <fujita.tomonori@gmail.com> wrote: > > 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> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> > --- > rust/helpers/helpers.c | 1 + > rust/helpers/processor.c | 8 ++++++++ > rust/kernel/lib.rs | 1 + > rust/kernel/processor.rs | 14 ++++++++++++++ > 4 files changed, 24 insertions(+) > create mode 100644 rust/helpers/processor.c > create mode 100644 rust/kernel/processor.rs > > diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c > index 7cf7fe95e41d..04598665e7c8 100644 > --- a/rust/helpers/helpers.c > +++ b/rust/helpers/helpers.c > @@ -34,6 +34,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 > index 000000000000..d41355e14d6e > --- /dev/null > +++ b/rust/helpers/processor.c > @@ -0,0 +1,8 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include <linux/processor.h> > + > +void rust_helper_cpu_relax(void) > +{ > + cpu_relax(); > +} > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index ed53169e795c..c098c47c1817 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -110,6 +110,7 @@ > 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 > index 000000000000..85b49b3614dd > --- /dev/null > +++ b/rust/kernel/processor.rs > @@ -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() } > +} > -- > 2.43.0 > >
Imagine a Japanese typewriter. Couldn't be done. On Sun, Aug 17, 2025 at 12:49 AM FUJITA Tomonori <fujita.tomonori@gmail.com> wrote: > > 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> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> > --- > rust/helpers/helpers.c | 1 + > rust/helpers/processor.c | 8 ++++++++ > rust/kernel/lib.rs | 1 + > rust/kernel/processor.rs | 14 ++++++++++++++ > 4 files changed, 24 insertions(+) > create mode 100644 rust/helpers/processor.c > create mode 100644 rust/kernel/processor.rs > > diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c > index 7cf7fe95e41d..04598665e7c8 100644 > --- a/rust/helpers/helpers.c > +++ b/rust/helpers/helpers.c > @@ -34,6 +34,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 > index 000000000000..d41355e14d6e > --- /dev/null > +++ b/rust/helpers/processor.c > @@ -0,0 +1,8 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include <linux/processor.h> > + > +void rust_helper_cpu_relax(void) > +{ > + cpu_relax(); > +} > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index ed53169e795c..c098c47c1817 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -110,6 +110,7 @@ > 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 > index 000000000000..85b49b3614dd > --- /dev/null > +++ b/rust/kernel/processor.rs > @@ -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() } > +} > -- > 2.43.0 > >
> On 17 Aug 2025, at 01:47, FUJITA Tomonori <fujita.tomonori@gmail.com> wrote: > > 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> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> > --- > rust/helpers/helpers.c | 1 + > rust/helpers/processor.c | 8 ++++++++ > rust/kernel/lib.rs | 1 + > rust/kernel/processor.rs | 14 ++++++++++++++ > 4 files changed, 24 insertions(+) > create mode 100644 rust/helpers/processor.c > create mode 100644 rust/kernel/processor.rs > > diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c > index 7cf7fe95e41d..04598665e7c8 100644 > --- a/rust/helpers/helpers.c > +++ b/rust/helpers/helpers.c > @@ -34,6 +34,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 > index 000000000000..d41355e14d6e > --- /dev/null > +++ b/rust/helpers/processor.c > @@ -0,0 +1,8 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include <linux/processor.h> > + > +void rust_helper_cpu_relax(void) > +{ > + cpu_relax(); > +} > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index ed53169e795c..c098c47c1817 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -110,6 +110,7 @@ > 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 > index 000000000000..85b49b3614dd > --- /dev/null > +++ b/rust/kernel/processor.rs > @@ -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() } > +} > -- > 2.43.0 > > Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Futa Daniel? Comon. On Tue, Aug 19, 2025 at 2:35 PM Daniel Almeida <daniel.almeida@collabora.com> wrote: > > > > > On 17 Aug 2025, at 01:47, FUJITA Tomonori <fujita.tomonori@gmail.com> wrote: > > > > 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> > > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> > > --- > > rust/helpers/helpers.c | 1 + > > rust/helpers/processor.c | 8 ++++++++ > > rust/kernel/lib.rs | 1 + > > rust/kernel/processor.rs | 14 ++++++++++++++ > > 4 files changed, 24 insertions(+) > > create mode 100644 rust/helpers/processor.c > > create mode 100644 rust/kernel/processor.rs > > > > diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c > > index 7cf7fe95e41d..04598665e7c8 100644 > > --- a/rust/helpers/helpers.c > > +++ b/rust/helpers/helpers.c > > @@ -34,6 +34,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 > > index 000000000000..d41355e14d6e > > --- /dev/null > > +++ b/rust/helpers/processor.c > > @@ -0,0 +1,8 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +#include <linux/processor.h> > > + > > +void rust_helper_cpu_relax(void) > > +{ > > + cpu_relax(); > > +} > > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > > index ed53169e795c..c098c47c1817 100644 > > --- a/rust/kernel/lib.rs > > +++ b/rust/kernel/lib.rs > > @@ -110,6 +110,7 @@ > > 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 > > index 000000000000..85b49b3614dd > > --- /dev/null > > +++ b/rust/kernel/processor.rs > > @@ -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() } > > +} > > -- > > 2.43.0 > > > > > > Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
© 2016 - 2025 Red Hat, Inc.