aboutsummaryrefslogtreecommitdiffstats
path: root/tools/power/cpupower/utils
diff options
context:
space:
mode:
authorThomas Renninger <trenn@suse.de>2013-06-28 09:34:31 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-07-04 19:52:19 -0400
commitc4f3610eba69321b9cf35779cd67e68b5138cc16 (patch)
tree1e290acedef8572a22812c98709cf0754f5d36a9 /tools/power/cpupower/utils
parent0924c369bc5492cf181a066fc2d459aa18ffa5ac (diff)
cpupower: Introduce idle-set subcommand and C-state enabling/disabling
Example: cpupower idle-set -d 3 will disable C-state 3 on all processors (set commands are active on all CPUs by default), same as: cpupower -c all idle-set -d 3 Signed-off-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools/power/cpupower/utils')
-rw-r--r--tools/power/cpupower/utils/builtin.h1
-rw-r--r--tools/power/cpupower/utils/cpuidle-info.c6
-rw-r--r--tools/power/cpupower/utils/cpuidle-set.c118
-rw-r--r--tools/power/cpupower/utils/cpupower.c13
4 files changed, 131 insertions, 7 deletions
diff --git a/tools/power/cpupower/utils/builtin.h b/tools/power/cpupower/utils/builtin.h
index c10496fbe3c6..2284c8ea4e2a 100644
--- a/tools/power/cpupower/utils/builtin.h
+++ b/tools/power/cpupower/utils/builtin.h
@@ -5,6 +5,7 @@ extern int cmd_set(int argc, const char **argv);
5extern int cmd_info(int argc, const char **argv); 5extern int cmd_info(int argc, const char **argv);
6extern int cmd_freq_set(int argc, const char **argv); 6extern int cmd_freq_set(int argc, const char **argv);
7extern int cmd_freq_info(int argc, const char **argv); 7extern int cmd_freq_info(int argc, const char **argv);
8extern int cmd_idle_set(int argc, const char **argv);
8extern int cmd_idle_info(int argc, const char **argv); 9extern int cmd_idle_info(int argc, const char **argv);
9extern int cmd_monitor(int argc, const char **argv); 10extern int cmd_monitor(int argc, const char **argv);
10 11
diff --git a/tools/power/cpupower/utils/cpuidle-info.c b/tools/power/cpupower/utils/cpuidle-info.c
index edd5dba3e249..75e66de7e7a7 100644
--- a/tools/power/cpupower/utils/cpuidle-info.c
+++ b/tools/power/cpupower/utils/cpuidle-info.c
@@ -48,10 +48,14 @@ static void cpuidle_cpu_output(unsigned int cpu, int verbose)
48 return; 48 return;
49 49
50 for (idlestate = 0; idlestate < idlestates; idlestate++) { 50 for (idlestate = 0; idlestate < idlestates; idlestate++) {
51 int disabled = sysfs_is_idlestate_disabled(cpu, idlestate);
52 /* Disabled interface not supported on older kernels */
53 if (disabled < 0)
54 disabled = 0;
51 tmp = sysfs_get_idlestate_name(cpu, idlestate); 55 tmp = sysfs_get_idlestate_name(cpu, idlestate);
52 if (!tmp) 56 if (!tmp)
53 continue; 57 continue;
54 printf("%s:\n", tmp); 58 printf("%s%s:\n", tmp, (disabled) ? " (DISABLED) " : "");
55 free(tmp); 59 free(tmp);
56 60
57 tmp = sysfs_get_idlestate_desc(cpu, idlestate); 61 tmp = sysfs_get_idlestate_desc(cpu, idlestate);
diff --git a/tools/power/cpupower/utils/cpuidle-set.c b/tools/power/cpupower/utils/cpuidle-set.c
new file mode 100644
index 000000000000..c78141c5dfac
--- /dev/null
+++ b/tools/power/cpupower/utils/cpuidle-set.c
@@ -0,0 +1,118 @@
1#include <unistd.h>
2#include <stdio.h>
3#include <errno.h>
4#include <stdlib.h>
5#include <limits.h>
6#include <string.h>
7#include <ctype.h>
8
9#include <getopt.h>
10
11#include "cpufreq.h"
12#include "helpers/helpers.h"
13#include "helpers/sysfs.h"
14
15static struct option info_opts[] = {
16 { .name = "disable", .has_arg = required_argument, .flag = NULL, .val = 'd'},
17 { .name = "enable", .has_arg = required_argument, .flag = NULL, .val = 'e'},
18 { },
19};
20
21
22int cmd_idle_set(int argc, char **argv)
23{
24 extern char *optarg;
25 extern int optind, opterr, optopt;
26 int ret = 0, cont = 1, param = 0, idlestate = 0;
27 unsigned int cpu = 0;
28
29 do {
30 ret = getopt_long(argc, argv, "d:e:", info_opts, NULL);
31 if (ret == -1)
32 break;
33 switch (ret) {
34 case '?':
35 param = '?';
36 cont = 0;
37 break;
38 case 'd':
39 if (param) {
40 param = -1;
41 cont = 0;
42 break;
43 }
44 param = ret;
45 idlestate = atoi(optarg);
46 break;
47 case 'e':
48 if (param) {
49 param = -1;
50 cont = 0;
51 break;
52 }
53 param = ret;
54 idlestate = atoi(optarg);
55 break;
56 case -1:
57 cont = 0;
58 break;
59 }
60 } while (cont);
61
62 switch (param) {
63 case -1:
64 printf(_("You can't specify more than one "
65 "output-specific argument\n"));
66 exit(EXIT_FAILURE);
67 case '?':
68 printf(_("invalid or unknown argument\n"));
69 exit(EXIT_FAILURE);
70 }
71
72 /* Default is: set all CPUs */
73 if (bitmask_isallclear(cpus_chosen))
74 bitmask_setall(cpus_chosen);
75
76 for (cpu = bitmask_first(cpus_chosen);
77 cpu <= bitmask_last(cpus_chosen); cpu++) {
78
79 if (!bitmask_isbitset(cpus_chosen, cpu))
80 continue;
81
82 switch (param) {
83
84 case 'd':
85 ret = sysfs_idlestate_disable(cpu, idlestate, 1);
86 if (ret == 0)
87 printf(_("Idlestate %u disabled on CPU %u\n"), idlestate, cpu);
88 else if (ret == -1)
89 printf(_("Idlestate %u not available on CPU %u\n"),
90 idlestate, cpu);
91 else if (ret == -2)
92 printf(_("Idlestate disabling not supported by kernel\n"));
93 else
94 printf(_("Idlestate %u not disabled on CPU %u\n"),
95 idlestate, cpu);
96 break;
97 case 'e':
98 ret = sysfs_idlestate_disable(cpu, idlestate, 0);
99 if (ret == 0)
100 printf(_("Idlestate %u enabled on CPU %u\n"), idlestate, cpu);
101 else if (ret == -1)
102 printf(_("Idlestate %u not available on CPU %u\n"),
103 idlestate, cpu);
104 else if (ret == -2)
105 printf(_("Idlestate enabling not supported by kernel\n"));
106 else
107 printf(_("Idlestate %u not enabled on CPU %u\n"),
108 idlestate, cpu);
109 break;
110 default:
111 /* Not reachable with proper args checking */
112 printf(_("Invalid or unknown argument\n"));
113 exit(EXIT_FAILURE);
114 break;
115 }
116 }
117 return EXIT_SUCCESS;
118}
diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
index 52bee591c1c5..7efc570ffbaa 100644
--- a/tools/power/cpupower/utils/cpupower.c
+++ b/tools/power/cpupower/utils/cpupower.c
@@ -17,12 +17,6 @@
17#include "helpers/helpers.h" 17#include "helpers/helpers.h"
18#include "helpers/bitmask.h" 18#include "helpers/bitmask.h"
19 19
20struct cmd_struct {
21 const char *cmd;
22 int (*main)(int, const char **);
23 int needs_root;
24};
25
26#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 20#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
27 21
28static int cmd_help(int argc, const char **argv); 22static int cmd_help(int argc, const char **argv);
@@ -43,10 +37,17 @@ int be_verbose;
43 37
44static void print_help(void); 38static void print_help(void);
45 39
40struct cmd_struct {
41 const char *cmd;
42 int (*main)(int, const char **);
43 int needs_root;
44};
45
46static struct cmd_struct commands[] = { 46static struct cmd_struct commands[] = {
47 { "frequency-info", cmd_freq_info, 0 }, 47 { "frequency-info", cmd_freq_info, 0 },
48 { "frequency-set", cmd_freq_set, 1 }, 48 { "frequency-set", cmd_freq_set, 1 },
49 { "idle-info", cmd_idle_info, 0 }, 49 { "idle-info", cmd_idle_info, 0 },
50 { "idle-set", cmd_idle_set, 1 },
50 { "set", cmd_set, 1 }, 51 { "set", cmd_set, 1 },
51 { "info", cmd_info, 0 }, 52 { "info", cmd_info, 0 },
52 { "monitor", cmd_monitor, 0 }, 53 { "monitor", cmd_monitor, 0 },