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 <lttng/tracepoint-event.h>
9 #include <linux/sched.h>
10 #include <linux/pid_namespace.h>
11 #include <linux/binfmts.h>
12 #include <lttng/kernel-version.h>
13 #include <linux/sched/rt.h>
15 #define LTTNG_MAX_PID_NS_LEVEL 32
17 #ifndef _TRACE_SCHED_DEF_
18 #define _TRACE_SCHED_DEF_
20 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0))
22 static inline long __trace_sched_switch_state(bool preempt
,
23 unsigned int prev_state
,
24 struct task_struct
*p
)
28 #ifdef CONFIG_SCHED_DEBUG
30 #endif /* CONFIG_SCHED_DEBUG */
33 * Preemption ignores task state, therefore preempted tasks are always
34 * RUNNING (we will not have dequeued if state != RUNNING).
37 return TASK_REPORT_MAX
;
40 * task_state_index() uses fls() and returns a value from 0-8 range.
41 * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
42 * it for left shift operation to get the correct task->state
45 state
= __task_state_index(prev_state
, p
->exit_state
);
47 return state
? (1 << (state
- 1)) : state
;
50 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0))
52 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
56 #ifdef CONFIG_SCHED_DEBUG
58 #endif /* CONFIG_SCHED_DEBUG */
61 * Preemption ignores task state, therefore preempted tasks are always
62 * RUNNING (we will not have dequeued if state != RUNNING).
65 return TASK_REPORT_MAX
;
68 * task_state_index() uses fls() and returns a value from 0-8 range.
69 * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
70 * it for left shift operation to get the correct task->state
73 state
= task_state_index(p
);
75 return state
? (1 << (state
- 1)) : state
;
78 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0))
80 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
84 #ifdef CONFIG_SCHED_DEBUG
86 #endif /* CONFIG_SCHED_DEBUG */
89 * Preemption ignores task state, therefore preempted tasks are always
90 * RUNNING (we will not have dequeued if state != RUNNING).
93 return TASK_REPORT_MAX
;
96 * __get_task_state() uses fls() and returns a value from 0-8 range.
97 * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
98 * it for left shift operation to get the correct task->state
101 state
= __get_task_state(p
);
103 return state
? (1 << (state
- 1)) : state
;
108 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
110 #ifdef CONFIG_SCHED_DEBUG
111 BUG_ON(p
!= current
);
112 #endif /* CONFIG_SCHED_DEBUG */
114 * Preemption ignores task state, therefore preempted tasks are always RUNNING
115 * (we will not have dequeued if state != RUNNING).
117 return preempt
? TASK_RUNNING
| TASK_STATE_MAX
: p
->state
;
121 #endif /* _TRACE_SCHED_DEF_ */
123 #ifdef CONFIG_LTTNG_EXPERIMENTAL_BITWISE_ENUM
125 * Enumeration of the task state bitmask.
126 * Only bit flags are enumerated here, not composition of states.
128 LTTNG_TRACEPOINT_ENUM(task_state
,
130 ctf_enum_value("TASK_RUNNING", TASK_RUNNING
)
131 ctf_enum_value("TASK_INTERRUPTIBLE", TASK_INTERRUPTIBLE
)
132 ctf_enum_value("TASK_UNINTERRUPTIBLE", TASK_UNINTERRUPTIBLE
)
133 ctf_enum_value("TASK_STOPPED", __TASK_STOPPED
)
134 ctf_enum_value("TASK_TRACED", __TASK_TRACED
)
135 ctf_enum_value("EXIT_DEAD", EXIT_DEAD
)
136 ctf_enum_value("EXIT_ZOMBIE", EXIT_ZOMBIE
)
137 ctf_enum_value("TASK_PARKED", TASK_PARKED
)
138 ctf_enum_value("TASK_DEAD", TASK_DEAD
)
139 ctf_enum_value("TASK_WAKEKILL", TASK_WAKEKILL
)
140 ctf_enum_value("TASK_WAKING", TASK_WAKING
)
141 ctf_enum_value("TASK_NOLOAD", TASK_NOLOAD
)
143 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,8,0))
144 ctf_enum_value("TASK_NEW", TASK_NEW
)
145 #endif /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,8,0)) */
147 ctf_enum_value("TASK_STATE_MAX", TASK_STATE_MAX
)
150 #endif /* CONFIG_LTTNG_EXPERIMENTAL_BITWISE_ENUM */
153 * Tracepoint for calling kthread_stop, performed to end a kthread:
155 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
157 TP_PROTO(struct task_struct
*t
),
162 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
163 ctf_integer(pid_t
, tid
, t
->pid
)
168 * Tracepoint for the return value of the kthread stopping:
170 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
177 ctf_integer(int, ret
, ret
)
182 * Tracepoint for waking up a task:
184 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
186 TP_PROTO(struct task_struct
*p
),
191 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
192 ctf_integer(pid_t
, tid
, p
->pid
)
193 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
194 ctf_integer(int, target_cpu
, task_cpu(p
))
199 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
200 * called from the waking context.
202 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
203 TP_PROTO(struct task_struct
*p
),
207 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
208 * It it not always called from the waking context.
210 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
211 TP_PROTO(struct task_struct
*p
),
215 * Tracepoint for waking up a new task:
217 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
218 TP_PROTO(struct task_struct
*p
),
222 * Tracepoint for task switches, performed by the scheduler:
225 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0))
226 LTTNG_TRACEPOINT_EVENT(sched_switch
,
228 TP_PROTO(bool preempt
,
229 struct task_struct
*prev
,
230 struct task_struct
*next
,
231 unsigned int prev_state
),
233 TP_ARGS(preempt
, prev
, next
, prev_state
),
236 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
237 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
238 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
239 #ifdef CONFIG_LTTNG_EXPERIMENTAL_BITWISE_ENUM
240 ctf_enum(task_state
, long, prev_state
, __trace_sched_switch_state(preempt
, prev_state
, prev
))
242 ctf_integer(long, prev_state
, __trace_sched_switch_state(preempt
, prev_state
, prev
))
244 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
245 ctf_integer(pid_t
, next_tid
, next
->pid
)
246 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
252 LTTNG_TRACEPOINT_EVENT(sched_switch
,
254 TP_PROTO(bool preempt
,
255 struct task_struct
*prev
,
256 struct task_struct
*next
),
258 TP_ARGS(preempt
, prev
, next
),
261 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
262 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
263 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
264 #ifdef CONFIG_LTTNG_EXPERIMENTAL_BITWISE_ENUM
265 ctf_enum(task_state
, long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
267 ctf_integer(long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
269 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
270 ctf_integer(pid_t
, next_tid
, next
->pid
)
271 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
277 * Tracepoint for a task being migrated:
279 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
281 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
283 TP_ARGS(p
, dest_cpu
),
286 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
287 ctf_integer(pid_t
, tid
, p
->pid
)
288 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
289 ctf_integer(int, orig_cpu
, task_cpu(p
))
290 ctf_integer(int, dest_cpu
, dest_cpu
)
294 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
296 TP_PROTO(struct task_struct
*p
),
301 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
302 ctf_integer(pid_t
, tid
, p
->pid
)
303 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
308 * Tracepoint for freeing a task:
310 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
311 TP_PROTO(struct task_struct
*p
),
316 * Tracepoint for a task exiting:
318 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
319 TP_PROTO(struct task_struct
*p
),
323 * Tracepoint for waiting on task to unschedule:
325 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
326 TP_PROTO(struct task_struct
*p
),
330 * Tracepoint for a waiting task:
332 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
334 TP_PROTO(struct pid
*pid
),
339 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
340 ctf_integer(pid_t
, tid
, pid_nr(pid
))
341 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
346 * Tracepoint for do_fork.
347 * Saving both TID and PID information, especially for the child, allows
348 * trace analyzers to distinguish between creation of a new process and
349 * creation of a new thread. Newly created processes will have child_tid
350 * == child_pid, while creation of a thread yields to child_tid !=
353 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
355 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
357 TP_ARGS(parent
, child
),
360 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
361 unsigned int ns_level
;
366 struct pid
*child_pid
;
369 child_pid
= task_pid(child
);
370 tp_locvar
->ns_level
=
371 min_t(unsigned int, child_pid
->level
+ 1,
372 LTTNG_MAX_PID_NS_LEVEL
);
373 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
374 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
379 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
380 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
381 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
382 ctf_integer(unsigned int, parent_ns_inum
,
384 unsigned int parent_ns_inum
= 0;
387 struct pid_namespace
*pid_ns
;
389 pid_ns
= task_active_pid_ns(parent
);
396 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
397 ctf_integer(pid_t
, child_tid
, child
->pid
)
398 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
399 ctf_integer(pid_t
, child_pid
, child
->tgid
)
400 ctf_integer(unsigned int, child_ns_inum
,
402 unsigned int child_ns_inum
= 0;
405 struct pid_namespace
*pid_ns
;
407 pid_ns
= task_active_pid_ns(child
);
420 * Tracepoint for exec:
422 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
424 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
425 struct linux_binprm
*bprm
),
427 TP_ARGS(p
, old_pid
, bprm
),
430 ctf_string(filename
, bprm
->filename
)
431 ctf_integer(pid_t
, tid
, p
->pid
)
432 ctf_integer(pid_t
, old_tid
, old_pid
)
437 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
438 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
440 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
442 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
447 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
448 ctf_integer(pid_t
, tid
, tsk
->pid
)
449 ctf_integer(u64
, delay
, delay
)
455 * Tracepoint for accounting wait time (time the task is runnable
456 * but not actually running due to scheduler contention).
458 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
459 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
463 * Tracepoint for accounting sleep time (time the task is not runnable,
464 * including iowait, see below).
466 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
467 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
471 * Tracepoint for accounting iowait time (time the task is not runnable
472 * due to waiting on IO to complete).
474 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
475 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
479 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
481 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
482 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
486 * Tracepoint for accounting runtime (time the task is executing
489 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
491 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
493 TP_ARGS(tsk
, runtime
, vruntime
),
496 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
497 ctf_integer(pid_t
, tid
, tsk
->pid
)
498 ctf_integer(u64
, runtime
, runtime
)
499 ctf_integer(u64
, vruntime
, vruntime
)
503 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,12,0) || \
504 LTTNG_RT_KERNEL_RANGE(4,9,27,18, 4,10,0,0) || \
505 LTTNG_RT_KERNEL_RANGE(4,11,5,1, 4,12,0,0))
507 * Tracepoint for showing priority inheritance modifying a tasks
510 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
512 TP_PROTO(struct task_struct
*tsk
, struct task_struct
*pi_task
),
514 TP_ARGS(tsk
, pi_task
),
517 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
518 ctf_integer(pid_t
, tid
, tsk
->pid
)
519 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
520 ctf_integer(int, newprio
, pi_task
? pi_task
->prio
- MAX_RT_PRIO
: tsk
->prio
- MAX_RT_PRIO
)
525 * Tracepoint for showing priority inheritance modifying a tasks
528 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
530 TP_PROTO(struct task_struct
*tsk
, int newprio
),
532 TP_ARGS(tsk
, newprio
),
535 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
536 ctf_integer(pid_t
, tid
, tsk
->pid
)
537 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
538 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
543 #endif /* LTTNG_TRACE_SCHED_H */
545 /* This part must be outside protection */
546 #include <lttng/define_trace.h>
This page took 0.040908 seconds and 4 git commands to generate.