irqchip: Fix dependencies for archs w/o HAS_IOMEM
[linux/fpc-iii.git] / tools / power / cpupower / utils / cpupower-info.c
blob10299f2e9d2a6917f0601dd07eedb0ff03c6bc92
1 /*
2 * (C) 2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
4 * Licensed under the terms of the GNU GPL License version 2.
5 */
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <errno.h>
12 #include <string.h>
13 #include <getopt.h>
15 #include <cpufreq.h>
16 #include "helpers/helpers.h"
17 #include "helpers/sysfs.h"
19 static struct option set_opts[] = {
20 {"perf-bias", optional_argument, NULL, 'b'},
21 { },
24 static void print_wrong_arg_exit(void)
26 printf(_("invalid or unknown argument\n"));
27 exit(EXIT_FAILURE);
30 int cmd_info(int argc, char **argv)
32 extern char *optarg;
33 extern int optind, opterr, optopt;
34 unsigned int cpu;
36 union {
37 struct {
38 int perf_bias:1;
40 int params;
41 } params = {};
42 int ret = 0;
44 setlocale(LC_ALL, "");
45 textdomain(PACKAGE);
47 /* parameter parsing */
48 while ((ret = getopt_long(argc, argv, "b", set_opts, NULL)) != -1) {
49 switch (ret) {
50 case 'b':
51 if (params.perf_bias)
52 print_wrong_arg_exit();
53 params.perf_bias = 1;
54 break;
55 default:
56 print_wrong_arg_exit();
60 if (!params.params)
61 params.params = 0x7;
63 /* Default is: show output of CPU 0 only */
64 if (bitmask_isallclear(cpus_chosen))
65 bitmask_setbit(cpus_chosen, 0);
67 /* Add more per cpu options here */
68 if (!params.perf_bias)
69 return ret;
71 if (params.perf_bias) {
72 if (!run_as_root) {
73 params.perf_bias = 0;
74 printf(_("Intel's performance bias setting needs root privileges\n"));
75 } else if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS)) {
76 printf(_("System does not support Intel's performance"
77 " bias setting\n"));
78 params.perf_bias = 0;
82 /* loop over CPUs */
83 for (cpu = bitmask_first(cpus_chosen);
84 cpu <= bitmask_last(cpus_chosen); cpu++) {
86 if (!bitmask_isbitset(cpus_chosen, cpu) ||
87 cpufreq_cpu_exists(cpu))
88 continue;
90 printf(_("analyzing CPU %d:\n"), cpu);
92 if (params.perf_bias) {
93 ret = msr_intel_get_perf_bias(cpu);
94 if (ret < 0) {
95 fprintf(stderr,
96 _("Could not read perf-bias value[%d]\n"), ret);
97 exit(EXIT_FAILURE);
98 } else
99 printf(_("perf-bias: %d\n"), ret);
102 return 0;