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>
16 #include <wrapper/namespace.h>
18 #define LTTNG_MAX_PID_NS_LEVEL 32
20 #ifndef _TRACE_SCHED_DEF_
21 #define _TRACE_SCHED_DEF_
23 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
25 static inline long __trace_sched_switch_state(bool preempt
, struct task_struct
*p
)
27 #ifdef CONFIG_SCHED_DEBUG
29 #endif /* CONFIG_SCHED_DEBUG */
31 * Preemption ignores task state, therefore preempted tasks are always RUNNING
32 * (we will not have dequeued if state != RUNNING).
34 return preempt
? TASK_RUNNING
| TASK_STATE_MAX
: p
->state
;
37 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
39 static inline long __trace_sched_switch_state(struct task_struct
*p
)
41 long state
= p
->state
;
44 #ifdef CONFIG_SCHED_DEBUG
46 #endif /* CONFIG_SCHED_DEBUG */
48 * For all intents and purposes a preempted task is a running task.
50 if (preempt_count() & PREEMPT_ACTIVE
)
51 state
= TASK_RUNNING
| TASK_STATE_MAX
;
52 #endif /* CONFIG_PREEMPT */
57 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
59 static inline long __trace_sched_switch_state(struct task_struct
*p
)
61 long state
= p
->state
;
65 * For all intents and purposes a preempted task is a running task.
67 if (task_preempt_count(p
) & PREEMPT_ACTIVE
)
68 state
= TASK_RUNNING
| TASK_STATE_MAX
;
74 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
76 static inline long __trace_sched_switch_state(struct task_struct
*p
)
78 long state
= p
->state
;
82 * For all intents and purposes a preempted task is a running task.
84 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
85 state
= TASK_RUNNING
| TASK_STATE_MAX
;
93 static inline long __trace_sched_switch_state(struct task_struct
*p
)
95 long state
= p
->state
;
99 * For all intents and purposes a preempted task is a running task.
101 if (task_thread_info(p
)->preempt_count
& PREEMPT_ACTIVE
)
102 state
= TASK_RUNNING
;
110 #endif /* _TRACE_SCHED_DEF_ */
113 * Tracepoint for calling kthread_stop, performed to end a kthread:
115 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop
,
117 TP_PROTO(struct task_struct
*t
),
122 ctf_array_text(char, comm
, t
->comm
, TASK_COMM_LEN
)
123 ctf_integer(pid_t
, tid
, t
->pid
)
128 * Tracepoint for the return value of the kthread stopping:
130 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret
,
137 ctf_integer(int, ret
, ret
)
142 * Tracepoint for waking up a task:
144 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
145 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
146 LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
147 LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
148 LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
149 LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
150 LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
151 LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
152 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
154 TP_PROTO(struct task_struct
*p
),
159 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
160 ctf_integer(pid_t
, tid
, p
->pid
)
161 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
162 ctf_integer(int, target_cpu
, task_cpu(p
))
165 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
166 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
168 TP_PROTO(struct task_struct
*p
, int success
),
173 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
174 ctf_integer(pid_t
, tid
, p
->pid
)
175 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
176 ctf_integer(int, success
, success
)
177 ctf_integer(int, target_cpu
, task_cpu(p
))
180 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
182 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) || \
183 LTTNG_RT_KERNEL_RANGE(4,1,10,11, 4,2,0,0) || \
184 LTTNG_RT_KERNEL_RANGE(3,18,27,26, 3,19,0,0) || \
185 LTTNG_RT_KERNEL_RANGE(3,14,61,63, 3,15,0,0) || \
186 LTTNG_RT_KERNEL_RANGE(3,12,54,73, 3,13,0,0) || \
187 LTTNG_RT_KERNEL_RANGE(3,10,97,106, 3,11,0,0) || \
188 LTTNG_RT_KERNEL_RANGE(3,4,110,139, 3,5,0,0) || \
189 LTTNG_RT_KERNEL_RANGE(3,2,77,111, 3,3,0,0))
192 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
193 * called from the waking context.
195 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_waking
,
196 TP_PROTO(struct task_struct
*p
),
200 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
201 * It it not always called from the waking context.
203 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
204 TP_PROTO(struct task_struct
*p
),
208 * Tracepoint for waking up a new task:
210 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
211 TP_PROTO(struct task_struct
*p
),
216 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
217 TP_PROTO(struct task_struct
*p
, int success
),
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
, int success
),
227 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
230 * Tracepoint for task switches, performed by the scheduler:
232 LTTNG_TRACEPOINT_EVENT(sched_switch
,
234 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
235 TP_PROTO(bool preempt
,
236 struct task_struct
*prev
,
237 struct task_struct
*next
),
239 TP_ARGS(preempt
, prev
, next
),
241 TP_PROTO(struct task_struct
*prev
,
242 struct task_struct
*next
),
245 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)) */
248 ctf_array_text(char, prev_comm
, prev
->comm
, TASK_COMM_LEN
)
249 ctf_integer(pid_t
, prev_tid
, prev
->pid
)
250 ctf_integer(int, prev_prio
, prev
->prio
- MAX_RT_PRIO
)
251 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0))
252 ctf_integer(long, prev_state
, __trace_sched_switch_state(preempt
, prev
))
254 ctf_integer(long, prev_state
, __trace_sched_switch_state(prev
))
256 ctf_array_text(char, next_comm
, next
->comm
, TASK_COMM_LEN
)
257 ctf_integer(pid_t
, next_tid
, next
->pid
)
258 ctf_integer(int, next_prio
, next
->prio
- MAX_RT_PRIO
)
263 * Tracepoint for a task being migrated:
265 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
267 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
269 TP_ARGS(p
, dest_cpu
),
272 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
273 ctf_integer(pid_t
, tid
, p
->pid
)
274 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
275 ctf_integer(int, orig_cpu
, task_cpu(p
))
276 ctf_integer(int, dest_cpu
, dest_cpu
)
280 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
282 TP_PROTO(struct task_struct
*p
),
287 ctf_array_text(char, comm
, p
->comm
, TASK_COMM_LEN
)
288 ctf_integer(pid_t
, tid
, p
->pid
)
289 ctf_integer(int, prio
, p
->prio
- MAX_RT_PRIO
)
294 * Tracepoint for freeing a task:
296 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
297 TP_PROTO(struct task_struct
*p
),
302 * Tracepoint for a task exiting:
304 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
305 TP_PROTO(struct task_struct
*p
),
309 * Tracepoint for waiting on task to unschedule:
311 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
312 TP_PROTO(struct task_struct
*p
),
316 * Tracepoint for a waiting task:
318 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
320 TP_PROTO(struct pid
*pid
),
325 ctf_array_text(char, comm
, current
->comm
, TASK_COMM_LEN
)
326 ctf_integer(pid_t
, tid
, pid_nr(pid
))
327 ctf_integer(int, prio
, current
->prio
- MAX_RT_PRIO
)
332 * Tracepoint for do_fork.
333 * Saving both TID and PID information, especially for the child, allows
334 * trace analyzers to distinguish between creation of a new process and
335 * creation of a new thread. Newly created processes will have child_tid
336 * == child_pid, while creation of a thread yields to child_tid !=
339 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork
,
341 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
343 TP_ARGS(parent
, child
),
346 pid_t vtids
[LTTNG_MAX_PID_NS_LEVEL
];
347 unsigned int ns_level
;
352 struct pid
*child_pid
;
355 child_pid
= task_pid(child
);
356 tp_locvar
->ns_level
=
357 min_t(unsigned int, child_pid
->level
+ 1,
358 LTTNG_MAX_PID_NS_LEVEL
);
359 for (i
= 0; i
< tp_locvar
->ns_level
; i
++)
360 tp_locvar
->vtids
[i
] = child_pid
->numbers
[i
].nr
;
365 ctf_array_text(char, parent_comm
, parent
->comm
, TASK_COMM_LEN
)
366 ctf_integer(pid_t
, parent_tid
, parent
->pid
)
367 ctf_integer(pid_t
, parent_pid
, parent
->tgid
)
368 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
369 ctf_integer(unsigned int, parent_ns_inum
,
371 unsigned int parent_ns_inum
= 0;
374 struct pid_namespace
*pid_ns
;
376 pid_ns
= task_active_pid_ns(parent
);
379 pid_ns
->lttng_ns_inum
;
384 ctf_array_text(char, child_comm
, child
->comm
, TASK_COMM_LEN
)
385 ctf_integer(pid_t
, child_tid
, child
->pid
)
386 ctf_sequence(pid_t
, vtids
, tp_locvar
->vtids
, u8
, tp_locvar
->ns_level
)
387 ctf_integer(pid_t
, child_pid
, child
->tgid
)
388 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
389 ctf_integer(unsigned int, child_ns_inum
,
391 unsigned int child_ns_inum
= 0;
394 struct pid_namespace
*pid_ns
;
396 pid_ns
= task_active_pid_ns(child
);
399 pid_ns
->lttng_ns_inum
;
409 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
411 * Tracepoint for exec:
413 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
415 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
416 struct linux_binprm
*bprm
),
418 TP_ARGS(p
, old_pid
, bprm
),
421 ctf_string(filename
, bprm
->filename
)
422 ctf_integer(pid_t
, tid
, p
->pid
)
423 ctf_integer(pid_t
, old_tid
, old_pid
)
429 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
430 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
432 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
434 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
439 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
440 ctf_integer(pid_t
, tid
, tsk
->pid
)
441 ctf_integer(u64
, delay
, delay
)
447 * Tracepoint for accounting wait time (time the task is runnable
448 * but not actually running due to scheduler contention).
450 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
451 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
455 * Tracepoint for accounting sleep time (time the task is not runnable,
456 * including iowait, see below).
458 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
459 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
463 * Tracepoint for accounting iowait time (time the task is not runnable
464 * due to waiting on IO to complete).
466 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
467 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
470 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
472 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
474 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
475 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
480 * Tracepoint for accounting runtime (time the task is executing
483 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
485 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
487 TP_ARGS(tsk
, runtime
, vruntime
),
490 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
491 ctf_integer(pid_t
, tid
, tsk
->pid
)
492 ctf_integer(u64
, runtime
, runtime
)
493 ctf_integer(u64
, vruntime
, vruntime
)
497 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) || \
498 LTTNG_RT_KERNEL_RANGE(4,9,27,18, 4,10,0,0) || \
499 LTTNG_RT_KERNEL_RANGE(4,11,5,1, 4,12,0,0))
501 * Tracepoint for showing priority inheritance modifying a tasks
504 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
506 TP_PROTO(struct task_struct
*tsk
, struct task_struct
*pi_task
),
508 TP_ARGS(tsk
, pi_task
),
511 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
512 ctf_integer(pid_t
, tid
, tsk
->pid
)
513 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
514 ctf_integer(int, newprio
, pi_task
? pi_task
->prio
- MAX_RT_PRIO
: tsk
->prio
- MAX_RT_PRIO
)
519 * Tracepoint for showing priority inheritance modifying a tasks
522 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
524 TP_PROTO(struct task_struct
*tsk
, int newprio
),
526 TP_ARGS(tsk
, newprio
),
529 ctf_array_text(char, comm
, tsk
->comm
, TASK_COMM_LEN
)
530 ctf_integer(pid_t
, tid
, tsk
->pid
)
531 ctf_integer(int, oldprio
, tsk
->prio
- MAX_RT_PRIO
)
532 ctf_integer(int, newprio
, newprio
- MAX_RT_PRIO
)
537 #endif /* LTTNG_TRACE_SCHED_H */
539 /* This part must be outside protection */
540 #include <probes/define_trace.h>
This page took 0.042753 seconds and 5 git commands to generate.