1/* SPDX-License-Identifier: GPL-2.0 */
2
3/*
4 * Like the headers that use TRACE_EVENT(), the TRACE_CUSTOM_EVENT()
5 * needs a header that allows for multiple inclusions.
6 *
7 * Test for a unique name (here we have _TRACE_CUSTOM_SCHED_H),
8 * also allowing to continue if TRACE_CUSTOM_MULTI_READ is defined.
9 */
10#if !defined(_TRACE_CUSTOM_SCHED_H) || defined(TRACE_CUSTOM_MULTI_READ)
11#define _TRACE_CUSTOM_SCHED_H
12
13/* Include linux/trace_events.h for initial defines of TRACE_CUSTOM_EVENT() */
14#include <linux/trace_events.h>
15
16/*
17 * TRACE_CUSTOM_EVENT() is just like TRACE_EVENT(). The first parameter
18 * is the event name of an existing event where the TRACE_EVENT has been included
19 * in the C file before including this file.
20 */
21TRACE_CUSTOM_EVENT(sched_switch,
22
23	/*
24	 * The TP_PROTO() and TP_ARGS must match the trace event
25	 * that the custom event is using.
26	 */
27	TP_PROTO(bool preempt,
28		 struct task_struct *prev,
29		 struct task_struct *next,
30		 unsigned int prev_state),
31
32	TP_ARGS(preempt, prev, next, prev_state),
33
34	/*
35	 * The next fields are where the customization happens.
36	 * The TP_STRUCT__entry() defines what will be recorded
37	 * in the ring buffer when the custom event triggers.
38	 *
39	 * The rest is just like the TRACE_EVENT() macro except that
40	 * it uses the custom entry.
41	 */
42	TP_STRUCT__entry(
43		__field(	unsigned short,		prev_prio	)
44		__field(	unsigned short,		next_prio	)
45		__field(	pid_t,	next_pid			)
46	),
47
48	TP_fast_assign(
49		__entry->prev_prio	= prev->prio;
50		__entry->next_pid	= next->pid;
51		__entry->next_prio	= next->prio;
52	),
53
54	TP_printk("prev_prio=%d next_pid=%d next_prio=%d",
55		  __entry->prev_prio, __entry->next_pid, __entry->next_prio)
56)
57
58
59TRACE_CUSTOM_EVENT(sched_waking,
60
61	TP_PROTO(struct task_struct *p),
62
63	TP_ARGS(p),
64
65	TP_STRUCT__entry(
66		__field(	pid_t,			pid	)
67		__field(	unsigned short,		prio	)
68	),
69
70	TP_fast_assign(
71		__entry->pid	= p->pid;
72		__entry->prio	= p->prio;
73	),
74
75	TP_printk("pid=%d prio=%d", __entry->pid, __entry->prio)
76)
77#endif
78/*
79 * Just like the headers that create TRACE_EVENTs, the below must
80 * be outside the protection of the above #if block.
81 */
82
83/*
84 * It is required that the Makefile includes:
85 *    CFLAGS_<c_file>.o := -I$(src)
86 */
87#undef TRACE_INCLUDE_PATH
88#undef TRACE_INCLUDE_FILE
89#define TRACE_INCLUDE_PATH .
90
91/*
92 * It is requred that the TRACE_INCLUDE_FILE be the same
93 * as this file without the ".h".
94 */
95#define TRACE_INCLUDE_FILE trace_custom_sched
96#include <trace/define_custom_trace.h>
97