13 #include "helpers/helpers.h"
15 static struct option info_opts
[] = {
16 {"disable", required_argument
, NULL
, 'd'},
17 {"enable", required_argument
, NULL
, 'e'},
18 {"disable-by-latency", required_argument
, NULL
, 'D'},
19 {"enable-all", no_argument
, NULL
, 'E'},
24 int cmd_idle_set(int argc
, char **argv
)
27 extern int optind
, opterr
, optopt
;
28 int ret
= 0, cont
= 1, param
= 0, disabled
;
29 unsigned long long latency
= 0, state_latency
;
30 unsigned int cpu
= 0, idlestate
= 0, idlestates
= 0;
34 ret
= getopt_long(argc
, argv
, "d:e:ED:", info_opts
, NULL
);
49 idlestate
= atoi(optarg
);
58 idlestate
= atoi(optarg
);
67 latency
= strtoull(optarg
, &endptr
, 10);
68 if (*endptr
!= '\0') {
69 printf(_("Bad latency value: %s\n"), optarg
);
89 printf(_("You can't specify more than one "
90 "output-specific argument\n"));
93 printf(_("invalid or unknown argument\n"));
97 /* Default is: set all CPUs */
98 if (bitmask_isallclear(cpus_chosen
))
99 bitmask_setall(cpus_chosen
);
101 for (cpu
= bitmask_first(cpus_chosen
);
102 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
104 if (!bitmask_isbitset(cpus_chosen
, cpu
))
107 if (cpupower_is_cpu_online(cpu
) != 1)
110 idlestates
= cpuidle_state_count(cpu
);
116 ret
= cpuidle_state_disable(cpu
, idlestate
, 1);
118 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate
, cpu
);
120 printf(_("Idlestate %u not available on CPU %u\n"),
123 printf(_("Idlestate disabling not supported by kernel\n"));
125 printf(_("Idlestate %u not disabled on CPU %u\n"),
129 ret
= cpuidle_state_disable(cpu
, idlestate
, 0);
131 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
133 printf(_("Idlestate %u not available on CPU %u\n"),
136 printf(_("Idlestate enabling not supported by kernel\n"));
138 printf(_("Idlestate %u not enabled on CPU %u\n"),
142 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
143 disabled
= cpuidle_is_state_disabled
145 state_latency
= cpuidle_state_latency
148 if (latency
> state_latency
){
149 ret
= cpuidle_state_disable
152 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
156 if (latency
<= state_latency
){
157 ret
= cpuidle_state_disable
160 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate
, cpu
);
165 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
166 disabled
= cpuidle_is_state_disabled
169 ret
= cpuidle_state_disable
172 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
177 /* Not reachable with proper args checking */
178 printf(_("Invalid or unknown argument\n"));