Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Alice Ryhl and committed by
Steven Rostedt (Google)
91d39024 ad37bcd9

+61 -1
+1
MAINTAINERS
··· 20223 20223 P: https://rust-for-linux.com/contributing 20224 20224 T: git https://github.com/Rust-for-Linux/linux.git rust-next 20225 20225 F: Documentation/rust/ 20226 + F: include/trace/events/rust_sample.h 20226 20227 F: rust/ 20227 20228 F: samples/rust/ 20228 20229 F: scripts/*rust*
+31
include/trace/events/rust_sample.h
··· 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>
+1
rust/bindings/bindings_helper.h
··· 23 23 #include <linux/tracepoint.h> 24 24 #include <linux/wait.h> 25 25 #include <linux/workqueue.h> 26 + #include <trace/events/rust_sample.h> 26 27 27 28 /* `bindgen` gets confused at certain things. */ 28 29 const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
+2 -1
samples/rust/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + ccflags-y += -I$(src) # needed for trace events 2 3 3 4 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 5 6 6 7 subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs
+18
samples/rust/rust_print.rs
··· 69 69 70 70 arc_print()?; 71 71 72 + trace::trace_rust_sample_loaded(42); 73 + 72 74 Ok(RustPrint) 73 75 } 74 76 } ··· 78 76 impl Drop for RustPrint { 79 77 fn drop(&mut self) { 80 78 pr_info!("Rust printing macros sample (exit)\n"); 79 + } 80 + } 81 + 82 + mod trace { 83 + use core::ffi::c_int; 84 + 85 + kernel::declare_trace! { 86 + /// # Safety 87 + /// 88 + /// Always safe to call. 89 + unsafe fn rust_sample_loaded(magic: c_int); 90 + } 91 + 92 + pub(crate) fn trace_rust_sample_loaded(magic: i32) { 93 + // SAFETY: Always safe to call. 94 + unsafe { rust_sample_loaded(magic as c_int) } 81 95 } 82 96 }
+8
samples/rust/rust_print_events.c
··· 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>