Blame view
tools/power/cpupower/utils/cpupower-set.c
2.95 KB
7fe2f6399 cpupowerutils - c... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* * (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" |
7fe2f6399 cpupowerutils - c... |
19 |
static struct option set_opts[] = { |
a1ce5ba2b cpupowerutils: ut... |
20 21 22 |
{ .name = "perf-bias", .has_arg = optional_argument, .flag = NULL, .val = 'b'}, { .name = "sched-mc", .has_arg = optional_argument, .flag = NULL, .val = 'm'}, { .name = "sched-smt", .has_arg = optional_argument, .flag = NULL, .val = 's'}, |
7fe2f6399 cpupowerutils - c... |
23 24 25 26 27 28 29 |
{ }, }; static void print_wrong_arg_exit(void) { printf(_("invalid or unknown argument ")); |
7fe2f6399 cpupowerutils - c... |
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
exit(EXIT_FAILURE); } int cmd_set(int argc, char **argv) { extern char *optarg; extern int optind, opterr, optopt; unsigned int cpu; union { struct { int sched_mc:1; int sched_smt:1; int perf_bias:1; }; int params; |
7fe2f6399 cpupowerutils - c... |
46 47 48 49 50 |
} params; int sched_mc = 0, sched_smt = 0, perf_bias = 0; int ret = 0; setlocale(LC_ALL, ""); |
a1ce5ba2b cpupowerutils: ut... |
51 |
textdomain(PACKAGE); |
7fe2f6399 cpupowerutils - c... |
52 53 54 |
params.params = 0; /* parameter parsing */ |
498ca793d cpupower: use man... |
55 |
while ((ret = getopt_long(argc, argv, "m:s:b:", |
a1ce5ba2b cpupowerutils: ut... |
56 |
set_opts, NULL)) != -1) { |
7fe2f6399 cpupowerutils - c... |
57 |
switch (ret) { |
7fe2f6399 cpupowerutils - c... |
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
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] "), 15); print_wrong_arg_exit(); } params.perf_bias = 1; break; case 'm': if (params.sched_mc) print_wrong_arg_exit(); sched_mc = atoi(optarg); if (sched_mc < 0 || sched_mc > 2) { printf(_("--sched-mc param out " "of range [0-%d] "), 2); print_wrong_arg_exit(); } params.sched_mc = 1; break; case 's': if (params.sched_smt) print_wrong_arg_exit(); sched_smt = atoi(optarg); if (sched_smt < 0 || sched_smt > 2) { printf(_("--sched-smt param out " "of range [0-%d] "), 2); print_wrong_arg_exit(); } params.sched_smt = 1; break; default: print_wrong_arg_exit(); } }; |
498ca793d cpupower: use man... |
98 99 |
if (!params.params) print_wrong_arg_exit(); |
7fe2f6399 cpupowerutils - c... |
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
if (params.sched_mc) { ret = sysfs_set_sched("mc", sched_mc); if (ret) fprintf(stderr, _("Error setting sched-mc %s "), (ret == -ENODEV) ? "not supported" : ""); } if (params.sched_smt) { ret = sysfs_set_sched("smt", sched_smt); if (ret) fprintf(stderr, _("Error setting sched-smt %s "), (ret == -ENODEV) ? "not supported" : ""); } /* 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++) { |
a1ce5ba2b cpupowerutils: ut... |
123 |
|
7fe2f6399 cpupowerutils - c... |
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
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 "), cpu); break; } } } return ret; } |