public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] turbostat: Running on virtual machine is not supported
@ 2017-07-25 12:55 Prarit Bhargava
  2017-07-25 15:59 ` Henrique de Moraes Holschuh
  0 siblings, 1 reply; 6+ messages in thread
From: Prarit Bhargava @ 2017-07-25 12:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: Prarit Bhargava, Len Brown, Len Brown

When running turbostat on a virtual machine the error

turbostat: msr 0 offset 0xe2 read failed: Input/output error

is output to the user.

/dev/msr and perf do not work on a virtual machine.  turbostat is
dependent on that support so turbostat does not work either.

A common way of determining if the system is a virtual machine is to
search /proc/cpuinfo flags entry for "hypervisor".  turbostat must output
a proper error message when found.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Len Brown <lenb@kernel.org>
---
 tools/power/x86/turbostat/turbostat.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 0dafba2c1e7d..ca1ea68bc4e8 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -5088,6 +5088,34 @@ void cmdline(int argc, char **argv)
 	}
 }
 
+int has_hypervisor(void)
+{
+	FILE *cpuinfo;
+	char *flags, *hypervisor;
+	char *buffer;
+
+	/* On VMs /proc/cpuinfo contains a "flags" entry for hypervisor */
+	cpuinfo = fopen_or_die("/proc/cpuinfo", "ro");
+
+	buffer = malloc(4096);
+	if (!buffer)
+		err(-ENOMEM, "buffer malloc fail");
+
+	fread(buffer, 1024, 1, cpuinfo);
+
+	flags = strstr(buffer, "flags");
+	rewind(cpuinfo);
+	fseek(cpuinfo, flags - buffer, SEEK_SET);
+	fgets(buffer, 4096, cpuinfo);
+	fclose(cpuinfo);
+
+	hypervisor = strstr(buffer, "hypervisor");
+
+	free(buffer);
+
+	return !!hypervisor;
+}
+
 int main(int argc, char **argv)
 {
 	outf = stderr;
@@ -5097,6 +5125,12 @@ int main(int argc, char **argv)
 	if (!quiet)
 		print_version();
 
+	if (has_hypervisor()) {
+		fprintf(outf,
+			"turbostat is not supported on virtual machines.\n");
+		return -ENXIO;
+	}
+
 	probe_sysfs();
 
 	turbostat_init();
-- 
1.8.5.5

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

* Re: [PATCH] turbostat: Running on virtual machine is not supported
  2017-07-25 12:55 [PATCH] turbostat: Running on virtual machine is not supported Prarit Bhargava
@ 2017-07-25 15:59 ` Henrique de Moraes Holschuh
  2017-07-27  3:09   ` Len Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Henrique de Moraes Holschuh @ 2017-07-25 15:59 UTC (permalink / raw)
  To: Prarit Bhargava; +Cc: linux-kernel, Len Brown, Len Brown

On Tue, 25 Jul 2017, Prarit Bhargava wrote:
> A common way of determining if the system is a virtual machine is to
> search /proc/cpuinfo flags entry for "hypervisor".  turbostat must output
> a proper error message when found.

Maybe you could output that message only if it fails to both use
/dev/msr and perf *and* it is under a virtual machine?  That would have
better forward compatibility, maybe someday /dev/msr or perf will work
inside a VM for what turbostat needs...

-- 
  Henrique Holschuh

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

* Re: [PATCH] turbostat: Running on virtual machine is not supported
  2017-07-25 15:59 ` Henrique de Moraes Holschuh
@ 2017-07-27  3:09   ` Len Brown
  2017-07-27 11:44     ` Prarit Bhargava
  2017-07-28 11:54     ` Prarit Bhargava
  0 siblings, 2 replies; 6+ messages in thread
From: Len Brown @ 2017-07-27  3:09 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh
  Cc: Prarit Bhargava, linux-kernel@vger.kernel.org, Len Brown

Henrique,

I like your suggestion, thanks!

BTW. let's discuss (and patch) turbostat on linux-pm, rather than on lkml.

thanks,
-Len


On Tue, Jul 25, 2017 at 11:59 AM, Henrique de Moraes Holschuh
<hmh@hmh.eng.br> wrote:
> On Tue, 25 Jul 2017, Prarit Bhargava wrote:
>> A common way of determining if the system is a virtual machine is to
>> search /proc/cpuinfo flags entry for "hypervisor".  turbostat must output
>> a proper error message when found.
>
> Maybe you could output that message only if it fails to both use
> /dev/msr and perf *and* it is under a virtual machine?  That would have
> better forward compatibility, maybe someday /dev/msr or perf will work
> inside a VM for what turbostat needs...
>
> --
>   Henrique Holschuh



-- 
Len Brown, Intel Open Source Technology Center

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

* Re: [PATCH] turbostat: Running on virtual machine is not supported
  2017-07-27  3:09   ` Len Brown
@ 2017-07-27 11:44     ` Prarit Bhargava
  2017-08-05  6:39       ` Len Brown
  2017-07-28 11:54     ` Prarit Bhargava
  1 sibling, 1 reply; 6+ messages in thread
From: Prarit Bhargava @ 2017-07-27 11:44 UTC (permalink / raw)
  To: Len Brown, Henrique de Moraes Holschuh
  Cc: linux-kernel@vger.kernel.org, Len Brown



On 07/26/2017 11:09 PM, Len Brown wrote:
> Henrique,
> 
> I like your suggestion, thanks!
> 
> BTW. let's discuss (and patch) turbostat on linux-pm, rather than on lkml.

Sure -- Len, can you add an entry to RHMAINTAINERS for that?  I use the
get_maintainer.pl script to apply all cc's.

P.

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

* Re: [PATCH] turbostat: Running on virtual machine is not supported
  2017-07-27  3:09   ` Len Brown
  2017-07-27 11:44     ` Prarit Bhargava
@ 2017-07-28 11:54     ` Prarit Bhargava
  1 sibling, 0 replies; 6+ messages in thread
From: Prarit Bhargava @ 2017-07-28 11:54 UTC (permalink / raw)
  To: Len Brown, Henrique de Moraes Holschuh
  Cc: linux-kernel@vger.kernel.org, Len Brown, linux-pm@vger.kernel.org



On 07/26/2017 11:09 PM, Len Brown wrote:
> Henrique,
> 
> I like your suggestion, thanks!
> 
> BTW. let's discuss (and patch) turbostat on linux-pm, rather than on lkml.
> 
> thanks,
> -Len
> 
> 
> On Tue, Jul 25, 2017 at 11:59 AM, Henrique de Moraes Holschuh
> <hmh@hmh.eng.br> wrote:
>> On Tue, 25 Jul 2017, Prarit Bhargava wrote:
>>> A common way of determining if the system is a virtual machine is to
>>> search /proc/cpuinfo flags entry for "hypervisor".  turbostat must output
>>> a proper error message when found.
>>
>> Maybe you could output that message only if it fails to both use
>> /dev/msr and perf *and* it is under a virtual machine?  That would have
>> better forward compatibility, maybe someday /dev/msr or perf will work
>> inside a VM for what turbostat needs...

To answer Len's previous question: I was wrong in my description.  perf does
work (mostly) under virt.  So this would only be for the msr code.  I'll post a
v2 to linux-pm, and take Henrique's suggestion to only trigger on an msr read
failure.

P.

>>
>> --
>>   Henrique Holschuh
> 
> 
> 

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

* Re: [PATCH] turbostat: Running on virtual machine is not supported
  2017-07-27 11:44     ` Prarit Bhargava
@ 2017-08-05  6:39       ` Len Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Len Brown @ 2017-08-05  6:39 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: Henrique de Moraes Holschuh, linux-kernel@vger.kernel.org,
	Len Brown

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

> Len, can you add an entry to RHMAINTAINERS for that?

done.

thx.
Len

[-- Attachment #2: 0001-MAINTAINERS-add-turbostat-utility.patch --]
[-- Type: application/octet-stream, Size: 1110 bytes --]

From a71ec6b6c6ce93fa07f2c6df1dfa69871f08cb5b Mon Sep 17 00:00:00 2001
Message-Id: <a71ec6b6c6ce93fa07f2c6df1dfa69871f08cb5b.1501915126.git.len.brown@intel.com>
From: Len Brown <len.brown@intel.com>
Date: Sat, 5 Aug 2017 02:36:50 -0400
Subject: [PATCH 01/14] MAINTAINERS: add turbostat utility
Reply-To: Len Brown <lenb@kernel.org>
Organization: Intel Open Source Technology Center

Signed-off-by: Len Brown <len.brown@intel.com>
---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7a28acd7f525..cb94ef6412b1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13033,6 +13033,15 @@ S:	Maintained
 F:	drivers/tc/
 F:	include/linux/tc.h
 
+TURBOSTAT UTILITY
+M:	"Len Brown" <lenb@kernel.org>
+L:	linux-pm@vger.kernel.org
+B:	https://bugzilla.kernel.org
+Q:	https://patchwork.kernel.org/project/linux-pm/list/
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git turbostat
+S:	Supported
+F:	tools/power/x86/turbostat/
+
 UBI FILE SYSTEM (UBIFS)
 M:	Richard Weinberger <richard@nod.at>
 M:	Artem Bityutskiy <dedekind1@gmail.com>
-- 
2.14.0-rc0


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

end of thread, other threads:[~2017-08-05  6:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 12:55 [PATCH] turbostat: Running on virtual machine is not supported Prarit Bhargava
2017-07-25 15:59 ` Henrique de Moraes Holschuh
2017-07-27  3:09   ` Len Brown
2017-07-27 11:44     ` Prarit Bhargava
2017-08-05  6:39       ` Len Brown
2017-07-28 11:54     ` Prarit Bhargava

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox