blob: 5e1a7578c9edd7315ede6017d1a9013c7d7591c6 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#undef TRACE_SYSTEM
3#define TRACE_SYSTEM sched
4
5#if !defined(_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_SCHED_H
7
8#include <linux/sched/numa_balancing.h>
9#include <linux/tracepoint.h>
10#include <linux/binfmts.h>
11
12/*
13 * Tracepoint for calling kthread_stop, performed to end a kthread:
14 */
15TRACE_EVENT(sched_kthread_stop,
16
17 TP_PROTO(struct task_struct *t),
18
19 TP_ARGS(t),
20
21 TP_STRUCT__entry(
22 __array( char, comm, TASK_COMM_LEN )
23 __field( pid_t, pid )
24 ),
25
26 TP_fast_assign(
27 memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
28 __entry->pid = t->pid;
29 ),
30
31 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
32);
33
34/*
35 * Tracepoint for the return value of the kthread stopping:
36 */
37TRACE_EVENT(sched_kthread_stop_ret,
38
39 TP_PROTO(int ret),
40
41 TP_ARGS(ret),
42
43 TP_STRUCT__entry(
44 __field( int, ret )
45 ),
46
47 TP_fast_assign(
48 __entry->ret = ret;
49 ),
50
51 TP_printk("ret=%d", __entry->ret)
52);
53
54/*
55 * Tracepoint for waking up a task:
56 */
57DECLARE_EVENT_CLASS(sched_wakeup_template,
58
59 TP_PROTO(struct task_struct *p),
60
61 TP_ARGS(__perf_task(p)),
62
63 TP_STRUCT__entry(
64 __array( char, comm, TASK_COMM_LEN )
65 __field( pid_t, pid )
66 __field( int, prio )
67 __field( int, success )
68 __field( int, target_cpu )
69 ),
70
71 TP_fast_assign(
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);
77 ),
78
79 TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
80 __entry->comm, __entry->pid, __entry->prio,
81 __entry->target_cpu)
82);
83
84/*
85 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
86 * called from the waking context.
87 */
88DEFINE_EVENT(sched_wakeup_template, sched_waking,
89 TP_PROTO(struct task_struct *p),
90 TP_ARGS(p));
91
92/*
93 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
94 * It it not always called from the waking context.
95 */
96DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
97 TP_PROTO(struct task_struct *p),
98 TP_ARGS(p));
99
100/*
101 * Tracepoint for waking up a new task:
102 */
103DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
104 TP_PROTO(struct task_struct *p),
105 TP_ARGS(p));
106
107#ifdef CREATE_TRACE_POINTS
108static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
109{
110 unsigned int state;
111
112#ifdef CONFIG_SCHED_DEBUG
113 BUG_ON(p != current);
114#endif /* CONFIG_SCHED_DEBUG */
115
116 /*
117 * Preemption ignores task state, therefore preempted tasks are always
118 * RUNNING (we will not have dequeued if state != RUNNING).
119 */
120 if (preempt)
121 return TASK_REPORT_MAX;
122
123 /*
124 * task_state_index() uses fls() and returns a value from 0-8 range.
125 * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
126 * it for left shift operation to get the correct task->state
127 * mapping.
128 */
129 state = task_state_index(p);
130
131 return state ? (1 << (state - 1)) : state;
132}
133#endif /* CREATE_TRACE_POINTS */
134
135/*
136 * Tracepoint for task switches, performed by the scheduler:
137 */
138TRACE_EVENT(sched_switch,
139
140 TP_PROTO(bool preempt,
141 struct task_struct *prev,
142 struct task_struct *next),
143
144 TP_ARGS(preempt, prev, next),
145
146 TP_STRUCT__entry(
147 __array( char, prev_comm, TASK_COMM_LEN )
148 __field( pid_t, prev_pid )
149 __field( int, prev_prio )
150 __field( long, prev_state )
151 __array( char, next_comm, TASK_COMM_LEN )
152 __field( pid_t, next_pid )
153 __field( int, next_prio )
154 ),
155
156 TP_fast_assign(
157 memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
158 __entry->prev_pid = prev->pid;
159 __entry->prev_prio = prev->prio;
160 __entry->prev_state = __trace_sched_switch_state(preempt, prev);
161 memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
162 __entry->next_pid = next->pid;
163 __entry->next_prio = next->prio;
164 /* XXX SCHED_DEADLINE */
165 ),
166
167 TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
168 __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
169
170 (__entry->prev_state & (TASK_REPORT_MAX - 1)) ?
171 __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|",
172 { 0x01, "S" }, { 0x02, "D" }, { 0x04, "T" },
173 { 0x08, "t" }, { 0x10, "X" }, { 0x20, "Z" },
174 { 0x40, "P" }, { 0x80, "I" }) :
175 "R",
176
177 __entry->prev_state & TASK_REPORT_MAX ? "+" : "",
178 __entry->next_comm, __entry->next_pid, __entry->next_prio)
179);
180
181/*
182 * Tracepoint for a task being migrated:
183 */
184TRACE_EVENT(sched_migrate_task,
185
186 TP_PROTO(struct task_struct *p, int dest_cpu),
187
188 TP_ARGS(p, dest_cpu),
189
190 TP_STRUCT__entry(
191 __array( char, comm, TASK_COMM_LEN )
192 __field( pid_t, pid )
193 __field( int, prio )
194 __field( int, orig_cpu )
195 __field( int, dest_cpu )
196 ),
197
198 TP_fast_assign(
199 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
200 __entry->pid = p->pid;
201 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
202 __entry->orig_cpu = task_cpu(p);
203 __entry->dest_cpu = dest_cpu;
204 ),
205
206 TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
207 __entry->comm, __entry->pid, __entry->prio,
208 __entry->orig_cpu, __entry->dest_cpu)
209);
210
211DECLARE_EVENT_CLASS(sched_process_template,
212
213 TP_PROTO(struct task_struct *p),
214
215 TP_ARGS(p),
216
217 TP_STRUCT__entry(
218 __array( char, comm, TASK_COMM_LEN )
219 __field( pid_t, pid )
220 __field( int, prio )
221 ),
222
223 TP_fast_assign(
224 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
225 __entry->pid = p->pid;
226 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
227 ),
228
229 TP_printk("comm=%s pid=%d prio=%d",
230 __entry->comm, __entry->pid, __entry->prio)
231);
232
233/*
234 * Tracepoint for freeing a task:
235 */
236DEFINE_EVENT(sched_process_template, sched_process_free,
237 TP_PROTO(struct task_struct *p),
238 TP_ARGS(p));
239
240
241/*
242 * Tracepoint for a task exiting:
243 */
244DEFINE_EVENT(sched_process_template, sched_process_exit,
245 TP_PROTO(struct task_struct *p),
246 TP_ARGS(p));
247
248/*
249 * Tracepoint for waiting on task to unschedule:
250 */
251DEFINE_EVENT(sched_process_template, sched_wait_task,
252 TP_PROTO(struct task_struct *p),
253 TP_ARGS(p));
254
255/*
256 * Tracepoint for a waiting task:
257 */
258TRACE_EVENT(sched_process_wait,
259
260 TP_PROTO(struct pid *pid),
261
262 TP_ARGS(pid),
263
264 TP_STRUCT__entry(
265 __array( char, comm, TASK_COMM_LEN )
266 __field( pid_t, pid )
267 __field( int, prio )
268 ),
269
270 TP_fast_assign(
271 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
272 __entry->pid = pid_nr(pid);
273 __entry->prio = current->prio; /* XXX SCHED_DEADLINE */
274 ),
275
276 TP_printk("comm=%s pid=%d prio=%d",
277 __entry->comm, __entry->pid, __entry->prio)
278);
279
280/*
281 * Tracepoint for do_fork:
282 */
283TRACE_EVENT(sched_process_fork,
284
285 TP_PROTO(struct task_struct *parent, struct task_struct *child),
286
287 TP_ARGS(parent, child),
288
289 TP_STRUCT__entry(
290 __array( char, parent_comm, TASK_COMM_LEN )
291 __field( pid_t, parent_pid )
292 __array( char, child_comm, TASK_COMM_LEN )
293 __field( pid_t, child_pid )
294 ),
295
296 TP_fast_assign(
297 memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
298 __entry->parent_pid = parent->pid;
299 memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
300 __entry->child_pid = child->pid;
301 ),
302
303 TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
304 __entry->parent_comm, __entry->parent_pid,
305 __entry->child_comm, __entry->child_pid)
306);
307
308/*
309 * Tracepoint for exec:
310 */
311TRACE_EVENT(sched_process_exec,
312
313 TP_PROTO(struct task_struct *p, pid_t old_pid,
314 struct linux_binprm *bprm),
315
316 TP_ARGS(p, old_pid, bprm),
317
318 TP_STRUCT__entry(
319 __string( filename, bprm->filename )
320 __field( pid_t, pid )
321 __field( pid_t, old_pid )
322 ),
323
324 TP_fast_assign(
325 __assign_str(filename, bprm->filename);
326 __entry->pid = p->pid;
327 __entry->old_pid = old_pid;
328 ),
329
330 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
331 __entry->pid, __entry->old_pid)
332);
333
334/*
335 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
336 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
337 */
338DECLARE_EVENT_CLASS(sched_stat_template,
339
340 TP_PROTO(struct task_struct *tsk, u64 delay),
341
342 TP_ARGS(__perf_task(tsk), __perf_count(delay)),
343
344 TP_STRUCT__entry(
345 __array( char, comm, TASK_COMM_LEN )
346 __field( pid_t, pid )
347 __field( u64, delay )
348 ),
349
350 TP_fast_assign(
351 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
352 __entry->pid = tsk->pid;
353 __entry->delay = delay;
354 ),
355
356 TP_printk("comm=%s pid=%d delay=%Lu [ns]",
357 __entry->comm, __entry->pid,
358 (unsigned long long)__entry->delay)
359);
360
361
362/*
363 * Tracepoint for accounting wait time (time the task is runnable
364 * but not actually running due to scheduler contention).
365 */
366DEFINE_EVENT(sched_stat_template, sched_stat_wait,
367 TP_PROTO(struct task_struct *tsk, u64 delay),
368 TP_ARGS(tsk, delay));
369
370/*
371 * Tracepoint for accounting sleep time (time the task is not runnable,
372 * including iowait, see below).
373 */
374DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
375 TP_PROTO(struct task_struct *tsk, u64 delay),
376 TP_ARGS(tsk, delay));
377
378/*
379 * Tracepoint for accounting iowait time (time the task is not runnable
380 * due to waiting on IO to complete).
381 */
382DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
383 TP_PROTO(struct task_struct *tsk, u64 delay),
384 TP_ARGS(tsk, delay));
385
386/*
387 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
388 */
389DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
390 TP_PROTO(struct task_struct *tsk, u64 delay),
391 TP_ARGS(tsk, delay));
392
393/*
394 * Tracepoint for accounting runtime (time the task is executing
395 * on a CPU).
396 */
397DECLARE_EVENT_CLASS(sched_stat_runtime,
398
399 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
400
401 TP_ARGS(tsk, __perf_count(runtime), vruntime),
402
403 TP_STRUCT__entry(
404 __array( char, comm, TASK_COMM_LEN )
405 __field( pid_t, pid )
406 __field( u64, runtime )
407 __field( u64, vruntime )
408 ),
409
410 TP_fast_assign(
411 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
412 __entry->pid = tsk->pid;
413 __entry->runtime = runtime;
414 __entry->vruntime = vruntime;
415 ),
416
417 TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
418 __entry->comm, __entry->pid,
419 (unsigned long long)__entry->runtime,
420 (unsigned long long)__entry->vruntime)
421);
422
423DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
424 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
425 TP_ARGS(tsk, runtime, vruntime));
426
427/*
428 * Tracepoint for showing priority inheritance modifying a tasks
429 * priority.
430 */
431TRACE_EVENT(sched_pi_setprio,
432
433 TP_PROTO(struct task_struct *tsk, struct task_struct *pi_task),
434
435 TP_ARGS(tsk, pi_task),
436
437 TP_STRUCT__entry(
438 __array( char, comm, TASK_COMM_LEN )
439 __field( pid_t, pid )
440 __field( int, oldprio )
441 __field( int, newprio )
442 ),
443
444 TP_fast_assign(
445 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
446 __entry->pid = tsk->pid;
447 __entry->oldprio = tsk->prio;
448 __entry->newprio = pi_task ?
449 min(tsk->normal_prio, pi_task->prio) :
450 tsk->normal_prio;
451 /* XXX SCHED_DEADLINE bits missing */
452 ),
453
454 TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
455 __entry->comm, __entry->pid,
456 __entry->oldprio, __entry->newprio)
457);
458
459#ifdef CONFIG_DETECT_HUNG_TASK
460TRACE_EVENT(sched_process_hang,
461 TP_PROTO(struct task_struct *tsk),
462 TP_ARGS(tsk),
463
464 TP_STRUCT__entry(
465 __array( char, comm, TASK_COMM_LEN )
466 __field( pid_t, pid )
467 ),
468
469 TP_fast_assign(
470 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
471 __entry->pid = tsk->pid;
472 ),
473
474 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
475);
476#endif /* CONFIG_DETECT_HUNG_TASK */
477
478DECLARE_EVENT_CLASS(sched_move_task_template,
479
480 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
481
482 TP_ARGS(tsk, src_cpu, dst_cpu),
483
484 TP_STRUCT__entry(
485 __field( pid_t, pid )
486 __field( pid_t, tgid )
487 __field( pid_t, ngid )
488 __field( int, src_cpu )
489 __field( int, src_nid )
490 __field( int, dst_cpu )
491 __field( int, dst_nid )
492 ),
493
494 TP_fast_assign(
495 __entry->pid = task_pid_nr(tsk);
496 __entry->tgid = task_tgid_nr(tsk);
497 __entry->ngid = task_numa_group_id(tsk);
498 __entry->src_cpu = src_cpu;
499 __entry->src_nid = cpu_to_node(src_cpu);
500 __entry->dst_cpu = dst_cpu;
501 __entry->dst_nid = cpu_to_node(dst_cpu);
502 ),
503
504 TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
505 __entry->pid, __entry->tgid, __entry->ngid,
506 __entry->src_cpu, __entry->src_nid,
507 __entry->dst_cpu, __entry->dst_nid)
508);
509
510/*
511 * Tracks migration of tasks from one runqueue to another. Can be used to
512 * detect if automatic NUMA balancing is bouncing between nodes
513 */
514DEFINE_EVENT(sched_move_task_template, sched_move_numa,
515 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
516
517 TP_ARGS(tsk, src_cpu, dst_cpu)
518);
519
520DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
521 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
522
523 TP_ARGS(tsk, src_cpu, dst_cpu)
524);
525
526TRACE_EVENT(sched_swap_numa,
527
528 TP_PROTO(struct task_struct *src_tsk, int src_cpu,
529 struct task_struct *dst_tsk, int dst_cpu),
530
531 TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
532
533 TP_STRUCT__entry(
534 __field( pid_t, src_pid )
535 __field( pid_t, src_tgid )
536 __field( pid_t, src_ngid )
537 __field( int, src_cpu )
538 __field( int, src_nid )
539 __field( pid_t, dst_pid )
540 __field( pid_t, dst_tgid )
541 __field( pid_t, dst_ngid )
542 __field( int, dst_cpu )
543 __field( int, dst_nid )
544 ),
545
546 TP_fast_assign(
547 __entry->src_pid = task_pid_nr(src_tsk);
548 __entry->src_tgid = task_tgid_nr(src_tsk);
549 __entry->src_ngid = task_numa_group_id(src_tsk);
550 __entry->src_cpu = src_cpu;
551 __entry->src_nid = cpu_to_node(src_cpu);
552 __entry->dst_pid = task_pid_nr(dst_tsk);
553 __entry->dst_tgid = task_tgid_nr(dst_tsk);
554 __entry->dst_ngid = task_numa_group_id(dst_tsk);
555 __entry->dst_cpu = dst_cpu;
556 __entry->dst_nid = cpu_to_node(dst_cpu);
557 ),
558
559 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",
560 __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
561 __entry->src_cpu, __entry->src_nid,
562 __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
563 __entry->dst_cpu, __entry->dst_nid)
564);
565
566/*
567 * Tracepoint for waking a polling cpu without an IPI.
568 */
569TRACE_EVENT(sched_wake_idle_without_ipi,
570
571 TP_PROTO(int cpu),
572
573 TP_ARGS(cpu),
574
575 TP_STRUCT__entry(
576 __field( int, cpu )
577 ),
578
579 TP_fast_assign(
580 __entry->cpu = cpu;
581 ),
582
583 TP_printk("cpu=%d", __entry->cpu)
584);
585#endif /* _TRACE_SCHED_H */
586
587/* This part must be outside protection */
588#include <trace/define_trace.h>