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.
16 #include "helpers/helpers.h"
17 #include "helpers/sysfs.h"
18 #include "helpers/bitmask.h"
22 static void cpuidle_cpu_output(unsigned int cpu, int verbose)
24 unsigned int idlestates, idlestate;
27 idlestates = sysfs_get_idlestate_count(cpu);
28 if (idlestates == 0) {
29 printf(_("CPU %u: No idle states\n"), cpu);
33 printf(_("Number of idle states: %d\n"), idlestates);
34 printf(_("Available idle states:"));
35 for (idlestate = 0; idlestate < idlestates; idlestate++) {
36 tmp = sysfs_get_idlestate_name(cpu, idlestate);
47 for (idlestate = 0; idlestate < idlestates; idlestate++) {
48 int disabled = sysfs_is_idlestate_disabled(cpu, idlestate);
49 /* Disabled interface not supported on older kernels */
52 tmp = sysfs_get_idlestate_name(cpu, idlestate);
55 printf("%s%s:\n", tmp, (disabled) ? " (DISABLED) " : "");
58 tmp = sysfs_get_idlestate_desc(cpu, idlestate);
61 printf(_("Flags/Description: %s\n"), tmp);
64 printf(_("Latency: %lu\n"),
65 sysfs_get_idlestate_latency(cpu, idlestate));
66 printf(_("Usage: %lu\n"),
67 sysfs_get_idlestate_usage(cpu, idlestate));
68 printf(_("Duration: %llu\n"),
69 sysfs_get_idlestate_time(cpu, idlestate));
73 static void cpuidle_general_output(void)
77 tmp = sysfs_get_cpuidle_driver();
79 printf(_("Could not determine cpuidle driver\n"));
83 printf(_("CPUidle driver: %s\n"), tmp);
86 tmp = sysfs_get_cpuidle_governor();
88 printf(_("Could not determine cpuidle governor\n"));
92 printf(_("CPUidle governor: %s\n"), tmp);
96 static void proc_cpuidle_cpu_output(unsigned int cpu)
98 long max_allowed_cstate = 2000000000;
99 unsigned int cstate, cstates;
101 cstates = sysfs_get_idlestate_count(cpu);
103 printf(_("CPU %u: No C-states info\n"), cpu);
107 printf(_("active state: C0\n"));
108 printf(_("max_cstate: C%u\n"), cstates-1);
109 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate);
110 printf(_("states:\t\n"));
111 for (cstate = 1; cstate < cstates; cstate++) {
113 "type[C%d] "), cstate, cstate);
114 printf(_("promotion[--] demotion[--] "));
115 printf(_("latency[%03lu] "),
116 sysfs_get_idlestate_latency(cpu, cstate));
117 printf(_("usage[%08lu] "),
118 sysfs_get_idlestate_usage(cpu, cstate));
119 printf(_("duration[%020Lu] \n"),
120 sysfs_get_idlestate_time(cpu, cstate));
124 static struct option info_opts[] = {
125 {"silent", no_argument, NULL, 's'},
126 {"proc", no_argument, NULL, 'o'},
130 static inline void cpuidle_exit(int fail)
135 int cmd_idle_info(int argc, char **argv)
138 extern int optind, opterr, optopt;
139 int ret = 0, cont = 1, output_param = 0, verbose = 1;
140 unsigned int cpu = 0;
143 ret = getopt_long(argc, argv, "os", info_opts, NULL);
168 switch (output_param) {
170 printf(_("You can't specify more than one "
171 "output-specific argument\n"));
172 cpuidle_exit(EXIT_FAILURE);
174 printf(_("invalid or unknown argument\n"));
175 cpuidle_exit(EXIT_FAILURE);
178 /* Default is: show output of CPU 0 only */
179 if (bitmask_isallclear(cpus_chosen))
180 bitmask_setbit(cpus_chosen, 0);
182 if (output_param == 0)
183 cpuidle_general_output();
185 for (cpu = bitmask_first(cpus_chosen);
186 cpu <= bitmask_last(cpus_chosen); cpu++) {
188 if (!bitmask_isbitset(cpus_chosen, cpu))
191 printf(_("analyzing CPU %d:\n"), cpu);
193 if (sysfs_is_cpu_online(cpu) != 1) {
194 printf(_(" *is offline\n"));
199 switch (output_param) {
202 proc_cpuidle_cpu_output(cpu);
206 cpuidle_cpu_output(cpu, verbose);