1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM sched
5 #if !defined(_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/sched/numa_balancing.h>
9 #include <linux/tracepoint.h>
10 #include <linux/binfmts.h>
13 * Tracepoint for calling kthread_stop, performed to end a kthread:
15 TRACE_EVENT(sched_kthread_stop,
17 TP_PROTO(struct task_struct *t),
22 __array( char, comm, TASK_COMM_LEN )
27 memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
28 __entry->pid = t->pid;
31 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
35 * Tracepoint for the return value of the kthread stopping:
37 TRACE_EVENT(sched_kthread_stop_ret,
51 TP_printk("ret=%d", __entry->ret)
55 * Tracepoint for waking up a task:
57 DECLARE_EVENT_CLASS(sched_wakeup_template,
59 TP_PROTO(struct task_struct *p),
61 TP_ARGS(__perf_task(p)),
64 __array( char, comm, TASK_COMM_LEN )
67 __field( int, success )
68 __field( int, target_cpu )
72 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
73 __entry->pid = p->pid;
74 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
75 __entry->success = 1; /* rudiment, kill when possible */
76 __entry->target_cpu = task_cpu(p);
79 TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
80 __entry->comm, __entry->pid, __entry->prio,
85 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
86 * called from the waking context.
88 DEFINE_EVENT(sched_wakeup_template, sched_waking,
89 TP_PROTO(struct task_struct *p),
93 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
94 * It it not always called from the waking context.
96 DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
97 TP_PROTO(struct task_struct *p),
101 * Tracepoint for waking up a new task:
103 DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
104 TP_PROTO(struct task_struct *p),
107 #ifdef CREATE_TRACE_POINTS
108 static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
110 #ifdef CONFIG_SCHED_DEBUG
111 BUG_ON(p != current);
112 #endif /* CONFIG_SCHED_DEBUG */
115 * Preemption ignores task state, therefore preempted tasks are always
116 * RUNNING (we will not have dequeued if state != RUNNING).
119 return TASK_REPORT_MAX;
121 return 1 << task_state_index(p);
123 #endif /* CREATE_TRACE_POINTS */
126 * Tracepoint for task switches, performed by the scheduler:
128 TRACE_EVENT(sched_switch,
130 TP_PROTO(bool preempt,
131 struct task_struct *prev,
132 struct task_struct *next),
134 TP_ARGS(preempt, prev, next),
137 __array( char, prev_comm, TASK_COMM_LEN )
138 __field( pid_t, prev_pid )
139 __field( int, prev_prio )
140 __field( long, prev_state )
141 __array( char, next_comm, TASK_COMM_LEN )
142 __field( pid_t, next_pid )
143 __field( int, next_prio )
147 memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
148 __entry->prev_pid = prev->pid;
149 __entry->prev_prio = prev->prio;
150 __entry->prev_state = __trace_sched_switch_state(preempt, prev);
151 memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
152 __entry->next_pid = next->pid;
153 __entry->next_prio = next->prio;
154 /* XXX SCHED_DEADLINE */
157 TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
158 __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
160 (__entry->prev_state & (TASK_REPORT_MAX - 1)) ?
161 __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|",
162 { TASK_INTERRUPTIBLE, "S" },
163 { TASK_UNINTERRUPTIBLE, "D" },
164 { __TASK_STOPPED, "T" },
165 { __TASK_TRACED, "t" },
167 { EXIT_ZOMBIE, "Z" },
168 { TASK_PARKED, "P" },
169 { TASK_DEAD, "I" }) :
172 __entry->prev_state & TASK_REPORT_MAX ? "+" : "",
173 __entry->next_comm, __entry->next_pid, __entry->next_prio)
177 * Tracepoint for a task being migrated:
179 TRACE_EVENT(sched_migrate_task,
181 TP_PROTO(struct task_struct *p, int dest_cpu),
183 TP_ARGS(p, dest_cpu),
186 __array( char, comm, TASK_COMM_LEN )
187 __field( pid_t, pid )
189 __field( int, orig_cpu )
190 __field( int, dest_cpu )
194 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
195 __entry->pid = p->pid;
196 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
197 __entry->orig_cpu = task_cpu(p);
198 __entry->dest_cpu = dest_cpu;
201 TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
202 __entry->comm, __entry->pid, __entry->prio,
203 __entry->orig_cpu, __entry->dest_cpu)
206 DECLARE_EVENT_CLASS(sched_process_template,
208 TP_PROTO(struct task_struct *p),
213 __array( char, comm, TASK_COMM_LEN )
214 __field( pid_t, pid )
219 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
220 __entry->pid = p->pid;
221 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
224 TP_printk("comm=%s pid=%d prio=%d",
225 __entry->comm, __entry->pid, __entry->prio)
229 * Tracepoint for freeing a task:
231 DEFINE_EVENT(sched_process_template, sched_process_free,
232 TP_PROTO(struct task_struct *p),
237 * Tracepoint for a task exiting:
239 DEFINE_EVENT(sched_process_template, sched_process_exit,
240 TP_PROTO(struct task_struct *p),
244 * Tracepoint for waiting on task to unschedule:
246 DEFINE_EVENT(sched_process_template, sched_wait_task,
247 TP_PROTO(struct task_struct *p),
251 * Tracepoint for a waiting task:
253 TRACE_EVENT(sched_process_wait,
255 TP_PROTO(struct pid *pid),
260 __array( char, comm, TASK_COMM_LEN )
261 __field( pid_t, pid )
266 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
267 __entry->pid = pid_nr(pid);
268 __entry->prio = current->prio; /* XXX SCHED_DEADLINE */
271 TP_printk("comm=%s pid=%d prio=%d",
272 __entry->comm, __entry->pid, __entry->prio)
276 * Tracepoint for do_fork:
278 TRACE_EVENT(sched_process_fork,
280 TP_PROTO(struct task_struct *parent, struct task_struct *child),
282 TP_ARGS(parent, child),
285 __array( char, parent_comm, TASK_COMM_LEN )
286 __field( pid_t, parent_pid )
287 __array( char, child_comm, TASK_COMM_LEN )
288 __field( pid_t, child_pid )
292 memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
293 __entry->parent_pid = parent->pid;
294 memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
295 __entry->child_pid = child->pid;
298 TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
299 __entry->parent_comm, __entry->parent_pid,
300 __entry->child_comm, __entry->child_pid)
304 * Tracepoint for exec:
306 TRACE_EVENT(sched_process_exec,
308 TP_PROTO(struct task_struct *p, pid_t old_pid,
309 struct linux_binprm *bprm),
311 TP_ARGS(p, old_pid, bprm),
314 __string( filename, bprm->filename )
315 __field( pid_t, pid )
316 __field( pid_t, old_pid )
320 __assign_str(filename, bprm->filename);
321 __entry->pid = p->pid;
322 __entry->old_pid = old_pid;
325 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
326 __entry->pid, __entry->old_pid)
330 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
331 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
333 DECLARE_EVENT_CLASS(sched_stat_template,
335 TP_PROTO(struct task_struct *tsk, u64 delay),
337 TP_ARGS(__perf_task(tsk), __perf_count(delay)),
340 __array( char, comm, TASK_COMM_LEN )
341 __field( pid_t, pid )
342 __field( u64, delay )
346 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
347 __entry->pid = tsk->pid;
348 __entry->delay = delay;
351 TP_printk("comm=%s pid=%d delay=%Lu [ns]",
352 __entry->comm, __entry->pid,
353 (unsigned long long)__entry->delay)
358 * Tracepoint for accounting wait time (time the task is runnable
359 * but not actually running due to scheduler contention).
361 DEFINE_EVENT(sched_stat_template, sched_stat_wait,
362 TP_PROTO(struct task_struct *tsk, u64 delay),
363 TP_ARGS(tsk, delay));
366 * Tracepoint for accounting sleep time (time the task is not runnable,
367 * including iowait, see below).
369 DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
370 TP_PROTO(struct task_struct *tsk, u64 delay),
371 TP_ARGS(tsk, delay));
374 * Tracepoint for accounting iowait time (time the task is not runnable
375 * due to waiting on IO to complete).
377 DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
378 TP_PROTO(struct task_struct *tsk, u64 delay),
379 TP_ARGS(tsk, delay));
382 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
384 DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
385 TP_PROTO(struct task_struct *tsk, u64 delay),
386 TP_ARGS(tsk, delay));
389 * Tracepoint for accounting runtime (time the task is executing
392 DECLARE_EVENT_CLASS(sched_stat_runtime,
394 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
396 TP_ARGS(tsk, __perf_count(runtime), vruntime),
399 __array( char, comm, TASK_COMM_LEN )
400 __field( pid_t, pid )
401 __field( u64, runtime )
402 __field( u64, vruntime )
406 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
407 __entry->pid = tsk->pid;
408 __entry->runtime = runtime;
409 __entry->vruntime = vruntime;
412 TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
413 __entry->comm, __entry->pid,
414 (unsigned long long)__entry->runtime,
415 (unsigned long long)__entry->vruntime)
418 DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
419 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
420 TP_ARGS(tsk, runtime, vruntime));
423 * Tracepoint for showing priority inheritance modifying a tasks
426 TRACE_EVENT(sched_pi_setprio,
428 TP_PROTO(struct task_struct *tsk, struct task_struct *pi_task),
430 TP_ARGS(tsk, pi_task),
433 __array( char, comm, TASK_COMM_LEN )
434 __field( pid_t, pid )
435 __field( int, oldprio )
436 __field( int, newprio )
440 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
441 __entry->pid = tsk->pid;
442 __entry->oldprio = tsk->prio;
443 __entry->newprio = pi_task ?
444 min(tsk->normal_prio, pi_task->prio) :
446 /* XXX SCHED_DEADLINE bits missing */
449 TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
450 __entry->comm, __entry->pid,
451 __entry->oldprio, __entry->newprio)
454 #ifdef CONFIG_DETECT_HUNG_TASK
455 TRACE_EVENT(sched_process_hang,
456 TP_PROTO(struct task_struct *tsk),
460 __array( char, comm, TASK_COMM_LEN )
461 __field( pid_t, pid )
465 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
466 __entry->pid = tsk->pid;
469 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
471 #endif /* CONFIG_DETECT_HUNG_TASK */
473 DECLARE_EVENT_CLASS(sched_move_task_template,
475 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
477 TP_ARGS(tsk, src_cpu, dst_cpu),
480 __field( pid_t, pid )
481 __field( pid_t, tgid )
482 __field( pid_t, ngid )
483 __field( int, src_cpu )
484 __field( int, src_nid )
485 __field( int, dst_cpu )
486 __field( int, dst_nid )
490 __entry->pid = task_pid_nr(tsk);
491 __entry->tgid = task_tgid_nr(tsk);
492 __entry->ngid = task_numa_group_id(tsk);
493 __entry->src_cpu = src_cpu;
494 __entry->src_nid = cpu_to_node(src_cpu);
495 __entry->dst_cpu = dst_cpu;
496 __entry->dst_nid = cpu_to_node(dst_cpu);
499 TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
500 __entry->pid, __entry->tgid, __entry->ngid,
501 __entry->src_cpu, __entry->src_nid,
502 __entry->dst_cpu, __entry->dst_nid)
506 * Tracks migration of tasks from one runqueue to another. Can be used to
507 * detect if automatic NUMA balancing is bouncing between nodes
509 DEFINE_EVENT(sched_move_task_template, sched_move_numa,
510 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
512 TP_ARGS(tsk, src_cpu, dst_cpu)
515 DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
516 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
518 TP_ARGS(tsk, src_cpu, dst_cpu)
521 TRACE_EVENT(sched_swap_numa,
523 TP_PROTO(struct task_struct *src_tsk, int src_cpu,
524 struct task_struct *dst_tsk, int dst_cpu),
526 TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
529 __field( pid_t, src_pid )
530 __field( pid_t, src_tgid )
531 __field( pid_t, src_ngid )
532 __field( int, src_cpu )
533 __field( int, src_nid )
534 __field( pid_t, dst_pid )
535 __field( pid_t, dst_tgid )
536 __field( pid_t, dst_ngid )
537 __field( int, dst_cpu )
538 __field( int, dst_nid )
542 __entry->src_pid = task_pid_nr(src_tsk);
543 __entry->src_tgid = task_tgid_nr(src_tsk);
544 __entry->src_ngid = task_numa_group_id(src_tsk);
545 __entry->src_cpu = src_cpu;
546 __entry->src_nid = cpu_to_node(src_cpu);
547 __entry->dst_pid = task_pid_nr(dst_tsk);
548 __entry->dst_tgid = task_tgid_nr(dst_tsk);
549 __entry->dst_ngid = task_numa_group_id(dst_tsk);
550 __entry->dst_cpu = dst_cpu;
551 __entry->dst_nid = cpu_to_node(dst_cpu);
554 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",
555 __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
556 __entry->src_cpu, __entry->src_nid,
557 __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
558 __entry->dst_cpu, __entry->dst_nid)
562 * Tracepoint for waking a polling cpu without an IPI.
564 TRACE_EVENT(sched_wake_idle_without_ipi,
578 TP_printk("cpu=%d", __entry->cpu)
580 #endif /* _TRACE_SCHED_H */
582 /* This part must be outside protection */
583 #include <trace/define_trace.h>