blob: 0bc469b225b7236d0d09a9cee0e87b0925d85298 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* 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 = __get_task_state(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 { TASK_INTERRUPTIBLE, "S" },
173 { TASK_UNINTERRUPTIBLE, "D" },
174 { __TASK_STOPPED, "T" },
175 { __TASK_TRACED, "t" },
176 { EXIT_DEAD, "X" },
177 { EXIT_ZOMBIE, "Z" },
178 { TASK_PARKED, "P" },
179 { TASK_DEAD, "I" }) :
180 "R",
181
182 __entry->prev_state & TASK_REPORT_MAX ? "+" : "",
183 __entry->next_comm, __entry->next_pid, __entry->next_prio)
184);
185
186/*
187 * Tracepoint for a task being migrated:
188 */
189TRACE_EVENT(sched_migrate_task,
190
191 TP_PROTO(struct task_struct *p, int dest_cpu),
192
193 TP_ARGS(p, dest_cpu),
194
195 TP_STRUCT__entry(
196 __array( char, comm, TASK_COMM_LEN )
197 __field( pid_t, pid )
198 __field( int, prio )
199 __field( int, orig_cpu )
200 __field( int, dest_cpu )
201 ),
202
203 TP_fast_assign(
204 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
205 __entry->pid = p->pid;
206 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
207 __entry->orig_cpu = task_cpu(p);
208 __entry->dest_cpu = dest_cpu;
209 ),
210
211 TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
212 __entry->comm, __entry->pid, __entry->prio,
213 __entry->orig_cpu, __entry->dest_cpu)
214);
215
216DECLARE_EVENT_CLASS(sched_process_template,
217
218 TP_PROTO(struct task_struct *p),
219
220 TP_ARGS(p),
221
222 TP_STRUCT__entry(
223 __array( char, comm, TASK_COMM_LEN )
224 __field( pid_t, pid )
225 __field( int, prio )
226 ),
227
228 TP_fast_assign(
229 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
230 __entry->pid = p->pid;
231 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
232 ),
233
234 TP_printk("comm=%s pid=%d prio=%d",
235 __entry->comm, __entry->pid, __entry->prio)
236);
237
238/*
239 * Tracepoint for freeing a task:
240 */
241DEFINE_EVENT(sched_process_template, sched_process_free,
242 TP_PROTO(struct task_struct *p),
243 TP_ARGS(p));
244
245
246/*
247 * Tracepoint for a task exiting:
248 */
249DEFINE_EVENT(sched_process_template, sched_process_exit,
250 TP_PROTO(struct task_struct *p),
251 TP_ARGS(p));
252
253/*
254 * Tracepoint for waiting on task to unschedule:
255 */
256DEFINE_EVENT(sched_process_template, sched_wait_task,
257 TP_PROTO(struct task_struct *p),
258 TP_ARGS(p));
259
260/*
261 * Tracepoint for a waiting task:
262 */
263TRACE_EVENT(sched_process_wait,
264
265 TP_PROTO(struct pid *pid),
266
267 TP_ARGS(pid),
268
269 TP_STRUCT__entry(
270 __array( char, comm, TASK_COMM_LEN )
271 __field( pid_t, pid )
272 __field( int, prio )
273 ),
274
275 TP_fast_assign(
276 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
277 __entry->pid = pid_nr(pid);
278 __entry->prio = current->prio; /* XXX SCHED_DEADLINE */
279 ),
280
281 TP_printk("comm=%s pid=%d prio=%d",
282 __entry->comm, __entry->pid, __entry->prio)
283);
284
285/*
286 * Tracepoint for do_fork:
287 */
288TRACE_EVENT(sched_process_fork,
289
290 TP_PROTO(struct task_struct *parent, struct task_struct *child),
291
292 TP_ARGS(parent, child),
293
294 TP_STRUCT__entry(
295 __array( char, parent_comm, TASK_COMM_LEN )
296 __field( pid_t, parent_pid )
297 __array( char, child_comm, TASK_COMM_LEN )
298 __field( pid_t, child_pid )
299 ),
300
301 TP_fast_assign(
302 memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
303 __entry->parent_pid = parent->pid;
304 memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
305 __entry->child_pid = child->pid;
306 ),
307
308 TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
309 __entry->parent_comm, __entry->parent_pid,
310 __entry->child_comm, __entry->child_pid)
311);
312
313/*
314 * Tracepoint for exec:
315 */
316TRACE_EVENT(sched_process_exec,
317
318 TP_PROTO(struct task_struct *p, pid_t old_pid,
319 struct linux_binprm *bprm),
320
321 TP_ARGS(p, old_pid, bprm),
322
323 TP_STRUCT__entry(
324 __string( filename, bprm->filename )
325 __field( pid_t, pid )
326 __field( pid_t, old_pid )
327 ),
328
329 TP_fast_assign(
330 __assign_str(filename, bprm->filename);
331 __entry->pid = p->pid;
332 __entry->old_pid = old_pid;
333 ),
334
335 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
336 __entry->pid, __entry->old_pid)
337);
338
339/*
340 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
341 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
342 */
343DECLARE_EVENT_CLASS(sched_stat_template,
344
345 TP_PROTO(struct task_struct *tsk, u64 delay),
346
347 TP_ARGS(__perf_task(tsk), __perf_count(delay)),
348
349 TP_STRUCT__entry(
350 __array( char, comm, TASK_COMM_LEN )
351 __field( pid_t, pid )
352 __field( u64, delay )
353 ),
354
355 TP_fast_assign(
356 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
357 __entry->pid = tsk->pid;
358 __entry->delay = delay;
359 ),
360
361 TP_printk("comm=%s pid=%d delay=%Lu [ns]",
362 __entry->comm, __entry->pid,
363 (unsigned long long)__entry->delay)
364);
365
366
367/*
368 * Tracepoint for accounting wait time (time the task is runnable
369 * but not actually running due to scheduler contention).
370 */
371DEFINE_EVENT(sched_stat_template, sched_stat_wait,
372 TP_PROTO(struct task_struct *tsk, u64 delay),
373 TP_ARGS(tsk, delay));
374
375/*
376 * Tracepoint for accounting sleep time (time the task is not runnable,
377 * including iowait, see below).
378 */
379DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
380 TP_PROTO(struct task_struct *tsk, u64 delay),
381 TP_ARGS(tsk, delay));
382
383/*
384 * Tracepoint for accounting iowait time (time the task is not runnable
385 * due to waiting on IO to complete).
386 */
387DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
388 TP_PROTO(struct task_struct *tsk, u64 delay),
389 TP_ARGS(tsk, delay));
390
391/*
392 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
393 */
394DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
395 TP_PROTO(struct task_struct *tsk, u64 delay),
396 TP_ARGS(tsk, delay));
397
398/*
399 * Tracepoint for recording the cause of uninterruptible sleep.
400 */
401TRACE_EVENT(sched_blocked_reason,
402
403 TP_PROTO(struct task_struct *tsk),
404
405 TP_ARGS(tsk),
406
407 TP_STRUCT__entry(
408 __field( pid_t, pid )
409 __field( void*, caller )
410 __field( bool, io_wait )
411 ),
412
413 TP_fast_assign(
414 __entry->pid = tsk->pid;
415 __entry->caller = (void*)get_wchan(tsk);
416 __entry->io_wait = tsk->in_iowait;
417 ),
418
419 TP_printk("pid=%d iowait=%d caller=%pS", __entry->pid, __entry->io_wait, __entry->caller)
420);
421
422/*
423 * Tracepoint for accounting runtime (time the task is executing
424 * on a CPU).
425 */
426DECLARE_EVENT_CLASS(sched_stat_runtime,
427
428 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
429
430 TP_ARGS(tsk, __perf_count(runtime), vruntime),
431
432 TP_STRUCT__entry(
433 __array( char, comm, TASK_COMM_LEN )
434 __field( pid_t, pid )
435 __field( u64, runtime )
436 __field( u64, vruntime )
437 ),
438
439 TP_fast_assign(
440 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
441 __entry->pid = tsk->pid;
442 __entry->runtime = runtime;
443 __entry->vruntime = vruntime;
444 ),
445
446 TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
447 __entry->comm, __entry->pid,
448 (unsigned long long)__entry->runtime,
449 (unsigned long long)__entry->vruntime)
450);
451
452DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
453 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
454 TP_ARGS(tsk, runtime, vruntime));
455
456/*
457 * Tracepoint for showing priority inheritance modifying a tasks
458 * priority.
459 */
460TRACE_EVENT(sched_pi_setprio,
461
462 TP_PROTO(struct task_struct *tsk, struct task_struct *pi_task),
463
464 TP_ARGS(tsk, pi_task),
465
466 TP_STRUCT__entry(
467 __array( char, comm, TASK_COMM_LEN )
468 __field( pid_t, pid )
469 __field( int, oldprio )
470 __field( int, newprio )
471 ),
472
473 TP_fast_assign(
474 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
475 __entry->pid = tsk->pid;
476 __entry->oldprio = tsk->prio;
477 __entry->newprio = pi_task ?
478 min(tsk->normal_prio, pi_task->prio) :
479 tsk->normal_prio;
480 /* XXX SCHED_DEADLINE bits missing */
481 ),
482
483 TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
484 __entry->comm, __entry->pid,
485 __entry->oldprio, __entry->newprio)
486);
487
488#ifdef CONFIG_DETECT_HUNG_TASK
489TRACE_EVENT(sched_process_hang,
490 TP_PROTO(struct task_struct *tsk),
491 TP_ARGS(tsk),
492
493 TP_STRUCT__entry(
494 __array( char, comm, TASK_COMM_LEN )
495 __field( pid_t, pid )
496 ),
497
498 TP_fast_assign(
499 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
500 __entry->pid = tsk->pid;
501 ),
502
503 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
504);
505#endif /* CONFIG_DETECT_HUNG_TASK */
506
507DECLARE_EVENT_CLASS(sched_move_task_template,
508
509 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
510
511 TP_ARGS(tsk, src_cpu, dst_cpu),
512
513 TP_STRUCT__entry(
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 )
521 ),
522
523 TP_fast_assign(
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);
531 ),
532
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)
537);
538
539/*
540 * Tracks migration of tasks from one runqueue to another. Can be used to
541 * detect if automatic NUMA balancing is bouncing between nodes
542 */
543DEFINE_EVENT(sched_move_task_template, sched_move_numa,
544 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
545
546 TP_ARGS(tsk, src_cpu, dst_cpu)
547);
548
549DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
550 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
551
552 TP_ARGS(tsk, src_cpu, dst_cpu)
553);
554
555TRACE_EVENT(sched_swap_numa,
556
557 TP_PROTO(struct task_struct *src_tsk, int src_cpu,
558 struct task_struct *dst_tsk, int dst_cpu),
559
560 TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
561
562 TP_STRUCT__entry(
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 )
573 ),
574
575 TP_fast_assign(
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);
586 ),
587
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)
593);
594
595/*
596 * Tracepoint for waking a polling cpu without an IPI.
597 */
598TRACE_EVENT(sched_wake_idle_without_ipi,
599
600 TP_PROTO(int cpu),
601
602 TP_ARGS(cpu),
603
604 TP_STRUCT__entry(
605 __field( int, cpu )
606 ),
607
608 TP_fast_assign(
609 __entry->cpu = cpu;
610 ),
611
612 TP_printk("cpu=%d", __entry->cpu)
613);
614
615#ifdef CONFIG_SMP
616#ifdef CREATE_TRACE_POINTS
617static inline
618int __trace_sched_cpu(struct cfs_rq *cfs_rq, struct sched_entity *se)
619{
620#ifdef CONFIG_FAIR_GROUP_SCHED
621 struct rq *rq = cfs_rq ? cfs_rq->rq : NULL;
622#else
623 struct rq *rq = cfs_rq ? container_of(cfs_rq, struct rq, cfs) : NULL;
624#endif
625 return rq ? cpu_of(rq)
626 : task_cpu((container_of(se, struct task_struct, se)));
627}
628
629static inline
630int __trace_sched_path(struct cfs_rq *cfs_rq, char *path, int len)
631{
632#ifdef CONFIG_FAIR_GROUP_SCHED
633 int l = path ? len : 0;
634
635 if (cfs_rq && task_group_is_autogroup(cfs_rq->tg))
636 return autogroup_path(cfs_rq->tg, path, l) + 1;
637 else if (cfs_rq && cfs_rq->tg->css.cgroup)
638 return cgroup_path(cfs_rq->tg->css.cgroup, path, l) + 1;
639#endif
640 if (path)
641 strcpy(path, "(null)");
642
643 return strlen("(null)");
644}
645
646static inline
647struct cfs_rq *__trace_sched_group_cfs_rq(struct sched_entity *se)
648{
649#ifdef CONFIG_FAIR_GROUP_SCHED
650 return se->my_q;
651#else
652 return NULL;
653#endif
654}
655#endif /* CREATE_TRACE_POINTS */
656
657#ifdef CONFIG_SCHED_WALT
658extern unsigned int sysctl_sched_use_walt_cpu_util;
659extern unsigned int sysctl_sched_use_walt_task_util;
660extern unsigned int walt_ravg_window;
661extern bool walt_disabled;
662
663#define walt_util(util_var, demand_sum) {\
664 u64 sum = demand_sum << SCHED_CAPACITY_SHIFT;\
665 do_div(sum, walt_ravg_window);\
666 util_var = (typeof(util_var))sum;\
667 }
668#endif
669
670/*
671 * Tracepoint for cfs_rq load tracking:
672 */
673TRACE_EVENT(sched_load_cfs_rq,
674
675 TP_PROTO(struct cfs_rq *cfs_rq),
676
677 TP_ARGS(cfs_rq),
678
679 TP_STRUCT__entry(
680 __field( int, cpu )
681 __dynamic_array(char, path,
682 __trace_sched_path(cfs_rq, NULL, 0) )
683 __field( unsigned long, load )
684 __field( unsigned long, util )
685 __field( unsigned long, util_pelt )
686 __field( unsigned long, util_walt )
687 ),
688
689 TP_fast_assign(
690 __entry->cpu = __trace_sched_cpu(cfs_rq, NULL);
691 __trace_sched_path(cfs_rq, __get_dynamic_array(path),
692 __get_dynamic_array_len(path));
693 __entry->load = cfs_rq->runnable_load_avg;
694 __entry->util = cfs_rq->avg.util_avg;
695 __entry->util_pelt = cfs_rq->avg.util_avg;
696 __entry->util_walt = 0;
697#ifdef CONFIG_SCHED_WALT
698 if (&cfs_rq->rq->cfs == cfs_rq) {
699 walt_util(__entry->util_walt,
700 cfs_rq->rq->prev_runnable_sum);
701 if (!walt_disabled && sysctl_sched_use_walt_cpu_util)
702 __entry->util = __entry->util_walt;
703 }
704#endif
705 ),
706
707 TP_printk("cpu=%d path=%s load=%lu util=%lu util_pelt=%lu util_walt=%lu",
708 __entry->cpu, __get_str(path), __entry->load, __entry->util,
709 __entry->util_pelt, __entry->util_walt)
710);
711
712/*
713 * Tracepoint for rt_rq load tracking:
714 */
715struct rt_rq;
716
717TRACE_EVENT(sched_load_rt_rq,
718
719 TP_PROTO(int cpu, struct rt_rq *rt_rq),
720
721 TP_ARGS(cpu, rt_rq),
722
723 TP_STRUCT__entry(
724 __field( int, cpu )
725 __field( unsigned long, util )
726 ),
727
728 TP_fast_assign(
729 __entry->cpu = cpu;
730 __entry->util = rt_rq->avg.util_avg;
731 ),
732
733 TP_printk("cpu=%d util=%lu", __entry->cpu,
734 __entry->util)
735);
736
737/*
738 * Tracepoint for sched_entity load tracking:
739 */
740TRACE_EVENT(sched_load_se,
741
742 TP_PROTO(struct sched_entity *se),
743
744 TP_ARGS(se),
745
746 TP_STRUCT__entry(
747 __field( int, cpu )
748 __dynamic_array(char, path,
749 __trace_sched_path(__trace_sched_group_cfs_rq(se), NULL, 0) )
750 __array( char, comm, TASK_COMM_LEN )
751 __field( pid_t, pid )
752 __field( unsigned long, load )
753 __field( unsigned long, util )
754 __field( unsigned long, util_pelt )
755 __field( unsigned long, util_walt )
756 ),
757
758 TP_fast_assign(
759 struct cfs_rq *gcfs_rq = __trace_sched_group_cfs_rq(se);
760 struct task_struct *p = gcfs_rq ? NULL
761 : container_of(se, struct task_struct, se);
762
763 __entry->cpu = __trace_sched_cpu(gcfs_rq, se);
764 __trace_sched_path(gcfs_rq, __get_dynamic_array(path),
765 __get_dynamic_array_len(path));
766 memcpy(__entry->comm, p ? p->comm : "(null)", TASK_COMM_LEN);
767 __entry->pid = p ? p->pid : -1;
768 __entry->load = se->avg.load_avg;
769 __entry->util = se->avg.util_avg;
770 __entry->util_pelt = __entry->util;
771 __entry->util_walt = 0;
772#ifdef CONFIG_SCHED_WALT
773 if (!se->my_q) {
774 struct task_struct *p = container_of(se, struct task_struct, se);
775 walt_util(__entry->util_walt, p->ravg.demand);
776 if (!walt_disabled && sysctl_sched_use_walt_task_util)
777 __entry->util = __entry->util_walt;
778 }
779#endif
780 ),
781
782 TP_printk("cpu=%d path=%s comm=%s pid=%d load=%lu util=%lu util_pelt=%lu util_walt=%lu",
783 __entry->cpu, __get_str(path), __entry->comm,
784 __entry->pid, __entry->load, __entry->util,
785 __entry->util_pelt, __entry->util_walt)
786);
787
788/*
789 * Tracepoint for task_group load tracking:
790 */
791#ifdef CONFIG_FAIR_GROUP_SCHED
792TRACE_EVENT(sched_load_tg,
793
794 TP_PROTO(struct cfs_rq *cfs_rq),
795
796 TP_ARGS(cfs_rq),
797
798 TP_STRUCT__entry(
799 __field( int, cpu )
800 __dynamic_array(char, path,
801 __trace_sched_path(cfs_rq, NULL, 0) )
802 __field( long, load )
803 ),
804
805 TP_fast_assign(
806 __entry->cpu = cfs_rq->rq->cpu;
807 __trace_sched_path(cfs_rq, __get_dynamic_array(path),
808 __get_dynamic_array_len(path));
809 __entry->load = atomic_long_read(&cfs_rq->tg->load_avg);
810 ),
811
812 TP_printk("cpu=%d path=%s load=%ld", __entry->cpu, __get_str(path),
813 __entry->load)
814);
815#endif /* CONFIG_FAIR_GROUP_SCHED */
816
817/*
818 * Tracepoint for accounting CPU boosted utilization
819 */
820TRACE_EVENT(sched_boost_cpu,
821
822 TP_PROTO(int cpu, unsigned long util, long margin),
823
824 TP_ARGS(cpu, util, margin),
825
826 TP_STRUCT__entry(
827 __field( int, cpu )
828 __field( unsigned long, util )
829 __field(long, margin )
830 ),
831
832 TP_fast_assign(
833 __entry->cpu = cpu;
834 __entry->util = util;
835 __entry->margin = margin;
836 ),
837
838 TP_printk("cpu=%d util=%lu margin=%ld",
839 __entry->cpu,
840 __entry->util,
841 __entry->margin)
842);
843
844/*
845 * Tracepoint for schedtune_tasks_update
846 */
847TRACE_EVENT(sched_tune_tasks_update,
848
849 TP_PROTO(struct task_struct *tsk, int cpu, int tasks, int idx,
850 int boost, int max_boost, u64 group_ts),
851
852 TP_ARGS(tsk, cpu, tasks, idx, boost, max_boost, group_ts),
853
854 TP_STRUCT__entry(
855 __array( char, comm, TASK_COMM_LEN )
856 __field( pid_t, pid )
857 __field( int, cpu )
858 __field( int, tasks )
859 __field( int, idx )
860 __field( int, boost )
861 __field( int, max_boost )
862 __field( u64, group_ts )
863 ),
864
865 TP_fast_assign(
866 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
867 __entry->pid = tsk->pid;
868 __entry->cpu = cpu;
869 __entry->tasks = tasks;
870 __entry->idx = idx;
871 __entry->boost = boost;
872 __entry->max_boost = max_boost;
873 __entry->group_ts = group_ts;
874 ),
875
876 TP_printk("pid=%d comm=%s "
877 "cpu=%d tasks=%d idx=%d boost=%d max_boost=%d timeout=%llu",
878 __entry->pid, __entry->comm,
879 __entry->cpu, __entry->tasks, __entry->idx,
880 __entry->boost, __entry->max_boost,
881 __entry->group_ts)
882);
883
884/*
885 * Tracepoint for schedtune_boostgroup_update
886 */
887TRACE_EVENT(sched_tune_boostgroup_update,
888
889 TP_PROTO(int cpu, int variation, int max_boost),
890
891 TP_ARGS(cpu, variation, max_boost),
892
893 TP_STRUCT__entry(
894 __field( int, cpu )
895 __field( int, variation )
896 __field( int, max_boost )
897 ),
898
899 TP_fast_assign(
900 __entry->cpu = cpu;
901 __entry->variation = variation;
902 __entry->max_boost = max_boost;
903 ),
904
905 TP_printk("cpu=%d variation=%d max_boost=%d",
906 __entry->cpu, __entry->variation, __entry->max_boost)
907);
908
909/*
910 * Tracepoint for accounting task boosted utilization
911 */
912TRACE_EVENT(sched_boost_task,
913
914 TP_PROTO(struct task_struct *tsk, unsigned long util, long margin),
915
916 TP_ARGS(tsk, util, margin),
917
918 TP_STRUCT__entry(
919 __array( char, comm, TASK_COMM_LEN )
920 __field( pid_t, pid )
921 __field( unsigned long, util )
922 __field( long, margin )
923
924 ),
925
926 TP_fast_assign(
927 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
928 __entry->pid = tsk->pid;
929 __entry->util = util;
930 __entry->margin = margin;
931 ),
932
933 TP_printk("comm=%s pid=%d util=%lu margin=%ld",
934 __entry->comm, __entry->pid,
935 __entry->util,
936 __entry->margin)
937);
938
939/*
940 * Tracepoint for system overutilized flag
941 */
942struct sched_domain;
943TRACE_EVENT_CONDITION(sched_overutilized,
944
945 TP_PROTO(struct sched_domain *sd, bool was_overutilized, bool overutilized),
946
947 TP_ARGS(sd, was_overutilized, overutilized),
948
949 TP_CONDITION(overutilized != was_overutilized),
950
951 TP_STRUCT__entry(
952 __field( bool, overutilized )
953 __array( char, cpulist , 32 )
954 ),
955
956 TP_fast_assign(
957 __entry->overutilized = overutilized;
958 scnprintf(__entry->cpulist, sizeof(__entry->cpulist), "%*pbl", cpumask_pr_args(sched_domain_span(sd)));
959 ),
960
961 TP_printk("overutilized=%d sd_span=%s",
962 __entry->overutilized ? 1 : 0, __entry->cpulist)
963);
964
965/*
966 * Tracepoint for find_best_target
967 */
968TRACE_EVENT(sched_find_best_target,
969
970 TP_PROTO(struct task_struct *tsk, bool prefer_idle,
971 unsigned long min_util, int start_cpu,
972 int best_idle, int best_active, int target),
973
974 TP_ARGS(tsk, prefer_idle, min_util, start_cpu,
975 best_idle, best_active, target),
976
977 TP_STRUCT__entry(
978 __array( char, comm, TASK_COMM_LEN )
979 __field( pid_t, pid )
980 __field( unsigned long, min_util )
981 __field( bool, prefer_idle )
982 __field( int, start_cpu )
983 __field( int, best_idle )
984 __field( int, best_active )
985 __field( int, target )
986 ),
987
988 TP_fast_assign(
989 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
990 __entry->pid = tsk->pid;
991 __entry->min_util = min_util;
992 __entry->prefer_idle = prefer_idle;
993 __entry->start_cpu = start_cpu;
994 __entry->best_idle = best_idle;
995 __entry->best_active = best_active;
996 __entry->target = target;
997 ),
998
999 TP_printk("pid=%d comm=%s prefer_idle=%d start_cpu=%d "
1000 "best_idle=%d best_active=%d target=%d",
1001 __entry->pid, __entry->comm,
1002 __entry->prefer_idle, __entry->start_cpu,
1003 __entry->best_idle, __entry->best_active,
1004 __entry->target)
1005);
1006
1007/*
1008 * Tracepoint for tasks' estimated utilization.
1009 */
1010TRACE_EVENT(sched_util_est_task,
1011
1012 TP_PROTO(struct task_struct *tsk, struct sched_avg *avg),
1013
1014 TP_ARGS(tsk, avg),
1015
1016 TP_STRUCT__entry(
1017 __array( char, comm, TASK_COMM_LEN )
1018 __field( pid_t, pid )
1019 __field( int, cpu )
1020 __field( unsigned int, util_avg )
1021 __field( unsigned int, est_enqueued )
1022 __field( unsigned int, est_ewma )
1023 ),
1024
1025 TP_fast_assign(
1026 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
1027 __entry->pid = tsk->pid;
1028 __entry->cpu = task_cpu(tsk);
1029 __entry->util_avg = avg->util_avg;
1030 __entry->est_enqueued = avg->util_est.enqueued;
1031 __entry->est_ewma = avg->util_est.ewma;
1032 ),
1033
1034 TP_printk("comm=%s pid=%d cpu=%d util_avg=%u util_est_ewma=%u util_est_enqueued=%u",
1035 __entry->comm,
1036 __entry->pid,
1037 __entry->cpu,
1038 __entry->util_avg,
1039 __entry->est_ewma,
1040 __entry->est_enqueued)
1041);
1042
1043/*
1044 * Tracepoint for root cfs_rq's estimated utilization.
1045 */
1046TRACE_EVENT(sched_util_est_cpu,
1047
1048 TP_PROTO(int cpu, struct cfs_rq *cfs_rq),
1049
1050 TP_ARGS(cpu, cfs_rq),
1051
1052 TP_STRUCT__entry(
1053 __field( int, cpu )
1054 __field( unsigned int, util_avg )
1055 __field( unsigned int, util_est_enqueued )
1056 ),
1057
1058 TP_fast_assign(
1059 __entry->cpu = cpu;
1060 __entry->util_avg = cfs_rq->avg.util_avg;
1061 __entry->util_est_enqueued = cfs_rq->avg.util_est.enqueued;
1062 ),
1063
1064 TP_printk("cpu=%d util_avg=%u util_est_enqueued=%u",
1065 __entry->cpu,
1066 __entry->util_avg,
1067 __entry->util_est_enqueued)
1068);
1069
1070#ifdef CONFIG_SCHED_WALT
1071struct rq;
1072
1073TRACE_EVENT(walt_update_task_ravg,
1074
1075 TP_PROTO(struct task_struct *p, struct rq *rq, int evt,
1076 u64 wallclock, u64 irqtime),
1077
1078 TP_ARGS(p, rq, evt, wallclock, irqtime),
1079
1080 TP_STRUCT__entry(
1081 __array( char, comm, TASK_COMM_LEN )
1082 __field( pid_t, pid )
1083 __field( pid_t, cur_pid )
1084 __field( u64, wallclock )
1085 __field( u64, mark_start )
1086 __field( u64, delta_m )
1087 __field( u64, win_start )
1088 __field( u64, delta )
1089 __field( u64, irqtime )
1090 __array( char, evt, 16 )
1091 __field(unsigned int, demand )
1092 __field(unsigned int, sum )
1093 __field( int, cpu )
1094 __field( u64, cs )
1095 __field( u64, ps )
1096 __field( u32, curr_window )
1097 __field( u32, prev_window )
1098 __field( u64, nt_cs )
1099 __field( u64, nt_ps )
1100 __field( u32, active_windows )
1101 ),
1102
1103 TP_fast_assign(
1104 static const char* walt_event_names[] =
1105 {
1106 "PUT_PREV_TASK",
1107 "PICK_NEXT_TASK",
1108 "TASK_WAKE",
1109 "TASK_MIGRATE",
1110 "TASK_UPDATE",
1111 "IRQ_UPDATE"
1112 };
1113 __entry->wallclock = wallclock;
1114 __entry->win_start = rq->window_start;
1115 __entry->delta = (wallclock - rq->window_start);
1116 strcpy(__entry->evt, walt_event_names[evt]);
1117 __entry->cpu = rq->cpu;
1118 __entry->cur_pid = rq->curr->pid;
1119 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
1120 __entry->pid = p->pid;
1121 __entry->mark_start = p->ravg.mark_start;
1122 __entry->delta_m = (wallclock - p->ravg.mark_start);
1123 __entry->demand = p->ravg.demand;
1124 __entry->sum = p->ravg.sum;
1125 __entry->irqtime = irqtime;
1126 __entry->cs = rq->curr_runnable_sum;
1127 __entry->ps = rq->prev_runnable_sum;
1128 __entry->curr_window = p->ravg.curr_window;
1129 __entry->prev_window = p->ravg.prev_window;
1130 __entry->nt_cs = rq->nt_curr_runnable_sum;
1131 __entry->nt_ps = rq->nt_prev_runnable_sum;
1132 __entry->active_windows = p->ravg.active_windows;
1133 ),
1134
1135 TP_printk("wallclock=%llu window_start=%llu delta=%llu event=%s cpu=%d cur_pid=%d pid=%d comm=%s"
1136 " mark_start=%llu delta=%llu demand=%u sum=%u irqtime=%llu"
1137 " curr_runnable_sum=%llu prev_runnable_sum=%llu cur_window=%u"
1138 " prev_window=%u nt_curr_runnable_sum=%llu nt_prev_runnable_sum=%llu active_windows=%u",
1139 __entry->wallclock, __entry->win_start, __entry->delta,
1140 __entry->evt, __entry->cpu, __entry->cur_pid,
1141 __entry->pid, __entry->comm, __entry->mark_start,
1142 __entry->delta_m, __entry->demand,
1143 __entry->sum, __entry->irqtime,
1144 __entry->cs, __entry->ps,
1145 __entry->curr_window, __entry->prev_window,
1146 __entry->nt_cs, __entry->nt_ps,
1147 __entry->active_windows
1148 )
1149);
1150
1151TRACE_EVENT(walt_update_history,
1152
1153 TP_PROTO(struct rq *rq, struct task_struct *p, u32 runtime, int samples,
1154 int evt),
1155
1156 TP_ARGS(rq, p, runtime, samples, evt),
1157
1158 TP_STRUCT__entry(
1159 __array( char, comm, TASK_COMM_LEN )
1160 __field( pid_t, pid )
1161 __field(unsigned int, runtime )
1162 __field( int, samples )
1163 __field( int, evt )
1164 __field( u64, demand )
1165 __field(unsigned int, walt_avg )
1166 __field(unsigned int, pelt_avg )
1167 __array( u32, hist, RAVG_HIST_SIZE_MAX)
1168 __field( int, cpu )
1169 ),
1170
1171 TP_fast_assign(
1172 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
1173 __entry->pid = p->pid;
1174 __entry->runtime = runtime;
1175 __entry->samples = samples;
1176 __entry->evt = evt;
1177 __entry->demand = p->ravg.demand;
1178 walt_util(__entry->walt_avg,__entry->demand);
1179 __entry->pelt_avg = p->se.avg.util_avg;
1180 memcpy(__entry->hist, p->ravg.sum_history,
1181 RAVG_HIST_SIZE_MAX * sizeof(u32));
1182 __entry->cpu = rq->cpu;
1183 ),
1184
1185 TP_printk("pid=%d comm=%s runtime=%u samples=%d event=%d demand=%llu ravg_window=%u"
1186 " walt=%u pelt=%u hist0=%u hist1=%u hist2=%u hist3=%u hist4=%u cpu=%d",
1187 __entry->pid, __entry->comm,
1188 __entry->runtime, __entry->samples, __entry->evt,
1189 __entry->demand,
1190 walt_ravg_window,
1191 __entry->walt_avg,
1192 __entry->pelt_avg,
1193 __entry->hist[0], __entry->hist[1],
1194 __entry->hist[2], __entry->hist[3],
1195 __entry->hist[4], __entry->cpu)
1196);
1197
1198TRACE_EVENT(walt_migration_update_sum,
1199
1200 TP_PROTO(struct rq *rq, struct task_struct *p),
1201
1202 TP_ARGS(rq, p),
1203
1204 TP_STRUCT__entry(
1205 __field(int, cpu )
1206 __field(int, pid )
1207 __field( u64, cs )
1208 __field( u64, ps )
1209 __field( s64, nt_cs )
1210 __field( s64, nt_ps )
1211 ),
1212
1213 TP_fast_assign(
1214 __entry->cpu = cpu_of(rq);
1215 __entry->cs = rq->curr_runnable_sum;
1216 __entry->ps = rq->prev_runnable_sum;
1217 __entry->nt_cs = (s64)rq->nt_curr_runnable_sum;
1218 __entry->nt_ps = (s64)rq->nt_prev_runnable_sum;
1219 __entry->pid = p->pid;
1220 ),
1221
1222 TP_printk("cpu=%d curr_runnable_sum=%llu prev_runnable_sum=%llu nt_curr_runnable_sum=%lld nt_prev_runnable_sum=%lld pid=%d",
1223 __entry->cpu, __entry->cs, __entry->ps,
1224 __entry->nt_cs, __entry->nt_ps, __entry->pid)
1225);
1226#endif /* CONFIG_SCHED_WALT */
1227#endif /* CONFIG_SMP */
1228#endif /* _TRACE_SCHED_H */
1229
1230/* This part must be outside protection */
1231#include <trace/define_trace.h>