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 <[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: Gary Guo <[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: Boqun Feng <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
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)