rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Steven Rostedt" <rostedt@goodmis.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Jason Baron" <jbaron@akamai.com>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	linux-trace-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Arnd Bergmann" <arnd@arndb.de>,
	linux-arch@vger.kernel.org,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Sean Christopherson" <seanjc@google.com>,
	"Uros Bizjak" <ubizjak@gmail.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>, "Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oliver.upton@linux.dev>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Fuad Tabba" <tabba@google.com>,
	linux-arm-kernel@lists.infradead.org,
	"Paul Walmsley" <paul.walmsley@sifive.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Anup Patel" <apatel@ventanamicro.com>,
	"Andrew Jones" <ajones@ventanamicro.com>,
	"Alexandre Ghiti" <alexghiti@rivosinc.com>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	"Samuel Holland" <samuel.holland@sifive.com>,
	linux-riscv@lists.infradead.org,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"WANG Xuerui" <kernel@xen0n.name>,
	"Bibo Mao" <maobibo@loongson.cn>,
	"Tiezhu Yang" <yangtiezhu@loongson.cn>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Tianrui Zhao" <zhaotianrui@loongson.cn>,
	loongarch@lists.linux.dev
Subject: Re: [PATCH v8 3/5] rust: samples: add tracepoint to Rust sample
Date: Thu, 22 Aug 2024 10:19:50 -0700	[thread overview]
Message-ID: <ZsdzNqUuXSXaGZqt@boqun-archlinux> (raw)
In-Reply-To: <20240822-tracepoint-v8-3-f0c5899e6fd3@google.com>

On Thu, Aug 22, 2024 at 12:04:15PM +0000, Alice Ryhl wrote:
> 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.
> 
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>  MAINTAINERS                        |  1 +
>  include/trace/events/rust_sample.h | 31 +++++++++++++++++++++++++++++++
>  rust/bindings/bindings_helper.h    |  1 +
>  samples/rust/Makefile              |  3 ++-
>  samples/rust/rust_print.rs         | 18 ++++++++++++++++++
>  samples/rust/rust_print_events.c   |  8 ++++++++
>  6 files changed, 61 insertions(+), 1 deletion(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index f328373463b0..1acf5bfddfc4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -19922,6 +19922,7 @@ C:	zulip://rust-for-linux.zulipchat.com
>  P:	https://rust-for-linux.com/contributing
>  T:	git https://github.com/Rust-for-Linux/linux.git rust-next
>  F:	Documentation/rust/
> +F:	include/trace/events/rust_sample.h
>  F:	rust/
>  F:	samples/rust/
>  F:	scripts/*rust*
> diff --git a/include/trace/events/rust_sample.h b/include/trace/events/rust_sample.h
> new file mode 100644
> index 000000000000..dbc80ca2e465
> --- /dev/null
> +++ b/include/trace/events/rust_sample.h

Is it possible to make this a header file inside sample/rust/? Given
this is just an example, I feel it's better if we could avoid making
this "public", but maybe I'm missing some constraints of tracepoints.

(Oh, I just remember the problem while I was writting this: we need the
header file here because this is now how bindgen generates bindings, so
moving it to sample/rust/ requires we have "per-module" or
"per-subsystem" bindgen feature)

Anyway this is not a big deal to me. We can move it later if possible.
So:

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun

> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Tracepoints for `samples/rust/rust_print.rs`.
> + *
> + * Copyright (C) 2024 Google, Inc.
> + */
> +
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM rust_sample
> +
> +#if !defined(_RUST_SAMPLE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _RUST_SAMPLE_TRACE_H
> +
> +#include <linux/tracepoint.h>
> +
> +TRACE_EVENT(rust_sample_loaded,
> +	TP_PROTO(int magic_number),
> +	TP_ARGS(magic_number),
> +	TP_STRUCT__entry(
> +		__field(int, magic_number)
> +	),
> +	TP_fast_assign(
> +		__entry->magic_number = magic_number;
> +	),
> +	TP_printk("magic=%d", __entry->magic_number)
> +);
> +
> +#endif /* _RUST_SAMPLE_TRACE_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> index fc6f94729789..fe97256afe65 100644
> --- a/rust/bindings/bindings_helper.h
> +++ b/rust/bindings/bindings_helper.h
> @@ -23,6 +23,7 @@
>  #include <linux/tracepoint.h>
>  #include <linux/wait.h>
>  #include <linux/workqueue.h>
> +#include <trace/events/rust_sample.h>
>  
>  /* `bindgen` gets confused at certain things. */
>  const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
> diff --git a/samples/rust/Makefile b/samples/rust/Makefile
> index 03086dabbea4..f29280ec4820 100644
> --- a/samples/rust/Makefile
> +++ b/samples/rust/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
> +ccflags-y += -I$(src)				# needed for trace events
>  
>  obj-$(CONFIG_SAMPLE_RUST_MINIMAL)		+= rust_minimal.o
> -obj-$(CONFIG_SAMPLE_RUST_PRINT)			+= rust_print.o
> +obj-$(CONFIG_SAMPLE_RUST_PRINT)			+= rust_print.o rust_print_events.o
>  
>  subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS)		+= hostprogs
> diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs
> index 6eabb0d79ea3..6d14b08cac1c 100644
> --- a/samples/rust/rust_print.rs
> +++ b/samples/rust/rust_print.rs
> @@ -69,6 +69,8 @@ fn init(_module: &'static ThisModule) -> Result<Self> {
>  
>          arc_print()?;
>  
> +        trace::trace_rust_sample_loaded(42);
> +
>          Ok(RustPrint)
>      }
>  }
> @@ -78,3 +80,19 @@ fn drop(&mut self) {
>          pr_info!("Rust printing macros sample (exit)\n");
>      }
>  }
> +
> +mod trace {
> +    use core::ffi::c_int;
> +
> +    kernel::declare_trace! {
> +        /// # Safety
> +        ///
> +        /// Always safe to call.
> +        unsafe fn rust_sample_loaded(magic: c_int);
> +    }
> +
> +    pub(crate) fn trace_rust_sample_loaded(magic: i32) {
> +        // SAFETY: Always safe to call.
> +        unsafe { rust_sample_loaded(magic as c_int) }
> +    }
> +}
> diff --git a/samples/rust/rust_print_events.c b/samples/rust/rust_print_events.c
> new file mode 100644
> index 000000000000..a9169ff0edf1
> --- /dev/null
> +++ b/samples/rust/rust_print_events.c
> @@ -0,0 +1,8 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright 2024 Google LLC
> + */
> +
> +#define CREATE_TRACE_POINTS
> +#define CREATE_RUST_TRACE_POINTS
> +#include <trace/events/rust_sample.h>
> 
> -- 
> 2.46.0.184.g6999bdac58-goog
> 

  reply	other threads:[~2024-08-22 17:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 12:04 [PATCH v8 0/5] Tracepoints and static branch in Rust Alice Ryhl
2024-08-22 12:04 ` [PATCH v8 1/5] rust: add generic static_key_false Alice Ryhl
2024-08-22 12:08   ` [PATCH v8 1/5 alt] " Alice Ryhl
2024-08-22 13:43     ` Boqun Feng
2024-08-22 12:04 ` [PATCH v8 2/5] rust: add tracepoint support Alice Ryhl
2024-08-22 14:38   ` Boqun Feng
2024-08-22 12:04 ` [PATCH v8 3/5] rust: samples: add tracepoint to Rust sample Alice Ryhl
2024-08-22 17:19   ` Boqun Feng [this message]
2024-08-22 12:04 ` [PATCH v8 4/5] jump_label: adjust inline asm to be consistent Alice Ryhl
2024-08-22 12:04 ` [PATCH v8 5/5] rust: add arch_static_branch Alice Ryhl
2024-10-01 13:15 ` [PATCH v8 0/5] Tracepoints and static branch in Rust Steven Rostedt
2024-10-01 13:32   ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZsdzNqUuXSXaGZqt@boqun-archlinux \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=ajones@ventanamicro.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.gaynor@gmail.com \
    --cc=alexghiti@rivosinc.com \
    --cc=aliceryhl@google.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=apatel@ventanamicro.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=conor.dooley@microchip.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=gary@garyguo.net \
    --cc=hpa@zytor.com \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=maobibo@loongson.cn \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=maz@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=samuel.holland@sifive.com \
    --cc=seanjc@google.com \
    --cc=tabba@google.com \
    --cc=tglx@linutronix.de \
    --cc=ubizjak@gmail.com \
    --cc=wedsonaf@gmail.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=yangtiezhu@loongson.cn \
    --cc=zhaotianrui@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).