Skip to content

Commit 61b985e

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel: Add perf core PMU support for Sapphire Rapids
Add perf core PMU support for the Intel Sapphire Rapids server, which is the successor of the Intel Ice Lake server. The enabling code is based on Ice Lake, but there are several new features introduced. The event encoding is changed and simplified, e.g., the event codes which are below 0x90 are restricted to counters 0-3. The event codes which above 0x90 are likely to have no restrictions. The event constraints, extra_regs(), and hardware cache events table are changed accordingly. A new Precise Distribution (PDist) facility is introduced, which further minimizes the skid when a precise event is programmed on the GP counter 0. Enable the Precise Distribution (PDist) facility with :ppp event. For this facility to work, the period must be initialized with a value larger than 127. Add spr_limit_period() to apply the limit for :ppp event. Two new data source fields, data block & address block, are added in the PEBS Memory Info Record for the load latency event. To enable the feature, - An auxiliary event has to be enabled together with the load latency event on Sapphire Rapids. A new flag PMU_FL_MEM_LOADS_AUX is introduced to indicate the case. A new event, mem-loads-aux, is exposed to sysfs for the user tool. Add a check in hw_config(). If the auxiliary event is not detected, return an unique error -ENODATA. - The union perf_mem_data_src is extended to support the new fields. - Ice Lake and earlier models do not support block information, but the fields may be set by HW on some machines. Add pebs_no_block to explicitly indicate the previous platforms which don't support the new block fields. Accessing the new block fields are ignored on those platforms. A new store Latency facility is introduced, which leverages the PEBS facility where it can provide additional information about sampled stores. The additional information includes the data address, memory auxiliary info (e.g. Data Source, STLB miss) and the latency of the store access. To enable the facility, the new event (0x02cd) has to be programed on the GP counter 0. A new flag PERF_X86_EVENT_PEBS_STLAT is introduced to indicate the event. The store_latency_data() is introduced to parse the memory auxiliary info. The layout of access latency field of PEBS Memory Info Record has been changed. Two latency, instruction latency (bit 15:0) and cache access latency (bit 47:32) are recorded. - The cache access latency is similar to previous memory access latency. For loads, the latency starts by the actual cache access until the data is returned by the memory subsystem. For stores, the latency starts when the demand write accesses the L1 data cache and lasts until the cacheline write is completed in the memory subsystem. The cache access latency is stored in low 32bits of the sample type PERF_SAMPLE_WEIGHT_STRUCT. - The instruction latency starts by the dispatch of the load operation for execution and lasts until completion of the instruction it belongs to. Add a new flag PMU_FL_INSTR_LATENCY to indicate the instruction latency support. The instruction latency is stored in the bit 47:32 of the sample type PERF_SAMPLE_WEIGHT_STRUCT. Extends the PERF_METRICS MSR to feature TMA method level 2 metrics. The lower half of the register is the TMA level 1 metrics (legacy). The upper half is also divided into four 8-bit fields for the new level 2 metrics. Expose all eight Topdown metrics events to user space. The full description for the SPR features can be found at Intel Architecture Instruction Set Extensions and Future Features Programming Reference, 319433-041. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/1611873611-156687-5-git-send-email-kan.liang@linux.intel.com
1 parent 1ab5f23 commit 61b985e

5 files changed

Lines changed: 443 additions & 14 deletions

File tree

‎arch/x86/events/intel/core.c‎

Lines changed: 302 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,55 @@ static struct extra_reg intel_icl_extra_regs[] __read_mostly = {
275275
EVENT_EXTRA_END
276276
};
277277

278+
static struct extra_reg intel_spr_extra_regs[] __read_mostly = {
279+
INTEL_UEVENT_EXTRA_REG(0x012a, MSR_OFFCORE_RSP_0, 0x3fffffffffull, RSP_0),
280+
INTEL_UEVENT_EXTRA_REG(0x012b, MSR_OFFCORE_RSP_1, 0x3fffffffffull, RSP_1),
281+
INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd),
282+
INTEL_UEVENT_EXTRA_REG(0x01c6, MSR_PEBS_FRONTEND, 0x7fff17, FE),
283+
EVENT_EXTRA_END
284+
};
285+
286+
static struct event_constraint intel_spr_event_constraints[] = {
287+
FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
288+
FIXED_EVENT_CONSTRAINT(0x01c0, 0), /* INST_RETIRED.PREC_DIST */
289+
FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
290+
FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
291+
FIXED_EVENT_CONSTRAINT(0x0400, 3), /* SLOTS */
292+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_RETIRING, 0),
293+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_BAD_SPEC, 1),
294+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_FE_BOUND, 2),
295+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_BE_BOUND, 3),
296+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_HEAVY_OPS, 4),
297+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_BR_MISPREDICT, 5),
298+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_FETCH_LAT, 6),
299+
METRIC_EVENT_CONSTRAINT(INTEL_TD_METRIC_MEM_BOUND, 7),
300+
301+
INTEL_EVENT_CONSTRAINT(0x2e, 0xff),
302+
INTEL_EVENT_CONSTRAINT(0x3c, 0xff),
303+
/*
304+
* Generally event codes < 0x90 are restricted to counters 0-3.
305+
* The 0x2E and 0x3C are exception, which has no restriction.
306+
*/
307+
INTEL_EVENT_CONSTRAINT_RANGE(0x01, 0x8f, 0xf),
308+
309+
INTEL_UEVENT_CONSTRAINT(0x01a3, 0xf),
310+
INTEL_UEVENT_CONSTRAINT(0x02a3, 0xf),
311+
INTEL_UEVENT_CONSTRAINT(0x08a3, 0xf),
312+
INTEL_UEVENT_CONSTRAINT(0x04a4, 0x1),
313+
INTEL_UEVENT_CONSTRAINT(0x08a4, 0x1),
314+
INTEL_UEVENT_CONSTRAINT(0x02cd, 0x1),
315+
INTEL_EVENT_CONSTRAINT(0xce, 0x1),
316+
INTEL_EVENT_CONSTRAINT_RANGE(0xd0, 0xdf, 0xf),
317+
/*
318+
* Generally event codes >= 0x90 are likely to have no restrictions.
319+
* The exception are defined as above.
320+
*/
321+
INTEL_EVENT_CONSTRAINT_RANGE(0x90, 0xfe, 0xff),
322+
323+
EVENT_CONSTRAINT_END
324+
};
325+
326+
278327
EVENT_ATTR_STR(mem-loads, mem_ld_nhm, "event=0x0b,umask=0x10,ldlat=3");
279328
EVENT_ATTR_STR(mem-loads, mem_ld_snb, "event=0xcd,umask=0x1,ldlat=3");
280329
EVENT_ATTR_STR(mem-stores, mem_st_snb, "event=0xcd,umask=0x2");
@@ -314,11 +363,15 @@ EVENT_ATTR_STR_HT(topdown-recovery-bubbles, td_recovery_bubbles,
314363
EVENT_ATTR_STR_HT(topdown-recovery-bubbles.scale, td_recovery_bubbles_scale,
315364
"4", "2");
316365

317-
EVENT_ATTR_STR(slots, slots, "event=0x00,umask=0x4");
318-
EVENT_ATTR_STR(topdown-retiring, td_retiring, "event=0x00,umask=0x80");
319-
EVENT_ATTR_STR(topdown-bad-spec, td_bad_spec, "event=0x00,umask=0x81");
320-
EVENT_ATTR_STR(topdown-fe-bound, td_fe_bound, "event=0x00,umask=0x82");
321-
EVENT_ATTR_STR(topdown-be-bound, td_be_bound, "event=0x00,umask=0x83");
366+
EVENT_ATTR_STR(slots, slots, "event=0x00,umask=0x4");
367+
EVENT_ATTR_STR(topdown-retiring, td_retiring, "event=0x00,umask=0x80");
368+
EVENT_ATTR_STR(topdown-bad-spec, td_bad_spec, "event=0x00,umask=0x81");
369+
EVENT_ATTR_STR(topdown-fe-bound, td_fe_bound, "event=0x00,umask=0x82");
370+
EVENT_ATTR_STR(topdown-be-bound, td_be_bound, "event=0x00,umask=0x83");
371+
EVENT_ATTR_STR(topdown-heavy-ops, td_heavy_ops, "event=0x00,umask=0x84");
372+
EVENT_ATTR_STR(topdown-br-mispredict, td_br_mispredict, "event=0x00,umask=0x85");
373+
EVENT_ATTR_STR(topdown-fetch-lat, td_fetch_lat, "event=0x00,umask=0x86");
374+
EVENT_ATTR_STR(topdown-mem-bound, td_mem_bound, "event=0x00,umask=0x87");
322375

323376
static struct attribute *snb_events_attrs[] = {
324377
EVENT_PTR(td_slots_issued),
@@ -384,6 +437,108 @@ static u64 intel_pmu_event_map(int hw_event)
384437
return intel_perfmon_event_map[hw_event];
385438
}
386439

440+
static __initconst const u64 spr_hw_cache_event_ids
441+
[PERF_COUNT_HW_CACHE_MAX]
442+
[PERF_COUNT_HW_CACHE_OP_MAX]
443+
[PERF_COUNT_HW_CACHE_RESULT_MAX] =
444+
{
445+
[ C(L1D ) ] = {
446+
[ C(OP_READ) ] = {
447+
[ C(RESULT_ACCESS) ] = 0x81d0,
448+
[ C(RESULT_MISS) ] = 0xe124,
449+
},
450+
[ C(OP_WRITE) ] = {
451+
[ C(RESULT_ACCESS) ] = 0x82d0,
452+
},
453+
},
454+
[ C(L1I ) ] = {
455+
[ C(OP_READ) ] = {
456+
[ C(RESULT_MISS) ] = 0xe424,
457+
},
458+
[ C(OP_WRITE) ] = {
459+
[ C(RESULT_ACCESS) ] = -1,
460+
[ C(RESULT_MISS) ] = -1,
461+
},
462+
},
463+
[ C(LL ) ] = {
464+
[ C(OP_READ) ] = {
465+
[ C(RESULT_ACCESS) ] = 0x12a,
466+
[ C(RESULT_MISS) ] = 0x12a,
467+
},
468+
[ C(OP_WRITE) ] = {
469+
[ C(RESULT_ACCESS) ] = 0x12a,
470+
[ C(RESULT_MISS) ] = 0x12a,
471+
},
472+
},
473+
[ C(DTLB) ] = {
474+
[ C(OP_READ) ] = {
475+
[ C(RESULT_ACCESS) ] = 0x81d0,
476+
[ C(RESULT_MISS) ] = 0xe12,
477+
},
478+
[ C(OP_WRITE) ] = {
479+
[ C(RESULT_ACCESS) ] = 0x82d0,
480+
[ C(RESULT_MISS) ] = 0xe13,
481+
},
482+
},
483+
[ C(ITLB) ] = {
484+
[ C(OP_READ) ] = {
485+
[ C(RESULT_ACCESS) ] = -1,
486+
[ C(RESULT_MISS) ] = 0xe11,
487+
},
488+
[ C(OP_WRITE) ] = {
489+
[ C(RESULT_ACCESS) ] = -1,
490+
[ C(RESULT_MISS) ] = -1,
491+
},
492+
[ C(OP_PREFETCH) ] = {
493+
[ C(RESULT_ACCESS) ] = -1,
494+
[ C(RESULT_MISS) ] = -1,
495+
},
496+
},
497+
[ C(BPU ) ] = {
498+
[ C(OP_READ) ] = {
499+
[ C(RESULT_ACCESS) ] = 0x4c4,
500+
[ C(RESULT_MISS) ] = 0x4c5,
501+
},
502+
[ C(OP_WRITE) ] = {
503+
[ C(RESULT_ACCESS) ] = -1,
504+
[ C(RESULT_MISS) ] = -1,
505+
},
506+
[ C(OP_PREFETCH) ] = {
507+
[ C(RESULT_ACCESS) ] = -1,
508+
[ C(RESULT_MISS) ] = -1,
509+
},
510+
},
511+
[ C(NODE) ] = {
512+
[ C(OP_READ) ] = {
513+
[ C(RESULT_ACCESS) ] = 0x12a,
514+
[ C(RESULT_MISS) ] = 0x12a,
515+
},
516+
},
517+
};
518+
519+
static __initconst const u64 spr_hw_cache_extra_regs
520+
[PERF_COUNT_HW_CACHE_MAX]
521+
[PERF_COUNT_HW_CACHE_OP_MAX]
522+
[PERF_COUNT_HW_CACHE_RESULT_MAX] =
523+
{
524+
[ C(LL ) ] = {
525+
[ C(OP_READ) ] = {
526+
[ C(RESULT_ACCESS) ] = 0x10001,
527+
[ C(RESULT_MISS) ] = 0x3fbfc00001,
528+
},
529+
[ C(OP_WRITE) ] = {
530+
[ C(RESULT_ACCESS) ] = 0x3f3ffc0002,
531+
[ C(RESULT_MISS) ] = 0x3f3fc00002,
532+
},
533+
},
534+
[ C(NODE) ] = {
535+
[ C(OP_READ) ] = {
536+
[ C(RESULT_ACCESS) ] = 0x10c000001,
537+
[ C(RESULT_MISS) ] = 0x3fb3000001,
538+
},
539+
},
540+
};
541+
387542
/*
388543
* Notes on the events:
389544
* - data reads do not include code reads (comparable to earlier tables)
@@ -3478,6 +3633,17 @@ static bool is_available_metric_event(struct perf_event *event)
34783633
event->attr.config <= INTEL_TD_METRIC_AVAILABLE_MAX;
34793634
}
34803635

3636+
static inline bool is_mem_loads_event(struct perf_event *event)
3637+
{
3638+
return (event->attr.config & INTEL_ARCH_EVENT_MASK) == X86_CONFIG(.event=0xcd, .umask=0x01);
3639+
}
3640+
3641+
static inline bool is_mem_loads_aux_event(struct perf_event *event)
3642+
{
3643+
return (event->attr.config & INTEL_ARCH_EVENT_MASK) == X86_CONFIG(.event=0x03, .umask=0x82);
3644+
}
3645+
3646+
34813647
static int intel_pmu_hw_config(struct perf_event *event)
34823648
{
34833649
int ret = x86_pmu_hw_config(event);
@@ -3580,6 +3746,33 @@ static int intel_pmu_hw_config(struct perf_event *event)
35803746
}
35813747
}
35823748

3749+
/*
3750+
* The load latency event X86_CONFIG(.event=0xcd, .umask=0x01) on SPR
3751+
* doesn't function quite right. As a work-around it needs to always be
3752+
* co-scheduled with a auxiliary event X86_CONFIG(.event=0x03, .umask=0x82).
3753+
* The actual count of this second event is irrelevant it just needs
3754+
* to be active to make the first event function correctly.
3755+
*
3756+
* In a group, the auxiliary event must be in front of the load latency
3757+
* event. The rule is to simplify the implementation of the check.
3758+
* That's because perf cannot have a complete group at the moment.
3759+
*/
3760+
if (x86_pmu.flags & PMU_FL_MEM_LOADS_AUX &&
3761+
(event->attr.sample_type & PERF_SAMPLE_DATA_SRC) &&
3762+
is_mem_loads_event(event)) {
3763+
struct perf_event *leader = event->group_leader;
3764+
struct perf_event *sibling = NULL;
3765+
3766+
if (!is_mem_loads_aux_event(leader)) {
3767+
for_each_sibling_event(sibling, leader) {
3768+
if (is_mem_loads_aux_event(sibling))
3769+
break;
3770+
}
3771+
if (list_entry_is_head(sibling, &leader->sibling_list, sibling_list))
3772+
return -ENODATA;
3773+
}
3774+
}
3775+
35833776
if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY))
35843777
return 0;
35853778

@@ -3759,6 +3952,29 @@ icl_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
37593952
return hsw_get_event_constraints(cpuc, idx, event);
37603953
}
37613954

3955+
static struct event_constraint *
3956+
spr_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
3957+
struct perf_event *event)
3958+
{
3959+
struct event_constraint *c;
3960+
3961+
c = icl_get_event_constraints(cpuc, idx, event);
3962+
3963+
/*
3964+
* The :ppp indicates the Precise Distribution (PDist) facility, which
3965+
* is only supported on the GP counter 0. If a :ppp event which is not
3966+
* available on the GP counter 0, error out.
3967+
*/
3968+
if (event->attr.precise_ip == 3) {
3969+
if (c->idxmsk64 & BIT_ULL(0))
3970+
return &counter0_constraint;
3971+
3972+
return &emptyconstraint;
3973+
}
3974+
3975+
return c;
3976+
}
3977+
37623978
static struct event_constraint *
37633979
glp_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
37643980
struct perf_event *event)
@@ -3848,6 +4064,14 @@ static u64 nhm_limit_period(struct perf_event *event, u64 left)
38484064
return max(left, 32ULL);
38494065
}
38504066

4067+
static u64 spr_limit_period(struct perf_event *event, u64 left)
4068+
{
4069+
if (event->attr.precise_ip == 3)
4070+
return max(left, 128ULL);
4071+
4072+
return left;
4073+
}
4074+
38514075
PMU_FORMAT_ATTR(event, "config:0-7" );
38524076
PMU_FORMAT_ATTR(umask, "config:8-15" );
38534077
PMU_FORMAT_ATTR(edge, "config:18" );
@@ -4559,6 +4783,42 @@ static struct attribute *icl_tsx_events_attrs[] = {
45594783
NULL,
45604784
};
45614785

4786+
4787+
EVENT_ATTR_STR(mem-stores, mem_st_spr, "event=0xcd,umask=0x2");
4788+
EVENT_ATTR_STR(mem-loads-aux, mem_ld_aux, "event=0x03,umask=0x82");
4789+
4790+
static struct attribute *spr_events_attrs[] = {
4791+
EVENT_PTR(mem_ld_hsw),
4792+
EVENT_PTR(mem_st_spr),
4793+
EVENT_PTR(mem_ld_aux),
4794+
NULL,
4795+
};
4796+
4797+
static struct attribute *spr_td_events_attrs[] = {
4798+
EVENT_PTR(slots),
4799+
EVENT_PTR(td_retiring),
4800+
EVENT_PTR(td_bad_spec),
4801+
EVENT_PTR(td_fe_bound),
4802+
EVENT_PTR(td_be_bound),
4803+
EVENT_PTR(td_heavy_ops),
4804+
EVENT_PTR(td_br_mispredict),
4805+
EVENT_PTR(td_fetch_lat),
4806+
EVENT_PTR(td_mem_bound),
4807+
NULL,
4808+
};
4809+
4810+
static struct attribute *spr_tsx_events_attrs[] = {
4811+
EVENT_PTR(tx_start),
4812+
EVENT_PTR(tx_abort),
4813+
EVENT_PTR(tx_commit),
4814+
EVENT_PTR(tx_capacity_read),
4815+
EVENT_PTR(tx_capacity_write),
4816+
EVENT_PTR(tx_conflict),
4817+
EVENT_PTR(cycles_t),
4818+
EVENT_PTR(cycles_ct),
4819+
NULL,
4820+
};
4821+
45624822
static ssize_t freeze_on_smi_show(struct device *cdev,
45634823
struct device_attribute *attr,
45644824
char *buf)
@@ -5341,6 +5601,43 @@ __init int intel_pmu_init(void)
53415601
name = "icelake";
53425602
break;
53435603

5604+
case INTEL_FAM6_SAPPHIRERAPIDS_X:
5605+
pmem = true;
5606+
x86_pmu.late_ack = true;
5607+
memcpy(hw_cache_event_ids, spr_hw_cache_event_ids, sizeof(hw_cache_event_ids));
5608+
memcpy(hw_cache_extra_regs, spr_hw_cache_extra_regs, sizeof(hw_cache_extra_regs));
5609+
5610+
x86_pmu.event_constraints = intel_spr_event_constraints;
5611+
x86_pmu.pebs_constraints = intel_spr_pebs_event_constraints;
5612+
x86_pmu.extra_regs = intel_spr_extra_regs;
5613+
x86_pmu.limit_period = spr_limit_period;
5614+
x86_pmu.pebs_aliases = NULL;
5615+
x86_pmu.pebs_prec_dist = true;
5616+
x86_pmu.pebs_block = true;
5617+
x86_pmu.flags |= PMU_FL_HAS_RSP_1;
5618+
x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
5619+
x86_pmu.flags |= PMU_FL_PEBS_ALL;
5620+
x86_pmu.flags |= PMU_FL_INSTR_LATENCY;
5621+
x86_pmu.flags |= PMU_FL_MEM_LOADS_AUX;
5622+
5623+
x86_pmu.hw_config = hsw_hw_config;
5624+
x86_pmu.get_event_constraints = spr_get_event_constraints;
5625+
extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
5626+
hsw_format_attr : nhm_format_attr;
5627+
extra_skl_attr = skl_format_attr;
5628+
mem_attr = spr_events_attrs;
5629+
td_attr = spr_td_events_attrs;
5630+
tsx_attr = spr_tsx_events_attrs;
5631+
x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xc9, .umask=0x04);
5632+
x86_pmu.lbr_pt_coexist = true;
5633+
intel_pmu_pebs_data_source_skl(pmem);
5634+
x86_pmu.num_topdown_events = 8;
5635+
x86_pmu.update_topdown_event = icl_update_topdown_event;
5636+
x86_pmu.set_topdown_event_period = icl_set_topdown_event_period;
5637+
pr_cont("Sapphire Rapids events, ");
5638+
name = "sapphire_rapids";
5639+
break;
5640+
53445641
default:
53455642
switch (x86_pmu.version) {
53465643
case 1:

0 commit comments

Comments
 (0)