Merge branch 'linus' into sched/core, to pick up fixes
[linux-2.6-block.git] / kernel / sched / debug.c
CommitLineData
43ae34cb 1/*
391e43da 2 * kernel/sched/debug.c
43ae34cb 3 *
325ea10c 4 * Print the CFS rbtree and other debugging details
43ae34cb
IM
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 */
029632fb
PZ
12#include "sched.h"
13
efe25c2c
BR
14static DEFINE_SPINLOCK(sched_debug_lock);
15
43ae34cb
IM
16/*
17 * This allows printing both to /proc/sched_debug and
18 * to the console
19 */
20#define SEQ_printf(m, x...) \
21 do { \
22 if (m) \
23 seq_printf(m, x); \
24 else \
25 printk(x); \
26 } while (0)
27
ef83a571
IM
28/*
29 * Ease the printing of nsec fields:
30 */
90b2628f 31static long long nsec_high(unsigned long long nsec)
ef83a571 32{
90b2628f 33 if ((long long)nsec < 0) {
ef83a571
IM
34 nsec = -nsec;
35 do_div(nsec, 1000000);
36 return -nsec;
37 }
38 do_div(nsec, 1000000);
39
40 return nsec;
41}
42
90b2628f 43static unsigned long nsec_low(unsigned long long nsec)
ef83a571 44{
90b2628f 45 if ((long long)nsec < 0)
ef83a571
IM
46 nsec = -nsec;
47
48 return do_div(nsec, 1000000);
49}
50
51#define SPLIT_NS(x) nsec_high(x), nsec_low(x)
52
d6ca41d7
SRRH
53#define SCHED_FEAT(name, enabled) \
54 #name ,
55
56static const char * const sched_feat_names[] = {
57#include "features.h"
58};
59
60#undef SCHED_FEAT
61
62static int sched_feat_show(struct seq_file *m, void *v)
63{
64 int i;
65
66 for (i = 0; i < __SCHED_FEAT_NR; i++) {
67 if (!(sysctl_sched_features & (1UL << i)))
68 seq_puts(m, "NO_");
69 seq_printf(m, "%s ", sched_feat_names[i]);
70 }
71 seq_puts(m, "\n");
72
73 return 0;
74}
75
76#ifdef HAVE_JUMP_LABEL
77
78#define jump_label_key__true STATIC_KEY_INIT_TRUE
79#define jump_label_key__false STATIC_KEY_INIT_FALSE
80
81#define SCHED_FEAT(name, enabled) \
82 jump_label_key__##enabled ,
83
84struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
85#include "features.h"
86};
87
88#undef SCHED_FEAT
89
90static void sched_feat_disable(int i)
91{
92 static_key_disable(&sched_feat_keys[i]);
93}
94
95static void sched_feat_enable(int i)
96{
97 static_key_enable(&sched_feat_keys[i]);
98}
99#else
100static void sched_feat_disable(int i) { };
101static void sched_feat_enable(int i) { };
102#endif /* HAVE_JUMP_LABEL */
103
104static int sched_feat_set(char *cmp)
105{
106 int i;
107 int neg = 0;
108
109 if (strncmp(cmp, "NO_", 3) == 0) {
110 neg = 1;
111 cmp += 3;
112 }
113
114 for (i = 0; i < __SCHED_FEAT_NR; i++) {
115 if (strcmp(cmp, sched_feat_names[i]) == 0) {
116 if (neg) {
117 sysctl_sched_features &= ~(1UL << i);
118 sched_feat_disable(i);
119 } else {
120 sysctl_sched_features |= (1UL << i);
121 sched_feat_enable(i);
122 }
123 break;
124 }
125 }
126
127 return i;
128}
129
130static ssize_t
131sched_feat_write(struct file *filp, const char __user *ubuf,
132 size_t cnt, loff_t *ppos)
133{
134 char buf[64];
135 char *cmp;
136 int i;
137 struct inode *inode;
138
139 if (cnt > 63)
140 cnt = 63;
141
142 if (copy_from_user(&buf, ubuf, cnt))
143 return -EFAULT;
144
145 buf[cnt] = 0;
146 cmp = strstrip(buf);
147
148 /* Ensure the static_key remains in a consistent state */
149 inode = file_inode(filp);
150 inode_lock(inode);
151 i = sched_feat_set(cmp);
152 inode_unlock(inode);
153 if (i == __SCHED_FEAT_NR)
154 return -EINVAL;
155
156 *ppos += cnt;
157
158 return cnt;
159}
160
161static int sched_feat_open(struct inode *inode, struct file *filp)
162{
163 return single_open(filp, sched_feat_show, NULL);
164}
165
166static const struct file_operations sched_feat_fops = {
167 .open = sched_feat_open,
168 .write = sched_feat_write,
169 .read = seq_read,
170 .llseek = seq_lseek,
171 .release = single_release,
172};
173
9469eb01
PZ
174__read_mostly bool sched_debug_enabled;
175
d6ca41d7
SRRH
176static __init int sched_init_debug(void)
177{
178 debugfs_create_file("sched_features", 0644, NULL, NULL,
179 &sched_feat_fops);
180
9469eb01
PZ
181 debugfs_create_bool("sched_debug", 0644, NULL,
182 &sched_debug_enabled);
183
d6ca41d7
SRRH
184 return 0;
185}
186late_initcall(sched_init_debug);
187
3866e845
SRRH
188#ifdef CONFIG_SMP
189
190#ifdef CONFIG_SYSCTL
191
192static struct ctl_table sd_ctl_dir[] = {
193 {
194 .procname = "sched_domain",
195 .mode = 0555,
196 },
197 {}
198};
199
200static struct ctl_table sd_ctl_root[] = {
201 {
202 .procname = "kernel",
203 .mode = 0555,
204 .child = sd_ctl_dir,
205 },
206 {}
207};
208
209static struct ctl_table *sd_alloc_ctl_entry(int n)
210{
211 struct ctl_table *entry =
212 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
213
214 return entry;
215}
216
217static void sd_free_ctl_entry(struct ctl_table **tablep)
218{
219 struct ctl_table *entry;
220
221 /*
222 * In the intermediate directories, both the child directory and
223 * procname are dynamically allocated and could fail but the mode
224 * will always be set. In the lowest directory the names are
225 * static strings and all have proc handlers.
226 */
227 for (entry = *tablep; entry->mode; entry++) {
228 if (entry->child)
229 sd_free_ctl_entry(&entry->child);
230 if (entry->proc_handler == NULL)
231 kfree(entry->procname);
232 }
233
234 kfree(*tablep);
235 *tablep = NULL;
236}
237
238static int min_load_idx = 0;
239static int max_load_idx = CPU_LOAD_IDX_MAX-1;
240
241static void
242set_table_entry(struct ctl_table *entry,
243 const char *procname, void *data, int maxlen,
244 umode_t mode, proc_handler *proc_handler,
245 bool load_idx)
246{
247 entry->procname = procname;
248 entry->data = data;
249 entry->maxlen = maxlen;
250 entry->mode = mode;
251 entry->proc_handler = proc_handler;
252
253 if (load_idx) {
254 entry->extra1 = &min_load_idx;
255 entry->extra2 = &max_load_idx;
256 }
257}
258
259static struct ctl_table *
260sd_alloc_ctl_domain_table(struct sched_domain *sd)
261{
262 struct ctl_table *table = sd_alloc_ctl_entry(14);
263
264 if (table == NULL)
265 return NULL;
266
97fb7a0a
IM
267 set_table_entry(&table[0] , "min_interval", &sd->min_interval, sizeof(long), 0644, proc_doulongvec_minmax, false);
268 set_table_entry(&table[1] , "max_interval", &sd->max_interval, sizeof(long), 0644, proc_doulongvec_minmax, false);
269 set_table_entry(&table[2] , "busy_idx", &sd->busy_idx, sizeof(int) , 0644, proc_dointvec_minmax, true );
270 set_table_entry(&table[3] , "idle_idx", &sd->idle_idx, sizeof(int) , 0644, proc_dointvec_minmax, true );
271 set_table_entry(&table[4] , "newidle_idx", &sd->newidle_idx, sizeof(int) , 0644, proc_dointvec_minmax, true );
272 set_table_entry(&table[5] , "wake_idx", &sd->wake_idx, sizeof(int) , 0644, proc_dointvec_minmax, true );
273 set_table_entry(&table[6] , "forkexec_idx", &sd->forkexec_idx, sizeof(int) , 0644, proc_dointvec_minmax, true );
274 set_table_entry(&table[7] , "busy_factor", &sd->busy_factor, sizeof(int) , 0644, proc_dointvec_minmax, false);
275 set_table_entry(&table[8] , "imbalance_pct", &sd->imbalance_pct, sizeof(int) , 0644, proc_dointvec_minmax, false);
276 set_table_entry(&table[9] , "cache_nice_tries", &sd->cache_nice_tries, sizeof(int) , 0644, proc_dointvec_minmax, false);
277 set_table_entry(&table[10], "flags", &sd->flags, sizeof(int) , 0644, proc_dointvec_minmax, false);
278 set_table_entry(&table[11], "max_newidle_lb_cost", &sd->max_newidle_lb_cost, sizeof(long), 0644, proc_doulongvec_minmax, false);
279 set_table_entry(&table[12], "name", sd->name, CORENAME_MAX_SIZE, 0444, proc_dostring, false);
3866e845
SRRH
280 /* &table[13] is terminator */
281
282 return table;
283}
284
285static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
286{
287 struct ctl_table *entry, *table;
288 struct sched_domain *sd;
289 int domain_num = 0, i;
290 char buf[32];
291
292 for_each_domain(cpu, sd)
293 domain_num++;
294 entry = table = sd_alloc_ctl_entry(domain_num + 1);
295 if (table == NULL)
296 return NULL;
297
298 i = 0;
299 for_each_domain(cpu, sd) {
300 snprintf(buf, 32, "domain%d", i);
301 entry->procname = kstrdup(buf, GFP_KERNEL);
302 entry->mode = 0555;
303 entry->child = sd_alloc_ctl_domain_table(sd);
304 entry++;
305 i++;
306 }
307 return table;
308}
309
97fb7a0a
IM
310static cpumask_var_t sd_sysctl_cpus;
311static struct ctl_table_header *sd_sysctl_header;
bbdacdfe 312
3866e845
SRRH
313void register_sched_domain_sysctl(void)
314{
bbdacdfe
PZ
315 static struct ctl_table *cpu_entries;
316 static struct ctl_table **cpu_idx;
3866e845 317 char buf[32];
bbdacdfe 318 int i;
3866e845 319
bbdacdfe
PZ
320 if (!cpu_entries) {
321 cpu_entries = sd_alloc_ctl_entry(num_possible_cpus() + 1);
322 if (!cpu_entries)
323 return;
3866e845 324
bbdacdfe
PZ
325 WARN_ON(sd_ctl_dir[0].child);
326 sd_ctl_dir[0].child = cpu_entries;
327 }
3866e845 328
bbdacdfe
PZ
329 if (!cpu_idx) {
330 struct ctl_table *e = cpu_entries;
331
332 cpu_idx = kcalloc(nr_cpu_ids, sizeof(struct ctl_table*), GFP_KERNEL);
333 if (!cpu_idx)
334 return;
335
336 /* deal with sparse possible map */
337 for_each_possible_cpu(i) {
338 cpu_idx[i] = e;
339 e++;
340 }
341 }
342
343 if (!cpumask_available(sd_sysctl_cpus)) {
344 if (!alloc_cpumask_var(&sd_sysctl_cpus, GFP_KERNEL))
345 return;
346
347 /* init to possible to not have holes in @cpu_entries */
348 cpumask_copy(sd_sysctl_cpus, cpu_possible_mask);
349 }
350
351 for_each_cpu(i, sd_sysctl_cpus) {
352 struct ctl_table *e = cpu_idx[i];
353
354 if (e->child)
355 sd_free_ctl_entry(&e->child);
356
357 if (!e->procname) {
358 snprintf(buf, 32, "cpu%d", i);
359 e->procname = kstrdup(buf, GFP_KERNEL);
360 }
361 e->mode = 0555;
362 e->child = sd_alloc_ctl_cpu_table(i);
363
364 __cpumask_clear_cpu(i, sd_sysctl_cpus);
3866e845
SRRH
365 }
366
367 WARN_ON(sd_sysctl_header);
368 sd_sysctl_header = register_sysctl_table(sd_ctl_root);
369}
370
bbdacdfe
PZ
371void dirty_sched_domain_sysctl(int cpu)
372{
373 if (cpumask_available(sd_sysctl_cpus))
374 __cpumask_set_cpu(cpu, sd_sysctl_cpus);
375}
376
3866e845
SRRH
377/* may be called multiple times per register */
378void unregister_sched_domain_sysctl(void)
379{
380 unregister_sysctl_table(sd_sysctl_header);
381 sd_sysctl_header = NULL;
3866e845
SRRH
382}
383#endif /* CONFIG_SYSCTL */
384#endif /* CONFIG_SMP */
385
ff9b48c3 386#ifdef CONFIG_FAIR_GROUP_SCHED
5091faa4 387static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
ff9b48c3
BR
388{
389 struct sched_entity *se = tg->se[cpu];
ff9b48c3 390
97fb7a0a
IM
391#define P(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
392#define P_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)schedstat_val(F))
393#define PN(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
394#define PN_SCHEDSTAT(F) SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(F)))
ff9b48c3 395
cd126afe 396 if (!se)
18bf2805 397 return;
18bf2805 398
ff9b48c3
BR
399 PN(se->exec_start);
400 PN(se->vruntime);
401 PN(se->sum_exec_runtime);
97fb7a0a 402
cb251765 403 if (schedstat_enabled()) {
4fa8d299
JP
404 PN_SCHEDSTAT(se->statistics.wait_start);
405 PN_SCHEDSTAT(se->statistics.sleep_start);
406 PN_SCHEDSTAT(se->statistics.block_start);
407 PN_SCHEDSTAT(se->statistics.sleep_max);
408 PN_SCHEDSTAT(se->statistics.block_max);
409 PN_SCHEDSTAT(se->statistics.exec_max);
410 PN_SCHEDSTAT(se->statistics.slice_max);
411 PN_SCHEDSTAT(se->statistics.wait_max);
412 PN_SCHEDSTAT(se->statistics.wait_sum);
413 P_SCHEDSTAT(se->statistics.wait_count);
cb251765 414 }
97fb7a0a 415
ff9b48c3 416 P(se->load.weight);
1ea6c46a 417 P(se->runnable_weight);
9d85f21c 418#ifdef CONFIG_SMP
9d89c257
YD
419 P(se->avg.load_avg);
420 P(se->avg.util_avg);
1ea6c46a 421 P(se->avg.runnable_load_avg);
9d85f21c 422#endif
4fa8d299
JP
423
424#undef PN_SCHEDSTAT
ff9b48c3 425#undef PN
4fa8d299 426#undef P_SCHEDSTAT
ff9b48c3
BR
427#undef P
428}
429#endif
430
efe25c2c
BR
431#ifdef CONFIG_CGROUP_SCHED
432static char group_path[PATH_MAX];
433
434static char *task_group_path(struct task_group *tg)
435{
8ecedd7a
BR
436 if (autogroup_path(tg, group_path, PATH_MAX))
437 return group_path;
438
4c737b41 439 cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
97fb7a0a 440
4c737b41 441 return group_path;
efe25c2c
BR
442}
443#endif
444
43ae34cb 445static void
a48da48b 446print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
43ae34cb 447{
20435d84 448 if (rq->curr == p)
e8c16495 449 SEQ_printf(m, ">R");
20435d84
XX
450 else
451 SEQ_printf(m, " %c", task_state_to_char(p));
43ae34cb 452
ef83a571 453 SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
fc840914 454 p->comm, task_pid_nr(p),
ef83a571 455 SPLIT_NS(p->se.vruntime),
43ae34cb 456 (long long)(p->nvcsw + p->nivcsw),
6f605d83 457 p->prio);
9c572591 458
33d6176e 459 SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
20e1d486 460 SPLIT_NS(schedstat_val_or_zero(p->se.statistics.wait_sum)),
33d6176e 461 SPLIT_NS(p->se.sum_exec_runtime),
20e1d486 462 SPLIT_NS(schedstat_val_or_zero(p->se.statistics.sum_sleep_runtime)));
9c572591 463
b32e86b4 464#ifdef CONFIG_NUMA_BALANCING
e3d24d0a 465 SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
b32e86b4 466#endif
efe25c2c
BR
467#ifdef CONFIG_CGROUP_SCHED
468 SEQ_printf(m, " %s", task_group_path(task_group(p)));
469#endif
d19ca308 470
d19ca308 471 SEQ_printf(m, "\n");
43ae34cb
IM
472}
473
a48da48b 474static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
43ae34cb
IM
475{
476 struct task_struct *g, *p;
477
478 SEQ_printf(m,
479 "\nrunnable tasks:\n"
e8c16495 480 " S task PID tree-key switches prio"
c5f3ab1c 481 " wait-time sum-exec sum-sleep\n"
e8c16495 482 "-------------------------------------------------------"
c86da3a3 483 "----------------------------------------------------\n");
43ae34cb 484
5bd96ab6 485 rcu_read_lock();
d38e83c7 486 for_each_process_thread(g, p) {
b32e86b4 487 if (task_cpu(p) != rq_cpu)
43ae34cb
IM
488 continue;
489
a48da48b 490 print_task(m, rq, p);
d38e83c7 491 }
5bd96ab6 492 rcu_read_unlock();
43ae34cb
IM
493}
494
5cef9eca 495void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
43ae34cb 496{
86d9560c
IM
497 s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
498 spread, rq0_min_vruntime, spread0;
348ec61e 499 struct rq *rq = cpu_rq(cpu);
67e12eac
IM
500 struct sched_entity *last;
501 unsigned long flags;
502
efe25c2c
BR
503#ifdef CONFIG_FAIR_GROUP_SCHED
504 SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
505#else
ada18de2 506 SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
efe25c2c 507#endif
ef83a571
IM
508 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
509 SPLIT_NS(cfs_rq->exec_clock));
67e12eac 510
05fa785c 511 raw_spin_lock_irqsave(&rq->lock, flags);
bfb06889 512 if (rb_first_cached(&cfs_rq->tasks_timeline))
ac53db59 513 MIN_vruntime = (__pick_first_entity(cfs_rq))->vruntime;
67e12eac
IM
514 last = __pick_last_entity(cfs_rq);
515 if (last)
516 max_vruntime = last->vruntime;
5ac5c4d6 517 min_vruntime = cfs_rq->min_vruntime;
348ec61e 518 rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime;
05fa785c 519 raw_spin_unlock_irqrestore(&rq->lock, flags);
ef83a571
IM
520 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime",
521 SPLIT_NS(MIN_vruntime));
522 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime",
523 SPLIT_NS(min_vruntime));
524 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime",
525 SPLIT_NS(max_vruntime));
67e12eac 526 spread = max_vruntime - MIN_vruntime;
ef83a571
IM
527 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread",
528 SPLIT_NS(spread));
86d9560c 529 spread0 = min_vruntime - rq0_min_vruntime;
ef83a571
IM
530 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0",
531 SPLIT_NS(spread0));
5ac5c4d6 532 SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over",
ddc97297 533 cfs_rq->nr_spread_over);
c82513e5 534 SEQ_printf(m, " .%-30s: %d\n", "nr_running", cfs_rq->nr_running);
2069dd75 535 SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
c09595f6 536#ifdef CONFIG_SMP
1ea6c46a 537 SEQ_printf(m, " .%-30s: %ld\n", "runnable_weight", cfs_rq->runnable_weight);
9d89c257
YD
538 SEQ_printf(m, " .%-30s: %lu\n", "load_avg",
539 cfs_rq->avg.load_avg);
13962234 540 SEQ_printf(m, " .%-30s: %lu\n", "runnable_load_avg",
1ea6c46a 541 cfs_rq->avg.runnable_load_avg);
9d89c257
YD
542 SEQ_printf(m, " .%-30s: %lu\n", "util_avg",
543 cfs_rq->avg.util_avg);
2a2f5d4e
PZ
544 SEQ_printf(m, " .%-30s: %ld\n", "removed.load_avg",
545 cfs_rq->removed.load_avg);
546 SEQ_printf(m, " .%-30s: %ld\n", "removed.util_avg",
547 cfs_rq->removed.util_avg);
0e2d2aaa
PZ
548 SEQ_printf(m, " .%-30s: %ld\n", "removed.runnable_sum",
549 cfs_rq->removed.runnable_sum);
333bb864 550#ifdef CONFIG_FAIR_GROUP_SCHED
9d89c257
YD
551 SEQ_printf(m, " .%-30s: %lu\n", "tg_load_avg_contrib",
552 cfs_rq->tg_load_avg_contrib);
333bb864
AS
553 SEQ_printf(m, " .%-30s: %ld\n", "tg_load_avg",
554 atomic_long_read(&cfs_rq->tg->load_avg));
c09595f6 555#endif
333bb864 556#endif
f9f9ffc2 557#ifdef CONFIG_CFS_BANDWIDTH
f9f9ffc2
BS
558 SEQ_printf(m, " .%-30s: %d\n", "throttled",
559 cfs_rq->throttled);
560 SEQ_printf(m, " .%-30s: %d\n", "throttle_count",
561 cfs_rq->throttle_count);
562#endif
2069dd75 563
333bb864 564#ifdef CONFIG_FAIR_GROUP_SCHED
ff9b48c3 565 print_cfs_group_stats(m, cpu, cfs_rq->tg);
c09595f6 566#endif
43ae34cb
IM
567}
568
ada18de2
PZ
569void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
570{
efe25c2c
BR
571#ifdef CONFIG_RT_GROUP_SCHED
572 SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
573#else
ada18de2 574 SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
efe25c2c 575#endif
ada18de2
PZ
576
577#define P(x) \
578 SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
48365b38
DBO
579#define PU(x) \
580 SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(rt_rq->x))
ada18de2
PZ
581#define PN(x) \
582 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
583
48365b38
DBO
584 PU(rt_nr_running);
585#ifdef CONFIG_SMP
586 PU(rt_nr_migratory);
587#endif
ada18de2
PZ
588 P(rt_throttled);
589 PN(rt_time);
590 PN(rt_runtime);
591
592#undef PN
48365b38 593#undef PU
ada18de2
PZ
594#undef P
595}
596
acb32132
WL
597void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
598{
ef477183
SRRH
599 struct dl_bw *dl_bw;
600
acb32132 601 SEQ_printf(m, "\ndl_rq[%d]:\n", cpu);
48365b38
DBO
602
603#define PU(x) \
604 SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x))
605
606 PU(dl_nr_running);
ef477183 607#ifdef CONFIG_SMP
48365b38 608 PU(dl_nr_migratory);
ef477183
SRRH
609 dl_bw = &cpu_rq(cpu)->rd->dl_bw;
610#else
611 dl_bw = &dl_rq->dl_bw;
612#endif
613 SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw);
614 SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw);
48365b38
DBO
615
616#undef PU
acb32132
WL
617}
618
5bb6b1ea
PZ
619extern __read_mostly int sched_clock_running;
620
a48da48b 621static void print_cpu(struct seq_file *m, int cpu)
43ae34cb 622{
348ec61e 623 struct rq *rq = cpu_rq(cpu);
efe25c2c 624 unsigned long flags;
43ae34cb
IM
625
626#ifdef CONFIG_X86
627 {
628 unsigned int freq = cpu_khz ? : 1;
629
bbbfeac9 630 SEQ_printf(m, "cpu#%d, %u.%03u MHz\n",
43ae34cb
IM
631 cpu, freq / 1000, (freq % 1000));
632 }
633#else
bbbfeac9 634 SEQ_printf(m, "cpu#%d\n", cpu);
43ae34cb
IM
635#endif
636
13e099d2
PZ
637#define P(x) \
638do { \
639 if (sizeof(rq->x) == 4) \
640 SEQ_printf(m, " .%-30s: %ld\n", #x, (long)(rq->x)); \
641 else \
642 SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x));\
643} while (0)
644
ef83a571
IM
645#define PN(x) \
646 SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
43ae34cb
IM
647
648 P(nr_running);
649 SEQ_printf(m, " .%-30s: %lu\n", "load",
495eca49 650 rq->load.weight);
43ae34cb
IM
651 P(nr_switches);
652 P(nr_load_updates);
653 P(nr_uninterruptible);
ef83a571 654 PN(next_balance);
fc840914 655 SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr)));
ef83a571 656 PN(clock);
5a537597 657 PN(clock_task);
43ae34cb
IM
658 P(cpu_load[0]);
659 P(cpu_load[1]);
660 P(cpu_load[2]);
661 P(cpu_load[3]);
662 P(cpu_load[4]);
663#undef P
ef83a571 664#undef PN
43ae34cb 665
1b9508f6 666#ifdef CONFIG_SMP
db6ea2fb 667#define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
1b9508f6 668 P64(avg_idle);
37e6bae8 669 P64(max_idle_balance_cost);
db6ea2fb 670#undef P64
1b9508f6 671#endif
5ac5c4d6 672
4fa8d299 673#define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, schedstat_val(rq->n));
cb251765
MG
674 if (schedstat_enabled()) {
675 P(yld_count);
676 P(sched_count);
677 P(sched_goidle);
678 P(ttwu_count);
679 P(ttwu_local);
680 }
5ac5c4d6 681#undef P
4fa8d299 682
efe25c2c 683 spin_lock_irqsave(&sched_debug_lock, flags);
5cef9eca 684 print_cfs_stats(m, cpu);
ada18de2 685 print_rt_stats(m, cpu);
acb32132 686 print_dl_stats(m, cpu);
43ae34cb 687
a48da48b 688 print_rq(m, rq, cpu);
efe25c2c 689 spin_unlock_irqrestore(&sched_debug_lock, flags);
bbbfeac9 690 SEQ_printf(m, "\n");
43ae34cb
IM
691}
692
1983a922
CE
693static const char *sched_tunable_scaling_names[] = {
694 "none",
695 "logaritmic",
696 "linear"
697};
698
bbbfeac9 699static void sched_debug_header(struct seq_file *m)
43ae34cb 700{
5bb6b1ea
PZ
701 u64 ktime, sched_clk, cpu_clk;
702 unsigned long flags;
43ae34cb 703
5bb6b1ea
PZ
704 local_irq_save(flags);
705 ktime = ktime_to_ns(ktime_get());
706 sched_clk = sched_clock();
707 cpu_clk = local_clock();
708 local_irq_restore(flags);
709
b32e86b4 710 SEQ_printf(m, "Sched Debug Version: v0.11, %s %.*s\n",
43ae34cb
IM
711 init_utsname()->release,
712 (int)strcspn(init_utsname()->version, " "),
713 init_utsname()->version);
714
5bb6b1ea
PZ
715#define P(x) \
716 SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
717#define PN(x) \
718 SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
719 PN(ktime);
720 PN(sched_clk);
721 PN(cpu_clk);
722 P(jiffies);
723#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
35af99e6 724 P(sched_clock_stable());
5bb6b1ea
PZ
725#endif
726#undef PN
727#undef P
728
729 SEQ_printf(m, "\n");
730 SEQ_printf(m, "sysctl_sched\n");
43ae34cb 731
1aa4731e 732#define P(x) \
d822cece 733 SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
1aa4731e 734#define PN(x) \
d822cece 735 SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
1aa4731e 736 PN(sysctl_sched_latency);
b2be5e96 737 PN(sysctl_sched_min_granularity);
1aa4731e 738 PN(sysctl_sched_wakeup_granularity);
eebef746 739 P(sysctl_sched_child_runs_first);
1aa4731e
IM
740 P(sysctl_sched_features);
741#undef PN
742#undef P
743
bbbfeac9
NZ
744 SEQ_printf(m, " .%-40s: %d (%s)\n",
745 "sysctl_sched_tunable_scaling",
1983a922
CE
746 sysctl_sched_tunable_scaling,
747 sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
bbbfeac9
NZ
748 SEQ_printf(m, "\n");
749}
1983a922 750
bbbfeac9
NZ
751static int sched_debug_show(struct seq_file *m, void *v)
752{
753 int cpu = (unsigned long)(v - 2);
43ae34cb 754
bbbfeac9
NZ
755 if (cpu != -1)
756 print_cpu(m, cpu);
757 else
758 sched_debug_header(m);
43ae34cb
IM
759
760 return 0;
761}
762
029632fb 763void sysrq_sched_debug_show(void)
43ae34cb 764{
bbbfeac9
NZ
765 int cpu;
766
767 sched_debug_header(NULL);
768 for_each_online_cpu(cpu)
769 print_cpu(NULL, cpu);
770
771}
772
773/*
774 * This itererator needs some explanation.
775 * It returns 1 for the header position.
97fb7a0a
IM
776 * This means 2 is CPU 0.
777 * In a hotplugged system some CPUs, including CPU 0, may be missing so we have
778 * to use cpumask_* to iterate over the CPUs.
bbbfeac9
NZ
779 */
780static void *sched_debug_start(struct seq_file *file, loff_t *offset)
781{
782 unsigned long n = *offset;
783
784 if (n == 0)
785 return (void *) 1;
786
787 n--;
788
789 if (n > 0)
790 n = cpumask_next(n - 1, cpu_online_mask);
791 else
792 n = cpumask_first(cpu_online_mask);
793
794 *offset = n + 1;
795
796 if (n < nr_cpu_ids)
797 return (void *)(unsigned long)(n + 2);
97fb7a0a 798
bbbfeac9
NZ
799 return NULL;
800}
801
802static void *sched_debug_next(struct seq_file *file, void *data, loff_t *offset)
803{
804 (*offset)++;
805 return sched_debug_start(file, offset);
806}
807
808static void sched_debug_stop(struct seq_file *file, void *data)
809{
810}
811
812static const struct seq_operations sched_debug_sops = {
97fb7a0a
IM
813 .start = sched_debug_start,
814 .next = sched_debug_next,
815 .stop = sched_debug_stop,
816 .show = sched_debug_show,
bbbfeac9
NZ
817};
818
819static int sched_debug_release(struct inode *inode, struct file *file)
820{
821 seq_release(inode, file);
822
823 return 0;
43ae34cb
IM
824}
825
826static int sched_debug_open(struct inode *inode, struct file *filp)
827{
bbbfeac9
NZ
828 int ret = 0;
829
830 ret = seq_open(filp, &sched_debug_sops);
831
832 return ret;
43ae34cb
IM
833}
834
0dbee3a6 835static const struct file_operations sched_debug_fops = {
43ae34cb
IM
836 .open = sched_debug_open,
837 .read = seq_read,
838 .llseek = seq_lseek,
bbbfeac9 839 .release = sched_debug_release,
43ae34cb
IM
840};
841
842static int __init init_sched_debug_procfs(void)
843{
844 struct proc_dir_entry *pe;
845
a9cf4ddb 846 pe = proc_create("sched_debug", 0444, NULL, &sched_debug_fops);
43ae34cb
IM
847 if (!pe)
848 return -ENOMEM;
43ae34cb
IM
849 return 0;
850}
851
852__initcall(init_sched_debug_procfs);
853
97fb7a0a
IM
854#define __P(F) SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F)
855#define P(F) SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F)
856#define __PN(F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
857#define PN(F) SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
b32e86b4
IM
858
859
397f2378
SD
860#ifdef CONFIG_NUMA_BALANCING
861void print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
862 unsigned long tpf, unsigned long gsf, unsigned long gpf)
863{
864 SEQ_printf(m, "numa_faults node=%d ", node);
865 SEQ_printf(m, "task_private=%lu task_shared=%lu ", tsf, tpf);
866 SEQ_printf(m, "group_private=%lu group_shared=%lu\n", gsf, gpf);
867}
868#endif
869
870
b32e86b4
IM
871static void sched_show_numa(struct task_struct *p, struct seq_file *m)
872{
873#ifdef CONFIG_NUMA_BALANCING
874 struct mempolicy *pol;
b32e86b4
IM
875
876 if (p->mm)
877 P(mm->numa_scan_seq);
878
879 task_lock(p);
880 pol = p->mempolicy;
881 if (pol && !(pol->flags & MPOL_F_MORON))
882 pol = NULL;
883 mpol_get(pol);
884 task_unlock(p);
885
397f2378
SD
886 P(numa_pages_migrated);
887 P(numa_preferred_nid);
888 P(total_numa_faults);
889 SEQ_printf(m, "current_node=%d, numa_group_id=%d\n",
890 task_node(p), task_numa_group_id(p));
891 show_numa_stats(p, m);
b32e86b4
IM
892 mpol_put(pol);
893#endif
894}
895
74dc3384
AS
896void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
897 struct seq_file *m)
43ae34cb 898{
cc367732 899 unsigned long nr_switches;
43ae34cb 900
74dc3384 901 SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, task_pid_nr_ns(p, ns),
5089a976 902 get_nr_threads(p));
2d92f227 903 SEQ_printf(m,
add332a1
KB
904 "---------------------------------------------------------"
905 "----------\n");
cc367732 906#define __P(F) \
add332a1 907 SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)F)
43ae34cb 908#define P(F) \
add332a1 909 SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)p->F)
4fa8d299
JP
910#define P_SCHEDSTAT(F) \
911 SEQ_printf(m, "%-45s:%21Ld\n", #F, (long long)schedstat_val(p->F))
cc367732 912#define __PN(F) \
add332a1 913 SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
ef83a571 914#define PN(F) \
add332a1 915 SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
4fa8d299
JP
916#define PN_SCHEDSTAT(F) \
917 SEQ_printf(m, "%-45s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)schedstat_val(p->F)))
43ae34cb 918
ef83a571
IM
919 PN(se.exec_start);
920 PN(se.vruntime);
921 PN(se.sum_exec_runtime);
6cfb0d5d 922
cc367732
IM
923 nr_switches = p->nvcsw + p->nivcsw;
924
cc367732 925 P(se.nr_migrations);
cc367732 926
cb251765 927 if (schedstat_enabled()) {
cc367732
IM
928 u64 avg_atom, avg_per_cpu;
929
4fa8d299
JP
930 PN_SCHEDSTAT(se.statistics.sum_sleep_runtime);
931 PN_SCHEDSTAT(se.statistics.wait_start);
932 PN_SCHEDSTAT(se.statistics.sleep_start);
933 PN_SCHEDSTAT(se.statistics.block_start);
934 PN_SCHEDSTAT(se.statistics.sleep_max);
935 PN_SCHEDSTAT(se.statistics.block_max);
936 PN_SCHEDSTAT(se.statistics.exec_max);
937 PN_SCHEDSTAT(se.statistics.slice_max);
938 PN_SCHEDSTAT(se.statistics.wait_max);
939 PN_SCHEDSTAT(se.statistics.wait_sum);
940 P_SCHEDSTAT(se.statistics.wait_count);
941 PN_SCHEDSTAT(se.statistics.iowait_sum);
942 P_SCHEDSTAT(se.statistics.iowait_count);
943 P_SCHEDSTAT(se.statistics.nr_migrations_cold);
944 P_SCHEDSTAT(se.statistics.nr_failed_migrations_affine);
945 P_SCHEDSTAT(se.statistics.nr_failed_migrations_running);
946 P_SCHEDSTAT(se.statistics.nr_failed_migrations_hot);
947 P_SCHEDSTAT(se.statistics.nr_forced_migrations);
948 P_SCHEDSTAT(se.statistics.nr_wakeups);
949 P_SCHEDSTAT(se.statistics.nr_wakeups_sync);
950 P_SCHEDSTAT(se.statistics.nr_wakeups_migrate);
951 P_SCHEDSTAT(se.statistics.nr_wakeups_local);
952 P_SCHEDSTAT(se.statistics.nr_wakeups_remote);
953 P_SCHEDSTAT(se.statistics.nr_wakeups_affine);
954 P_SCHEDSTAT(se.statistics.nr_wakeups_affine_attempts);
955 P_SCHEDSTAT(se.statistics.nr_wakeups_passive);
956 P_SCHEDSTAT(se.statistics.nr_wakeups_idle);
cb251765 957
cc367732
IM
958 avg_atom = p->se.sum_exec_runtime;
959 if (nr_switches)
b0ab99e7 960 avg_atom = div64_ul(avg_atom, nr_switches);
cc367732
IM
961 else
962 avg_atom = -1LL;
963
964 avg_per_cpu = p->se.sum_exec_runtime;
c1a89740 965 if (p->se.nr_migrations) {
6f6d6a1a
RZ
966 avg_per_cpu = div64_u64(avg_per_cpu,
967 p->se.nr_migrations);
c1a89740 968 } else {
cc367732 969 avg_per_cpu = -1LL;
c1a89740 970 }
cc367732
IM
971
972 __PN(avg_atom);
973 __PN(avg_per_cpu);
974 }
4fa8d299 975
cc367732 976 __P(nr_switches);
add332a1 977 SEQ_printf(m, "%-45s:%21Ld\n",
cc367732 978 "nr_voluntary_switches", (long long)p->nvcsw);
add332a1 979 SEQ_printf(m, "%-45s:%21Ld\n",
cc367732
IM
980 "nr_involuntary_switches", (long long)p->nivcsw);
981
43ae34cb 982 P(se.load.weight);
1ea6c46a 983 P(se.runnable_weight);
333bb864 984#ifdef CONFIG_SMP
9d89c257 985 P(se.avg.load_sum);
1ea6c46a 986 P(se.avg.runnable_load_sum);
9d89c257
YD
987 P(se.avg.util_sum);
988 P(se.avg.load_avg);
1ea6c46a 989 P(se.avg.runnable_load_avg);
9d89c257
YD
990 P(se.avg.util_avg);
991 P(se.avg.last_update_time);
939fd731 992#endif
43ae34cb
IM
993 P(policy);
994 P(prio);
59f8c298
TC
995 if (p->policy == SCHED_DEADLINE) {
996 P(dl.runtime);
997 P(dl.deadline);
998 }
4fa8d299 999#undef PN_SCHEDSTAT
ef83a571 1000#undef PN
cc367732 1001#undef __PN
4fa8d299 1002#undef P_SCHEDSTAT
cc367732
IM
1003#undef P
1004#undef __P
43ae34cb
IM
1005
1006 {
29d7b90c 1007 unsigned int this_cpu = raw_smp_processor_id();
43ae34cb
IM
1008 u64 t0, t1;
1009
29d7b90c
IM
1010 t0 = cpu_clock(this_cpu);
1011 t1 = cpu_clock(this_cpu);
add332a1 1012 SEQ_printf(m, "%-45s:%21Ld\n",
43ae34cb
IM
1013 "clock-delta", (long long)(t1-t0));
1014 }
b32e86b4
IM
1015
1016 sched_show_numa(p, m);
43ae34cb
IM
1017}
1018
1019void proc_sched_set_task(struct task_struct *p)
1020{
6cfb0d5d 1021#ifdef CONFIG_SCHEDSTATS
41acab88 1022 memset(&p->se.statistics, 0, sizeof(p->se.statistics));
6cfb0d5d 1023#endif
43ae34cb 1024}