From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C5CBC433F5 for ; Thu, 3 Mar 2022 22:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236780AbiCCWH0 (ORCPT ); Thu, 3 Mar 2022 17:07:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236739AbiCCWHP (ORCPT ); Thu, 3 Mar 2022 17:07:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0B3B16BCD1 for ; Thu, 3 Mar 2022 14:06:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6BF91B826F8 for ; Thu, 3 Mar 2022 22:06:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F020C004E1; Thu, 3 Mar 2022 22:06:26 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.95) (envelope-from ) id 1nPtab-00ESVk-54; Thu, 03 Mar 2022 17:06:25 -0500 Message-ID: <20220303220530.058538533@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 03 Mar 2022 17:05:30 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Andrew Morton , Joel Fernandes , Peter Zijlstra , Masami Hiramatsu , Tom Zanussi Subject: [PATCH 0/4 v3] tracing: Add a way to have custom events in the tracefs directory Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We would like to have in production a way to record sched wakeups and sched switch, and be able to save the information in a small file with as much available as possible. Currently the wake up and sched switch events are 36 and 64 bytes each (plus a 4 byte ring buffer event header). By having a custom module tap into the sched switch and waking trace points we can bring those events down to 16 and 14 bytes respectively. This version adds the new TRACE_CUSTOM_EVENT() which makes creating a custom event as easy as creating a TRACE_EVENT()! The TRACE_CUSTOM_EVENT() macro does all the work to create the event, and has the same format as the TRACE_EVENT() does. Note, currently perf and bpf do not hook to this, but we can add that later. I kept patch 2 that has the complex way of hand coding the custom event just to keep the histor of it. But now, to add a custom event for sched_switch, all that needs to be done is: trace_custom_sched.c: -------------------------%<------------------------- #include #include #include #include #include #define CREATE_CUSTOM_TRACE_EVENTS #include "trace_custom_sched.h" static void fct(struct tracepoint *tp, void *priv) { trace_custom_event_sched_switch_update(tp); } static int __init trace_sched_init(void) { for_each_kernel_tracepoint(fct, NULL); return 0; } static void __exit trace_sched_exit(void) { } module_init(trace_sched_init); module_exit(trace_sched_exit); ------------------------->%------------------------- -------------------------%<------------------------- #if !defined(_TRACE_CUSTOM_SCHED_H) || defined(TRACE_CUSTOM_MULTI_READ) #define _TRACE_CUSTOM_SCHED_H #include TRACE_CUSTOM_EVENT(sched_switch, /* The below must be the same as the original sched_switch */ TP_PROTO(bool preempt, struct task_struct *prev, struct task_struct *next), TP_ARGS(preempt, prev, next), /* The below is the customization */ TP_STRUCT__entry( __field( unsigned short, prev_prio ) __field( unsigned short, next_prio ) __field( pid_t, next_pid ) ), TP_fast_assign( __entry->prev_prio = prev->prio; __entry->next_pid = next->pid; __entry->next_prio = next->prio; ), TP_printk("prev_prio=%d next_pid=%d next_prio=%d", __entry->prev_prio, __entry->next_pid, __entry->next_prio) ) #endif #undef TRACE_INCLUDE_PATH #undef TRACE_INCLUDE_FILE #define TRACE_INCLUDE_PATH . #define TRACE_INCLUDE_FILE trace_custom_sched #include ------------------------->%------------------------- And update the Makefile to have: CFLAGS_trace_custom_sched.o := -I$(src) Changes since v2: https://lore.kernel.org/all/20220303214832.031378059@goodmis.org/ Forgot to do a: git add include/trace/trace_custom_events.h include/trace/define_custom_trace.h in v2. Steven Rostedt (Google) (4): tracing: Allow custom events to be added to the tracefs directory tracing: Add sample code for custom trace events tracing: Move the defines to create TRACE_EVENTS into their own files tracing: Add TRACE_CUSTOM_EVENT() macro ---- arch/x86/kernel/kprobes/core.c | 4 +- include/linux/trace_events.h | 24 +- include/trace/define_custom_trace.h | 77 +++++ include/trace/stages/init.h | 37 +++ include/trace/stages/stage1_defines.h | 46 +++ include/trace/stages/stage2_defines.h | 48 +++ include/trace/stages/stage3_defines.h | 129 ++++++++ include/trace/stages/stage4_defines.h | 57 ++++ include/trace/stages/stage5_defines.h | 83 +++++ include/trace/stages/stage6_defines.h | 86 +++++ include/trace/stages/stage7_defines.h | 34 ++ include/trace/trace_custom_events.h | 221 +++++++++++++ include/trace/trace_events.h | 499 +----------------------------- kernel/trace/ftrace.c | 33 +- kernel/trace/trace_events.c | 2 + samples/Kconfig | 8 +- samples/Makefile | 1 + samples/trace_events/Makefile | 2 + samples/trace_events/trace_custom_sched.c | 60 ++++ samples/trace_events/trace_custom_sched.h | 95 ++++++ 20 files changed, 1049 insertions(+), 497 deletions(-) create mode 100644 include/trace/define_custom_trace.h create mode 100644 include/trace/stages/init.h create mode 100644 include/trace/stages/stage1_defines.h create mode 100644 include/trace/stages/stage2_defines.h create mode 100644 include/trace/stages/stage3_defines.h create mode 100644 include/trace/stages/stage4_defines.h create mode 100644 include/trace/stages/stage5_defines.h create mode 100644 include/trace/stages/stage6_defines.h create mode 100644 include/trace/stages/stage7_defines.h create mode 100644 include/trace/trace_custom_events.h create mode 100644 samples/trace_events/trace_custom_sched.c create mode 100644 samples/trace_events/trace_custom_sched.h