llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: kernel: cpu: mark `CpuId::current()` inline
@ 2025-08-11  1:19 Ritvik Gupta
  2025-08-11  1:24 ` Boqun Feng
  2025-08-11  9:56 ` Alice Ryhl
  0 siblings, 2 replies; 3+ messages in thread
From: Ritvik Gupta @ 2025-08-11  1:19 UTC (permalink / raw)
  To: Thomas Gleixner, Peter Zijlstra, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt
  Cc: skhan, linux-kernel, rust-for-linux, llvm

When building the kernel using llvm-20.1.7-rust-1.89.0-x86_64,
this symbol is generated:

$ llvm-nm --demangle vmlinux | grep CpuId
ffffffff84c77450 T <kernel::cpu::CpuId>::current

However, this Rust symbol is a trivial wrapper around
`raw_smp_processor_id` function. It doesn't make sense
to go through a trivial wrapper for such functions,
so mark it inline.

After applying this patch, the above command will produce no output.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: Ritvik Gupta <ritvikfoss@gmail.com>
---
 rust/kernel/cpu.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/cpu.rs b/rust/kernel/cpu.rs
index 5de730c8d817..cb6c0338ef5a 100644
--- a/rust/kernel/cpu.rs
+++ b/rust/kernel/cpu.rs
@@ -109,6 +109,7 @@ pub fn as_u32(&self) -> u32 {
     /// unexpectedly due to preemption or CPU migration. It should only be
     /// used when the context ensures that the task remains on the same CPU
     /// or the users could use a stale (yet valid) CPU ID.
+    #[inline]
     pub fn current() -> Self {
         // SAFETY: raw_smp_processor_id() always returns a valid CPU ID.
         unsafe { Self::from_u32_unchecked(bindings::raw_smp_processor_id()) }

base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: kernel: cpu: mark `CpuId::current()` inline
  2025-08-11  1:19 [PATCH] rust: kernel: cpu: mark `CpuId::current()` inline Ritvik Gupta
@ 2025-08-11  1:24 ` Boqun Feng
  2025-08-11  9:56 ` Alice Ryhl
  1 sibling, 0 replies; 3+ messages in thread
From: Boqun Feng @ 2025-08-11  1:24 UTC (permalink / raw)
  To: Ritvik Gupta
  Cc: Thomas Gleixner, Peter Zijlstra, Miguel Ojeda, Alex Gaynor,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, skhan,
	linux-kernel, rust-for-linux, llvm

On Mon, Aug 11, 2025 at 06:49:58AM +0530, Ritvik Gupta wrote:
> When building the kernel using llvm-20.1.7-rust-1.89.0-x86_64,
> this symbol is generated:
> 
> $ llvm-nm --demangle vmlinux | grep CpuId
> ffffffff84c77450 T <kernel::cpu::CpuId>::current
> 
> However, this Rust symbol is a trivial wrapper around
> `raw_smp_processor_id` function. It doesn't make sense
> to go through a trivial wrapper for such functions,
> so mark it inline.
> 
> After applying this patch, the above command will produce no output.
> 
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Link: https://github.com/Rust-for-Linux/linux/issues/1145
> Signed-off-by: Ritvik Gupta <ritvikfoss@gmail.com>

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun

> ---
>  rust/kernel/cpu.rs | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/rust/kernel/cpu.rs b/rust/kernel/cpu.rs
> index 5de730c8d817..cb6c0338ef5a 100644
> --- a/rust/kernel/cpu.rs
> +++ b/rust/kernel/cpu.rs
> @@ -109,6 +109,7 @@ pub fn as_u32(&self) -> u32 {
>      /// unexpectedly due to preemption or CPU migration. It should only be
>      /// used when the context ensures that the task remains on the same CPU
>      /// or the users could use a stale (yet valid) CPU ID.
> +    #[inline]
>      pub fn current() -> Self {
>          // SAFETY: raw_smp_processor_id() always returns a valid CPU ID.
>          unsafe { Self::from_u32_unchecked(bindings::raw_smp_processor_id()) }
> 
> base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
> -- 
> 2.50.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: kernel: cpu: mark `CpuId::current()` inline
  2025-08-11  1:19 [PATCH] rust: kernel: cpu: mark `CpuId::current()` inline Ritvik Gupta
  2025-08-11  1:24 ` Boqun Feng
@ 2025-08-11  9:56 ` Alice Ryhl
  1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-08-11  9:56 UTC (permalink / raw)
  To: Ritvik Gupta
  Cc: Thomas Gleixner, Peter Zijlstra, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	skhan, linux-kernel, rust-for-linux, llvm

On Mon, Aug 11, 2025 at 06:49:58AM +0530, Ritvik Gupta wrote:
> When building the kernel using llvm-20.1.7-rust-1.89.0-x86_64,
> this symbol is generated:
> 
> $ llvm-nm --demangle vmlinux | grep CpuId
> ffffffff84c77450 T <kernel::cpu::CpuId>::current
> 
> However, this Rust symbol is a trivial wrapper around
> `raw_smp_processor_id` function. It doesn't make sense
> to go through a trivial wrapper for such functions,
> so mark it inline.
> 
> After applying this patch, the above command will produce no output.
> 
> Suggested-by: Alice Ryhl <aliceryhl@google.com>
> Link: https://github.com/Rust-for-Linux/linux/issues/1145
> Signed-off-by: Ritvik Gupta <ritvikfoss@gmail.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-11  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11  1:19 [PATCH] rust: kernel: cpu: mark `CpuId::current()` inline Ritvik Gupta
2025-08-11  1:24 ` Boqun Feng
2025-08-11  9:56 ` Alice Ryhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).