Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * event tracer |
| 4 | * |
| 5 | * Copyright (C) 2022 Google Inc, Steven Rostedt <rostedt@goodmis.org> |
| 6 | */ |
| 7 | |
| 8 | #define pr_fmt(fmt) fmt |
| 9 | |
| 10 | #include <linux/trace_events.h> |
| 11 | #include <linux/version.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/sched.h> |
Steven Rostedt (Google) | 3a73333 | 2022-03-03 17:05:34 -0500 | [diff] [blame] | 14 | |
| 15 | /* |
| 16 | * Must include the event header that the custom event will attach to, |
| 17 | * from the C file, and not in the custom header file. |
| 18 | */ |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 19 | #include <trace/events/sched.h> |
| 20 | |
Steven Rostedt (Google) | 3a73333 | 2022-03-03 17:05:34 -0500 | [diff] [blame] | 21 | /* Declare CREATE_CUSTOM_TRACE_EVENTS before including custom header */ |
| 22 | #define CREATE_CUSTOM_TRACE_EVENTS |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 23 | |
Steven Rostedt (Google) | 3a73333 | 2022-03-03 17:05:34 -0500 | [diff] [blame] | 24 | #include "trace_custom_sched.h" |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 25 | |
Steven Rostedt (Google) | 3a73333 | 2022-03-03 17:05:34 -0500 | [diff] [blame] | 26 | /* |
| 27 | * As the trace events are not exported to modules, the use of |
| 28 | * for_each_kernel_tracepoint() is needed to find the trace event |
| 29 | * to attach to. The fct() function below, is a callback that |
| 30 | * will be called for every event. |
| 31 | * |
| 32 | * Helper functions are created by the TRACE_CUSTOM_EVENT() macro |
| 33 | * update the event. Those are of the form: |
| 34 | * |
| 35 | * trace_custom_event_<event>_update() |
| 36 | * |
| 37 | * Where <event> is the event to attach. |
| 38 | */ |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 39 | static void fct(struct tracepoint *tp, void *priv) |
| 40 | { |
Steven Rostedt (Google) | 3a73333 | 2022-03-03 17:05:34 -0500 | [diff] [blame] | 41 | trace_custom_event_sched_switch_update(tp); |
| 42 | trace_custom_event_sched_waking_update(tp); |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static int __init trace_sched_init(void) |
| 46 | { |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 47 | for_each_kernel_tracepoint(fct, NULL); |
Steven Rostedt (Google) | 3a73333 | 2022-03-03 17:05:34 -0500 | [diff] [blame] | 48 | return 0; |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void __exit trace_sched_exit(void) |
| 52 | { |
Steven Rostedt (Google) | 953c2f0 | 2022-03-03 17:05:32 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | module_init(trace_sched_init); |
| 56 | module_exit(trace_sched_exit); |
| 57 | |
| 58 | MODULE_AUTHOR("Steven Rostedt"); |
| 59 | MODULE_DESCRIPTION("Custom scheduling events"); |
| 60 | MODULE_LICENSE("GPL"); |