mirror of
https://github.com/torvalds/linux.git
synced 2024-12-26 12:52:30 +00:00
57ab3b0872
This patch tries to creates a common structure initialization within the cpupower tool. Previously the ``struct option`` was initialized using `designated initializer` technique which was not needed. There were conflicting initialization methods seen with bench/main.c & others. Signed-off-by: Sriram Raghunathan <sriram@marirs.net.in> Signed-off-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
96 lines
1.8 KiB
C
96 lines
1.8 KiB
C
/*
|
|
* (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
|
|
*
|
|
* Licensed under the terms of the GNU GPL License version 2.
|
|
*/
|
|
|
|
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <getopt.h>
|
|
|
|
#include <cpufreq.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;
|
|
|
|
union {
|
|
struct {
|
|
int perf_bias:1;
|
|
};
|
|
int params;
|
|
} params;
|
|
int perf_bias = 0;
|
|
int ret = 0;
|
|
|
|
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) ||
|
|
cpufreq_cpu_exists(cpu))
|
|
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;
|
|
}
|