mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors
@ 2016-10-13  8:28 Imre Palik
  2016-10-16 13:50 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Imre Palik @ 2016-10-13  8:28 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86
  Cc: Peter Zijlstra, Andi Kleen, Stephane Eranian, Kan Liang,
	David Carrillo-Cisneros, linux-kernel, Alexander Kozyrev,
	Artyom Kuanbekov, Imre Palik, Matt Wilson

From: Imre Palik <imrep@amazon.de>

perf doesn't seem to honour the number of fixed counters specified by cpuid
leaf 0xa.  It always assume that Intel CPUs have at least 3 fixed counters.

So if some of the fixed counters are masked out by the hypervisor, it still
tries to check/set them.

This patch makes perf behave nicer when the kernel is running under a
hypervisor that doesn't expose all the counters.

This patch contains some ideas from Matt Wilson.

Signed-off-by: Imre Palik <imrep@amazon.de>
Cc: Matt Wilson <msw@amazon.com>
---
 arch/x86/events/intel/core.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a3a9eb8..12ca3f9 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3607,10 +3607,18 @@ __init int intel_pmu_init(void)
 
 	/*
 	 * Quirk: v2 perfmon does not report fixed-purpose events, so
-	 * assume at least 3 events:
+	 * assume at least 3 events, when not running in a hypervisor:
 	 */
-	if (version > 1)
-		x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
+	if (version > 1) {
+		unsigned int ecx = cpuid_ecx(1);
+
+		if (ecx >> 31)
+			x86_pmu.num_counters_fixed =
+				edx.split.num_counters_fixed;
+		else
+			x86_pmu.num_counters_fixed =
+				max((int)edx.split.num_counters_fixed, 3);
+	}
 
 	if (boot_cpu_has(X86_FEATURE_PDCM)) {
 		u64 capabilities;
-- 
2.10.1

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

* Re: [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors
  2016-10-13  8:28 [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors Imre Palik
@ 2016-10-16 13:50 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2016-10-16 13:50 UTC (permalink / raw)
  To: Imre Palik
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Andi Kleen,
	Stephane Eranian, Kan Liang, David Carrillo-Cisneros,
	linux-kernel, Alexander Kozyrev, Artyom Kuanbekov, Imre Palik,
	Matt Wilson

On Thu, Oct 13, 2016 at 01:28:09AM -0700, Imre Palik wrote:
> +	if (version > 1) {
> +		unsigned int ecx = cpuid_ecx(1);
> +
> +		if (ecx >> 31)

What is this magic, undocumented gunk doing? Is that supposed to be
static_cpu_has(X86_FEATURE_HYPERVISOR) ?

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

end of thread, other threads:[~2016-10-16 13:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-13  8:28 [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors Imre Palik
2016-10-16 13:50 ` Peter Zijlstra

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

Powered by JetHome