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/version.h>
13 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
14 #include <linux/sched/rt.h>
17 #define LTTNG_MAX_PID_NS_LEVEL 32
19 #ifndef _TRACE_SCHED_DEF_
20 #define _TRACE_SCHED_DEF_
22 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
24 static inline long __trace_sched_switch_state(bool preempt
, 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(p
);
47 return state
? (1 << (state
- 1)) : state
;
50 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,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 * __get_task_state() 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
= __get_task_state(p
);
75 return state
? (1 << (state
- 1)) : state
;
78 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
80 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
82 #ifdef CONFIG_SCHED_DEBUG
84 #endif /* CONFIG_SCHED_DEBUG */
86 * Preemption ignores task state, therefore preempted tasks are always RUNNING
87 * (we will not have dequeued if state != RUNNING).
89 return preempt
? TASK_RUNNING
| TASK_STATE_MAX
: p
->state
;
92 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
94 static inline long __trace_sched_switch_state(struct task_struct
*p
)
96 long state
= p
->state
;
99 #ifdef CONFIG_SCHED_DEBUG
100 BUG_ON(p
!= current
);
101 #endif /* CONFIG_SCHED_DEBUG */
103 * For all intents and purposes a preempted task is a running task.
105 if (preempt_count() & PREEMPT_ACTIVE
)
106 state
= TASK_RUNNING
| TASK_STATE_MAX
;
107 #endif /* CONFIG_PREEMPT */
112 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
114 static inline long __trace_sched_switch_state(struct task_struct
*p
)
116 long state
= p
->state
;
118 #ifdef CONFIG_PREEMPT
120 * For all intents and purposes a preempted task is a running task.
122 if (task_preempt_count(p
) & PREEMPT_ACTIVE
)
123 state
= TASK_RUNNING
| TASK_STATE_MAX
;
129 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
131 static inline long __trace_sched_switch_state(struct task_struct
*p
)
133 long state
= p
->state
;
135 #ifdef CONFIG_PREEMPT
137 * For all intents and purposes a preempted task is a running task.
139 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
140 state
= TASK_RUNNING
| TASK_STATE_MAX
;
148 static inline long __trace_sched_switch_state(struct task_struct
*p
)
150 long state
= p
->state
;
152 #ifdef CONFIG_PREEMPT
154 * For all intents and purposes a preempted task is a running task.
156 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
157 state
= TASK_RUNNING
;
165 #endif /* _TRACE_SCHED_DEF_ */
168 * Enumeration of the task state bitmask.
169 * Only bit flags are enumerated here, not composition of states.
171 LTTNG_TRACEPOINT_ENUM(task_state
,
173 ctf_enum_value("TASK_RUNNING", TASK_RUNNING
)
174 ctf_enum_value("TASK_INTERRUPTIBLE", TASK_INTERRUPTIBLE
)
175 ctf_enum_value("TASK_UNINTERRUPTIBLE", TASK_UNINTERRUPTIBLE
)
176 ctf_enum_value("TASK_STOPPED", __TASK_STOPPED
)
177 ctf_enum_value("TASK_TRACED", __TASK_TRACED
)
178 ctf_enum_value("EXIT_DEAD", EXIT_DEAD
)
179 ctf_enum_value("EXIT_ZOMBIE", EXIT_ZOMBIE
)
181 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
182 ctf_enum_value("TASK_PARKED", TASK_PARKED
)
183 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)) */
185 ctf_enum_value("TASK_DEAD", TASK_DEAD
)
186 ctf_enum_value("TASK_WAKEKILL", TASK_WAKEKILL
)
187 ctf_enum_value("TASK_WAKING", TASK_WAKING
)
189 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0))
190 ctf_enum_value("TASK_NOLOAD", TASK_NOLOAD
)
191 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
193 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0))
194 ctf_enum_value("TASK_NEW", TASK_NEW
)
195 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) */
197 ctf_enum_value("TASK_STATE_MAX", TASK_STATE_MAX
)
202 * Tracepoint for calling kthread_stop, performed to end a kthread:
204 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
206 TP_PROTO(struct task_struct
*t
),
211 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
212 ctf_integer(pid_t
, tid
, t
->pid
)
217 * Tracepoint for the return value of the kthread stopping:
219 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
226 ctf_integer(int, ret
, ret
)
231 * Tracepoint for waking up a task:
233 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
234 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
235 LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
236 LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
237 LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
238 LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
239 LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
240 LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
241 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
243 TP_PROTO(struct task_struct
*p
),
248 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
249 ctf_integer(pid_t
, tid
, p
->pid
)
250 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
251 ctf_integer(int, target_cpu
, task_cpu(p
))
254 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
255 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
257 TP_PROTO(struct task_struct
*p
, int success
),
262 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
263 ctf_integer(pid_t
, tid
, p
->pid
)
264 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
265 ctf_integer(int, success
, success
)
266 ctf_integer(int, target_cpu
, task_cpu(p
))
269 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
271 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
272 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
273 LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
274 LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
275 LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
276 LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
277 LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
278 LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
281 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
282 * called from the waking context.
284 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
285 TP_PROTO(struct task_struct
*p
),
289 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
290 * It it not always called from the waking context.
292 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
293 TP_PROTO(struct task_struct
*p
),
297 * Tracepoint for waking up a new task:
299 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
300 TP_PROTO(struct task_struct
*p
),
305 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
306 TP_PROTO(struct task_struct
*p
, int success
),
310 * Tracepoint for waking up a new task:
312 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
313 TP_PROTO(struct task_struct
*p
, int success
),
316 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
319 * Tracepoint for task switches, performed by the scheduler:
321 LTTNG_TRACEPOINT_EVENT(sched_switch
,
323 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
324 TP_PROTO(bool preempt
,
325 struct task_struct
*prev
,
326 struct task_struct
*next
),
328 TP_ARGS(preempt
, prev
, next
),
330 TP_PROTO(struct task_struct
*prev
,
331 struct task_struct
*next
),
334 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)) */
337 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
338 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
339 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
340 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
341 ctf_enum(task_state
, long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
343 ctf_enum(task_state
, long, prev_state
, __trace_sched_switch_state(prev
))
345 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
346 ctf_integer(pid_t
, next_tid
, next
->pid
)
347 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
352 * Tracepoint for a task being migrated:
354 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
356 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
358 TP_ARGS(p
, dest_cpu
),
361 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
362 ctf_integer(pid_t
, tid
, p
->pid
)
363 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
364 ctf_integer(int, orig_cpu
, task_cpu(p
))
365 ctf_integer(int, dest_cpu
, dest_cpu
)
369 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
371 TP_PROTO(struct task_struct
*p
),
376 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
377 ctf_integer(pid_t
, tid
, p
->pid
)
378 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
383 * Tracepoint for freeing a task:
385 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
386 TP_PROTO(struct task_struct
*p
),
391 * Tracepoint for a task exiting:
393 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
394 TP_PROTO(struct task_struct
*p
),
398 * Tracepoint for waiting on task to unschedule:
400 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
401 TP_PROTO(struct task_struct
*p
),
405 * Tracepoint for a waiting task:
407 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
409 TP_PROTO(struct pid
*pid
),
414 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
415 ctf_integer(pid_t
, tid
, pid_nr(pid
))
416 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
421 * Tracepoint for do_fork.
422 * Saving both TID and PID information, especially for the child, allows
423 * trace analyzers to distinguish between creation of a new process and
424 * creation of a new thread. Newly created processes will have child_tid
425 * == child_pid, while creation of a thread yields to child_tid !=
428 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
430 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
432 TP_ARGS(parent
, child
),
435 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
436 unsigned int ns_level
;
441 struct pid
*child_pid
;
444 child_pid
= task_pid(child
);
445 tp_locvar
->ns_level
=
446 min_t(unsigned int, child_pid
->level
+ 1,
447 LTTNG_MAX_PID_NS_LEVEL
);
448 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
449 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
454 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
455 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
456 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
457 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
458 ctf_integer(unsigned int, parent_ns_inum
,
460 unsigned int parent_ns_inum
= 0;
463 struct pid_namespace
*pid_ns
;
465 pid_ns
= task_active_pid_ns(parent
);
473 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
474 ctf_integer(pid_t
, child_tid
, child
->pid
)
475 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
476 ctf_integer(pid_t
, child_pid
, child
->tgid
)
477 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
478 ctf_integer(unsigned int, child_ns_inum
,
480 unsigned int child_ns_inum
= 0;
483 struct pid_namespace
*pid_ns
;
485 pid_ns
= task_active_pid_ns(child
);
498 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
500 * Tracepoint for exec:
502 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
504 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
505 struct linux_binprm
*bprm
),
507 TP_ARGS(p
, old_pid
, bprm
),
510 ctf_string(filename
, bprm
->filename
)
511 ctf_integer(pid_t
, tid
, p
->pid
)
512 ctf_integer(pid_t
, old_tid
, old_pid
)
518 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
519 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
521 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
523 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
528 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
529 ctf_integer(pid_t
, tid
, tsk
->pid
)
530 ctf_integer(u64
, delay
, delay
)
536 * Tracepoint for accounting wait time (time the task is runnable
537 * but not actually running due to scheduler contention).
539 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
540 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
544 * Tracepoint for accounting sleep time (time the task is not runnable,
545 * including iowait, see below).
547 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
548 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
552 * Tracepoint for accounting iowait time (time the task is not runnable
553 * due to waiting on IO to complete).
555 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
556 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
559 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
561 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
563 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
564 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
569 * Tracepoint for accounting runtime (time the task is executing
572 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
574 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
576 TP_ARGS(tsk
, runtime
, vruntime
),
579 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
580 ctf_integer(pid_t
, tid
, tsk
->pid
)
581 ctf_integer(u64
, runtime
, runtime
)
582 ctf_integer(u64
, vruntime
, vruntime
)
586 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) || \
587 LTTNG_RT_KERNEL_RANGE(4,9,27,18, 4,10,0,0) || \
588 LTTNG_RT_KERNEL_RANGE(4,11,5,1, 4,12,0,0))
590 * Tracepoint for showing priority inheritance modifying a tasks
593 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
595 TP_PROTO(struct task_struct
*tsk
, struct task_struct
*pi_task
),
597 TP_ARGS(tsk
, pi_task
),
600 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
601 ctf_integer(pid_t
, tid
, tsk
->pid
)
602 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
603 ctf_integer(int, newprio
, pi_task
? pi_task
->prio
- MAX_RT_PRIO
: tsk
->prio
- MAX_RT_PRIO
)
608 * Tracepoint for showing priority inheritance modifying a tasks
611 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
613 TP_PROTO(struct task_struct
*tsk
, int newprio
),
615 TP_ARGS(tsk
, newprio
),
618 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
619 ctf_integer(pid_t
, tid
, tsk
->pid
)
620 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
621 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
626 #endif /* LTTNG_TRACE_SCHED_H */
628 /* This part must be outside protection */
629 #include <probes/define_trace.h>
This page took 0.044899 seconds and 5 git commands to generate.