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 printf(_("Number of idle states: %d\n"), idlestates);
39 printf(_("Available idle states:"));
40 for (idlestate = 0; idlestate < idlestates; idlestate++) {
41 tmp = sysfs_get_idlestate_name(cpu, idlestate);
52 for (idlestate = 0; idlestate < idlestates; idlestate++) {
53 tmp = sysfs_get_idlestate_name(cpu, idlestate);
59 tmp = sysfs_get_idlestate_desc(cpu, idlestate);
62 printf(_("Flags/Description: %s\n"), tmp);
65 printf(_("Latency: %lu\n"),
66 sysfs_get_idlestate_latency(cpu, idlestate));
67 printf(_("Usage: %lu\n"),
68 sysfs_get_idlestate_usage(cpu, idlestate));
69 printf(_("Duration: %llu\n"),
70 sysfs_get_idlestate_time(cpu, idlestate));
75 static void cpuidle_general_output(void)
79 tmp = sysfs_get_cpuidle_driver();
81 printf(_("Could not determine cpuidle driver\n"));
85 printf(_("CPUidle driver: %s\n"), tmp);
88 tmp = sysfs_get_cpuidle_governor();
90 printf(_("Could not determine cpuidle governor\n"));
94 printf(_("CPUidle governor: %s\n"), tmp);
98 static void proc_cpuidle_cpu_output(unsigned int cpu)
100 long max_allowed_cstate = 2000000000;
103 cstates = sysfs_get_idlestate_count(cpu);
106 * Go on and print same useless info as you'd see with
107 * cat /proc/acpi/processor/../power
108 * printf(_("CPU %u: No C-states available\n"), cpu);
111 } else if (cstates <= 0) {
112 printf(_("CPU %u: Can't read C-state info\n"), cpu);
115 /* printf("Cstates: %d\n", cstates); */
117 printf(_("active state: C0\n"));
118 printf(_("max_cstate: C%u\n"), cstates-1);
119 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate);
120 printf(_("states:\t\n"));
121 for (cstate = 1; cstate < cstates; cstate++) {
123 "type[C%d] "), cstate, cstate);
124 printf(_("promotion[--] demotion[--] "));
125 printf(_("latency[%03lu] "),
126 sysfs_get_idlestate_latency(cpu, cstate));
127 printf(_("usage[%08lu] "),
128 sysfs_get_idlestate_usage(cpu, cstate));
129 printf(_("duration[%020Lu] \n"),
130 sysfs_get_idlestate_time(cpu, cstate));
134 static struct option info_opts[] = {
135 { .name = "silent", .has_arg = no_argument, .flag = NULL, .val = 's'},
136 { .name = "proc", .has_arg = no_argument, .flag = NULL, .val = 'o'},
140 static inline void cpuidle_exit(int fail)
145 int cmd_idle_info(int argc, char **argv)
148 extern int optind, opterr, optopt;
149 int ret = 0, cont = 1, output_param = 0, verbose = 1;
150 unsigned int cpu = 0;
153 ret = getopt_long(argc, argv, "os", info_opts, NULL);
178 switch (output_param) {
180 printf(_("You can't specify more than one "
181 "output-specific argument\n"));
182 cpuidle_exit(EXIT_FAILURE);
184 printf(_("invalid or unknown argument\n"));
185 cpuidle_exit(EXIT_FAILURE);
188 /* Default is: show output of CPU 0 only */
189 if (bitmask_isallclear(cpus_chosen))
190 bitmask_setbit(cpus_chosen, 0);
192 if (output_param == 0)
193 cpuidle_general_output();
195 for (cpu = bitmask_first(cpus_chosen);
196 cpu <= bitmask_last(cpus_chosen); cpu++) {
198 if (!bitmask_isbitset(cpus_chosen, cpu) ||
199 cpufreq_cpu_exists(cpu))
202 switch (output_param) {
205 proc_cpuidle_cpu_output(cpu);
209 cpuidle_cpu_output(cpu, verbose);