1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #define TRACE_SYSTEM sched
5 #if !defined(LTTNG_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_SCHED_H
8 #include <probes/lttng-tracepoint-event.h>
9 #include <linux/sched.h>
10 #include <linux/pid_namespace.h>
11 #include <linux/binfmts.h>
12 #include <linux/sched/rt.h>
14 #define LTTNG_MAX_PID_NS_LEVEL 32
16 #ifndef _TRACE_SCHED_DEF_
17 #define _TRACE_SCHED_DEF_
19 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
23 #ifdef CONFIG_SCHED_DEBUG
25 #endif /* CONFIG_SCHED_DEBUG */
28 * Preemption ignores task state, therefore preempted tasks are always
29 * RUNNING (we will not have dequeued if state != RUNNING).
32 return TASK_REPORT_MAX
;
35 * task_state_index() uses fls() and returns a value from 0-8 range.
36 * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
37 * it for left shift operation to get the correct task->state
40 state
= task_state_index(p
);
42 return state
? (1 << (state
- 1)) : state
;
45 #endif /* _TRACE_SCHED_DEF_ */
48 * Enumeration of the task state bitmask.
49 * Only bit flags are enumerated here, not composition of states.
51 LTTNG_TRACEPOINT_ENUM(task_state
,
53 ctf_enum_value("TASK_RUNNING", TASK_RUNNING
)
54 ctf_enum_value("TASK_INTERRUPTIBLE", TASK_INTERRUPTIBLE
)
55 ctf_enum_value("TASK_UNINTERRUPTIBLE", TASK_UNINTERRUPTIBLE
)
56 ctf_enum_value("TASK_STOPPED", __TASK_STOPPED
)
57 ctf_enum_value("TASK_TRACED", __TASK_TRACED
)
58 ctf_enum_value("EXIT_DEAD", EXIT_DEAD
)
59 ctf_enum_value("EXIT_ZOMBIE", EXIT_ZOMBIE
)
60 ctf_enum_value("TASK_PARKED", TASK_PARKED
)
61 ctf_enum_value("TASK_DEAD", TASK_DEAD
)
62 ctf_enum_value("TASK_WAKEKILL", TASK_WAKEKILL
)
63 ctf_enum_value("TASK_WAKING", TASK_WAKING
)
64 ctf_enum_value("TASK_NOLOAD", TASK_NOLOAD
)
65 ctf_enum_value("TASK_NEW", TASK_NEW
)
66 ctf_enum_value("TASK_STATE_MAX", TASK_STATE_MAX
)
71 * Tracepoint for calling kthread_stop, performed to end a kthread:
73 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
75 TP_PROTO(struct task_struct
*t
),
80 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
81 ctf_integer(pid_t
, tid
, t
->pid
)
86 * Tracepoint for the return value of the kthread stopping:
88 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
95 ctf_integer(int, ret
, ret
)
100 * Tracepoint for waking up a task:
102 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
104 TP_PROTO(struct task_struct
*p
),
109 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
110 ctf_integer(pid_t
, tid
, p
->pid
)
111 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
112 ctf_integer(int, target_cpu
, task_cpu(p
))
117 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
118 * called from the waking context.
120 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
121 TP_PROTO(struct task_struct
*p
),
125 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
126 * It it not always called from the waking context.
128 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
129 TP_PROTO(struct task_struct
*p
),
133 * Tracepoint for waking up a new task:
135 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
136 TP_PROTO(struct task_struct
*p
),
140 * Tracepoint for task switches, performed by the scheduler:
142 LTTNG_TRACEPOINT_EVENT(sched_switch
,
144 TP_PROTO(bool preempt
,
145 struct task_struct
*prev
,
146 struct task_struct
*next
),
148 TP_ARGS(preempt
, prev
, next
),
151 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
152 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
153 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
154 ctf_enum(task_state
, long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
155 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
156 ctf_integer(pid_t
, next_tid
, next
->pid
)
157 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
162 * Tracepoint for a task being migrated:
164 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
166 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
168 TP_ARGS(p
, dest_cpu
),
171 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
172 ctf_integer(pid_t
, tid
, p
->pid
)
173 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
174 ctf_integer(int, orig_cpu
, task_cpu(p
))
175 ctf_integer(int, dest_cpu
, dest_cpu
)
179 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
181 TP_PROTO(struct task_struct
*p
),
186 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
187 ctf_integer(pid_t
, tid
, p
->pid
)
188 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
193 * Tracepoint for freeing a task:
195 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
196 TP_PROTO(struct task_struct
*p
),
201 * Tracepoint for a task exiting:
203 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
204 TP_PROTO(struct task_struct
*p
),
208 * Tracepoint for waiting on task to unschedule:
210 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
211 TP_PROTO(struct task_struct
*p
),
215 * Tracepoint for a waiting task:
217 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
219 TP_PROTO(struct pid
*pid
),
224 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
225 ctf_integer(pid_t
, tid
, pid_nr(pid
))
226 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
231 * Tracepoint for do_fork.
232 * Saving both TID and PID information, especially for the child, allows
233 * trace analyzers to distinguish between creation of a new process and
234 * creation of a new thread. Newly created processes will have child_tid
235 * == child_pid, while creation of a thread yields to child_tid !=
238 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
240 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
242 TP_ARGS(parent
, child
),
245 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
246 unsigned int ns_level
;
251 struct pid
*child_pid
;
254 child_pid
= task_pid(child
);
255 tp_locvar
->ns_level
=
256 min_t(unsigned int, child_pid
->level
+ 1,
257 LTTNG_MAX_PID_NS_LEVEL
);
258 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
259 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
264 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
265 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
266 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
267 ctf_integer(unsigned int, parent_ns_inum
,
269 unsigned int parent_ns_inum
= 0;
272 struct pid_namespace
*pid_ns
;
274 pid_ns
= task_active_pid_ns(parent
);
281 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
282 ctf_integer(pid_t
, child_tid
, child
->pid
)
283 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
284 ctf_integer(pid_t
, child_pid
, child
->tgid
)
285 ctf_integer(unsigned int, child_ns_inum
,
287 unsigned int child_ns_inum
= 0;
290 struct pid_namespace
*pid_ns
;
292 pid_ns
= task_active_pid_ns(child
);
305 * Tracepoint for exec:
307 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
309 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
310 struct linux_binprm
*bprm
),
312 TP_ARGS(p
, old_pid
, bprm
),
315 ctf_string(filename
, bprm
->filename
)
316 ctf_integer(pid_t
, tid
, p
->pid
)
317 ctf_integer(pid_t
, old_tid
, old_pid
)
322 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
323 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
325 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
327 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
332 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
333 ctf_integer(pid_t
, tid
, tsk
->pid
)
334 ctf_integer(u64
, delay
, delay
)
340 * Tracepoint for accounting wait time (time the task is runnable
341 * but not actually running due to scheduler contention).
343 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
344 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
348 * Tracepoint for accounting sleep time (time the task is not runnable,
349 * including iowait, see below).
351 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
352 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
356 * Tracepoint for accounting iowait time (time the task is not runnable
357 * due to waiting on IO to complete).
359 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
360 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
364 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
366 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
367 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
371 * Tracepoint for accounting runtime (time the task is executing
374 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
376 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
378 TP_ARGS(tsk
, runtime
, vruntime
),
381 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
382 ctf_integer(pid_t
, tid
, tsk
->pid
)
383 ctf_integer(u64
, runtime
, runtime
)
384 ctf_integer(u64
, vruntime
, vruntime
)
389 * Tracepoint for showing priority inheritance modifying a tasks
392 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
394 TP_PROTO(struct task_struct
*tsk
, struct task_struct
*pi_task
),
396 TP_ARGS(tsk
, pi_task
),
399 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
400 ctf_integer(pid_t
, tid
, tsk
->pid
)
401 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
402 ctf_integer(int, newprio
, pi_task
? pi_task
->prio
- MAX_RT_PRIO
: tsk
->prio
- MAX_RT_PRIO
)
406 #endif /* LTTNG_TRACE_SCHED_H */
408 /* This part must be outside protection */
409 #include <probes/define_trace.h>
This page took 0.044676 seconds and 4 git commands to generate.