1 // SPDX-License-Identifier: GPL-2.0
3 * /proc/schedstat implementation
8 * Current schedstat API version.
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
)
20 seq_printf(seq
, "version %d\n", SCHEDSTAT_VERSION
);
21 seq_printf(seq
, "timestamp %lu\n", jiffies
);
25 struct sched_domain
*sd
;
28 cpu
= (unsigned long)(v
- 2);
31 /* runqueue-specific stats */
33 "cpu%d %u 0 %u %u %u %u %llu %llu %lu",
35 rq
->sched_count
, rq
->sched_goidle
,
36 rq
->ttwu_count
, rq
->ttwu_local
,
38 rq
->rq_sched_info
.run_delay
, rq
->rq_sched_info
.pcount
);
40 seq_printf(seq
, "\n");
43 /* domain-specific stats */
45 for_each_domain(cpu
, sd
) {
46 enum cpu_idle_type itype
;
48 seq_printf(seq
, "domain%d %*pb", dcount
++,
49 cpumask_pr_args(sched_domain_span(sd
)));
50 for (itype
= CPU_IDLE
; itype
< CPU_MAX_IDLE_TYPES
;
52 seq_printf(seq
, " %u %u %u %u %u %u %u %u",
54 sd
->lb_balanced
[itype
],
56 sd
->lb_imbalance
[itype
],
58 sd
->lb_hot_gained
[itype
],
59 sd
->lb_nobusyq
[itype
],
60 sd
->lb_nobusyg
[itype
]);
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
);
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.
83 static void *schedstat_start(struct seq_file
*file
, loff_t
*offset
)
85 unsigned long n
= *offset
;
93 n
= cpumask_next(n
- 1, cpu_online_mask
);
95 n
= cpumask_first(cpu_online_mask
);
100 return (void *)(unsigned long)(n
+ 2);
105 static void *schedstat_next(struct seq_file
*file
, void *data
, loff_t
*offset
)
109 return schedstat_start(file
, offset
);
112 static void schedstat_stop(struct seq_file
*file
, void *data
)
116 static const struct seq_operations schedstat_sops
= {
117 .start
= schedstat_start
,
118 .next
= schedstat_next
,
119 .stop
= schedstat_stop
,
120 .show
= show_schedstat
,
123 static int __init
proc_schedstat_init(void)
125 proc_create_seq("schedstat", 0, NULL
, &schedstat_sops
);
128 subsys_initcall(proc_schedstat_init
);