powertop.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [Powertop] [PATCH] Don't use intel_cpus if APERF MSR isn't supported
@ 2018-05-04 21:55 
  0 siblings, 0 replies; 2+ messages in thread
From:  @ 2018-05-04 21:55 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2593 bytes --]

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(-)

diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index f3711f5..019d922 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -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);
 
 	if (!ret)
@@ -105,7 +105,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);
 
 	if (!ret)
@@ -134,7 +134,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;
 
 	if (!ret)
diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp
index 4c7b315..0030dba 100644
--- a/src/cpu/intel_cpus.cpp
+++ b/src/cpu/intel_cpus.cpp
@@ -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;
 }
diff --git a/src/cpu/intel_cpus.h b/src/cpu/intel_cpus.h
index d20db9a..79afb98 100644
--- a/src/cpu/intel_cpus.h
+++ b/src/cpu/intel_cpus.h
@@ -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();
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Powertop] [PATCH] Don't use intel_cpus if APERF MSR isn't supported
@ 2018-05-15 16:20 
  0 siblings, 0 replies; 2+ messages in thread
From:  @ 2018-05-15 16:20 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2674 bytes --]

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(-)

diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index f6bae03..28afc4f 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -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);
 			}
diff --git a/src/cpu/intel_cpus.cpp b/src/cpu/intel_cpus.cpp
index 4c7b315..0030dba 100644
--- a/src/cpu/intel_cpus.cpp
+++ b/src/cpu/intel_cpus.cpp
@@ -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;
 }
diff --git a/src/cpu/intel_cpus.h b/src/cpu/intel_cpus.h
index d20db9a..79afb98 100644
--- a/src/cpu/intel_cpus.h
+++ b/src/cpu/intel_cpus.h
@@ -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();
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-15 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04 21:55 [Powertop] [PATCH] Don't use intel_cpus if APERF MSR isn't supported 
2018-05-15 16:20 

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).