Skip to content

Commit b34133f

Browse files
committed
Merge tag 'perf-core-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf event updates from Ingo Molnar: "HW support updates: - Add uncore support for Intel Comet Lake - Add RAPL support for Hygon Fam18h - Add Intel "IIO stack to PMON mapping" support on Skylake-SP CPUs, which enumerates per device performance counters via sysfs and enables the perf stat --iiostat functionality - Add support for Intel "Architectural LBRs", which generalized the model specific LBR hardware tracing feature into a model-independent, architected performance monitoring feature. Usage is mostly seamless to tooling, as the pre-existing LBR features are kept, but there's a couple of advantages under the hood, such as faster context-switching, faster LBR reads, cleaner exposure of LBR features to guest kernels, etc. ( Since architectural LBRs are supported via XSAVE, there's related changes to the x86 FPU code as well. ) ftrace/perf updates: - Add support to add a text poke event to record changes to kernel text (i.e. self-modifying code) in order to support tracers like Intel PT decoding through jump labels, kprobes and ftrace trampolines. Misc cleanups, smaller fixes..." * tag 'perf-core-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (47 commits) perf/x86/rapl: Add Hygon Fam18h RAPL support kprobes: Remove unnecessary module_mutex locking from kprobe_optimizer() x86/perf: Fix a typo perf: <linux/perf_event.h>: drop a duplicated word perf/x86/intel/lbr: Support XSAVES for arch LBR read perf/x86/intel/lbr: Support XSAVES/XRSTORS for LBR context switch x86/fpu/xstate: Add helpers for LBR dynamic supervisor feature x86/fpu/xstate: Support dynamic supervisor feature for LBR x86/fpu: Use proper mask to replace full instruction mask perf/x86: Remove task_ctx_size perf/x86/intel/lbr: Create kmem_cache for the LBR context data perf/core: Use kmem_cache to allocate the PMU specific data perf/core: Factor out functions to allocate/free the task_ctx_data perf/x86/intel/lbr: Support Architectural LBR perf/x86/intel/lbr: Factor out intel_pmu_store_lbr perf/x86/intel/lbr: Factor out rdlbr_all() and wrlbr_all() perf/x86/intel/lbr: Mark the {rd,wr}lbr_{to,from} wrappers __always_inline perf/x86/intel/lbr: Unify the stored format of LBR information perf/x86/intel/lbr: Support LBR_CTL perf/x86: Expose CPUID enumeration bits for arch LBR ...
2 parents 9dee868 + d903b6d commit b34133f

File tree

32 files changed

+1943
-280
lines changed

32 files changed

+1943
-280
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
What: /sys/devices/uncore_iio_x/dieX
2+
Date: February 2020
3+
Contact: Roman Sudarikov <[email protected]>
4+
Description:
5+
Each IIO stack (PCIe root port) has its own IIO PMON block, so
6+
each dieX file (where X is die number) holds "Segment:Root Bus"
7+
for PCIe root port, which can be monitored by that IIO PMON
8+
block.
9+
For example, on 4-die Xeon platform with up to 6 IIO stacks per
10+
die and, therefore, 6 IIO PMON blocks per die, the mapping of
11+
IIO PMON block 0 exposes as the following:
12+
13+
$ ls /sys/devices/uncore_iio_0/die*
14+
-r--r--r-- /sys/devices/uncore_iio_0/die0
15+
-r--r--r-- /sys/devices/uncore_iio_0/die1
16+
-r--r--r-- /sys/devices/uncore_iio_0/die2
17+
-r--r--r-- /sys/devices/uncore_iio_0/die3
18+
19+
$ tail /sys/devices/uncore_iio_0/die*
20+
==> /sys/devices/uncore_iio_0/die0 <==
21+
0000:00
22+
==> /sys/devices/uncore_iio_0/die1 <==
23+
0000:40
24+
==> /sys/devices/uncore_iio_0/die2 <==
25+
0000:80
26+
==> /sys/devices/uncore_iio_0/die3 <==
27+
0000:c0
28+
29+
Which means:
30+
IIO PMU 0 on die 0 belongs to PCI RP on bus 0x00, domain 0x0000
31+
IIO PMU 0 on die 1 belongs to PCI RP on bus 0x40, domain 0x0000
32+
IIO PMU 0 on die 2 belongs to PCI RP on bus 0x80, domain 0x0000
33+
IIO PMU 0 on die 3 belongs to PCI RP on bus 0xc0, domain 0x0000

arch/x86/events/core.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ u64 x86_perf_event_update(struct perf_event *event)
7171
struct hw_perf_event *hwc = &event->hw;
7272
int shift = 64 - x86_pmu.cntval_bits;
7373
u64 prev_raw_count, new_raw_count;
74-
int idx = hwc->idx;
7574
u64 delta;
7675

77-
if (idx == INTEL_PMC_IDX_FIXED_BTS)
76+
if (unlikely(!hwc->event_base))
7877
return 0;
7978

8079
/*
@@ -359,6 +358,7 @@ void x86_release_hardware(void)
359358
if (atomic_dec_and_mutex_lock(&pmc_refcount, &pmc_reserve_mutex)) {
360359
release_pmc_hardware();
361360
release_ds_buffers();
361+
release_lbr_buffers();
362362
mutex_unlock(&pmc_reserve_mutex);
363363
}
364364
}
@@ -1097,22 +1097,31 @@ static inline void x86_assign_hw_event(struct perf_event *event,
10971097
struct cpu_hw_events *cpuc, int i)
10981098
{
10991099
struct hw_perf_event *hwc = &event->hw;
1100+
int idx;
11001101

1101-
hwc->idx = cpuc->assign[i];
1102+
idx = hwc->idx = cpuc->assign[i];
11021103
hwc->last_cpu = smp_processor_id();
11031104
hwc->last_tag = ++cpuc->tags[i];
11041105

1105-
if (hwc->idx == INTEL_PMC_IDX_FIXED_BTS) {
1106+
switch (hwc->idx) {
1107+
case INTEL_PMC_IDX_FIXED_BTS:
1108+
case INTEL_PMC_IDX_FIXED_VLBR:
11061109
hwc->config_base = 0;
11071110
hwc->event_base = 0;
1108-
} else if (hwc->idx >= INTEL_PMC_IDX_FIXED) {
1111+
break;
1112+
1113+
case INTEL_PMC_IDX_FIXED ... INTEL_PMC_IDX_FIXED_BTS-1:
11091114
hwc->config_base = MSR_ARCH_PERFMON_FIXED_CTR_CTRL;
1110-
hwc->event_base = MSR_ARCH_PERFMON_FIXED_CTR0 + (hwc->idx - INTEL_PMC_IDX_FIXED);
1111-
hwc->event_base_rdpmc = (hwc->idx - INTEL_PMC_IDX_FIXED) | 1<<30;
1112-
} else {
1115+
hwc->event_base = MSR_ARCH_PERFMON_FIXED_CTR0 +
1116+
(idx - INTEL_PMC_IDX_FIXED);
1117+
hwc->event_base_rdpmc = (idx - INTEL_PMC_IDX_FIXED) | 1<<30;
1118+
break;
1119+
1120+
default:
11131121
hwc->config_base = x86_pmu_config_addr(hwc->idx);
11141122
hwc->event_base = x86_pmu_event_addr(hwc->idx);
11151123
hwc->event_base_rdpmc = x86_pmu_rdpmc_index(hwc->idx);
1124+
break;
11161125
}
11171126
}
11181127

@@ -1233,7 +1242,7 @@ int x86_perf_event_set_period(struct perf_event *event)
12331242
s64 period = hwc->sample_period;
12341243
int ret = 0, idx = hwc->idx;
12351244

1236-
if (idx == INTEL_PMC_IDX_FIXED_BTS)
1245+
if (unlikely(!hwc->event_base))
12371246
return 0;
12381247

12391248
/*
@@ -2363,7 +2372,6 @@ static struct pmu pmu = {
23632372

23642373
.event_idx = x86_pmu_event_idx,
23652374
.sched_task = x86_pmu_sched_task,
2366-
.task_ctx_size = sizeof(struct x86_perf_task_context),
23672375
.swap_task_ctx = x86_pmu_swap_task_ctx,
23682376
.check_period = x86_pmu_check_period,
23692377

arch/x86/events/intel/core.c

Lines changed: 86 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,8 +2136,35 @@ static inline void intel_pmu_ack_status(u64 ack)
21362136
wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack);
21372137
}
21382138

2139-
static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
2139+
static inline bool event_is_checkpointed(struct perf_event *event)
21402140
{
2141+
return unlikely(event->hw.config & HSW_IN_TX_CHECKPOINTED) != 0;
2142+
}
2143+
2144+
static inline void intel_set_masks(struct perf_event *event, int idx)
2145+
{
2146+
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2147+
2148+
if (event->attr.exclude_host)
2149+
__set_bit(idx, (unsigned long *)&cpuc->intel_ctrl_guest_mask);
2150+
if (event->attr.exclude_guest)
2151+
__set_bit(idx, (unsigned long *)&cpuc->intel_ctrl_host_mask);
2152+
if (event_is_checkpointed(event))
2153+
__set_bit(idx, (unsigned long *)&cpuc->intel_cp_status);
2154+
}
2155+
2156+
static inline void intel_clear_masks(struct perf_event *event, int idx)
2157+
{
2158+
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2159+
2160+
__clear_bit(idx, (unsigned long *)&cpuc->intel_ctrl_guest_mask);
2161+
__clear_bit(idx, (unsigned long *)&cpuc->intel_ctrl_host_mask);
2162+
__clear_bit(idx, (unsigned long *)&cpuc->intel_cp_status);
2163+
}
2164+
2165+
static void intel_pmu_disable_fixed(struct perf_event *event)
2166+
{
2167+
struct hw_perf_event *hwc = &event->hw;
21412168
int idx = hwc->idx - INTEL_PMC_IDX_FIXED;
21422169
u64 ctrl_val, mask;
21432170

@@ -2148,30 +2175,22 @@ static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
21482175
wrmsrl(hwc->config_base, ctrl_val);
21492176
}
21502177

2151-
static inline bool event_is_checkpointed(struct perf_event *event)
2152-
{
2153-
return (event->hw.config & HSW_IN_TX_CHECKPOINTED) != 0;
2154-
}
2155-
21562178
static void intel_pmu_disable_event(struct perf_event *event)
21572179
{
21582180
struct hw_perf_event *hwc = &event->hw;
2159-
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2181+
int idx = hwc->idx;
21602182

2161-
if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) {
2183+
if (idx < INTEL_PMC_IDX_FIXED) {
2184+
intel_clear_masks(event, idx);
2185+
x86_pmu_disable_event(event);
2186+
} else if (idx < INTEL_PMC_IDX_FIXED_BTS) {
2187+
intel_clear_masks(event, idx);
2188+
intel_pmu_disable_fixed(event);
2189+
} else if (idx == INTEL_PMC_IDX_FIXED_BTS) {
21622190
intel_pmu_disable_bts();
21632191
intel_pmu_drain_bts_buffer();
2164-
return;
2165-
}
2166-
2167-
cpuc->intel_ctrl_guest_mask &= ~(1ull << hwc->idx);
2168-
cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx);
2169-
cpuc->intel_cp_status &= ~(1ull << hwc->idx);
2170-
2171-
if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL))
2172-
intel_pmu_disable_fixed(hwc);
2173-
else
2174-
x86_pmu_disable_event(event);
2192+
} else if (idx == INTEL_PMC_IDX_FIXED_VLBR)
2193+
intel_clear_masks(event, idx);
21752194

21762195
/*
21772196
* Needs to be called after x86_pmu_disable_event,
@@ -2238,33 +2257,23 @@ static void intel_pmu_enable_fixed(struct perf_event *event)
22382257
static void intel_pmu_enable_event(struct perf_event *event)
22392258
{
22402259
struct hw_perf_event *hwc = &event->hw;
2241-
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2242-
2243-
if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) {
2244-
if (!__this_cpu_read(cpu_hw_events.enabled))
2245-
return;
2246-
2247-
intel_pmu_enable_bts(hwc->config);
2248-
return;
2249-
}
2250-
2251-
if (event->attr.exclude_host)
2252-
cpuc->intel_ctrl_guest_mask |= (1ull << hwc->idx);
2253-
if (event->attr.exclude_guest)
2254-
cpuc->intel_ctrl_host_mask |= (1ull << hwc->idx);
2255-
2256-
if (unlikely(event_is_checkpointed(event)))
2257-
cpuc->intel_cp_status |= (1ull << hwc->idx);
2260+
int idx = hwc->idx;
22582261

22592262
if (unlikely(event->attr.precise_ip))
22602263
intel_pmu_pebs_enable(event);
22612264

2262-
if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
2265+
if (idx < INTEL_PMC_IDX_FIXED) {
2266+
intel_set_masks(event, idx);
2267+
__x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
2268+
} else if (idx < INTEL_PMC_IDX_FIXED_BTS) {
2269+
intel_set_masks(event, idx);
22632270
intel_pmu_enable_fixed(event);
2264-
return;
2265-
}
2266-
2267-
__x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
2271+
} else if (idx == INTEL_PMC_IDX_FIXED_BTS) {
2272+
if (!__this_cpu_read(cpu_hw_events.enabled))
2273+
return;
2274+
intel_pmu_enable_bts(hwc->config);
2275+
} else if (idx == INTEL_PMC_IDX_FIXED_VLBR)
2276+
intel_set_masks(event, idx);
22682277
}
22692278

22702279
static void intel_pmu_add_event(struct perf_event *event)
@@ -2614,6 +2623,20 @@ intel_bts_constraints(struct perf_event *event)
26142623
return NULL;
26152624
}
26162625

2626+
/*
2627+
* Note: matches a fake event, like Fixed2.
2628+
*/
2629+
static struct event_constraint *
2630+
intel_vlbr_constraints(struct perf_event *event)
2631+
{
2632+
struct event_constraint *c = &vlbr_constraint;
2633+
2634+
if (unlikely(constraint_match(c, event->hw.config)))
2635+
return c;
2636+
2637+
return NULL;
2638+
}
2639+
26172640
static int intel_alt_er(int idx, u64 config)
26182641
{
26192642
int alt_idx = idx;
@@ -2804,6 +2827,10 @@ __intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
28042827
{
28052828
struct event_constraint *c;
28062829

2830+
c = intel_vlbr_constraints(event);
2831+
if (c)
2832+
return c;
2833+
28072834
c = intel_bts_constraints(event);
28082835
if (c)
28092836
return c;
@@ -3951,6 +3978,11 @@ static __initconst const struct x86_pmu core_pmu = {
39513978
.cpu_dead = intel_pmu_cpu_dead,
39523979

39533980
.check_period = intel_pmu_check_period,
3981+
3982+
.lbr_reset = intel_pmu_lbr_reset_64,
3983+
.lbr_read = intel_pmu_lbr_read_64,
3984+
.lbr_save = intel_pmu_lbr_save,
3985+
.lbr_restore = intel_pmu_lbr_restore,
39543986
};
39553987

39563988
static __initconst const struct x86_pmu intel_pmu = {
@@ -3996,6 +4028,11 @@ static __initconst const struct x86_pmu intel_pmu = {
39964028
.check_period = intel_pmu_check_period,
39974029

39984030
.aux_output_match = intel_pmu_aux_output_match,
4031+
4032+
.lbr_reset = intel_pmu_lbr_reset_64,
4033+
.lbr_read = intel_pmu_lbr_read_64,
4034+
.lbr_save = intel_pmu_lbr_save,
4035+
.lbr_restore = intel_pmu_lbr_restore,
39994036
};
40004037

40014038
static __init void intel_clovertown_quirk(void)
@@ -4622,6 +4659,14 @@ __init int intel_pmu_init(void)
46224659
x86_pmu.intel_cap.capabilities = capabilities;
46234660
}
46244661

4662+
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) {
4663+
x86_pmu.lbr_reset = intel_pmu_lbr_reset_32;
4664+
x86_pmu.lbr_read = intel_pmu_lbr_read_32;
4665+
}
4666+
4667+
if (boot_cpu_has(X86_FEATURE_ARCH_LBR))
4668+
intel_pmu_arch_lbr_init();
4669+
46254670
intel_ds_init();
46264671

46274672
x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */

arch/x86/events/intel/ds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ static void adaptive_pebs_record_size_update(void)
954954
if (pebs_data_cfg & PEBS_DATACFG_XMMS)
955955
sz += sizeof(struct pebs_xmm);
956956
if (pebs_data_cfg & PEBS_DATACFG_LBRS)
957-
sz += x86_pmu.lbr_nr * sizeof(struct pebs_lbr_entry);
957+
sz += x86_pmu.lbr_nr * sizeof(struct lbr_entry);
958958

959959
cpuc->pebs_record_size = sz;
960960
}
@@ -1595,10 +1595,10 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,
15951595
}
15961596

15971597
if (format_size & PEBS_DATACFG_LBRS) {
1598-
struct pebs_lbr *lbr = next_record;
1598+
struct lbr_entry *lbr = next_record;
15991599
int num_lbr = ((format_size >> PEBS_DATACFG_LBR_SHIFT)
16001600
& 0xff) + 1;
1601-
next_record = next_record + num_lbr*sizeof(struct pebs_lbr_entry);
1601+
next_record = next_record + num_lbr * sizeof(struct lbr_entry);
16021602

16031603
if (has_branch_stack(event)) {
16041604
intel_pmu_store_pebs_lbrs(lbr);

0 commit comments

Comments
 (0)