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 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template
,
140 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
141 TP_PROTO(struct task_struct
*p
, int success
),
145 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
147 TP_ARGS(rq
, p
, success
),
151 __array_text( char, comm
, TASK_COMM_LEN
)
152 __field( pid_t
, tid
)
154 __field( int, success
)
155 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
156 __field( int, target_cpu
)
161 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
162 tp_assign(tid
, p
->pid
)
163 tp_assign(prio
, p
->prio
)
164 tp_assign(success
, success
)
165 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
166 tp_assign(target_cpu
, task_cpu(p
))
168 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
176 TP_printk("comm=%s tid=%d prio=%d success=%d target_cpu=%03d",
177 __entry
->comm
, __entry
->tid
, __entry
->prio
,
178 __entry
->success
, __entry
->target_cpu
)
180 TP_printk("comm=%s tid=%d prio=%d success=%d",
181 __entry
->comm
, __entry
->tid
, __entry
->prio
,
186 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
188 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
189 TP_PROTO(struct task_struct
*p
, int success
),
193 * Tracepoint for waking up a new task:
195 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
196 TP_PROTO(struct task_struct
*p
, int success
),
199 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
201 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup
,
202 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
203 TP_ARGS(rq
, p
, success
))
206 * Tracepoint for waking up a new task:
208 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template
, sched_wakeup_new
,
209 TP_PROTO(struct rq
*rq
, struct task_struct
*p
, int success
),
210 TP_ARGS(rq
, p
, success
))
212 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
215 * Tracepoint for task switches, performed by the scheduler:
217 LTTNG_TRACEPOINT_EVENT(sched_switch
,
219 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
220 TP_PROTO(struct task_struct
*prev
,
221 struct task_struct
*next
),
224 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
225 TP_PROTO(struct rq
*rq
, struct task_struct
*prev
,
226 struct task_struct
*next
),
228 TP_ARGS(rq
, prev
, next
),
229 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
232 __array_text( char, prev_comm
, TASK_COMM_LEN
)
233 __field( pid_t
, prev_tid
)
234 __field( int, prev_prio
)
235 __field( long, prev_state
)
236 __array_text( char, next_comm
, TASK_COMM_LEN
)
237 __field( pid_t
, next_tid
)
238 __field( int, next_prio
)
242 tp_memcpy(next_comm
, next
->comm
, TASK_COMM_LEN
)
243 tp_assign(prev_tid
, prev
->pid
)
244 tp_assign(prev_prio
, prev
->prio
- MAX_RT_PRIO
)
245 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
246 tp_assign(prev_state
, __trace_sched_switch_state(prev
))
248 tp_assign(prev_state
, prev
->state
)
250 tp_memcpy(prev_comm
, prev
->comm
, TASK_COMM_LEN
)
251 tp_assign(next_tid
, next
->pid
)
252 tp_assign(next_prio
, next
->prio
- MAX_RT_PRIO
)
255 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
256 TP_printk("prev_comm=%s prev_tid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_tid=%d next_prio=%d",
257 __entry
->prev_comm
, __entry
->prev_tid
, __entry
->prev_prio
,
258 __entry
->prev_state
& (TASK_STATE_MAX
-1) ?
259 __print_flags(__entry
->prev_state
& (TASK_STATE_MAX
-1), "|",
260 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
261 { 16, "Z" }, { 32, "X" }, { 64, "x" },
263 __entry
->prev_state
& TASK_STATE_MAX
? "+" : "",
264 __entry
->next_comm
, __entry
->next_tid
, __entry
->next_prio
)
266 TP_printk("prev_comm=%s prev_tid=%d prev_prio=%d prev_state=%s ==> next_comm=%s next_tid=%d next_prio=%d",
267 __entry
->prev_comm
, __entry
->prev_tid
, __entry
->prev_prio
,
268 __entry
->prev_state
?
269 __print_flags(__entry
->prev_state
, "|",
270 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
271 { 16, "Z" }, { 32, "X" }, { 64, "x" },
273 __entry
->next_comm
, __entry
->next_tid
, __entry
->next_prio
)
278 * Tracepoint for a task being migrated:
280 LTTNG_TRACEPOINT_EVENT(sched_migrate_task
,
282 TP_PROTO(struct task_struct
*p
, int dest_cpu
),
284 TP_ARGS(p
, dest_cpu
),
287 __array_text( char, comm
, TASK_COMM_LEN
)
288 __field( pid_t
, tid
)
290 __field( int, orig_cpu
)
291 __field( int, dest_cpu
)
295 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
296 tp_assign(tid
, p
->pid
)
297 tp_assign(prio
, p
->prio
- MAX_RT_PRIO
)
298 tp_assign(orig_cpu
, task_cpu(p
))
299 tp_assign(dest_cpu
, dest_cpu
)
302 TP_printk("comm=%s tid=%d prio=%d orig_cpu=%d dest_cpu=%d",
303 __entry
->comm
, __entry
->tid
, __entry
->prio
,
304 __entry
->orig_cpu
, __entry
->dest_cpu
)
307 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template
,
309 TP_PROTO(struct task_struct
*p
),
314 __array_text( char, comm
, TASK_COMM_LEN
)
315 __field( pid_t
, tid
)
320 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
321 tp_assign(tid
, p
->pid
)
322 tp_assign(prio
, p
->prio
- MAX_RT_PRIO
)
325 TP_printk("comm=%s tid=%d prio=%d",
326 __entry
->comm
, __entry
->tid
, __entry
->prio
)
330 * Tracepoint for freeing a task:
332 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_free
,
333 TP_PROTO(struct task_struct
*p
),
338 * Tracepoint for a task exiting:
340 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_process_exit
,
341 TP_PROTO(struct task_struct
*p
),
345 * Tracepoint for waiting on task to unschedule:
347 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
348 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
349 TP_PROTO(struct task_struct
*p
),
351 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
352 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template
, sched_wait_task
,
353 TP_PROTO(struct rq
*rq
, struct task_struct
*p
),
355 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
358 * Tracepoint for a waiting task:
360 LTTNG_TRACEPOINT_EVENT(sched_process_wait
,
362 TP_PROTO(struct pid
*pid
),
367 __array_text( char, comm
, TASK_COMM_LEN
)
368 __field( pid_t
, tid
)
373 tp_memcpy(comm
, current
->comm
, TASK_COMM_LEN
)
374 tp_assign(tid
, pid_nr(pid
))
375 tp_assign(prio
, current
->prio
- MAX_RT_PRIO
)
378 TP_printk("comm=%s tid=%d prio=%d",
379 __entry
->comm
, __entry
->tid
, __entry
->prio
)
383 * Tracepoint for do_fork.
384 * Saving both TID and PID information, especially for the child, allows
385 * trace analyzers to distinguish between creation of a new process and
386 * creation of a new thread. Newly created processes will have child_tid
387 * == child_pid, while creation of a thread yields to child_tid !=
390 LTTNG_TRACEPOINT_EVENT(sched_process_fork
,
392 TP_PROTO(struct task_struct
*parent
, struct task_struct
*child
),
394 TP_ARGS(parent
, child
),
397 __array_text( char, parent_comm
, TASK_COMM_LEN
)
398 __field( pid_t
, parent_tid
)
399 __field( pid_t
, parent_pid
)
400 __array_text( char, child_comm
, TASK_COMM_LEN
)
401 __field( pid_t
, child_tid
)
402 __field( pid_t
, child_pid
)
406 tp_memcpy(parent_comm
, parent
->comm
, TASK_COMM_LEN
)
407 tp_assign(parent_tid
, parent
->pid
)
408 tp_assign(parent_pid
, parent
->tgid
)
409 tp_memcpy(child_comm
, child
->comm
, TASK_COMM_LEN
)
410 tp_assign(child_tid
, child
->pid
)
411 tp_assign(child_pid
, child
->tgid
)
414 TP_printk("comm=%s tid=%d child_comm=%s child_tid=%d",
415 __entry
->parent_comm
, __entry
->parent_tid
,
416 __entry
->child_comm
, __entry
->child_tid
)
419 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
421 * Tracepoint for sending a signal:
423 LTTNG_TRACEPOINT_EVENT(sched_signal_send
,
425 TP_PROTO(int sig
, struct task_struct
*p
),
431 __array( char, comm
, TASK_COMM_LEN
)
432 __field( pid_t
, pid
)
436 tp_memcpy(comm
, p
->comm
, TASK_COMM_LEN
)
437 tp_assign(pid
, p
->pid
)
441 TP_printk("sig=%d comm=%s pid=%d",
442 __entry
->sig
, __entry
->comm
, __entry
->pid
)
446 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
448 * Tracepoint for exec:
450 LTTNG_TRACEPOINT_EVENT(sched_process_exec
,
452 TP_PROTO(struct task_struct
*p
, pid_t old_pid
,
453 struct linux_binprm
*bprm
),
455 TP_ARGS(p
, old_pid
, bprm
),
458 __string( filename
, bprm
->filename
)
459 __field( pid_t
, tid
)
460 __field( pid_t
, old_tid
)
464 tp_strcpy(filename
, bprm
->filename
)
465 tp_assign(tid
, p
->pid
)
466 tp_assign(old_tid
, old_pid
)
469 TP_printk("filename=%s tid=%d old_tid=%d", __get_str(filename
),
470 __entry
->tid
, __entry
->old_tid
)
474 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
476 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
477 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
479 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template
,
481 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
486 __array_text( char, comm
, TASK_COMM_LEN
)
487 __field( pid_t
, tid
)
488 __field( u64
, delay
)
492 tp_memcpy(comm
, tsk
->comm
, TASK_COMM_LEN
)
493 tp_assign(tid
, tsk
->pid
)
494 tp_assign(delay
, delay
)
500 TP_printk("comm=%s tid=%d delay=%Lu [ns]",
501 __entry
->comm
, __entry
->tid
,
502 (unsigned long long)__entry
->delay
)
507 * Tracepoint for accounting wait time (time the task is runnable
508 * but not actually running due to scheduler contention).
510 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_wait
,
511 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
515 * Tracepoint for accounting sleep time (time the task is not runnable,
516 * including iowait, see below).
518 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_sleep
,
519 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
523 * Tracepoint for accounting iowait time (time the task is not runnable
524 * due to waiting on IO to complete).
526 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_iowait
,
527 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
530 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
532 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
534 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template
, sched_stat_blocked
,
535 TP_PROTO(struct task_struct
*tsk
, u64 delay
),
540 * Tracepoint for accounting runtime (time the task is executing
543 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime
,
545 TP_PROTO(struct task_struct
*tsk
, u64 runtime
, u64 vruntime
),
547 TP_ARGS(tsk
, runtime
, vruntime
),
550 __array_text( char, comm
, TASK_COMM_LEN
)
551 __field( pid_t
, tid
)
552 __field( u64
, runtime
)
553 __field( u64
, vruntime
)
557 tp_memcpy(comm
, tsk
->comm
, TASK_COMM_LEN
)
558 tp_assign(tid
, tsk
->pid
)
559 tp_assign(runtime
, runtime
)
560 tp_assign(vruntime
, vruntime
)
563 __perf_count(runtime
)
564 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
569 TP_printk("comm=%s tid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
570 __entry
->comm
, __entry
->tid
,
571 (unsigned long long)__entry
->runtime
,
572 (unsigned long long)__entry
->vruntime
)
576 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
578 * Tracepoint for showing priority inheritance modifying a tasks
581 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio
,
583 TP_PROTO(struct task_struct
*tsk
, int newprio
),
585 TP_ARGS(tsk
, newprio
),
588 __array_text( char, comm
, TASK_COMM_LEN
)
589 __field( pid_t
, tid
)
590 __field( int, oldprio
)
591 __field( int, newprio
)
595 tp_memcpy(comm
, tsk
->comm
, TASK_COMM_LEN
)
596 tp_assign(tid
, tsk
->pid
)
597 tp_assign(oldprio
, tsk
->prio
- MAX_RT_PRIO
)
598 tp_assign(newprio
, newprio
- MAX_RT_PRIO
)
601 TP_printk("comm=%s tid=%d oldprio=%d newprio=%d",
602 __entry
->comm
, __entry
->tid
,
603 __entry
->oldprio
, __entry
->newprio
)
607 #endif /* LTTNG_TRACE_SCHED_H */
609 /* This part must be outside protection */
610 #include "../../../probes/define_trace.h"
This page took 0.040897 seconds and 4 git commands to generate.