1 // SPDX-License-Identifier: GPL-2.0
14 #include "helpers/helpers.h"
16 static struct option info_opts
[] = {
17 {"disable", required_argument
, NULL
, 'd'},
18 {"enable", required_argument
, NULL
, 'e'},
19 {"disable-by-latency", required_argument
, NULL
, 'D'},
20 {"enable-all", no_argument
, NULL
, 'E'},
25 int cmd_idle_set(int argc
, char **argv
)
28 extern int optind
, opterr
, optopt
;
29 int ret
= 0, cont
= 1, param
= 0, disabled
;
30 unsigned long long latency
= 0, state_latency
;
31 unsigned int cpu
= 0, idlestate
= 0, idlestates
= 0;
35 ret
= getopt_long(argc
, argv
, "d:e:ED:", info_opts
, NULL
);
50 idlestate
= atoi(optarg
);
59 idlestate
= atoi(optarg
);
68 latency
= strtoull(optarg
, &endptr
, 10);
69 if (*endptr
!= '\0') {
70 printf(_("Bad latency value: %s\n"), optarg
);
90 printf(_("You can't specify more than one "
91 "output-specific argument\n"));
94 printf(_("invalid or unknown argument\n"));
98 /* Default is: set all CPUs */
99 if (bitmask_isallclear(cpus_chosen
))
100 bitmask_setall(cpus_chosen
);
102 for (cpu
= bitmask_first(cpus_chosen
);
103 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
105 if (!bitmask_isbitset(cpus_chosen
, cpu
))
108 if (cpupower_is_cpu_online(cpu
) != 1)
111 idlestates
= cpuidle_state_count(cpu
);
117 ret
= cpuidle_state_disable(cpu
, idlestate
, 1);
119 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate
, cpu
);
121 printf(_("Idlestate %u not available on CPU %u\n"),
124 printf(_("Idlestate disabling not supported by kernel\n"));
126 printf(_("Idlestate %u not disabled on CPU %u\n"),
130 ret
= cpuidle_state_disable(cpu
, idlestate
, 0);
132 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
134 printf(_("Idlestate %u not available on CPU %u\n"),
137 printf(_("Idlestate enabling not supported by kernel\n"));
139 printf(_("Idlestate %u not enabled on CPU %u\n"),
143 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
144 disabled
= cpuidle_is_state_disabled
146 state_latency
= cpuidle_state_latency
149 if (latency
> state_latency
){
150 ret
= cpuidle_state_disable
153 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
157 if (latency
<= state_latency
){
158 ret
= cpuidle_state_disable
161 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate
, cpu
);
166 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
167 disabled
= cpuidle_is_state_disabled
170 ret
= cpuidle_state_disable
173 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
178 /* Not reachable with proper args checking */
179 printf(_("Invalid or unknown argument\n"));