Commit f92b7604 authored by Imre Palik's avatar Imre Palik Committed by Ingo Molnar

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: default avatarImre Palik <>
Signed-off-by: default avatarPeter Zijlstra (Intel) <>
Reviewed-by: default avatarAndi 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: default avatarIngo Molnar <>
parent 5aab90ce
......@@ -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;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment