1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2024 Google LLC.
5 //! Logic for tracepoints.
7 /// Declare the Rust entry point for a tracepoint.
9 /// This macro generates an unsafe function that calls into C, and its safety requirements will be
10 /// whatever the relevant C code requires. To document these safety requirements, you may add
11 /// doc-comments when invoking the macro.
13 macro_rules! declare_trace {
14 ($($(#[$attr:meta])* $pub:vis unsafe fn $name:ident($($argname:ident : $argtyp:ty),* $(,)?);)*) => {$(
17 $pub unsafe fn $name($($argname : $argtyp),*) {
18 #[cfg(CONFIG_TRACEPOINTS)]
20 // SAFETY: It's always okay to query the static key for a tracepoint.
21 let should_trace = unsafe {
22 $crate::macros::paste! {
23 $crate::jump_label::static_branch_unlikely!(
24 $crate::bindings::[< __tracepoint_ $name >],
25 $crate::bindings::tracepoint,
32 $crate::macros::paste! {
33 // SAFETY: The caller guarantees that it is okay to call this tracepoint.
34 unsafe { $crate::bindings::[< rust_do_trace_ $name >]($($argname),*) };
39 #[cfg(not(CONFIG_TRACEPOINTS))]
41 // If tracepoints are disabled, insert a trivial use of each argument
42 // to avoid unused argument warnings.
43 $( let _unused = $argname; )*
49 pub use declare_trace;