4e829a33a7838685dbc78459980d88ee1be66c25
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_ */
117 * Tracepoint for calling kthread_stop, performed to end a kthread:
119 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
121 TP_PROTO(struct task_struct
*t
),
126 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
127 ctf_integer(pid_t
, tid
, t
->pid
)
132 * Tracepoint for the return value of the kthread stopping:
134 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
141 ctf_integer(int, ret
, ret
)
146 * Tracepoint for waking up a task:
148 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0))
149 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
151 TP_PROTO(struct task_struct
*p
),
156 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
157 ctf_integer(pid_t
, tid
, p
->pid
)
158 ctf_integer(int, prio
, p
->prio
)
159 ctf_integer(int, target_cpu
, task_cpu(p
))
162 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
163 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
165 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
166 TP_PROTO(struct task_struct
*p
, int success
),
170 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
172 TP_ARGS(rq
, p
, success
),
176 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
177 ctf_integer(pid_t
, tid
, p
->pid
)
178 ctf_integer(int, prio
, p
->prio
)
179 ctf_integer(int, success
, success
)
180 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
181 ctf_integer(int, target_cpu
, task_cpu(p
))
185 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
187 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0))
190 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
191 * called from the waking context.
193 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
194 TP_PROTO(struct task_struct
*p
),
198 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
199 * It it not always called from the waking context.
201 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
202 TP_PROTO(struct task_struct
*p
),
206 * Tracepoint for waking up a new task:
208 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
209 TP_PROTO(struct task_struct
*p
),
212 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
214 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
215 TP_PROTO(struct task_struct
*p
, int success
),
219 * Tracepoint for waking up a new task:
221 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
222 TP_PROTO(struct task_struct
*p
, int success
),
225 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
227 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
228 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
229 TP_ARGS(rq
, p
, success
))
232 * Tracepoint for waking up a new task:
234 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
235 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
236 TP_ARGS(rq
, p
, success
))
238 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
241 * Tracepoint for task switches, performed by the scheduler:
243 LTTNG_TRACEPOINT_EVENT(sched_switch
,
245 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
246 TP_PROTO(bool preempt
,
247 struct task_struct
*prev
,
248 struct task_struct
*next
),
250 TP_ARGS(preempt
, prev
, next
),
251 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
252 TP_PROTO(struct task_struct
*prev
,
253 struct task_struct
*next
),
256 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
257 TP_PROTO(struct rq
*rq
, struct task_struct
*prev
,
258 struct task_struct
*next
),
260 TP_ARGS(rq
, prev
, next
),
261 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
264 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
265 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
266 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
267 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
268 ctf_integer(long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
269 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
270 ctf_integer(long, prev_state
, __trace_sched_switch_state(prev
))
272 ctf_integer(long, prev_state
, prev
->state
)
274 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
275 ctf_integer(pid_t
, next_tid
, next
->pid
)
276 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
281 * Tracepoint for a task being migrated:
283 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
285 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
287 TP_ARGS(p
, dest_cpu
),
290 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
291 ctf_integer(pid_t
, tid
, p
->pid
)
292 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
293 ctf_integer(int, orig_cpu
, task_cpu(p
))
294 ctf_integer(int, dest_cpu
, dest_cpu
)
298 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
300 TP_PROTO(struct task_struct
*p
),
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
)
312 * Tracepoint for freeing a task:
314 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
315 TP_PROTO(struct task_struct
*p
),
320 * Tracepoint for a task exiting:
322 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
323 TP_PROTO(struct task_struct
*p
),
327 * Tracepoint for waiting on task to unschedule:
329 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
330 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
331 TP_PROTO(struct task_struct
*p
),
333 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
334 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
335 TP_PROTO(struct rq
*rq
, struct task_struct
*p
),
337 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
340 * Tracepoint for a waiting task:
342 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
344 TP_PROTO(struct pid
*pid
),
349 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
350 ctf_integer(pid_t
, tid
, pid_nr(pid
))
351 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
356 * Tracepoint for do_fork.
357 * Saving both TID and PID information, especially for the child, allows
358 * trace analyzers to distinguish between creation of a new process and
359 * creation of a new thread. Newly created processes will have child_tid
360 * == child_pid, while creation of a thread yields to child_tid !=
363 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
365 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
367 TP_ARGS(parent
, child
),
370 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
371 unsigned int ns_level
;
376 struct pid
*child_pid
;
379 child_pid
= task_pid(child
);
380 tp_locvar
->ns_level
=
381 min_t(unsigned int, child_pid
->level
+ 1,
382 LTTNG_MAX_PID_NS_LEVEL
);
383 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
384 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
389 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
390 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
391 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
392 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
393 ctf_integer(unsigned int, parent_ns_inum
,
395 unsigned int parent_ns_inum
= 0;
398 struct pid_namespace
*pid_ns
;
400 pid_ns
= task_active_pid_ns(parent
);
403 pid_ns
->lttng_proc_inum
;
408 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
409 ctf_integer(pid_t
, child_tid
, child
->pid
)
410 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
411 ctf_integer(pid_t
, child_pid
, child
->tgid
)
412 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
413 ctf_integer(unsigned int, child_ns_inum
,
415 unsigned int child_ns_inum
= 0;
418 struct pid_namespace
*pid_ns
;
420 pid_ns
= task_active_pid_ns(child
);
423 pid_ns
->lttng_proc_inum
;
433 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
435 * Tracepoint for sending a signal:
437 LTTNG_TRACEPOINT_EVENT(sched_signal_send
,
439 TP_PROTO(int sig
, struct task_struct
*p
),
444 ctf_integer(int, sig
, sig
)
445 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
446 ctf_integer(pid_t
, tid
, p
->pid
)
451 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
453 * Tracepoint for exec:
455 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
457 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
458 struct linux_binprm
*bprm
),
460 TP_ARGS(p
, old_pid
, bprm
),
463 ctf_string(filename
, bprm
->filename
)
464 ctf_integer(pid_t
, tid
, p
->pid
)
465 ctf_integer(pid_t
, old_tid
, old_pid
)
470 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
472 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
473 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
475 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
477 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
482 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
483 ctf_integer(pid_t
, tid
, tsk
->pid
)
484 ctf_integer(u64
, delay
, delay
)
490 * Tracepoint for accounting wait time (time the task is runnable
491 * but not actually running due to scheduler contention).
493 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
494 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
498 * Tracepoint for accounting sleep time (time the task is not runnable,
499 * including iowait, see below).
501 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
502 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
506 * Tracepoint for accounting iowait time (time the task is not runnable
507 * due to waiting on IO to complete).
509 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
510 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
513 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
515 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
517 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
518 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
523 * Tracepoint for accounting runtime (time the task is executing
526 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
528 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
530 TP_ARGS(tsk
, runtime
, vruntime
),
533 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
534 ctf_integer(pid_t
, tid
, tsk
->pid
)
535 ctf_integer(u64
, runtime
, runtime
)
536 ctf_integer(u64
, vruntime
, vruntime
)
541 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
543 * Tracepoint for showing priority inheritance modifying a tasks
546 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
548 TP_PROTO(struct task_struct
*tsk
, int newprio
),
550 TP_ARGS(tsk
, newprio
),
553 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
554 ctf_integer(pid_t
, tid
, tsk
->pid
)
555 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
556 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
561 #endif /* LTTNG_TRACE_SCHED_H */
563 /* This part must be outside protection */
564 #include "../../../probes/define_trace.h"
This page took 0.059431 seconds and 4 git commands to generate.