spi-topcliff-pch: Fix issue for transmitting over 4KByte
[zen-stable.git] / tools / power / cpupower / utils / cpupower-info.c
blob3f68632c28c7bccc02f2d0a3266288e4a7bfd74a
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 { .name = "perf-bias", .has_arg = optional_argument, .flag = NULL, .val = 'b'},
21 { .name = "sched-mc", .has_arg = optional_argument, .flag = NULL, .val = 'm'},
22 { .name = "sched-smt", .has_arg = optional_argument, .flag = NULL, .val = 's'},
23 { },
26 static void print_wrong_arg_exit(void)
28 printf(_("invalid or unknown argument\n"));
29 exit(EXIT_FAILURE);
32 int cmd_info(int argc, char **argv)
34 extern char *optarg;
35 extern int optind, opterr, optopt;
36 unsigned int cpu;
38 union {
39 struct {
40 int sched_mc:1;
41 int sched_smt:1;
42 int perf_bias:1;
44 int params;
45 } params = {};
46 int ret = 0;
48 setlocale(LC_ALL, "");
49 textdomain(PACKAGE);
51 /* parameter parsing */
52 while ((ret = getopt_long(argc, argv, "msb", set_opts, NULL)) != -1) {
53 switch (ret) {
54 case 'b':
55 if (params.perf_bias)
56 print_wrong_arg_exit();
57 params.perf_bias = 1;
58 break;
59 case 'm':
60 if (params.sched_mc)
61 print_wrong_arg_exit();
62 params.sched_mc = 1;
63 break;
64 case 's':
65 if (params.sched_smt)
66 print_wrong_arg_exit();
67 params.sched_smt = 1;
68 break;
69 default:
70 print_wrong_arg_exit();
74 if (!params.params)
75 params.params = 0x7;
77 /* Default is: show output of CPU 0 only */
78 if (bitmask_isallclear(cpus_chosen))
79 bitmask_setbit(cpus_chosen, 0);
81 if (params.sched_mc) {
82 ret = sysfs_get_sched("mc");
83 printf(_("System's multi core scheduler setting: "));
84 if (ret < 0)
85 /* if sysfs file is missing it's: errno == ENOENT */
86 printf(_("not supported\n"));
87 else
88 printf("%d\n", ret);
90 if (params.sched_smt) {
91 ret = sysfs_get_sched("smt");
92 printf(_("System's thread sibling scheduler setting: "));
93 if (ret < 0)
94 /* if sysfs file is missing it's: errno == ENOENT */
95 printf(_("not supported\n"));
96 else
97 printf("%d\n", ret);
100 /* Add more per cpu options here */
101 if (!params.perf_bias)
102 return ret;
104 if (params.perf_bias) {
105 if (!run_as_root) {
106 params.perf_bias = 0;
107 printf(_("Intel's performance bias setting needs root privileges\n"));
108 } else if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS)) {
109 printf(_("System does not support Intel's performance"
110 " bias setting\n"));
111 params.perf_bias = 0;
115 /* loop over CPUs */
116 for (cpu = bitmask_first(cpus_chosen);
117 cpu <= bitmask_last(cpus_chosen); cpu++) {
119 if (!bitmask_isbitset(cpus_chosen, cpu) ||
120 cpufreq_cpu_exists(cpu))
121 continue;
123 printf(_("analyzing CPU %d:\n"), cpu);
125 if (params.perf_bias) {
126 ret = msr_intel_get_perf_bias(cpu);
127 if (ret < 0) {
128 printf(_("Could not read perf-bias value\n"));
129 break;
130 } else
131 printf(_("perf-bias: %d\n"), ret);
134 return ret;