1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
4 * (C) 2010 Thomas Renninger <trenn@suse.de>
17 #include "helpers/sysfs.h"
18 #include "helpers/helpers.h"
19 #include "helpers/bitmask.h"
23 static void cpuidle_cpu_output(unsigned int cpu
, int verbose
)
25 unsigned int idlestates
, idlestate
;
28 idlestates
= cpuidle_state_count(cpu
);
29 if (idlestates
== 0) {
30 printf(_("CPU %u: No idle states\n"), cpu
);
34 printf(_("Number of idle states: %d\n"), idlestates
);
35 printf(_("Available idle states:"));
36 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
37 tmp
= cpuidle_state_name(cpu
, idlestate
);
48 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
49 int disabled
= cpuidle_is_state_disabled(cpu
, idlestate
);
50 /* Disabled interface not supported on older kernels */
53 tmp
= cpuidle_state_name(cpu
, idlestate
);
56 printf("%s%s:\n", tmp
, (disabled
) ? " (DISABLED) " : "");
59 tmp
= cpuidle_state_desc(cpu
, idlestate
);
62 printf(_("Flags/Description: %s\n"), tmp
);
65 printf(_("Latency: %lu\n"),
66 cpuidle_state_latency(cpu
, idlestate
));
67 printf(_("Residency: %lu\n"),
68 cpuidle_state_residency(cpu
, idlestate
));
69 printf(_("Usage: %lu\n"),
70 cpuidle_state_usage(cpu
, idlestate
));
71 printf(_("Duration: %llu\n"),
72 cpuidle_state_time(cpu
, idlestate
));
76 static void cpuidle_general_output(void)
80 tmp
= cpuidle_get_driver();
82 printf(_("Could not determine cpuidle driver\n"));
86 printf(_("CPUidle driver: %s\n"), tmp
);
89 tmp
= cpuidle_get_governor();
91 printf(_("Could not determine cpuidle governor\n"));
95 printf(_("CPUidle governor: %s\n"), tmp
);
99 static void proc_cpuidle_cpu_output(unsigned int cpu
)
101 long max_allowed_cstate
= 2000000000;
102 unsigned int cstate
, cstates
;
104 cstates
= cpuidle_state_count(cpu
);
106 printf(_("CPU %u: No C-states info\n"), cpu
);
110 printf(_("active state: C0\n"));
111 printf(_("max_cstate: C%u\n"), cstates
-1);
112 printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate
);
113 printf(_("states:\t\n"));
114 for (cstate
= 1; cstate
< cstates
; cstate
++) {
116 "type[C%d] "), cstate
, cstate
);
117 printf(_("promotion[--] demotion[--] "));
118 printf(_("latency[%03lu] "),
119 cpuidle_state_latency(cpu
, cstate
));
120 printf(_("residency[%05lu] "),
121 cpuidle_state_residency(cpu
, cstate
));
122 printf(_("usage[%08lu] "),
123 cpuidle_state_usage(cpu
, cstate
));
124 printf(_("duration[%020Lu] \n"),
125 cpuidle_state_time(cpu
, cstate
));
129 static struct option info_opts
[] = {
130 {"silent", no_argument
, NULL
, 's'},
131 {"proc", no_argument
, NULL
, 'o'},
135 static inline void cpuidle_exit(int fail
)
140 int cmd_idle_info(int argc
, char **argv
)
143 extern int optind
, opterr
, optopt
;
144 int ret
= 0, cont
= 1, output_param
= 0, verbose
= 1;
145 unsigned int cpu
= 0;
148 ret
= getopt_long(argc
, argv
, "os", info_opts
, NULL
);
173 switch (output_param
) {
175 printf(_("You can't specify more than one "
176 "output-specific argument\n"));
177 cpuidle_exit(EXIT_FAILURE
);
179 printf(_("invalid or unknown argument\n"));
180 cpuidle_exit(EXIT_FAILURE
);
183 /* Default is: show output of base_cpu only */
184 if (bitmask_isallclear(cpus_chosen
))
185 bitmask_setbit(cpus_chosen
, base_cpu
);
187 if (output_param
== 0)
188 cpuidle_general_output();
190 for (cpu
= bitmask_first(cpus_chosen
);
191 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
193 if (!bitmask_isbitset(cpus_chosen
, cpu
))
196 printf(_("analyzing CPU %d:\n"), cpu
);
198 if (sysfs_is_cpu_online(cpu
) != 1) {
199 printf(_(" *is offline\n"));
204 switch (output_param
) {
207 proc_cpuidle_cpu_output(cpu
);
211 cpuidle_cpu_output(cpu
, verbose
);