]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/sched/debug.c
sched: Aggregate load contributed by task entities on parenting cfs_rq
[mirror_ubuntu-zesty-kernel.git] / kernel / sched / debug.c
CommitLineData
43ae34cb 1/*
391e43da 2 * kernel/sched/debug.c
43ae34cb
IM
3 *
4 * Print the CFS rbtree
5 *
6 * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/proc_fs.h>
14#include <linux/sched.h>
15#include <linux/seq_file.h>
16#include <linux/kallsyms.h>
17#include <linux/utsname.h>
18
029632fb
PZ
19#include "sched.h"
20
efe25c2c
BR
21static DEFINE_SPINLOCK(sched_debug_lock);
22
43ae34cb
IM
23/*
24 * This allows printing both to /proc/sched_debug and
25 * to the console
26 */
27#define SEQ_printf(m, x...) \
28 do { \
29 if (m) \
30 seq_printf(m, x); \
31 else \
32 printk(x); \
33 } while (0)
34
ef83a571
IM
35/*
36 * Ease the printing of nsec fields:
37 */
90b2628f 38static long long nsec_high(unsigned long long nsec)
ef83a571 39{
90b2628f 40 if ((long long)nsec < 0) {
ef83a571
IM
41 nsec = -nsec;
42 do_div(nsec, 1000000);
43 return -nsec;
44 }
45 do_div(nsec, 1000000);
46
47 return nsec;
48}
49
90b2628f 50static unsigned long nsec_low(unsigned long long nsec)
ef83a571 51{
90b2628f 52 if ((long long)nsec < 0)
ef83a571
IM
53 nsec = -nsec;
54
55 return do_div(nsec, 1000000);
56}
57
58#define SPLIT_NS(x) nsec_high(x), nsec_low(x)
59
ff9b48c3 60#ifdef CONFIG_FAIR_GROUP_SCHED
5091faa4 61static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
ff9b48c3
BR
62{
63 struct sched_entity *se = tg->se[cpu];
ff9b48c3
BR
64
65#define P(F) \
66 SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
67#define PN(F) \
68 SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
69
18bf2805
BS
70 if (!se) {
71 struct sched_avg *avg = &cpu_rq(cpu)->avg;
72 P(avg->runnable_avg_sum);
73 P(avg->runnable_avg_period);
74 return;
75 }
76
77
ff9b48c3
BR
78 PN(se->exec_start);
79 PN(se->vruntime);
80 PN(se->sum_exec_runtime);
81#ifdef CONFIG_SCHEDSTATS
41acab88
LDM
82 PN(se->statistics.wait_start);
83 PN(se->statistics.sleep_start);
84 PN(se->statistics.block_start);
85 PN(se->statistics.sleep_max);
86 PN(se->statistics.block_max);
87 PN(se->statistics.exec_max);
88 PN(se->statistics.slice_max);
89 PN(se->statistics.wait_max);
90 PN(se->statistics.wait_sum);
91 P(se->statistics.wait_count);
ff9b48c3
BR
92#endif
93 P(se->load.weight);
9d85f21c
PT
94#ifdef CONFIG_SMP
95 P(se->avg.runnable_avg_sum);
96 P(se->avg.runnable_avg_period);
2dac754e 97 P(se->avg.load_avg_contrib);
9d85f21c 98#endif
ff9b48c3
BR
99#undef PN
100#undef P
101}
102#endif
103
efe25c2c
BR
104#ifdef CONFIG_CGROUP_SCHED
105static char group_path[PATH_MAX];
106
107static char *task_group_path(struct task_group *tg)
108{
8ecedd7a
BR
109 if (autogroup_path(tg, group_path, PATH_MAX))
110 return group_path;
111
efe25c2c
BR
112 /*
113 * May be NULL if the underlying cgroup isn't fully-created yet
114 */
115 if (!tg->css.cgroup) {
116 group_path[0] = '\0';
117 return group_path;
118 }
119 cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
120 return group_path;
121}
122#endif
123
43ae34cb 124static void
a48da48b 125print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
43ae34cb
IM
126{
127 if (rq->curr == p)
128 SEQ_printf(m, "R");
129 else
130 SEQ_printf(m, " ");
131
ef83a571 132 SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
43ae34cb 133 p->comm, p->pid,
ef83a571 134 SPLIT_NS(p->se.vruntime),
43ae34cb 135 (long long)(p->nvcsw + p->nivcsw),
6f605d83 136 p->prio);
6cfb0d5d 137#ifdef CONFIG_SCHEDSTATS
d19ca308 138 SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
ef83a571
IM
139 SPLIT_NS(p->se.vruntime),
140 SPLIT_NS(p->se.sum_exec_runtime),
41acab88 141 SPLIT_NS(p->se.statistics.sum_sleep_runtime));
6cfb0d5d 142#else
d19ca308 143 SEQ_printf(m, "%15Ld %15Ld %15Ld.%06ld %15Ld.%06ld %15Ld.%06ld",
ef83a571 144 0LL, 0LL, 0LL, 0L, 0LL, 0L, 0LL, 0L);
6cfb0d5d 145#endif
efe25c2c
BR
146#ifdef CONFIG_CGROUP_SCHED
147 SEQ_printf(m, " %s", task_group_path(task_group(p)));
148#endif
d19ca308 149
d19ca308 150 SEQ_printf(m, "\n");
43ae34cb
IM
151}
152
a48da48b 153static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
43ae34cb
IM
154{
155 struct task_struct *g, *p;
ab63a633 156 unsigned long flags;
43ae34cb
IM
157
158 SEQ_printf(m,
159 "\nrunnable tasks:\n"
c86da3a3
MG
160 " task PID tree-key switches prio"
161 " exec-runtime sum-exec sum-sleep\n"
1a75b94f 162 "------------------------------------------------------"
c86da3a3 163 "----------------------------------------------------\n");
43ae34cb 164
ab63a633 165 read_lock_irqsave(&tasklist_lock, flags);
43ae34cb
IM
166
167 do_each_thread(g, p) {
fd2f4419 168 if (!p->on_rq || task_cpu(p) != rq_cpu)
43ae34cb
IM
169 continue;
170
a48da48b 171 print_task(m, rq, p);
43ae34cb
IM
172 } while_each_thread(g, p);
173
ab63a633 174 read_unlock_irqrestore(&tasklist_lock, flags);
43ae34cb
IM
175}
176
5cef9eca 177void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
43ae34cb 178{
86d9560c
IM
179 s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
180 spread, rq0_min_vruntime, spread0;
348ec61e 181 struct rq *rq = cpu_rq(cpu);
67e12eac
IM
182 struct sched_entity *last;
183 unsigned long flags;
184
efe25c2c
BR
185#ifdef CONFIG_FAIR_GROUP_SCHED
186 SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
187#else
ada18de2 188 SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
efe25c2c 189#endif
ef83a571
IM
190 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
191 SPLIT_NS(cfs_rq->exec_clock));
67e12eac 192
05fa785c 193 raw_spin_lock_irqsave(&rq->lock, flags);
67e12eac 194 if (cfs_rq->rb_leftmost)
ac53db59 195 MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime;
67e12eac
IM
196 last = __pick_last_entity(cfs_rq);
197 if (last)
198 max_vruntime = last->vruntime;
5ac5c4d6 199 min_vruntime = cfs_rq->min_vruntime;
348ec61e 200 rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime;
05fa785c 201 raw_spin_unlock_irqrestore(&rq->lock, flags);
ef83a571
IM
202 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime",
203 SPLIT_NS(MIN_vruntime));
204 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime",
205 SPLIT_NS(min_vruntime));
206 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime",
207 SPLIT_NS(max_vruntime));
67e12eac 208 spread = max_vruntime - MIN_vruntime;
ef83a571
IM
209 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread",
210 SPLIT_NS(spread));
86d9560c 211 spread0 = min_vruntime - rq0_min_vruntime;
ef83a571
IM
212 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0",
213 SPLIT_NS(spread0));
5ac5c4d6 214 SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over",
ddc97297 215 cfs_rq->nr_spread_over);
c82513e5 216 SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running);
2069dd75 217 SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
c09595f6
PZ
218#ifdef CONFIG_FAIR_GROUP_SCHED
219#ifdef CONFIG_SMP
2069dd75
PZ
220 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "load_avg",
221 SPLIT_NS(cfs_rq->load_avg));
222 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "load_period",
223 SPLIT_NS(cfs_rq->load_period));
224 SEQ_printf(m, " .%-30s: %ld\n", "load_contrib",
225 cfs_rq->load_contribution);
226 SEQ_printf(m, " .%-30s: %d\n", "load_tg",
5091faa4 227 atomic_read(&cfs_rq->tg->load_weight));
2dac754e
PT
228 SEQ_printf(m, " .%-30s: %lld\n", "runnable_load_avg",
229 cfs_rq->runnable_load_avg);
c09595f6 230#endif
2069dd75 231
ff9b48c3 232 print_cfs_group_stats(m, cpu, cfs_rq->tg);
c09595f6 233#endif
43ae34cb
IM
234}
235
ada18de2
PZ
236void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
237{
efe25c2c
BR
238#ifdef CONFIG_RT_GROUP_SCHED
239 SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
240#else
ada18de2 241 SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
efe25c2c 242#endif
ada18de2
PZ
243
244#define P(x) \
245 SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
246#define PN(x) \
247 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
248
249 P(rt_nr_running);
250 P(rt_throttled);
251 PN(rt_time);
252 PN(rt_runtime);
253
254#undef PN
255#undef P
256}
257
5bb6b1ea
PZ
258extern __read_mostly int sched_clock_running;
259
a48da48b 260static void print_cpu(struct seq_file *m, int cpu)
43ae34cb 261{
348ec61e 262 struct rq *rq = cpu_rq(cpu);
efe25c2c 263 unsigned long flags;
43ae34cb
IM
264
265#ifdef CONFIG_X86
266 {
267 unsigned int freq = cpu_khz ? : 1;
268
269 SEQ_printf(m, "\ncpu#%d, %u.%03u MHz\n",
270 cpu, freq / 1000, (freq % 1000));
271 }
272#else
273 SEQ_printf(m, "\ncpu#%d\n", cpu);
274#endif
275
13e099d2
PZ
276#define P(x) \
277do { \
278 if (sizeof(rq->x) == 4) \
279 SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \
280 else \
281 SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
282} while (0)
283
ef83a571
IM
284#define PN(x) \
285 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
43ae34cb
IM
286
287 P(nr_running);
288 SEQ_printf(m, " .%-30s: %lu\n", "load",
495eca49 289 rq->load.weight);
43ae34cb
IM
290 P(nr_switches);
291 P(nr_load_updates);
292 P(nr_uninterruptible);
ef83a571 293 PN(next_balance);
43ae34cb 294 P(curr->pid);
ef83a571 295 PN(clock);
43ae34cb
IM
296 P(cpu_load[0]);
297 P(cpu_load[1]);
298 P(cpu_load[2]);
299 P(cpu_load[3]);
300 P(cpu_load[4]);
301#undef P
ef83a571 302#undef PN
43ae34cb 303
5ac5c4d6
PZ
304#ifdef CONFIG_SCHEDSTATS
305#define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, rq->n);
1b9508f6 306#define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
5ac5c4d6 307
5ac5c4d6
PZ
308 P(yld_count);
309
5ac5c4d6
PZ
310 P(sched_count);
311 P(sched_goidle);
1b9508f6
MG
312#ifdef CONFIG_SMP
313 P64(avg_idle);
314#endif
5ac5c4d6
PZ
315
316 P(ttwu_count);
317 P(ttwu_local);
318
5ac5c4d6 319#undef P
fce20979 320#undef P64
5ac5c4d6 321#endif
efe25c2c 322 spin_lock_irqsave(&sched_debug_lock, flags);
5cef9eca 323 print_cfs_stats(m, cpu);
ada18de2 324 print_rt_stats(m, cpu);
43ae34cb 325
efe25c2c 326 rcu_read_lock();
a48da48b 327 print_rq(m, rq, cpu);
efe25c2c
BR
328 rcu_read_unlock();
329 spin_unlock_irqrestore(&sched_debug_lock, flags);
43ae34cb
IM
330}
331
1983a922
CE
332static const char *sched_tunable_scaling_names[] = {
333 "none",
334 "logaritmic",
335 "linear"
336};
337
43ae34cb
IM
338static int sched_debug_show(struct seq_file *m, void *v)
339{
5bb6b1ea
PZ
340 u64 ktime, sched_clk, cpu_clk;
341 unsigned long flags;
43ae34cb
IM
342 int cpu;
343
5bb6b1ea
PZ
344 local_irq_save(flags);
345 ktime = ktime_to_ns(ktime_get());
346 sched_clk = sched_clock();
347 cpu_clk = local_clock();
348 local_irq_restore(flags);
349
350 SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
43ae34cb
IM
351 init_utsname()->release,
352 (int)strcspn(init_utsname()->version, " "),
353 init_utsname()->version);
354
5bb6b1ea
PZ
355#define P(x) \
356 SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
357#define PN(x) \
358 SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
359 PN(ktime);
360 PN(sched_clk);
361 PN(cpu_clk);
362 P(jiffies);
363#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
364 P(sched_clock_stable);
365#endif
366#undef PN
367#undef P
368
369 SEQ_printf(m, "\n");
370 SEQ_printf(m, "sysctl_sched\n");
43ae34cb 371
1aa4731e 372#define P(x) \
d822cece 373 SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
1aa4731e 374#define PN(x) \
d822cece 375 SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
1aa4731e 376 PN(sysctl_sched_latency);
b2be5e96 377 PN(sysctl_sched_min_granularity);
1aa4731e 378 PN(sysctl_sched_wakeup_granularity);
eebef746 379 P(sysctl_sched_child_runs_first);
1aa4731e
IM
380 P(sysctl_sched_features);
381#undef PN
382#undef P
383
1983a922
CE
384 SEQ_printf(m, " .%-40s: %d (%s)\n", "sysctl_sched_tunable_scaling",
385 sysctl_sched_tunable_scaling,
386 sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
387
43ae34cb 388 for_each_online_cpu(cpu)
a48da48b 389 print_cpu(m, cpu);
43ae34cb
IM
390
391 SEQ_printf(m, "\n");
392
393 return 0;
394}
395
029632fb 396void sysrq_sched_debug_show(void)
43ae34cb
IM
397{
398 sched_debug_show(NULL, NULL);
399}
400
401static int sched_debug_open(struct inode *inode, struct file *filp)
402{
403 return single_open(filp, sched_debug_show, NULL);
404}
405
0dbee3a6 406static const struct file_operations sched_debug_fops = {
43ae34cb
IM
407 .open = sched_debug_open,
408 .read = seq_read,
409 .llseek = seq_lseek,
5ea473a1 410 .release = single_release,
43ae34cb
IM
411};
412
413static int __init init_sched_debug_procfs(void)
414{
415 struct proc_dir_entry *pe;
416
a9cf4ddb 417 pe = proc_create("sched_debug", 0444, NULL, &sched_debug_fops);
43ae34cb
IM
418 if (!pe)
419 return -ENOMEM;
43ae34cb
IM
420 return 0;
421}
422
423__initcall(init_sched_debug_procfs);
424
425void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
426{
cc367732 427 unsigned long nr_switches;
43ae34cb 428
5089a976
ON
429 SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, p->pid,
430 get_nr_threads(p));
2d92f227
IM
431 SEQ_printf(m,
432 "---------------------------------------------------------\n");
cc367732
IM
433#define __P(F) \
434 SEQ_printf(m, "%-35s:%21Ld\n", #F, (long long)F)
43ae34cb 435#define P(F) \
2d92f227 436 SEQ_printf(m, "%-35s:%21Ld\n", #F, (long long)p->F)
cc367732
IM
437#define __PN(F) \
438 SEQ_printf(m, "%-35s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
ef83a571 439#define PN(F) \
2d92f227 440 SEQ_printf(m, "%-35s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
43ae34cb 441
ef83a571
IM
442 PN(se.exec_start);
443 PN(se.vruntime);
444 PN(se.sum_exec_runtime);
6cfb0d5d 445
cc367732
IM
446 nr_switches = p->nvcsw + p->nivcsw;
447
6cfb0d5d 448#ifdef CONFIG_SCHEDSTATS
41acab88
LDM
449 PN(se.statistics.wait_start);
450 PN(se.statistics.sleep_start);
451 PN(se.statistics.block_start);
452 PN(se.statistics.sleep_max);
453 PN(se.statistics.block_max);
454 PN(se.statistics.exec_max);
455 PN(se.statistics.slice_max);
456 PN(se.statistics.wait_max);
457 PN(se.statistics.wait_sum);
458 P(se.statistics.wait_count);
459 PN(se.statistics.iowait_sum);
460 P(se.statistics.iowait_count);
cc367732 461 P(se.nr_migrations);
41acab88
LDM
462 P(se.statistics.nr_migrations_cold);
463 P(se.statistics.nr_failed_migrations_affine);
464 P(se.statistics.nr_failed_migrations_running);
465 P(se.statistics.nr_failed_migrations_hot);
466 P(se.statistics.nr_forced_migrations);
467 P(se.statistics.nr_wakeups);
468 P(se.statistics.nr_wakeups_sync);
469 P(se.statistics.nr_wakeups_migrate);
470 P(se.statistics.nr_wakeups_local);
471 P(se.statistics.nr_wakeups_remote);
472 P(se.statistics.nr_wakeups_affine);
473 P(se.statistics.nr_wakeups_affine_attempts);
474 P(se.statistics.nr_wakeups_passive);
475 P(se.statistics.nr_wakeups_idle);
cc367732
IM
476
477 {
478 u64 avg_atom, avg_per_cpu;
479
480 avg_atom = p->se.sum_exec_runtime;
481 if (nr_switches)
482 do_div(avg_atom, nr_switches);
483 else
484 avg_atom = -1LL;
485
486 avg_per_cpu = p->se.sum_exec_runtime;
c1a89740 487 if (p->se.nr_migrations) {
6f6d6a1a
RZ
488 avg_per_cpu = div64_u64(avg_per_cpu,
489 p->se.nr_migrations);
c1a89740 490 } else {
cc367732 491 avg_per_cpu = -1LL;
c1a89740 492 }
cc367732
IM
493
494 __PN(avg_atom);
495 __PN(avg_per_cpu);
496 }
6cfb0d5d 497#endif
cc367732 498 __P(nr_switches);
2d92f227 499 SEQ_printf(m, "%-35s:%21Ld\n",
cc367732
IM
500 "nr_voluntary_switches", (long long)p->nvcsw);
501 SEQ_printf(m, "%-35s:%21Ld\n",
502 "nr_involuntary_switches", (long long)p->nivcsw);
503
43ae34cb
IM
504 P(se.load.weight);
505 P(policy);
506 P(prio);
ef83a571 507#undef PN
cc367732
IM
508#undef __PN
509#undef P
510#undef __P
43ae34cb
IM
511
512 {
29d7b90c 513 unsigned int this_cpu = raw_smp_processor_id();
43ae34cb
IM
514 u64 t0, t1;
515
29d7b90c
IM
516 t0 = cpu_clock(this_cpu);
517 t1 = cpu_clock(this_cpu);
2d92f227 518 SEQ_printf(m, "%-35s:%21Ld\n",
43ae34cb
IM
519 "clock-delta", (long long)(t1-t0));
520 }
521}
522
523void proc_sched_set_task(struct task_struct *p)
524{
6cfb0d5d 525#ifdef CONFIG_SCHEDSTATS
41acab88 526 memset(&p->se.statistics, 0, sizeof(p->se.statistics));
6cfb0d5d 527#endif
43ae34cb 528}