Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758602AbcJ1KO6 (ORCPT ); Fri, 28 Oct 2016 06:14:58 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53026 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbcJ1KO5 (ORCPT ); Fri, 28 Oct 2016 06:14:57 -0400 Date: Fri, 28 Oct 2016 03:11:03 -0700 From: tip-bot for Imre Palik Message-ID: Cc: torvalds@linux-foundation.org, peterz@infradead.org, hpa@zytor.com, ak@linux.intel.com, imrep@amazon.de, acme@redhat.com, alexander.kozyrev@intel.com, jolsa@redhat.com, msw@amazon.com, linux-kernel@vger.kernel.org, eranian@google.com, kan.liang@intel.com, dwmw@amazon.co.uk, alexander.shishkin@linux.intel.com, davidcc@google.com, mingo@kernel.org, tglx@linutronix.de, artyom.kuanbekov@intel.com Reply-To: eranian@google.com, kan.liang@intel.com, msw@amazon.com, linux-kernel@vger.kernel.org, alexander.kozyrev@intel.com, jolsa@redhat.com, tglx@linutronix.de, artyom.kuanbekov@intel.com, davidcc@google.com, mingo@kernel.org, alexander.shishkin@linux.intel.com, dwmw@amazon.co.uk, ak@linux.intel.com, peterz@infradead.org, hpa@zytor.com, torvalds@linux-foundation.org, acme@redhat.com, imrep@amazon.de In-Reply-To: <1477037939-15605-1-git-send-email-imrep.amz@gmail.com> References: <1477037939-15605-1-git-send-email-imrep.amz@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf/x86/intel: Honour the CPUID for number of fixed counters in hypervisors Git-Commit-ID: f92b7604149a55cb601fc0b52911b1e11f0f2514 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2529 Lines: 65 Commit-ID: f92b7604149a55cb601fc0b52911b1e11f0f2514 Gitweb: http://git.kernel.org/tip/f92b7604149a55cb601fc0b52911b1e11f0f2514 Author: Imre Palik AuthorDate: Fri, 21 Oct 2016 01:18:59 -0700 Committer: Ingo Molnar CommitDate: Fri, 28 Oct 2016 11:06:25 +0200 perf/x86/intel: Honour the CPUID for number of fixed counters in hypervisors perf doesn't seem to honour the number of fixed counters specified by CPUID leaf 0xa. It always assumes 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 Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andi Kleen Cc: Alexander Kozyrev Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Artyom Kuanbekov Cc: David Carrillo-Cisneros Cc: David Woodhouse Cc: H. Peter Anvin Cc: Jiri Olsa Cc: Kan Liang Cc: Linus Torvalds Cc: Matt Wilson Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1477037939-15605-1-git-send-email-imrep.amz@gmail.com Signed-off-by: Ingo Molnar --- 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 eab0915..a74a2db 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) { + int assume = 3 * !boot_cpu_has(X86_FEATURE_HYPERVISOR); + + x86_pmu.num_counters_fixed = + max((int)edx.split.num_counters_fixed, assume); + } if (boot_cpu_has(X86_FEATURE_PDCM)) { u64 capabilities;