Skip to content

Commit ee28855

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel: Increase max number of the fixed counters
The new PEBS format 5 implies that the number of the fixed counters can be up to 16. The current INTEL_PMC_MAX_FIXED is still 4. If the current kernel runs on a future platform which has more than 4 fixed counters, a warning will be triggered. The number of the fixed counters will be clipped to 4. Users have to upgrade the kernel to access the new fixed counters. Add a new default constraint for PerfMon v5 and up, which can support up to 16 fixed counters. The pseudo-encoding is applied for the fixed counters 4 and later. The user can have generic support for the new fixed counters on the future platfroms without updating the kernel. Increase the INTEL_PMC_MAX_FIXED to 16. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 0144ba0 commit ee28855

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

arch/x86/events/intel/core.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ static struct event_constraint intel_gen_event_constraints[] __read_mostly =
181181
EVENT_CONSTRAINT_END
182182
};
183183

184+
static struct event_constraint intel_v5_gen_event_constraints[] __read_mostly =
185+
{
186+
FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
187+
FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
188+
FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
189+
FIXED_EVENT_CONSTRAINT(0x0400, 3), /* SLOTS */
190+
FIXED_EVENT_CONSTRAINT(0x0500, 4),
191+
FIXED_EVENT_CONSTRAINT(0x0600, 5),
192+
FIXED_EVENT_CONSTRAINT(0x0700, 6),
193+
FIXED_EVENT_CONSTRAINT(0x0800, 7),
194+
FIXED_EVENT_CONSTRAINT(0x0900, 8),
195+
FIXED_EVENT_CONSTRAINT(0x0a00, 9),
196+
FIXED_EVENT_CONSTRAINT(0x0b00, 10),
197+
FIXED_EVENT_CONSTRAINT(0x0c00, 11),
198+
FIXED_EVENT_CONSTRAINT(0x0d00, 12),
199+
FIXED_EVENT_CONSTRAINT(0x0e00, 13),
200+
FIXED_EVENT_CONSTRAINT(0x0f00, 14),
201+
FIXED_EVENT_CONSTRAINT(0x1000, 15),
202+
EVENT_CONSTRAINT_END
203+
};
204+
184205
static struct event_constraint intel_slm_event_constraints[] __read_mostly =
185206
{
186207
FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
@@ -6295,14 +6316,31 @@ __init int intel_pmu_init(void)
62956316
pr_cont("generic architected perfmon v1, ");
62966317
name = "generic_arch_v1";
62976318
break;
6298-
default:
6319+
case 2:
6320+
case 3:
6321+
case 4:
62996322
/*
63006323
* default constraints for v2 and up
63016324
*/
63026325
x86_pmu.event_constraints = intel_gen_event_constraints;
63036326
pr_cont("generic architected perfmon, ");
63046327
name = "generic_arch_v2+";
63056328
break;
6329+
default:
6330+
/*
6331+
* The default constraints for v5 and up can support up to
6332+
* 16 fixed counters. For the fixed counters 4 and later,
6333+
* the pseudo-encoding is applied.
6334+
* The constraints may be cut according to the CPUID enumeration
6335+
* by inserting the EVENT_CONSTRAINT_END.
6336+
*/
6337+
if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED)
6338+
x86_pmu.num_counters_fixed = INTEL_PMC_MAX_FIXED;
6339+
intel_v5_gen_event_constraints[x86_pmu.num_counters_fixed].weight = -1;
6340+
x86_pmu.event_constraints = intel_v5_gen_event_constraints;
6341+
pr_cont("generic architected perfmon, ");
6342+
name = "generic_arch_v5+";
6343+
break;
63066344
}
63076345
}
63086346

arch/x86/include/asm/perf_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
#define INTEL_PMC_MAX_GENERIC 32
10-
#define INTEL_PMC_MAX_FIXED 4
10+
#define INTEL_PMC_MAX_FIXED 16
1111
#define INTEL_PMC_IDX_FIXED 32
1212

1313
#define X86_PMC_IDX_MAX 64

0 commit comments

Comments
 (0)