From patchwork Fri Oct 11 10:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13832327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AFE6CFD316 for ; Fri, 11 Oct 2024 10:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fvWLJDL4H9a1U9tTpIBXALeOXBxFcs1MlgGGeXypH0o=; b=tZnKJmK0lWVu3NDEjbGFAUj+7W y+RkrbHKcrWpSIIC6WIaRBkZrjohnl7tB9qv60ccLwXCGS5vry0zqNrXt9LDUn6fBFgY+9Hvpxrgy Ca1NK9cL+nsHvVcu2vC/g96Z/nIG29a7plj5vxXfmMKOVrR14jvjqikYYPQVu5l2Q2X0VQqMTnqQi 2qXouO24ilfVDfIrEflIKC9D7mhlG5kKjXwfmE1Zd5SKK+UCLHQ8uNwouBPzY+53c9wAy2ntNdRvu OUYLb7rNxaIR6hkTTjxvcBjg8gtvGB2wSIbARZXV5teHzpc322WUM9SnlcyAXTVKNpl7ADwKP6tvc YAjbP3mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1szCfE-0000000Fvvy-0HTR; Fri, 11 Oct 2024 10:14:28 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1szCf8-0000000Fvpq-0lUG for linux-riscv@lists.infradead.org; Fri, 11 Oct 2024 10:14:24 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-43057c9b32bso11631625e9.0 for ; Fri, 11 Oct 2024 03:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728641660; x=1729246460; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UZneAmtjYaP5W4qvsAgvZmY0+FlDJmT5YgM1QOUVihI=; b=Edn9Xa9dzsQr+GXgOD8PzRVe2wZAKwNrgh1xpXhTpz9z4hSU+wnZCnq3PhCfyKk+Hv h2trXlf1gta0Sxp8w1nmgZx2O2K72x9WGJJDkgETRLUH2gyxEytPCQVEuJSoGUaBvH7K l1FbHyFZN7f2uWusXXtl2/ZnZV7alIT05QBxV0sX7OkQzKmWq+N+LSlFe1oM5CLN26Yq 5DFlashIUfPadh22Wsgc6DwMN4bg4VMH7Ppp7QTmCv2EoW3rrxT8ZPy4dHXFv3RUKuIq 34y1hj4XSpOlV7ICqRvdJItlANTRLUDgToZgR3gtNYby2hUaDHnB3ASXdQn/w/Rts+tg jmOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728641660; x=1729246460; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UZneAmtjYaP5W4qvsAgvZmY0+FlDJmT5YgM1QOUVihI=; b=DzVEoO96hOdtd6HfITqx40/J3fC1ka+QgvqdDbRg0nkHzmXOEjYCfKFxtEkJm7piYF JbYcVvnywv4Q3+KeVGxtHiIeB9m5lWnY2foFIs/5pYwt0BLizfk9b75m/98UaZduRrGr YkaSjuN0CJSSKxShcLMBfjmTXtWIFNDNiUtbRcrSqyjb+Q7nNjBob7/tFFUvhtbK8q+o pVNIH7PaeyGn1OPD5kCRZMe4CLevCQ7nP3+BGTM2sBdxgYzHARLK4QnOGABqe8lp/+k6 vPNhu/jimEjGxN/HLSE6IyGIlPQoFwdXdDDqAqO/gpAmbfQgox+5G8Ryh/+Z1JB/sYmm dsJQ== X-Forwarded-Encrypted: i=1; AJvYcCXDAgBNq8Dq0zOHWSCdwAiltE4sdBCCy50mn6OltTZs7mUt1thkrzA55UHrojwCoh0qNhjJVpWghhH0ZA==@lists.infradead.org X-Gm-Message-State: AOJu0YzrXrsOE9zB7/VhyGHIZHRzAlDGHHVFrhs4sAHnY5a05A809qug Qw97FYGTnWlKMsU/DZZQS/6p/g79+25Q/DEvBtvr6e9xHkqsGOM6o8n50/8B/04URZwl2SZfY7i t7iUDMRXTnNuXNA== X-Google-Smtp-Source: AGHT+IHwSshcnmQuyVjoiggjp0suaGgugY0GhsgHeqQ62Wpnp4cvxzx9Leg6f46QE7rgGmMJJguSn62m3/uZW1k= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:35bd]) (user=aliceryhl job=sendgmr) by 2002:a7b:ce91:0:b0:42c:b3cb:296c with SMTP id 5b1f17b1804b1-4311df4b8e8mr27955e9.7.1728641659750; Fri, 11 Oct 2024 03:14:19 -0700 (PDT) Date: Fri, 11 Oct 2024 10:13:36 +0000 In-Reply-To: <20241011-tracepoint-v10-0-7fbde4d6b525@google.com> Mime-Version: 1.0 References: <20241011-tracepoint-v10-0-7fbde4d6b525@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=4321; i=aliceryhl@google.com; h=from:subject:message-id; bh=wthozKz61nBwTqsdkL/dd5IHBHSbPc3jb7JMQXND02Q=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnCPpwllzrVPf0XbtgvnBfNst4p6IA1aRL6WpWU 4aylkW0T0aJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZwj6cAAKCRAEWL7uWMY5 Ru61D/9dPQkiC24ZCDf7aZ+W5r69bavpsSXs8AyW+ckOYlQsP6mfv+X2iABRlZF/31B0HIIV/15 oJwDb5xAklEo4SWnZWxcLInom3QnwykoLyuX/COb7z6y9xUVPeoiYdCFJG6NNdCxJwsuyr5NvSh VjEebkjDS0xhS6z8n1fPr5m/L3soem8NznQy2LHFRyIIE0mrm1dl8kH96KBFRxjS0KO/MEprY74 pq3TQYFY8ML4ZAFqGQRh72m0aJdTc5HBH0gaWNz91GIEPLLJeO4AAOSGu5c3L+fKXLEYMpBoKxZ 8w2Z9r0InuRSX0Cz7aiKu4Zo3lxbztreA0iMxruWgP85OFkFthJQL7LnqWKhA59trIYL6UNwU+Z GW7NkyAwkgpHvMn06ZiIwo4qWSY04XYpF/dusKW5qzQuGOEi4VFDOucrRLfZkFcQpY8hA3Z/7lg ltj7PQ17KRKt9KuGNhcNk29CwETmCku96W5Ou7LVhbZp9/m4AZW+YlMDVs16jdkpPV8Mz8L+gYL RyE4SNWpTlI2APc0JkX1ReFLFlakd5wWADdgkhdCcmZYAQ/aZQ3iVRVRUGiyaUZkXsK6NVMDIbB FWQhq1SbuvK2r8aH8L8me8NZBUe2OiPWAPbO5AWZqbVvPaWTrDUnzMKrGDn/XJCN1InZ4WhYdta +6raBZmdMFrnMSA== X-Mailer: b4 0.13.0 Message-ID: <20241011-tracepoint-v10-3-7fbde4d6b525@google.com> Subject: [PATCH v10 3/5] rust: samples: add tracepoint to Rust sample From: Alice Ryhl To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg Cc: linux-trace-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Arnd Bergmann , linux-arch@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Sean Christopherson , Uros Bizjak , Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Mark Rutland , Ryan Roberts , Fuad Tabba , linux-arm-kernel@lists.infradead.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Andrew Jones , Alexandre Ghiti , Conor Dooley , Samuel Holland , linux-riscv@lists.infradead.org, Huacai Chen , WANG Xuerui , Bibo Mao , Tiezhu Yang , Andrew Morton , Tianrui Zhao , loongarch@lists.linux.dev, Alice Ryhl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241011_031422_339806_84D9C7AE X-CRM114-Status: GOOD ( 17.37 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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. Reviewed-by: Boqun Feng Signed-off-by: Alice Ryhl --- 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 a097afd76ded..a9b71411d77a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20223,6 +20223,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 @@ -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 + +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 diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 752572e638a6..b072c197ce9e 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -23,6 +23,7 @@ #include #include #include +#include /* `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 { 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