1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
13 #include <sys/utsname.h>
15 #include "helpers/helpers.h"
16 #include "helpers/sysfs.h"
17 #include "helpers/bitmask.h"
19 static struct option set_opts
[] = {
20 {"perf-bias", required_argument
, NULL
, 'b'},
24 static void print_wrong_arg_exit(void)
26 printf(_("invalid or unknown argument\n"));
30 int cmd_set(int argc
, char **argv
)
33 extern int optind
, opterr
, optopt
;
47 if (!ret
&& (!strcmp(uts
.machine
, "ppc64le") ||
48 !strcmp(uts
.machine
, "ppc64"))) {
49 fprintf(stderr
, _("Subcommand not supported on POWER.\n"));
53 setlocale(LC_ALL
, "");
57 /* parameter parsing */
58 while ((ret
= getopt_long(argc
, argv
, "b:",
59 set_opts
, NULL
)) != -1) {
63 print_wrong_arg_exit();
64 perf_bias
= atoi(optarg
);
65 if (perf_bias
< 0 || perf_bias
> 15) {
66 printf(_("--perf-bias param out "
67 "of range [0-%d]\n"), 15);
68 print_wrong_arg_exit();
73 print_wrong_arg_exit();
78 print_wrong_arg_exit();
80 /* Default is: set all CPUs */
81 if (bitmask_isallclear(cpus_chosen
))
82 bitmask_setall(cpus_chosen
);
85 for (cpu
= bitmask_first(cpus_chosen
);
86 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
88 if (!bitmask_isbitset(cpus_chosen
, cpu
))
91 if (sysfs_is_cpu_online(cpu
) != 1){
92 fprintf(stderr
, _("Cannot set values on CPU %d:"), cpu
);
93 fprintf(stderr
, _(" *is offline\n"));
97 if (params
.perf_bias
) {
98 ret
= cpupower_intel_set_perf_bias(cpu
, perf_bias
);
100 fprintf(stderr
, _("Error setting perf-bias "
101 "value on CPU %d\n"), cpu
);