Skip to contentSkip to conversation

Don't use intel_cpus if APERF MSR isn't supported

PATCH New Jaroslav Škarvada <jskarvad at redhat.com> 1 participant 1 message May 15, 2018

lore
Share & tools
lore

Jaroslav Škarvada <jskarvad at redhat.com>

#0 lore raw

PATCH 1/1 Don't use intel_cpus if APERF MSR isn't supported

The intel_cpus (class nhm_package) needs APERF MSR. This maybe problem on some virtual machines (e.g. KVM) where the APERF MSR is not implemented. On such VMs powertop exits with MSR read error and doesn't work. Previously, powertop worked in such cases (e.g. powertop-2.3). This patch adds check whether APERF MSR is supported, if not, intel_cpus is not used.

Signed-off-by Jaroslav Škarvada <jskarvad(a)redhat.com>
---
 src/cpu/cpu.cpp        | 6 +++---
 src/cpu/intel_cpus.cpp | 6 ++++--
 src/cpu/intel_cpus.h   | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)
src/cpu/cpu.cpp +3 -3
index f6bae03..28afc4f 100644
@@ -68,7 +68,7 @@ static class abstract_cpu * new_package(int package, int cpu, char * vendor, int
 	char packagename[128];
 	if (strcmp(vendor, "GenuineIntel") == 0)
 		if (family == 6)
-			if (is_supported_intel_cpu(model)) {
+			if (is_supported_intel_cpu(model, cpu)) {
 				ret = new class nhm_package(model);
 				ret->set_intel_MSR(true);
 			}
@@ -109,7 +109,7 @@ static class abstract_cpu * new_core(int core, int cpu, char * vendor, int famil
 
 	if (strcmp(vendor, "GenuineIntel") == 0)
 		if (family == 6)
-			if (is_supported_intel_cpu(model)) {
+			if (is_supported_intel_cpu(model, cpu)) {
 				ret = new class nhm_core(model);
 				ret->set_intel_MSR(true);
 			}
@@ -143,7 +143,7 @@ static class abstract_cpu * new_cpu(int number, char * vendor, int family, int m
 
 	if (strcmp(vendor, "GenuineIntel") == 0)
 		if (family == 6)
-			if (is_supported_intel_cpu(model)) {
+			if (is_supported_intel_cpu(model, number)) {
 				ret = new class nhm_cpu;
 				ret->set_intel_MSR(true);
 			}
src/cpu/intel_cpus.cpp +4 -2
index 4c7b315..0030dba 100644
@@ -77,13 +77,15 @@ static int intel_cpu_models[] = {
 
 static int intel_pstate_driver_loaded = -1;
 
-int is_supported_intel_cpu(int model)
+int is_supported_intel_cpu(int model, int cpu)
 {
 	int i;
+	uint64_t msr;
 
 	for (i = 0; intel_cpu_models[i] != 0; i++)
 		if (model == intel_cpu_models[i])
-			return 1;
+			if (cpu < 0 || read_msr(cpu, MSR_APERF, &msr) >= 0)
+				return 1;
 
 	return 0;
 }
src/cpu/intel_cpus.h +1 -1
index d20db9a..79afb98 100644
@@ -172,7 +172,7 @@ public:
 
 };
 
-int is_supported_intel_cpu(int model);
+int is_supported_intel_cpu(int model, int cpu);
 int byt_has_ahci();
 
 int is_intel_pstate_driver_loaded();
Signature · 1 line
2.14.3