All of lore.kernel.org
 help / color / mirror / Atom feed
* [Powertop] Don't use intel_cpus if APERF MSR isn't supported
@ 2018-05-15 10:47 Jaroslav Skarvada
  0 siblings, 0 replies; only message in thread
From: Jaroslav Skarvada @ 2018-05-15 10:47 UTC (permalink / raw)
  To: powertop

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

Hi,

resending the patch which should allow PowerTOP to run on KVM and
other VMs not fully supporting MSR

thanks & regards

Jaroslav

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-use-intel_cpus-if-APERF-MSR-isn-t-supported.patch --]
[-- Type: text/x-patch, Size: 2840 bytes --]

From f3b21d8aa4799db5b1ec41543fcae681c02a8c89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= <jskarvad@redhat.com>
Date: Fri, 4 May 2018 23:36:46 +0200
Subject: [PATCH] Don't use intel_cpus if APERF MSR isn't supported
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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@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] only message in thread

only message in thread, other threads:[~2018-05-15 10:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15 10:47 [Powertop] Don't use intel_cpus if APERF MSR isn't supported Jaroslav Skarvada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.