mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 21:02:43 +01:00
Make it possible to have Rust code call into tracepoints defined by C code. It is still required that the tracepoint is declared in a C header, and that this header is included in the input to bindgen. Instead of calling __DO_TRACE directly, the exported rust_do_trace_ function calls an inline helper function. This is because the `cond` argument does not exist at the callsite of DEFINE_RUST_DO_TRACE. __DECLARE_TRACE always emits an inline static and an extern declaration that is only used when CREATE_RUST_TRACE_POINTS is set. These should not end up in the final binary so it is not a problem that they sometimes are emitted without a user. Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Jason Baron <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Alex Gaynor <[email protected]> Cc: Wedson Almeida Filho <[email protected]> Cc: " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " <[email protected]> Cc: Benno Lossin <[email protected]> Cc: Andreas Hindborg <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Uros Bizjak <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Fuad Tabba <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Albert Ou <[email protected]> Cc: Anup Patel <[email protected]> Cc: Andrew Jones <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Conor Dooley <[email protected]> Cc: Samuel Holland <[email protected]> Cc: Huacai Chen <[email protected]> Cc: WANG Xuerui <[email protected]> Cc: Bibo Mao <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Tianrui Zhao <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Carlos Llamas <[email protected]> Reviewed-by: Gary Guo <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
50 lines
1.8 KiB
Rust
50 lines
1.8 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Copyright (C) 2024 Google LLC.
|
|
|
|
//! Logic for tracepoints.
|
|
|
|
/// Declare the Rust entry point for a tracepoint.
|
|
///
|
|
/// This macro generates an unsafe function that calls into C, and its safety requirements will be
|
|
/// whatever the relevant C code requires. To document these safety requirements, you may add
|
|
/// doc-comments when invoking the macro.
|
|
#[macro_export]
|
|
macro_rules! declare_trace {
|
|
($($(#[$attr:meta])* $pub:vis unsafe fn $name:ident($($argname:ident : $argtyp:ty),* $(,)?);)*) => {$(
|
|
$( #[$attr] )*
|
|
#[inline(always)]
|
|
$pub unsafe fn $name($($argname : $argtyp),*) {
|
|
#[cfg(CONFIG_TRACEPOINTS)]
|
|
{
|
|
// SAFETY: It's always okay to query the static key for a tracepoint.
|
|
let should_trace = unsafe {
|
|
$crate::macros::paste! {
|
|
$crate::jump_label::static_branch_unlikely!(
|
|
$crate::bindings::[< __tracepoint_ $name >],
|
|
$crate::bindings::tracepoint,
|
|
key
|
|
)
|
|
}
|
|
};
|
|
|
|
if should_trace {
|
|
$crate::macros::paste! {
|
|
// SAFETY: The caller guarantees that it is okay to call this tracepoint.
|
|
unsafe { $crate::bindings::[< 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;
|