2 #include <linux/slab.h>
4 #include <linux/seq_file.h>
5 #include <linux/proc_fs.h>
10 * bump this up when changing the output format or the meaning of an existing
11 * format, so that tools can adapt (or abort)
13 #define SCHEDSTAT_VERSION 15
15 static int show_schedstat(struct seq_file
*seq
, void *v
)
18 int mask_len
= DIV_ROUND_UP(NR_CPUS
, 32) * 9;
19 char *mask_str
= kmalloc(mask_len
, GFP_KERNEL
);
25 seq_printf(seq
, "version %d\n", SCHEDSTAT_VERSION
);
26 seq_printf(seq
, "timestamp %lu\n", jiffies
);
30 struct sched_domain
*sd
;
33 cpu
= (unsigned long)(v
- 2);
36 /* runqueue-specific stats */
38 "cpu%d %u 0 %u %u %u %u %llu %llu %lu",
40 rq
->sched_count
, rq
->sched_goidle
,
41 rq
->ttwu_count
, rq
->ttwu_local
,
43 rq
->rq_sched_info
.run_delay
, rq
->rq_sched_info
.pcount
);
45 seq_printf(seq
, "\n");
48 /* domain-specific stats */
50 for_each_domain(cpu
, sd
) {
51 enum cpu_idle_type itype
;
53 cpumask_scnprintf(mask_str
, mask_len
,
54 sched_domain_span(sd
));
55 seq_printf(seq
, "domain%d %s", dcount
++, mask_str
);
56 for (itype
= CPU_IDLE
; itype
< CPU_MAX_IDLE_TYPES
;
58 seq_printf(seq
, " %u %u %u %u %u %u %u %u",
60 sd
->lb_balanced
[itype
],
62 sd
->lb_imbalance
[itype
],
64 sd
->lb_hot_gained
[itype
],
65 sd
->lb_nobusyq
[itype
],
66 sd
->lb_nobusyg
[itype
]);
69 " %u %u %u %u %u %u %u %u %u %u %u %u\n",
70 sd
->alb_count
, sd
->alb_failed
, sd
->alb_pushed
,
71 sd
->sbe_count
, sd
->sbe_balanced
, sd
->sbe_pushed
,
72 sd
->sbf_count
, sd
->sbf_balanced
, sd
->sbf_pushed
,
73 sd
->ttwu_wake_remote
, sd
->ttwu_move_affine
,
74 sd
->ttwu_move_balance
);
84 * This itererator needs some explanation.
85 * It returns 1 for the header position.
86 * This means 2 is cpu 0.
87 * In a hotplugged system some cpus, including cpu 0, may be missing so we have
88 * to use cpumask_* to iterate over the cpus.
90 static void *schedstat_start(struct seq_file
*file
, loff_t
*offset
)
92 unsigned long n
= *offset
;
100 n
= cpumask_next(n
- 1, cpu_online_mask
);
102 n
= cpumask_first(cpu_online_mask
);
107 return (void *)(unsigned long)(n
+ 2);
111 static void *schedstat_next(struct seq_file
*file
, void *data
, loff_t
*offset
)
114 return schedstat_start(file
, offset
);
117 static void schedstat_stop(struct seq_file
*file
, void *data
)
121 static const struct seq_operations schedstat_sops
= {
122 .start
= schedstat_start
,
123 .next
= schedstat_next
,
124 .stop
= schedstat_stop
,
125 .show
= show_schedstat
,
128 static int schedstat_open(struct inode
*inode
, struct file
*file
)
130 return seq_open(file
, &schedstat_sops
);
133 static const struct file_operations proc_schedstat_operations
= {
134 .open
= schedstat_open
,
137 .release
= seq_release
,
140 static int __init
proc_schedstat_init(void)
142 proc_create("schedstat", 0, NULL
, &proc_schedstat_operations
);
145 subsys_initcall(proc_schedstat_init
);