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
);
35 else if (idlestates
<= 0) {
36 printf(_("CPU %u: Can't read idle state info\n"), cpu
);
39 tmp
= sysfs_get_idlestate_name(cpu
, idlestates
- 1);
41 printf(_("Could not determine max idle state %u\n"),
46 printf(_("Number of idle states: %d\n"), idlestates
);
48 printf(_("Available idle states:"));
49 for (idlestate
= 1; idlestate
< idlestates
; idlestate
++) {
50 tmp
= sysfs_get_idlestate_name(cpu
, idlestate
);
61 for (idlestate
= 1; idlestate
< idlestates
; idlestate
++) {
62 tmp
= sysfs_get_idlestate_name(cpu
, idlestate
);
68 tmp
= sysfs_get_idlestate_desc(cpu
, idlestate
);
71 printf(_("Flags/Description: %s\n"), tmp
);
74 printf(_("Latency: %lu\n"),
75 sysfs_get_idlestate_latency(cpu
, idlestate
));
76 printf(_("Usage: %lu\n"),
77 sysfs_get_idlestate_usage(cpu
, idlestate
));
78 printf(_("Duration: %llu\n"),
79 sysfs_get_idlestate_time(cpu
, idlestate
));
84 static void cpuidle_general_output(void)
88 tmp
= sysfs_get_cpuidle_driver();
90 printf(_("Could not determine cpuidle driver\n"));
94 printf(_("CPUidle driver: %s\n"), tmp
);
97 tmp
= sysfs_get_cpuidle_governor();
99 printf(_("Could not determine cpuidle governor\n"));
103 printf(_("CPUidle governor: %s\n"), tmp
);
107 static void proc_cpuidle_cpu_output(unsigned int cpu
)
109 long max_allowed_cstate
= 2000000000;
112 cstates
= sysfs_get_idlestate_count(cpu
);
115 * Go on and print same useless info as you'd see with
116 * cat /proc/acpi/processor/../power
117 * printf(_("CPU %u: No C-states available\n"), cpu);
121 else if (cstates
<= 0) {
122 printf(_("CPU %u: Can't read C-state info\n"), cpu
);
125 /* printf("Cstates: %d\n", cstates); */
127 printf(_("active state: C0\n"));
128 printf(_("max_cstate: C%u\n"), cstates
-1);
129 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate
);
130 printf(_("states:\t\n"));
131 for (cstate
= 1; cstate
< cstates
; cstate
++) {
133 "type[C%d] "), cstate
, cstate
);
134 printf(_("promotion[--] demotion[--] "));
135 printf(_("latency[%03lu] "),
136 sysfs_get_idlestate_latency(cpu
, cstate
));
137 printf(_("usage[%08lu] "),
138 sysfs_get_idlestate_usage(cpu
, cstate
));
139 printf(_("duration[%020Lu] \n"),
140 sysfs_get_idlestate_time(cpu
, cstate
));
146 void idle_info_help(void) {
147 printf(_ ("Usage: cpupower idleinfo [options]\n"));
148 printf(_ ("Options:\n"));
149 printf(_ (" -s, --silent Only show general C-state information\n"));
150 printf(_ (" -o, --proc Prints out information like provided by the /proc/acpi/processor/*/power\n"
151 " interface in older kernels\n"));
152 printf(_ (" -h, --help Prints out this screen\n"));
157 static struct option info_opts
[] = {
158 { .name
="silent", .has_arg
=no_argument
, .flag
=NULL
, .val
='s'},
159 { .name
="proc", .has_arg
=no_argument
, .flag
=NULL
, .val
='o'},
160 { .name
="help", .has_arg
=no_argument
, .flag
=NULL
, .val
='h'},
164 static inline void cpuidle_exit(int fail
)
170 int cmd_idle_info(int argc
, char **argv
)
173 extern int optind
, opterr
, optopt
;
174 int ret
= 0, cont
= 1, output_param
= 0, verbose
= 1;
175 unsigned int cpu
= 0;
178 ret
= getopt_long(argc
, argv
, "hos", info_opts
, NULL
);
207 switch (output_param
) {
209 printf(_("You can't specify more than one "
210 "output-specific argument\n"));
211 cpuidle_exit(EXIT_FAILURE
);
213 printf(_("invalid or unknown argument\n"));
214 cpuidle_exit(EXIT_FAILURE
);
216 cpuidle_exit(EXIT_SUCCESS
);
219 /* Default is: show output of CPU 0 only */
220 if (bitmask_isallclear(cpus_chosen
))
221 bitmask_setbit(cpus_chosen
, 0);
223 if (output_param
== 0)
224 cpuidle_general_output();
226 for (cpu
= bitmask_first(cpus_chosen
);
227 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
229 if (!bitmask_isbitset(cpus_chosen
, cpu
) ||
230 cpufreq_cpu_exists(cpu
))
233 switch (output_param
) {
236 proc_cpuidle_cpu_output(cpu
);
240 cpuidle_cpu_output(cpu
, verbose
);
244 return (EXIT_SUCCESS
);