|
|
480824 |
diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
|
|
|
480824 |
index 1eb340c..b021955 100644
|
|
|
480824 |
--- a/src/cpu/cpu.cpp
|
|
|
480824 |
+++ b/src/cpu/cpu.cpp
|
|
|
480824 |
@@ -57,6 +57,7 @@ class perf_power_bundle: public perf_bundle
|
|
|
480824 |
|
|
|
480824 |
static class abstract_cpu * new_package(int package, int cpu, char * vendor, int family, int model)
|
|
|
480824 |
{
|
|
|
480824 |
+ uint64_t msr;
|
|
|
480824 |
class abstract_cpu *ret = NULL;
|
|
|
480824 |
class cpudevice *cpudev;
|
|
|
480824 |
char packagename[128];
|
|
|
480824 |
@@ -71,15 +72,19 @@ static class abstract_cpu * new_package(int package, int cpu, char * vendor, int
|
|
|
480824 |
case 0x25: /* Westmere */
|
|
|
480824 |
case 0x27: /* Medfield Atom*/
|
|
|
480824 |
case 0x2C: /* Westmere */
|
|
|
480824 |
- ret = new class nhm_package;
|
|
|
480824 |
+ if (read_msr(cpu, MSR_APERF, &msr) >= 0)
|
|
|
480824 |
+ ret = new class nhm_package;
|
|
|
480824 |
break;
|
|
|
480824 |
case 0x2A: /* SNB */
|
|
|
480824 |
case 0x2D: /* SNB Xeon */
|
|
|
480824 |
case 0x3A: /* IVB */
|
|
|
480824 |
case 0x3C:
|
|
|
480824 |
case 0x3D: /* IVB Xeon */
|
|
|
480824 |
- has_c2c7_res = 1;
|
|
|
480824 |
- ret = new class nhm_package;
|
|
|
480824 |
+ if (read_msr(cpu, MSR_PKG_C7_RESIDENCY, &msr) >= 0)
|
|
|
480824 |
+ {
|
|
|
480824 |
+ has_c2c7_res = 1;
|
|
|
480824 |
+ ret = new class nhm_package;
|
|
|
480824 |
+ }
|
|
|
480824 |
break;
|
|
|
480824 |
}
|
|
|
480824 |
}
|
|
|
480824 |
@@ -99,6 +104,7 @@ static class abstract_cpu * new_package(int package, int cpu, char * vendor, int
|
|
|
480824 |
|
|
|
480824 |
static class abstract_cpu * new_core(int core, int cpu, char * vendor, int family, int model)
|
|
|
480824 |
{
|
|
|
480824 |
+ uint64_t msr;
|
|
|
480824 |
class abstract_cpu *ret = NULL;
|
|
|
480824 |
|
|
|
480824 |
if (strcmp(vendor, "GenuineIntel") == 0) {
|
|
|
480824 |
@@ -116,7 +122,8 @@ static class abstract_cpu * new_core(int core, int cpu, char * vendor, int famil
|
|
|
480824 |
case 0x3A: /* IVB */
|
|
|
480824 |
case 0x3C:
|
|
|
480824 |
case 0x3D: /* IVB Xeon */
|
|
|
480824 |
- ret = new class nhm_core;
|
|
|
480824 |
+ if (read_msr(cpu, MSR_APERF, &msr) >= 0)
|
|
|
480824 |
+ ret = new class nhm_core;
|
|
|
480824 |
}
|
|
|
480824 |
}
|
|
|
480824 |
|
|
|
480824 |
@@ -142,6 +149,7 @@ static class abstract_cpu * new_i965_gpu(void)
|
|
|
480824 |
|
|
|
480824 |
static class abstract_cpu * new_cpu(int number, char * vendor, int family, int model)
|
|
|
480824 |
{
|
|
|
480824 |
+ uint64_t msr;
|
|
|
480824 |
class abstract_cpu * ret = NULL;
|
|
|
480824 |
|
|
|
480824 |
if (strcmp(vendor, "GenuineIntel") == 0) {
|
|
|
480824 |
@@ -159,7 +167,8 @@ static class abstract_cpu * new_cpu(int number, char * vendor, int family, int m
|
|
|
480824 |
case 0x3A: /* IVB */
|
|
|
480824 |
case 0x3C:
|
|
|
480824 |
case 0x3D: /* IVB Xeon */
|
|
|
480824 |
- ret = new class nhm_cpu;
|
|
|
480824 |
+ if (read_msr(number, MSR_APERF, &msr) >= 0)
|
|
|
480824 |
+ ret = new class nhm_cpu;
|
|
|
480824 |
}
|
|
|
480824 |
}
|
|
|
480824 |
|
|
|
480824 |
diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp
|
|
|
480824 |
index 2b78d31..8d5f51a 100644
|
|
|
480824 |
--- a/src/cpu/intel_cpus.cpp
|
|
|
480824 |
+++ b/src/cpu/intel_cpus.cpp
|
|
|
480824 |
@@ -49,30 +49,15 @@ static uint64_t get_msr(int cpu, uint64_t offset)
|
|
|
480824 |
{
|
|
|
480824 |
ssize_t retval;
|
|
|
480824 |
uint64_t msr;
|
|
|
480824 |
- int fd;
|
|
|
480824 |
- char msr_path[256];
|
|
|
480824 |
|
|
|
480824 |
- fd = sprintf(msr_path, "/dev/cpu/%d/msr", cpu);
|
|
|
480824 |
-
|
|
|
480824 |
- if (access(msr_path, R_OK) != 0){
|
|
|
480824 |
- fd = sprintf(msr_path, "/dev/msr%d", cpu);
|
|
|
480824 |
-
|
|
|
480824 |
- if (access(msr_path, R_OK) != 0){
|
|
|
480824 |
- fprintf(stderr, _("msr reg not found"));
|
|
|
480824 |
- exit(-2);
|
|
|
480824 |
- }
|
|
|
480824 |
- }
|
|
|
480824 |
-
|
|
|
480824 |
- fd = open(msr_path, O_RDONLY);
|
|
|
480824 |
-
|
|
|
480824 |
- retval = pread(fd, &msr, sizeof msr, offset);
|
|
|
480824 |
- if (retval != sizeof msr) {
|
|
|
480824 |
+ retval = read_msr(cpu, offset, &msr;;
|
|
|
480824 |
+ if (retval < 0) {
|
|
|
480824 |
reset_display();
|
|
|
480824 |
- fprintf(stderr, _("pread cpu%d 0x%llx : "), cpu, (unsigned long long)offset);
|
|
|
480824 |
+ fprintf(stderr, _("read_msr cpu%d 0x%llx : "), cpu, (unsigned long long)offset);
|
|
|
480824 |
fprintf(stderr, "%s\n", strerror(errno));
|
|
|
480824 |
exit(-2);
|
|
|
480824 |
}
|
|
|
480824 |
- close(fd);
|
|
|
480824 |
+
|
|
|
480824 |
return msr;
|
|
|
480824 |
}
|
|
|
480824 |
|
|
|
480824 |
diff --git a/src/lib.cpp b/src/lib.cpp
|
|
|
480824 |
index 723517a..6993088 100644
|
|
|
480824 |
--- a/src/lib.cpp
|
|
|
480824 |
+++ b/src/lib.cpp
|
|
|
480824 |
@@ -56,6 +56,7 @@ extern "C" {
|
|
|
480824 |
#include <limits>
|
|
|
480824 |
#include <math.h>
|
|
|
480824 |
#include <ncurses.h>
|
|
|
480824 |
+#include <fcntl.h>
|
|
|
480824 |
|
|
|
480824 |
static int kallsyms_read = 0;
|
|
|
480824 |
|
|
|
480824 |
@@ -450,3 +451,36 @@ int get_user_input(char *buf, unsigned sz)
|
|
|
480824 |
/* to distinguish between getnstr error and empty line */
|
|
|
480824 |
return ret || strlen(buf);
|
|
|
480824 |
}
|
|
|
480824 |
+
|
|
|
480824 |
+int read_msr(int cpu, uint64_t offset, uint64_t *value)
|
|
|
480824 |
+{
|
|
|
480824 |
+ ssize_t retval;
|
|
|
480824 |
+ uint64_t msr;
|
|
|
480824 |
+ int fd;
|
|
|
480824 |
+ char msr_path[256];
|
|
|
480824 |
+
|
|
|
480824 |
+ sprintf(msr_path, "/dev/cpu/%d/msr", cpu);
|
|
|
480824 |
+
|
|
|
480824 |
+ if (access(msr_path, R_OK) != 0){
|
|
|
480824 |
+ sprintf(msr_path, "/dev/msr%d", cpu);
|
|
|
480824 |
+
|
|
|
480824 |
+ if (access(msr_path, R_OK) != 0){
|
|
|
480824 |
+ fprintf(stderr,
|
|
|
480824 |
+ _("Model-specific registers (MSR)\
|
|
|
480824 |
+ not found (try enabling CONFIG_X86_MSR).\n"));
|
|
|
480824 |
+ return -1;
|
|
|
480824 |
+ }
|
|
|
480824 |
+ }
|
|
|
480824 |
+
|
|
|
480824 |
+ fd = open(msr_path, O_RDONLY);
|
|
|
480824 |
+ if (fd < 0)
|
|
|
480824 |
+ return -1;
|
|
|
480824 |
+ retval = pread(fd, &msr, sizeof msr, offset);
|
|
|
480824 |
+ close(fd);
|
|
|
480824 |
+ if (retval != sizeof msr) {
|
|
|
480824 |
+ return -1;
|
|
|
480824 |
+ }
|
|
|
480824 |
+ *value = msr;
|
|
|
480824 |
+
|
|
|
480824 |
+ return retval;
|
|
|
480824 |
+}
|
|
|
480824 |
diff --git a/src/lib.h b/src/lib.h
|
|
|
480824 |
index de2de5a..1c9ca42 100644
|
|
|
480824 |
--- a/src/lib.h
|
|
|
480824 |
+++ b/src/lib.h
|
|
|
480824 |
@@ -74,5 +74,6 @@ typedef void (*callback)(const char*);
|
|
|
480824 |
extern void process_directory(const char *d_name, callback fn);
|
|
|
480824 |
extern int utf_ok;
|
|
|
480824 |
extern int get_user_input(char *buf, unsigned sz);
|
|
|
480824 |
+extern int read_msr(int cpu, uint64_t offset, uint64_t *value);
|
|
|
480824 |
|
|
|
480824 |
#endif
|