2 #define TRACE_SYSTEM sched
4 #if !defined(_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
7 #include <linux/sched.h>
8 #include <linux/tracepoint.h>
9 #include <linux/binfmts.h>
12 * Tracepoint for calling kthread_stop, performed to end a kthread:
14 TRACE_EVENT(sched_kthread_stop,
16 TP_PROTO(struct task_struct *t),
21 __array( char, comm, TASK_COMM_LEN )
26 memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
27 __entry->pid = t->pid;
30 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
34 * Tracepoint for the return value of the kthread stopping:
36 TRACE_EVENT(sched_kthread_stop_ret,
50 TP_printk("ret=%d", __entry->ret)
54 * Tracepoint for waking up a task:
56 DECLARE_EVENT_CLASS(sched_wakeup_template,
58 TP_PROTO(struct task_struct *p),
60 TP_ARGS(__perf_task(p)),
63 __array( char, comm, TASK_COMM_LEN )
66 __field( int, success )
67 __field( int, target_cpu )
71 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
72 __entry->pid = p->pid;
73 __entry->prio = p->prio;
74 __entry->success = 1; /* rudiment, kill when possible */
75 __entry->target_cpu = task_cpu(p);
78 TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
79 __entry->comm, __entry->pid, __entry->prio,
84 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
85 * called from the waking context.
87 DEFINE_EVENT(sched_wakeup_template, sched_waking,
88 TP_PROTO(struct task_struct *p),
92 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
93 * It it not always called from the waking context.
95 DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
96 TP_PROTO(struct task_struct *p),
100 * Tracepoint for waking up a new task:
102 DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
103 TP_PROTO(struct task_struct *p),
106 #ifdef CREATE_TRACE_POINTS
107 static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
109 #ifdef CONFIG_SCHED_DEBUG
110 BUG_ON(p != current);
111 #endif /* CONFIG_SCHED_DEBUG */
114 * Preemption ignores task state, therefore preempted tasks are always
115 * RUNNING (we will not have dequeued if state != RUNNING).
117 return preempt ? TASK_RUNNING | TASK_STATE_MAX : p->state;
119 #endif /* CREATE_TRACE_POINTS */
122 * Tracepoint for task switches, performed by the scheduler:
124 TRACE_EVENT(sched_switch,
126 TP_PROTO(bool preempt,
127 struct task_struct *prev,
128 struct task_struct *next),
130 TP_ARGS(preempt, prev, next),
133 __array( char, prev_comm, TASK_COMM_LEN )
134 __field( pid_t, prev_pid )
135 __field( int, prev_prio )
136 __field( long, prev_state )
137 __array( char, next_comm, TASK_COMM_LEN )
138 __field( pid_t, next_pid )
139 __field( int, next_prio )
143 memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
144 __entry->prev_pid = prev->pid;
145 __entry->prev_prio = prev->prio;
146 __entry->prev_state = __trace_sched_switch_state(preempt, prev);
147 memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
148 __entry->next_pid = next->pid;
149 __entry->next_prio = next->prio;
152 TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
153 __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
154 __entry->prev_state & (TASK_STATE_MAX-1) ?
155 __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
156 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
157 { 16, "Z" }, { 32, "X" }, { 64, "x" },
158 { 128, "K" }, { 256, "W" }, { 512, "P" },
159 { 1024, "N" }) : "R",
160 __entry->prev_state & TASK_STATE_MAX ? "+" : "",
161 __entry->next_comm, __entry->next_pid, __entry->next_prio)
165 * Tracepoint for a task being migrated:
167 TRACE_EVENT(sched_migrate_task,
169 TP_PROTO(struct task_struct *p, int dest_cpu),
171 TP_ARGS(p, dest_cpu),
174 __array( char, comm, TASK_COMM_LEN )
175 __field( pid_t, pid )
177 __field( int, orig_cpu )
178 __field( int, dest_cpu )
182 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
183 __entry->pid = p->pid;
184 __entry->prio = p->prio;
185 __entry->orig_cpu = task_cpu(p);
186 __entry->dest_cpu = dest_cpu;
189 TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
190 __entry->comm, __entry->pid, __entry->prio,
191 __entry->orig_cpu, __entry->dest_cpu)
195 * Tracepoint for a CPU going offline/online:
197 TRACE_EVENT(sched_cpu_hotplug,
199 TP_PROTO(int affected_cpu, int error, int status),
201 TP_ARGS(affected_cpu, error, status),
204 __field( int, affected_cpu )
205 __field( int, error )
206 __field( int, status )
210 __entry->affected_cpu = affected_cpu;
211 __entry->error = error;
212 __entry->status = status;
215 TP_printk("cpu %d %s error=%d", __entry->affected_cpu,
216 __entry->status ? "online" : "offline", __entry->error)
219 DECLARE_EVENT_CLASS(sched_process_template,
221 TP_PROTO(struct task_struct *p),
226 __array( char, comm, TASK_COMM_LEN )
227 __field( pid_t, pid )
232 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
233 __entry->pid = p->pid;
234 __entry->prio = p->prio;
237 TP_printk("comm=%s pid=%d prio=%d",
238 __entry->comm, __entry->pid, __entry->prio)
242 * Tracepoint for freeing a task:
244 DEFINE_EVENT(sched_process_template, sched_process_free,
245 TP_PROTO(struct task_struct *p),
250 * Tracepoint for a task exiting:
252 DEFINE_EVENT(sched_process_template, sched_process_exit,
253 TP_PROTO(struct task_struct *p),
257 * Tracepoint for waiting on task to unschedule:
259 DEFINE_EVENT(sched_process_template, sched_wait_task,
260 TP_PROTO(struct task_struct *p),
264 * Tracepoint for a waiting task:
266 TRACE_EVENT(sched_process_wait,
268 TP_PROTO(struct pid *pid),
273 __array( char, comm, TASK_COMM_LEN )
274 __field( pid_t, pid )
279 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
280 __entry->pid = pid_nr(pid);
281 __entry->prio = current->prio;
284 TP_printk("comm=%s pid=%d prio=%d",
285 __entry->comm, __entry->pid, __entry->prio)
289 * Tracepoint for do_fork:
291 TRACE_EVENT(sched_process_fork,
293 TP_PROTO(struct task_struct *parent, struct task_struct *child),
295 TP_ARGS(parent, child),
298 __array( char, parent_comm, TASK_COMM_LEN )
299 __field( pid_t, parent_pid )
300 __array( char, child_comm, TASK_COMM_LEN )
301 __field( pid_t, child_pid )
305 memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
306 __entry->parent_pid = parent->pid;
307 memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
308 __entry->child_pid = child->pid;
311 TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
312 __entry->parent_comm, __entry->parent_pid,
313 __entry->child_comm, __entry->child_pid)
317 * Tracepoint for exec:
319 TRACE_EVENT(sched_process_exec,
321 TP_PROTO(struct task_struct *p, pid_t old_pid,
322 struct linux_binprm *bprm),
324 TP_ARGS(p, old_pid, bprm),
327 __string( filename, bprm->filename )
328 __field( pid_t, pid )
329 __field( pid_t, old_pid )
333 __assign_str(filename, bprm->filename);
334 __entry->pid = p->pid;
335 __entry->old_pid = old_pid;
338 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
339 __entry->pid, __entry->old_pid)
343 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
344 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
346 DECLARE_EVENT_CLASS(sched_stat_template,
348 TP_PROTO(struct task_struct *tsk, u64 delay),
350 TP_ARGS(__perf_task(tsk), __perf_count(delay)),
353 __array( char, comm, TASK_COMM_LEN )
354 __field( pid_t, pid )
355 __field( u64, delay )
359 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
360 __entry->pid = tsk->pid;
361 __entry->delay = delay;
364 TP_printk("comm=%s pid=%d delay=%Lu [ns]",
365 __entry->comm, __entry->pid,
366 (unsigned long long)__entry->delay)
371 * Tracepoint for accounting wait time (time the task is runnable
372 * but not actually running due to scheduler contention).
374 DEFINE_EVENT(sched_stat_template, sched_stat_wait,
375 TP_PROTO(struct task_struct *tsk, u64 delay),
376 TP_ARGS(tsk, delay));
379 * Tracepoint for accounting sleep time (time the task is not runnable,
380 * including iowait, see below).
382 DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
383 TP_PROTO(struct task_struct *tsk, u64 delay),
384 TP_ARGS(tsk, delay));
387 * Tracepoint for accounting iowait time (time the task is not runnable
388 * due to waiting on IO to complete).
390 DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
391 TP_PROTO(struct task_struct *tsk, u64 delay),
392 TP_ARGS(tsk, delay));
395 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
397 DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
398 TP_PROTO(struct task_struct *tsk, u64 delay),
399 TP_ARGS(tsk, delay));
402 * Tracepoint for recording the cause of uninterruptible sleep.
404 TRACE_EVENT(sched_blocked_reason,
406 TP_PROTO(struct task_struct *tsk),
411 __field( pid_t, pid )
412 __field( void*, caller )
413 __field( bool, io_wait )
417 __entry->pid = tsk->pid;
418 __entry->caller = (void*)get_wchan(tsk);
419 __entry->io_wait = tsk->in_iowait;
422 TP_printk("pid=%d iowait=%d caller=%pS", __entry->pid, __entry->io_wait, __entry->caller)
426 * Tracepoint for accounting runtime (time the task is executing
429 DECLARE_EVENT_CLASS(sched_stat_runtime,
431 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
433 TP_ARGS(tsk, __perf_count(runtime), vruntime),
436 __array( char, comm, TASK_COMM_LEN )
437 __field( pid_t, pid )
438 __field( u64, runtime )
439 __field( u64, vruntime )
443 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
444 __entry->pid = tsk->pid;
445 __entry->runtime = runtime;
446 __entry->vruntime = vruntime;
449 TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
450 __entry->comm, __entry->pid,
451 (unsigned long long)__entry->runtime,
452 (unsigned long long)__entry->vruntime)
455 DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
456 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
457 TP_ARGS(tsk, runtime, vruntime));
460 * Tracepoint for showing priority inheritance modifying a tasks
463 TRACE_EVENT(sched_pi_setprio,
465 TP_PROTO(struct task_struct *tsk, int newprio),
467 TP_ARGS(tsk, newprio),
470 __array( char, comm, TASK_COMM_LEN )
471 __field( pid_t, pid )
472 __field( int, oldprio )
473 __field( int, newprio )
477 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
478 __entry->pid = tsk->pid;
479 __entry->oldprio = tsk->prio;
480 __entry->newprio = newprio;
483 TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
484 __entry->comm, __entry->pid,
485 __entry->oldprio, __entry->newprio)
488 #ifdef CONFIG_DETECT_HUNG_TASK
489 TRACE_EVENT(sched_process_hang,
490 TP_PROTO(struct task_struct *tsk),
494 __array( char, comm, TASK_COMM_LEN )
495 __field( pid_t, pid )
499 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
500 __entry->pid = tsk->pid;
503 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
505 #endif /* CONFIG_DETECT_HUNG_TASK */
507 DECLARE_EVENT_CLASS(sched_move_task_template,
509 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
511 TP_ARGS(tsk, src_cpu, dst_cpu),
514 __field( pid_t, pid )
515 __field( pid_t, tgid )
516 __field( pid_t, ngid )
517 __field( int, src_cpu )
518 __field( int, src_nid )
519 __field( int, dst_cpu )
520 __field( int, dst_nid )
524 __entry->pid = task_pid_nr(tsk);
525 __entry->tgid = task_tgid_nr(tsk);
526 __entry->ngid = task_numa_group_id(tsk);
527 __entry->src_cpu = src_cpu;
528 __entry->src_nid = cpu_to_node(src_cpu);
529 __entry->dst_cpu = dst_cpu;
530 __entry->dst_nid = cpu_to_node(dst_cpu);
533 TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
534 __entry->pid, __entry->tgid, __entry->ngid,
535 __entry->src_cpu, __entry->src_nid,
536 __entry->dst_cpu, __entry->dst_nid)
540 * Tracks migration of tasks from one runqueue to another. Can be used to
541 * detect if automatic NUMA balancing is bouncing between nodes
543 DEFINE_EVENT(sched_move_task_template, sched_move_numa,
544 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
546 TP_ARGS(tsk, src_cpu, dst_cpu)
549 DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
550 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
552 TP_ARGS(tsk, src_cpu, dst_cpu)
555 TRACE_EVENT(sched_swap_numa,
557 TP_PROTO(struct task_struct *src_tsk, int src_cpu,
558 struct task_struct *dst_tsk, int dst_cpu),
560 TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
563 __field( pid_t, src_pid )
564 __field( pid_t, src_tgid )
565 __field( pid_t, src_ngid )
566 __field( int, src_cpu )
567 __field( int, src_nid )
568 __field( pid_t, dst_pid )
569 __field( pid_t, dst_tgid )
570 __field( pid_t, dst_ngid )
571 __field( int, dst_cpu )
572 __field( int, dst_nid )
576 __entry->src_pid = task_pid_nr(src_tsk);
577 __entry->src_tgid = task_tgid_nr(src_tsk);
578 __entry->src_ngid = task_numa_group_id(src_tsk);
579 __entry->src_cpu = src_cpu;
580 __entry->src_nid = cpu_to_node(src_cpu);
581 __entry->dst_pid = task_pid_nr(dst_tsk);
582 __entry->dst_tgid = task_tgid_nr(dst_tsk);
583 __entry->dst_ngid = task_numa_group_id(dst_tsk);
584 __entry->dst_cpu = dst_cpu;
585 __entry->dst_nid = cpu_to_node(dst_cpu);
588 TP_printk("src_pid=%d src_tgid=%d src_ngid=%d src_cpu=%d src_nid=%d dst_pid=%d dst_tgid=%d dst_ngid=%d dst_cpu=%d dst_nid=%d",
589 __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
590 __entry->src_cpu, __entry->src_nid,
591 __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
592 __entry->dst_cpu, __entry->dst_nid)
596 * Tracepoint for waking a polling cpu without an IPI.
598 TRACE_EVENT(sched_wake_idle_without_ipi,
612 TP_printk("cpu=%d", __entry->cpu)
614 #endif /* _TRACE_SCHED_H */
616 /* This part must be outside protection */
617 #include <trace/define_trace.h>