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/pid_namespace.h>
10 #include <linux/binfmts.h>
11 #include <linux/version.h>
12 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
13 #include <linux/sched/rt.h>
16 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
17 #define lttng_proc_inum ns.inum
19 #define lttng_proc_inum proc_inum
22 #define LTTNG_MAX_PID_NS_LEVEL 32
24 #ifndef _TRACE_SCHED_DEF_
25 #define _TRACE_SCHED_DEF_
27 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
29 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
31 #ifdef CONFIG_SCHED_DEBUG
33 #endif /* CONFIG_SCHED_DEBUG */
35 * Preemption ignores task state, therefore preempted tasks are always RUNNING
36 * (we will not have dequeued if state != RUNNING).
38 return preempt
? TASK_RUNNING
| TASK_STATE_MAX
: p
->state
;
41 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
43 static inline long __trace_sched_switch_state(struct task_struct
*p
)
45 long state
= p
->state
;
48 #ifdef CONFIG_SCHED_DEBUG
50 #endif /* CONFIG_SCHED_DEBUG */
52 * For all intents and purposes a preempted task is a running task.
54 if (preempt_count() & PREEMPT_ACTIVE
)
55 state
= TASK_RUNNING
| TASK_STATE_MAX
;
56 #endif /* CONFIG_PREEMPT */
61 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
63 static inline long __trace_sched_switch_state(struct task_struct
*p
)
65 long state
= p
->state
;
69 * For all intents and purposes a preempted task is a running task.
71 if (task_preempt_count(p
) & PREEMPT_ACTIVE
)
72 state
= TASK_RUNNING
| TASK_STATE_MAX
;
78 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
80 static inline long __trace_sched_switch_state(struct task_struct
*p
)
82 long state
= p
->state
;
86 * For all intents and purposes a preempted task is a running task.
88 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
89 state
= TASK_RUNNING
| TASK_STATE_MAX
;
95 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
97 static inline long __trace_sched_switch_state(struct task_struct
*p
)
99 long state
= p
->state
;
101 #ifdef CONFIG_PREEMPT
103 * For all intents and purposes a preempted task is a running task.
105 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
106 state
= TASK_RUNNING
;
114 #endif /* _TRACE_SCHED_DEF_ */
116 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0))
117 LTTNG_TRACEPOINT_ENUM(lttng_sched_policy
,
119 ctf_enum_value("SCHED_NORMAL", SCHED_NORMAL
)
120 ctf_enum_value("SCHED_FIFO", SCHED_FIFO
)
121 ctf_enum_value("SCHED_RR", SCHED_RR
)
122 ctf_enum_value("SCHED_BATCH", SCHED_BATCH
)
123 ctf_enum_value("SCHED_IDLE", SCHED_IDLE
)
124 ctf_enum_value("SCHED_DEADLINE", SCHED_DEADLINE
)
130 * Tracepoint for calling kthread_stop, performed to end a kthread:
132 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
134 TP_PROTO(struct task_struct
*t
),
139 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
140 ctf_integer(pid_t
, tid
, t
->pid
)
145 * Tracepoint for the return value of the kthread stopping:
147 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
154 ctf_integer(int, ret
, ret
)
159 * Tracepoint for waking up a task:
161 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
162 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0))
163 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
165 TP_PROTO(struct task_struct
*p
),
170 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
171 ctf_integer(pid_t
, tid
, p
->pid
)
172 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
173 ctf_integer(int, target_cpu
, task_cpu(p
))
176 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
177 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
179 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
180 TP_PROTO(struct task_struct
*p
, int success
),
184 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
186 TP_ARGS(rq
, p
, success
),
190 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
191 ctf_integer(pid_t
, tid
, p
->pid
)
192 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
193 ctf_integer(int, success
, success
)
194 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
195 ctf_integer(int, target_cpu
, task_cpu(p
))
199 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
201 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
202 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,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
;
443 ctf_integer(int, prio
, child
->prio
- MAX_RT_PRIO
)
444 ctf_enum(lttng_sched_policy
, unsigned int, policy
, child
->policy
)
445 ctf_integer(int, nice
, task_nice(child
))
446 ctf_integer(unsigned int, rt_priority
, child
->rt_priority
)
447 ctf_integer(u64
, dl_runtime
, child
->dl
.dl_runtime
)
448 ctf_integer(u64
, dl_deadline
, child
->dl
.dl_deadline
)
449 ctf_integer(u64
, dl_period
, child
->dl
.dl_period
)
455 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
457 * Tracepoint for sending a signal:
459 LTTNG_TRACEPOINT_EVENT(sched_signal_send
,
461 TP_PROTO(int sig
, struct task_struct
*p
),
466 ctf_integer(int, sig
, sig
)
467 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
468 ctf_integer(pid_t
, tid
, p
->pid
)
473 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
475 * Tracepoint for exec:
477 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
479 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
480 struct linux_binprm
*bprm
),
482 TP_ARGS(p
, old_pid
, bprm
),
485 ctf_string(filename
, bprm
->filename
)
486 ctf_integer(pid_t
, tid
, p
->pid
)
487 ctf_integer(pid_t
, old_tid
, old_pid
)
492 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
494 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
495 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
497 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
499 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
504 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
505 ctf_integer(pid_t
, tid
, tsk
->pid
)
506 ctf_integer(u64
, delay
, delay
)
512 * Tracepoint for accounting wait time (time the task is runnable
513 * but not actually running due to scheduler contention).
515 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
516 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
520 * Tracepoint for accounting sleep time (time the task is not runnable,
521 * including iowait, see below).
523 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
524 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
528 * Tracepoint for accounting iowait time (time the task is not runnable
529 * due to waiting on IO to complete).
531 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
532 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
535 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
537 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
539 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
540 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
545 * Tracepoint for accounting runtime (time the task is executing
548 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
550 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
552 TP_ARGS(tsk
, runtime
, vruntime
),
555 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
556 ctf_integer(pid_t
, tid
, tsk
->pid
)
557 ctf_integer(u64
, runtime
, runtime
)
558 ctf_integer(u64
, vruntime
, vruntime
)
563 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
565 * Tracepoint for showing priority inheritance modifying a tasks
568 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
570 TP_PROTO(struct task_struct
*tsk
, int newprio
),
572 TP_ARGS(tsk
, newprio
),
575 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
576 ctf_integer(pid_t
, tid
, tsk
->pid
)
577 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
578 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
583 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0))
585 * Tracepoint for priority changes of a task.
587 LTTNG_TRACEPOINT_EVENT(sched_update_prio
,
589 TP_PROTO(struct task_struct
*tsk
),
594 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
595 ctf_integer(pid_t
, tid
, tsk
->pid
)
596 ctf_integer(int, prio
, tsk
->prio
- MAX_RT_PRIO
)
597 ctf_enum(lttng_sched_policy
, unsigned int, policy
, tsk
->policy
)
598 ctf_integer(int, nice
, task_nice(tsk
))
599 ctf_integer(unsigned int, rt_priority
, tsk
->rt_priority
)
600 ctf_integer(u64
, dl_runtime
, tsk
->dl
.dl_runtime
)
601 ctf_integer(u64
, dl_deadline
, tsk
->dl
.dl_deadline
)
602 ctf_integer(u64
, dl_period
, tsk
->dl
.dl_period
)
607 #endif /* LTTNG_TRACE_SCHED_H */
609 /* This part must be outside protection */
610 #include <probes/define_trace.h>
This page took 0.044044 seconds and 5 git commands to generate.