~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/power/cpupower/utils/cpupower-set.c

Version: ~ [ linux-5.11-rc3 ] ~ [ linux-5.10.7 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.89 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.167 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.215 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.251 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.251 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
  3  *
  4  *  Licensed under the terms of the GNU GPL License version 2.
  5  */
  6 
  7 
  8 #include <unistd.h>
  9 #include <stdio.h>
 10 #include <stdlib.h>
 11 #include <errno.h>
 12 #include <string.h>
 13 #include <getopt.h>
 14 
 15 #include "helpers/helpers.h"
 16 #include "helpers/sysfs.h"
 17 #include "helpers/bitmask.h"
 18 
 19 static struct option set_opts[] = {
 20         {"perf-bias", required_argument, NULL, 'b'},
 21         { },
 22 };
 23 
 24 static void print_wrong_arg_exit(void)
 25 {
 26         printf(_("invalid or unknown argument\n"));
 27         exit(EXIT_FAILURE);
 28 }
 29 
 30 int cmd_set(int argc, char **argv)
 31 {
 32         extern char *optarg;
 33         extern int optind, opterr, optopt;
 34         unsigned int cpu;
 35 
 36         union {
 37                 struct {
 38                         int perf_bias:1;
 39                 };
 40                 int params;
 41         } params;
 42         int perf_bias = 0;
 43         int ret = 0;
 44 
 45         setlocale(LC_ALL, "");
 46         textdomain(PACKAGE);
 47 
 48         params.params = 0;
 49         /* parameter parsing */
 50         while ((ret = getopt_long(argc, argv, "b:",
 51                                                 set_opts, NULL)) != -1) {
 52                 switch (ret) {
 53                 case 'b':
 54                         if (params.perf_bias)
 55                                 print_wrong_arg_exit();
 56                         perf_bias = atoi(optarg);
 57                         if (perf_bias < 0 || perf_bias > 15) {
 58                                 printf(_("--perf-bias param out "
 59                                          "of range [0-%d]\n"), 15);
 60                                 print_wrong_arg_exit();
 61                         }
 62                         params.perf_bias = 1;
 63                         break;
 64                 default:
 65                         print_wrong_arg_exit();
 66                 }
 67         };
 68 
 69         if (!params.params)
 70                 print_wrong_arg_exit();
 71 
 72         /* Default is: set all CPUs */
 73         if (bitmask_isallclear(cpus_chosen))
 74                 bitmask_setall(cpus_chosen);
 75 
 76         /* loop over CPUs */
 77         for (cpu = bitmask_first(cpus_chosen);
 78              cpu <= bitmask_last(cpus_chosen); cpu++) {
 79 
 80                 if (!bitmask_isbitset(cpus_chosen, cpu))
 81                         continue;
 82 
 83                 if (sysfs_is_cpu_online(cpu) != 1){
 84                         fprintf(stderr, _("Cannot set values on CPU %d:"), cpu);
 85                         fprintf(stderr, _(" *is offline\n"));
 86                         continue;
 87                 }
 88 
 89                 if (params.perf_bias) {
 90                         ret = msr_intel_set_perf_bias(cpu, perf_bias);
 91                         if (ret) {
 92                                 fprintf(stderr, _("Error setting perf-bias "
 93                                                   "value on CPU %d\n"), cpu);
 94                                 break;
 95                         }
 96                 }
 97         }
 98         return ret;
 99 }
100 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp