2 * (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
4 * Licensed under the terms of the GNU GPL License version 2.
16 #include "helpers/helpers.h"
17 #include "helpers/sysfs.h"
18 #include "helpers/bitmask.h"
22 printf(_("Usage: cpupower set [ -b val ] [ -m val ] [ -s val ]\n"));
23 printf(_("Options:\n"));
24 printf(_(" -b, --perf-bias [VAL] Sets CPU's power vs performance policy on some\n"
25 " Intel models [0-15], see manpage for details\n"));
26 printf(_(" -m, --sched-mc [VAL] Sets the kernel's multi core scheduler policy.\n"));
27 printf(_(" -s, --sched-smt [VAL] Sets the kernel's thread sibling scheduler policy.\n"));
28 printf(_(" -h, --help Prints out this screen\n"));
32 static struct option set_opts[] = {
33 { .name="perf-bias", .has_arg=optional_argument, .flag=NULL, .val='b'},
34 { .name="sched-mc", .has_arg=optional_argument, .flag=NULL, .val='m'},
35 { .name="sched-smt", .has_arg=optional_argument, .flag=NULL, .val='s'},
36 { .name="help", .has_arg=no_argument, .flag=NULL, .val='h'},
40 static void print_wrong_arg_exit(void)
42 printf(_("invalid or unknown argument\n"));
47 int cmd_set(int argc, char **argv)
50 extern int optind, opterr, optopt;
62 int sched_mc = 0, sched_smt = 0, perf_bias = 0;
65 setlocale(LC_ALL, "");
69 /* parameter parsing */
70 while ((ret = getopt_long(argc, argv, "m:s:b:h", set_opts, NULL)) != -1) {
77 print_wrong_arg_exit();
78 perf_bias = atoi(optarg);
79 if (perf_bias < 0 || perf_bias > 15) {
80 printf(_("--perf-bias param out "
81 "of range [0-%d]\n"), 15);
82 print_wrong_arg_exit();
88 print_wrong_arg_exit();
89 sched_mc = atoi(optarg);
90 if (sched_mc < 0 || sched_mc > 2) {
91 printf(_("--sched-mc param out "
92 "of range [0-%d]\n"), 2);
93 print_wrong_arg_exit();
99 print_wrong_arg_exit();
100 sched_smt = atoi(optarg);
101 if (sched_smt < 0 || sched_smt > 2) {
102 printf(_("--sched-smt param out "
103 "of range [0-%d]\n"), 2);
104 print_wrong_arg_exit();
106 params.sched_smt = 1;
109 print_wrong_arg_exit();
113 if (!params.params) {
118 if (params.sched_mc) {
119 ret = sysfs_set_sched("mc", sched_mc);
121 fprintf(stderr, _("Error setting sched-mc %s\n"),
122 (ret == -ENODEV) ? "not supported" : "");
124 if (params.sched_smt) {
125 ret = sysfs_set_sched("smt", sched_smt);
127 fprintf(stderr, _("Error setting sched-smt %s\n"),
128 (ret == -ENODEV) ? "not supported" : "");
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) ||
140 cpufreq_cpu_exists(cpu))
143 if (params.perf_bias) {
144 ret = msr_intel_set_perf_bias(cpu, perf_bias);
146 fprintf(stderr, _("Error setting perf-bias "
147 "value on CPU %d\n"), cpu);