blob: 87e2c9f0c33e7470252206c893fd5fb1e250790c [file] [log] [blame]
Peter Zijlstra029632f2011-10-25 10:00:11 +02001
2#include <linux/slab.h>
3#include <linux/fs.h>
4#include <linux/seq_file.h>
5#include <linux/proc_fs.h>
6
7#include "sched.h"
8
9/*
10 * bump this up when changing the output format or the meaning of an existing
11 * format, so that tools can adapt (or abort)
12 */
13#define SCHEDSTAT_VERSION 15
14
15static int show_schedstat(struct seq_file *seq, void *v)
16{
17 int cpu;
Peter Zijlstra029632f2011-10-25 10:00:11 +020018
Nathan Zimmercb152ff2013-02-21 15:15:08 -080019 if (v == (void *)1) {
20 seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION);
21 seq_printf(seq, "timestamp %lu\n", jiffies);
22 } else {
23 struct rq *rq;
Peter Zijlstra029632f2011-10-25 10:00:11 +020024#ifdef CONFIG_SMP
25 struct sched_domain *sd;
26 int dcount = 0;
27#endif
Nathan Zimmercb152ff2013-02-21 15:15:08 -080028 cpu = (unsigned long)(v - 2);
29 rq = cpu_rq(cpu);
Peter Zijlstra029632f2011-10-25 10:00:11 +020030
31 /* runqueue-specific stats */
32 seq_printf(seq,
Rakib Mullick30fd0492012-01-24 22:33:56 +060033 "cpu%d %u 0 %u %u %u %u %llu %llu %lu",
Peter Zijlstra029632f2011-10-25 10:00:11 +020034 cpu, rq->yld_count,
Rakib Mullick30fd0492012-01-24 22:33:56 +060035 rq->sched_count, rq->sched_goidle,
Peter Zijlstra029632f2011-10-25 10:00:11 +020036 rq->ttwu_count, rq->ttwu_local,
37 rq->rq_cpu_time,
38 rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount);
39
40 seq_printf(seq, "\n");
41
42#ifdef CONFIG_SMP
43 /* domain-specific stats */
44 rcu_read_lock();
45 for_each_domain(cpu, sd) {
46 enum cpu_idle_type itype;
47
Tejun Heo333470e2015-02-13 14:37:28 -080048 seq_printf(seq, "domain%d %*pb", dcount++,
49 cpumask_pr_args(sched_domain_span(sd)));
Peter Zijlstra029632f2011-10-25 10:00:11 +020050 for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES;
51 itype++) {
52 seq_printf(seq, " %u %u %u %u %u %u %u %u",
53 sd->lb_count[itype],
54 sd->lb_balanced[itype],
55 sd->lb_failed[itype],
56 sd->lb_imbalance[itype],
57 sd->lb_gained[itype],
58 sd->lb_hot_gained[itype],
59 sd->lb_nobusyq[itype],
60 sd->lb_nobusyg[itype]);
61 }
62 seq_printf(seq,
63 " %u %u %u %u %u %u %u %u %u %u %u %u\n",
64 sd->alb_count, sd->alb_failed, sd->alb_pushed,
65 sd->sbe_count, sd->sbe_balanced, sd->sbe_pushed,
66 sd->sbf_count, sd->sbf_balanced, sd->sbf_pushed,
67 sd->ttwu_wake_remote, sd->ttwu_move_affine,
68 sd->ttwu_move_balance);
69 }
70 rcu_read_unlock();
71#endif
72 }
Peter Zijlstra029632f2011-10-25 10:00:11 +020073 return 0;
74}
75
Nathan Zimmercb152ff2013-02-21 15:15:08 -080076/*
77 * This itererator needs some explanation.
78 * It returns 1 for the header position.
79 * This means 2 is cpu 0.
80 * In a hotplugged system some cpus, including cpu 0, may be missing so we have
81 * to use cpumask_* to iterate over the cpus.
82 */
83static void *schedstat_start(struct seq_file *file, loff_t *offset)
84{
85 unsigned long n = *offset;
86
87 if (n == 0)
88 return (void *) 1;
89
90 n--;
91
92 if (n > 0)
93 n = cpumask_next(n - 1, cpu_online_mask);
94 else
95 n = cpumask_first(cpu_online_mask);
96
97 *offset = n + 1;
98
99 if (n < nr_cpu_ids)
100 return (void *)(unsigned long)(n + 2);
101 return NULL;
102}
103
104static void *schedstat_next(struct seq_file *file, void *data, loff_t *offset)
105{
106 (*offset)++;
107 return schedstat_start(file, offset);
108}
109
110static void schedstat_stop(struct seq_file *file, void *data)
111{
112}
113
114static const struct seq_operations schedstat_sops = {
115 .start = schedstat_start,
116 .next = schedstat_next,
117 .stop = schedstat_stop,
118 .show = show_schedstat,
119};
120
Peter Zijlstra029632f2011-10-25 10:00:11 +0200121static int schedstat_open(struct inode *inode, struct file *file)
122{
Nathan Zimmercb152ff2013-02-21 15:15:08 -0800123 return seq_open(file, &schedstat_sops);
Peter Zijlstra029632f2011-10-25 10:00:11 +0200124}
125
126static const struct file_operations proc_schedstat_operations = {
127 .open = schedstat_open,
128 .read = seq_read,
129 .llseek = seq_lseek,
Al Viro8e0bcc72013-04-15 13:29:15 -0400130 .release = seq_release,
Peter Zijlstra029632f2011-10-25 10:00:11 +0200131};
132
133static int __init proc_schedstat_init(void)
134{
135 proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
136 return 0;
137}
Paul Gortmakerc96d6662014-04-03 14:48:35 -0700138subsys_initcall(proc_schedstat_init);