2019-05-27 06:55:14 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-03-30 14:30:11 +00:00
|
|
|
/*
|
|
|
|
* (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
2019-10-17 05:56:39 +00:00
|
|
|
#include <sys/utsname.h>
|
2011-03-30 14:30:11 +00:00
|
|
|
|
|
|
|
#include "helpers/helpers.h"
|
|
|
|
#include "helpers/sysfs.h"
|
|
|
|
#include "helpers/bitmask.h"
|
|
|
|
|
|
|
|
static struct option set_opts[] = {
|
2015-10-23 07:52:45 +00:00
|
|
|
{"perf-bias", required_argument, NULL, 'b'},
|
2011-03-30 14:30:11 +00:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void print_wrong_arg_exit(void)
|
|
|
|
{
|
|
|
|
printf(_("invalid or unknown argument\n"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_set(int argc, char **argv)
|
|
|
|
{
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind, opterr, optopt;
|
|
|
|
unsigned int cpu;
|
2019-10-17 05:56:39 +00:00
|
|
|
struct utsname uts;
|
2011-03-30 14:30:11 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int perf_bias:1;
|
|
|
|
};
|
|
|
|
int params;
|
|
|
|
} params;
|
2014-05-13 10:41:45 +00:00
|
|
|
int perf_bias = 0;
|
2011-03-30 14:30:11 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2019-10-17 05:56:39 +00:00
|
|
|
ret = uname(&uts);
|
|
|
|
if (!ret && (!strcmp(uts.machine, "ppc64le") ||
|
|
|
|
!strcmp(uts.machine, "ppc64"))) {
|
|
|
|
fprintf(stderr, _("Subcommand not supported on POWER.\n"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:30:11 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2011-04-19 18:33:50 +00:00
|
|
|
textdomain(PACKAGE);
|
2011-03-30 14:30:11 +00:00
|
|
|
|
|
|
|
params.params = 0;
|
|
|
|
/* parameter parsing */
|
2014-05-13 10:41:45 +00:00
|
|
|
while ((ret = getopt_long(argc, argv, "b:",
|
2011-04-19 18:33:50 +00:00
|
|
|
set_opts, NULL)) != -1) {
|
2011-03-30 14:30:11 +00:00
|
|
|
switch (ret) {
|
|
|
|
case 'b':
|
|
|
|
if (params.perf_bias)
|
|
|
|
print_wrong_arg_exit();
|
|
|
|
perf_bias = atoi(optarg);
|
|
|
|
if (perf_bias < 0 || perf_bias > 15) {
|
|
|
|
printf(_("--perf-bias param out "
|
|
|
|
"of range [0-%d]\n"), 15);
|
|
|
|
print_wrong_arg_exit();
|
|
|
|
}
|
|
|
|
params.perf_bias = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
print_wrong_arg_exit();
|
|
|
|
}
|
2020-04-28 09:43:15 +00:00
|
|
|
}
|
2011-03-30 14:30:11 +00:00
|
|
|
|
2011-08-06 16:11:43 +00:00
|
|
|
if (!params.params)
|
|
|
|
print_wrong_arg_exit();
|
2011-03-30 14:30:11 +00:00
|
|
|
|
|
|
|
/* Default is: set all CPUs */
|
|
|
|
if (bitmask_isallclear(cpus_chosen))
|
|
|
|
bitmask_setall(cpus_chosen);
|
|
|
|
|
|
|
|
/* loop over CPUs */
|
|
|
|
for (cpu = bitmask_first(cpus_chosen);
|
|
|
|
cpu <= bitmask_last(cpus_chosen); cpu++) {
|
2011-04-19 18:33:50 +00:00
|
|
|
|
2015-12-01 16:14:15 +00:00
|
|
|
if (!bitmask_isbitset(cpus_chosen, cpu))
|
2011-03-30 14:30:11 +00:00
|
|
|
continue;
|
|
|
|
|
2015-12-01 16:14:15 +00:00
|
|
|
if (sysfs_is_cpu_online(cpu) != 1){
|
|
|
|
fprintf(stderr, _("Cannot set values on CPU %d:"), cpu);
|
|
|
|
fprintf(stderr, _(" *is offline\n"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:30:11 +00:00
|
|
|
if (params.perf_bias) {
|
|
|
|
ret = msr_intel_set_perf_bias(cpu, perf_bias);
|
|
|
|
if (ret) {
|
|
|
|
fprintf(stderr, _("Error setting perf-bias "
|
|
|
|
"value on CPU %d\n"), cpu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|