2 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
3 * (C) 2010 Thomas Renninger <trenn@suse.de>
5 * Licensed under the terms of the GNU GPL License version 2.
17 #include "helpers/helpers.h"
18 #include "helpers/sysfs.h"
19 #include "helpers/bitmask.h"
23 static void cpuidle_cpu_output(unsigned int cpu
, int verbose
)
25 int idlestates
, idlestate
;
28 printf(_ ("Analyzing CPU %d:\n"), cpu
);
30 idlestates
= sysfs_get_idlestate_count(cpu
);
31 if (idlestates
== 0) {
32 printf(_("CPU %u: No idle states\n"), cpu
);
34 } else if (idlestates
<= 0) {
35 printf(_("CPU %u: Can't read idle state info\n"), cpu
);
38 tmp
= sysfs_get_idlestate_name(cpu
, idlestates
- 1);
40 printf(_("Could not determine max idle state %u\n"),
45 printf(_("Number of idle states: %d\n"), idlestates
);
47 printf(_("Available idle states:"));
48 for (idlestate
= 1; idlestate
< idlestates
; idlestate
++) {
49 tmp
= sysfs_get_idlestate_name(cpu
, idlestate
);
60 for (idlestate
= 1; idlestate
< idlestates
; idlestate
++) {
61 tmp
= sysfs_get_idlestate_name(cpu
, idlestate
);
67 tmp
= sysfs_get_idlestate_desc(cpu
, idlestate
);
70 printf(_("Flags/Description: %s\n"), tmp
);
73 printf(_("Latency: %lu\n"),
74 sysfs_get_idlestate_latency(cpu
, idlestate
));
75 printf(_("Usage: %lu\n"),
76 sysfs_get_idlestate_usage(cpu
, idlestate
));
77 printf(_("Duration: %llu\n"),
78 sysfs_get_idlestate_time(cpu
, idlestate
));
83 static void cpuidle_general_output(void)
87 tmp
= sysfs_get_cpuidle_driver();
89 printf(_("Could not determine cpuidle driver\n"));
93 printf(_("CPUidle driver: %s\n"), tmp
);
96 tmp
= sysfs_get_cpuidle_governor();
98 printf(_("Could not determine cpuidle governor\n"));
102 printf(_("CPUidle governor: %s\n"), tmp
);
106 static void proc_cpuidle_cpu_output(unsigned int cpu
)
108 long max_allowed_cstate
= 2000000000;
111 cstates
= sysfs_get_idlestate_count(cpu
);
114 * Go on and print same useless info as you'd see with
115 * cat /proc/acpi/processor/../power
116 * printf(_("CPU %u: No C-states available\n"), cpu);
119 } else if (cstates
<= 0) {
120 printf(_("CPU %u: Can't read C-state info\n"), cpu
);
123 /* printf("Cstates: %d\n", cstates); */
125 printf(_("active state: C0\n"));
126 printf(_("max_cstate: C%u\n"), cstates
-1);
127 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate
);
128 printf(_("states:\t\n"));
129 for (cstate
= 1; cstate
< cstates
; cstate
++) {
131 "type[C%d] "), cstate
, cstate
);
132 printf(_("promotion[--] demotion[--] "));
133 printf(_("latency[%03lu] "),
134 sysfs_get_idlestate_latency(cpu
, cstate
));
135 printf(_("usage[%08lu] "),
136 sysfs_get_idlestate_usage(cpu
, cstate
));
137 printf(_("duration[%020Lu] \n"),
138 sysfs_get_idlestate_time(cpu
, cstate
));
142 static struct option info_opts
[] = {
143 { .name
= "silent", .has_arg
= no_argument
, .flag
= NULL
, .val
= 's'},
144 { .name
= "proc", .has_arg
= no_argument
, .flag
= NULL
, .val
= 'o'},
148 static inline void cpuidle_exit(int fail
)
153 int cmd_idle_info(int argc
, char **argv
)
156 extern int optind
, opterr
, optopt
;
157 int ret
= 0, cont
= 1, output_param
= 0, verbose
= 1;
158 unsigned int cpu
= 0;
161 ret
= getopt_long(argc
, argv
, "os", info_opts
, NULL
);
186 switch (output_param
) {
188 printf(_("You can't specify more than one "
189 "output-specific argument\n"));
190 cpuidle_exit(EXIT_FAILURE
);
192 printf(_("invalid or unknown argument\n"));
193 cpuidle_exit(EXIT_FAILURE
);
196 /* Default is: show output of CPU 0 only */
197 if (bitmask_isallclear(cpus_chosen
))
198 bitmask_setbit(cpus_chosen
, 0);
200 if (output_param
== 0)
201 cpuidle_general_output();
203 for (cpu
= bitmask_first(cpus_chosen
);
204 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
206 if (!bitmask_isbitset(cpus_chosen
, cpu
) ||
207 cpufreq_cpu_exists(cpu
))
210 switch (output_param
) {
213 proc_cpuidle_cpu_output(cpu
);
217 cpuidle_cpu_output(cpu
, verbose
);