Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1500097 > unrolled thread

[RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors

Started byImre Palik <imrep.amz@gmail.com>
First post2016-10-13 10:50 +0200
Last post2016-10-16 16:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors Imre Palik <imrep.amz@gmail.com> - 2016-10-13 10:50 +0200
    Re: [RFC PATCH] perf: honouring the cpuid for number of fixed  counters in hypervisors Peter Zijlstra <peterz@infradead.org> - 2016-10-16 16:00 +0200

#1500097 — [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors

FromImre Palik <imrep.amz@gmail.com>
Date2016-10-13 10:50 +0200
Subject[RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors
Message-ID<srJS9-18s-7@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1501456 — Re: [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors

FromPeter Zijlstra <peterz@infradead.org>
Date2016-10-16 16:00 +0200
SubjectRe: [RFC PATCH] perf: honouring the cpuid for number of fixed counters in hypervisors
Message-ID<ssU8N-6xj-3@gated-at.bofh.it>
In reply to#1500097
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) ?

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web