12 #include "helpers/helpers.h"
13 #include "helpers/sysfs.h"
15 static struct option info_opts
[] = {
17 .has_arg
= required_argument
, .flag
= NULL
, .val
= 'd'},
19 .has_arg
= required_argument
, .flag
= NULL
, .val
= 'e'},
20 { .name
= "disable-by-latency",
21 .has_arg
= required_argument
, .flag
= NULL
, .val
= 'D'},
22 { .name
= "enable-all",
23 .has_arg
= no_argument
, .flag
= NULL
, .val
= 'E'},
28 int cmd_idle_set(int argc
, char **argv
)
31 extern int optind
, opterr
, optopt
;
32 int ret
= 0, cont
= 1, param
= 0, disabled
;
33 unsigned long long latency
= 0, state_latency
;
34 unsigned int cpu
= 0, idlestate
= 0, idlestates
= 0;
38 ret
= getopt_long(argc
, argv
, "d:e:ED:", info_opts
, NULL
);
53 idlestate
= atoi(optarg
);
62 idlestate
= atoi(optarg
);
71 latency
= strtoull(optarg
, &endptr
, 10);
72 if (*endptr
!= '\0') {
73 printf(_("Bad latency value: %s\n"), optarg
);
93 printf(_("You can't specify more than one "
94 "output-specific argument\n"));
97 printf(_("invalid or unknown argument\n"));
101 /* Default is: set all CPUs */
102 if (bitmask_isallclear(cpus_chosen
))
103 bitmask_setall(cpus_chosen
);
105 for (cpu
= bitmask_first(cpus_chosen
);
106 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
108 if (!bitmask_isbitset(cpus_chosen
, cpu
))
111 if (sysfs_is_cpu_online(cpu
) != 1)
114 idlestates
= sysfs_get_idlestate_count(cpu
);
120 ret
= sysfs_idlestate_disable(cpu
, idlestate
, 1);
122 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate
, cpu
);
124 printf(_("Idlestate %u not available on CPU %u\n"),
127 printf(_("Idlestate disabling not supported by kernel\n"));
129 printf(_("Idlestate %u not disabled on CPU %u\n"),
133 ret
= sysfs_idlestate_disable(cpu
, idlestate
, 0);
135 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
137 printf(_("Idlestate %u not available on CPU %u\n"),
140 printf(_("Idlestate enabling not supported by kernel\n"));
142 printf(_("Idlestate %u not enabled on CPU %u\n"),
146 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
147 disabled
= sysfs_is_idlestate_disabled
149 state_latency
= sysfs_get_idlestate_latency
152 if (latency
> state_latency
){
153 ret
= sysfs_idlestate_disable
156 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
160 if (latency
<= state_latency
){
161 ret
= sysfs_idlestate_disable
164 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate
, cpu
);
169 for (idlestate
= 0; idlestate
< idlestates
; idlestate
++) {
170 disabled
= sysfs_is_idlestate_disabled
173 ret
= sysfs_idlestate_disable
176 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate
, cpu
);
181 /* Not reachable with proper args checking */
182 printf(_("Invalid or unknown argument\n"));