diff options
author | Thomas Renninger <trenn@suse.de> | 2014-05-13 06:41:43 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-05-16 18:36:36 -0400 |
commit | 8a19cb586708361058e089b7c23b6f3eb33af6c6 (patch) | |
tree | a59cffe15d0efb00a4b1ce7fe73dfcc9fb1f3a79 /tools/power | |
parent | 84baab91772b5aeec9040cb33de6a46738b1aba8 (diff) |
cpupower: If root, try to load msr driver on x86 if /dev/cpu/0/msr is not available
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r-- | tools/power/cpupower/utils/cpupower.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c index 7efc570ffbaa..7cdcf88659c7 100644 --- a/tools/power/cpupower/utils/cpupower.c +++ b/tools/power/cpupower/utils/cpupower.c | |||
@@ -12,6 +12,9 @@ | |||
12 | #include <string.h> | 12 | #include <string.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | #include <sys/types.h> | ||
16 | #include <sys/stat.h> | ||
17 | #include <sys/utsname.h> | ||
15 | 18 | ||
16 | #include "builtin.h" | 19 | #include "builtin.h" |
17 | #include "helpers/helpers.h" | 20 | #include "helpers/helpers.h" |
@@ -169,6 +172,8 @@ int main(int argc, const char *argv[]) | |||
169 | { | 172 | { |
170 | const char *cmd; | 173 | const char *cmd; |
171 | unsigned int i, ret; | 174 | unsigned int i, ret; |
175 | struct stat statbuf; | ||
176 | struct utsname uts; | ||
172 | 177 | ||
173 | cpus_chosen = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF)); | 178 | cpus_chosen = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF)); |
174 | 179 | ||
@@ -195,6 +200,15 @@ int main(int argc, const char *argv[]) | |||
195 | 200 | ||
196 | get_cpu_info(0, &cpupower_cpu_info); | 201 | get_cpu_info(0, &cpupower_cpu_info); |
197 | run_as_root = !getuid(); | 202 | run_as_root = !getuid(); |
203 | if (run_as_root) { | ||
204 | ret = uname(&uts); | ||
205 | if (!ret && !strcmp(uts.machine, "x86_64") && | ||
206 | stat("/dev/cpu/0/msr", &statbuf) != 0) { | ||
207 | if (system("modprobe msr") == -1) | ||
208 | fprintf(stderr, _("MSR access not available.\n")); | ||
209 | } | ||
210 | } | ||
211 | |||
198 | 212 | ||
199 | for (i = 0; i < ARRAY_SIZE(commands); i++) { | 213 | for (i = 0; i < ARRAY_SIZE(commands); i++) { |
200 | struct cmd_struct *p = commands + i; | 214 | struct cmd_struct *p = commands + i; |