mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Imre Palik <imrep.amz@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Andi Kleen <ak@linux.intel.com>,
	Stephane Eranian <eranian@google.com>,
	Kan Liang <kan.liang@intel.com>,
	David Carrillo-Cisneros <davidcc@google.com>,
	linux-kernel@vger.kernel.org,
	Alexander Kozyrev <alexander.kozyrev@intel.com>,
	Artyom Kuanbekov <artyom.kuanbekov@intel.com>,
	Imre Palik <imrep@amazon.de>, Matt Wilson <msw@amazon.com>,
	David Woodhouse <dwmw@amazon.co.uk>
Subject: [RFC PATCH v2] perf: honouring the cpuid for number of fixed counters in hypervisors
Date: Fri, 21 Oct 2016 01:18:59 -0700	[thread overview]
Message-ID: <1477037939-15605-1-git-send-email-imrep.amz@gmail.com> (raw)

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>
Cc: David Woodhouse <dwmw@amazon.co.uk>
---
 arch/x86/events/intel/core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a3a9eb8..e06d071 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3607,10 +3607,14 @@ __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) {
+		if (static_cpu_has(X86_FEATURE_HYPERVISOR))
+			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

             reply	other threads:[~2016-10-21  8:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21  8:18 Imre Palik [this message]
2016-10-24 16:50 ` Andi Kleen
2016-10-26  9:16 ` Peter Zijlstra
2016-10-28 10:11 ` [tip:perf/urgent] perf/x86/intel: Honour the CPUID " tip-bot for Imre Palik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1477037939-15605-1-git-send-email-imrep.amz@gmail.com \
    --to=imrep.amz@gmail.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.kozyrev@intel.com \
    --cc=artyom.kuanbekov@intel.com \
    --cc=davidcc@google.com \
    --cc=dwmw@amazon.co.uk \
    --cc=eranian@google.com \
    --cc=hpa@zytor.com \
    --cc=imrep@amazon.de \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=msw@amazon.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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