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'},
21 {"epp", required_argument
, NULL
, 'e'},
22 {"amd-pstate-mode", required_argument
, NULL
, 'm'},
23 {"turbo-boost", required_argument
, NULL
, 't'},
27 static void print_wrong_arg_exit(void)
29 printf(_("invalid or unknown argument\n"));
33 int cmd_set(int argc
, char **argv
)
36 extern int optind
, opterr
, optopt
;
49 int perf_bias
= 0, turbo_boost
= 1;
51 char epp
[30], mode
[20];
54 if (!ret
&& (!strcmp(uts
.machine
, "ppc64le") ||
55 !strcmp(uts
.machine
, "ppc64"))) {
56 fprintf(stderr
, _("Subcommand not supported on POWER.\n"));
60 setlocale(LC_ALL
, "");
64 /* parameter parsing */
65 while ((ret
= getopt_long(argc
, argv
, "b:e:m:",
66 set_opts
, NULL
)) != -1) {
70 print_wrong_arg_exit();
71 perf_bias
= atoi(optarg
);
72 if (perf_bias
< 0 || perf_bias
> 15) {
73 printf(_("--perf-bias param out "
74 "of range [0-%d]\n"), 15);
75 print_wrong_arg_exit();
81 print_wrong_arg_exit();
82 if (sscanf(optarg
, "%29s", epp
) != 1) {
83 print_wrong_arg_exit();
89 if (cpupower_cpu_info
.vendor
!= X86_VENDOR_AMD
)
90 print_wrong_arg_exit();
92 print_wrong_arg_exit();
93 if (sscanf(optarg
, "%19s", mode
) != 1) {
94 print_wrong_arg_exit();
100 if (params
.turbo_boost
)
101 print_wrong_arg_exit();
102 turbo_boost
= atoi(optarg
);
103 if (turbo_boost
< 0 || turbo_boost
> 1) {
104 printf("--turbo-boost param out of range [0-1]\n");
105 print_wrong_arg_exit();
107 params
.turbo_boost
= 1;
112 print_wrong_arg_exit();
117 print_wrong_arg_exit();
120 ret
= cpupower_set_amd_pstate_mode(mode
);
122 fprintf(stderr
, "Error setting mode\n");
125 if (params
.turbo_boost
) {
126 ret
= cpupower_set_turbo_boost(turbo_boost
);
128 fprintf(stderr
, "Error setting turbo-boost\n");
131 /* Default is: set all CPUs */
132 if (bitmask_isallclear(cpus_chosen
))
133 bitmask_setall(cpus_chosen
);
136 for (cpu
= bitmask_first(cpus_chosen
);
137 cpu
<= bitmask_last(cpus_chosen
); cpu
++) {
139 if (!bitmask_isbitset(cpus_chosen
, cpu
))
142 if (sysfs_is_cpu_online(cpu
) != 1){
143 fprintf(stderr
, _("Cannot set values on CPU %d:"), cpu
);
144 fprintf(stderr
, _(" *is offline\n"));
148 if (params
.perf_bias
) {
149 ret
= cpupower_intel_set_perf_bias(cpu
, perf_bias
);
151 fprintf(stderr
, _("Error setting perf-bias "
152 "value on CPU %d\n"), cpu
);
158 ret
= cpupower_set_epp(cpu
, epp
);
161 "Error setting epp value on CPU %d\n", cpu
);