diff options
author | Thomas Renninger <trenn@suse.de> | 2013-06-28 09:34:31 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-07-04 19:52:19 -0400 |
commit | c4f3610eba69321b9cf35779cd67e68b5138cc16 (patch) | |
tree | 1e290acedef8572a22812c98709cf0754f5d36a9 /tools | |
parent | 0924c369bc5492cf181a066fc2d459aa18ffa5ac (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')
-rw-r--r-- | tools/power/cpupower/Makefile | 3 | ||||
-rw-r--r-- | tools/power/cpupower/man/cpupower-monitor.1 | 10 | ||||
-rw-r--r-- | tools/power/cpupower/utils/builtin.h | 1 | ||||
-rw-r--r-- | tools/power/cpupower/utils/cpuidle-info.c | 6 | ||||
-rw-r--r-- | tools/power/cpupower/utils/cpuidle-set.c | 118 | ||||
-rw-r--r-- | tools/power/cpupower/utils/cpupower.c | 13 |
6 files changed, 142 insertions, 9 deletions
diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile index d875a74a3bdf..ce17f30f04ba 100644 --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile | |||
@@ -131,7 +131,8 @@ UTIL_OBJS = utils/helpers/amd.o utils/helpers/topology.o utils/helpers/msr.o \ | |||
131 | utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ | 131 | utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ |
132 | utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ | 132 | utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ |
133 | utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ | 133 | utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ |
134 | utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o | 134 | utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \ |
135 | utils/cpuidle-set.o | ||
135 | 136 | ||
136 | UTIL_SRC := $(UTIL_OBJS:.o=.c) | 137 | UTIL_SRC := $(UTIL_OBJS:.o=.c) |
137 | 138 | ||
diff --git a/tools/power/cpupower/man/cpupower-monitor.1 b/tools/power/cpupower/man/cpupower-monitor.1 index e01c35d13b6e..914cbb9d9cd0 100644 --- a/tools/power/cpupower/man/cpupower-monitor.1 +++ b/tools/power/cpupower/man/cpupower-monitor.1 | |||
@@ -110,13 +110,21 @@ May work poorly on Linux-2.6.20 through 2.6.29, as the \fBacpi-cpufreq \fP | |||
110 | kernel frequency driver periodically cleared aperf/mperf registers in those | 110 | kernel frequency driver periodically cleared aperf/mperf registers in those |
111 | kernels. | 111 | kernels. |
112 | 112 | ||
113 | .SS "Nehalem" "SandyBridge" | 113 | .SS "Nehalem" "SandyBridge" "HaswellExtended" |
114 | Intel Core and Package sleep state counters. | 114 | Intel Core and Package sleep state counters. |
115 | Threads (hyperthreaded cores) may not be able to enter deeper core states if | 115 | Threads (hyperthreaded cores) may not be able to enter deeper core states if |
116 | its sibling is utilized. | 116 | its sibling is utilized. |
117 | Deepest package sleep states may in reality show up as machine/platform wide | 117 | Deepest package sleep states may in reality show up as machine/platform wide |
118 | sleep states and can only be entered if all cores are idle. Look up Intel | 118 | sleep states and can only be entered if all cores are idle. Look up Intel |
119 | manuals (some are provided in the References section) for further details. | 119 | manuals (some are provided in the References section) for further details. |
120 | The monitors are named after the CPU family where the sleep state capabilities | ||
121 | got introduced and may not match exactly the CPU name of the platform. | ||
122 | For example an IvyBridge processor has sleep state capabilities which got | ||
123 | introduced in Nehalem and SandyBridge processor families. | ||
124 | Thus on an IvyBridge processor one will get Nehalem and SandyBridge sleep | ||
125 | state monitors. | ||
126 | HaswellExtended extra package sleep state capabilities are available only in a | ||
127 | specific Haswell (family 0x45) and probably also other future processors. | ||
120 | 128 | ||
121 | .SS "Fam_12h" "Fam_14h" | 129 | .SS "Fam_12h" "Fam_14h" |
122 | AMD laptop and desktop processor (family 12h and 14h) sleep state counters. | 130 | AMD laptop and desktop processor (family 12h and 14h) sleep state counters. |
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); | |||
5 | extern int cmd_info(int argc, const char **argv); | 5 | extern int cmd_info(int argc, const char **argv); |
6 | extern int cmd_freq_set(int argc, const char **argv); | 6 | extern int cmd_freq_set(int argc, const char **argv); |
7 | extern int cmd_freq_info(int argc, const char **argv); | 7 | extern int cmd_freq_info(int argc, const char **argv); |
8 | extern int cmd_idle_set(int argc, const char **argv); | ||
8 | extern int cmd_idle_info(int argc, const char **argv); | 9 | extern int cmd_idle_info(int argc, const char **argv); |
9 | extern int cmd_monitor(int argc, const char **argv); | 10 | extern 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 | |||
15 | static 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 | |||
22 | int 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 | ||
20 | struct 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 | ||
28 | static int cmd_help(int argc, const char **argv); | 22 | static int cmd_help(int argc, const char **argv); |
@@ -43,10 +37,17 @@ int be_verbose; | |||
43 | 37 | ||
44 | static void print_help(void); | 38 | static void print_help(void); |
45 | 39 | ||
40 | struct cmd_struct { | ||
41 | const char *cmd; | ||
42 | int (*main)(int, const char **); | ||
43 | int needs_root; | ||
44 | }; | ||
45 | |||
46 | static struct cmd_struct commands[] = { | 46 | static 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 }, |