Skip to content

Commit 91d3902

Browse files
Darksonnrostedt
authored andcommitted
rust: samples: add tracepoint to Rust sample
This updates the Rust printing sample to invoke a tracepoint. This ensures that we have a user in-tree from the get-go even though the patch is being merged before its real user. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Jason Baron <jbaron@akamai.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Wedson Almeida Filho <wedsonaf@gmail.com> Cc: Gary Guo <gary@garyguo.net> Cc: " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " <bjorn3_gh@protonmail.com> Cc: Benno Lossin <benno.lossin@proton.me> Cc: Andreas Hindborg <a.hindborg@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Uros Bizjak <ubizjak@gmail.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Marc Zyngier <maz@kernel.org> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Fuad Tabba <tabba@google.com> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Anup Patel <apatel@ventanamicro.com> Cc: Andrew Jones <ajones@ventanamicro.com> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Conor Dooley <conor.dooley@microchip.com> Cc: Samuel Holland <samuel.holland@sifive.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: WANG Xuerui <kernel@xen0n.name> Cc: Bibo Mao <maobibo@loongson.cn> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Tianrui Zhao <zhaotianrui@loongson.cn> Link: https://lore.kernel.org/20241030-tracepoint-v12-3-eec7f0f8ad22@google.com Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ad37bcd commit 91d3902

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20223,6 +20223,7 @@ C: zulip://rust-for-linux.zulipchat.com
2022320223
P: https://rust-for-linux.com/contributing
2022420224
T: git https://github.com/Rust-for-Linux/linux.git rust-next
2022520225
F: Documentation/rust/
20226+
F: include/trace/events/rust_sample.h
2022620227
F: rust/
2022720228
F: samples/rust/
2022820229
F: scripts/*rust*

include/trace/events/rust_sample.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Tracepoints for `samples/rust/rust_print.rs`.
4+
*
5+
* Copyright (C) 2024 Google, Inc.
6+
*/
7+
8+
#undef TRACE_SYSTEM
9+
#define TRACE_SYSTEM rust_sample
10+
11+
#if !defined(_RUST_SAMPLE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
12+
#define _RUST_SAMPLE_TRACE_H
13+
14+
#include <linux/tracepoint.h>
15+
16+
TRACE_EVENT(rust_sample_loaded,
17+
TP_PROTO(int magic_number),
18+
TP_ARGS(magic_number),
19+
TP_STRUCT__entry(
20+
__field(int, magic_number)
21+
),
22+
TP_fast_assign(
23+
__entry->magic_number = magic_number;
24+
),
25+
TP_printk("magic=%d", __entry->magic_number)
26+
);
27+
28+
#endif /* _RUST_SAMPLE_TRACE_H */
29+
30+
/* This part must be outside protection */
31+
#include <trace/define_trace.h>

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/tracepoint.h>
2424
#include <linux/wait.h>
2525
#include <linux/workqueue.h>
26+
#include <trace/events/rust_sample.h>
2627

2728
/* `bindgen` gets confused at certain things. */
2829
const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;

samples/rust/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
ccflags-y += -I$(src) # needed for trace events
23

34
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
4-
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
5+
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o rust_print_events.o
56

67
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs

samples/rust/rust_print.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ impl kernel::Module for RustPrint {
6969

7070
arc_print()?;
7171

72+
trace::trace_rust_sample_loaded(42);
73+
7274
Ok(RustPrint)
7375
}
7476
}
@@ -78,3 +80,19 @@ impl Drop for RustPrint {
7880
pr_info!("Rust printing macros sample (exit)\n");
7981
}
8082
}
83+
84+
mod trace {
85+
use core::ffi::c_int;
86+
87+
kernel::declare_trace! {
88+
/// # Safety
89+
///
90+
/// Always safe to call.
91+
unsafe fn rust_sample_loaded(magic: c_int);
92+
}
93+
94+
pub(crate) fn trace_rust_sample_loaded(magic: i32) {
95+
// SAFETY: Always safe to call.
96+
unsafe { rust_sample_loaded(magic as c_int) }
97+
}
98+
}

samples/rust/rust_print_events.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright 2024 Google LLC
4+
*/
5+
6+
#define CREATE_TRACE_POINTS
7+
#define CREATE_RUST_TRACE_POINTS
8+
#include <trace/events/rust_sample.h>

0 commit comments

Comments
 (0)