1 /* SPDX-License-Identifier: GPL-2.0 */
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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
18 #define lttng_proc_inum ns.inum
20 #define lttng_proc_inum proc_inum
23 #define LTTNG_MAX_PID_NS_LEVEL 32
25 #ifndef _TRACE_SCHED_DEF_
26 #define _TRACE_SCHED_DEF_
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
30 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
32 #ifdef CONFIG_SCHED_DEBUG
34 #endif /* CONFIG_SCHED_DEBUG */
36 * Preemption ignores task state, therefore preempted tasks are always RUNNING
37 * (we will not have dequeued if state != RUNNING).
39 return preempt
? TASK_RUNNING
| TASK_STATE_MAX
: p
->state
;
42 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
44 static inline long __trace_sched_switch_state(struct task_struct
*p
)
46 long state
= p
->state
;
49 #ifdef CONFIG_SCHED_DEBUG
51 #endif /* CONFIG_SCHED_DEBUG */
53 * For all intents and purposes a preempted task is a running task.
55 if (preempt_count() & PREEMPT_ACTIVE
)
56 state
= TASK_RUNNING
| TASK_STATE_MAX
;
57 #endif /* CONFIG_PREEMPT */
62 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
64 static inline long __trace_sched_switch_state(struct task_struct
*p
)
66 long state
= p
->state
;
70 * For all intents and purposes a preempted task is a running task.
72 if (task_preempt_count(p
) & PREEMPT_ACTIVE
)
73 state
= TASK_RUNNING
| TASK_STATE_MAX
;
79 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
81 static inline long __trace_sched_switch_state(struct task_struct
*p
)
83 long state
= p
->state
;
87 * For all intents and purposes a preempted task is a running task.
89 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
90 state
= TASK_RUNNING
| TASK_STATE_MAX
;
96 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
98 static inline long __trace_sched_switch_state(struct task_struct
*p
)
100 long state
= p
->state
;
102 #ifdef CONFIG_PREEMPT
104 * For all intents and purposes a preempted task is a running task.
106 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
107 state
= TASK_RUNNING
;
115 #endif /* _TRACE_SCHED_DEF_ */
118 * Tracepoint for calling kthread_stop, performed to end a kthread:
120 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
122 TP_PROTO(struct task_struct
*t
),
127 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
128 ctf_integer(pid_t
, tid
, t
->pid
)
133 * Tracepoint for the return value of the kthread stopping:
135 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
142 ctf_integer(int, ret
, ret
)
147 * Tracepoint for waking up a task:
149 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
150 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
151 LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
152 LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
153 LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
154 LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
155 LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
156 LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
157 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
159 TP_PROTO(struct task_struct
*p
),
164 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
165 ctf_integer(pid_t
, tid
, p
->pid
)
166 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
167 ctf_integer(int, target_cpu
, task_cpu(p
))
170 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
171 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
173 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
174 TP_PROTO(struct task_struct
*p
, int success
),
178 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
180 TP_ARGS(rq
, p
, success
),
184 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
185 ctf_integer(pid_t
, tid
, p
->pid
)
186 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
187 ctf_integer(int, success
, success
)
188 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
189 ctf_integer(int, target_cpu
, task_cpu(p
))
193 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
195 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
196 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
197 LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
198 LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
199 LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
200 LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
201 LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
202 LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
205 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
206 * called from the waking context.
208 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
209 TP_PROTO(struct task_struct
*p
),
213 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
214 * It it not always called from the waking context.
216 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
217 TP_PROTO(struct task_struct
*p
),
221 * Tracepoint for waking up a new task:
223 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
224 TP_PROTO(struct task_struct
*p
),
227 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
229 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
230 TP_PROTO(struct task_struct
*p
, int success
),
234 * Tracepoint for waking up a new task:
236 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
237 TP_PROTO(struct task_struct
*p
, int success
),
240 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
242 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
243 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
244 TP_ARGS(rq
, p
, success
))
247 * Tracepoint for waking up a new task:
249 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
250 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
251 TP_ARGS(rq
, p
, success
))
253 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
256 * Tracepoint for task switches, performed by the scheduler:
258 LTTNG_TRACEPOINT_EVENT(sched_switch
,
260 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
261 TP_PROTO(bool preempt
,
262 struct task_struct
*prev
,
263 struct task_struct
*next
),
265 TP_ARGS(preempt
, prev
, next
),
266 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
267 TP_PROTO(struct task_struct
*prev
,
268 struct task_struct
*next
),
271 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
272 TP_PROTO(struct rq
*rq
, struct task_struct
*prev
,
273 struct task_struct
*next
),
275 TP_ARGS(rq
, prev
, next
),
276 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
279 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
280 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
281 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
282 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
283 ctf_integer(long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
284 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
285 ctf_integer(long, prev_state
, __trace_sched_switch_state(prev
))
287 ctf_integer(long, prev_state
, prev
->state
)
289 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
290 ctf_integer(pid_t
, next_tid
, next
->pid
)
291 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
296 * Tracepoint for a task being migrated:
298 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
300 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
302 TP_ARGS(p
, dest_cpu
),
305 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
306 ctf_integer(pid_t
, tid
, p
->pid
)
307 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
308 ctf_integer(int, orig_cpu
, task_cpu(p
))
309 ctf_integer(int, dest_cpu
, dest_cpu
)
313 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
315 TP_PROTO(struct task_struct
*p
),
320 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
321 ctf_integer(pid_t
, tid
, p
->pid
)
322 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
327 * Tracepoint for freeing a task:
329 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
330 TP_PROTO(struct task_struct
*p
),
335 * Tracepoint for a task exiting:
337 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
338 TP_PROTO(struct task_struct
*p
),
342 * Tracepoint for waiting on task to unschedule:
344 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
345 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
346 TP_PROTO(struct task_struct
*p
),
348 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
349 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
350 TP_PROTO(struct rq
*rq
, struct task_struct
*p
),
352 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
355 * Tracepoint for a waiting task:
357 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
359 TP_PROTO(struct pid
*pid
),
364 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
365 ctf_integer(pid_t
, tid
, pid_nr(pid
))
366 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
371 * Tracepoint for do_fork.
372 * Saving both TID and PID information, especially for the child, allows
373 * trace analyzers to distinguish between creation of a new process and
374 * creation of a new thread. Newly created processes will have child_tid
375 * == child_pid, while creation of a thread yields to child_tid !=
378 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
380 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
382 TP_ARGS(parent
, child
),
385 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
386 unsigned int ns_level
;
391 struct pid
*child_pid
;
394 child_pid
= task_pid(child
);
395 tp_locvar
->ns_level
=
396 min_t(unsigned int, child_pid
->level
+ 1,
397 LTTNG_MAX_PID_NS_LEVEL
);
398 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
399 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
404 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
405 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
406 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
407 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
408 ctf_integer(unsigned int, parent_ns_inum
,
410 unsigned int parent_ns_inum
= 0;
413 struct pid_namespace
*pid_ns
;
415 pid_ns
= task_active_pid_ns(parent
);
418 pid_ns
->lttng_proc_inum
;
423 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
424 ctf_integer(pid_t
, child_tid
, child
->pid
)
425 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
426 ctf_integer(pid_t
, child_pid
, child
->tgid
)
427 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
428 ctf_integer(unsigned int, child_ns_inum
,
430 unsigned int child_ns_inum
= 0;
433 struct pid_namespace
*pid_ns
;
435 pid_ns
= task_active_pid_ns(child
);
438 pid_ns
->lttng_proc_inum
;
448 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
450 * Tracepoint for sending a signal:
452 LTTNG_TRACEPOINT_EVENT(sched_signal_send
,
454 TP_PROTO(int sig
, struct task_struct
*p
),
459 ctf_integer(int, sig
, sig
)
460 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
461 ctf_integer(pid_t
, tid
, p
->pid
)
466 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
468 * Tracepoint for exec:
470 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
472 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
473 struct linux_binprm
*bprm
),
475 TP_ARGS(p
, old_pid
, bprm
),
478 ctf_string(filename
, bprm
->filename
)
479 ctf_integer(pid_t
, tid
, p
->pid
)
480 ctf_integer(pid_t
, old_tid
, old_pid
)
485 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
487 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
488 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
490 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
492 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
497 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
498 ctf_integer(pid_t
, tid
, tsk
->pid
)
499 ctf_integer(u64
, delay
, delay
)
505 * Tracepoint for accounting wait time (time the task is runnable
506 * but not actually running due to scheduler contention).
508 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
509 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
513 * Tracepoint for accounting sleep time (time the task is not runnable,
514 * including iowait, see below).
516 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
517 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
521 * Tracepoint for accounting iowait time (time the task is not runnable
522 * due to waiting on IO to complete).
524 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
525 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
528 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
530 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
532 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
533 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
538 * Tracepoint for accounting runtime (time the task is executing
541 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
543 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
545 TP_ARGS(tsk
, runtime
, vruntime
),
548 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
549 ctf_integer(pid_t
, tid
, tsk
->pid
)
550 ctf_integer(u64
, runtime
, runtime
)
551 ctf_integer(u64
, vruntime
, vruntime
)
556 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) || \
557 LTTNG_RT_KERNEL_RANGE(4,9,27,18, 4,10,0,0) || \
558 LTTNG_RT_KERNEL_RANGE(4,11,5,1, 4,12,0,0))
560 * Tracepoint for showing priority inheritance modifying a tasks
563 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
565 TP_PROTO(struct task_struct
*tsk
, struct task_struct
*pi_task
),
567 TP_ARGS(tsk
, pi_task
),
570 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
571 ctf_integer(pid_t
, tid
, tsk
->pid
)
572 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
573 ctf_integer(int, newprio
, pi_task
? pi_task
->prio
- MAX_RT_PRIO
: tsk
->prio
- MAX_RT_PRIO
)
576 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
578 * Tracepoint for showing priority inheritance modifying a tasks
581 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
583 TP_PROTO(struct task_struct
*tsk
, int newprio
),
585 TP_ARGS(tsk
, newprio
),
588 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
589 ctf_integer(pid_t
, tid
, tsk
->pid
)
590 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
591 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
596 #endif /* LTTNG_TRACE_SCHED_H */
598 /* This part must be outside protection */
599 #include <probes/define_trace.h>
This page took 0.077779 seconds and 4 git commands to generate.