On 28.06.24 15:23, Alice Ryhl wrote: > diff --git a/rust/kernel/tracepoint.rs b/rust/kernel/tracepoint.rs > new file mode 100644 > index 000000000000..1005f09e0330 > --- /dev/null > +++ b/rust/kernel/tracepoint.rs > @@ -0,0 +1,47 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +// Copyright (C) 2024 Google LLC. > + > +//! Logic for tracepoints. > + > +/// Declare the Rust entry point for a tracepoint. > +#[macro_export] > +macro_rules! declare_trace { > + ($($(#[$attr:meta])* $pub:vis fn $name:ident($($argname:ident : $argtyp:ty),* $(,)?);)*) => {$( > + $( #[$attr] )* > + #[inline(always)] > + $pub unsafe fn $name($($argname : $argtyp),*) { > + #[cfg(CONFIG_TRACEPOINTS)] > + { > + use $crate::bindings::*; Why is this needed, can't you put this into the invocation of `paste!`? ie `[< $crate::bindings::__tracepoint_ $name >]`? > + > + // SAFETY: It's always okay to query the static key for a tracepoint. > + let should_trace = unsafe { > + $crate::macros::paste! { > + $crate::static_key::static_key_false!( > + [< __tracepoint_ $name >], > + $crate::bindings::tracepoint, > + key > + ) > + } > + }; > + > + if should_trace { > + $crate::macros::paste! { > + // SAFETY: The caller guarantees that it is okay to call this tracepoint. Can you add this on the docs of `$name`? ie add a Safety section. The docs should still appear when creating them/when LSPs show them to you. --- Cheers, Benno > + unsafe { [< rust_do_trace_ $name >]($($argname),*) }; > + } > + } > + } > + > + #[cfg(not(CONFIG_TRACEPOINTS))] > + { > + // If tracepoints are disabled, insert a trivial use of each argument > + // to avoid unused argument warnings. > + $( let _unused = $argname; )* > + } > + } > + )*} > +} > + > +pub use declare_trace; > > -- > 2.45.2.803.g4e1b14247a-goog >