mirror of
https://github.com/torvalds/linux.git
synced 2024-12-25 04:11:49 +00:00
7b0bf99b9e
Fixes coccicheck warnings: tools/power/cpupower/utils/cpupower-info.c:65:2-3: Unneeded semicolon tools/power/cpupower/utils/cpupower-set.c:75:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c:120:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c:175:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c:56:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c:75:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/hsw_ext_idle.c:82:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/nhm_idle.c:94:2-3: Unneeded semicolon tools/power/cpupower/utils/idle_monitor/snb_idle.c:80:2-3: Unneeded semicolon Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Zou Wei <zou_wei@huawei.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
108 lines
2.1 KiB
C
108 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* (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>
|
|
#include <sys/utsname.h>
|
|
|
|
#include "helpers/helpers.h"
|
|
#include "helpers/sysfs.h"
|
|
#include "helpers/bitmask.h"
|
|
|
|
static struct option set_opts[] = {
|
|
{"perf-bias", required_argument, NULL, 'b'},
|
|
{ },
|
|
};
|
|
|
|
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;
|
|
struct utsname uts;
|
|
|
|
union {
|
|
struct {
|
|
int perf_bias:1;
|
|
};
|
|
int params;
|
|
} params;
|
|
int perf_bias = 0;
|
|
int ret = 0;
|
|
|
|
ret = uname(&uts);
|
|
if (!ret && (!strcmp(uts.machine, "ppc64le") ||
|
|
!strcmp(uts.machine, "ppc64"))) {
|
|
fprintf(stderr, _("Subcommand not supported on POWER.\n"));
|
|
return ret;
|
|
}
|
|
|
|
setlocale(LC_ALL, "");
|
|
textdomain(PACKAGE);
|
|
|
|
params.params = 0;
|
|
/* parameter parsing */
|
|
while ((ret = getopt_long(argc, argv, "b:",
|
|
set_opts, NULL)) != -1) {
|
|
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();
|
|
}
|
|
}
|
|
|
|
if (!params.params)
|
|
print_wrong_arg_exit();
|
|
|
|
/* 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++) {
|
|
|
|
if (!bitmask_isbitset(cpus_chosen, cpu))
|
|
continue;
|
|
|
|
if (sysfs_is_cpu_online(cpu) != 1){
|
|
fprintf(stderr, _("Cannot set values on CPU %d:"), cpu);
|
|
fprintf(stderr, _(" *is offline\n"));
|
|
continue;
|
|
}
|
|
|
|
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;
|
|
}
|