Merge tag 'leds-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/pavel...
[linux-2.6-microblaze.git] / samples / trace_events / trace_custom_sched.c
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>
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  */
19 #include <trace/events/sched.h>
20
21 /* Declare CREATE_CUSTOM_TRACE_EVENTS before including custom header */
22 #define CREATE_CUSTOM_TRACE_EVENTS
23
24 #include "trace_custom_sched.h"
25
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  */
39 static void fct(struct tracepoint *tp, void *priv)
40 {
41         trace_custom_event_sched_switch_update(tp);
42         trace_custom_event_sched_waking_update(tp);
43 }
44
45 static int __init trace_sched_init(void)
46 {
47         for_each_kernel_tracepoint(fct, NULL);
48         return 0;
49 }
50
51 static void __exit trace_sched_exit(void)
52 {
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");