2 #define TRACE_SYSTEM sched
4 #if !defined(LTTNG_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define LTTNG_TRACE_SCHED_H
7 #include "../../../probes/lttng-tracepoint-event.h"
8 #include <linux/sched.h>
9 #include <linux/binfmts.h>
10 #include <linux/version.h>
11 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
12 #include <linux/sched/rt.h>
15 #ifndef _TRACE_SCHED_DEF_
16 #define _TRACE_SCHED_DEF_
18 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
20 static inline long __trace_sched_switch_state(struct task_struct
*p
)
22 long state
= p
->state
;
25 #ifdef CONFIG_SCHED_DEBUG
27 #endif /* CONFIG_SCHED_DEBUG */
29 * For all intents and purposes a preempted task is a running task.
31 if (preempt_count() & PREEMPT_ACTIVE
)
32 state
= TASK_RUNNING
| TASK_STATE_MAX
;
33 #endif /* CONFIG_PREEMPT */
38 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
40 static inline long __trace_sched_switch_state(struct task_struct
*p
)
42 long state
= p
->state
;
46 * For all intents and purposes a preempted task is a running task.
48 if (task_preempt_count(p
) & PREEMPT_ACTIVE
)
49 state
= TASK_RUNNING
| TASK_STATE_MAX
;
55 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
57 static inline long __trace_sched_switch_state(struct task_struct
*p
)
59 long state
= p
->state
;
63 * For all intents and purposes a preempted task is a running task.
65 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
66 state
= TASK_RUNNING
| TASK_STATE_MAX
;
72 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
74 static inline long __trace_sched_switch_state(struct task_struct
*p
)
76 long state
= p
->state
;
80 * For all intents and purposes a preempted task is a running task.
82 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
91 #endif /* _TRACE_SCHED_DEF_ */
94 * Tracepoint for calling kthread_stop, performed to end a kthread:
96 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
98 TP_PROTO(struct task_struct
*t
),
103 __array_text( char, comm
, TASK_COMM_LEN
)
104 __field( pid_t
, tid
)
108 tp_memcpy(comm
, t
->comm
, TASK_COMM_LEN
)
109 tp_assign(tid
, t
->pid
)
112 TP_printk("comm=%s tid=%d", __entry
->comm
, __entry
->tid
)
116 * Tracepoint for the return value of the kthread stopping:
118 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
132 TP_printk("ret=%d", __entry
->ret
)
136 * Tracepoint for waking up a task:
138 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0))
139 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
141 TP_PROTO(struct task_struct
*p
),
146 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
147 ctf_integer(pid_t
, tid
, p
->pid
)
148 ctf_integer(int, prio
, p
->prio
)
149 ctf_integer(int, target_cpu
, task_cpu(p
))
152 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
153 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
155 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
156 TP_PROTO(struct task_struct
*p
, int success
),
160 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
162 TP_ARGS(rq
, p
, success
),
166 __array_text( char, comm
, TASK_COMM_LEN
)
167 __field( pid_t
, tid
)
169 __field( int, success
)
170 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
171 __field( int, target_cpu
)
176 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
177 tp_assign(tid
, p
->pid
)
178 tp_assign(prio
, p
->prio
)
179 tp_assign(success
, success
)
180 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
181 tp_assign(target_cpu
, task_cpu(p
))
183 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
190 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
191 TP_printk("comm=%s tid=%d prio=%d success=%d target_cpu=%03d",
192 __entry
->comm
, __entry
->tid
, __entry
->prio
,
193 __entry
->success
, __entry
->target_cpu
)
195 TP_printk("comm=%s tid=%d prio=%d success=%d",
196 __entry
->comm
, __entry
->tid
, __entry
->prio
,
200 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
202 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,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(2,6,35))
261 TP_PROTO(struct task_struct
*prev
,
262 struct task_struct
*next
),
265 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
266 TP_PROTO(struct rq
*rq
, struct task_struct
*prev
,
267 struct task_struct
*next
),
269 TP_ARGS(rq
, prev
, next
),
270 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
273 __array_text( char, prev_comm
, TASK_COMM_LEN
)
274 __field( pid_t
, prev_tid
)
275 __field( int, prev_prio
)
276 __field( long, prev_state
)
277 __array_text( char, next_comm
, TASK_COMM_LEN
)
278 __field( pid_t
, next_tid
)
279 __field( int, next_prio
)
283 tp_memcpy(next_comm
, next
->comm
, TASK_COMM_LEN
)
284 tp_assign(prev_tid
, prev
->pid
)
285 tp_assign(prev_prio
, prev
->prio
- MAX_RT_PRIO
)
286 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
287 tp_assign(prev_state
, __trace_sched_switch_state(prev
))
289 tp_assign(prev_state
, prev
->state
)
291 tp_memcpy(prev_comm
, prev
->comm
, TASK_COMM_LEN
)
292 tp_assign(next_tid
, next
->pid
)
293 tp_assign(next_prio
, next
->prio
- MAX_RT_PRIO
)
296 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
297 TP_printk("prev_comm=%s prev_tid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_tid=%d next_prio=%d",
298 __entry
->prev_comm
, __entry
->prev_tid
, __entry
->prev_prio
,
299 __entry
->prev_state
& (TASK_STATE_MAX
-1) ?
300 __print_flags(__entry
->prev_state
& (TASK_STATE_MAX
-1), "|",
301 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
302 { 16, "Z" }, { 32, "X" }, { 64, "x" },
304 __entry
->prev_state
& TASK_STATE_MAX
? "+" : "",
305 __entry
->next_comm
, __entry
->next_tid
, __entry
->next_prio
)
307 TP_printk("prev_comm=%s prev_tid=%d prev_prio=%d prev_state=%s ==> next_comm=%s next_tid=%d next_prio=%d",
308 __entry
->prev_comm
, __entry
->prev_tid
, __entry
->prev_prio
,
309 __entry
->prev_state
?
310 __print_flags(__entry
->prev_state
, "|",
311 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
312 { 16, "Z" }, { 32, "X" }, { 64, "x" },
314 __entry
->next_comm
, __entry
->next_tid
, __entry
->next_prio
)
319 * Tracepoint for a task being migrated:
321 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
323 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
325 TP_ARGS(p
, dest_cpu
),
328 __array_text( char, comm
, TASK_COMM_LEN
)
329 __field( pid_t
, tid
)
331 __field( int, orig_cpu
)
332 __field( int, dest_cpu
)
336 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
337 tp_assign(tid
, p
->pid
)
338 tp_assign(prio
, p
->prio
- MAX_RT_PRIO
)
339 tp_assign(orig_cpu
, task_cpu(p
))
340 tp_assign(dest_cpu
, dest_cpu
)
343 TP_printk("comm=%s tid=%d prio=%d orig_cpu=%d dest_cpu=%d",
344 __entry
->comm
, __entry
->tid
, __entry
->prio
,
345 __entry
->orig_cpu
, __entry
->dest_cpu
)
348 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
350 TP_PROTO(struct task_struct
*p
),
355 __array_text( char, comm
, TASK_COMM_LEN
)
356 __field( pid_t
, tid
)
361 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
362 tp_assign(tid
, p
->pid
)
363 tp_assign(prio
, p
->prio
- MAX_RT_PRIO
)
366 TP_printk("comm=%s tid=%d prio=%d",
367 __entry
->comm
, __entry
->tid
, __entry
->prio
)
371 * Tracepoint for freeing a task:
373 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
374 TP_PROTO(struct task_struct
*p
),
379 * Tracepoint for a task exiting:
381 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
382 TP_PROTO(struct task_struct
*p
),
386 * Tracepoint for waiting on task to unschedule:
388 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
389 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
390 TP_PROTO(struct task_struct
*p
),
392 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
393 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
394 TP_PROTO(struct rq
*rq
, struct task_struct
*p
),
396 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
399 * Tracepoint for a waiting task:
401 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
403 TP_PROTO(struct pid
*pid
),
408 __array_text( char, comm
, TASK_COMM_LEN
)
409 __field( pid_t
, tid
)
414 tp_memcpy(comm
, current
->comm
, TASK_COMM_LEN
)
415 tp_assign(tid
, pid_nr(pid
))
416 tp_assign(prio
, current
->prio
- MAX_RT_PRIO
)
419 TP_printk("comm=%s tid=%d prio=%d",
420 __entry
->comm
, __entry
->tid
, __entry
->prio
)
424 * Tracepoint for do_fork.
425 * Saving both TID and PID information, especially for the child, allows
426 * trace analyzers to distinguish between creation of a new process and
427 * creation of a new thread. Newly created processes will have child_tid
428 * == child_pid, while creation of a thread yields to child_tid !=
431 LTTNG_TRACEPOINT_EVENT(sched_process_fork
,
433 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
435 TP_ARGS(parent
, child
),
438 __array_text( char, parent_comm
, TASK_COMM_LEN
)
439 __field( pid_t
, parent_tid
)
440 __field( pid_t
, parent_pid
)
441 __array_text( char, child_comm
, TASK_COMM_LEN
)
442 __field( pid_t
, child_tid
)
443 __field( pid_t
, child_pid
)
447 tp_memcpy(parent_comm
, parent
->comm
, TASK_COMM_LEN
)
448 tp_assign(parent_tid
, parent
->pid
)
449 tp_assign(parent_pid
, parent
->tgid
)
450 tp_memcpy(child_comm
, child
->comm
, TASK_COMM_LEN
)
451 tp_assign(child_tid
, child
->pid
)
452 tp_assign(child_pid
, child
->tgid
)
455 TP_printk("comm=%s tid=%d child_comm=%s child_tid=%d",
456 __entry
->parent_comm
, __entry
->parent_tid
,
457 __entry
->child_comm
, __entry
->child_tid
)
460 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
462 * Tracepoint for sending a signal:
464 LTTNG_TRACEPOINT_EVENT(sched_signal_send
,
466 TP_PROTO(int sig
, struct task_struct
*p
),
472 __array( char, comm
, TASK_COMM_LEN
)
473 __field( pid_t
, pid
)
477 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
478 tp_assign(pid
, p
->pid
)
482 TP_printk("sig=%d comm=%s pid=%d",
483 __entry
->sig
, __entry
->comm
, __entry
->pid
)
487 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
489 * Tracepoint for exec:
491 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
493 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
494 struct linux_binprm
*bprm
),
496 TP_ARGS(p
, old_pid
, bprm
),
499 __string( filename
, bprm
->filename
)
500 __field( pid_t
, tid
)
501 __field( pid_t
, old_tid
)
505 tp_strcpy(filename
, bprm
->filename
)
506 tp_assign(tid
, p
->pid
)
507 tp_assign(old_tid
, old_pid
)
510 TP_printk("filename=%s tid=%d old_tid=%d", __get_str(filename
),
511 __entry
->tid
, __entry
->old_tid
)
515 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
517 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
518 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
520 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
522 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
527 __array_text( char, comm
, TASK_COMM_LEN
)
528 __field( pid_t
, tid
)
529 __field( u64
, delay
)
533 tp_memcpy(comm
, tsk
->comm
, TASK_COMM_LEN
)
534 tp_assign(tid
, tsk
->pid
)
535 tp_assign(delay
, delay
)
541 TP_printk("comm=%s tid=%d delay=%Lu [ns]",
542 __entry
->comm
, __entry
->tid
,
543 (unsigned long long)__entry
->delay
)
548 * Tracepoint for accounting wait time (time the task is runnable
549 * but not actually running due to scheduler contention).
551 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
552 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
556 * Tracepoint for accounting sleep time (time the task is not runnable,
557 * including iowait, see below).
559 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
560 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
564 * Tracepoint for accounting iowait time (time the task is not runnable
565 * due to waiting on IO to complete).
567 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
568 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
571 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
573 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
575 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
576 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
581 * Tracepoint for accounting runtime (time the task is executing
584 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
586 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
588 TP_ARGS(tsk
, runtime
, vruntime
),
591 __array_text( char, comm
, TASK_COMM_LEN
)
592 __field( pid_t
, tid
)
593 __field( u64
, runtime
)
594 __field( u64
, vruntime
)
598 tp_memcpy(comm
, tsk
->comm
, TASK_COMM_LEN
)
599 tp_assign(tid
, tsk
->pid
)
600 tp_assign(runtime
, runtime
)
601 tp_assign(vruntime
, vruntime
)
604 __perf_count(runtime
)
605 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
610 TP_printk("comm=%s tid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
611 __entry
->comm
, __entry
->tid
,
612 (unsigned long long)__entry
->runtime
,
613 (unsigned long long)__entry
->vruntime
)
617 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
619 * Tracepoint for showing priority inheritance modifying a tasks
622 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
624 TP_PROTO(struct task_struct
*tsk
, int newprio
),
626 TP_ARGS(tsk
, newprio
),
629 __array_text( char, comm
, TASK_COMM_LEN
)
630 __field( pid_t
, tid
)
631 __field( int, oldprio
)
632 __field( int, newprio
)
636 tp_memcpy(comm
, tsk
->comm
, TASK_COMM_LEN
)
637 tp_assign(tid
, tsk
->pid
)
638 tp_assign(oldprio
, tsk
->prio
- MAX_RT_PRIO
)
639 tp_assign(newprio
, newprio
- MAX_RT_PRIO
)
642 TP_printk("comm=%s tid=%d oldprio=%d newprio=%d",
643 __entry
->comm
, __entry
->tid
,
644 __entry
->oldprio
, __entry
->newprio
)
648 #endif /* LTTNG_TRACE_SCHED_H */
650 /* This part must be outside protection */
651 #include "../../../probes/define_trace.h"
This page took 0.043559 seconds and 5 git commands to generate.