1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
4 * (C) 2010 Thomas Renninger <trenn@suse.de>
17 #include "helpers/sysfs.h"
18 #include "helpers/helpers.h"
19 #include "helpers/bitmask.h"
23 static void cpuidle_cpu_output(unsigned int cpu
, int verbose
)
25 unsigned int idlestates
, idlestate
;
28 idlestates
= cpuidle_state_count(cpu
);
29 if (idlestates
== 0) {
30 printf(_("CPU %u: No idle states\n"), cpu
);
34 printf(_("Number of idle states: %d\n"), idlestates
);
35 printf(_("Available idle states:"));
36 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
37 tmp
= cpuidle_state_name(cpu
, idlestate
);
48 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
49 int disabled
= cpuidle_is_state_disabled(cpu
, idlestate
);
50 /* Disabled interface not supported on older kernels */
53 tmp
= cpuidle_state_name(cpu
, idlestate
);
56 printf("%s%s:\n", tmp
, (disabled
) ? " (DISABLED) " : "");
59 tmp
= cpuidle_state_desc(cpu
, idlestate
);
62 printf(_("Flags/Description: %s\n"), tmp
);
65 printf(_("Latency: %lu\n"),
66 cpuidle_state_latency(cpu
, idlestate
));
67 printf(_("Usage: %lu\n"),
68 cpuidle_state_usage(cpu
, idlestate
));
69 printf(_("Duration: %llu\n"),
70 cpuidle_state_time(cpu
, idlestate
));
74 static void cpuidle_general_output(void)
78 tmp
= cpuidle_get_driver();
80 printf(_("Could not determine cpuidle driver\n"));
84 printf(_("CPUidle driver: %s\n"), tmp
);
87 tmp
= cpuidle_get_governor();
89 printf(_("Could not determine cpuidle governor\n"));
93 printf(_("CPUidle governor: %s\n"), tmp
);
97 static void proc_cpuidle_cpu_output(unsigned int cpu
)
99 long max_allowed_cstate
= 2000000000;
100 unsigned int cstate
, cstates
;
102 cstates
= cpuidle_state_count(cpu
);
104 printf(_("CPU %u: No C-states info\n"), cpu
);
108 printf(_("active state: C0\n"));
109 printf(_("max_cstate: C%u\n"), cstates
-1);
110 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate
);
111 printf(_("states:\t\n"));
112 for (cstate
= 1; cstate
< cstates
; cstate
++) {
114 "type[C%d] "), cstate
, cstate
);
115 printf(_("promotion[--] demotion[--] "));
116 printf(_("latency[%03lu] "),
117 cpuidle_state_latency(cpu
, cstate
));
118 printf(_("usage[%08lu] "),
119 cpuidle_state_usage(cpu
, cstate
));
120 printf(_("duration[%020Lu] \n"),
121 cpuidle_state_time(cpu
, cstate
));
125 static struct option info_opts
[] = {
126 {"silent", no_argument
, NULL
, 's'},
127 {"proc", no_argument
, NULL
, 'o'},
131 static inline void cpuidle_exit(int fail
)
136 int cmd_idle_info(int argc
, char **argv
)
139 extern int optind
, opterr
, optopt
;
140 int ret
= 0, cont
= 1, output_param
= 0, verbose
= 1;
141 unsigned int cpu
= 0;
144 ret
= getopt_long(argc
, argv
, "os", info_opts
, NULL
);
169 switch (output_param
) {
171 printf(_("You can't specify more than one "
172 "output-specific argument\n"));
173 cpuidle_exit(EXIT_FAILURE
);
175 printf(_("invalid or unknown argument\n"));
176 cpuidle_exit(EXIT_FAILURE
);
179 /* Default is: show output of CPU 0 only */
180 if (bitmask_isallclear(cpus_chosen
))
181 bitmask_setbit(cpus_chosen
, 0);
183 if (output_param
== 0)
184 cpuidle_general_output();
186 for (cpu
= bitmask_first(cpus_chosen
);
187 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
189 if (!bitmask_isbitset(cpus_chosen
, cpu
))
192 printf(_("analyzing CPU %d:\n"), cpu
);
194 if (sysfs_is_cpu_online(cpu
) != 1) {
195 printf(_(" *is offline\n"));
200 switch (output_param
) {
203 proc_cpuidle_cpu_output(cpu
);
207 cpuidle_cpu_output(cpu
, verbose
);