blob: ba457e3603f3e320b9835a5762757d7d1910850b [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +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#include "eas_plus.h"
12
13
14/*
15 * Tracepoint for calling kthread_stop, performed to end a kthread:
16 */
17TRACE_EVENT(sched_kthread_stop,
18
19 TP_PROTO(struct task_struct *t),
20
21 TP_ARGS(t),
22
23 TP_STRUCT__entry(
24 __array( char, comm, TASK_COMM_LEN )
25 __field( pid_t, pid )
26 ),
27
28 TP_fast_assign(
29 memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
30 __entry->pid = t->pid;
31 ),
32
33 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
34);
35
36/*
37 * Tracepoint for the return value of the kthread stopping:
38 */
39TRACE_EVENT(sched_kthread_stop_ret,
40
41 TP_PROTO(int ret),
42
43 TP_ARGS(ret),
44
45 TP_STRUCT__entry(
46 __field( int, ret )
47 ),
48
49 TP_fast_assign(
50 __entry->ret = ret;
51 ),
52
53 TP_printk("ret=%d", __entry->ret)
54);
55
56/*
57 * Tracepoint for waking up a task:
58 */
59DECLARE_EVENT_CLASS(sched_wakeup_template,
60
61 TP_PROTO(struct task_struct *p),
62
63 TP_ARGS(__perf_task(p)),
64
65 TP_STRUCT__entry(
66 __array( char, comm, TASK_COMM_LEN )
67 __field( pid_t, pid )
68 __field( int, prio )
69 __field( int, success )
70 __field( int, target_cpu )
71 ),
72
73 TP_fast_assign(
74 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
75 __entry->pid = p->pid;
76 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
77 __entry->success = 1; /* rudiment, kill when possible */
78 __entry->target_cpu = task_cpu(p);
79 ),
80
81 TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
82 __entry->comm, __entry->pid, __entry->prio,
83 __entry->target_cpu)
84);
85
86/*
87 * Tracepoint called when waking a task; this tracepoint is guaranteed to be
88 * called from the waking context.
89 */
90DEFINE_EVENT(sched_wakeup_template, sched_waking,
91 TP_PROTO(struct task_struct *p),
92 TP_ARGS(p));
93
94/*
95 * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
96 * It it not always called from the waking context.
97 */
98DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
99 TP_PROTO(struct task_struct *p),
100 TP_ARGS(p));
101
102/*
103 * Tracepoint for waking up a new task:
104 */
105DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
106 TP_PROTO(struct task_struct *p),
107 TP_ARGS(p));
108
109#ifdef CREATE_TRACE_POINTS
110static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
111{
112 unsigned int state;
113
114#ifdef CONFIG_SCHED_DEBUG
115 BUG_ON(p != current);
116#endif /* CONFIG_SCHED_DEBUG */
117
118 /*
119 * Preemption ignores task state, therefore preempted tasks are always
120 * RUNNING (we will not have dequeued if state != RUNNING).
121 */
122 if (preempt)
123 return TASK_REPORT_MAX;
124
125 /*
126 * task_state_index() uses fls() and returns a value from 0-8 range.
127 * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using
128 * it for left shift operation to get the correct task->state
129 * mapping.
130 */
131 state = task_state_index(p);
132
133 return state ? (1 << (state - 1)) : state;
134}
135#endif /* CREATE_TRACE_POINTS */
136
137/*
138 * Tracepoint for task switches, performed by the scheduler:
139 */
140TRACE_EVENT(sched_switch,
141
142 TP_PROTO(bool preempt,
143 struct task_struct *prev,
144 struct task_struct *next),
145
146 TP_ARGS(preempt, prev, next),
147
148 TP_STRUCT__entry(
149 __array( char, prev_comm, TASK_COMM_LEN )
150 __field( pid_t, prev_pid )
151 __field( int, prev_prio )
152 __field( long, prev_state )
153 __array( char, next_comm, TASK_COMM_LEN )
154 __field( pid_t, next_pid )
155 __field( int, next_prio )
156#if defined(CONFIG_MTK_SCHED_TRACERS) && defined(CONFIG_CGROUPS)
157 __field(int, prev_cgrp_id)
158 __field(int, next_cgrp_id)
159 __field(int, prev_st_cgrp_id)
160 __field(int, next_st_cgrp_id)
161#endif
162 ),
163
164 TP_fast_assign(
165 memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
166 __entry->prev_pid = prev->pid;
167 __entry->prev_prio = prev->prio;
168 __entry->prev_state = __trace_sched_switch_state(preempt, prev);
169 memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
170 __entry->next_pid = next->pid;
171 __entry->next_prio = next->prio;
172#if defined(CONFIG_MTK_SCHED_TRACERS) && defined(CONFIG_CGROUPS)
173#ifdef CONFIG_CPUSETS
174 __entry->prev_cgrp_id = prev->cgroups->subsys[0]->cgroup->id;
175 __entry->next_cgrp_id = next->cgroups->subsys[0]->cgroup->id;
176#else
177 __entry->prev_cgrp_id = 0;
178 __entry->next_cgrp_id = 0;
179#endif
180#ifdef CONFIG_SCHED_TUNE
181 __entry->prev_st_cgrp_id = prev->cgroups->subsys[3]->cgroup->id;
182 __entry->next_st_cgrp_id = next->cgroups->subsys[3]->cgroup->id;
183#else
184 __entry->prev_st_cgrp_id = 0;
185 __entry->next_st_cgrp_id = 0;
186#endif
187#endif
188 /* XXX SCHED_DEADLINE */
189 ),
190
191#if defined(CONFIG_MTK_SCHED_TRACERS) && defined(CONFIG_CGROUPS)
192 TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d prev->cgrp=%d next->cgrp=%d prev->st=%d next->st=%d",
193 __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
194
195 (__entry->prev_state & (TASK_REPORT_MAX - 1)) ?
196 __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|",
197 { 0x01, "S" }, { 0x02, "D" }, { 0x04, "T" },
198 { 0x08, "t" }, { 0x10, "X" }, { 0x20, "Z" },
199 { 0x40, "P" }, { 0x80, "I" }) :
200 "R",
201
202 __entry->prev_state & TASK_REPORT_MAX ? "+" : "",
203 __entry->next_comm, __entry->next_pid, __entry->next_prio
204 , __entry->prev_cgrp_id
205 , __entry->next_cgrp_id
206 , __entry->prev_st_cgrp_id
207 , __entry->next_st_cgrp_id
208 )
209
210#else
211 TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
212 __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
213
214 (__entry->prev_state & (TASK_REPORT_MAX - 1)) ?
215 __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|",
216 { TASK_INTERRUPTIBLE, "S" },
217 { TASK_UNINTERRUPTIBLE, "D" },
218 { __TASK_STOPPED, "T" },
219 { __TASK_TRACED, "t" },
220 { EXIT_DEAD, "X" },
221 { EXIT_ZOMBIE, "Z" },
222 { TASK_PARKED, "P" },
223 { TASK_DEAD, "I" }) :
224 "R",
225
226 __entry->prev_state & TASK_REPORT_MAX ? "+" : "",
227 __entry->next_comm, __entry->next_pid, __entry->next_prio)
228#endif
229);
230
231/*
232 * Tracepoint for a task being migrated:
233 */
234TRACE_EVENT(sched_migrate_task,
235
236 TP_PROTO(struct task_struct *p, int dest_cpu),
237
238 TP_ARGS(p, dest_cpu),
239
240 TP_STRUCT__entry(
241 __array( char, comm, TASK_COMM_LEN )
242 __field( pid_t, pid )
243 __field( int, prio )
244 __field( int, orig_cpu )
245 __field( int, dest_cpu )
246 ),
247
248 TP_fast_assign(
249 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
250 __entry->pid = p->pid;
251 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
252 __entry->orig_cpu = task_cpu(p);
253 __entry->dest_cpu = dest_cpu;
254 ),
255
256 TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
257 __entry->comm, __entry->pid, __entry->prio,
258 __entry->orig_cpu, __entry->dest_cpu)
259);
260
261DECLARE_EVENT_CLASS(sched_process_template,
262
263 TP_PROTO(struct task_struct *p),
264
265 TP_ARGS(p),
266
267 TP_STRUCT__entry(
268 __array( char, comm, TASK_COMM_LEN )
269 __field( pid_t, pid )
270 __field( int, prio )
271 ),
272
273 TP_fast_assign(
274 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
275 __entry->pid = p->pid;
276 __entry->prio = p->prio; /* XXX SCHED_DEADLINE */
277 ),
278
279 TP_printk("comm=%s pid=%d prio=%d",
280 __entry->comm, __entry->pid, __entry->prio)
281);
282
283/*
284 * Tracepoint for freeing a task:
285 */
286DEFINE_EVENT(sched_process_template, sched_process_free,
287 TP_PROTO(struct task_struct *p),
288 TP_ARGS(p));
289
290
291/*
292 * Tracepoint for a task exiting:
293 */
294DEFINE_EVENT(sched_process_template, sched_process_exit,
295 TP_PROTO(struct task_struct *p),
296 TP_ARGS(p));
297
298/*
299 * Tracepoint for waiting on task to unschedule:
300 */
301DEFINE_EVENT(sched_process_template, sched_wait_task,
302 TP_PROTO(struct task_struct *p),
303 TP_ARGS(p));
304
305/*
306 * Tracepoint for a waiting task:
307 */
308TRACE_EVENT(sched_process_wait,
309
310 TP_PROTO(struct pid *pid),
311
312 TP_ARGS(pid),
313
314 TP_STRUCT__entry(
315 __array( char, comm, TASK_COMM_LEN )
316 __field( pid_t, pid )
317 __field( int, prio )
318 ),
319
320 TP_fast_assign(
321 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
322 __entry->pid = pid_nr(pid);
323 __entry->prio = current->prio; /* XXX SCHED_DEADLINE */
324 ),
325
326 TP_printk("comm=%s pid=%d prio=%d",
327 __entry->comm, __entry->pid, __entry->prio)
328);
329
330/*
331 * Tracepoint for do_fork:
332 */
333TRACE_EVENT(sched_process_fork,
334
335 TP_PROTO(struct task_struct *parent, struct task_struct *child),
336
337 TP_ARGS(parent, child),
338
339 TP_STRUCT__entry(
340 __array( char, parent_comm, TASK_COMM_LEN )
341 __field( pid_t, parent_pid )
342 __array( char, child_comm, TASK_COMM_LEN )
343 __field( pid_t, child_pid )
344 ),
345
346 TP_fast_assign(
347 memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
348 __entry->parent_pid = parent->pid;
349 memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
350 __entry->child_pid = child->pid;
351 ),
352
353 TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
354 __entry->parent_comm, __entry->parent_pid,
355 __entry->child_comm, __entry->child_pid)
356);
357
358/*
359 * Tracepoint for exec:
360 */
361TRACE_EVENT(sched_process_exec,
362
363 TP_PROTO(struct task_struct *p, pid_t old_pid,
364 struct linux_binprm *bprm),
365
366 TP_ARGS(p, old_pid, bprm),
367
368 TP_STRUCT__entry(
369 __string( filename, bprm->filename )
370 __field( pid_t, pid )
371 __field( pid_t, old_pid )
372 ),
373
374 TP_fast_assign(
375 __assign_str(filename, bprm->filename);
376 __entry->pid = p->pid;
377 __entry->old_pid = old_pid;
378 ),
379
380 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
381 __entry->pid, __entry->old_pid)
382);
383
384/*
385 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
386 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
387 */
388DECLARE_EVENT_CLASS(sched_stat_template,
389
390 TP_PROTO(struct task_struct *tsk, u64 delay),
391
392 TP_ARGS(__perf_task(tsk), __perf_count(delay)),
393
394 TP_STRUCT__entry(
395 __array( char, comm, TASK_COMM_LEN )
396 __field( pid_t, pid )
397 __field( u64, delay )
398 ),
399
400 TP_fast_assign(
401 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
402 __entry->pid = tsk->pid;
403 __entry->delay = delay;
404 ),
405
406 TP_printk("comm=%s pid=%d delay=%Lu [ns]",
407 __entry->comm, __entry->pid,
408 (unsigned long long)__entry->delay)
409);
410
411
412/*
413 * Tracepoint for accounting wait time (time the task is runnable
414 * but not actually running due to scheduler contention).
415 */
416DEFINE_EVENT(sched_stat_template, sched_stat_wait,
417 TP_PROTO(struct task_struct *tsk, u64 delay),
418 TP_ARGS(tsk, delay));
419
420/*
421 * Tracepoint for accounting sleep time (time the task is not runnable,
422 * including iowait, see below).
423 */
424DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
425 TP_PROTO(struct task_struct *tsk, u64 delay),
426 TP_ARGS(tsk, delay));
427
428/*
429 * Tracepoint for accounting iowait time (time the task is not runnable
430 * due to waiting on IO to complete).
431 */
432DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
433 TP_PROTO(struct task_struct *tsk, u64 delay),
434 TP_ARGS(tsk, delay));
435
436/*
437 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
438 */
439DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
440 TP_PROTO(struct task_struct *tsk, u64 delay),
441 TP_ARGS(tsk, delay));
442
443/*
444 * Tracepoint for recording the cause of uninterruptible sleep.
445 */
446TRACE_EVENT(sched_blocked_reason,
447
448 TP_PROTO(struct task_struct *tsk),
449
450 TP_ARGS(tsk),
451
452 TP_STRUCT__entry(
453 __field( pid_t, pid )
454 __field( void*, caller )
455 __field( bool, io_wait )
456 ),
457
458 TP_fast_assign(
459 __entry->pid = tsk->pid;
460 __entry->caller = (void*)get_wchan(tsk);
461 __entry->io_wait = tsk->in_iowait;
462 ),
463
464 TP_printk("pid=%d iowait=%d caller=%pS", __entry->pid, __entry->io_wait, __entry->caller)
465);
466
467/*
468 * Tracepoint for accounting runtime (time the task is executing
469 * on a CPU).
470 */
471DECLARE_EVENT_CLASS(sched_stat_runtime,
472
473 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
474
475 TP_ARGS(tsk, __perf_count(runtime), vruntime),
476
477 TP_STRUCT__entry(
478 __array( char, comm, TASK_COMM_LEN )
479 __field( pid_t, pid )
480 __field( u64, runtime )
481 __field( u64, vruntime )
482 ),
483
484 TP_fast_assign(
485 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
486 __entry->pid = tsk->pid;
487 __entry->runtime = runtime;
488 __entry->vruntime = vruntime;
489 ),
490
491 TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
492 __entry->comm, __entry->pid,
493 (unsigned long long)__entry->runtime,
494 (unsigned long long)__entry->vruntime)
495);
496
497DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
498 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
499 TP_ARGS(tsk, runtime, vruntime));
500
501/*
502 * Tracepoint for showing priority inheritance modifying a tasks
503 * priority.
504 */
505TRACE_EVENT(sched_pi_setprio,
506
507 TP_PROTO(struct task_struct *tsk, struct task_struct *pi_task),
508
509 TP_ARGS(tsk, pi_task),
510
511 TP_STRUCT__entry(
512 __array( char, comm, TASK_COMM_LEN )
513 __field( pid_t, pid )
514 __field( int, oldprio )
515 __field( int, newprio )
516 ),
517
518 TP_fast_assign(
519 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
520 __entry->pid = tsk->pid;
521 __entry->oldprio = tsk->prio;
522 __entry->newprio = pi_task ?
523 min(tsk->normal_prio, pi_task->prio) :
524 tsk->normal_prio;
525 /* XXX SCHED_DEADLINE bits missing */
526 ),
527
528 TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
529 __entry->comm, __entry->pid,
530 __entry->oldprio, __entry->newprio)
531);
532
533#ifdef CONFIG_DETECT_HUNG_TASK
534TRACE_EVENT(sched_process_hang,
535 TP_PROTO(struct task_struct *tsk),
536 TP_ARGS(tsk),
537
538 TP_STRUCT__entry(
539 __array( char, comm, TASK_COMM_LEN )
540 __field( pid_t, pid )
541 ),
542
543 TP_fast_assign(
544 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
545 __entry->pid = tsk->pid;
546 ),
547
548 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
549);
550#endif /* CONFIG_DETECT_HUNG_TASK */
551
552DECLARE_EVENT_CLASS(sched_move_task_template,
553
554 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
555
556 TP_ARGS(tsk, src_cpu, dst_cpu),
557
558 TP_STRUCT__entry(
559 __field( pid_t, pid )
560 __field( pid_t, tgid )
561 __field( pid_t, ngid )
562 __field( int, src_cpu )
563 __field( int, src_nid )
564 __field( int, dst_cpu )
565 __field( int, dst_nid )
566 ),
567
568 TP_fast_assign(
569 __entry->pid = task_pid_nr(tsk);
570 __entry->tgid = task_tgid_nr(tsk);
571 __entry->ngid = task_numa_group_id(tsk);
572 __entry->src_cpu = src_cpu;
573 __entry->src_nid = cpu_to_node(src_cpu);
574 __entry->dst_cpu = dst_cpu;
575 __entry->dst_nid = cpu_to_node(dst_cpu);
576 ),
577
578 TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
579 __entry->pid, __entry->tgid, __entry->ngid,
580 __entry->src_cpu, __entry->src_nid,
581 __entry->dst_cpu, __entry->dst_nid)
582);
583
584/*
585 * Tracks migration of tasks from one runqueue to another. Can be used to
586 * detect if automatic NUMA balancing is bouncing between nodes
587 */
588DEFINE_EVENT(sched_move_task_template, sched_move_numa,
589 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
590
591 TP_ARGS(tsk, src_cpu, dst_cpu)
592);
593
594DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
595 TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
596
597 TP_ARGS(tsk, src_cpu, dst_cpu)
598);
599
600TRACE_EVENT(sched_swap_numa,
601
602 TP_PROTO(struct task_struct *src_tsk, int src_cpu,
603 struct task_struct *dst_tsk, int dst_cpu),
604
605 TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
606
607 TP_STRUCT__entry(
608 __field( pid_t, src_pid )
609 __field( pid_t, src_tgid )
610 __field( pid_t, src_ngid )
611 __field( int, src_cpu )
612 __field( int, src_nid )
613 __field( pid_t, dst_pid )
614 __field( pid_t, dst_tgid )
615 __field( pid_t, dst_ngid )
616 __field( int, dst_cpu )
617 __field( int, dst_nid )
618 ),
619
620 TP_fast_assign(
621 __entry->src_pid = task_pid_nr(src_tsk);
622 __entry->src_tgid = task_tgid_nr(src_tsk);
623 __entry->src_ngid = task_numa_group_id(src_tsk);
624 __entry->src_cpu = src_cpu;
625 __entry->src_nid = cpu_to_node(src_cpu);
626 __entry->dst_pid = task_pid_nr(dst_tsk);
627 __entry->dst_tgid = task_tgid_nr(dst_tsk);
628 __entry->dst_ngid = task_numa_group_id(dst_tsk);
629 __entry->dst_cpu = dst_cpu;
630 __entry->dst_nid = cpu_to_node(dst_cpu);
631 ),
632
633 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",
634 __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
635 __entry->src_cpu, __entry->src_nid,
636 __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
637 __entry->dst_cpu, __entry->dst_nid)
638);
639
640/*
641 * Tracepoint for waking a polling cpu without an IPI.
642 */
643TRACE_EVENT(sched_wake_idle_without_ipi,
644
645 TP_PROTO(int cpu),
646
647 TP_ARGS(cpu),
648
649 TP_STRUCT__entry(
650 __field( int, cpu )
651 ),
652
653 TP_fast_assign(
654 __entry->cpu = cpu;
655 ),
656
657 TP_printk("cpu=%d", __entry->cpu)
658);
659
660#ifdef CONFIG_SMP
661#ifdef CREATE_TRACE_POINTS
662static inline
663int __trace_sched_cpu(struct cfs_rq *cfs_rq, struct sched_entity *se)
664{
665#ifdef CONFIG_FAIR_GROUP_SCHED
666 struct rq *rq = cfs_rq ? cfs_rq->rq : NULL;
667#else
668 struct rq *rq = cfs_rq ? container_of(cfs_rq, struct rq, cfs) : NULL;
669#endif
670 return rq ? cpu_of(rq)
671 : task_cpu((container_of(se, struct task_struct, se)));
672}
673
674static inline
675int __trace_sched_path(struct cfs_rq *cfs_rq, char *path, int len)
676{
677#ifdef CONFIG_FAIR_GROUP_SCHED
678 int l = path ? len : 0;
679
680 if (cfs_rq && task_group_is_autogroup(cfs_rq->tg))
681 return autogroup_path(cfs_rq->tg, path, l) + 1;
682 else if (cfs_rq && cfs_rq->tg->css.cgroup)
683 return cgroup_path(cfs_rq->tg->css.cgroup, path, l) + 1;
684#endif
685 if (path)
686 strcpy(path, "(null)");
687
688 return strlen("(null)");
689}
690
691static inline
692struct cfs_rq *__trace_sched_group_cfs_rq(struct sched_entity *se)
693{
694#ifdef CONFIG_FAIR_GROUP_SCHED
695 return se->my_q;
696#else
697 return NULL;
698#endif
699}
700#endif /* CREATE_TRACE_POINTS */
701
702/*
703 * Tracepoint for cfs_rq load tracking:
704 */
705TRACE_EVENT(sched_load_cfs_rq,
706
707 TP_PROTO(struct cfs_rq *cfs_rq),
708
709 TP_ARGS(cfs_rq),
710
711 TP_STRUCT__entry(
712 __field( int, cpu )
713 __dynamic_array(char, path,
714 __trace_sched_path(cfs_rq, NULL, 0) )
715 __field( unsigned long, load )
716 __field( unsigned long, rbl_load )
717 __field( unsigned long, util )
718 ),
719
720 TP_fast_assign(
721 __entry->cpu = __trace_sched_cpu(cfs_rq, NULL);
722 __trace_sched_path(cfs_rq, __get_dynamic_array(path),
723 __get_dynamic_array_len(path));
724 __entry->load = cfs_rq->avg.load_avg;
725 __entry->rbl_load = cfs_rq->avg.runnable_load_avg;
726 __entry->util = cfs_rq->avg.util_avg;
727 ),
728
729 TP_printk("cpu=%d path=%s load=%lu rbl_load=%lu util=%lu",
730 __entry->cpu, __get_str(path), __entry->load,
731 __entry->rbl_load,__entry->util)
732);
733
734/*
735 * Tracepoint for rt_rq load tracking:
736 */
737struct rq;
738TRACE_EVENT(sched_load_rt_rq,
739
740 TP_PROTO(struct rq *rq),
741
742 TP_ARGS(rq),
743
744 TP_STRUCT__entry(
745 __field( int, cpu )
746 __field( unsigned long, util )
747 ),
748
749 TP_fast_assign(
750 __entry->cpu = rq->cpu;
751 __entry->util = rq->avg_rt.util_avg;
752 ),
753
754 TP_printk("cpu=%d util=%lu", __entry->cpu,
755 __entry->util)
756);
757
758/*
759 * Tracepoint for sched_entity load tracking:
760 */
761TRACE_EVENT(sched_load_se,
762
763 TP_PROTO(struct sched_entity *se),
764
765 TP_ARGS(se),
766
767 TP_STRUCT__entry(
768 __field( int, cpu )
769 __dynamic_array(char, path,
770 __trace_sched_path(__trace_sched_group_cfs_rq(se), NULL, 0) )
771 __array( char, comm, TASK_COMM_LEN )
772 __field( pid_t, pid )
773 __field( unsigned long, load )
774 __field( unsigned long, rbl_load )
775 __field( unsigned long, util )
776 ),
777
778 TP_fast_assign(
779 struct cfs_rq *gcfs_rq = __trace_sched_group_cfs_rq(se);
780 struct task_struct *p = gcfs_rq ? NULL
781 : container_of(se, struct task_struct, se);
782
783 __entry->cpu = __trace_sched_cpu(gcfs_rq, se);
784 __trace_sched_path(gcfs_rq, __get_dynamic_array(path),
785 __get_dynamic_array_len(path));
786 memcpy(__entry->comm, p ? p->comm : "(null)",
787 p ? TASK_COMM_LEN : sizeof("(null)"));
788 __entry->pid = p ? p->pid : -1;
789 __entry->load = se->avg.load_avg;
790 __entry->rbl_load = se->avg.runnable_load_avg;
791 __entry->util = se->avg.util_avg;
792 ),
793
794 TP_printk("cpu=%d path=%s comm=%s pid=%d load=%lu rbl_load=%lu util=%lu",
795 __entry->cpu, __get_str(path), __entry->comm, __entry->pid,
796 __entry->load, __entry->rbl_load, __entry->util)
797);
798
799/*
800 * Tracepoint for task_group load tracking:
801 */
802#ifdef CONFIG_FAIR_GROUP_SCHED
803TRACE_EVENT(sched_load_tg,
804
805 TP_PROTO(struct cfs_rq *cfs_rq),
806
807 TP_ARGS(cfs_rq),
808
809 TP_STRUCT__entry(
810 __field( int, cpu )
811 __dynamic_array(char, path,
812 __trace_sched_path(cfs_rq, NULL, 0) )
813 __field( long, load )
814 ),
815
816 TP_fast_assign(
817 __entry->cpu = cfs_rq->rq->cpu;
818 __trace_sched_path(cfs_rq, __get_dynamic_array(path),
819 __get_dynamic_array_len(path));
820 __entry->load = atomic_long_read(&cfs_rq->tg->load_avg);
821 ),
822
823 TP_printk("cpu=%d path=%s load=%ld", __entry->cpu, __get_str(path),
824 __entry->load)
825);
826#endif /* CONFIG_FAIR_GROUP_SCHED */
827
828/*
829 * Tracepoint for tasks' estimated utilization.
830 */
831TRACE_EVENT(sched_util_est_task,
832
833 TP_PROTO(struct task_struct *tsk, struct sched_avg *avg),
834
835 TP_ARGS(tsk, avg),
836
837 TP_STRUCT__entry(
838 __array( char, comm, TASK_COMM_LEN )
839 __field( pid_t, pid )
840 __field( int, cpu )
841 __field( unsigned int, util_avg )
842 __field( unsigned int, est_enqueued )
843 __field( unsigned int, est_ewma )
844
845 ),
846
847 TP_fast_assign(
848 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
849 __entry->pid = tsk->pid;
850 __entry->cpu = task_cpu(tsk);
851 __entry->util_avg = avg->util_avg;
852 __entry->est_enqueued = avg->util_est.enqueued;
853 __entry->est_ewma = avg->util_est.ewma;
854 ),
855
856 TP_printk("comm=%s pid=%d cpu=%d util_avg=%u util_est_ewma=%u util_est_enqueued=%u",
857 __entry->comm,
858 __entry->pid,
859 __entry->cpu,
860 __entry->util_avg,
861 __entry->est_ewma,
862 __entry->est_enqueued)
863);
864
865/*
866 * Tracepoint for root cfs_rq's estimated utilization.
867 */
868TRACE_EVENT(sched_util_est_cpu,
869
870 TP_PROTO(int cpu, struct cfs_rq *cfs_rq),
871
872 TP_ARGS(cpu, cfs_rq),
873
874 TP_STRUCT__entry(
875 __field( int, cpu )
876 __field( unsigned int, util_avg )
877 __field( unsigned int, util_est_enqueued )
878 ),
879
880 TP_fast_assign(
881 __entry->cpu = cpu;
882 __entry->util_avg = cfs_rq->avg.util_avg;
883 __entry->util_est_enqueued = cfs_rq->avg.util_est.enqueued;
884 ),
885
886 TP_printk("cpu=%d util_avg=%u util_est_enqueued=%u",
887 __entry->cpu,
888 __entry->util_avg,
889 __entry->util_est_enqueued)
890);
891
892/*
893 * Tracepoint for find_best_target
894 */
895TRACE_EVENT(sched_find_best_target,
896
897 TP_PROTO(struct task_struct *tsk, bool prefer_idle,
898 unsigned long min_util, int best_idle, int best_active,
899 int target, int backup),
900
901 TP_ARGS(tsk, prefer_idle, min_util, best_idle,
902 best_active, target, backup),
903
904 TP_STRUCT__entry(
905 __array( char, comm, TASK_COMM_LEN )
906 __field( pid_t, pid )
907 __field( unsigned long, min_util )
908 __field( bool, prefer_idle )
909 __field( int, best_idle )
910 __field( int, best_active )
911 __field( int, target )
912 __field( int, backup )
913 ),
914
915 TP_fast_assign(
916 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
917 __entry->pid = tsk->pid;
918 __entry->min_util = min_util;
919 __entry->prefer_idle = prefer_idle;
920 __entry->best_idle = best_idle;
921 __entry->best_active = best_active;
922 __entry->target = target;
923 __entry->backup = backup;
924 ),
925
926 TP_printk("pid=%d comm=%s prefer_idle=%d "
927 "best_idle=%d best_active=%d target=%d backup=%d",
928 __entry->pid, __entry->comm, __entry->prefer_idle,
929 __entry->best_idle, __entry->best_active,
930 __entry->target, __entry->backup)
931);
932
933/*
934 * Tracepoint for accounting CPU boosted utilization
935 */
936TRACE_EVENT(sched_boost_cpu,
937
938 TP_PROTO(int cpu, unsigned long util, long margin),
939
940 TP_ARGS(cpu, util, margin),
941
942 TP_STRUCT__entry(
943 __field( int, cpu )
944 __field( unsigned long, util )
945 __field(long, margin )
946 ),
947
948 TP_fast_assign(
949 __entry->cpu = cpu;
950 __entry->util = util;
951 __entry->margin = margin;
952 ),
953
954 TP_printk("cpu=%d util=%lu margin=%ld",
955 __entry->cpu,
956 __entry->util,
957 __entry->margin)
958);
959
960/*
961 * Tracepoint for schedtune_tasks_update
962 */
963TRACE_EVENT(sched_tune_tasks_update,
964
965 TP_PROTO(struct task_struct *tsk, int cpu, int tasks, int idx,
966 int boost, int max_boost, u64 group_ts),
967
968 TP_ARGS(tsk, cpu, tasks, idx, boost, max_boost, group_ts),
969
970 TP_STRUCT__entry(
971 __array( char, comm, TASK_COMM_LEN )
972 __field( pid_t, pid )
973 __field( int, cpu )
974 __field( int, tasks )
975 __field( int, idx )
976 __field( int, boost )
977 __field( int, max_boost )
978 __field( u64, group_ts )
979 ),
980
981 TP_fast_assign(
982 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
983 __entry->pid = tsk->pid;
984 __entry->cpu = cpu;
985 __entry->tasks = tasks;
986 __entry->idx = idx;
987 __entry->boost = boost;
988 __entry->max_boost = max_boost;
989 __entry->group_ts = group_ts;
990 ),
991
992 TP_printk("pid=%d comm=%s "
993 "cpu=%d tasks=%d idx=%d boost=%d max_boost=%d timeout=%llu",
994 __entry->pid, __entry->comm,
995 __entry->cpu, __entry->tasks, __entry->idx,
996 __entry->boost, __entry->max_boost,
997 __entry->group_ts)
998);
999
1000/*
1001 * Tracepoint for schedtune_boostgroup_update
1002 */
1003TRACE_EVENT(sched_tune_boostgroup_update,
1004
1005 TP_PROTO(int cpu, int variation, int max_boost),
1006
1007 TP_ARGS(cpu, variation, max_boost),
1008
1009 TP_STRUCT__entry(
1010 __field( int, cpu )
1011 __field( int, variation )
1012 __field( int, max_boost )
1013 ),
1014
1015 TP_fast_assign(
1016 __entry->cpu = cpu;
1017 __entry->variation = variation;
1018 __entry->max_boost = max_boost;
1019 ),
1020
1021 TP_printk("cpu=%d variation=%d max_boost=%d",
1022 __entry->cpu, __entry->variation, __entry->max_boost)
1023);
1024
1025/*
1026 * Tracepoint for accounting task boosted utilization
1027 */
1028TRACE_EVENT(sched_boost_task,
1029
1030 TP_PROTO(struct task_struct *tsk, unsigned long util, long margin),
1031
1032 TP_ARGS(tsk, util, margin),
1033
1034 TP_STRUCT__entry(
1035 __array( char, comm, TASK_COMM_LEN )
1036 __field( pid_t, pid )
1037 __field( unsigned long, util )
1038 __field( long, margin )
1039
1040 ),
1041
1042 TP_fast_assign(
1043 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
1044 __entry->pid = tsk->pid;
1045 __entry->util = util;
1046 __entry->margin = margin;
1047 ),
1048
1049 TP_printk("comm=%s pid=%d util=%lu margin=%ld",
1050 __entry->comm, __entry->pid,
1051 __entry->util,
1052 __entry->margin)
1053);
1054
1055/*
1056 * Tracepoint for system overutilized flag
1057*/
1058TRACE_EVENT(sched_overutilized,
1059
1060 TP_PROTO(int overutilized),
1061
1062 TP_ARGS(overutilized),
1063
1064 TP_STRUCT__entry(
1065 __field( int, overutilized )
1066 ),
1067
1068 TP_fast_assign(
1069 __entry->overutilized = overutilized;
1070 ),
1071
1072 TP_printk("overutilized=%d",
1073 __entry->overutilized)
1074);
1075
1076#endif /* CONFIG_SMP */
1077#endif /* _TRACE_SCHED_H */
1078
1079/* This part must be outside protection */
1080#include <trace/define_trace.h>