21 #define NORM_FREQ_LEN 32
23 static struct option set_opts[] = {
24 { .name =
"min", .has_arg = required_argument, .flag =
NULL, .val =
'd'},
25 { .name =
"max", .has_arg = required_argument, .flag =
NULL, .val =
'u'},
26 { .name =
"governor", .has_arg = required_argument, .flag =
NULL, .val =
'g'},
27 { .name =
"freq", .has_arg = required_argument, .flag =
NULL, .val =
'f'},
28 { .name =
"related", .has_arg = no_argument, .flag =
NULL, .val=
'r'},
32 static void print_error(
void)
34 printf(
_(
"Error setting new values. Common errors:\n"
35 "- Do you have proper administration rights? (super-user?)\n"
36 "- Is the governor you requested available and modprobed?\n"
37 "- Trying to set an invalid policy?\n"
38 "- Trying to set a specific frequency, but userspace governor is not available,\n"
39 " for example because of hardware which cannot be set to a specific frequency\n"
40 " or because the userspace governor isn't loaded?\n"));
57 static void print_unknown_arg(
void)
59 printf(
_(
"invalid or unknown argument\n"));
62 static unsigned long string_to_frequency(
const char *
str)
74 for (scan = str;
isdigit(*scan) || *scan ==
'.'; scan++) {
83 for (unit = def_units; unit->
str_unit; unit++) {
98 for (cp = 0;
isdigit(str[cp]); cp++)
101 if (str[cp] ==
'.') {
102 while (power > -1 &&
isdigit(str[cp+1]))
108 pad = 0, cp += power + 1;
114 for (
i = 0;
i <
cp;
i++, str++) {
117 normalized[
i] = *
str;
120 for (;
i < cp +
pad;
i++)
130 freq = strtoul(normalized, &end, 10);
146 printf(
_(
"wrong, unknown or unhandled CPU?\n"));
151 new_pol->
min = cur_pol->
min;
154 new_pol->
max = cur_pol->
max;
167 static int do_one_cpu(
unsigned int cpu,
struct cpufreq_policy *new_pol,
168 unsigned long freq,
unsigned int pc)
180 else if (new_pol->
max)
188 return do_new_policy(cpu, new_pol);
195 extern int optind, opterr, optopt;
196 int ret = 0,
cont = 1;
197 int double_parm = 0, related = 0, policychange = 0;
198 unsigned long freq = 0;
210 ret = getopt_long(argc, argv,
"d:u:g:f:r", set_opts,
NULL);
227 new_pol.
min = string_to_frequency(optarg);
228 if (new_pol.
min == 0) {
237 new_pol.
max = string_to_frequency(optarg);
238 if (new_pol.
max == 0) {
246 freq = string_to_frequency(optarg);
260 if ((
sscanf(optarg,
"%s", gov)) != 1) {
271 printf(
"the same parameter was passed more than once\n");
275 if (freq && policychange) {
276 printf(
_(
"the -f/--freq parameter cannot be combined with -d/--min, -u/--max or\n"
277 "-g/--governor parameters\n"));
281 if (!freq && !policychange) {
282 printf(
_(
"At least one parameter out of -f/--freq, -d/--min, -u/--max, and\n"
283 "-g/--governor must be passed\n"));
321 printf(
_(
"Setting cpu: %d\n"), cpu);
322 ret = do_one_cpu(cpu, &new_pol, freq, policychange);