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.
18 #include "helpers/sysfs.h"
19 #include "helpers/helpers.h"
20 #include "helpers/bitmask.h"
24 static void cpuidle_cpu_output(unsigned int cpu, int verbose)
26 unsigned int idlestates, idlestate;
29 idlestates = cpuidle_state_count(cpu);
30 if (idlestates == 0) {
31 printf(_("CPU %u: No idle states\n"), cpu);
35 printf(_("Number of idle states: %d\n"), idlestates);
36 printf(_("Available idle states:"));
37 for (idlestate = 0; idlestate < idlestates; idlestate++) {
38 tmp = cpuidle_state_name(cpu, idlestate);
49 for (idlestate = 0; idlestate < idlestates; idlestate++) {
50 int disabled = cpuidle_is_state_disabled(cpu, idlestate);
51 /* Disabled interface not supported on older kernels */
54 tmp = cpuidle_state_name(cpu, idlestate);
57 printf("%s%s:\n", tmp, (disabled) ? " (DISABLED) " : "");
60 tmp = cpuidle_state_desc(cpu, idlestate);
63 printf(_("Flags/Description: %s\n"), tmp);
66 printf(_("Latency: %lu\n"),
67 cpuidle_state_latency(cpu, idlestate));
68 printf(_("Usage: %lu\n"),
69 cpuidle_state_usage(cpu, idlestate));
70 printf(_("Duration: %llu\n"),
71 cpuidle_state_time(cpu, idlestate));
75 static void cpuidle_general_output(void)
79 tmp = cpuidle_get_driver();
81 printf(_("Could not determine cpuidle driver\n"));
85 printf(_("CPUidle driver: %s\n"), tmp);
88 tmp = cpuidle_get_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;
101 unsigned int cstate, cstates;
103 cstates = cpuidle_state_count(cpu);
105 printf(_("CPU %u: No C-states info\n"), cpu);
109 printf(_("active state: C0\n"));
110 printf(_("max_cstate: C%u\n"), cstates-1);
111 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate);
112 printf(_("states:\t\n"));
113 for (cstate = 1; cstate < cstates; cstate++) {
115 "type[C%d] "), cstate, cstate);
116 printf(_("promotion[--] demotion[--] "));
117 printf(_("latency[%03lu] "),
118 cpuidle_state_latency(cpu, cstate));
119 printf(_("usage[%08lu] "),
120 cpuidle_state_usage(cpu, cstate));
121 printf(_("duration[%020Lu] \n"),
122 cpuidle_state_time(cpu, cstate));
126 static struct option info_opts[] = {
127 {"silent", no_argument, NULL, 's'},
128 {"proc", no_argument, NULL, 'o'},
132 static inline void cpuidle_exit(int fail)
137 int cmd_idle_info(int argc, char **argv)
140 extern int optind, opterr, optopt;
141 int ret = 0, cont = 1, output_param = 0, verbose = 1;
142 unsigned int cpu = 0;
145 ret = getopt_long(argc, argv, "os", info_opts, NULL);
170 switch (output_param) {
172 printf(_("You can't specify more than one "
173 "output-specific argument\n"));
174 cpuidle_exit(EXIT_FAILURE);
176 printf(_("invalid or unknown argument\n"));
177 cpuidle_exit(EXIT_FAILURE);
180 /* Default is: show output of CPU 0 only */
181 if (bitmask_isallclear(cpus_chosen))
182 bitmask_setbit(cpus_chosen, 0);
184 if (output_param == 0)
185 cpuidle_general_output();
187 for (cpu = bitmask_first(cpus_chosen);
188 cpu <= bitmask_last(cpus_chosen); cpu++) {
190 if (!bitmask_isbitset(cpus_chosen, cpu))
193 printf(_("analyzing CPU %d:\n"), cpu);
195 if (sysfs_is_cpu_online(cpu) != 1) {
196 printf(_(" *is offline\n"));
201 switch (output_param) {
204 proc_cpuidle_cpu_output(cpu);
208 cpuidle_cpu_output(cpu, verbose);