[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b675e620-6a20-496a-8d23-8e184d7bde6b@proton.me>
Date: Wed, 31 Jul 2024 18:58:28 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alice Ryhl <aliceryhl@...gle.com>, Steven Rostedt <rostedt@...dmis.org>, Masami Hiramatsu <mhiramat@...nel.org>, Mathieu Desnoyers <mathieu.desnoyers@...icios.com>, Peter Zijlstra <peterz@...radead.org>, Josh Poimboeuf <jpoimboe@...nel.org>, Jason Baron <jbaron@...mai.com>, Ard Biesheuvel <ardb@...nel.org>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...sung.com>
Cc: linux-trace-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org, Arnd Bergmann <arnd@...db.de>, linux-arch@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>, "Peter Zijlstra (Intel)" <peterz@...radaed.org>, Sean Christopherson <seanjc@...gle.com>, Uros Bizjak <ubizjak@...il.com>, Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>, Marc Zyngier <maz@...nel.org>, Oliver Upton <oliver.upton@...ux.dev>, Mark Rutland <mark.rutland@....com>, Ryan Roberts <ryan.roberts@....com>, Fuad Tabba <tabba@...gle.com>, linux-arm-kernel@...ts.infradead.org, Paul Walmsley <paul.walmsley@...ive.com>, Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>, Anup Patel <apatel@...tanamicro.com>, Andrew Jones <ajones@...tanamicro.com>, Alexandre Ghiti
<alexghiti@...osinc.com>, Conor Dooley <conor.dooley@...rochip.com>, Samuel Holland <samuel.holland@...ive.com>, linux-riscv@...ts.infradead.org, Huacai Chen <chenhuacai@...nel.org>, WANG Xuerui <kernel@...0n.name>, Bibo Mao <maobibo@...ngson.cn>, Tiezhu Yang <yangtiezhu@...ngson.cn>, Andrew Morton <akpm@...ux-foundation.org>, Tianrui Zhao <zhaotianrui@...ngson.cn>, loongarch@...ts.linux.dev
Subject: Re: [PATCH v4 2/2] rust: add tracepoint support
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
>
Powered by blists - more mailing lists