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(3,19,0))
29 static inline long __trace_sched_switch_state(struct task_struct
*p
)
31 long state
= p
->state
;
34 #ifdef CONFIG_SCHED_DEBUG
36 #endif /* CONFIG_SCHED_DEBUG */
38 * For all intents and purposes a preempted task is a running task.
40 if (preempt_count() & PREEMPT_ACTIVE
)
41 state
= TASK_RUNNING
| TASK_STATE_MAX
;
42 #endif /* CONFIG_PREEMPT */
47 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
49 static inline long __trace_sched_switch_state(struct task_struct
*p
)
51 long state
= p
->state
;
55 * For all intents and purposes a preempted task is a running task.
57 if (task_preempt_count(p
) & PREEMPT_ACTIVE
)
58 state
= TASK_RUNNING
| TASK_STATE_MAX
;
64 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
66 static inline long __trace_sched_switch_state(struct task_struct
*p
)
68 long state
= p
->state
;
72 * For all intents and purposes a preempted task is a running task.
74 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
75 state
= TASK_RUNNING
| TASK_STATE_MAX
;
81 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
83 static inline long __trace_sched_switch_state(struct task_struct
*p
)
85 long state
= p
->state
;
89 * For all intents and purposes a preempted task is a running task.
91 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
100 #endif /* _TRACE_SCHED_DEF_ */
103 * Tracepoint for calling kthread_stop, performed to end a kthread:
105 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
107 TP_PROTO(struct task_struct
*t
),
112 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
113 ctf_integer(pid_t
, tid
, t
->pid
)
118 * Tracepoint for the return value of the kthread stopping:
120 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
127 ctf_integer(int, ret
, ret
)
132 * Tracepoint for waking up a task:
134 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0))
135 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
137 TP_PROTO(struct task_struct
*p
),
142 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
143 ctf_integer(pid_t
, tid
, p
->pid
)
144 ctf_integer(int, prio
, p
->prio
)
145 ctf_integer(int, target_cpu
, task_cpu(p
))
148 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
149 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
151 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
152 TP_PROTO(struct task_struct
*p
, int success
),
156 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
158 TP_ARGS(rq
, p
, success
),
162 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
163 ctf_integer(pid_t
, tid
, p
->pid
)
164 ctf_integer(int, prio
, p
->prio
)
165 ctf_integer(int, success
, success
)
166 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
167 ctf_integer(int, target_cpu
, task_cpu(p
))
171 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
173 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0))
176 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
177 * called from the waking context.
179 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
180 TP_PROTO(struct task_struct
*p
),
184 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
185 * It it not always called from the waking context.
187 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
188 TP_PROTO(struct task_struct
*p
),
192 * Tracepoint for waking up a new task:
194 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
195 TP_PROTO(struct task_struct
*p
),
198 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
200 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
201 TP_PROTO(struct task_struct
*p
, int success
),
205 * Tracepoint for waking up a new task:
207 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
208 TP_PROTO(struct task_struct
*p
, int success
),
211 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
213 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
214 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
215 TP_ARGS(rq
, p
, success
))
218 * Tracepoint for waking up a new task:
220 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
221 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
222 TP_ARGS(rq
, p
, success
))
224 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
227 * Tracepoint for task switches, performed by the scheduler:
229 LTTNG_TRACEPOINT_EVENT(sched_switch
,
231 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
232 TP_PROTO(struct task_struct
*prev
,
233 struct task_struct
*next
),
236 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
237 TP_PROTO(struct rq
*rq
, struct task_struct
*prev
,
238 struct task_struct
*next
),
240 TP_ARGS(rq
, prev
, next
),
241 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
244 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
245 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
246 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
247 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
248 ctf_integer(long, prev_state
, __trace_sched_switch_state(prev
))
250 ctf_integer(long, prev_state
, prev
->state
)
252 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
253 ctf_integer(pid_t
, next_tid
, next
->pid
)
254 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
259 * Tracepoint for a task being migrated:
261 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
263 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
265 TP_ARGS(p
, dest_cpu
),
268 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
269 ctf_integer(pid_t
, tid
, p
->pid
)
270 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
271 ctf_integer(int, orig_cpu
, task_cpu(p
))
272 ctf_integer(int, dest_cpu
, dest_cpu
)
276 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
278 TP_PROTO(struct task_struct
*p
),
283 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
284 ctf_integer(pid_t
, tid
, p
->pid
)
285 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
290 * Tracepoint for freeing a task:
292 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
293 TP_PROTO(struct task_struct
*p
),
298 * Tracepoint for a task exiting:
300 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
301 TP_PROTO(struct task_struct
*p
),
305 * Tracepoint for waiting on task to unschedule:
307 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
308 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
309 TP_PROTO(struct task_struct
*p
),
311 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
312 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
313 TP_PROTO(struct rq
*rq
, struct task_struct
*p
),
315 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
318 * Tracepoint for a waiting task:
320 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
322 TP_PROTO(struct pid
*pid
),
327 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
328 ctf_integer(pid_t
, tid
, pid_nr(pid
))
329 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
334 * Tracepoint for do_fork.
335 * Saving both TID and PID information, especially for the child, allows
336 * trace analyzers to distinguish between creation of a new process and
337 * creation of a new thread. Newly created processes will have child_tid
338 * == child_pid, while creation of a thread yields to child_tid !=
341 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
343 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
345 TP_ARGS(parent
, child
),
348 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
349 unsigned int ns_level
;
354 struct pid
*child_pid
;
357 child_pid
= task_pid(child
);
358 tp_locvar
->ns_level
=
359 min_t(unsigned int, child_pid
->level
+ 1,
360 LTTNG_MAX_PID_NS_LEVEL
);
361 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
362 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
367 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
368 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
369 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
370 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
371 ctf_integer(unsigned int, parent_ns_inum
,
373 unsigned int parent_ns_inum
= 0;
376 struct pid_namespace
*pid_ns
;
378 pid_ns
= task_active_pid_ns(parent
);
381 pid_ns
->lttng_proc_inum
;
386 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
387 ctf_integer(pid_t
, child_tid
, child
->pid
)
388 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
389 ctf_integer(pid_t
, child_pid
, child
->tgid
)
390 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
391 ctf_integer(unsigned int, child_ns_inum
,
393 unsigned int child_ns_inum
= 0;
396 struct pid_namespace
*pid_ns
;
398 pid_ns
= task_active_pid_ns(child
);
401 pid_ns
->lttng_proc_inum
;
411 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
413 * Tracepoint for sending a signal:
415 LTTNG_TRACEPOINT_EVENT(sched_signal_send
,
417 TP_PROTO(int sig
, struct task_struct
*p
),
422 ctf_integer(int, sig
, sig
)
423 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
424 ctf_integer(pid_t
, tid
, p
->pid
)
429 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
431 * Tracepoint for exec:
433 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
435 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
436 struct linux_binprm
*bprm
),
438 TP_ARGS(p
, old_pid
, bprm
),
441 ctf_string(filename
, bprm
->filename
)
442 ctf_integer(pid_t
, tid
, p
->pid
)
443 ctf_integer(pid_t
, old_tid
, old_pid
)
448 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
450 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
451 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
453 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
455 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
460 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
461 ctf_integer(pid_t
, tid
, tsk
->pid
)
462 ctf_integer(u64
, delay
, delay
)
468 * Tracepoint for accounting wait time (time the task is runnable
469 * but not actually running due to scheduler contention).
471 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
472 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
476 * Tracepoint for accounting sleep time (time the task is not runnable,
477 * including iowait, see below).
479 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
480 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
484 * Tracepoint for accounting iowait time (time the task is not runnable
485 * due to waiting on IO to complete).
487 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
488 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
491 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
493 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
495 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
496 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
501 * Tracepoint for accounting runtime (time the task is executing
504 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
506 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
508 TP_ARGS(tsk
, runtime
, vruntime
),
511 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
512 ctf_integer(pid_t
, tid
, tsk
->pid
)
513 ctf_integer(u64
, runtime
, runtime
)
514 ctf_integer(u64
, vruntime
, vruntime
)
519 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
521 * Tracepoint for showing priority inheritance modifying a tasks
524 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
526 TP_PROTO(struct task_struct
*tsk
, int newprio
),
528 TP_ARGS(tsk
, newprio
),
531 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
532 ctf_integer(pid_t
, tid
, tsk
->pid
)
533 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
534 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
539 #endif /* LTTNG_TRACE_SCHED_H */
541 /* This part must be outside protection */
542 #include "../../../probes/define_trace.h"
This page took 0.043076 seconds and 5 git commands to generate.