History

Merge tag 'perf-core-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf events updates from Ingo Molnar: "Core & generic-arch updates: - Add support for dynamic constraints and propagate it to the Intel driver (Kan Liang) - Fix & enhance driver-specific throttling support (Kan Liang) - Record sample last_period before updating on the x86 and PowerPC platforms (Mark Barnett) - Make perf_pmu_unregister() usable (Peter Zijlstra) - Unify perf_event_free_task() / perf_event_exit_task_context() (Peter Zijlstra) - Simplify perf_event_release_kernel() and perf_event_free_task() (Peter Zijlstra) - Allocate non-contiguous AUX pages by default (Yabin Cui) Uprobes updates: - Add support to emulate NOP instructions (Jiri Olsa) - selftests/bpf: Add 5-byte NOP uprobe trigger benchmark (Jiri Olsa) x86 Intel PMU enhancements: - Support Intel Auto Counter Reload [ACR] (Kan Liang) - Add PMU support for Clearwater Forest (Dapeng Mi) - Arch-PEBS preparatory changes: (Dapeng Mi) - Parse CPUID archPerfmonExt leaves for non-hybrid CPUs - Decouple BTS initialization from PEBS initialization - Introduce pairs of PEBS static calls x86 AMD PMU enhancements: - Use hrtimer for handling overflows in the AMD uncore driver (Sandipan Das) - Prevent UMC counters from saturating (Sandipan Das) Fixes and cleanups: - Fix put_ctx() ordering (Frederic Weisbecker) - Fix irq work dereferencing garbage (Frederic Weisbecker) - Misc fixes and cleanups (Changbin Du, Frederic Weisbecker, Ian Rogers, Ingo Molnar, Kan Liang, Peter Zijlstra, Qing Wang, Sandipan Das, Thorsten Blum)" * tag 'perf-core-2025-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (60 commits) perf/headers: Clean up <linux/perf_event.h> a bit perf/uapi: Clean up <uapi/linux/perf_event.h> a bit perf/uapi: Fix PERF_RECORD_SAMPLE comments in <uapi/linux/perf_event.h> mips/perf: Remove driver-specific throttle support xtensa/perf: Remove driver-specific throttle support sparc/perf: Remove driver-specific throttle support loongarch/perf: Remove driver-specific throttle support csky/perf: Remove driver-specific throttle support arc/perf: Remove driver-specific throttle support alpha/perf: Remove driver-specific throttle support perf/apple_m1: Remove driver-specific throttle support perf/arm: Remove driver-specific throttle support s390/perf: Remove driver-specific throttle support powerpc/perf: Remove driver-specific throttle support perf/x86/zhaoxin: Remove driver-specific throttle support perf/x86/amd: Remove driver-specific throttle support perf/x86/intel: Remove driver-specific throttle support perf: Only dump the throttle log for the leader perf: Fix the throttle logic for a group perf/core: Add the is_event_in_freq_mode() helper to simplify the code ...

Linus Torvalds committed 1 year ago

Commit ddddf9d2 parents eaed94d e7d952c44 files · +1996 −1210Browse files

Unified · Split

44 files
  1. arch/alpha/kernel/perf_event.c +3 −8
  2. arch/arc/kernel/perf_event.c +2 −4
  3. arch/csky/kernel/perf_event.c +1 −2
  4. arch/loongarch/kernel/perf_event.c +1 −2
  5. arch/mips/kernel/perf_event_mipsxx.c +1 −2
  6. arch/powerpc/perf/core-book3s.c +4 −5
  7. arch/powerpc/perf/core-fsl-emb.c +3 −3
  8. arch/s390/kernel/perf_cpum_cf.c +0 −2
  9. arch/s390/kernel/perf_cpum_sf.c +1 −4
  10. arch/sparc/kernel/perf_event.c +1 −2
  11. arch/x86/events/amd/core.c +1 −2
  12. arch/x86/events/amd/ibs.c +1 −3
  13. arch/x86/events/amd/uncore.c +101 −2
  14. arch/x86/events/core.c +25 −12
  15. arch/x86/events/intel/bts.c +77 −73
  16. arch/x86/events/intel/core.c +319 −26
  17. arch/x86/events/intel/ds.c +29 −26
  18. arch/x86/events/intel/knc.c +4 −3
  19. arch/x86/events/intel/lbr.c +1 −1
  20. arch/x86/events/intel/p4.c +1 −2
  21. arch/x86/events/intel/pt.c +2 −0
  22. arch/x86/events/intel/uncore.c +2 −10
  23. arch/x86/events/perf_event.h +43 −2
  24. arch/x86/events/perf_event_flags.h +21 −20
  25. arch/x86/events/zhaoxin/core.c +1 −2
  26. arch/x86/include/asm/msr-index.h +4 −0
  27. arch/x86/include/asm/perf_event.h +1 −0
  28. arch/x86/kernel/uprobes.c +5 −0
  29. arch/xtensa/kernel/perf_event.c +1 −2
  30. drivers/perf/apple_m1_cpu_pmu.c +1 −2
  31. drivers/perf/arm_pmuv3.c +1 −2
  32. drivers/perf/arm_v6_pmu.c +1 −2
  33. drivers/perf/arm_v7_pmu.c +1 −2
  34. drivers/perf/arm_xscale_pmu.c +2 −4
  35. include/linux/cpuhotplug.h +0 −1
  36. include/linux/perf_event.h +167 −131
  37. include/uapi/linux/perf_event.h +334 −323
  38. kernel/cpu.c +0 −5
  39. kernel/events/core.c +424 −185
  40. kernel/events/ring_buffer.c +20 −9
  41. tools/include/uapi/linux/perf_event.h +334 −323
  42. tools/testing/selftests/bpf/bench.c +12 −0
  43. tools/testing/selftests/bpf/benchs/bench_trigger.c +42 −0
  44. tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh +1 −1
arch/alpha/kernel/perf_event.c+3−8
@@ -852,14 +852,9 @@ static void alpha_perf_event_irq_handler(unsigned long la_ptr, · 851 unmodified lines
852852 alpha_perf_event_update(event, hwc, idx, alpha_pmu->pmc_max_period[idx]+1);
853853 perf_sample_data_init(&data, 0, hwc->last_period);
854854
855− if (alpha_perf_event_set_period(event, hwc, idx)) {
856− if (perf_event_overflow(event, &data, regs)) {
857− /* Interrupts coming too quickly; "throttle" the
858− * counter, i.e., disable it for a little while.
859− */
860− alpha_pmu_stop(event, 0);
861− }
862− }
855+ if (alpha_perf_event_set_period(event, hwc, idx))
856+ perf_event_overflow(event, &data, regs);
857+
863858 wrperfmon(PERFMON_CMD_ENABLE, cpuc->idx_mask);
864859
865860 return;
arch/arc/kernel/perf_event.c+2−4
@@ -599,10 +599,8 @@ static irqreturn_t arc_pmu_intr(int irq, void *dev) · 598 unmodified lines
599599
600600 arc_perf_event_update(event, &event->hw, event->hw.idx);
601601 perf_sample_data_init(&data, 0, hwc->last_period);
602− if (arc_pmu_event_set_period(event)) {
603− if (perf_event_overflow(event, &data, regs))
604− arc_pmu_stop(event, 0);
605− }
602+ if (arc_pmu_event_set_period(event))
603+ perf_event_overflow(event, &data, regs);
606604
607605 active_ints &= ~BIT(idx);
608606 } while (active_ints);
arch/csky/kernel/perf_event.c+1−2
@@ -1139,8 +1139,7 @@ static irqreturn_t csky_pmu_handle_irq(int irq_num, void *dev) · 1138 unmodified lines
11391139 perf_sample_data_init(&data, 0, hwc->last_period);
11401140 csky_pmu_event_set_period(event);
11411141
1142− if (perf_event_overflow(event, &data, regs))
1143− csky_pmu_stop_event(event);
1142+ perf_event_overflow(event, &data, regs);
11441143 }
11451144
11461145 csky_pmu_enable(&csky_pmu.pmu);
arch/loongarch/kernel/perf_event.c+1−2
@@ -479,8 +479,7 @@ static void handle_associated_event(struct cpu_hw_events *cpuc, int idx, · 478 unmodified lines
479479 if (!loongarch_pmu_event_set_period(event, hwc, idx))
480480 return;
481481
482− if (perf_event_overflow(event, data, regs))
483− loongarch_pmu_disable_event(idx);
482+ perf_event_overflow(event, data, regs);
484483 }
485484
486485 static irqreturn_t pmu_handle_irq(int irq, void *dev)
arch/mips/kernel/perf_event_mipsxx.c+1−2
@@ -791,8 +791,7 @@ static void handle_associated_event(struct cpu_hw_events *cpuc, · 790 unmodified lines
791791 if (!mipspmu_event_set_period(event, hwc, idx))
792792 return;
793793
794− if (perf_event_overflow(event, data, regs))
795− mipsxx_pmu_disable_event(idx);
794+ perf_event_overflow(event, data, regs);
796795 }
797796
798797
arch/powerpc/perf/core-book3s.c+4−5
@@ -2239,6 +2239,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 2238 unmodified lines
22392239 struct pt_regs *regs)
22402240 {
22412241 u64 period = event->hw.sample_period;
2242+ const u64 last_period = event->hw.last_period;
22422243 s64 prev, delta, left;
22432244 int record = 0;
22442245
@@ -2320,7 +2321,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 75 unmodified lines
23202321 if (record) {
23212322 struct perf_sample_data data;
23222323
2323− perf_sample_data_init(&data, ~0ULL, event->hw.last_period);
2324+ perf_sample_data_init(&data, ~0ULL, last_period);
23242325
23252326 if (event->attr.sample_type & PERF_SAMPLE_ADDR_TYPE)
23262327 perf_get_data_addr(event, regs, &data.addr);
@@ -2343,12 +2344,10 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 16 unmodified lines
23432344 ppmu->get_mem_weight(&data.weight.full, event->attr.sample_type);
23442345 data.sample_flags |= PERF_SAMPLE_WEIGHT_TYPE;
23452346 }
2346− if (perf_event_overflow(event, &data, regs))
2347− power_pmu_stop(event, 0);
2347+ perf_event_overflow(event, &data, regs);
23482348 } else if (period) {
23492349 /* Account for interrupt in case of invalid SIAR */
2350− if (perf_event_account_interrupt(event))
2351− power_pmu_stop(event, 0);
2350+ perf_event_account_interrupt(event);
23522351 }
23532352 }
23542353
arch/powerpc/perf/core-fsl-emb.c+3−3
@@ -590,6 +590,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 589 unmodified lines
590590 struct pt_regs *regs)
591591 {
592592 u64 period = event->hw.sample_period;
593+ const u64 last_period = event->hw.last_period;
593594 s64 prev, delta, left;
594595 int record = 0;
595596
@@ -632,10 +633,9 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 36 unmodified lines
632633 if (record) {
633634 struct perf_sample_data data;
634635
635− perf_sample_data_init(&data, 0, event->hw.last_period);
636+ perf_sample_data_init(&data, 0, last_period);
636637
637− if (perf_event_overflow(event, &data, regs))
638− fsl_emb_pmu_stop(event, 0);
638+ perf_event_overflow(event, &data, regs);
639639 }
640640 }
641641
arch/s390/kernel/perf_cpum_cf.c+0−2
@@ -980,8 +980,6 @@ static int cfdiag_push_sample(struct perf_event *event, · 979 unmodified lines
980980 }
981981
982982 overflow = perf_event_overflow(event, &data, &regs);
983− if (overflow)
984− event->pmu->stop(event, 0);
985983
986984 perf_event_update_userpage(event);
987985 return overflow;
arch/s390/kernel/perf_cpum_sf.c+1−4
@@ -1072,10 +1072,7 @@ static int perf_push_sample(struct perf_event *event, · 1071 unmodified lines
10721072 overflow = 0;
10731073 if (perf_event_exclude(event, &regs, sde_regs))
10741074 goto out;
1075− if (perf_event_overflow(event, &data, &regs)) {
1076− overflow = 1;
1077− event->pmu->stop(event, 0);
1078− }
1075+ overflow = perf_event_overflow(event, &data, &regs);
10791076 perf_event_update_userpage(event);
10801077 out:
10811078 return overflow;
arch/sparc/kernel/perf_event.c+1−2
@@ -1668,8 +1668,7 @@ static int __kprobes perf_event_nmi_handler(struct notifier_block *self, · 1667 unmodified lines
16681668 if (!sparc_perf_event_set_period(event, hwc, idx))
16691669 continue;
16701670
1671− if (perf_event_overflow(event, &data, regs))
1672− sparc_pmu_stop(event, 0);
1671+ perf_event_overflow(event, &data, regs);
16731672 }
16741673
16751674 finish_clock = sched_clock();
arch/x86/events/amd/core.c+1−2
@@ -1003,8 +1003,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs) · 1002 unmodified lines
10031003
10041004 perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
10051005
1006− if (perf_event_overflow(event, &data, regs))
1007− x86_pmu_stop(event, 0);
1006+ perf_event_overflow(event, &data, regs);
10081007 }
10091008
10101009 /*
arch/x86/events/amd/ibs.c+1−3
@@ -1373,9 +1373,7 @@ fail: · 1372 unmodified lines
13731373 hwc->sample_period = perf_ibs->min_period;
13741374
13751375 out:
1376− if (throttle) {
1377− perf_ibs_stop(event, 0);
1378− } else {
1376+ if (!throttle) {
13791377 if (perf_ibs == &perf_ibs_op) {
13801378 if (ibs_caps & IBS_CAPS_OPCNTEXT) {
13811379 new_config = period & IBS_OP_MAX_CNT_EXT_MASK;
arch/x86/events/amd/uncore.c+101−2
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #define NUM_COUNTERS_NB 4
2222 #define NUM_COUNTERS_L2 4
2323 #define NUM_COUNTERS_L3 6
24+#define NUM_COUNTERS_MAX 64
2425
2526 #define RDPMC_BASE_NB 6
2627 #define RDPMC_BASE_LLC 10
@@ -38,7 +39,10 @@ struct amd_uncore_ctx { · 11 unmodified lines
3839 int refcnt;
3940 int cpu;
4041 struct perf_event **events;
41− struct hlist_node node;
42+ unsigned long active_mask[BITS_TO_LONGS(NUM_COUNTERS_MAX)];
43+ int nr_active;
44+ struct hrtimer hrtimer;
45+ u64 hrtimer_duration;
4246 };
4347
4448 struct amd_uncore_pmu {
@@ -83,11 +87,51 @@ struct amd_uncore { · 38 unmodified lines
8387
8488 static struct amd_uncore uncores[UNCORE_TYPE_MAX];
8589
90+/* Interval for hrtimer, defaults to 60000 milliseconds */
91+static unsigned int update_interval = 60 * MSEC_PER_SEC;
92+module_param(update_interval, uint, 0444);
93+
8694 static struct amd_uncore_pmu *event_to_amd_uncore_pmu(struct perf_event *event)
8795 {
8896 return container_of(event->pmu, struct amd_uncore_pmu, pmu);
8997 }
9098
99+static enum hrtimer_restart amd_uncore_hrtimer(struct hrtimer *hrtimer)
100+{
101+ struct amd_uncore_ctx *ctx;
102+ struct perf_event *event;
103+ int bit;
104+
105+ ctx = container_of(hrtimer, struct amd_uncore_ctx, hrtimer);
106+
107+ if (!ctx->nr_active || ctx->cpu != smp_processor_id())
108+ return HRTIMER_NORESTART;
109+
110+ for_each_set_bit(bit, ctx->active_mask, NUM_COUNTERS_MAX) {
111+ event = ctx->events[bit];
112+ event->pmu->read(event);
113+ }
114+
115+ hrtimer_forward_now(hrtimer, ns_to_ktime(ctx->hrtimer_duration));
116+ return HRTIMER_RESTART;
117+}
118+
119+static void amd_uncore_start_hrtimer(struct amd_uncore_ctx *ctx)
120+{
121+ hrtimer_start(&ctx->hrtimer, ns_to_ktime(ctx->hrtimer_duration),
122+ HRTIMER_MODE_REL_PINNED_HARD);
123+}
124+
125+static void amd_uncore_cancel_hrtimer(struct amd_uncore_ctx *ctx)
126+{
127+ hrtimer_cancel(&ctx->hrtimer);
128+}
129+
130+static void amd_uncore_init_hrtimer(struct amd_uncore_ctx *ctx)
131+{
132+ hrtimer_setup(&ctx->hrtimer, amd_uncore_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
133+}
134+
91135 static void amd_uncore_read(struct perf_event *event)
92136 {
93137 struct hw_perf_event *hwc = &event->hw;
@@ -118,18 +162,26 @@ static void amd_uncore_read(struct perf_event *event) · 24 unmodified lines
118162
119163 static void amd_uncore_start(struct perf_event *event, int flags)
120164 {
165+ struct amd_uncore_pmu *pmu = event_to_amd_uncore_pmu(event);
166+ struct amd_uncore_ctx *ctx = *per_cpu_ptr(pmu->ctx, event->cpu);
121167 struct hw_perf_event *hwc = &event->hw;
122168
169+ if (!ctx->nr_active++)
170+ amd_uncore_start_hrtimer(ctx);
171+
123172 if (flags & PERF_EF_RELOAD)
124173 wrmsrl(hwc->event_base, (u64)local64_read(&hwc->prev_count));
125174
126175 hwc->state = 0;
176+ __set_bit(hwc->idx, ctx->active_mask);
127177 wrmsrl(hwc->config_base, (hwc->config | ARCH_PERFMON_EVENTSEL_ENABLE));
128178 perf_event_update_userpage(event);
129179 }
130180
131181 static void amd_uncore_stop(struct perf_event *event, int flags)
132182 {
183+ struct amd_uncore_pmu *pmu = event_to_amd_uncore_pmu(event);
184+ struct amd_uncore_ctx *ctx = *per_cpu_ptr(pmu->ctx, event->cpu);
133185 struct hw_perf_event *hwc = &event->hw;
134186
135187 wrmsrl(hwc->config_base, hwc->config);
@@ -139,6 +191,11 @@ static void amd_uncore_stop(struct perf_event *event, int flags) · 3 unmodified lines
139191 event->pmu->read(event);
140192 hwc->state |= PERF_HES_UPTODATE;
141193 }
194+
195+ if (!--ctx->nr_active)
196+ amd_uncore_cancel_hrtimer(ctx);
197+
198+ __clear_bit(hwc->idx, ctx->active_mask);
142199 }
143200
144201 static int amd_uncore_add(struct perf_event *event, int flags)
@@ -491,6 +548,9 @@ static int amd_uncore_ctx_init(struct amd_uncore *uncore, unsigned int cpu) · 346 unmodified lines
491548 goto fail;
492549 }
493550
551+ amd_uncore_init_hrtimer(curr);
552+ curr->hrtimer_duration = (u64)update_interval * NSEC_PER_MSEC;
553+
494554 cpumask_set_cpu(cpu, &pmu->active_mask);
495555 }
496556
@@ -880,16 +940,55 @@ static int amd_uncore_umc_event_init(struct perf_event *event) · 383 unmodified lines
880940
881941 static void amd_uncore_umc_start(struct perf_event *event, int flags)
882942 {
943+ struct amd_uncore_pmu *pmu = event_to_amd_uncore_pmu(event);
944+ struct amd_uncore_ctx *ctx = *per_cpu_ptr(pmu->ctx, event->cpu);
883945 struct hw_perf_event *hwc = &event->hw;
884946
947+ if (!ctx->nr_active++)
948+ amd_uncore_start_hrtimer(ctx);
949+
885950 if (flags & PERF_EF_RELOAD)
886951 wrmsrl(hwc->event_base, (u64)local64_read(&hwc->prev_count));
887952
888953 hwc->state = 0;
954+ __set_bit(hwc->idx, ctx->active_mask);
889955 wrmsrl(hwc->config_base, (hwc->config | AMD64_PERFMON_V2_ENABLE_UMC));
890956 perf_event_update_userpage(event);
891957 }
892958
959+static void amd_uncore_umc_read(struct perf_event *event)
960+{
961+ struct hw_perf_event *hwc = &event->hw;
962+ u64 prev, new, shift;
963+ s64 delta;
964+
965+ shift = COUNTER_SHIFT + 1;
966+ prev = local64_read(&hwc->prev_count);
967+
968+ /*
969+ * UMC counters do not have RDPMC assignments. Read counts directly
970+ * from the corresponding PERF_CTR.
971+ */
972+ rdmsrl(hwc->event_base, new);
973+
974+ /*
975+ * Unlike the other uncore counters, UMC counters saturate and set the
976+ * Overflow bit (bit 48) on overflow. Since they do not roll over,
977+ * proactively reset the corresponding PERF_CTR when bit 47 is set so
978+ * that the counter never gets a chance to saturate.
979+ */
980+ if (new & BIT_ULL(63 - COUNTER_SHIFT)) {
981+ wrmsrl(hwc->event_base, 0);
982+ local64_set(&hwc->prev_count, 0);
983+ } else {
984+ local64_set(&hwc->prev_count, new);
985+ }
986+
987+ delta = (new << shift) - (prev << shift);
988+ delta >>= shift;
989+ local64_add(delta, &event->count);
990+}
991+
893992 static
894993 void amd_uncore_umc_ctx_scan(struct amd_uncore *uncore, unsigned int cpu)
895994 {
@@ -968,7 +1067,7 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu) · 72 unmodified lines
9681067 .del = amd_uncore_del,
9691068 .start = amd_uncore_umc_start,
9701069 .stop = amd_uncore_stop,
971− .read = amd_uncore_read,
1070+ .read = amd_uncore_umc_read,
9721071 .capabilities = PERF_PMU_CAP_NO_EXCLUDE | PERF_PMU_CAP_NO_INTERRUPT,
9731072 .module = THIS_MODULE,
9741073 };
arch/x86/events/core.c+25−12
@@ -95,6 +95,11 @@ DEFINE_STATIC_CALL_NULL(x86_pmu_filter, *x86_pmu.filter); · 94 unmodified lines
9595
9696 DEFINE_STATIC_CALL_NULL(x86_pmu_late_setup, *x86_pmu.late_setup);
9797
98+DEFINE_STATIC_CALL_NULL(x86_pmu_pebs_enable, *x86_pmu.pebs_enable);
99+DEFINE_STATIC_CALL_NULL(x86_pmu_pebs_disable, *x86_pmu.pebs_disable);
100+DEFINE_STATIC_CALL_NULL(x86_pmu_pebs_enable_all, *x86_pmu.pebs_enable_all);
101+DEFINE_STATIC_CALL_NULL(x86_pmu_pebs_disable_all, *x86_pmu.pebs_disable_all);
102+
98103 /*
99104 * This one is magic, it will get called even when PMU init fails (because
100105 * there is no PMU), in which case it should simply return NULL.
@@ -674,6 +679,7 @@ static int __x86_pmu_event_init(struct perf_event *event) · 573 unmodified lines
674679 event->hw.idx = -1;
675680 event->hw.last_cpu = -1;
676681 event->hw.last_tag = ~0ULL;
682+ event->hw.dyn_constraint = ~0ULL;
677683
678684 /* mark unused */
679685 event->hw.extra_reg.idx = EXTRA_REG_NONE;
@@ -756,15 +762,16 @@ void x86_pmu_enable_all(int added) · 76 unmodified lines
756762
757763 int is_x86_event(struct perf_event *event)
758764 {
759− int i;
760−
761− if (!is_hybrid())
762− return event->pmu == &pmu;
763−
764− for (i = 0; i < x86_pmu.num_hybrid_pmus; i++) {
765− if (event->pmu == &x86_pmu.hybrid_pmu[i].pmu)
766− return true;
767− }
765+ /*
766+ * For a non-hybrid platforms, the type of X86 pmu is
767+ * always PERF_TYPE_RAW.
768+ * For a hybrid platform, the PERF_PMU_CAP_EXTENDED_HW_TYPE
769+ * is a unique capability for the X86 PMU.
770+ * Use them to detect a X86 event.
771+ */
772+ if (event->pmu->type == PERF_TYPE_RAW ||
773+ event->pmu->capabilities & PERF_PMU_CAP_EXTENDED_HW_TYPE)
774+ return true;
768775
769776 return false;
770777 }
@@ -1683,6 +1690,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) · 912 unmodified lines
16831690 struct cpu_hw_events *cpuc;
16841691 struct perf_event *event;
16851692 int idx, handled = 0;
1693+ u64 last_period;
16861694 u64 val;
16871695
16881696 cpuc = this_cpu_ptr(&cpu_hw_events);
@@ -1702,6 +1710,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) · 13 unmodified lines
17021710 continue;
17031711
17041712 event = cpuc->events[idx];
1713+ last_period = event->hw.last_period;
17051714
17061715 val = static_call(x86_pmu_update)(event);
17071716 if (val & (1ULL << (x86_pmu.cntval_bits - 1)))
@@ -1715,12 +1724,11 @@ int x86_pmu_handle_irq(struct pt_regs *regs) · 7 unmodified lines
17151724 if (!static_call(x86_pmu_set_period)(event))
17161725 continue;
17171726
1718− perf_sample_data_init(&data, 0, event->hw.last_period);
1727+ perf_sample_data_init(&data, 0, last_period);
17191728
17201729 perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
17211730
1722− if (perf_event_overflow(event, &data, regs))
1723− x86_pmu_stop(event, 0);
1731+ perf_event_overflow(event, &data, regs);
17241732 }
17251733
17261734 if (handled)
@@ -2046,6 +2054,11 @@ static void x86_pmu_static_call_update(void) · 319 unmodified lines
20462054 static_call_update(x86_pmu_filter, x86_pmu.filter);
20472055
20482056 static_call_update(x86_pmu_late_setup, x86_pmu.late_setup);
2057+
2058+ static_call_update(x86_pmu_pebs_enable, x86_pmu.pebs_enable);
2059+ static_call_update(x86_pmu_pebs_disable, x86_pmu.pebs_disable);
2060+ static_call_update(x86_pmu_pebs_enable_all, x86_pmu.pebs_enable_all);
2061+ static_call_update(x86_pmu_pebs_disable_all, x86_pmu.pebs_disable_all);
20492062 }
20502063
20512064 static void _x86_pmu_read(struct perf_event *event)
arch/x86/events/intel/bts.c+77−73
@@ -80,54 +80,54 @@ static void * · 79 unmodified lines
8080 bts_buffer_setup_aux(struct perf_event *event, void **pages,
8181 int nr_pages, bool overwrite)
8282 {
83− struct bts_buffer *buf;
83+ struct bts_buffer *bb;
8484 struct page *page;
8585 int cpu = event->cpu;
8686 int node = (cpu == -1) ? cpu : cpu_to_node(cpu);
8787 unsigned long offset;
8888 size_t size = nr_pages << PAGE_SHIFT;
89− int pg, nbuf, pad;
89+ int pg, nr_buf, pad;
9090
9191 /* count all the high order buffers */
92− for (pg = 0, nbuf = 0; pg < nr_pages;) {
92+ for (pg = 0, nr_buf = 0; pg < nr_pages;) {
9393 page = virt_to_page(pages[pg]);
9494 pg += buf_nr_pages(page);
95− nbuf++;
95+ nr_buf++;
9696 }
9797
9898 /*
9999 * to avoid interrupts in overwrite mode, only allow one physical
100100 */
101− if (overwrite && nbuf > 1)
101+ if (overwrite && nr_buf > 1)
102102 return NULL;
103103
104− buf = kzalloc_node(offsetof(struct bts_buffer, buf[nbuf]), GFP_KERNEL, node);
105− if (!buf)
104+ bb = kzalloc_node(struct_size(bb, buf, nr_buf), GFP_KERNEL, node);
105+ if (!bb)
106106 return NULL;
107107
108− buf->nr_pages = nr_pages;
109− buf->nr_bufs = nbuf;
110− buf->snapshot = overwrite;
111− buf->data_pages = pages;
112− buf->real_size = size - size % BTS_RECORD_SIZE;
108+ bb->nr_pages = nr_pages;
109+ bb->nr_bufs = nr_buf;
110+ bb->snapshot = overwrite;
111+ bb->data_pages = pages;
112+ bb->real_size = size - size % BTS_RECORD_SIZE;
113113
114− for (pg = 0, nbuf = 0, offset = 0, pad = 0; nbuf < buf->nr_bufs; nbuf++) {
114+ for (pg = 0, nr_buf = 0, offset = 0, pad = 0; nr_buf < bb->nr_bufs; nr_buf++) {
115115 unsigned int __nr_pages;
116116
117117 page = virt_to_page(pages[pg]);
118118 __nr_pages = buf_nr_pages(page);
119− buf->buf[nbuf].page = page;
120− buf->buf[nbuf].offset = offset;
121− buf->buf[nbuf].displacement = (pad ? BTS_RECORD_SIZE - pad : 0);
122− buf->buf[nbuf].size = buf_size(page) - buf->buf[nbuf].displacement;
123− pad = buf->buf[nbuf].size % BTS_RECORD_SIZE;
124− buf->buf[nbuf].size -= pad;
119+ bb->buf[nr_buf].page = page;
120+ bb->buf[nr_buf].offset = offset;
121+ bb->buf[nr_buf].displacement = (pad ? BTS_RECORD_SIZE - pad : 0);
122+ bb->buf[nr_buf].size = buf_size(page) - bb->buf[nr_buf].displacement;
123+ pad = bb->buf[nr_buf].size % BTS_RECORD_SIZE;
124+ bb->buf[nr_buf].size -= pad;
125125
126126 pg += __nr_pages;
127127 offset += __nr_pages << PAGE_SHIFT;
128128 }
129129
130− return buf;
130+ return bb;
131131 }
132132
133133 static void bts_buffer_free_aux(void *data)
@@ -135,25 +135,25 @@ static void bts_buffer_free_aux(void *data) · 1 unmodified line
135135 kfree(data);
136136 }
137137
138−static unsigned long bts_buffer_offset(struct bts_buffer *buf, unsigned int idx)
138+static unsigned long bts_buffer_offset(struct bts_buffer *bb, unsigned int idx)
139139 {
140− return buf->buf[idx].offset + buf->buf[idx].displacement;
140+ return bb->buf[idx].offset + bb->buf[idx].displacement;
141141 }
142142
143143 static void
144−bts_config_buffer(struct bts_buffer *buf)
144+bts_config_buffer(struct bts_buffer *bb)
145145 {
146146 int cpu = raw_smp_processor_id();
147147 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
148− struct bts_phys *phys = &buf->buf[buf->cur_buf];
148+ struct bts_phys *phys = &bb->buf[bb->cur_buf];
149149 unsigned long index, thresh = 0, end = phys->size;
150150 struct page *page = phys->page;
151151
152− index = local_read(&buf->head);
152+ index = local_read(&bb->head);
153153
154− if (!buf->snapshot) {
155− if (buf->end < phys->offset + buf_size(page))
156− end = buf->end - phys->offset - phys->displacement;
154+ if (!bb->snapshot) {
155+ if (bb->end < phys->offset + buf_size(page))
156+ end = bb->end - phys->offset - phys->displacement;
157157
158158 index -= phys->offset + phys->displacement;
159159
@@ -168,7 +168,7 @@ bts_config_buffer(struct bts_buffer *buf) · 8 unmodified lines
168168 ds->bts_buffer_base = (u64)(long)page_address(page) + phys->displacement;
169169 ds->bts_index = ds->bts_buffer_base + index;
170170 ds->bts_absolute_maximum = ds->bts_buffer_base + end;
171− ds->bts_interrupt_threshold = !buf->snapshot
171+ ds->bts_interrupt_threshold = !bb->snapshot
172172 ? ds->bts_buffer_base + thresh
173173 : ds->bts_absolute_maximum + BTS_RECORD_SIZE;
174174 }
@@ -184,16 +184,16 @@ static void bts_update(struct bts_ctx *bts) · 9 unmodified lines
184184 {
185185 int cpu = raw_smp_processor_id();
186186 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
187− struct bts_buffer *buf = perf_get_aux(&bts->handle);
187+ struct bts_buffer *bb = perf_get_aux(&bts->handle);
188188 unsigned long index = ds->bts_index - ds->bts_buffer_base, old, head;
189189
190− if (!buf)
190+ if (!bb)
191191 return;
192192
193− head = index + bts_buffer_offset(buf, buf->cur_buf);
194− old = local_xchg(&buf->head, head);
193+ head = index + bts_buffer_offset(bb, bb->cur_buf);
194+ old = local_xchg(&bb->head, head);
195195
196− if (!buf->snapshot) {
196+ if (!bb->snapshot) {
197197 if (old == head)
198198 return;
199199
@@ -205,9 +205,9 @@ static void bts_update(struct bts_ctx *bts) · 5 unmodified lines
205205 * old and head are always in the same physical buffer, so we
206206 * can subtract them to get the data size.
207207 */
208− local_add(head - old, &buf->data_size);
208+ local_add(head - old, &bb->data_size);
209209 } else {
210− local_set(&buf->data_size, head);
210+ local_set(&bb->data_size, head);
211211 }
212212
213213 /*
@@ -218,7 +218,7 @@ static void bts_update(struct bts_ctx *bts) · 4 unmodified lines
218218 }
219219
220220 static int
221−bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle);
221+bts_buffer_reset(struct bts_buffer *bb, struct perf_output_handle *handle);
222222
223223 /*
224224 * Ordering PMU callbacks wrt themselves and the PMI is done by means
@@ -232,17 +232,17 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle); · 7 unmodified lines
232232 static void __bts_event_start(struct perf_event *event)
233233 {
234234 struct bts_ctx *bts = this_cpu_ptr(bts_ctx);
235− struct bts_buffer *buf = perf_get_aux(&bts->handle);
235+ struct bts_buffer *bb = perf_get_aux(&bts->handle);
236236 u64 config = 0;
237237
238− if (!buf->snapshot)
238+ if (!bb->snapshot)
239239 config |= ARCH_PERFMON_EVENTSEL_INT;
240240 if (!event->attr.exclude_kernel)
241241 config |= ARCH_PERFMON_EVENTSEL_OS;
242242 if (!event->attr.exclude_user)
243243 config |= ARCH_PERFMON_EVENTSEL_USR;
244244
245− bts_config_buffer(buf);
245+ bts_config_buffer(bb);
246246
247247 /*
248248 * local barrier to make sure that ds configuration made it
@@ -261,13 +261,13 @@ static void bts_event_start(struct perf_event *event, int flags) · 12 unmodified lines
261261 {
262262 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
263263 struct bts_ctx *bts = this_cpu_ptr(bts_ctx);
264− struct bts_buffer *buf;
264+ struct bts_buffer *bb;
265265
266− buf = perf_aux_output_begin(&bts->handle, event);
267− if (!buf)
266+ bb = perf_aux_output_begin(&bts->handle, event);
267+ if (!bb)
268268 goto fail_stop;
269269
270− if (bts_buffer_reset(buf, &bts->handle))
270+ if (bts_buffer_reset(bb, &bts->handle))
271271 goto fail_end_stop;
272272
273273 bts->ds_back.bts_buffer_base = cpuc->ds->bts_buffer_base;
@@ -306,27 +306,27 @@ static void bts_event_stop(struct perf_event *event, int flags) · 32 unmodified lines
306306 {
307307 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
308308 struct bts_ctx *bts = this_cpu_ptr(bts_ctx);
309− struct bts_buffer *buf = NULL;
309+ struct bts_buffer *bb = NULL;
310310 int state = READ_ONCE(bts->state);
311311
312312 if (state == BTS_STATE_ACTIVE)
313313 __bts_event_stop(event, BTS_STATE_STOPPED);
314314
315315 if (state != BTS_STATE_STOPPED)
316− buf = perf_get_aux(&bts->handle);
316+ bb = perf_get_aux(&bts->handle);
317317
318318 event->hw.state |= PERF_HES_STOPPED;
319319
320320 if (flags & PERF_EF_UPDATE) {
321321 bts_update(bts);
322322
323− if (buf) {
324− if (buf->snapshot)
323+ if (bb) {
324+ if (bb->snapshot)
325325 bts->handle.head =
326− local_xchg(&buf->data_size,
327− buf->nr_pages << PAGE_SHIFT);
326+ local_xchg(&bb->data_size,
327+ bb->nr_pages << PAGE_SHIFT);
328328 perf_aux_output_end(&bts->handle,
329− local_xchg(&buf->data_size, 0));
329+ local_xchg(&bb->data_size, 0));
330330 }
331331
332332 cpuc->ds->bts_index = bts->ds_back.bts_buffer_base;
@@ -382,19 +382,19 @@ void intel_bts_disable_local(void) · 49 unmodified lines
382382 }
383383
384384 static int
385−bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle)
385+bts_buffer_reset(struct bts_buffer *bb, struct perf_output_handle *handle)
386386 {
387387 unsigned long head, space, next_space, pad, gap, skip, wakeup;
388388 unsigned int next_buf;
389389 struct bts_phys *phys, *next_phys;
390390 int ret;
391391
392− if (buf->snapshot)
392+ if (bb->snapshot)
393393 return 0;
394394
395− head = handle->head & ((buf->nr_pages << PAGE_SHIFT) - 1);
395+ head = handle->head & ((bb->nr_pages << PAGE_SHIFT) - 1);
396396
397− phys = &buf->buf[buf->cur_buf];
397+ phys = &bb->buf[bb->cur_buf];
398398 space = phys->offset + phys->displacement + phys->size - head;
399399 pad = space;
400400 if (space > handle->size) {
@@ -403,10 +403,10 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle) · 2 unmodified lines
403403 }
404404 if (space <= BTS_SAFETY_MARGIN) {
405405 /* See if next phys buffer has more space */
406− next_buf = buf->cur_buf + 1;
407− if (next_buf >= buf->nr_bufs)
406+ next_buf = bb->cur_buf + 1;
407+ if (next_buf >= bb->nr_bufs)
408408 next_buf = 0;
409− next_phys = &buf->buf[next_buf];
409+ next_phys = &bb->buf[next_buf];
410410 gap = buf_size(phys->page) - phys->displacement - phys->size +
411411 next_phys->displacement;
412412 skip = pad + gap;
@@ -431,8 +431,8 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle) · 18 unmodified lines
431431 * anymore, so we must not be racing with
432432 * bts_update().
433433 */
434− buf->cur_buf = next_buf;
435− local_set(&buf->head, head);
434+ bb->cur_buf = next_buf;
435+ local_set(&bb->head, head);
436436 }
437437 }
438438 }
@@ -445,7 +445,7 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle) · 6 unmodified lines
445445 space -= space % BTS_RECORD_SIZE;
446446 }
447447
448− buf->end = head + space;
448+ bb->end = head + space;
449449
450450 /*
451451 * If we have no space, the lost notification would have been sent when
@@ -462,7 +462,7 @@ int intel_bts_interrupt(void) · 10 unmodified lines
462462 struct debug_store *ds = this_cpu_ptr(&cpu_hw_events)->ds;
463463 struct bts_ctx *bts;
464464 struct perf_event *event;
465− struct bts_buffer *buf;
465+ struct bts_buffer *bb;
466466 s64 old_head;
467467 int err = -ENOSPC, handled = 0;
468468
@@ -485,8 +485,8 @@ int intel_bts_interrupt(void) · 16 unmodified lines
485485 if (READ_ONCE(bts->state) == BTS_STATE_STOPPED)
486486 return handled;
487487
488− buf = perf_get_aux(&bts->handle);
489− if (!buf)
488+ bb = perf_get_aux(&bts->handle);
489+ if (!bb)
490490 return handled;
491491
492492 /*
@@ -494,26 +494,26 @@ int intel_bts_interrupt(void) · 1 unmodified line
494494 * there's no other way of telling, because the pointer will
495495 * keep moving
496496 */
497− if (buf->snapshot)
497+ if (bb->snapshot)
498498 return 0;
499499
500− old_head = local_read(&buf->head);
500+ old_head = local_read(&bb->head);
501501 bts_update(bts);
502502
503503 /* no new data */
504− if (old_head == local_read(&buf->head))
504+ if (old_head == local_read(&bb->head))
505505 return handled;
506506
507− perf_aux_output_end(&bts->handle, local_xchg(&buf->data_size, 0));
507+ perf_aux_output_end(&bts->handle, local_xchg(&bb->data_size, 0));
508508
509− buf = perf_aux_output_begin(&bts->handle, event);
510− if (buf)
511− err = bts_buffer_reset(buf, &bts->handle);
509+ bb = perf_aux_output_begin(&bts->handle, event);
510+ if (bb)
511+ err = bts_buffer_reset(bb, &bts->handle);
512512
513513 if (err) {
514514 WRITE_ONCE(bts->state, BTS_STATE_STOPPED);
515515
516− if (buf) {
516+ if (bb) {
517517 /*
518518 * BTS_STATE_STOPPED should be visible before
519519 * cleared handle::event
@@ -599,7 +599,11 @@ static void bts_event_read(struct perf_event *event) · 79 unmodified lines
599599
600600 static __init int bts_init(void)
601601 {
602− if (!boot_cpu_has(X86_FEATURE_DTES64) || !x86_pmu.bts)
602+ if (!boot_cpu_has(X86_FEATURE_DTES64))
603+ return -ENODEV;
604+
605+ x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS);
606+ if (!x86_pmu.bts)
603607 return -ENODEV;
604608
605609 if (boot_cpu_has(X86_FEATURE_PTI)) {
arch/x86/events/intel/core.c+319−26
@@ -2224,6 +2224,18 @@ static struct extra_reg intel_cmt_extra_regs[] __read_mostly = { · 2223 unmodified lines
22242224 EVENT_EXTRA_END
22252225 };
22262226
2227+EVENT_ATTR_STR(topdown-fe-bound, td_fe_bound_skt, "event=0x9c,umask=0x01");
2228+EVENT_ATTR_STR(topdown-retiring, td_retiring_skt, "event=0xc2,umask=0x02");
2229+EVENT_ATTR_STR(topdown-be-bound, td_be_bound_skt, "event=0xa4,umask=0x02");
2230+
2231+static struct attribute *skt_events_attrs[] = {
2232+ EVENT_PTR(td_fe_bound_skt),
2233+ EVENT_PTR(td_retiring_skt),
2234+ EVENT_PTR(td_bad_spec_cmt),
2235+ EVENT_PTR(td_be_bound_skt),
2236+ NULL,
2237+};
2238+
22272239 #define KNL_OT_L2_HITE BIT_ULL(19) /* Other Tile L2 Hit */
22282240 #define KNL_OT_L2_HITF BIT_ULL(20) /* Other Tile L2 Hit */
22292241 #define KNL_MCDRAM_LOCAL BIT_ULL(21)
@@ -2294,7 +2306,7 @@ static __always_inline void __intel_pmu_disable_all(bool bts) · 64 unmodified lines
22942306 static __always_inline void intel_pmu_disable_all(void)
22952307 {
22962308 __intel_pmu_disable_all(true);
2297− intel_pmu_pebs_disable_all();
2309+ static_call_cond(x86_pmu_pebs_disable_all)();
22982310 intel_pmu_lbr_disable_all();
22992311 }
23002312
@@ -2326,7 +2338,7 @@ static void __intel_pmu_enable_all(int added, bool pmi) · 25 unmodified lines
23262338
23272339 static void intel_pmu_enable_all(int added)
23282340 {
2329− intel_pmu_pebs_enable_all();
2341+ static_call_cond(x86_pmu_pebs_enable_all)();
23302342 __intel_pmu_enable_all(added, false);
23312343 }
23322344
@@ -2583,7 +2595,7 @@ static void intel_pmu_disable_event(struct perf_event *event) · 250 unmodified lines
25832595 * so we don't trigger the event without PEBS bit set.
25842596 */
25852597 if (unlikely(event->attr.precise_ip))
2586− intel_pmu_pebs_disable(event);
2598+ static_call(x86_pmu_pebs_disable)(event);
25872599 }
25882600
25892601 static void intel_pmu_assign_event(struct perf_event *event, int idx)
@@ -2603,6 +2615,9 @@ static void intel_pmu_del_event(struct perf_event *event) · 13 unmodified lines
26032615 intel_pmu_lbr_del(event);
26042616 if (event->attr.precise_ip)
26052617 intel_pmu_pebs_del(event);
2618+ if (is_pebs_counter_event_group(event) ||
2619+ is_acr_event_group(event))
2620+ this_cpu_ptr(&cpu_hw_events)->n_late_setup--;
26062621 }
26072622
26082623 static int icl_set_topdown_event_period(struct perf_event *event)
@@ -2880,6 +2895,52 @@ static void intel_pmu_enable_fixed(struct perf_event *event) · 271 unmodified lines
28802895 cpuc->fixed_ctrl_val |= bits;
28812896 }
28822897
2898+static void intel_pmu_config_acr(int idx, u64 mask, u32 reload)
2899+{
2900+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2901+ int msr_b, msr_c;
2902+
2903+ if (!mask && !cpuc->acr_cfg_b[idx])
2904+ return;
2905+
2906+ if (idx < INTEL_PMC_IDX_FIXED) {
2907+ msr_b = MSR_IA32_PMC_V6_GP0_CFG_B;
2908+ msr_c = MSR_IA32_PMC_V6_GP0_CFG_C;
2909+ } else {
2910+ msr_b = MSR_IA32_PMC_V6_FX0_CFG_B;
2911+ msr_c = MSR_IA32_PMC_V6_FX0_CFG_C;
2912+ idx -= INTEL_PMC_IDX_FIXED;
2913+ }
2914+
2915+ if (cpuc->acr_cfg_b[idx] != mask) {
2916+ wrmsrl(msr_b + x86_pmu.addr_offset(idx, false), mask);
2917+ cpuc->acr_cfg_b[idx] = mask;
2918+ }
2919+ /* Only need to update the reload value when there is a valid config value. */
2920+ if (mask && cpuc->acr_cfg_c[idx] != reload) {
2921+ wrmsrl(msr_c + x86_pmu.addr_offset(idx, false), reload);
2922+ cpuc->acr_cfg_c[idx] = reload;
2923+ }
2924+}
2925+
2926+static void intel_pmu_enable_acr(struct perf_event *event)
2927+{
2928+ struct hw_perf_event *hwc = &event->hw;
2929+
2930+ if (!is_acr_event_group(event) || !event->attr.config2) {
2931+ /*
2932+ * The disable doesn't clear the ACR CFG register.
2933+ * Check and clear the ACR CFG register.
2934+ */
2935+ intel_pmu_config_acr(hwc->idx, 0, 0);
2936+ return;
2937+ }
2938+
2939+ intel_pmu_config_acr(hwc->idx, hwc->config1, -hwc->sample_period);
2940+}
2941+
2942+DEFINE_STATIC_CALL_NULL(intel_pmu_enable_acr_event, intel_pmu_enable_acr);
2943+
28832944 static void intel_pmu_enable_event(struct perf_event *event)
28842945 {
28852946 u64 enable_mask = ARCH_PERFMON_EVENTSEL_ENABLE;
@@ -2887,16 +2948,19 @@ static void intel_pmu_enable_event(struct perf_event *event) · 1 unmodified line
28872948 int idx = hwc->idx;
28882949
28892950 if (unlikely(event->attr.precise_ip))
2890− intel_pmu_pebs_enable(event);
2951+ static_call(x86_pmu_pebs_enable)(event);
28912952
28922953 switch (idx) {
28932954 case 0 ... INTEL_PMC_IDX_FIXED - 1:
28942955 if (branch_sample_counters(event))
28952956 enable_mask |= ARCH_PERFMON_EVENTSEL_BR_CNTR;
28962957 intel_set_masks(event, idx);
2958+ static_call_cond(intel_pmu_enable_acr_event)(event);
28972959 __x86_pmu_enable_event(hwc, enable_mask);
28982960 break;
28992961 case INTEL_PMC_IDX_FIXED ... INTEL_PMC_IDX_FIXED_BTS - 1:
2962+ static_call_cond(intel_pmu_enable_acr_event)(event);
2963+ fallthrough;
29002964 case INTEL_PMC_IDX_METRIC_BASE ... INTEL_PMC_IDX_METRIC_END:
29012965 intel_pmu_enable_fixed(event);
29022966 break;
@@ -2914,12 +2978,51 @@ static void intel_pmu_enable_event(struct perf_event *event) · 11 unmodified lines
29142978 }
29152979 }
29162980
2981+static void intel_pmu_acr_late_setup(struct cpu_hw_events *cpuc)
2982+{
2983+ struct perf_event *event, *leader;
2984+ int i, j, idx;
2985+
2986+ for (i = 0; i < cpuc->n_events; i++) {
2987+ leader = cpuc->event_list[i];
2988+ if (!is_acr_event_group(leader))
2989+ continue;
2990+
2991+ /* The ACR events must be contiguous. */
2992+ for (j = i; j < cpuc->n_events; j++) {
2993+ event = cpuc->event_list[j];
2994+ if (event->group_leader != leader->group_leader)
2995+ break;
2996+ for_each_set_bit(idx, (unsigned long *)&event->attr.config2, X86_PMC_IDX_MAX) {
2997+ if (WARN_ON_ONCE(i + idx > cpuc->n_events))
2998+ return;
2999+ __set_bit(cpuc->assign[i + idx], (unsigned long *)&event->hw.config1);
3000+ }
3001+ }
3002+ i = j - 1;
3003+ }
3004+}
3005+
3006+void intel_pmu_late_setup(void)
3007+{
3008+ struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
3009+
3010+ if (!cpuc->n_late_setup)
3011+ return;
3012+
3013+ intel_pmu_pebs_late_setup(cpuc);
3014+ intel_pmu_acr_late_setup(cpuc);
3015+}
3016+
29173017 static void intel_pmu_add_event(struct perf_event *event)
29183018 {
29193019 if (event->attr.precise_ip)
29203020 intel_pmu_pebs_add(event);
29213021 if (intel_pmu_needs_branch_stack(event))
29223022 intel_pmu_lbr_add(event);
3023+ if (is_pebs_counter_event_group(event) ||
3024+ is_acr_event_group(event))
3025+ this_cpu_ptr(&cpu_hw_events)->n_late_setup++;
29233026 }
29243027
29253028 /*
@@ -3035,8 +3138,7 @@ static void x86_pmu_handle_guest_pebs(struct pt_regs *regs, · 109 unmodified lines
30353138 continue;
30363139
30373140 perf_sample_data_init(data, 0, event->hw.last_period);
3038− if (perf_event_overflow(event, data, regs))
3039− x86_pmu_stop(event, 0);
3141+ perf_event_overflow(event, data, regs);
30403142
30413143 /* Inject one fake event is enough. */
30423144 break;
@@ -3141,6 +3243,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) · 98 unmodified lines
31413243
31423244 for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
31433245 struct perf_event *event = cpuc->events[bit];
3246+ u64 last_period;
31443247
31453248 handled++;
31463249
@@ -3168,16 +3271,17 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) · 21 unmodified lines
31683271 if (is_pebs_counter_event_group(event))
31693272 x86_pmu.drain_pebs(regs, &data);
31703273
3274+ last_period = event->hw.last_period;
3275+
31713276 if (!intel_pmu_save_and_restart(event))
31723277 continue;
31733278
3174− perf_sample_data_init(&data, 0, event->hw.last_period);
3279+ perf_sample_data_init(&data, 0, last_period);
31753280
31763281 if (has_branch_stack(event))
31773282 intel_pmu_lbr_save_brstack(&data, cpuc, event);
31783283
3179− if (perf_event_overflow(event, &data, regs))
3180− x86_pmu_stop(event, 0);
3284+ perf_event_overflow(event, &data, regs);
31813285 }
31823286
31833287 return handled;
@@ -3739,10 +3843,9 @@ intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx, · 555 unmodified lines
37393843 if (cpuc->excl_cntrs)
37403844 return intel_get_excl_constraints(cpuc, event, idx, c2);
37413845
3742− /* Not all counters support the branch counter feature. */
3743− if (branch_sample_counters(event)) {
3846+ if (event->hw.dyn_constraint != ~0ULL) {
37443847 c2 = dyn_constraint(cpuc, c2, idx);
3745− c2->idxmsk64 &= x86_pmu.lbr_counters;
3848+ c2->idxmsk64 &= event->hw.dyn_constraint;
37463849 c2->weight = hweight64(c2->idxmsk64);
37473850 }
37483851
@@ -4083,6 +4186,39 @@ end: · 334 unmodified lines
40834186 return start;
40844187 }
40854188
4189+static inline bool intel_pmu_has_acr(struct pmu *pmu)
4190+{
4191+ return !!hybrid(pmu, acr_cause_mask64);
4192+}
4193+
4194+static bool intel_pmu_is_acr_group(struct perf_event *event)
4195+{
4196+ /* The group leader has the ACR flag set */
4197+ if (is_acr_event_group(event))
4198+ return true;
4199+
4200+ /* The acr_mask is set */
4201+ if (event->attr.config2)
4202+ return true;
4203+
4204+ return false;
4205+}
4206+
4207+static inline void intel_pmu_set_acr_cntr_constr(struct perf_event *event,
4208+ u64 *cause_mask, int *num)
4209+{
4210+ event->hw.dyn_constraint &= hybrid(event->pmu, acr_cntr_mask64);
4211+ *cause_mask |= event->attr.config2;
4212+ *num += 1;
4213+}
4214+
4215+static inline void intel_pmu_set_acr_caused_constr(struct perf_event *event,
4216+ int idx, u64 cause_mask)
4217+{
4218+ if (test_bit(idx, (unsigned long *)&cause_mask))
4219+ event->hw.dyn_constraint &= hybrid(event->pmu, acr_cause_mask64);
4220+}
4221+
40864222 static int intel_pmu_hw_config(struct perf_event *event)
40874223 {
40884224 int ret = x86_pmu_hw_config(event);
@@ -4144,15 +4280,19 @@ static int intel_pmu_hw_config(struct perf_event *event) · 55 unmodified lines
41444280 leader = event->group_leader;
41454281 if (branch_sample_call_stack(leader))
41464282 return -EINVAL;
4147− if (branch_sample_counters(leader))
4283+ if (branch_sample_counters(leader)) {
41484284 num++;
4285+ leader->hw.dyn_constraint &= x86_pmu.lbr_counters;
4286+ }
41494287 leader->hw.flags |= PERF_X86_EVENT_BRANCH_COUNTERS;
41504288
41514289 for_each_sibling_event(sibling, leader) {
41524290 if (branch_sample_call_stack(sibling))
41534291 return -EINVAL;
4154− if (branch_sample_counters(sibling))
4292+ if (branch_sample_counters(sibling)) {
41554293 num++;
4294+ sibling->hw.dyn_constraint &= x86_pmu.lbr_counters;
4295+ }
41564296 }
41574297
41584298 if (num > fls(x86_pmu.lbr_counters))
@@ -4207,6 +4347,94 @@ static int intel_pmu_hw_config(struct perf_event *event) · 48 unmodified lines
42074347 event->attr.precise_ip)
42084348 event->group_leader->hw.flags |= PERF_X86_EVENT_PEBS_CNTR;
42094349
4350+ if (intel_pmu_has_acr(event->pmu) && intel_pmu_is_acr_group(event)) {
4351+ struct perf_event *sibling, *leader = event->group_leader;
4352+ struct pmu *pmu = event->pmu;
4353+ bool has_sw_event = false;
4354+ int num = 0, idx = 0;
4355+ u64 cause_mask = 0;
4356+
4357+ /* Not support perf metrics */
4358+ if (is_metric_event(event))
4359+ return -EINVAL;
4360+
4361+ /* Not support freq mode */
4362+ if (event->attr.freq)
4363+ return -EINVAL;
4364+
4365+ /* PDist is not supported */
4366+ if (event->attr.config2 && event->attr.precise_ip > 2)
4367+ return -EINVAL;
4368+
4369+ /* The reload value cannot exceeds the max period */
4370+ if (event->attr.sample_period > x86_pmu.max_period)
4371+ return -EINVAL;
4372+ /*
4373+ * The counter-constraints of each event cannot be finalized
4374+ * unless the whole group is scanned. However, it's hard
4375+ * to know whether the event is the last one of the group.
4376+ * Recalculate the counter-constraints for each event when
4377+ * adding a new event.
4378+ *
4379+ * The group is traversed twice, which may be optimized later.
4380+ * In the first round,
4381+ * - Find all events which do reload when other events
4382+ * overflow and set the corresponding counter-constraints
4383+ * - Add all events, which can cause other events reload,
4384+ * in the cause_mask
4385+ * - Error out if the number of events exceeds the HW limit
4386+ * - The ACR events must be contiguous.
4387+ * Error out if there are non-X86 events between ACR events.
4388+ * This is not a HW limit, but a SW limit.
4389+ * With the assumption, the intel_pmu_acr_late_setup() can
4390+ * easily convert the event idx to counter idx without
4391+ * traversing the whole event list.
4392+ */
4393+ if (!is_x86_event(leader))
4394+ return -EINVAL;
4395+
4396+ if (leader->attr.config2)
4397+ intel_pmu_set_acr_cntr_constr(leader, &cause_mask, &num);
4398+
4399+ if (leader->nr_siblings) {
4400+ for_each_sibling_event(sibling, leader) {
4401+ if (!is_x86_event(sibling)) {
4402+ has_sw_event = true;
4403+ continue;
4404+ }
4405+ if (!sibling->attr.config2)
4406+ continue;
4407+ if (has_sw_event)
4408+ return -EINVAL;
4409+ intel_pmu_set_acr_cntr_constr(sibling, &cause_mask, &num);
4410+ }
4411+ }
4412+ if (leader != event && event->attr.config2) {
4413+ if (has_sw_event)
4414+ return -EINVAL;
4415+ intel_pmu_set_acr_cntr_constr(event, &cause_mask, &num);
4416+ }
4417+
4418+ if (hweight64(cause_mask) > hweight64(hybrid(pmu, acr_cause_mask64)) ||
4419+ num > hweight64(hybrid(event->pmu, acr_cntr_mask64)))
4420+ return -EINVAL;
4421+ /*
4422+ * In the second round, apply the counter-constraints for
4423+ * the events which can cause other events reload.
4424+ */
4425+ intel_pmu_set_acr_caused_constr(leader, idx++, cause_mask);
4426+
4427+ if (leader->nr_siblings) {
4428+ for_each_sibling_event(sibling, leader)
4429+ intel_pmu_set_acr_caused_constr(sibling, idx++, cause_mask);
4430+ }
4431+
4432+ if (leader != event)
4433+ intel_pmu_set_acr_caused_constr(event, idx, cause_mask);
4434+
4435+ leader->hw.flags |= PERF_X86_EVENT_ACR;
4436+ }
4437+
42104438 if ((event->attr.type == PERF_TYPE_HARDWARE) ||
42114439 (event->attr.type == PERF_TYPE_HW_CACHE))
42124440 return 0;
@@ -4354,7 +4582,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data) · 141 unmodified lines
43544582 .guest = intel_ctrl & ~cpuc->intel_ctrl_host_mask & ~pebs_mask,
43554583 };
43564584
4357− if (!x86_pmu.pebs)
4585+ if (!x86_pmu.ds_pebs)
43584586 return arr;
43594587
43604588 /*
@@ -4952,7 +5180,7 @@ int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu) · 591 unmodified lines
49525180 goto err;
49535181 }
49545182
4955− if (x86_pmu.flags & (PMU_FL_EXCL_CNTRS | PMU_FL_TFA | PMU_FL_BR_CNTR)) {
5183+ if (x86_pmu.flags & (PMU_FL_EXCL_CNTRS | PMU_FL_TFA | PMU_FL_DYN_CONSTRAINT)) {
49565184 size_t sz = X86_PMC_IDX_MAX * sizeof(struct event_constraint);
49575185
49585186 cpuc->constraint_list = kzalloc_node(sz, GFP_KERNEL, cpu_to_node(cpu));
@@ -5041,7 +5269,7 @@ static inline bool intel_pmu_broken_perf_cap(void) · 82 unmodified lines
50415269 return false;
50425270 }
50435271
5044−static void update_pmu_cap(struct x86_hybrid_pmu *pmu)
5272+static void update_pmu_cap(struct pmu *pmu)
50455273 {
50465274 unsigned int cntr, fixed_cntr, ecx, edx;
50475275 union cpuid35_eax eax;
@@ -5050,20 +5278,30 @@ static void update_pmu_cap(struct x86_hybrid_pmu *pmu) · 2 unmodified lines
50505278 cpuid(ARCH_PERFMON_EXT_LEAF, &eax.full, &ebx.full, &ecx, &edx);
50515279
50525280 if (ebx.split.umask2)
5053− pmu->config_mask |= ARCH_PERFMON_EVENTSEL_UMASK2;
5281+ hybrid(pmu, config_mask) |= ARCH_PERFMON_EVENTSEL_UMASK2;
50545282 if (ebx.split.eq)
5055− pmu->config_mask |= ARCH_PERFMON_EVENTSEL_EQ;
5283+ hybrid(pmu, config_mask) |= ARCH_PERFMON_EVENTSEL_EQ;
50565284
50575285 if (eax.split.cntr_subleaf) {
50585286 cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF,
50595287 &cntr, &fixed_cntr, &ecx, &edx);
5060− pmu->cntr_mask64 = cntr;
5061− pmu->fixed_cntr_mask64 = fixed_cntr;
5288+ hybrid(pmu, cntr_mask64) = cntr;
5289+ hybrid(pmu, fixed_cntr_mask64) = fixed_cntr;
5290+ }
5291+
5292+ if (eax.split.acr_subleaf) {
5293+ cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_ACR_LEAF,
5294+ &cntr, &fixed_cntr, &ecx, &edx);
5295+ /* The mask of the counters which can be reloaded */
5296+ hybrid(pmu, acr_cntr_mask64) = cntr | ((u64)fixed_cntr << INTEL_PMC_IDX_FIXED);
5297+
5298+ /* The mask of the counters which can cause a reload of reloadable counters */
5299+ hybrid(pmu, acr_cause_mask64) = ecx | ((u64)edx << INTEL_PMC_IDX_FIXED);
50625300 }
50635301
50645302 if (!intel_pmu_broken_perf_cap()) {
50655303 /* Perf Metric (Bit 15) and PEBS via PT (Bit 16) are hybrid enumeration */
5066− rdmsrl(MSR_IA32_PERF_CAPABILITIES, pmu->intel_cap.capabilities);
5304+ rdmsrl(MSR_IA32_PERF_CAPABILITIES, hybrid(pmu, intel_cap).capabilities);
50675305 }
50685306 }
50695307
@@ -5150,7 +5388,7 @@ static bool init_hybrid_pmu(int cpu) · 80 unmodified lines
51505388 goto end;
51515389
51525390 if (this_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT))
5153− update_pmu_cap(pmu);
5391+ update_pmu_cap(&pmu->pmu);
51545392
51555393 intel_pmu_check_hybrid_pmus(pmu);
51565394
@@ -5524,7 +5762,7 @@ static __init void intel_clovertown_quirk(void) · 367 unmodified lines
55245762 * these chips.
55255763 */
55265764 pr_warn("PEBS disabled due to CPU errata\n");
5527− x86_pmu.pebs = 0;
5765+ x86_pmu.ds_pebs = 0;
55285766 x86_pmu.pebs_constraints = NULL;
55295767 }
55305768
@@ -6012,7 +6250,7 @@ tsx_is_visible(struct kobject *kobj, struct attribute *attr, int i) · 481 unmodified lines
60126250 static umode_t
60136251 pebs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
60146252 {
6015− return x86_pmu.pebs ? attr->mode : 0;
6253+ return x86_pmu.ds_pebs ? attr->mode : 0;
60166254 }
60176255
60186256 static umode_t
@@ -6043,6 +6281,21 @@ td_is_visible(struct kobject *kobj, struct attribute *attr, int i) · 24 unmodified lines
60436281 return attr->mode;
60446282 }
60456283
6284+PMU_FORMAT_ATTR(acr_mask, "config2:0-63");
6285+
6286+static struct attribute *format_acr_attrs[] = {
6287+ &format_attr_acr_mask.attr,
6288+ NULL
6289+};
6290+
6291+static umode_t
6292+acr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
6293+{
6294+ struct device *dev = kobj_to_dev(kobj);
6295+
6296+ return intel_pmu_has_acr(dev_get_drvdata(dev)) ? attr->mode : 0;
6297+}
6298+
60466299 static struct attribute_group group_events_td = {
60476300 .name = "events",
60486301 .is_visible = td_is_visible,
@@ -6085,6 +6338,12 @@ static struct attribute_group group_format_evtsel_ext = { · 36 unmodified lines
60856338 .is_visible = evtsel_ext_is_visible,
60866339 };
60876340
6341+static struct attribute_group group_format_acr = {
6342+ .name = "format",
6343+ .attrs = format_acr_attrs,
6344+ .is_visible = acr_is_visible,
6345+};
6346+
60886347 static struct attribute_group group_default = {
60896348 .attrs = intel_pmu_attrs,
60906349 .is_visible = default_is_visible,
@@ -6099,6 +6358,7 @@ static const struct attribute_group *attr_update[] = { · 8 unmodified lines
60996358 &group_format_extra,
61006359 &group_format_extra_skl,
61016360 &group_format_evtsel_ext,
6361+ &group_format_acr,
61026362 &group_default,
61036363 NULL,
61046364 };
@@ -6383,6 +6643,7 @@ static const struct attribute_group *hybrid_attr_update[] = { · 278 unmodified lines
63836643 &group_caps_lbr,
63846644 &hybrid_group_format_extra,
63856645 &group_format_evtsel_ext,
6646+ &group_format_acr,
63866647 &group_default,
63876648 &hybrid_group_cpus,
63886649 NULL,
@@ -6575,6 +6836,7 @@ static __always_inline void intel_pmu_init_skt(struct pmu *pmu) · 186 unmodified lines
65756836 intel_pmu_init_grt(pmu);
65766837 hybrid(pmu, event_constraints) = intel_skt_event_constraints;
65776838 hybrid(pmu, extra_regs) = intel_cmt_extra_regs;
6839+ static_call_update(intel_pmu_enable_acr_event, intel_pmu_enable_acr);
65786840 }
65796841
65806842 __init int intel_pmu_init(void)
@@ -6635,6 +6897,7 @@ __init int intel_pmu_init(void) · 54 unmodified lines
66356897
66366898 x86_pmu.pebs_events_mask = intel_pmu_pebs_mask(x86_pmu.cntr_mask64);
66376899 x86_pmu.pebs_capable = PEBS_COUNTER_MASK;
6900+ x86_pmu.config_mask = X86_RAW_EVENT_MASK;
66386901
66396902 /*
66406903 * Quirk: v2 perfmon does not report fixed-purpose events, so
@@ -6663,7 +6926,7 @@ __init int intel_pmu_init(void) · 22 unmodified lines
66636926 if (boot_cpu_has(X86_FEATURE_ARCH_LBR))
66646927 intel_pmu_arch_lbr_init();
66656928
6666− intel_ds_init();
6929+ intel_pebs_init();
66676930
66686931 x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */
66696932
@@ -6673,6 +6936,12 @@ __init int intel_pmu_init(void) · 3 unmodified lines
66736936 pr_cont(" AnyThread deprecated, ");
66746937 }
66756938
6939+ /*
6940+ * Many features on and after V6 require dynamic constraint,
6941+ * e.g., Arch PEBS, ACR.
6942+ */
6943+ if (version >= 6)
6944+ x86_pmu.flags |= PMU_FL_DYN_CONSTRAINT;
66766945 /*
66776946 * Install the hw-cache-events table:
66786947 */
@@ -6884,6 +7153,18 @@ __init int intel_pmu_init(void) · 205 unmodified lines
68847153 name = "crestmont";
68857154 break;
68867155
7156+ case INTEL_ATOM_DARKMONT_X:
7157+ intel_pmu_init_skt(NULL);
7158+ intel_pmu_pebs_data_source_cmt();
7159+ x86_pmu.pebs_latency_data = cmt_latency_data;
7160+ x86_pmu.get_event_constraints = cmt_get_event_constraints;
7161+ td_attr = skt_events_attrs;
7162+ mem_attr = grt_mem_attrs;
7163+ extra_attr = cmt_format_attr;
7164+ pr_cont("Darkmont events, ");
7165+ name = "darkmont";
7166+ break;
7167+
68877168 case INTEL_WESTMERE:
68887169 case INTEL_WESTMERE_EP:
68897170 case INTEL_WESTMERE_EX:
@@ -7433,6 +7714,18 @@ __init int intel_pmu_init(void) · 543 unmodified lines
74337714 x86_pmu.attr_update = hybrid_attr_update;
74347715 }
74357716
7717+ /*
7718+ * The archPerfmonExt (0x23) includes an enhanced enumeration of
7719+ * PMU architectural features with a per-core view. For non-hybrid,
7720+ * each core has the same PMU capabilities. It's good enough to
7721+ * update the x86_pmu from the booting CPU. For hybrid, the x86_pmu
7722+ * is used to keep the common capabilities. Still keep the values
7723+ * from the leaf 0xa. The core specific update will be done later
7724+ * when a new type is online.
7725+ */
7726+ if (!is_hybrid() && boot_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT))
7727+ update_pmu_cap(NULL);
7728+
74367729 intel_pmu_check_counters_mask(&x86_pmu.cntr_mask64,
74377730 &x86_pmu.fixed_cntr_mask64,
74387731 &x86_pmu.intel_ctrl);
arch/x86/events/intel/ds.c+29−26
@@ -624,7 +624,7 @@ static int alloc_pebs_buffer(int cpu) · 623 unmodified lines
624624 int max, node = cpu_to_node(cpu);
625625 void *buffer, *insn_buff, *cea;
626626
627− if (!x86_pmu.pebs)
627+ if (!x86_pmu.ds_pebs)
628628 return 0;
629629
630630 buffer = dsalloc_pages(bsiz, GFP_KERNEL, cpu);
@@ -659,7 +659,7 @@ static void release_pebs_buffer(int cpu) · 28 unmodified lines
659659 struct cpu_hw_events *hwev = per_cpu_ptr(&cpu_hw_events, cpu);
660660 void *cea;
661661
662− if (!x86_pmu.pebs)
662+ if (!x86_pmu.ds_pebs)
663663 return;
664664
665665 kfree(per_cpu(insn_buffer, cpu));
@@ -734,7 +734,7 @@ void release_ds_buffers(void) · 68 unmodified lines
734734 {
735735 int cpu;
736736
737− if (!x86_pmu.bts && !x86_pmu.pebs)
737+ if (!x86_pmu.bts && !x86_pmu.ds_pebs)
738738 return;
739739
740740 for_each_possible_cpu(cpu)
@@ -750,7 +750,8 @@ void release_ds_buffers(void) · 9 unmodified lines
750750 }
751751
752752 for_each_possible_cpu(cpu) {
753− release_pebs_buffer(cpu);
753+ if (x86_pmu.ds_pebs)
754+ release_pebs_buffer(cpu);
754755 release_bts_buffer(cpu);
755756 }
756757 }
@@ -761,15 +762,17 @@ void reserve_ds_buffers(void) · 4 unmodified lines
761762 int cpu;
762763
763764 x86_pmu.bts_active = 0;
764− x86_pmu.pebs_active = 0;
765765
766− if (!x86_pmu.bts && !x86_pmu.pebs)
766+ if (x86_pmu.ds_pebs)
767+ x86_pmu.pebs_active = 0;
768+
769+ if (!x86_pmu.bts && !x86_pmu.ds_pebs)
767770 return;
768771
769772 if (!x86_pmu.bts)
770773 bts_err = 1;
771774
772− if (!x86_pmu.pebs)
775+ if (!x86_pmu.ds_pebs)
773776 pebs_err = 1;
774777
775778 for_each_possible_cpu(cpu) {
@@ -781,7 +784,8 @@ void reserve_ds_buffers(void) · 5 unmodified lines
781784 if (!bts_err && alloc_bts_buffer(cpu))
782785 bts_err = 1;
783786
784− if (!pebs_err && alloc_pebs_buffer(cpu))
787+ if (x86_pmu.ds_pebs && !pebs_err &&
788+ alloc_pebs_buffer(cpu))
785789 pebs_err = 1;
786790
787791 if (bts_err && pebs_err)
@@ -793,7 +797,7 @@ void reserve_ds_buffers(void) · 5 unmodified lines
793797 release_bts_buffer(cpu);
794798 }
795799
796− if (pebs_err) {
800+ if (x86_pmu.ds_pebs && pebs_err) {
797801 for_each_possible_cpu(cpu)
798802 release_pebs_buffer(cpu);
799803 }
@@ -805,7 +809,7 @@ void reserve_ds_buffers(void) · 5 unmodified lines
805809 if (x86_pmu.bts && !bts_err)
806810 x86_pmu.bts_active = 1;
807811
808− if (x86_pmu.pebs && !pebs_err)
812+ if (x86_pmu.ds_pebs && !pebs_err)
809813 x86_pmu.pebs_active = 1;
810814
811815 for_each_possible_cpu(cpu) {
@@ -1355,9 +1359,8 @@ static void __intel_pmu_pebs_update_cfg(struct perf_event *event, · 543 unmodified lines
13551359 }
13561360
13571361
1358−static void intel_pmu_late_setup(void)
1362+void intel_pmu_pebs_late_setup(struct cpu_hw_events *cpuc)
13591363 {
1360− struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
13611364 struct perf_event *event;
13621365 u64 pebs_data_cfg = 0;
13631366 int i;
@@ -1828,8 +1831,6 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, · 464 unmodified lines
18281831
18291832 perf_sample_data_init(data, 0, event->hw.last_period);
18301833
1831− data->period = event->hw.last_period;
1832−
18331834 /*
18341835 * Use latency for weight (only avail with PEBS-LL)
18351836 */
@@ -2082,7 +2083,6 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, · 246 unmodified lines
20822083 sample_type = event->attr.sample_type;
20832084 format_group = basic->format_group;
20842085 perf_sample_data_init(data, 0, event->hw.last_period);
2085− data->period = event->hw.last_period;
20862086
20872087 setup_pebs_time(event, data, basic->tsc);
20882088
@@ -2359,8 +2359,7 @@ __intel_pmu_pebs_last_event(struct perf_event *event, · 270 unmodified lines
23592359 * All but the last records are processed.
23602360 * The last one is left to be able to call the overflow handler.
23612361 */
2362− if (perf_event_overflow(event, data, regs))
2363− x86_pmu_stop(event, 0);
2362+ perf_event_overflow(event, data, regs);
23642363 }
23652364
23662365 if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) {
@@ -2589,8 +2588,8 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d · 222 unmodified lines
25892588 if (error[bit]) {
25902589 perf_log_lost_samples(event, error[bit]);
25912590
2592− if (iregs && perf_event_account_interrupt(event))
2593− x86_pmu_stop(event, 0);
2591+ if (iregs)
2592+ perf_event_account_interrupt(event);
25942593 }
25952594
25962595 if (counts[bit]) {
@@ -2670,10 +2669,10 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_d · 73 unmodified lines
26702669 }
26712670
26722671 /*
2673− * BTS, PEBS probe and setup
2672+ * PEBS probe and setup
26742673 */
26752674
2676−void __init intel_ds_init(void)
2675+void __init intel_pebs_init(void)
26772676 {
26782677 /*
26792678 * No support for 32bit formats
@@ -2681,13 +2680,12 @@ void __init intel_ds_init(void) · 1 unmodified line
26812680 if (!boot_cpu_has(X86_FEATURE_DTES64))
26822681 return;
26832682
2684− x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS);
2685− x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS);
2683+ x86_pmu.ds_pebs = boot_cpu_has(X86_FEATURE_PEBS);
26862684 x86_pmu.pebs_buffer_size = PEBS_BUFFER_SIZE;
26872685 if (x86_pmu.version <= 4)
26882686 x86_pmu.pebs_no_isolation = 1;
26892687
2690− if (x86_pmu.pebs) {
2688+ if (x86_pmu.ds_pebs) {
26912689 char pebs_type = x86_pmu.intel_cap.pebs_trap ? '+' : '-';
26922690 char *pebs_qual = "";
26932691 int format = x86_pmu.intel_cap.pebs_format;
@@ -2695,6 +2693,11 @@ void __init intel_ds_init(void) · 1 unmodified line
26952693 if (format < 4)
26962694 x86_pmu.intel_cap.pebs_baseline = 0;
26972695
2696+ x86_pmu.pebs_enable = intel_pmu_pebs_enable;
2697+ x86_pmu.pebs_disable = intel_pmu_pebs_disable;
2698+ x86_pmu.pebs_enable_all = intel_pmu_pebs_enable_all;
2699+ x86_pmu.pebs_disable_all = intel_pmu_pebs_disable_all;
2700+
26982701 switch (format) {
26992702 case 0:
27002703 pr_cont("PEBS fmt0%c, ", pebs_type);
@@ -2779,7 +2782,7 @@ void __init intel_ds_init(void) · 78 unmodified lines
27792782
27802783 default:
27812784 pr_cont("no PEBS fmt%d%c, ", format, pebs_type);
2782− x86_pmu.pebs = 0;
2785+ x86_pmu.ds_pebs = 0;
27832786 }
27842787 }
27852788 }
@@ -2788,7 +2791,7 @@ void perf_restore_debug_store(void) · 2 unmodified lines
27882791 {
27892792 struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
27902793
2791− if (!x86_pmu.bts && !x86_pmu.pebs)
2794+ if (!x86_pmu.bts && !x86_pmu.ds_pebs)
27922795 return;
27932796
27942797 wrmsrl(MSR_IA32_DS_AREA, (unsigned long)ds);
arch/x86/events/intel/knc.c+4−3
@@ -241,19 +241,20 @@ again: · 240 unmodified lines
241241
242242 for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
243243 struct perf_event *event = cpuc->events[bit];
244+ u64 last_period;
244245
245246 handled++;
246247
247248 if (!test_bit(bit, cpuc->active_mask))
248249 continue;
249250
251+ last_period = event->hw.last_period;
250252 if (!intel_pmu_save_and_restart(event))
251253 continue;
252254
253− perf_sample_data_init(&data, 0, event->hw.last_period);
255+ perf_sample_data_init(&data, 0, last_period);
254256
255− if (perf_event_overflow(event, &data, regs))
256− x86_pmu_stop(event, 0);
257+ perf_event_overflow(event, &data, regs);
257258 }
258259
259260 /*
arch/x86/events/intel/lbr.c+1−1
@@ -1618,7 +1618,7 @@ void __init intel_pmu_arch_lbr_init(void) · 1617 unmodified lines
16181618 x86_pmu.lbr_nr = lbr_nr;
16191619
16201620 if (!!x86_pmu.lbr_counters)
1621− x86_pmu.flags |= PMU_FL_BR_CNTR;
1621+ x86_pmu.flags |= PMU_FL_BR_CNTR | PMU_FL_DYN_CONSTRAINT;
16221622
16231623 if (x86_pmu.lbr_mispred)
16241624 static_branch_enable(&x86_lbr_mispred);
arch/x86/events/intel/p4.c+1−2
@@ -1072,8 +1072,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) · 1071 unmodified lines
10721072 continue;
10731073
10741074
1075− if (perf_event_overflow(event, &data, regs))
1076− x86_pmu_stop(event, 0);
1075+ perf_event_overflow(event, &data, regs);
10771076 }
10781077
10791078 if (handled)
arch/x86/events/intel/pt.c+2−0
@@ -1863,6 +1863,8 @@ static __init int pt_init(void) · 1862 unmodified lines
18631863
18641864 if (!intel_pt_validate_hw_cap(PT_CAP_topa_multiple_entries))
18651865 pt_pmu.pmu.capabilities = PERF_PMU_CAP_AUX_NO_SG;
1866+ else
1867+ pt_pmu.pmu.capabilities = PERF_PMU_CAP_AUX_PREFER_LARGE;
18661868
18671869 pt_pmu.pmu.capabilities |= PERF_PMU_CAP_EXCLUSIVE |
18681870 PERF_PMU_CAP_ITRACE |
arch/x86/events/intel/uncore.c+2−10
@@ -305,17 +305,11 @@ static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) · 304 unmodified lines
305305 {
306306 struct intel_uncore_box *box;
307307 struct perf_event *event;
308− unsigned long flags;
309308 int bit;
310309
311310 box = container_of(hrtimer, struct intel_uncore_box, hrtimer);
312311 if (!box->n_active || box->cpu != smp_processor_id())
313312 return HRTIMER_NORESTART;
314− /*
315− * disable local interrupt to prevent uncore_pmu_event_start/stop
316− * to interrupt the update process
317− */
318− local_irq_save(flags);
319313
320314 /*
321315 * handle boxes with an active event list as opposed to active
@@ -328,8 +322,6 @@ static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) · 6 unmodified lines
328322 for_each_set_bit(bit, box->active_mask, UNCORE_PMC_IDX_MAX)
329323 uncore_perf_event_update(box, box->events[bit]);
330324
331− local_irq_restore(flags);
332−
333325 hrtimer_forward_now(hrtimer, ns_to_ktime(box->hrtimer_duration));
334326 return HRTIMER_RESTART;
335327 }
@@ -337,7 +329,7 @@ static enum hrtimer_restart uncore_pmu_hrtimer(struct hrtimer *hrtimer) · 1 unmodified line
337329 void uncore_pmu_start_hrtimer(struct intel_uncore_box *box)
338330 {
339331 hrtimer_start(&box->hrtimer, ns_to_ktime(box->hrtimer_duration),
340− HRTIMER_MODE_REL_PINNED);
332+ HRTIMER_MODE_REL_PINNED_HARD);
341333 }
342334
343335 void uncore_pmu_cancel_hrtimer(struct intel_uncore_box *box)
@@ -347,7 +339,7 @@ void uncore_pmu_cancel_hrtimer(struct intel_uncore_box *box) · 3 unmodified lines
347339
348340 static void uncore_pmu_init_hrtimer(struct intel_uncore_box *box)
349341 {
350− hrtimer_setup(&box->hrtimer, uncore_pmu_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
342+ hrtimer_setup(&box->hrtimer, uncore_pmu_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
351343 }
352344
353345 static struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type,
arch/x86/events/perf_event.h+43−2
@@ -127,6 +127,11 @@ static inline bool is_pebs_counter_event_group(struct perf_event *event) · 126 unmodified lines
127127 return check_leader_group(event->group_leader, PERF_X86_EVENT_PEBS_CNTR);
128128 }
129129
130+static inline bool is_acr_event_group(struct perf_event *event)
131+{
132+ return check_leader_group(event->group_leader, PERF_X86_EVENT_ACR);
133+}
134+
130135 struct amd_nb {
131136 int nb_id; /* NorthBridge id */
132137 int refcnt; /* reference count */
@@ -268,6 +273,7 @@ struct cpu_hw_events { · 135 unmodified lines
268273 struct event_constraint *event_constraint[X86_PMC_IDX_MAX];
269274
270275 int n_excl; /* the number of exclusive events */
276+ int n_late_setup; /* the num of events needs late setup */
271277
272278 unsigned int txn_flags;
273279 int is_fake;
@@ -293,6 +299,10 @@ struct cpu_hw_events { · 19 unmodified lines
293299 u64 fixed_ctrl_val;
294300 u64 active_fixed_ctrl_val;
295301
302+ /* Intel ACR configuration */
303+ u64 acr_cfg_b[X86_PMC_IDX_MAX];
304+ u64 acr_cfg_c[X86_PMC_IDX_MAX];
305+
296306 /*
297307 * Intel LBR bits
298308 */
@@ -714,6 +724,15 @@ struct x86_hybrid_pmu { · 415 unmodified lines
714724 u64 fixed_cntr_mask64;
715725 unsigned long fixed_cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
716726 };
727+
728+ union {
729+ u64 acr_cntr_mask64;
730+ unsigned long acr_cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
731+ };
732+ union {
733+ u64 acr_cause_mask64;
734+ unsigned long acr_cause_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
735+ };
717736 struct event_constraint unconstrained;
718737
719738 u64 hw_cache_event_ids
@@ -796,6 +815,10 @@ struct x86_pmu { · 76 unmodified lines
796815 int (*hw_config)(struct perf_event *event);
797816 int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign);
798817 void (*late_setup)(void);
818+ void (*pebs_enable)(struct perf_event *event);
819+ void (*pebs_disable)(struct perf_event *event);
820+ void (*pebs_enable_all)(void);
821+ void (*pebs_disable_all)(void);
799822 unsigned eventsel;
800823 unsigned perfctr;
801824 unsigned fixedctr;
@@ -812,6 +835,14 @@ struct x86_pmu { · 10 unmodified lines
812835 u64 fixed_cntr_mask64;
813836 unsigned long fixed_cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
814837 };
838+ union {
839+ u64 acr_cntr_mask64;
840+ unsigned long acr_cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
841+ };
842+ union {
843+ u64 acr_cause_mask64;
844+ unsigned long acr_cause_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
845+ };
815846 int cntval_bits;
816847 u64 cntval_mask;
817848 union {
@@ -878,7 +909,7 @@ struct x86_pmu { · 60 unmodified lines
878909 */
879910 unsigned int bts :1,
880911 bts_active :1,
881− pebs :1,
912+ ds_pebs :1,
882913 pebs_active :1,
883914 pebs_broken :1,
884915 pebs_prec_dist :1,
@@ -1049,6 +1080,7 @@ do { \ · 164 unmodified lines
10491080 #define PMU_FL_MEM_LOADS_AUX 0x100 /* Require an auxiliary event for the complete memory info */
10501081 #define PMU_FL_RETIRE_LATENCY 0x200 /* Support Retire Latency in PEBS */
10511082 #define PMU_FL_BR_CNTR 0x400 /* Support branch counter logging */
1083+#define PMU_FL_DYN_CONSTRAINT 0x800 /* Needs dynamic constraint */
10521084
10531085 #define EVENT_VAR(_id) event_attr_##_id
10541086 #define EVENT_PTR(_id) &event_attr_##_id.attr.attr
@@ -1091,6 +1123,7 @@ static struct perf_pmu_format_hybrid_attr format_attr_hybrid_##_name = {\ · 36 unmodified lines
10911123 .pmu_type = _pmu, \
10921124 }
10931125
1126+int is_x86_event(struct perf_event *event);
10941127 struct pmu *x86_get_pmu(unsigned int cpu);
10951128 extern struct x86_pmu x86_pmu __read_mostly;
10961129
@@ -1098,6 +1131,10 @@ DECLARE_STATIC_CALL(x86_pmu_set_period, *x86_pmu.set_period); · 1 unmodified line
10981131 DECLARE_STATIC_CALL(x86_pmu_update, *x86_pmu.update);
10991132 DECLARE_STATIC_CALL(x86_pmu_drain_pebs, *x86_pmu.drain_pebs);
11001133 DECLARE_STATIC_CALL(x86_pmu_late_setup, *x86_pmu.late_setup);
1134+DECLARE_STATIC_CALL(x86_pmu_pebs_enable, *x86_pmu.pebs_enable);
1135+DECLARE_STATIC_CALL(x86_pmu_pebs_disable, *x86_pmu.pebs_disable);
1136+DECLARE_STATIC_CALL(x86_pmu_pebs_enable_all, *x86_pmu.pebs_enable_all);
1137+DECLARE_STATIC_CALL(x86_pmu_pebs_disable_all, *x86_pmu.pebs_disable_all);
11011138
11021139 static __always_inline struct x86_perf_task_context_opt *task_context_opt(void *ctx)
11031140 {
@@ -1587,6 +1624,8 @@ void intel_pmu_disable_bts(void); · 483 unmodified lines
15871624
15881625 int intel_pmu_drain_bts_buffer(void);
15891626
1627+void intel_pmu_late_setup(void);
1628+
15901629 u64 grt_latency_data(struct perf_event *event, u64 status);
15911630
15921631 u64 cmt_latency_data(struct perf_event *event, u64 status);
@@ -1643,11 +1682,13 @@ void intel_pmu_pebs_disable_all(void); · 50 unmodified lines
16431682
16441683 void intel_pmu_pebs_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in);
16451684
1685+void intel_pmu_pebs_late_setup(struct cpu_hw_events *cpuc);
1686+
16461687 void intel_pmu_drain_pebs_buffer(void);
16471688
16481689 void intel_pmu_store_pebs_lbrs(struct lbr_entry *lbr);
16491690
1650−void intel_ds_init(void);
1691+void intel_pebs_init(void);
16511692
16521693 void intel_pmu_lbr_save_brstack(struct perf_sample_data *data,
16531694 struct cpu_hw_events *cpuc,
arch/x86/events/perf_event_flags.h+21−20
@@ -2,23 +2,24 @@ · 1 unmodified line
22 /*
33 * struct hw_perf_event.flags flags
44 */
5−PERF_ARCH(PEBS_LDLAT, 0x00001) /* ld+ldlat data address sampling */
6−PERF_ARCH(PEBS_ST, 0x00002) /* st data address sampling */
7−PERF_ARCH(PEBS_ST_HSW, 0x00004) /* haswell style datala, store */
8−PERF_ARCH(PEBS_LD_HSW, 0x00008) /* haswell style datala, load */
9−PERF_ARCH(PEBS_NA_HSW, 0x00010) /* haswell style datala, unknown */
10−PERF_ARCH(EXCL, 0x00020) /* HT exclusivity on counter */
11−PERF_ARCH(DYNAMIC, 0x00040) /* dynamic alloc'd constraint */
12−PERF_ARCH(PEBS_CNTR, 0x00080) /* PEBS counters snapshot */
13−PERF_ARCH(EXCL_ACCT, 0x00100) /* accounted EXCL event */
14−PERF_ARCH(AUTO_RELOAD, 0x00200) /* use PEBS auto-reload */
15−PERF_ARCH(LARGE_PEBS, 0x00400) /* use large PEBS */
16−PERF_ARCH(PEBS_VIA_PT, 0x00800) /* use PT buffer for PEBS */
17−PERF_ARCH(PAIR, 0x01000) /* Large Increment per Cycle */
18−PERF_ARCH(LBR_SELECT, 0x02000) /* Save/Restore MSR_LBR_SELECT */
19−PERF_ARCH(TOPDOWN, 0x04000) /* Count Topdown slots/metrics events */
20−PERF_ARCH(PEBS_STLAT, 0x08000) /* st+stlat data address sampling */
21−PERF_ARCH(AMD_BRS, 0x10000) /* AMD Branch Sampling */
22−PERF_ARCH(PEBS_LAT_HYBRID, 0x20000) /* ld and st lat for hybrid */
23−PERF_ARCH(NEEDS_BRANCH_STACK, 0x40000) /* require branch stack setup */
24−PERF_ARCH(BRANCH_COUNTERS, 0x80000) /* logs the counters in the extra space of each branch */
5+PERF_ARCH(PEBS_LDLAT, 0x0000001) /* ld+ldlat data address sampling */
6+PERF_ARCH(PEBS_ST, 0x0000002) /* st data address sampling */
7+PERF_ARCH(PEBS_ST_HSW, 0x0000004) /* haswell style datala, store */
8+PERF_ARCH(PEBS_LD_HSW, 0x0000008) /* haswell style datala, load */
9+PERF_ARCH(PEBS_NA_HSW, 0x0000010) /* haswell style datala, unknown */
10+PERF_ARCH(EXCL, 0x0000020) /* HT exclusivity on counter */
11+PERF_ARCH(DYNAMIC, 0x0000040) /* dynamic alloc'd constraint */
12+PERF_ARCH(PEBS_CNTR, 0x0000080) /* PEBS counters snapshot */
13+PERF_ARCH(EXCL_ACCT, 0x0000100) /* accounted EXCL event */
14+PERF_ARCH(AUTO_RELOAD, 0x0000200) /* use PEBS auto-reload */
15+PERF_ARCH(LARGE_PEBS, 0x0000400) /* use large PEBS */
16+PERF_ARCH(PEBS_VIA_PT, 0x0000800) /* use PT buffer for PEBS */
17+PERF_ARCH(PAIR, 0x0001000) /* Large Increment per Cycle */
18+PERF_ARCH(LBR_SELECT, 0x0002000) /* Save/Restore MSR_LBR_SELECT */
19+PERF_ARCH(TOPDOWN, 0x0004000) /* Count Topdown slots/metrics events */
20+PERF_ARCH(PEBS_STLAT, 0x0008000) /* st+stlat data address sampling */
21+PERF_ARCH(AMD_BRS, 0x0010000) /* AMD Branch Sampling */
22+PERF_ARCH(PEBS_LAT_HYBRID, 0x0020000) /* ld and st lat for hybrid */
23+PERF_ARCH(NEEDS_BRANCH_STACK, 0x0040000) /* require branch stack setup */
24+PERF_ARCH(BRANCH_COUNTERS, 0x0080000) /* logs the counters in the extra space of each branch */
25+PERF_ARCH(ACR, 0x0100000) /* Auto counter reload */
arch/x86/events/zhaoxin/core.c+1−2
@@ -397,8 +397,7 @@ again: · 396 unmodified lines
397397 if (!x86_perf_event_set_period(event))
398398 continue;
399399
400− if (perf_event_overflow(event, &data, regs))
401− x86_pmu_stop(event, 0);
400+ perf_event_overflow(event, &data, regs);
402401 }
403402
404403 /*
arch/x86/include/asm/msr-index.h+4−0
@@ -602,7 +602,11 @@ · 601 unmodified lines
602602 /* V6 PMON MSR range */
603603 #define MSR_IA32_PMC_V6_GP0_CTR 0x1900
604604 #define MSR_IA32_PMC_V6_GP0_CFG_A 0x1901
605+#define MSR_IA32_PMC_V6_GP0_CFG_B 0x1902
606+#define MSR_IA32_PMC_V6_GP0_CFG_C 0x1903
605607 #define MSR_IA32_PMC_V6_FX0_CTR 0x1980
608+#define MSR_IA32_PMC_V6_FX0_CFG_B 0x1982
609+#define MSR_IA32_PMC_V6_FX0_CFG_C 0x1983
606610 #define MSR_IA32_PMC_V6_STEP 4
607611
608612 /* KeyID partitioning between MKTME and TDX */
arch/x86/include/asm/perf_event.h+1−0
@@ -195,6 +195,7 @@ union cpuid10_edx { · 194 unmodified lines
195195 */
196196 #define ARCH_PERFMON_EXT_LEAF 0x00000023
197197 #define ARCH_PERFMON_NUM_COUNTER_LEAF 0x1
198+#define ARCH_PERFMON_ACR_LEAF 0x2
198199
199200 union cpuid35_eax {
200201 struct {
arch/x86/kernel/uprobes.c+5−0
@@ -840,6 +840,11 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn) · 839 unmodified lines
840840 insn_byte_t p;
841841 int i;
842842
843+ /* x86_nops[insn->length]; same as jmp with .offs = 0 */
844+ if (insn->length <= ASM_NOP_MAX &&
845+ !memcmp(insn->kaddr, x86_nops[insn->length], insn->length))
846+ goto setup;
847+
843848 switch (opc1) {
844849 case 0xeb: /* jmp 8 */
845850 case 0xe9: /* jmp 32 */
arch/xtensa/kernel/perf_event.c+1−2
@@ -388,8 +388,7 @@ irqreturn_t xtensa_pmu_irq_handler(int irq, void *dev_id) · 387 unmodified lines
388388 struct pt_regs *regs = get_irq_regs();
389389
390390 perf_sample_data_init(&data, 0, last_period);
391− if (perf_event_overflow(event, &data, regs))
392− xtensa_pmu_stop(event, 0);
391+ perf_event_overflow(event, &data, regs);
393392 }
394393
395394 rc = IRQ_HANDLED;
drivers/perf/apple_m1_cpu_pmu.c+1−2
@@ -474,8 +474,7 @@ static irqreturn_t m1_pmu_handle_irq(struct arm_pmu *cpu_pmu) · 473 unmodified lines
474474 if (!armpmu_event_set_period(event))
475475 continue;
476476
477− if (perf_event_overflow(event, &data, regs))
478− m1_pmu_disable_event(event);
477+ perf_event_overflow(event, &data, regs);
479478 }
480479
481480 cpu_pmu->start(cpu_pmu);
drivers/perf/arm_pmuv3.c+1−2
@@ -887,8 +887,7 @@ static irqreturn_t armv8pmu_handle_irq(struct arm_pmu *cpu_pmu) · 886 unmodified lines
887887 * an irq_work which will be taken care of in the handling of
888888 * IPI_IRQ_WORK.
889889 */
890− if (perf_event_overflow(event, &data, regs))
891− cpu_pmu->disable(event);
890+ perf_event_overflow(event, &data, regs);
892891 }
893892 armv8pmu_start(cpu_pmu);
894893
drivers/perf/arm_v6_pmu.c+1−2
@@ -276,8 +276,7 @@ armv6pmu_handle_irq(struct arm_pmu *cpu_pmu) · 275 unmodified lines
276276 if (!armpmu_event_set_period(event))
277277 continue;
278278
279− if (perf_event_overflow(event, &data, regs))
280− cpu_pmu->disable(event);
279+ perf_event_overflow(event, &data, regs);
281280 }
282281
283282 /*
drivers/perf/arm_v7_pmu.c+1−2
@@ -930,8 +930,7 @@ static irqreturn_t armv7pmu_handle_irq(struct arm_pmu *cpu_pmu) · 929 unmodified lines
930930 if (!armpmu_event_set_period(event))
931931 continue;
932932
933− if (perf_event_overflow(event, &data, regs))
934− cpu_pmu->disable(event);
933+ perf_event_overflow(event, &data, regs);
935934 }
936935
937936 /*
drivers/perf/arm_xscale_pmu.c+2−4
@@ -186,8 +186,7 @@ xscale1pmu_handle_irq(struct arm_pmu *cpu_pmu) · 185 unmodified lines
186186 if (!armpmu_event_set_period(event))
187187 continue;
188188
189− if (perf_event_overflow(event, &data, regs))
190− cpu_pmu->disable(event);
189+ perf_event_overflow(event, &data, regs);
191190 }
192191
193192 irq_work_run();
@@ -519,8 +518,7 @@ xscale2pmu_handle_irq(struct arm_pmu *cpu_pmu) · 325 unmodified lines
519518 if (!armpmu_event_set_period(event))
520519 continue;
521520
522− if (perf_event_overflow(event, &data, regs))
523− cpu_pmu->disable(event);
521+ perf_event_overflow(event, &data, regs);
524522 }
525523
526524 irq_work_run();
include/linux/cpuhotplug.h+0−1
@@ -60,7 +60,6 @@ enum cpuhp_state { · 59 unmodified lines
6060 /* PREPARE section invoked on a control CPU */
6161 CPUHP_OFFLINE = 0,
6262 CPUHP_CREATE_THREADS,
63− CPUHP_PERF_PREPARE,
6463 CPUHP_PERF_X86_PREPARE,
6564 CPUHP_PERF_X86_AMD_UNCORE_PREP,
6665 CPUHP_PERF_POWER,
include/linux/perf_event.h+167−131
@@ -26,18 +26,9 @@ · 25 unmodified lines
2626 # include <asm/local64.h>
2727 #endif
2828
29−#define PERF_GUEST_ACTIVE 0x01
30−#define PERF_GUEST_USER 0x02
31−
32−struct perf_guest_info_callbacks {
33− unsigned int (*state)(void);
34− unsigned long (*get_ip)(void);
35− unsigned int (*handle_intel_pt_intr)(void);
36−};
37−
3829 #ifdef CONFIG_HAVE_HW_BREAKPOINT
39−#include <linux/rhashtable-types.h>
40−#include <asm/hw_breakpoint.h>
30+# include <linux/rhashtable-types.h>
31+# include <asm/hw_breakpoint.h>
4132 #endif
4233
4334 #include <linux/list.h>
@@ -62,19 +53,20 @@ struct perf_guest_info_callbacks { · 18 unmodified lines
6253 #include <linux/security.h>
6354 #include <linux/static_call.h>
6455 #include <linux/lockdep.h>
56+
6557 #include <asm/local.h>
6658
6759 struct perf_callchain_entry {
68− __u64 nr;
69− __u64 ip[]; /* /proc/sys/kernel/perf_event_max_stack */
60+ u64 nr;
61+ u64 ip[]; /* /proc/sys/kernel/perf_event_max_stack */
7062 };
7163
7264 struct perf_callchain_entry_ctx {
73− struct perf_callchain_entry *entry;
74− u32 max_stack;
75− u32 nr;
76− short contexts;
77− bool contexts_maxed;
65+ struct perf_callchain_entry *entry;
66+ u32 max_stack;
67+ u32 nr;
68+ short contexts;
69+ bool contexts_maxed;
7870 };
7971
8072 typedef unsigned long (*perf_copy_f)(void *dst, const void *src,
@@ -121,8 +113,8 @@ static __always_inline bool perf_raw_frag_last(const struct perf_raw_frag *frag) · 40 unmodified lines
121113 * already stored in age order, the hw_idx should be 0.
122114 */
123115 struct perf_branch_stack {
124− __u64 nr;
125− __u64 hw_idx;
116+ u64 nr;
117+ u64 hw_idx;
126118 struct perf_branch_entry entries[];
127119 };
128120
@@ -132,10 +124,10 @@ struct task_struct; · 3 unmodified lines
132124 * extra PMU register associated with an event
133125 */
134126 struct hw_perf_event_extra {
135− u64 config; /* register value */
136− unsigned int reg; /* register address or index */
137− int alloc; /* extra register already allocated */
138− int idx; /* index in shared_regs->regs[] */
127+ u64 config; /* register value */
128+ unsigned int reg; /* register address or index */
129+ int alloc; /* extra register already allocated */
130+ int idx; /* index in shared_regs->regs[] */
139131 };
140132
141133 /**
@@ -144,8 +136,8 @@ struct hw_perf_event_extra { · 2 unmodified lines
144136 * PERF_EVENT_FLAG_ARCH bits are reserved for architecture-specific
145137 * usage.
146138 */
147−#define PERF_EVENT_FLAG_ARCH 0x000fffff
148−#define PERF_EVENT_FLAG_USER_READ_CNT 0x80000000
139+#define PERF_EVENT_FLAG_ARCH 0x0fffffff
140+#define PERF_EVENT_FLAG_USER_READ_CNT 0x80000000
149141
150142 static_assert((PERF_EVENT_FLAG_USER_READ_CNT & PERF_EVENT_FLAG_ARCH) == 0);
151143
@@ -157,7 +149,9 @@ struct hw_perf_event { · 5 unmodified lines
157149 union {
158150 struct { /* hardware */
159151 u64 config;
152+ u64 config1;
160153 u64 last_tag;
154+ u64 dyn_constraint;
161155 unsigned long config_base;
162156 unsigned long event_base;
163157 int event_base_rdpmc;
@@ -225,9 +219,14 @@ struct hw_perf_event { · 61 unmodified lines
225219 /*
226220 * hw_perf_event::state flags; used to track the PERF_EF_* state.
227221 */
228−#define PERF_HES_STOPPED 0x01 /* the counter is stopped */
229−#define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
230−#define PERF_HES_ARCH 0x04
222+
223+/* the counter is stopped */
224+#define PERF_HES_STOPPED 0x01
225+
226+/* event->count up-to-date */
227+#define PERF_HES_UPTODATE 0x02
228+
229+#define PERF_HES_ARCH 0x04
231230
232231 int state;
233232
@@ -276,7 +275,7 @@ struct hw_perf_event { · 42 unmodified lines
276275 */
277276 u64 freq_time_stamp;
278277 u64 freq_count_stamp;
279−#endif
278+#endif /* CONFIG_PERF_EVENTS */
280279 };
281280
282281 struct perf_event;
@@ -285,28 +284,33 @@ struct perf_event_pmu_context; · 2 unmodified lines
285284 /*
286285 * Common implementation detail of pmu::{start,commit,cancel}_txn
287286 */
288−#define PERF_PMU_TXN_ADD 0x1 /* txn to add/schedule event on PMU */
289−#define PERF_PMU_TXN_READ 0x2 /* txn to read event group from PMU */
287+
288+/* txn to add/schedule event on PMU */
289+#define PERF_PMU_TXN_ADD 0x1
290+
291+/* txn to read event group from PMU */
292+#define PERF_PMU_TXN_READ 0x2
290293
291294 /**
292295 * pmu::capabilities flags
293296 */
294−#define PERF_PMU_CAP_NO_INTERRUPT 0x0001
295−#define PERF_PMU_CAP_NO_NMI 0x0002
296−#define PERF_PMU_CAP_AUX_NO_SG 0x0004
297−#define PERF_PMU_CAP_EXTENDED_REGS 0x0008
298−#define PERF_PMU_CAP_EXCLUSIVE 0x0010
299−#define PERF_PMU_CAP_ITRACE 0x0020
300−#define PERF_PMU_CAP_NO_EXCLUDE 0x0040
301−#define PERF_PMU_CAP_AUX_OUTPUT 0x0080
302−#define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x0100
303−#define PERF_PMU_CAP_AUX_PAUSE 0x0200
297+#define PERF_PMU_CAP_NO_INTERRUPT 0x0001
298+#define PERF_PMU_CAP_NO_NMI 0x0002
299+#define PERF_PMU_CAP_AUX_NO_SG 0x0004
300+#define PERF_PMU_CAP_EXTENDED_REGS 0x0008
301+#define PERF_PMU_CAP_EXCLUSIVE 0x0010
302+#define PERF_PMU_CAP_ITRACE 0x0020
303+#define PERF_PMU_CAP_NO_EXCLUDE 0x0040
304+#define PERF_PMU_CAP_AUX_OUTPUT 0x0080
305+#define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x0100
306+#define PERF_PMU_CAP_AUX_PAUSE 0x0200
307+#define PERF_PMU_CAP_AUX_PREFER_LARGE 0x0400
304308
305309 /**
306310 * pmu::scope
307311 */
308312 enum perf_pmu_scope {
309− PERF_PMU_SCOPE_NONE = 0,
313+ PERF_PMU_SCOPE_NONE = 0,
310314 PERF_PMU_SCOPE_CORE,
311315 PERF_PMU_SCOPE_DIE,
312316 PERF_PMU_SCOPE_CLUSTER,
@@ -325,6 +329,9 @@ struct perf_output_handle; · 12 unmodified lines
325329 struct pmu {
326330 struct list_head entry;
327331
332+ spinlock_t events_lock;
333+ struct list_head events;
334+
328335 struct module *module;
329336 struct device *dev;
330337 struct device *parent;
@@ -387,11 +394,21 @@ struct pmu { · 56 unmodified lines
387394 * Flags for ->add()/->del()/ ->start()/->stop(). There are
388395 * matching hw_perf_event::state flags.
389396 */
390−#define PERF_EF_START 0x01 /* start the counter when adding */
391−#define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
392−#define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
393−#define PERF_EF_PAUSE 0x08 /* AUX area event, pause tracing */
394−#define PERF_EF_RESUME 0x10 /* AUX area event, resume tracing */
397+
398+/* start the counter when adding */
399+#define PERF_EF_START 0x01
400+
401+/* reload the counter when starting */
402+#define PERF_EF_RELOAD 0x02
403+
404+/* update the counter when stopping */
405+#define PERF_EF_UPDATE 0x04
406+
407+/* AUX area event, pause tracing */
408+#define PERF_EF_PAUSE 0x08
409+
410+/* AUX area event, resume tracing */
411+#define PERF_EF_RESUME 0x10
395412
396413 /*
397414 * Adds/Removes a counter to/from the PMU, can be done inside a
@@ -590,10 +607,10 @@ enum perf_addr_filter_action_t { · 192 unmodified lines
590607 * This is a hardware-agnostic filter configuration as specified by the user.
591608 */
592609 struct perf_addr_filter {
593− struct list_head entry;
594− struct path path;
595− unsigned long offset;
596− unsigned long size;
610+ struct list_head entry;
611+ struct path path;
612+ unsigned long offset;
613+ unsigned long size;
597614 enum perf_addr_filter_action_t action;
598615 };
599616
@@ -608,23 +625,24 @@ struct perf_addr_filter { · 8 unmodified lines
608625 * bundled together; see perf_event_addr_filters().
609626 */
610627 struct perf_addr_filters_head {
611− struct list_head list;
612− raw_spinlock_t lock;
613− unsigned int nr_file_filters;
628+ struct list_head list;
629+ raw_spinlock_t lock;
630+ unsigned int nr_file_filters;
614631 };
615632
616633 struct perf_addr_filter_range {
617− unsigned long start;
618− unsigned long size;
634+ unsigned long start;
635+ unsigned long size;
619636 };
620637
621638 /**
622639 * enum perf_event_state - the states of an event:
623640 */
624641 enum perf_event_state {
625− PERF_EVENT_STATE_DEAD = -4,
626− PERF_EVENT_STATE_EXIT = -3,
627− PERF_EVENT_STATE_ERROR = -2,
642+ PERF_EVENT_STATE_DEAD = -5,
643+ PERF_EVENT_STATE_REVOKED = -4, /* pmu gone, must not touch */
644+ PERF_EVENT_STATE_EXIT = -3, /* task died, still inherit */
645+ PERF_EVENT_STATE_ERROR = -2, /* scheduling error, can enable */
628646 PERF_EVENT_STATE_OFF = -1,
629647 PERF_EVENT_STATE_INACTIVE = 0,
630648 PERF_EVENT_STATE_ACTIVE = 1,
@@ -662,24 +680,24 @@ struct swevent_hlist { · 31 unmodified lines
662680 struct rcu_head rcu_head;
663681 };
664682
665−#define PERF_ATTACH_CONTEXT 0x0001
666−#define PERF_ATTACH_GROUP 0x0002
667−#define PERF_ATTACH_TASK 0x0004
668−#define PERF_ATTACH_TASK_DATA 0x0008
669−#define PERF_ATTACH_GLOBAL_DATA 0x0010
670−#define PERF_ATTACH_SCHED_CB 0x0020
671−#define PERF_ATTACH_CHILD 0x0040
672−#define PERF_ATTACH_EXCLUSIVE 0x0080
673−#define PERF_ATTACH_CALLCHAIN 0x0100
674−#define PERF_ATTACH_ITRACE 0x0200
683+#define PERF_ATTACH_CONTEXT 0x0001
684+#define PERF_ATTACH_GROUP 0x0002
685+#define PERF_ATTACH_TASK 0x0004
686+#define PERF_ATTACH_TASK_DATA 0x0008
687+#define PERF_ATTACH_GLOBAL_DATA 0x0010
688+#define PERF_ATTACH_SCHED_CB 0x0020
689+#define PERF_ATTACH_CHILD 0x0040
690+#define PERF_ATTACH_EXCLUSIVE 0x0080
691+#define PERF_ATTACH_CALLCHAIN 0x0100
692+#define PERF_ATTACH_ITRACE 0x0200
675693
676694 struct bpf_prog;
677695 struct perf_cgroup;
678696 struct perf_buffer;
679697
680698 struct pmu_event_list {
681− raw_spinlock_t lock;
682− struct list_head list;
699+ raw_spinlock_t lock;
700+ struct list_head list;
683701 };
684702
685703 /*
@@ -689,12 +707,12 @@ struct pmu_event_list { · 3 unmodified lines
689707 * disabled is sufficient since it will hold-off the IPIs.
690708 */
691709 #ifdef CONFIG_PROVE_LOCKING
692−#define lockdep_assert_event_ctx(event) \
710+# define lockdep_assert_event_ctx(event) \
693711 WARN_ON_ONCE(__lockdep_enabled && \
694712 (this_cpu_read(hardirqs_enabled) && \
695713 lockdep_is_held(&(event)->ctx->mutex) != LOCK_STATE_HELD))
696714 #else
697−#define lockdep_assert_event_ctx(event)
715+# define lockdep_assert_event_ctx(event)
698716 #endif
699717
700718 #define for_each_sibling_event(sibling, event) \
@@ -852,9 +870,9 @@ struct perf_event { · 151 unmodified lines
852870 #ifdef CONFIG_EVENT_TRACING
853871 struct trace_event_call *tp_event;
854872 struct event_filter *filter;
855−#ifdef CONFIG_FUNCTION_TRACER
873+# ifdef CONFIG_FUNCTION_TRACER
856874 struct ftrace_ops ftrace_ops;
857−#endif
875+# endif
858876 #endif
859877
860878 #ifdef CONFIG_CGROUP_PERF
@@ -865,6 +883,7 @@ struct perf_event { · 4 unmodified lines
865883 void *security;
866884 #endif
867885 struct list_head sb_list;
886+ struct list_head pmu_list;
868887
869888 /*
870889 * Certain events gets forwarded to another pmu internally by over-
@@ -872,7 +891,7 @@ struct perf_event { · 1 unmodified line
872891 * of it. event->orig_type contains original 'type' requested by
873892 * user.
874893 */
875− __u32 orig_type;
894+ u32 orig_type;
876895 #endif /* CONFIG_PERF_EVENTS */
877896 };
878897
@@ -937,8 +956,8 @@ static inline bool perf_pmu_ctx_is_active(struct perf_event_pmu_context *epc) · 58 unmodified lines
937956 }
938957
939958 struct perf_event_groups {
940− struct rb_root tree;
941− u64 index;
959+ struct rb_root tree;
960+ u64 index;
942961 };
943962
944963
@@ -1155,7 +1174,7 @@ extern void perf_aux_output_flag(struct perf_output_handle *handle, u64 flags); · 210 unmodified lines
11551174 extern void perf_event_itrace_started(struct perf_event *event);
11561175
11571176 extern int perf_pmu_register(struct pmu *pmu, const char *name, int type);
1158−extern void perf_pmu_unregister(struct pmu *pmu);
1177+extern int perf_pmu_unregister(struct pmu *pmu);
11591178
11601179 extern void __perf_event_task_sched_in(struct task_struct *prev,
11611180 struct task_struct *task);
@@ -1181,16 +1200,18 @@ extern void perf_pmu_resched(struct pmu *pmu); · 19 unmodified lines
11811200 extern int perf_event_refresh(struct perf_event *event, int refresh);
11821201 extern void perf_event_update_userpage(struct perf_event *event);
11831202 extern int perf_event_release_kernel(struct perf_event *event);
1203+
11841204 extern struct perf_event *
11851205 perf_event_create_kernel_counter(struct perf_event_attr *attr,
1186− int cpu,
1187− struct task_struct *task,
1188− perf_overflow_handler_t callback,
1189− void *context);
1206+ int cpu,
1207+ struct task_struct *task,
1208+ perf_overflow_handler_t callback,
1209+ void *context);
1210+
11901211 extern void perf_pmu_migrate_context(struct pmu *pmu,
1191− int src_cpu, int dst_cpu);
1192−int perf_event_read_local(struct perf_event *event, u64 *value,
1193− u64 *enabled, u64 *running);
1212+ int src_cpu, int dst_cpu);
1213+extern int perf_event_read_local(struct perf_event *event, u64 *value,
1214+ u64 *enabled, u64 *running);
11941215 extern u64 perf_event_read_value(struct perf_event *event,
11951216 u64 *enabled, u64 *running);
11961217
@@ -1407,14 +1428,14 @@ static inline u32 perf_sample_data_size(struct perf_sample_data *data, · 210 unmodified lines
14071428 */
14081429 static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *br)
14091430 {
1410− br->mispred = 0;
1411− br->predicted = 0;
1412− br->in_tx = 0;
1413− br->abort = 0;
1414− br->cycles = 0;
1415− br->type = 0;
1416− br->spec = PERF_BR_SPEC_NA;
1417− br->reserved = 0;
1431+ br->mispred = 0;
1432+ br->predicted = 0;
1433+ br->in_tx = 0;
1434+ br->abort = 0;
1435+ br->cycles = 0;
1436+ br->type = 0;
1437+ br->spec = PERF_BR_SPEC_NA;
1438+ br->reserved = 0;
14181439 }
14191440
14201441 extern void perf_output_sample(struct perf_output_handle *handle,
@@ -1603,7 +1624,17 @@ extern void perf_event_bpf_event(struct bpf_prog *prog, · 182 unmodified lines
16031624 enum perf_bpf_event_type type,
16041625 u16 flags);
16051626
1627+#define PERF_GUEST_ACTIVE 0x01
1628+#define PERF_GUEST_USER 0x02
1629+
1630+struct perf_guest_info_callbacks {
1631+ unsigned int (*state)(void);
1632+ unsigned long (*get_ip)(void);
1633+ unsigned int (*handle_intel_pt_intr)(void);
1634+};
1635+
16061636 #ifdef CONFIG_GUEST_PERF_EVENTS
1637+
16071638 extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
16081639
16091640 DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state);
@@ -1614,21 +1645,27 @@ static inline unsigned int perf_guest_state(void) · 4 unmodified lines
16141645 {
16151646 return static_call(__perf_guest_state)();
16161647 }
1648+
16171649 static inline unsigned long perf_guest_get_ip(void)
16181650 {
16191651 return static_call(__perf_guest_get_ip)();
16201652 }
1653+
16211654 static inline unsigned int perf_guest_handle_intel_pt_intr(void)
16221655 {
16231656 return static_call(__perf_guest_handle_intel_pt_intr)();
16241657 }
1658+
16251659 extern void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
16261660 extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
1627−#else
1661+
1662+#else /* !CONFIG_GUEST_PERF_EVENTS: */
1663+
16281664 static inline unsigned int perf_guest_state(void) { return 0; }
16291665 static inline unsigned long perf_guest_get_ip(void) { return 0; }
16301666 static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
1631−#endif /* CONFIG_GUEST_PERF_EVENTS */
1667+
1668+#endif /* !CONFIG_GUEST_PERF_EVENTS */
16321669
16331670 extern void perf_event_exec(void);
16341671 extern void perf_event_comm(struct task_struct *tsk, bool exec);
@@ -1658,6 +1695,7 @@ static inline int perf_callchain_store_context(struct perf_callchain_entry_ctx * · 23 unmodified lines
16581695 {
16591696 if (ctx->contexts < sysctl_perf_event_max_contexts_per_stack) {
16601697 struct perf_callchain_entry *entry = ctx->entry;
1698+
16611699 entry->ip[entry->nr++] = ip;
16621700 ++ctx->contexts;
16631701 return 0;
@@ -1671,6 +1709,7 @@ static inline int perf_callchain_store(struct perf_callchain_entry_ctx *ctx, u64 · 7 unmodified lines
16711709 {
16721710 if (ctx->nr < ctx->max_stack && !ctx->contexts_maxed) {
16731711 struct perf_callchain_entry *entry = ctx->entry;
1712+
16741713 entry->ip[entry->nr++] = ip;
16751714 ++ctx->nr;
16761715 return 0;
@@ -1697,7 +1736,7 @@ static inline int perf_is_paranoid(void) · 20 unmodified lines
16971736 return sysctl_perf_event_paranoid > -1;
16981737 }
16991738
1700−int perf_allow_kernel(void);
1739+extern int perf_allow_kernel(void);
17011740
17021741 static inline int perf_allow_cpu(void)
17031742 {
@@ -1760,7 +1799,7 @@ static inline bool needs_branch_stack(struct perf_event *event) · 56 unmodified lines
17601799
17611800 static inline bool has_aux(struct perf_event *event)
17621801 {
1763− return event->pmu->setup_aux;
1802+ return event->pmu && event->pmu->setup_aux;
17641803 }
17651804
17661805 static inline bool has_aux_action(struct perf_event *event)
@@ -1819,7 +1858,7 @@ extern int perf_output_begin_backward(struct perf_output_handle *handle, · 52 unmodified lines
18191858
18201859 extern void perf_output_end(struct perf_output_handle *handle);
18211860 extern unsigned int perf_output_copy(struct perf_output_handle *handle,
1822− const void *buf, unsigned int len);
1861+ const void *buf, unsigned int len);
18231862 extern unsigned int perf_output_skip(struct perf_output_handle *handle,
18241863 unsigned int len);
18251864 extern long perf_output_copy_aux(struct perf_output_handle *aux_handle,
@@ -1836,7 +1875,9 @@ extern void perf_event_task_tick(void); · 10 unmodified lines
18361875 extern int perf_event_account_interrupt(struct perf_event *event);
18371876 extern int perf_event_period(struct perf_event *event, u64 value);
18381877 extern u64 perf_event_pause(struct perf_event *event, bool reset);
1878+
18391879 #else /* !CONFIG_PERF_EVENTS: */
1880+
18401881 static inline void *
18411882 perf_aux_output_begin(struct perf_output_handle *handle,
18421883 struct perf_event *event) { return NULL; }
@@ -1914,19 +1955,14 @@ static inline void perf_event_disable(struct perf_event *event) { } · 71 unmodified lines
19141955 static inline int __perf_event_disable(void *info) { return -1; }
19151956 static inline void perf_event_task_tick(void) { }
19161957 static inline int perf_event_release_kernel(struct perf_event *event) { return 0; }
1917−static inline int perf_event_period(struct perf_event *event, u64 value)
1918−{
1919− return -EINVAL;
1920−}
1921−static inline u64 perf_event_pause(struct perf_event *event, bool reset)
1922−{
1923− return 0;
1924−}
1925−static inline int perf_exclude_event(struct perf_event *event, struct pt_regs *regs)
1926−{
1927− return 0;
1928−}
1929−#endif
1958+static inline int
1959+perf_event_period(struct perf_event *event, u64 value) { return -EINVAL; }
1960+static inline u64
1961+perf_event_pause(struct perf_event *event, bool reset) { return 0; }
1962+static inline int
1963+perf_exclude_event(struct perf_event *event, struct pt_regs *regs) { return 0; }
1964+
1965+#endif /* !CONFIG_PERF_EVENTS */
19301966
19311967 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
19321968 extern void perf_restore_debug_store(void);
@@ -1934,31 +1970,31 @@ extern void perf_restore_debug_store(void); · 1 unmodified line
19341970 static inline void perf_restore_debug_store(void) { }
19351971 #endif
19361972
1937−#define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
1973+#define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
19381974
19391975 struct perf_pmu_events_attr {
1940− struct device_attribute attr;
1941− u64 id;
1942− const char *event_str;
1976+ struct device_attribute attr;
1977+ u64 id;
1978+ const char *event_str;
19431979 };
19441980
19451981 struct perf_pmu_events_ht_attr {
1946− struct device_attribute attr;
1947− u64 id;
1948− const char *event_str_ht;
1949− const char *event_str_noht;
1982+ struct device_attribute attr;
1983+ u64 id;
1984+ const char *event_str_ht;
1985+ const char *event_str_noht;
19501986 };
19511987
19521988 struct perf_pmu_events_hybrid_attr {
1953− struct device_attribute attr;
1954− u64 id;
1955− const char *event_str;
1956− u64 pmu_type;
1989+ struct device_attribute attr;
1990+ u64 id;
1991+ const char *event_str;
1992+ u64 pmu_type;
19571993 };
19581994
19591995 struct perf_pmu_format_hybrid_attr {
1960− struct device_attribute attr;
1961− u64 pmu_type;
1996+ struct device_attribute attr;
1997+ u64 pmu_type;
19621998 };
19631999
19642000 ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
@@ -2000,11 +2036,11 @@ static struct device_attribute format_attr_##_name = __ATTR_RO(_name) · 35 unmodified lines
20002036
20012037 /* Performance counter hotplug functions */
20022038 #ifdef CONFIG_PERF_EVENTS
2003−int perf_event_init_cpu(unsigned int cpu);
2004−int perf_event_exit_cpu(unsigned int cpu);
2039+extern int perf_event_init_cpu(unsigned int cpu);
2040+extern int perf_event_exit_cpu(unsigned int cpu);
20052041 #else
2006−#define perf_event_init_cpu NULL
2007−#define perf_event_exit_cpu NULL
2042+# define perf_event_init_cpu NULL
2043+# define perf_event_exit_cpu NULL
20082044 #endif
20092045
20102046 extern void arch_perf_update_userpage(struct perf_event *event,
include/uapi/linux/perf_event.h+334−323
@@ -39,18 +39,21 @@ enum perf_type_id { · 38 unmodified lines
3939
4040 /*
4141 * attr.config layout for type PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE
42+ *
4243 * PERF_TYPE_HARDWARE: 0xEEEEEEEE000000AA
4344 * AA: hardware event ID
4445 * EEEEEEEE: PMU type ID
46+ *
4547 * PERF_TYPE_HW_CACHE: 0xEEEEEEEE00DDCCBB
4648 * BB: hardware cache ID
4749 * CC: hardware cache op ID
4850 * DD: hardware cache op result ID
4951 * EEEEEEEE: PMU type ID
50− * If the PMU type ID is 0, the PERF_TYPE_RAW will be applied.
52+ *
53+ * If the PMU type ID is 0, PERF_TYPE_RAW will be applied.
5154 */
52−#define PERF_PMU_TYPE_SHIFT 32
53−#define PERF_HW_EVENT_MASK 0xffffffff
55+#define PERF_PMU_TYPE_SHIFT 32
56+#define PERF_HW_EVENT_MASK 0xffffffff
5457
5558 /*
5659 * Generalized performance event event_id types, used by the
@@ -112,7 +115,7 @@ enum perf_hw_cache_op_result_id { · 55 unmodified lines
112115 /*
113116 * Special "software" events provided by the kernel, even if the hardware
114117 * does not support performance events. These events measure various
115− * physical and sw events of the kernel (and allow the profiling of them as
118+ * physical and SW events of the kernel (and allow the profiling of them as
116119 * well):
117120 */
118121 enum perf_sw_ids {
@@ -167,8 +170,9 @@ enum perf_event_sample_format { · 48 unmodified lines
167170 };
168171
169172 #define PERF_SAMPLE_WEIGHT_TYPE (PERF_SAMPLE_WEIGHT | PERF_SAMPLE_WEIGHT_STRUCT)
173+
170174 /*
171− * values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set
175+ * Values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set.
172176 *
173177 * If the user does not pass priv level information via branch_sample_type,
174178 * the kernel uses the event's priv level. Branch and event priv levels do
@@ -178,20 +182,20 @@ enum perf_event_sample_format { · 3 unmodified lines
178182 * of branches and therefore it supersedes all the other types.
179183 */
180184 enum perf_branch_sample_type_shift {
181− PERF_SAMPLE_BRANCH_USER_SHIFT = 0, /* user branches */
182− PERF_SAMPLE_BRANCH_KERNEL_SHIFT = 1, /* kernel branches */
183− PERF_SAMPLE_BRANCH_HV_SHIFT = 2, /* hypervisor branches */
184−
185− PERF_SAMPLE_BRANCH_ANY_SHIFT = 3, /* any branch types */
186− PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT = 4, /* any call branch */
187− PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT = 5, /* any return branch */
188− PERF_SAMPLE_BRANCH_IND_CALL_SHIFT = 6, /* indirect calls */
189− PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT = 7, /* transaction aborts */
190− PERF_SAMPLE_BRANCH_IN_TX_SHIFT = 8, /* in transaction */
191− PERF_SAMPLE_BRANCH_NO_TX_SHIFT = 9, /* not in transaction */
185+ PERF_SAMPLE_BRANCH_USER_SHIFT = 0, /* user branches */
186+ PERF_SAMPLE_BRANCH_KERNEL_SHIFT = 1, /* kernel branches */
187+ PERF_SAMPLE_BRANCH_HV_SHIFT = 2, /* hypervisor branches */
188+
189+ PERF_SAMPLE_BRANCH_ANY_SHIFT = 3, /* any branch types */
190+ PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT = 4, /* any call branch */
191+ PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT = 5, /* any return branch */
192+ PERF_SAMPLE_BRANCH_IND_CALL_SHIFT = 6, /* indirect calls */
193+ PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT = 7, /* transaction aborts */
194+ PERF_SAMPLE_BRANCH_IN_TX_SHIFT = 8, /* in transaction */
195+ PERF_SAMPLE_BRANCH_NO_TX_SHIFT = 9, /* not in transaction */
192196 PERF_SAMPLE_BRANCH_COND_SHIFT = 10, /* conditional branches */
193197
194− PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* call/ret stack */
198+ PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* CALL/RET stack */
195199 PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT = 12, /* indirect jumps */
196200 PERF_SAMPLE_BRANCH_CALL_SHIFT = 13, /* direct call */
197201
@@ -210,96 +214,95 @@ enum perf_branch_sample_type_shift { · 12 unmodified lines
210214 };
211215
212216 enum perf_branch_sample_type {
213− PERF_SAMPLE_BRANCH_USER = 1U << PERF_SAMPLE_BRANCH_USER_SHIFT,
214− PERF_SAMPLE_BRANCH_KERNEL = 1U << PERF_SAMPLE_BRANCH_KERNEL_SHIFT,
215− PERF_SAMPLE_BRANCH_HV = 1U << PERF_SAMPLE_BRANCH_HV_SHIFT,
217+ PERF_SAMPLE_BRANCH_USER = 1U << PERF_SAMPLE_BRANCH_USER_SHIFT,
218+ PERF_SAMPLE_BRANCH_KERNEL = 1U << PERF_SAMPLE_BRANCH_KERNEL_SHIFT,
219+ PERF_SAMPLE_BRANCH_HV = 1U << PERF_SAMPLE_BRANCH_HV_SHIFT,
216220
217− PERF_SAMPLE_BRANCH_ANY = 1U << PERF_SAMPLE_BRANCH_ANY_SHIFT,
218− PERF_SAMPLE_BRANCH_ANY_CALL = 1U << PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,
219− PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,
220− PERF_SAMPLE_BRANCH_IND_CALL = 1U << PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,
221− PERF_SAMPLE_BRANCH_ABORT_TX = 1U << PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,
222− PERF_SAMPLE_BRANCH_IN_TX = 1U << PERF_SAMPLE_BRANCH_IN_TX_SHIFT,
223− PERF_SAMPLE_BRANCH_NO_TX = 1U << PERF_SAMPLE_BRANCH_NO_TX_SHIFT,
224− PERF_SAMPLE_BRANCH_COND = 1U << PERF_SAMPLE_BRANCH_COND_SHIFT,
221+ PERF_SAMPLE_BRANCH_ANY = 1U << PERF_SAMPLE_BRANCH_ANY_SHIFT,
222+ PERF_SAMPLE_BRANCH_ANY_CALL = 1U << PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,
223+ PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,
224+ PERF_SAMPLE_BRANCH_IND_CALL = 1U << PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,
225+ PERF_SAMPLE_BRANCH_ABORT_TX = 1U << PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,
226+ PERF_SAMPLE_BRANCH_IN_TX = 1U << PERF_SAMPLE_BRANCH_IN_TX_SHIFT,
227+ PERF_SAMPLE_BRANCH_NO_TX = 1U << PERF_SAMPLE_BRANCH_NO_TX_SHIFT,
228+ PERF_SAMPLE_BRANCH_COND = 1U << PERF_SAMPLE_BRANCH_COND_SHIFT,
225229
226− PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
227− PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
228− PERF_SAMPLE_BRANCH_CALL = 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT,
230+ PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
231+ PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
232+ PERF_SAMPLE_BRANCH_CALL = 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT,
229233
230− PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,
231− PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT,
234+ PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,
235+ PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT,
232236
233− PERF_SAMPLE_BRANCH_TYPE_SAVE =
234− 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT,
237+ PERF_SAMPLE_BRANCH_TYPE_SAVE = 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT,
235238
236− PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
239+ PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
237240
238− PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
241+ PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
239242
240− PERF_SAMPLE_BRANCH_COUNTERS = 1U << PERF_SAMPLE_BRANCH_COUNTERS_SHIFT,
243+ PERF_SAMPLE_BRANCH_COUNTERS = 1U << PERF_SAMPLE_BRANCH_COUNTERS_SHIFT,
241244
242− PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
245+ PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
243246 };
244247
245248 /*
246− * Common flow change classification
249+ * Common control flow change classifications:
247250 */
248251 enum {
249− PERF_BR_UNKNOWN = 0, /* unknown */
250− PERF_BR_COND = 1, /* conditional */
251− PERF_BR_UNCOND = 2, /* unconditional */
252− PERF_BR_IND = 3, /* indirect */
253− PERF_BR_CALL = 4, /* function call */
254− PERF_BR_IND_CALL = 5, /* indirect function call */
255− PERF_BR_RET = 6, /* function return */
256− PERF_BR_SYSCALL = 7, /* syscall */
257− PERF_BR_SYSRET = 8, /* syscall return */
258− PERF_BR_COND_CALL = 9, /* conditional function call */
259− PERF_BR_COND_RET = 10, /* conditional function return */
260− PERF_BR_ERET = 11, /* exception return */
261− PERF_BR_IRQ = 12, /* irq */
262− PERF_BR_SERROR = 13, /* system error */
263− PERF_BR_NO_TX = 14, /* not in transaction */
264− PERF_BR_EXTEND_ABI = 15, /* extend ABI */
252+ PERF_BR_UNKNOWN = 0, /* Unknown */
253+ PERF_BR_COND = 1, /* Conditional */
254+ PERF_BR_UNCOND = 2, /* Unconditional */
255+ PERF_BR_IND = 3, /* Indirect */
256+ PERF_BR_CALL = 4, /* Function call */
257+ PERF_BR_IND_CALL = 5, /* Indirect function call */
258+ PERF_BR_RET = 6, /* Function return */
259+ PERF_BR_SYSCALL = 7, /* Syscall */
260+ PERF_BR_SYSRET = 8, /* Syscall return */
261+ PERF_BR_COND_CALL = 9, /* Conditional function call */
262+ PERF_BR_COND_RET = 10, /* Conditional function return */
263+ PERF_BR_ERET = 11, /* Exception return */
264+ PERF_BR_IRQ = 12, /* IRQ */
265+ PERF_BR_SERROR = 13, /* System error */
266+ PERF_BR_NO_TX = 14, /* Not in transaction */
267+ PERF_BR_EXTEND_ABI = 15, /* Extend ABI */
265268 PERF_BR_MAX,
266269 };
267270
268271 /*
269− * Common branch speculation outcome classification
272+ * Common branch speculation outcome classifications:
270273 */
271274 enum {
272− PERF_BR_SPEC_NA = 0, /* Not available */
273− PERF_BR_SPEC_WRONG_PATH = 1, /* Speculative but on wrong path */
274− PERF_BR_NON_SPEC_CORRECT_PATH = 2, /* Non-speculative but on correct path */
275− PERF_BR_SPEC_CORRECT_PATH = 3, /* Speculative and on correct path */
275+ PERF_BR_SPEC_NA = 0, /* Not available */
276+ PERF_BR_SPEC_WRONG_PATH = 1, /* Speculative but on wrong path */
277+ PERF_BR_NON_SPEC_CORRECT_PATH = 2, /* Non-speculative but on correct path */
278+ PERF_BR_SPEC_CORRECT_PATH = 3, /* Speculative and on correct path */
276279 PERF_BR_SPEC_MAX,
277280 };
278281
279282 enum {
280− PERF_BR_NEW_FAULT_ALGN = 0, /* Alignment fault */
281− PERF_BR_NEW_FAULT_DATA = 1, /* Data fault */
282− PERF_BR_NEW_FAULT_INST = 2, /* Inst fault */
283− PERF_BR_NEW_ARCH_1 = 3, /* Architecture specific */
284− PERF_BR_NEW_ARCH_2 = 4, /* Architecture specific */
285− PERF_BR_NEW_ARCH_3 = 5, /* Architecture specific */
286− PERF_BR_NEW_ARCH_4 = 6, /* Architecture specific */
287− PERF_BR_NEW_ARCH_5 = 7, /* Architecture specific */
283+ PERF_BR_NEW_FAULT_ALGN = 0, /* Alignment fault */
284+ PERF_BR_NEW_FAULT_DATA = 1, /* Data fault */
285+ PERF_BR_NEW_FAULT_INST = 2, /* Inst fault */
286+ PERF_BR_NEW_ARCH_1 = 3, /* Architecture specific */
287+ PERF_BR_NEW_ARCH_2 = 4, /* Architecture specific */
288+ PERF_BR_NEW_ARCH_3 = 5, /* Architecture specific */
289+ PERF_BR_NEW_ARCH_4 = 6, /* Architecture specific */
290+ PERF_BR_NEW_ARCH_5 = 7, /* Architecture specific */
288291 PERF_BR_NEW_MAX,
289292 };
290293
291294 enum {
292− PERF_BR_PRIV_UNKNOWN = 0,
293− PERF_BR_PRIV_USER = 1,
294− PERF_BR_PRIV_KERNEL = 2,
295− PERF_BR_PRIV_HV = 3,
295+ PERF_BR_PRIV_UNKNOWN = 0,
296+ PERF_BR_PRIV_USER = 1,
297+ PERF_BR_PRIV_KERNEL = 2,
298+ PERF_BR_PRIV_HV = 3,
296299 };
297300
298−#define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1
299−#define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2
300−#define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3
301−#define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4
302−#define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5
301+#define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1
302+#define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2
303+#define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3
304+#define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4
305+#define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5
303306
304307 #define PERF_SAMPLE_BRANCH_PLM_ALL \
305308 (PERF_SAMPLE_BRANCH_USER|\
@@ -310,9 +313,9 @@ enum { · 4 unmodified lines
310313 * Values to determine ABI of the registers dump.
311314 */
312315 enum perf_sample_regs_abi {
313− PERF_SAMPLE_REGS_ABI_NONE = 0,
314− PERF_SAMPLE_REGS_ABI_32 = 1,
315− PERF_SAMPLE_REGS_ABI_64 = 2,
316+ PERF_SAMPLE_REGS_ABI_NONE = 0,
317+ PERF_SAMPLE_REGS_ABI_32 = 1,
318+ PERF_SAMPLE_REGS_ABI_64 = 2,
316319 };
317320
318321 /*
@@ -320,21 +323,21 @@ enum perf_sample_regs_abi { · 1 unmodified line
320323 * abort events. Multiple bits can be set.
321324 */
322325 enum {
323− PERF_TXN_ELISION = (1 << 0), /* From elision */
324− PERF_TXN_TRANSACTION = (1 << 1), /* From transaction */
325− PERF_TXN_SYNC = (1 << 2), /* Instruction is related */
326− PERF_TXN_ASYNC = (1 << 3), /* Instruction not related */
327− PERF_TXN_RETRY = (1 << 4), /* Retry possible */
328− PERF_TXN_CONFLICT = (1 << 5), /* Conflict abort */
329− PERF_TXN_CAPACITY_WRITE = (1 << 6), /* Capacity write abort */
330− PERF_TXN_CAPACITY_READ = (1 << 7), /* Capacity read abort */
326+ PERF_TXN_ELISION = (1 << 0), /* From elision */
327+ PERF_TXN_TRANSACTION = (1 << 1), /* From transaction */
328+ PERF_TXN_SYNC = (1 << 2), /* Instruction is related */
329+ PERF_TXN_ASYNC = (1 << 3), /* Instruction is not related */
330+ PERF_TXN_RETRY = (1 << 4), /* Retry possible */
331+ PERF_TXN_CONFLICT = (1 << 5), /* Conflict abort */
332+ PERF_TXN_CAPACITY_WRITE = (1 << 6), /* Capacity write abort */
333+ PERF_TXN_CAPACITY_READ = (1 << 7), /* Capacity read abort */
331334
332− PERF_TXN_MAX = (1 << 8), /* non-ABI */
335+ PERF_TXN_MAX = (1 << 8), /* non-ABI */
333336
334− /* bits 32..63 are reserved for the abort code */
337+ /* Bits 32..63 are reserved for the abort code */
335338
336− PERF_TXN_ABORT_MASK = (0xffffffffULL << 32),
337− PERF_TXN_ABORT_SHIFT = 32,
339+ PERF_TXN_ABORT_MASK = (0xffffffffULL << 32),
340+ PERF_TXN_ABORT_SHIFT = 32,
338341 };
339342
340343 /*
@@ -369,24 +372,22 @@ enum perf_event_read_format { · 28 unmodified lines
369372 PERF_FORMAT_MAX = 1U << 5, /* non-ABI */
370373 };
371374
372−#define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
373−#define PERF_ATTR_SIZE_VER1 72 /* add: config2 */
374−#define PERF_ATTR_SIZE_VER2 80 /* add: branch_sample_type */
375−#define PERF_ATTR_SIZE_VER3 96 /* add: sample_regs_user */
376− /* add: sample_stack_user */
377−#define PERF_ATTR_SIZE_VER4 104 /* add: sample_regs_intr */
378−#define PERF_ATTR_SIZE_VER5 112 /* add: aux_watermark */
379−#define PERF_ATTR_SIZE_VER6 120 /* add: aux_sample_size */
380−#define PERF_ATTR_SIZE_VER7 128 /* add: sig_data */
381−#define PERF_ATTR_SIZE_VER8 136 /* add: config3 */
375+#define PERF_ATTR_SIZE_VER0 64 /* Size of first published 'struct perf_event_attr' */
376+#define PERF_ATTR_SIZE_VER1 72 /* Add: config2 */
377+#define PERF_ATTR_SIZE_VER2 80 /* Add: branch_sample_type */
378+#define PERF_ATTR_SIZE_VER3 96 /* Add: sample_regs_user */
379+ /* Add: sample_stack_user */
380+#define PERF_ATTR_SIZE_VER4 104 /* Add: sample_regs_intr */
381+#define PERF_ATTR_SIZE_VER5 112 /* Add: aux_watermark */
382+#define PERF_ATTR_SIZE_VER6 120 /* Add: aux_sample_size */
383+#define PERF_ATTR_SIZE_VER7 128 /* Add: sig_data */
384+#define PERF_ATTR_SIZE_VER8 136 /* Add: config3 */
382385
383386 /*
384− * Hardware event_id to monitor via a performance monitoring event:
385− *
386− * @sample_max_stack: Max number of frame pointers in a callchain,
387− * should be < /proc/sys/kernel/perf_event_max_stack
388− * Max number of entries of branch stack
389− * should be < hardware limit
387+ * 'struct perf_event_attr' contains various attributes that define
388+ * a performance event - most of them hardware related configuration
389+ * details, but also a lot of behavioral switches and values implemented
390+ * by the kernel.
390391 */
391392 struct perf_event_attr {
392393
@@ -396,7 +397,7 @@ struct perf_event_attr { · 3 unmodified lines
396397 __u32 type;
397398
398399 /*
399− * Size of the attr structure, for fwd/bwd compat.
400+ * Size of the attr structure, for forward/backwards compatibility.
400401 */
401402 __u32 size;
402403
@@ -451,21 +452,21 @@ struct perf_event_attr { · 48 unmodified lines
451452 comm_exec : 1, /* flag comm events that are due to an exec */
452453 use_clockid : 1, /* use @clockid for time fields */
453454 context_switch : 1, /* context switch data */
454− write_backward : 1, /* Write ring buffer from end to beginning */
455+ write_backward : 1, /* write ring buffer from end to beginning */
455456 namespaces : 1, /* include namespaces data */
456457 ksymbol : 1, /* include ksymbol events */
457− bpf_event : 1, /* include bpf events */
458+ bpf_event : 1, /* include BPF events */
458459 aux_output : 1, /* generate AUX records instead of events */
459460 cgroup : 1, /* include cgroup events */
460461 text_poke : 1, /* include text poke events */
461− build_id : 1, /* use build id in mmap2 events */
462+ build_id : 1, /* use build ID in mmap2 events */
462463 inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD */
463464 remove_on_exec : 1, /* event is removed from task on exec */
464465 sigtrap : 1, /* send synchronous SIGTRAP on event */
465466 __reserved_1 : 26;
466467
467468 union {
468− __u32 wakeup_events; /* wakeup every n events */
469+ __u32 wakeup_events; /* wake up every n events */
469470 __u32 wakeup_watermark; /* bytes before wakeup */
470471 };
471472
@@ -474,13 +475,13 @@ struct perf_event_attr { · 2 unmodified lines
474475 __u64 bp_addr;
475476 __u64 kprobe_func; /* for perf_kprobe */
476477 __u64 uprobe_path; /* for perf_uprobe */
477− __u64 config1; /* extension of config */
478+ __u64 config1; /* extension of config */
478479 };
479480 union {
480481 __u64 bp_len;
481− __u64 kprobe_addr; /* when kprobe_func == NULL */
482+ __u64 kprobe_addr; /* when kprobe_func == NULL */
482483 __u64 probe_offset; /* for perf_[k,u]probe */
483− __u64 config2; /* extension of config1 */
484+ __u64 config2; /* extension of config1 */
484485 };
485486 __u64 branch_sample_type; /* enum perf_branch_sample_type */
486487
@@ -510,7 +511,16 @@ struct perf_event_attr { · 23 unmodified lines
510511 * Wakeup watermark for AUX area
511512 */
512513 __u32 aux_watermark;
514+
515+ /*
516+ * Max number of frame pointers in a callchain, should be
517+ * lower than /proc/sys/kernel/perf_event_max_stack.
518+ *
519+ * Max number of entries of branch stack should be lower
520+ * than the hardware limit.
521+ */
513522 __u16 sample_max_stack;
523+
514524 __u16 __reserved_2;
515525 __u32 aux_sample_size;
516526
@@ -537,7 +547,7 @@ struct perf_event_attr { · 20 unmodified lines
537547
538548 /*
539549 * Structure used by below PERF_EVENT_IOC_QUERY_BPF command
540− * to query bpf programs attached to the same perf tracepoint
550+ * to query BPF programs attached to the same perf tracepoint
541551 * as the given perf event.
542552 */
543553 struct perf_event_query_bpf {
@@ -559,21 +569,21 @@ struct perf_event_query_bpf { · 15 unmodified lines
559569 /*
560570 * Ioctls that can be done on a perf event fd:
561571 */
562−#define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
563−#define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
564−#define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
565−#define PERF_EVENT_IOC_RESET _IO ('$', 3)
566−#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
567−#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
568−#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
569−#define PERF_EVENT_IOC_ID _IOR('$', 7, __u64 *)
570−#define PERF_EVENT_IOC_SET_BPF _IOW('$', 8, __u32)
571−#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32)
572+#define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
573+#define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
574+#define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
575+#define PERF_EVENT_IOC_RESET _IO ('$', 3)
576+#define PERF_EVENT_IOC_PERIOD _IOW ('$', 4, __u64)
577+#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
578+#define PERF_EVENT_IOC_SET_FILTER _IOW ('$', 6, char *)
579+#define PERF_EVENT_IOC_ID _IOR ('$', 7, __u64 *)
580+#define PERF_EVENT_IOC_SET_BPF _IOW ('$', 8, __u32)
581+#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW ('$', 9, __u32)
572582 #define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *)
573−#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *)
583+#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW ('$', 11, struct perf_event_attr *)
574584
575585 enum perf_event_ioc_flags {
576− PERF_IOC_FLAG_GROUP = 1U << 0,
586+ PERF_IOC_FLAG_GROUP = 1U << 0,
577587 };
578588
579589 /*
@@ -584,7 +594,7 @@ struct perf_event_mmap_page { · 4 unmodified lines
584594 __u32 compat_version; /* lowest version this is compat with */
585595
586596 /*
587− * Bits needed to read the hw events in user-space.
597+ * Bits needed to read the HW events in user-space.
588598 *
589599 * u32 seq, time_mult, time_shift, index, width;
590600 * u64 count, enabled, running;
@@ -622,7 +632,7 @@ struct perf_event_mmap_page { · 31 unmodified lines
622632 __u32 index; /* hardware event identifier */
623633 __s64 offset; /* add to hardware event value */
624634 __u64 time_enabled; /* time event active */
625− __u64 time_running; /* time event on cpu */
635+ __u64 time_running; /* time event on CPU */
626636 union {
627637 __u64 capabilities;
628638 struct {
@@ -650,7 +660,7 @@ struct perf_event_mmap_page { · 21 unmodified lines
650660
651661 /*
652662 * If cap_usr_time the below fields can be used to compute the time
653− * delta since time_enabled (in ns) using rdtsc or similar.
663+ * delta since time_enabled (in ns) using RDTSC or similar.
654664 *
655665 * u64 quot, rem;
656666 * u64 delta;
@@ -723,7 +733,7 @@ struct perf_event_mmap_page { · 66 unmodified lines
723733 * after reading this value.
724734 *
725735 * When the mapping is PROT_WRITE the @data_tail value should be
726− * written by userspace to reflect the last read data, after issueing
736+ * written by user-space to reflect the last read data, after issuing
727737 * an smp_mb() to separate the data read from the ->data_tail store.
728738 * In this case the kernel will not over-write unread data.
729739 *
@@ -739,7 +749,7 @@ struct perf_event_mmap_page { · 9 unmodified lines
739749
740750 /*
741751 * AUX area is defined by aux_{offset,size} fields that should be set
742− * by the userspace, so that
752+ * by the user-space, so that
743753 *
744754 * aux_offset >= data_offset + data_size
745755 *
@@ -813,7 +823,7 @@ struct perf_event_mmap_page { · 67 unmodified lines
813823 * Indicates that thread was preempted in TASK_RUNNING state.
814824 *
815825 * PERF_RECORD_MISC_MMAP_BUILD_ID:
816− * Indicates that mmap2 event carries build id data.
826+ * Indicates that mmap2 event carries build ID data.
817827 */
818828 #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
819829 #define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
@@ -824,26 +834,26 @@ struct perf_event_mmap_page { · 4 unmodified lines
824834 #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15)
825835
826836 struct perf_event_header {
827− __u32 type;
828− __u16 misc;
829− __u16 size;
837+ __u32 type;
838+ __u16 misc;
839+ __u16 size;
830840 };
831841
832842 struct perf_ns_link_info {
833− __u64 dev;
834− __u64 ino;
843+ __u64 dev;
844+ __u64 ino;
835845 };
836846
837847 enum {
838− NET_NS_INDEX = 0,
839− UTS_NS_INDEX = 1,
840− IPC_NS_INDEX = 2,
841− PID_NS_INDEX = 3,
842− USER_NS_INDEX = 4,
843− MNT_NS_INDEX = 5,
844− CGROUP_NS_INDEX = 6,
845−
846− NR_NAMESPACES, /* number of available namespaces */
848+ NET_NS_INDEX = 0,
849+ UTS_NS_INDEX = 1,
850+ IPC_NS_INDEX = 2,
851+ PID_NS_INDEX = 3,
852+ USER_NS_INDEX = 4,
853+ MNT_NS_INDEX = 5,
854+ CGROUP_NS_INDEX = 6,
855+
856+ NR_NAMESPACES, /* number of available namespaces */
847857 };
848858
849859 enum perf_event_type {
@@ -859,11 +869,11 @@ enum perf_event_type { · 9 unmodified lines
859869 * optional fields being ignored.
860870 *
861871 * struct sample_id {
862− * { u32 pid, tid; } && PERF_SAMPLE_TID
863− * { u64 time; } && PERF_SAMPLE_TIME
864− * { u64 id; } && PERF_SAMPLE_ID
865− * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
866− * { u32 cpu, res; } && PERF_SAMPLE_CPU
872+ * { u32 pid, tid; } && PERF_SAMPLE_TID
873+ * { u64 time; } && PERF_SAMPLE_TIME
874+ * { u64 id; } && PERF_SAMPLE_ID
875+ * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
876+ * { u32 cpu, res; } && PERF_SAMPLE_CPU
867877 * { u64 id; } && PERF_SAMPLE_IDENTIFIER
868878 * } && perf_event_attr::sample_id_all
869879 *
@@ -874,7 +884,7 @@ enum perf_event_type { · 4 unmodified lines
874884
875885 /*
876886 * The MMAP events record the PROT_EXEC mappings so that we can
877− * correlate userspace IPs to code. They have the following structure:
887+ * correlate user-space IPs to code. They have the following structure:
878888 *
879889 * struct {
880890 * struct perf_event_header header;
@@ -884,7 +894,7 @@ enum perf_event_type { · 3 unmodified lines
884894 * u64 len;
885895 * u64 pgoff;
886896 * char filename[];
887− * struct sample_id sample_id;
897+ * struct sample_id sample_id;
888898 * };
889899 */
890900 PERF_RECORD_MMAP = 1,
@@ -894,7 +904,7 @@ enum perf_event_type { · 3 unmodified lines
894904 * struct perf_event_header header;
895905 * u64 id;
896906 * u64 lost;
897− * struct sample_id sample_id;
907+ * struct sample_id sample_id;
898908 * };
899909 */
900910 PERF_RECORD_LOST = 2,
@@ -905,7 +915,7 @@ enum perf_event_type { · 4 unmodified lines
905915 *
906916 * u32 pid, tid;
907917 * char comm[];
908− * struct sample_id sample_id;
918+ * struct sample_id sample_id;
909919 * };
910920 */
911921 PERF_RECORD_COMM = 3,
@@ -916,7 +926,7 @@ enum perf_event_type { · 4 unmodified lines
916926 * u32 pid, ppid;
917927 * u32 tid, ptid;
918928 * u64 time;
919− * struct sample_id sample_id;
929+ * struct sample_id sample_id;
920930 * };
921931 */
922932 PERF_RECORD_EXIT = 4,
@@ -927,7 +937,7 @@ enum perf_event_type { · 4 unmodified lines
927937 * u64 time;
928938 * u64 id;
929939 * u64 stream_id;
930− * struct sample_id sample_id;
940+ * struct sample_id sample_id;
931941 * };
932942 */
933943 PERF_RECORD_THROTTLE = 5,
@@ -939,7 +949,7 @@ enum perf_event_type { · 5 unmodified lines
939949 * u32 pid, ppid;
940950 * u32 tid, ptid;
941951 * u64 time;
942− * struct sample_id sample_id;
952+ * struct sample_id sample_id;
943953 * };
944954 */
945955 PERF_RECORD_FORK = 7,
@@ -950,7 +960,7 @@ enum perf_event_type { · 4 unmodified lines
950960 * u32 pid, tid;
951961 *
952962 * struct read_format values;
953− * struct sample_id sample_id;
963+ * struct sample_id sample_id;
954964 * };
955965 */
956966 PERF_RECORD_READ = 8,
@@ -1005,12 +1015,12 @@ enum perf_event_type { · 48 unmodified lines
10051015 * { u64 counters; } cntr[nr] && PERF_SAMPLE_BRANCH_COUNTERS
10061016 * } && PERF_SAMPLE_BRANCH_STACK
10071017 *
1008− * { u64 abi; # enum perf_sample_regs_abi
1009− * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER
1018+ * { u64 abi; # enum perf_sample_regs_abi
1019+ * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER
10101020 *
1011− * { u64 size;
1012− * char data[size];
1013− * u64 dyn_size; } && PERF_SAMPLE_STACK_USER
1021+ * { u64 size;
1022+ * char data[size];
1023+ * u64 dyn_size; } && PERF_SAMPLE_STACK_USER
10141024 *
10151025 * { union perf_sample_weight
10161026 * {
@@ -1035,10 +1045,11 @@ enum perf_event_type { · 18 unmodified lines
10351045 * { u64 abi; # enum perf_sample_regs_abi
10361046 * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
10371047 * { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR
1038− * { u64 size;
1039− * char data[size]; } && PERF_SAMPLE_AUX
1048+ * { u64 cgroup;} && PERF_SAMPLE_CGROUP
10401049 * { u64 data_page_size;} && PERF_SAMPLE_DATA_PAGE_SIZE
10411050 * { u64 code_page_size;} && PERF_SAMPLE_CODE_PAGE_SIZE
1051+ * { u64 size;
1052+ * char data[size]; } && PERF_SAMPLE_AUX
10421053 * };
10431054 */
10441055 PERF_RECORD_SAMPLE = 9,
@@ -1070,7 +1081,7 @@ enum perf_event_type { · 25 unmodified lines
10701081 * };
10711082 * u32 prot, flags;
10721083 * char filename[];
1073− * struct sample_id sample_id;
1084+ * struct sample_id sample_id;
10741085 * };
10751086 */
10761087 PERF_RECORD_MMAP2 = 10,
@@ -1079,12 +1090,12 @@ enum perf_event_type { · 2 unmodified lines
10791090 * Records that new data landed in the AUX buffer part.
10801091 *
10811092 * struct {
1082− * struct perf_event_header header;
1093+ * struct perf_event_header header;
10831094 *
1084− * u64 aux_offset;
1085− * u64 aux_size;
1095+ * u64 aux_offset;
1096+ * u64 aux_size;
10861097 * u64 flags;
1087− * struct sample_id sample_id;
1098+ * struct sample_id sample_id;
10881099 * };
10891100 */
10901101 PERF_RECORD_AUX = 11,
@@ -1167,7 +1178,7 @@ enum perf_event_type { · 76 unmodified lines
11671178 PERF_RECORD_KSYMBOL = 17,
11681179
11691180 /*
1170− * Record bpf events:
1181+ * Record BPF events:
11711182 * enum perf_bpf_event_type {
11721183 * PERF_BPF_EVENT_UNKNOWN = 0,
11731184 * PERF_BPF_EVENT_PROG_LOAD = 1,
@@ -1245,181 +1256,181 @@ enum perf_record_ksymbol_type { · 71 unmodified lines
12451256 #define PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER (1 << 0)
12461257
12471258 enum perf_bpf_event_type {
1248− PERF_BPF_EVENT_UNKNOWN = 0,
1249− PERF_BPF_EVENT_PROG_LOAD = 1,
1250− PERF_BPF_EVENT_PROG_UNLOAD = 2,
1251− PERF_BPF_EVENT_MAX, /* non-ABI */
1259+ PERF_BPF_EVENT_UNKNOWN = 0,
1260+ PERF_BPF_EVENT_PROG_LOAD = 1,
1261+ PERF_BPF_EVENT_PROG_UNLOAD = 2,
1262+ PERF_BPF_EVENT_MAX, /* non-ABI */
12521263 };
12531264
1254−#define PERF_MAX_STACK_DEPTH 127
1255−#define PERF_MAX_CONTEXTS_PER_STACK 8
1265+#define PERF_MAX_STACK_DEPTH 127
1266+#define PERF_MAX_CONTEXTS_PER_STACK 8
12561267
12571268 enum perf_callchain_context {
1258− PERF_CONTEXT_HV = (__u64)-32,
1259− PERF_CONTEXT_KERNEL = (__u64)-128,
1260− PERF_CONTEXT_USER = (__u64)-512,
1269+ PERF_CONTEXT_HV = (__u64)-32,
1270+ PERF_CONTEXT_KERNEL = (__u64)-128,
1271+ PERF_CONTEXT_USER = (__u64)-512,
12611272
1262− PERF_CONTEXT_GUEST = (__u64)-2048,
1263− PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
1264− PERF_CONTEXT_GUEST_USER = (__u64)-2560,
1273+ PERF_CONTEXT_GUEST = (__u64)-2048,
1274+ PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
1275+ PERF_CONTEXT_GUEST_USER = (__u64)-2560,
12651276
1266− PERF_CONTEXT_MAX = (__u64)-4095,
1277+ PERF_CONTEXT_MAX = (__u64)-4095,
12671278 };
12681279
12691280 /**
12701281 * PERF_RECORD_AUX::flags bits
12711282 */
1272−#define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */
1273−#define PERF_AUX_FLAG_OVERWRITE 0x02 /* snapshot from overwrite mode */
1274−#define PERF_AUX_FLAG_PARTIAL 0x04 /* record contains gaps */
1275−#define PERF_AUX_FLAG_COLLISION 0x08 /* sample collided with another */
1283+#define PERF_AUX_FLAG_TRUNCATED 0x0001 /* Record was truncated to fit */
1284+#define PERF_AUX_FLAG_OVERWRITE 0x0002 /* Snapshot from overwrite mode */
1285+#define PERF_AUX_FLAG_PARTIAL 0x0004 /* Record contains gaps */
1286+#define PERF_AUX_FLAG_COLLISION 0x0008 /* Sample collided with another */
12761287 #define PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK 0xff00 /* PMU specific trace format type */
12771288
12781289 /* CoreSight PMU AUX buffer formats */
1279−#define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000 /* Default for backward compatibility */
1280−#define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100 /* Raw format of the source */
1290+#define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000 /* Default for backward compatibility */
1291+#define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100 /* Raw format of the source */
12811292
1282−#define PERF_FLAG_FD_NO_GROUP (1UL << 0)
1283−#define PERF_FLAG_FD_OUTPUT (1UL << 1)
1284−#define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup id, per-cpu mode only */
1285−#define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */
1293+#define PERF_FLAG_FD_NO_GROUP (1UL << 0)
1294+#define PERF_FLAG_FD_OUTPUT (1UL << 1)
1295+#define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup ID, per-CPU mode only */
1296+#define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */
12861297
12871298 #if defined(__LITTLE_ENDIAN_BITFIELD)
12881299 union perf_mem_data_src {
12891300 __u64 val;
12901301 struct {
1291− __u64 mem_op:5, /* type of opcode */
1292− mem_lvl:14, /* memory hierarchy level */
1293− mem_snoop:5, /* snoop mode */
1294− mem_lock:2, /* lock instr */
1295− mem_dtlb:7, /* tlb access */
1296− mem_lvl_num:4, /* memory hierarchy level number */
1297− mem_remote:1, /* remote */
1298− mem_snoopx:2, /* snoop mode, ext */
1299− mem_blk:3, /* access blocked */
1300− mem_hops:3, /* hop level */
1301− mem_rsvd:18;
1302+ __u64 mem_op : 5, /* Type of opcode */
1303+ mem_lvl : 14, /* Memory hierarchy level */
1304+ mem_snoop : 5, /* Snoop mode */
1305+ mem_lock : 2, /* Lock instr */
1306+ mem_dtlb : 7, /* TLB access */
1307+ mem_lvl_num : 4, /* Memory hierarchy level number */
1308+ mem_remote : 1, /* Remote */
1309+ mem_snoopx : 2, /* Snoop mode, ext */
1310+ mem_blk : 3, /* Access blocked */
1311+ mem_hops : 3, /* Hop level */
1312+ mem_rsvd : 18;
13021313 };
13031314 };
13041315 #elif defined(__BIG_ENDIAN_BITFIELD)
13051316 union perf_mem_data_src {
13061317 __u64 val;
13071318 struct {
1308− __u64 mem_rsvd:18,
1309− mem_hops:3, /* hop level */
1310− mem_blk:3, /* access blocked */
1311− mem_snoopx:2, /* snoop mode, ext */
1312− mem_remote:1, /* remote */
1313− mem_lvl_num:4, /* memory hierarchy level number */
1314− mem_dtlb:7, /* tlb access */
1315− mem_lock:2, /* lock instr */
1316− mem_snoop:5, /* snoop mode */
1317− mem_lvl:14, /* memory hierarchy level */
1318− mem_op:5; /* type of opcode */
1319+ __u64 mem_rsvd : 18,
1320+ mem_hops : 3, /* Hop level */
1321+ mem_blk : 3, /* Access blocked */
1322+ mem_snoopx : 2, /* Snoop mode, ext */
1323+ mem_remote : 1, /* Remote */
1324+ mem_lvl_num : 4, /* Memory hierarchy level number */
1325+ mem_dtlb : 7, /* TLB access */
1326+ mem_lock : 2, /* Lock instr */
1327+ mem_snoop : 5, /* Snoop mode */
1328+ mem_lvl : 14, /* Memory hierarchy level */
1329+ mem_op : 5; /* Type of opcode */
13191330 };
13201331 };
13211332 #else
1322−#error "Unknown endianness"
1333+# error "Unknown endianness"
13231334 #endif
13241335
1325−/* type of opcode (load/store/prefetch,code) */
1326−#define PERF_MEM_OP_NA 0x01 /* not available */
1327−#define PERF_MEM_OP_LOAD 0x02 /* load instruction */
1328−#define PERF_MEM_OP_STORE 0x04 /* store instruction */
1329−#define PERF_MEM_OP_PFETCH 0x08 /* prefetch */
1330−#define PERF_MEM_OP_EXEC 0x10 /* code (execution) */
1331−#define PERF_MEM_OP_SHIFT 0
1336+/* Type of memory opcode: */
1337+#define PERF_MEM_OP_NA 0x0001 /* Not available */
1338+#define PERF_MEM_OP_LOAD 0x0002 /* Load instruction */
1339+#define PERF_MEM_OP_STORE 0x0004 /* Store instruction */
1340+#define PERF_MEM_OP_PFETCH 0x0008 /* Prefetch */
1341+#define PERF_MEM_OP_EXEC 0x0010 /* Code (execution) */
1342+#define PERF_MEM_OP_SHIFT 0
13321343
13331344 /*
1334− * PERF_MEM_LVL_* namespace being depricated to some extent in the
1345+ * The PERF_MEM_LVL_* namespace is being deprecated to some extent in
13351346 * favour of newer composite PERF_MEM_{LVLNUM_,REMOTE_,SNOOPX_} fields.
1336− * Supporting this namespace inorder to not break defined ABIs.
1347+ * We support this namespace in order to not break defined ABIs.
13371348 *
1338− * memory hierarchy (memory level, hit or miss)
1349+ * Memory hierarchy (memory level, hit or miss)
13391350 */
1340−#define PERF_MEM_LVL_NA 0x01 /* not available */
1341−#define PERF_MEM_LVL_HIT 0x02 /* hit level */
1342−#define PERF_MEM_LVL_MISS 0x04 /* miss level */
1343−#define PERF_MEM_LVL_L1 0x08 /* L1 */
1344−#define PERF_MEM_LVL_LFB 0x10 /* Line Fill Buffer */
1345−#define PERF_MEM_LVL_L2 0x20 /* L2 */
1346−#define PERF_MEM_LVL_L3 0x40 /* L3 */
1347−#define PERF_MEM_LVL_LOC_RAM 0x80 /* Local DRAM */
1348−#define PERF_MEM_LVL_REM_RAM1 0x100 /* Remote DRAM (1 hop) */
1349−#define PERF_MEM_LVL_REM_RAM2 0x200 /* Remote DRAM (2 hops) */
1350−#define PERF_MEM_LVL_REM_CCE1 0x400 /* Remote Cache (1 hop) */
1351−#define PERF_MEM_LVL_REM_CCE2 0x800 /* Remote Cache (2 hops) */
1352−#define PERF_MEM_LVL_IO 0x1000 /* I/O memory */
1353−#define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */
1354−#define PERF_MEM_LVL_SHIFT 5
1355−
1356−#define PERF_MEM_REMOTE_REMOTE 0x01 /* Remote */
1357−#define PERF_MEM_REMOTE_SHIFT 37
1358−
1359−#define PERF_MEM_LVLNUM_L1 0x01 /* L1 */
1360−#define PERF_MEM_LVLNUM_L2 0x02 /* L2 */
1361−#define PERF_MEM_LVLNUM_L3 0x03 /* L3 */
1362−#define PERF_MEM_LVLNUM_L4 0x04 /* L4 */
1363−#define PERF_MEM_LVLNUM_L2_MHB 0x05 /* L2 Miss Handling Buffer */
1364−#define PERF_MEM_LVLNUM_MSC 0x06 /* Memory-side Cache */
1365−/* 0x7 available */
1366−#define PERF_MEM_LVLNUM_UNC 0x08 /* Uncached */
1367−#define PERF_MEM_LVLNUM_CXL 0x09 /* CXL */
1368−#define PERF_MEM_LVLNUM_IO 0x0a /* I/O */
1369−#define PERF_MEM_LVLNUM_ANY_CACHE 0x0b /* Any cache */
1370−#define PERF_MEM_LVLNUM_LFB 0x0c /* LFB / L1 Miss Handling Buffer */
1371−#define PERF_MEM_LVLNUM_RAM 0x0d /* RAM */
1372−#define PERF_MEM_LVLNUM_PMEM 0x0e /* PMEM */
1373−#define PERF_MEM_LVLNUM_NA 0x0f /* N/A */
1374−
1375−#define PERF_MEM_LVLNUM_SHIFT 33
1376−
1377−/* snoop mode */
1378−#define PERF_MEM_SNOOP_NA 0x01 /* not available */
1379−#define PERF_MEM_SNOOP_NONE 0x02 /* no snoop */
1380−#define PERF_MEM_SNOOP_HIT 0x04 /* snoop hit */
1381−#define PERF_MEM_SNOOP_MISS 0x08 /* snoop miss */
1382−#define PERF_MEM_SNOOP_HITM 0x10 /* snoop hit modified */
1383−#define PERF_MEM_SNOOP_SHIFT 19
1384−
1385−#define PERF_MEM_SNOOPX_FWD 0x01 /* forward */
1386−#define PERF_MEM_SNOOPX_PEER 0x02 /* xfer from peer */
1387−#define PERF_MEM_SNOOPX_SHIFT 38
1388−
1389−/* locked instruction */
1390−#define PERF_MEM_LOCK_NA 0x01 /* not available */
1391−#define PERF_MEM_LOCK_LOCKED 0x02 /* locked transaction */
1392−#define PERF_MEM_LOCK_SHIFT 24
1351+#define PERF_MEM_LVL_NA 0x0001 /* Not available */
1352+#define PERF_MEM_LVL_HIT 0x0002 /* Hit level */
1353+#define PERF_MEM_LVL_MISS 0x0004 /* Miss level */
1354+#define PERF_MEM_LVL_L1 0x0008 /* L1 */
1355+#define PERF_MEM_LVL_LFB 0x0010 /* Line Fill Buffer */
1356+#define PERF_MEM_LVL_L2 0x0020 /* L2 */
1357+#define PERF_MEM_LVL_L3 0x0040 /* L3 */
1358+#define PERF_MEM_LVL_LOC_RAM 0x0080 /* Local DRAM */
1359+#define PERF_MEM_LVL_REM_RAM1 0x0100 /* Remote DRAM (1 hop) */
1360+#define PERF_MEM_LVL_REM_RAM2 0x0200 /* Remote DRAM (2 hops) */
1361+#define PERF_MEM_LVL_REM_CCE1 0x0400 /* Remote Cache (1 hop) */
1362+#define PERF_MEM_LVL_REM_CCE2 0x0800 /* Remote Cache (2 hops) */
1363+#define PERF_MEM_LVL_IO 0x1000 /* I/O memory */
1364+#define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */
1365+#define PERF_MEM_LVL_SHIFT 5
1366+
1367+#define PERF_MEM_REMOTE_REMOTE 0x0001 /* Remote */
1368+#define PERF_MEM_REMOTE_SHIFT 37
1369+
1370+#define PERF_MEM_LVLNUM_L1 0x0001 /* L1 */
1371+#define PERF_MEM_LVLNUM_L2 0x0002 /* L2 */
1372+#define PERF_MEM_LVLNUM_L3 0x0003 /* L3 */
1373+#define PERF_MEM_LVLNUM_L4 0x0004 /* L4 */
1374+#define PERF_MEM_LVLNUM_L2_MHB 0x0005 /* L2 Miss Handling Buffer */
1375+#define PERF_MEM_LVLNUM_MSC 0x0006 /* Memory-side Cache */
1376+/* 0x007 available */
1377+#define PERF_MEM_LVLNUM_UNC 0x0008 /* Uncached */
1378+#define PERF_MEM_LVLNUM_CXL 0x0009 /* CXL */
1379+#define PERF_MEM_LVLNUM_IO 0x000a /* I/O */
1380+#define PERF_MEM_LVLNUM_ANY_CACHE 0x000b /* Any cache */
1381+#define PERF_MEM_LVLNUM_LFB 0x000c /* LFB / L1 Miss Handling Buffer */
1382+#define PERF_MEM_LVLNUM_RAM 0x000d /* RAM */
1383+#define PERF_MEM_LVLNUM_PMEM 0x000e /* PMEM */
1384+#define PERF_MEM_LVLNUM_NA 0x000f /* N/A */
1385+
1386+#define PERF_MEM_LVLNUM_SHIFT 33
1387+
1388+/* Snoop mode */
1389+#define PERF_MEM_SNOOP_NA 0x0001 /* Not available */
1390+#define PERF_MEM_SNOOP_NONE 0x0002 /* No snoop */
1391+#define PERF_MEM_SNOOP_HIT 0x0004 /* Snoop hit */
1392+#define PERF_MEM_SNOOP_MISS 0x0008 /* Snoop miss */
1393+#define PERF_MEM_SNOOP_HITM 0x0010 /* Snoop hit modified */
1394+#define PERF_MEM_SNOOP_SHIFT 19
1395+
1396+#define PERF_MEM_SNOOPX_FWD 0x0001 /* Forward */
1397+#define PERF_MEM_SNOOPX_PEER 0x0002 /* Transfer from peer */
1398+#define PERF_MEM_SNOOPX_SHIFT 38
1399+
1400+/* Locked instruction */
1401+#define PERF_MEM_LOCK_NA 0x0001 /* Not available */
1402+#define PERF_MEM_LOCK_LOCKED 0x0002 /* Locked transaction */
1403+#define PERF_MEM_LOCK_SHIFT 24
13931404
13941405 /* TLB access */
1395−#define PERF_MEM_TLB_NA 0x01 /* not available */
1396−#define PERF_MEM_TLB_HIT 0x02 /* hit level */
1397−#define PERF_MEM_TLB_MISS 0x04 /* miss level */
1398−#define PERF_MEM_TLB_L1 0x08 /* L1 */
1399−#define PERF_MEM_TLB_L2 0x10 /* L2 */
1400−#define PERF_MEM_TLB_WK 0x20 /* Hardware Walker*/
1401−#define PERF_MEM_TLB_OS 0x40 /* OS fault handler */
1402−#define PERF_MEM_TLB_SHIFT 26
1406+#define PERF_MEM_TLB_NA 0x0001 /* Not available */
1407+#define PERF_MEM_TLB_HIT 0x0002 /* Hit level */
1408+#define PERF_MEM_TLB_MISS 0x0004 /* Miss level */
1409+#define PERF_MEM_TLB_L1 0x0008 /* L1 */
1410+#define PERF_MEM_TLB_L2 0x0010 /* L2 */
1411+#define PERF_MEM_TLB_WK 0x0020 /* Hardware Walker*/
1412+#define PERF_MEM_TLB_OS 0x0040 /* OS fault handler */
1413+#define PERF_MEM_TLB_SHIFT 26
14031414
14041415 /* Access blocked */
1405−#define PERF_MEM_BLK_NA 0x01 /* not available */
1406−#define PERF_MEM_BLK_DATA 0x02 /* data could not be forwarded */
1407−#define PERF_MEM_BLK_ADDR 0x04 /* address conflict */
1408−#define PERF_MEM_BLK_SHIFT 40
1409−
1410−/* hop level */
1411−#define PERF_MEM_HOPS_0 0x01 /* remote core, same node */
1412−#define PERF_MEM_HOPS_1 0x02 /* remote node, same socket */
1413−#define PERF_MEM_HOPS_2 0x03 /* remote socket, same board */
1414−#define PERF_MEM_HOPS_3 0x04 /* remote board */
1416+#define PERF_MEM_BLK_NA 0x0001 /* Not available */
1417+#define PERF_MEM_BLK_DATA 0x0002 /* Data could not be forwarded */
1418+#define PERF_MEM_BLK_ADDR 0x0004 /* Address conflict */
1419+#define PERF_MEM_BLK_SHIFT 40
1420+
1421+/* Hop level */
1422+#define PERF_MEM_HOPS_0 0x0001 /* Remote core, same node */
1423+#define PERF_MEM_HOPS_1 0x0002 /* Remote node, same socket */
1424+#define PERF_MEM_HOPS_2 0x0003 /* Remote socket, same board */
1425+#define PERF_MEM_HOPS_3 0x0004 /* Remote board */
14151426 /* 5-7 available */
1416−#define PERF_MEM_HOPS_SHIFT 43
1427+#define PERF_MEM_HOPS_SHIFT 43
14171428
14181429 #define PERF_MEM_S(a, s) \
14191430 (((__u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)
14201431
14211432 /*
1422− * single taken branch record layout:
1433+ * Layout of single taken branch records:
14231434 *
14241435 * from: source instruction (may not always be a branch insn)
14251436 * to: branch target
@@ -1438,37 +1449,37 @@ union perf_mem_data_src { · 12 unmodified lines
14381449 struct perf_branch_entry {
14391450 __u64 from;
14401451 __u64 to;
1441− __u64 mispred:1, /* target mispredicted */
1442− predicted:1,/* target predicted */
1443− in_tx:1, /* in transaction */
1444− abort:1, /* transaction abort */
1445− cycles:16, /* cycle count to last branch */
1446− type:4, /* branch type */
1447− spec:2, /* branch speculation info */
1448− new_type:4, /* additional branch type */
1449− priv:3, /* privilege level */
1450− reserved:31;
1452+ __u64 mispred : 1, /* target mispredicted */
1453+ predicted : 1, /* target predicted */
1454+ in_tx : 1, /* in transaction */
1455+ abort : 1, /* transaction abort */
1456+ cycles : 16, /* cycle count to last branch */
1457+ type : 4, /* branch type */
1458+ spec : 2, /* branch speculation info */
1459+ new_type : 4, /* additional branch type */
1460+ priv : 3, /* privilege level */
1461+ reserved : 31;
14511462 };
14521463
14531464 /* Size of used info bits in struct perf_branch_entry */
14541465 #define PERF_BRANCH_ENTRY_INFO_BITS_MAX 33
14551466
14561467 union perf_sample_weight {
1457− __u64 full;
1468+ __u64 full;
14581469 #if defined(__LITTLE_ENDIAN_BITFIELD)
14591470 struct {
1460− __u32 var1_dw;
1461− __u16 var2_w;
1462− __u16 var3_w;
1471+ __u32 var1_dw;
1472+ __u16 var2_w;
1473+ __u16 var3_w;
14631474 };
14641475 #elif defined(__BIG_ENDIAN_BITFIELD)
14651476 struct {
1466− __u16 var3_w;
1467− __u16 var2_w;
1468− __u32 var1_dw;
1477+ __u16 var3_w;
1478+ __u16 var2_w;
1479+ __u32 var1_dw;
14691480 };
14701481 #else
1471−#error "Unknown endianness"
1482+# error "Unknown endianness"
14721483 #endif
14731484 };
14741485
kernel/cpu.c+0−5
@@ -2069,11 +2069,6 @@ static struct cpuhp_step cpuhp_hp_states[] = { · 2068 unmodified lines
20692069 .teardown.single = NULL,
20702070 .cant_stop = true,
20712071 },
2072− [CPUHP_PERF_PREPARE] = {
2073− .name = "perf:prepare",
2074− .startup.single = perf_event_init_cpu,
2075− .teardown.single = perf_event_exit_cpu,
2076− },
20772072 [CPUHP_RANDOM_PREPARE] = {
20782073 .name = "random:prepare",
20792074 .startup.single = random_prepare_cpu,
kernel/events/core.c+424−185
@@ -1270,6 +1270,10 @@ static void put_ctx(struct perf_event_context *ctx) · 1269 unmodified lines
12701270 if (ctx->task && ctx->task != TASK_TOMBSTONE)
12711271 put_task_struct(ctx->task);
12721272 call_rcu(&ctx->rcu_head, free_ctx);
1273+ } else {
1274+ smp_mb__after_atomic(); /* pairs with wait_var_event() */
1275+ if (ctx->task == TASK_TOMBSTONE)
1276+ wake_up_var(&ctx->refcount);
12731277 }
12741278 }
12751279
@@ -2167,7 +2171,7 @@ static void perf_put_aux_event(struct perf_event *event) · 891 unmodified lines
21672171 * If the event is an aux_event, tear down all links to
21682172 * it from other events.
21692173 */
2170− for_each_sibling_event(iter, event->group_leader) {
2174+ for_each_sibling_event(iter, event) {
21712175 if (iter->aux_event != event)
21722176 continue;
21732177
@@ -2325,7 +2329,11 @@ static void perf_child_detach(struct perf_event *event) · 151 unmodified lines
23252329 if (WARN_ON_ONCE(!parent_event))
23262330 return;
23272331
2332+ /*
2333+ * Can't check this from an IPI, the holder is likey another CPU.
2334+ *
23282335 lockdep_assert_held(&parent_event->child_mutex);
2336+ */
23292337
23302338 sync_child_event(event);
23312339 list_del_init(&event->child_list);
@@ -2343,6 +2351,11 @@ event_filter_match(struct perf_event *event) · 11 unmodified lines
23432351 perf_cgroup_match(event);
23442352 }
23452353
2354+static inline bool is_event_in_freq_mode(struct perf_event *event)
2355+{
2356+ return event->attr.freq && event->attr.sample_freq;
2357+}
2358+
23462359 static void
23472360 event_sched_out(struct perf_event *event, struct perf_event_context *ctx)
23482361 {
@@ -2380,7 +2393,7 @@ event_sched_out(struct perf_event *event, struct perf_event_context *ctx) · 31 unmodified lines
23802393
23812394 if (!is_software_event(event))
23822395 cpc->active_oncpu--;
2383− if (event->attr.freq && event->attr.sample_freq) {
2396+ if (is_event_in_freq_mode(event)) {
23842397 ctx->nr_freq--;
23852398 epc->nr_freq--;
23862399 }
@@ -2450,8 +2463,9 @@ ctx_time_update_event(struct perf_event_context *ctx, struct perf_event *event) · 63 unmodified lines
24502463
24512464 #define DETACH_GROUP 0x01UL
24522465 #define DETACH_CHILD 0x02UL
2453−#define DETACH_DEAD 0x04UL
2454−#define DETACH_EXIT 0x08UL
2466+#define DETACH_EXIT 0x04UL
2467+#define DETACH_REVOKE 0x08UL
2468+#define DETACH_DEAD 0x10UL
24552469
24562470 /*
24572471 * Cross CPU call to remove a performance event
@@ -2477,12 +2491,15 @@ __perf_remove_from_context(struct perf_event *event, · 19 unmodified lines
24772491 */
24782492 if (flags & DETACH_EXIT)
24792493 state = PERF_EVENT_STATE_EXIT;
2494+ if (flags & DETACH_REVOKE)
2495+ state = PERF_EVENT_STATE_REVOKED;
24802496 if (flags & DETACH_DEAD) {
24812497 event->pending_disable = 1;
24822498 state = PERF_EVENT_STATE_DEAD;
24832499 }
24842500 event_sched_out(event, ctx);
24852501 perf_event_set_state(event, min(event->state, state));
2502+
24862503 if (flags & DETACH_GROUP)
24872504 perf_group_detach(event);
24882505 if (flags & DETACH_CHILD)
@@ -2628,6 +2645,41 @@ void perf_event_disable_inatomic(struct perf_event *event) · 139 unmodified lines
26282645 static void perf_log_throttle(struct perf_event *event, int enable);
26292646 static void perf_log_itrace_start(struct perf_event *event);
26302647
2648+static void perf_event_unthrottle(struct perf_event *event, bool start)
2649+{
2650+ event->hw.interrupts = 0;
2651+ if (start)
2652+ event->pmu->start(event, 0);
2653+ if (event == event->group_leader)
2654+ perf_log_throttle(event, 1);
2655+}
2656+
2657+static void perf_event_throttle(struct perf_event *event)
2658+{
2659+ event->pmu->stop(event, 0);
2660+ event->hw.interrupts = MAX_INTERRUPTS;
2661+ if (event == event->group_leader)
2662+ perf_log_throttle(event, 0);
2663+}
2664+
2665+static void perf_event_unthrottle_group(struct perf_event *event, bool skip_start_event)
2666+{
2667+ struct perf_event *sibling, *leader = event->group_leader;
2668+
2669+ perf_event_unthrottle(leader, skip_start_event ? leader != event : true);
2670+ for_each_sibling_event(sibling, leader)
2671+ perf_event_unthrottle(sibling, skip_start_event ? sibling != event : true);
2672+}
2673+
2674+static void perf_event_throttle_group(struct perf_event *event)
2675+{
2676+ struct perf_event *sibling, *leader = event->group_leader;
2677+
2678+ perf_event_throttle(leader);
2679+ for_each_sibling_event(sibling, leader)
2680+ perf_event_throttle(sibling);
2681+}
2682+
26312683 static int
26322684 event_sched_in(struct perf_event *event, struct perf_event_context *ctx)
26332685 {
@@ -2656,10 +2708,8 @@ event_sched_in(struct perf_event *event, struct perf_event_context *ctx) · 22 unmodified lines
26562708 * ticks already, also for a heavily scheduling task there is little
26572709 * guarantee it'll get a tick in a timely manner.
26582710 */
2659− if (unlikely(event->hw.interrupts == MAX_INTERRUPTS)) {
2660− perf_log_throttle(event, 1);
2661− event->hw.interrupts = 0;
2662− }
2711+ if (unlikely(event->hw.interrupts == MAX_INTERRUPTS))
2712+ perf_event_unthrottle(event, false);
26632713
26642714 perf_pmu_disable(event->pmu);
26652715
@@ -2674,7 +2724,7 @@ event_sched_in(struct perf_event *event, struct perf_event_context *ctx) · 8 unmodified lines
26742724
26752725 if (!is_software_event(event))
26762726 cpc->active_oncpu++;
2677− if (event->attr.freq && event->attr.sample_freq) {
2727+ if (is_event_in_freq_mode(event)) {
26782728 ctx->nr_freq++;
26792729 epc->nr_freq++;
26802730 }
@@ -4237,14 +4287,10 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) · 1556 unmodified lines
42374287
42384288 hwc = &event->hw;
42394289
4240− if (hwc->interrupts == MAX_INTERRUPTS) {
4241− hwc->interrupts = 0;
4242− perf_log_throttle(event, 1);
4243− if (!event->attr.freq || !event->attr.sample_freq)
4244− event->pmu->start(event, 0);
4245− }
4290+ if (hwc->interrupts == MAX_INTERRUPTS)
4291+ perf_event_unthrottle_group(event, is_event_in_freq_mode(event));
42464292
4247− if (!event->attr.freq || !event->attr.sample_freq)
4293+ if (!is_event_in_freq_mode(event))
42484294 continue;
42494295
42504296 /*
@@ -4516,7 +4562,8 @@ out: · 265 unmodified lines
45164562
45174563 static void perf_remove_from_owner(struct perf_event *event);
45184564 static void perf_event_exit_event(struct perf_event *event,
4519− struct perf_event_context *ctx);
4565+ struct perf_event_context *ctx,
4566+ bool revoke);
45204567
45214568 /*
45224569 * Removes all events from the current task that have been marked
@@ -4543,7 +4590,7 @@ static void perf_event_remove_on_exec(struct perf_event_context *ctx) · 20 unmodified lines
45434590
45444591 modified = true;
45454592
4546− perf_event_exit_event(event, ctx);
4593+ perf_event_exit_event(event, ctx, false);
45474594 }
45484595
45494596 raw_spin_lock_irqsave(&ctx->lock, flags);
@@ -5125,6 +5172,7 @@ static bool is_sb_event(struct perf_event *event) · 575 unmodified lines
51255172 attr->context_switch || attr->text_poke ||
51265173 attr->bpf_event)
51275174 return true;
5175+
51285176 return false;
51295177 }
51305178
@@ -5521,6 +5569,8 @@ static void perf_free_addr_filters(struct perf_event *event); · 390 unmodified lines
55215569 /* vs perf_event_alloc() error */
55225570 static void __free_event(struct perf_event *event)
55235571 {
5572+ struct pmu *pmu = event->pmu;
5573+
55245574 if (event->attach_state & PERF_ATTACH_CALLCHAIN)
55255575 put_callchain_buffers();
55265576
@@ -5550,6 +5600,7 @@ static void __free_event(struct perf_event *event) · 23 unmodified lines
55505600 * put_pmu_ctx() needs an event->ctx reference, because of
55515601 * epc->ctx.
55525602 */
5603+ WARN_ON_ONCE(!pmu);
55535604 WARN_ON_ONCE(!event->ctx);
55545605 WARN_ON_ONCE(event->pmu_ctx->ctx != event->ctx);
55555606 put_pmu_ctx(event->pmu_ctx);
@@ -5562,8 +5613,13 @@ static void __free_event(struct perf_event *event) · 6 unmodified lines
55625613 if (event->ctx)
55635614 put_ctx(event->ctx);
55645615
5565− if (event->pmu)
5566− module_put(event->pmu->module);
5616+ if (pmu) {
5617+ module_put(pmu->module);
5618+ scoped_guard (spinlock, &pmu->events_lock) {
5619+ list_del(&event->pmu_list);
5620+ wake_up_var(pmu);
5621+ }
5622+ }
55675623
55685624 call_rcu(&event->rcu_head, free_event_rcu);
55695625 }
@@ -5600,13 +5656,13 @@ static void _free_event(struct perf_event *event) · 30 unmodified lines
56005656
56015657 /*
56025658 * Used to free events which have a known refcount of 1, such as in error paths
5603− * where the event isn't exposed yet and inherited events.
5659+ * of inherited events.
56045660 */
56055661 static void free_event(struct perf_event *event)
56065662 {
56075663 if (WARN(atomic_long_cmpxchg(&event->refcount, 1, 0) != 1,
5608− "unexpected event refcount: %ld; ptr=%p\n",
5609− atomic_long_read(&event->refcount), event)) {
5664+ "unexpected event refcount: %ld; ptr=%p\n",
5665+ atomic_long_read(&event->refcount), event)) {
56105666 /* leak to avoid use-after-free */
56115667 return;
56125668 }
@@ -5689,7 +5745,6 @@ int perf_event_release_kernel(struct perf_event *event) · 76 unmodified lines
56895745 {
56905746 struct perf_event_context *ctx = event->ctx;
56915747 struct perf_event *child, *tmp;
5692− LIST_HEAD(free_list);
56935748
56945749 /*
56955750 * If we got here through err_alloc: free_event(event); we will not
@@ -5718,15 +5773,17 @@ int perf_event_release_kernel(struct perf_event *event) · 22 unmodified lines
57185773 * Thus this guarantees that we will in fact observe and kill _ALL_
57195774 * child events.
57205775 */
5721− perf_remove_from_context(event, DETACH_GROUP|DETACH_DEAD);
5776+ if (event->state > PERF_EVENT_STATE_REVOKED) {
5777+ perf_remove_from_context(event, DETACH_GROUP|DETACH_DEAD);
5778+ } else {
5779+ event->state = PERF_EVENT_STATE_DEAD;
5780+ }
57225781
57235782 perf_event_ctx_unlock(event, ctx);
57245783
57255784 again:
57265785 mutex_lock(&event->child_mutex);
57275786 list_for_each_entry(child, &event->child_list, child_list) {
5728− void *var = NULL;
5729−
57305787 /*
57315788 * Cannot change, child events are not migrated, see the
57325789 * comment with perf_event_ctx_lock_nested().
@@ -5759,44 +5816,24 @@ again: · 26 unmodified lines
57595816 tmp = list_first_entry_or_null(&event->child_list,
57605817 struct perf_event, child_list);
57615818 if (tmp == child) {
5762− perf_remove_from_context(child, DETACH_GROUP);
5763− list_move(&child->child_list, &free_list);
5819+ perf_remove_from_context(child, DETACH_GROUP | DETACH_CHILD);
57645820 } else {
5765− var = &ctx->refcount;
5821+ child = NULL;
57665822 }
57675823
57685824 mutex_unlock(&event->child_mutex);
57695825 mutex_unlock(&ctx->mutex);
5770− put_ctx(ctx);
57715826
5772− if (var) {
5773− /*
5774− * If perf_event_free_task() has deleted all events from the
5775− * ctx while the child_mutex got released above, make sure to
5776− * notify about the preceding put_ctx().
5777− */
5778− smp_mb(); /* pairs with wait_var_event() */
5779− wake_up_var(var);
5827+ if (child) {
5828+ /* Last reference unless ->pending_task work is pending */
5829+ put_event(child);
57805830 }
5831+ put_ctx(ctx);
5832+
57815833 goto again;
57825834 }
57835835 mutex_unlock(&event->child_mutex);
57845836
5785− list_for_each_entry_safe(child, tmp, &free_list, child_list) {
5786− void *var = &child->ctx->refcount;
5787−
5788− list_del(&child->child_list);
5789− /* Last reference unless ->pending_task work is pending */
5790− put_event(child);
5791−
5792− /*
5793− * Wake any perf_event_free_task() waiting for this event to be
5794− * freed.
5795− */
5796− smp_mb(); /* pairs with wait_var_event() */
5797− wake_up_var(var);
5798− }
5799−
58005837 no_ctx:
58015838 /*
58025839 * Last reference unless ->pending_task work is pending on this event
@@ -6068,8 +6105,14 @@ static __poll_t perf_poll(struct file *file, poll_table *wait) · 265 unmodified lines
60686105 struct perf_buffer *rb;
60696106 __poll_t events = EPOLLHUP;
60706107
6108+ if (event->state <= PERF_EVENT_STATE_REVOKED)
6109+ return EPOLLERR;
6110+
60716111 poll_wait(file, &event->waitq, wait);
60726112
6113+ if (event->state <= PERF_EVENT_STATE_REVOKED)
6114+ return EPOLLERR;
6115+
60736116 if (is_event_hup(event))
60746117 return events;
60756118
@@ -6167,14 +6210,6 @@ static void __perf_event_period(struct perf_event *event, · 91 unmodified lines
61676210 active = (event->state == PERF_EVENT_STATE_ACTIVE);
61686211 if (active) {
61696212 perf_pmu_disable(event->pmu);
6170− /*
6171− * We could be throttled; unthrottle now to avoid the tick
6172− * trying to unthrottle while we already re-started the event.
6173− */
6174− if (event->hw.interrupts == MAX_INTERRUPTS) {
6175− event->hw.interrupts = 0;
6176− perf_log_throttle(event, 1);
6177− }
61786213 event->pmu->stop(event, PERF_EF_UPDATE);
61796214 }
61806215
@@ -6182,6 +6217,14 @@ static void __perf_event_period(struct perf_event *event, · 1 unmodified line
61826217
61836218 if (active) {
61846219 event->pmu->start(event, PERF_EF_RELOAD);
6220+ /*
6221+ * Once the period is force-reset, the event starts immediately.
6222+ * But the event/group could be throttled. Unthrottle the
6223+ * event/group now to avoid the next tick trying to unthrottle
6224+ * while we already re-started the event/group.
6225+ */
6226+ if (event->hw.interrupts == MAX_INTERRUPTS)
6227+ perf_event_unthrottle_group(event, true);
61856228 perf_pmu_enable(event->pmu);
61866229 }
61876230 }
@@ -6239,12 +6282,18 @@ static int perf_event_set_output(struct perf_event *event, · 51 unmodified lines
62396282 static int perf_event_set_filter(struct perf_event *event, void __user *arg);
62406283 static int perf_copy_attr(struct perf_event_attr __user *uattr,
62416284 struct perf_event_attr *attr);
6285+static int __perf_event_set_bpf_prog(struct perf_event *event,
6286+ struct bpf_prog *prog,
6287+ u64 bpf_cookie);
62426288
62436289 static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned long arg)
62446290 {
62456291 void (*func)(struct perf_event *);
62466292 u32 flags = arg;
62476293
6294+ if (event->state <= PERF_EVENT_STATE_REVOKED)
6295+ return -ENODEV;
6296+
62486297 switch (cmd) {
62496298 case PERF_EVENT_IOC_ENABLE:
62506299 func = _perf_event_enable;
@@ -6301,7 +6350,7 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon · 50 unmodified lines
63016350 if (IS_ERR(prog))
63026351 return PTR_ERR(prog);
63036352
6304− err = perf_event_set_bpf_prog(event, prog, 0);
6353+ err = __perf_event_set_bpf_prog(event, prog, 0);
63056354 if (err) {
63066355 bpf_prog_put(prog);
63076356 return err;
@@ -6620,9 +6669,22 @@ void ring_buffer_put(struct perf_buffer *rb) · 312 unmodified lines
66206669 call_rcu(&rb->rcu_head, rb_free_rcu);
66216670 }
66226671
6672+typedef void (*mapped_f)(struct perf_event *event, struct mm_struct *mm);
6673+
6674+#define get_mapped(event, func) \
6675+({ struct pmu *pmu; \
6676+ mapped_f f = NULL; \
6677+ guard(rcu)(); \
6678+ pmu = READ_ONCE(event->pmu); \
6679+ if (pmu) \
6680+ f = pmu->func; \
6681+ f; \
6682+})
6683+
66236684 static void perf_mmap_open(struct vm_area_struct *vma)
66246685 {
66256686 struct perf_event *event = vma->vm_file->private_data;
6687+ mapped_f mapped = get_mapped(event, event_mapped);
66266688
66276689 atomic_inc(&event->mmap_count);
66286690 atomic_inc(&event->rb->mmap_count);
@@ -6630,8 +6692,8 @@ static void perf_mmap_open(struct vm_area_struct *vma) · 1 unmodified line
66306692 if (vma->vm_pgoff)
66316693 atomic_inc(&event->rb->aux_mmap_count);
66326694
6633− if (event->pmu->event_mapped)
6634− event->pmu->event_mapped(event, vma->vm_mm);
6695+ if (mapped)
6696+ mapped(event, vma->vm_mm);
66356697 }
66366698
66376699 static void perf_pmu_output_stop(struct perf_event *event);
@@ -6647,14 +6709,16 @@ static void perf_pmu_output_stop(struct perf_event *event); · 9 unmodified lines
66476709 static void perf_mmap_close(struct vm_area_struct *vma)
66486710 {
66496711 struct perf_event *event = vma->vm_file->private_data;
6712+ mapped_f unmapped = get_mapped(event, event_unmapped);
66506713 struct perf_buffer *rb = ring_buffer_get(event);
66516714 struct user_struct *mmap_user = rb->mmap_user;
66526715 int mmap_locked = rb->mmap_locked;
66536716 unsigned long size = perf_data_size(rb);
66546717 bool detach_rest = false;
66556718
6656− if (event->pmu->event_unmapped)
6657− event->pmu->event_unmapped(event, vma->vm_mm);
6719+ /* FIXIES vs perf_pmu_unregister() */
6720+ if (unmapped)
6721+ unmapped(event, vma->vm_mm);
66586722
66596723 /*
66606724 * The AUX buffer is strictly a sub-buffer, serialize using aux_mutex
@@ -6847,6 +6911,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) · 186 unmodified lines
68476911 unsigned long nr_pages;
68486912 long user_extra = 0, extra = 0;
68496913 int ret, flags = 0;
6914+ mapped_f mapped;
68506915
68516916 /*
68526917 * Don't allow mmap() of inherited per-task counters. This would
@@ -6877,6 +6942,16 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) · 24 unmodified lines
68776942 mutex_lock(&event->mmap_mutex);
68786943 ret = -EINVAL;
68796944
6945+ /*
6946+ * This relies on __pmu_detach_event() taking mmap_mutex after marking
6947+ * the event REVOKED. Either we observe the state, or __pmu_detach_event()
6948+ * will detach the rb created here.
6949+ */
6950+ if (event->state <= PERF_EVENT_STATE_REVOKED) {
6951+ ret = -ENODEV;
6952+ goto unlock;
6953+ }
6954+
68806955 if (vma->vm_pgoff == 0) {
68816956 nr_pages -= 1;
68826957
@@ -7055,8 +7130,9 @@ aux_unlock: · 172 unmodified lines
70557130 if (!ret)
70567131 ret = map_range(rb, vma);
70577132
7058− if (!ret && event->pmu->event_mapped)
7059− event->pmu->event_mapped(event, vma->vm_mm);
7133+ mapped = get_mapped(event, event_mapped);
7134+ if (mapped)
7135+ mapped(event, vma->vm_mm);
70607136
70617137 return ret;
70627138 }
@@ -7067,6 +7143,9 @@ static int perf_fasync(int fd, struct file *filp, int on) · 4 unmodified lines
70677143 struct perf_event *event = filp->private_data;
70687144 int retval;
70697145
7146+ if (event->state <= PERF_EVENT_STATE_REVOKED)
7147+ return -ENODEV;
7148+
70707149 inode_lock(inode);
70717150 retval = fasync_helper(fd, filp, on, &event->fasync);
70727151 inode_unlock(inode);
@@ -9946,7 +10025,7 @@ void perf_event_text_poke(const void *addr, const void *old_bytes, · 2873 unmodified lines
994610025
994710026 void perf_event_itrace_started(struct perf_event *event)
994810027 {
9949− event->attach_state |= PERF_ATTACH_ITRACE;
10028+ WRITE_ONCE(event->attach_state, event->attach_state | PERF_ATTACH_ITRACE);
995010029 }
995110030
995210031 static void perf_log_itrace_start(struct perf_event *event)
@@ -10029,14 +10108,13 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle) · 76 unmodified lines
1002910108 hwc->interrupts = 1;
1003010109 } else {
1003110110 hwc->interrupts++;
10032− if (unlikely(throttle &&
10033− hwc->interrupts > max_samples_per_tick)) {
10034− __this_cpu_inc(perf_throttled_count);
10035− tick_dep_set_cpu(smp_processor_id(), TICK_DEP_BIT_PERF_EVENTS);
10036− hwc->interrupts = MAX_INTERRUPTS;
10037− perf_log_throttle(event, 0);
10038− ret = 1;
10039− }
10111+ }
10112+
10113+ if (unlikely(throttle && hwc->interrupts >= max_samples_per_tick)) {
10114+ __this_cpu_inc(perf_throttled_count);
10115+ tick_dep_set_cpu(smp_processor_id(), TICK_DEP_BIT_PERF_EVENTS);
10116+ perf_event_throttle_group(event);
10117+ ret = 1;
1004010118 }
1004110119
1004210120 if (event->attr.freq) {
@@ -11069,11 +11147,15 @@ static inline bool perf_event_is_tracing(struct perf_event *event) · 1026 unmodified lines
1106911147 return false;
1107011148 }
1107111149
11072−int perf_event_set_bpf_prog(struct perf_event *event, struct bpf_prog *prog,
11073− u64 bpf_cookie)
11150+static int __perf_event_set_bpf_prog(struct perf_event *event,
11151+ struct bpf_prog *prog,
11152+ u64 bpf_cookie)
1107411153 {
1107511154 bool is_kprobe, is_uprobe, is_tracepoint, is_syscall_tp;
1107611155
11156+ if (event->state <= PERF_EVENT_STATE_REVOKED)
11157+ return -ENODEV;
11158+
1107711159 if (!perf_event_is_tracing(event))
1107811160 return perf_event_set_bpf_handler(event, prog, bpf_cookie);
1107911161
@@ -11108,6 +11190,20 @@ int perf_event_set_bpf_prog(struct perf_event *event, struct bpf_prog *prog, · 28 unmodified lines
1110811190 return perf_event_attach_bpf_prog(event, prog, bpf_cookie);
1110911191 }
1111011192
11193+int perf_event_set_bpf_prog(struct perf_event *event,
11194+ struct bpf_prog *prog,
11195+ u64 bpf_cookie)
11196+{
11197+ struct perf_event_context *ctx;
11198+ int ret;
11199+
11200+ ctx = perf_event_ctx_lock(event);
11201+ ret = __perf_event_set_bpf_prog(event, prog, bpf_cookie);
11202+ perf_event_ctx_unlock(event, ctx);
11203+
11204+ return ret;
11205+}
11206+
1111111207 void perf_event_free_bpf_prog(struct perf_event *event)
1111211208 {
1111311209 if (!event->prog)
@@ -11130,7 +11226,15 @@ static void perf_event_free_filter(struct perf_event *event) · 16 unmodified lines
1113011226 {
1113111227 }
1113211228
11133−int perf_event_set_bpf_prog(struct perf_event *event, struct bpf_prog *prog,
11229+static int __perf_event_set_bpf_prog(struct perf_event *event,
11230+ struct bpf_prog *prog,
11231+ u64 bpf_cookie)
11232+{
11233+ return -ENOENT;
11234+}
11235+
11236+int perf_event_set_bpf_prog(struct perf_event *event,
11237+ struct bpf_prog *prog,
1113411238 u64 bpf_cookie)
1113511239 {
1113611240 return -ENOENT;
@@ -12235,6 +12339,9 @@ int perf_pmu_register(struct pmu *_pmu, const char *name, int type) · 1098 unmodified lines
1223512339 if (!pmu->event_idx)
1223612340 pmu->event_idx = perf_event_idx_default;
1223712341
12342+ INIT_LIST_HEAD(&pmu->events);
12343+ spin_lock_init(&pmu->events_lock);
12344+
1223812345 /*
1223912346 * Now that the PMU is complete, make it visible to perf_try_init_event().
1224012347 */
@@ -12248,21 +12355,143 @@ int perf_pmu_register(struct pmu *_pmu, const char *name, int type) · 7 unmodified lines
1224812355 }
1224912356 EXPORT_SYMBOL_GPL(perf_pmu_register);
1225012357
12251−void perf_pmu_unregister(struct pmu *pmu)
12358+static void __pmu_detach_event(struct pmu *pmu, struct perf_event *event,
12359+ struct perf_event_context *ctx)
12360+{
12361+ /*
12362+ * De-schedule the event and mark it REVOKED.
12363+ */
12364+ perf_event_exit_event(event, ctx, true);
12365+
12366+ /*
12367+ * All _free_event() bits that rely on event->pmu:
12368+ *
12369+ * Notably, perf_mmap() relies on the ordering here.
12370+ */
12371+ scoped_guard (mutex, &event->mmap_mutex) {
12372+ WARN_ON_ONCE(pmu->event_unmapped);
12373+ /*
12374+ * Mostly an empty lock sequence, such that perf_mmap(), which
12375+ * relies on mmap_mutex, is sure to observe the state change.
12376+ */
12377+ }
12378+
12379+ perf_event_free_bpf_prog(event);
12380+ perf_free_addr_filters(event);
12381+
12382+ if (event->destroy) {
12383+ event->destroy(event);
12384+ event->destroy = NULL;
12385+ }
12386+
12387+ if (event->pmu_ctx) {
12388+ put_pmu_ctx(event->pmu_ctx);
12389+ event->pmu_ctx = NULL;
12390+ }
12391+
12392+ exclusive_event_destroy(event);
12393+ module_put(pmu->module);
12394+
12395+ event->pmu = NULL; /* force fault instead of UAF */
12396+}
12397+
12398+static void pmu_detach_event(struct pmu *pmu, struct perf_event *event)
12399+{
12400+ struct perf_event_context *ctx;
12401+
12402+ ctx = perf_event_ctx_lock(event);
12403+ __pmu_detach_event(pmu, event, ctx);
12404+ perf_event_ctx_unlock(event, ctx);
12405+
12406+ scoped_guard (spinlock, &pmu->events_lock)
12407+ list_del(&event->pmu_list);
12408+}
12409+
12410+static struct perf_event *pmu_get_event(struct pmu *pmu)
12411+{
12412+ struct perf_event *event;
12413+
12414+ guard(spinlock)(&pmu->events_lock);
12415+ list_for_each_entry(event, &pmu->events, pmu_list) {
12416+ if (atomic_long_inc_not_zero(&event->refcount))
12417+ return event;
12418+ }
12419+
12420+ return NULL;
12421+}
12422+
12423+static bool pmu_empty(struct pmu *pmu)
12424+{
12425+ guard(spinlock)(&pmu->events_lock);
12426+ return list_empty(&pmu->events);
12427+}
12428+
12429+static void pmu_detach_events(struct pmu *pmu)
12430+{
12431+ struct perf_event *event;
12432+
12433+ for (;;) {
12434+ event = pmu_get_event(pmu);
12435+ if (!event)
12436+ break;
12437+
12438+ pmu_detach_event(pmu, event);
12439+ put_event(event);
12440+ }
12441+
12442+ /*
12443+ * wait for pending _free_event()s
12444+ */
12445+ wait_var_event(pmu, pmu_empty(pmu));
12446+}
12447+
12448+int perf_pmu_unregister(struct pmu *pmu)
1225212449 {
1225312450 scoped_guard (mutex, &pmus_lock) {
12451+ if (!idr_cmpxchg(&pmu_idr, pmu->type, pmu, NULL))
12452+ return -EINVAL;
12453+
1225412454 list_del_rcu(&pmu->entry);
12255− idr_remove(&pmu_idr, pmu->type);
1225612455 }
1225712456
1225812457 /*
1225912458 * We dereference the pmu list under both SRCU and regular RCU, so
1226012459 * synchronize against both of those.
12460+ *
12461+ * Notably, the entirety of event creation, from perf_init_event()
12462+ * (which will now fail, because of the above) until
12463+ * perf_install_in_context() should be under SRCU such that
12464+ * this synchronizes against event creation. This avoids trying to
12465+ * detach events that are not fully formed.
1226112466 */
1226212467 synchronize_srcu(&pmus_srcu);
1226312468 synchronize_rcu();
1226412469
12470+ if (pmu->event_unmapped && !pmu_empty(pmu)) {
12471+ /*
12472+ * Can't force remove events when pmu::event_unmapped()
12473+ * is used in perf_mmap_close().
12474+ */
12475+ guard(mutex)(&pmus_lock);
12476+ idr_cmpxchg(&pmu_idr, pmu->type, NULL, pmu);
12477+ list_add_rcu(&pmu->entry, &pmus);
12478+ return -EBUSY;
12479+ }
12480+
12481+ scoped_guard (mutex, &pmus_lock)
12482+ idr_remove(&pmu_idr, pmu->type);
12483+
12484+ /*
12485+ * PMU is removed from the pmus list, so no new events will
12486+ * be created, now take care of the existing ones.
12487+ */
12488+ pmu_detach_events(pmu);
12489+
12490+ /*
12491+ * PMU is unused, make it go away.
12492+ */
1226512493 perf_pmu_free(pmu);
12494+ return 0;
1226612495 }
1226712496 EXPORT_SYMBOL_GPL(perf_pmu_unregister);
1226812497
@@ -12356,7 +12585,7 @@ static struct pmu *perf_init_event(struct perf_event *event) · 87 unmodified lines
1235612585 struct pmu *pmu;
1235712586 int type, ret;
1235812587
12359− guard(srcu)(&pmus_srcu);
12588+ guard(srcu)(&pmus_srcu); /* pmu idr/list access */
1236012589
1236112590 /*
1236212591 * Save original type before calling pmu->event_init() since certain
@@ -12580,6 +12809,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, · 217 unmodified lines
1258012809 INIT_LIST_HEAD(&event->active_entry);
1258112810 INIT_LIST_HEAD(&event->addr_filters.list);
1258212811 INIT_HLIST_NODE(&event->hlist_entry);
12812+ INIT_LIST_HEAD(&event->pmu_list);
1258312813
1258412814
1258512815 init_waitqueue_head(&event->waitq);
@@ -12651,7 +12881,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, · 65 unmodified lines
1265112881
1265212882 hwc = &event->hw;
1265312883 hwc->sample_period = attr->sample_period;
12654− if (attr->freq && attr->sample_freq)
12884+ if (is_event_in_freq_mode(event))
1265512885 hwc->sample_period = 1;
1265612886 hwc->last_period = hwc->sample_period;
1265712887
@@ -12758,6 +12988,13 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, · 100 unmodified lines
1275812988 /* symmetric to unaccount_event() in _free_event() */
1275912989 account_event(event);
1276012990
12991+ /*
12992+ * Event creation should be under SRCU, see perf_pmu_unregister().
12993+ */
12994+ lockdep_assert_held(&pmus_srcu);
12995+ scoped_guard (spinlock, &pmu->events_lock)
12996+ list_add(&event->pmu_list, &pmu->events);
12997+
1276112998 return_ptr(event);
1276212999 }
1276313000
@@ -12957,6 +13194,9 @@ set: · 193 unmodified lines
1295713194 goto unlock;
1295813195
1295913196 if (output_event) {
13197+ if (output_event->state <= PERF_EVENT_STATE_REVOKED)
13198+ goto unlock;
13199+
1296013200 /* get the rb we want to redirect to */
1296113201 rb = ring_buffer_get(output_event);
1296213202 if (!rb)
@@ -13138,6 +13378,11 @@ SYSCALL_DEFINE5(perf_event_open, · 175 unmodified lines
1313813378 if (event_fd < 0)
1313913379 return event_fd;
1314013380
13381+ /*
13382+ * Event creation should be under SRCU, see perf_pmu_unregister().
13383+ */
13384+ guard(srcu)(&pmus_srcu);
13385+
1314113386 CLASS(fd, group)(group_fd); // group_fd == -1 => empty
1314213387 if (group_fd != -1) {
1314313388 if (!is_perf_file(group)) {
@@ -13145,6 +13390,10 @@ SYSCALL_DEFINE5(perf_event_open, · 1 unmodified line
1314513390 goto err_fd;
1314613391 }
1314713392 group_leader = fd_file(group)->private_data;
13393+ if (group_leader->state <= PERF_EVENT_STATE_REVOKED) {
13394+ err = -ENODEV;
13395+ goto err_fd;
13396+ }
1314813397 if (flags & PERF_FLAG_FD_OUTPUT)
1314913398 output_event = group_leader;
1315013399 if (flags & PERF_FLAG_FD_NO_GROUP)
@@ -13441,7 +13690,7 @@ err_cred: · 290 unmodified lines
1344113690 if (task)
1344213691 up_read(&task->signal->exec_update_lock);
1344313692 err_alloc:
13444− free_event(event);
13693+ put_event(event);
1344513694 err_task:
1344613695 if (task)
1344713696 put_task_struct(task);
@@ -13478,6 +13727,11 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, · 30 unmodified lines
1347813727 if (attr->aux_output || attr->aux_action)
1347913728 return ERR_PTR(-EINVAL);
1348013729
13730+ /*
13731+ * Event creation should be under SRCU, see perf_pmu_unregister().
13732+ */
13733+ guard(srcu)(&pmus_srcu);
13734+
1348113735 event = perf_event_alloc(attr, cpu, task, NULL, NULL,
1348213736 overflow_handler, context, -1);
1348313737 if (IS_ERR(event)) {
@@ -13549,7 +13803,7 @@ err_unlock: · 65 unmodified lines
1354913803 perf_unpin_context(ctx);
1355013804 put_ctx(ctx);
1355113805 err_alloc:
13552− free_event(event);
13806+ put_event(event);
1355313807 err:
1355413808 return ERR_PTR(err);
1355513809 }
@@ -13689,10 +13943,12 @@ static void sync_child_event(struct perf_event *child_event) · 133 unmodified lines
1368913943 }
1369013944
1369113945 static void
13692−perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx)
13946+perf_event_exit_event(struct perf_event *event,
13947+ struct perf_event_context *ctx, bool revoke)
1369313948 {
1369413949 struct perf_event *parent_event = event->parent;
13695− unsigned long detach_flags = 0;
13950+ unsigned long detach_flags = DETACH_EXIT;
13951+ unsigned int attach_state;
1369613952
1369713953 if (parent_event) {
1369813954 /*
@@ -13707,22 +13963,38 @@ perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx) · 8 unmodified lines
1370713963 * Do destroy all inherited groups, we don't care about those
1370813964 * and being thorough is better.
1370913965 */
13710− detach_flags = DETACH_GROUP | DETACH_CHILD;
13966+ detach_flags |= DETACH_GROUP | DETACH_CHILD;
1371113967 mutex_lock(&parent_event->child_mutex);
13968+ /* PERF_ATTACH_ITRACE might be set concurrently */
13969+ attach_state = READ_ONCE(event->attach_state);
1371213970 }
1371313971
13714− perf_remove_from_context(event, detach_flags | DETACH_EXIT);
13972+ if (revoke)
13973+ detach_flags |= DETACH_GROUP | DETACH_REVOKE;
1371513974
13975+ perf_remove_from_context(event, detach_flags);
1371613976 /*
1371713977 * Child events can be freed.
1371813978 */
1371913979 if (parent_event) {
1372013980 mutex_unlock(&parent_event->child_mutex);
13981+
1372113982 /*
13722− * Kick perf_poll() for is_event_hup();
13983+ * Match the refcount initialization. Make sure it doesn't happen
13984+ * twice if pmu_detach_event() calls it on an already exited task.
1372313985 */
13724− perf_event_wakeup(parent_event);
13725− put_event(event);
13986+ if (attach_state & PERF_ATTACH_CHILD) {
13987+ /*
13988+ * Kick perf_poll() for is_event_hup();
13989+ */
13990+ perf_event_wakeup(parent_event);
13991+ /*
13992+ * pmu_detach_event() will have an extra refcount.
13993+ * perf_pending_task() might have one too.
13994+ */
13995+ put_event(event);
13996+ }
13997+
1372613998 return;
1372713999 }
1372814000
@@ -13732,15 +14004,13 @@ perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx) · 3 unmodified lines
1373214004 perf_event_wakeup(event);
1373314005 }
1373414006
13735−static void perf_event_exit_task_context(struct task_struct *child)
14007+static void perf_event_exit_task_context(struct task_struct *task, bool exit)
1373614008 {
13737− struct perf_event_context *child_ctx, *clone_ctx = NULL;
14009+ struct perf_event_context *ctx, *clone_ctx = NULL;
1373814010 struct perf_event *child_event, *next;
1373914011
13740− WARN_ON_ONCE(child != current);
13741−
13742− child_ctx = perf_pin_task_context(child);
13743− if (!child_ctx)
14012+ ctx = perf_pin_task_context(task);
14013+ if (!ctx)
1374414014 return;
1374514015
1374614016 /*
@@ -13753,27 +14023,28 @@ static void perf_event_exit_task_context(struct task_struct *child) · 6 unmodified lines
1375314023 * without ctx::mutex (it cannot because of the move_group double mutex
1375414024 * lock thing). See the comments in perf_install_in_context().
1375514025 */
13756− mutex_lock(&child_ctx->mutex);
14026+ mutex_lock(&ctx->mutex);
1375714027
1375814028 /*
1375914029 * In a single ctx::lock section, de-schedule the events and detach the
1376014030 * context from the task such that we cannot ever get it scheduled back
1376114031 * in.
1376214032 */
13763− raw_spin_lock_irq(&child_ctx->lock);
13764− task_ctx_sched_out(child_ctx, NULL, EVENT_ALL);
14033+ raw_spin_lock_irq(&ctx->lock);
14034+ if (exit)
14035+ task_ctx_sched_out(ctx, NULL, EVENT_ALL);
1376514036
1376614037 /*
1376714038 * Now that the context is inactive, destroy the task <-> ctx relation
1376814039 * and mark the context dead.
1376914040 */
13770− RCU_INIT_POINTER(child->perf_event_ctxp, NULL);
13771− put_ctx(child_ctx); /* cannot be last */
13772− WRITE_ONCE(child_ctx->task, TASK_TOMBSTONE);
13773− put_task_struct(current); /* cannot be last */
14041+ RCU_INIT_POINTER(task->perf_event_ctxp, NULL);
14042+ put_ctx(ctx); /* cannot be last */
14043+ WRITE_ONCE(ctx->task, TASK_TOMBSTONE);
14044+ put_task_struct(task); /* cannot be last */
1377414045
13775− clone_ctx = unclone_ctx(child_ctx);
13776− raw_spin_unlock_irq(&child_ctx->lock);
14046+ clone_ctx = unclone_ctx(ctx);
14047+ raw_spin_unlock_irq(&ctx->lock);
1377714048
1377814049 if (clone_ctx)
1377914050 put_ctx(clone_ctx);
@@ -13783,28 +14054,48 @@ static void perf_event_exit_task_context(struct task_struct *child) · 3 unmodified lines
1378314054 * won't get any samples after PERF_RECORD_EXIT. We can however still
1378414055 * get a few PERF_RECORD_READ events.
1378514056 */
13786− perf_event_task(child, child_ctx, 0);
14057+ if (exit)
14058+ perf_event_task(task, ctx, 0);
1378714059
13788− list_for_each_entry_safe(child_event, next, &child_ctx->event_list, event_entry)
13789− perf_event_exit_event(child_event, child_ctx);
14060+ list_for_each_entry_safe(child_event, next, &ctx->event_list, event_entry)
14061+ perf_event_exit_event(child_event, ctx, false);
1379014062
13791− mutex_unlock(&child_ctx->mutex);
14063+ mutex_unlock(&ctx->mutex);
1379214064
13793− put_ctx(child_ctx);
14065+ if (!exit) {
14066+ /*
14067+ * perf_event_release_kernel() could still have a reference on
14068+ * this context. In that case we must wait for these events to
14069+ * have been freed (in particular all their references to this
14070+ * task must've been dropped).
14071+ *
14072+ * Without this copy_process() will unconditionally free this
14073+ * task (irrespective of its reference count) and
14074+ * _free_event()'s put_task_struct(event->hw.target) will be a
14075+ * use-after-free.
14076+ *
14077+ * Wait for all events to drop their context reference.
14078+ */
14079+ wait_var_event(&ctx->refcount,
14080+ refcount_read(&ctx->refcount) == 1);
14081+ }
14082+ put_ctx(ctx);
1379414083 }
1379514084
1379614085 /*
13797− * When a child task exits, feed back event values to parent events.
14086+ * When a task exits, feed back event values to parent events.
1379814087 *
1379914088 * Can be called with exec_update_lock held when called from
1380014089 * setup_new_exec().
1380114090 */
13802−void perf_event_exit_task(struct task_struct *child)
14091+void perf_event_exit_task(struct task_struct *task)
1380314092 {
1380414093 struct perf_event *event, *tmp;
1380514094
13806− mutex_lock(&child->perf_event_mutex);
13807− list_for_each_entry_safe(event, tmp, &child->perf_event_list,
14095+ WARN_ON_ONCE(task != current);
14096+
14097+ mutex_lock(&task->perf_event_mutex);
14098+ list_for_each_entry_safe(event, tmp, &task->perf_event_list,
1380814099 owner_entry) {
1380914100 list_del_init(&event->owner_entry);
1381014101
@@ -13815,42 +14106,23 @@ void perf_event_exit_task(struct task_struct *child) · 4 unmodified lines
1381514106 */
1381614107 smp_store_release(&event->owner, NULL);
1381714108 }
13818− mutex_unlock(&child->perf_event_mutex);
14109+ mutex_unlock(&task->perf_event_mutex);
1381914110
13820− perf_event_exit_task_context(child);
14111+ perf_event_exit_task_context(task, true);
1382114112
1382214113 /*
1382314114 * The perf_event_exit_task_context calls perf_event_task
13824− * with child's task_ctx, which generates EXIT events for
13825− * child contexts and sets child->perf_event_ctxp[] to NULL.
14115+ * with task's task_ctx, which generates EXIT events for
14116+ * task contexts and sets task->perf_event_ctxp[] to NULL.
1382614117 * At this point we need to send EXIT events to cpu contexts.
1382714118 */
13828− perf_event_task(child, NULL, 0);
14119+ perf_event_task(task, NULL, 0);
1382914120
1383014121 /*
1383114122 * Detach the perf_ctx_data for the system-wide event.
1383214123 */
1383314124 guard(percpu_read)(&global_ctx_data_rwsem);
13834− detach_task_ctx_data(child);
13835−}
13836−
13837−static void perf_free_event(struct perf_event *event,
13838− struct perf_event_context *ctx)
13839−{
13840− struct perf_event *parent = event->parent;
13841−
13842− if (WARN_ON_ONCE(!parent))
13843− return;
13844−
13845− mutex_lock(&parent->child_mutex);
13846− list_del_init(&event->child_list);
13847− mutex_unlock(&parent->child_mutex);
13848−
13849− raw_spin_lock_irq(&ctx->lock);
13850− perf_group_detach(event);
13851− list_del_event(event, ctx);
13852− raw_spin_unlock_irq(&ctx->lock);
13853− put_event(event);
14125+ detach_task_ctx_data(task);
1385414126 }
1385514127
1385614128 /*
@@ -13862,48 +14134,7 @@ static void perf_free_event(struct perf_event *event, · 5 unmodified lines
1386214134 */
1386314135 void perf_event_free_task(struct task_struct *task)
1386414136 {
13865− struct perf_event_context *ctx;
13866− struct perf_event *event, *tmp;
13867−
13868− ctx = rcu_access_pointer(task->perf_event_ctxp);
13869− if (!ctx)
13870− return;
13871−
13872− mutex_lock(&ctx->mutex);
13873− raw_spin_lock_irq(&ctx->lock);
13874− /*
13875− * Destroy the task <-> ctx relation and mark the context dead.
13876− *
13877− * This is important because even though the task hasn't been
13878− * exposed yet the context has been (through child_list).
13879− */
13880− RCU_INIT_POINTER(task->perf_event_ctxp, NULL);
13881− WRITE_ONCE(ctx->task, TASK_TOMBSTONE);
13882− put_task_struct(task); /* cannot be last */
13883− raw_spin_unlock_irq(&ctx->lock);
13884−
13885−
13886− list_for_each_entry_safe(event, tmp, &ctx->event_list, event_entry)
13887− perf_free_event(event, ctx);
13888−
13889− mutex_unlock(&ctx->mutex);
13890−
13891− /*
13892− * perf_event_release_kernel() could've stolen some of our
13893− * child events and still have them on its free_list. In that
13894− * case we must wait for these events to have been freed (in
13895− * particular all their references to this task must've been
13896− * dropped).
13897− *
13898− * Without this copy_process() will unconditionally free this
13899− * task (irrespective of its reference count) and
13900− * _free_event()'s put_task_struct(event->hw.target) will be a
13901− * use-after-free.
13902− *
13903− * Wait for all events to drop their context reference.
13904− */
13905− wait_var_event(&ctx->refcount, refcount_read(&ctx->refcount) == 1);
13906− put_ctx(ctx); /* must be last */
14137+ perf_event_exit_task_context(task, false);
1390714138 }
1390814139
1390914140 void perf_event_delayed_put(struct task_struct *task)
@@ -13980,6 +14211,14 @@ inherit_event(struct perf_event *parent_event, · 70 unmodified lines
1398014211 if (parent_event->parent)
1398114212 parent_event = parent_event->parent;
1398214213
14214+ if (parent_event->state <= PERF_EVENT_STATE_REVOKED)
14215+ return NULL;
14216+
14217+ /*
14218+ * Event creation should be under SRCU, see perf_pmu_unregister().
14219+ */
14220+ guard(srcu)(&pmus_srcu);
14221+
1398314222 child_event = perf_event_alloc(&parent_event->attr,
1398414223 parent_event->cpu,
1398514224 child,
kernel/events/ring_buffer.c+20−9
@@ -679,7 +679,15 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, · 678 unmodified lines
679679 {
680680 bool overwrite = !(flags & RING_BUFFER_WRITABLE);
681681 int node = (event->cpu == -1) ? -1 : cpu_to_node(event->cpu);
682− int ret = -ENOMEM, max_order;
682+ bool use_contiguous_pages = event->pmu->capabilities & (
683+ PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_AUX_PREFER_LARGE);
684+ /*
685+ * Initialize max_order to 0 for page allocation. This allocates single
686+ * pages to minimize memory fragmentation. This is overridden if the
687+ * PMU needs or prefers contiguous pages (use_contiguous_pages = true).
688+ */
689+ int max_order = 0;
690+ int ret = -ENOMEM;
683691
684692 if (!has_aux(event))
685693 return -EOPNOTSUPP;
@@ -689,8 +697,8 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, · 3 unmodified lines
689697
690698 if (!overwrite) {
691699 /*
692− * Watermark defaults to half the buffer, and so does the
693− * max_order, to aid PMU drivers in double buffering.
700+ * Watermark defaults to half the buffer, to aid PMU drivers
701+ * in double buffering.
694702 */
695703 if (!watermark)
696704 watermark = min_t(unsigned long,
@@ -698,16 +706,19 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, · 1 unmodified line
698706 (unsigned long)nr_pages << (PAGE_SHIFT - 1));
699707
700708 /*
701− * Use aux_watermark as the basis for chunking to
702− * help PMU drivers honor the watermark.
709+ * If using contiguous pages, use aux_watermark as the basis
710+ * for chunking to help PMU drivers honor the watermark.
703711 */
704− max_order = get_order(watermark);
712+ if (use_contiguous_pages)
713+ max_order = get_order(watermark);
705714 } else {
706715 /*
707− * We need to start with the max_order that fits in nr_pages,
708− * not the other way around, hence ilog2() and not get_order.
716+ * If using contiguous pages, we need to start with the
717+ * max_order that fits in nr_pages, not the other way around,
718+ * hence ilog2() and not get_order.
709719 */
710− max_order = ilog2(nr_pages);
720+ if (use_contiguous_pages)
721+ max_order = ilog2(nr_pages);
711722 watermark = 0;
712723 }
713724
tools/include/uapi/linux/perf_event.h+334−323
@@ -39,18 +39,21 @@ enum perf_type_id { · 38 unmodified lines
3939
4040 /*
4141 * attr.config layout for type PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE
42+ *
4243 * PERF_TYPE_HARDWARE: 0xEEEEEEEE000000AA
4344 * AA: hardware event ID
4445 * EEEEEEEE: PMU type ID
46+ *
4547 * PERF_TYPE_HW_CACHE: 0xEEEEEEEE00DDCCBB
4648 * BB: hardware cache ID
4749 * CC: hardware cache op ID
4850 * DD: hardware cache op result ID
4951 * EEEEEEEE: PMU type ID
50− * If the PMU type ID is 0, the PERF_TYPE_RAW will be applied.
52+ *
53+ * If the PMU type ID is 0, PERF_TYPE_RAW will be applied.
5154 */
52−#define PERF_PMU_TYPE_SHIFT 32
53−#define PERF_HW_EVENT_MASK 0xffffffff
55+#define PERF_PMU_TYPE_SHIFT 32
56+#define PERF_HW_EVENT_MASK 0xffffffff
5457
5558 /*
5659 * Generalized performance event event_id types, used by the
@@ -112,7 +115,7 @@ enum perf_hw_cache_op_result_id { · 55 unmodified lines
112115 /*
113116 * Special "software" events provided by the kernel, even if the hardware
114117 * does not support performance events. These events measure various
115− * physical and sw events of the kernel (and allow the profiling of them as
118+ * physical and SW events of the kernel (and allow the profiling of them as
116119 * well):
117120 */
118121 enum perf_sw_ids {
@@ -167,8 +170,9 @@ enum perf_event_sample_format { · 48 unmodified lines
167170 };
168171
169172 #define PERF_SAMPLE_WEIGHT_TYPE (PERF_SAMPLE_WEIGHT | PERF_SAMPLE_WEIGHT_STRUCT)
173+
170174 /*
171− * values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set
175+ * Values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set.
172176 *
173177 * If the user does not pass priv level information via branch_sample_type,
174178 * the kernel uses the event's priv level. Branch and event priv levels do
@@ -178,20 +182,20 @@ enum perf_event_sample_format { · 3 unmodified lines
178182 * of branches and therefore it supersedes all the other types.
179183 */
180184 enum perf_branch_sample_type_shift {
181− PERF_SAMPLE_BRANCH_USER_SHIFT = 0, /* user branches */
182− PERF_SAMPLE_BRANCH_KERNEL_SHIFT = 1, /* kernel branches */
183− PERF_SAMPLE_BRANCH_HV_SHIFT = 2, /* hypervisor branches */
184−
185− PERF_SAMPLE_BRANCH_ANY_SHIFT = 3, /* any branch types */
186− PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT = 4, /* any call branch */
187− PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT = 5, /* any return branch */
188− PERF_SAMPLE_BRANCH_IND_CALL_SHIFT = 6, /* indirect calls */
189− PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT = 7, /* transaction aborts */
190− PERF_SAMPLE_BRANCH_IN_TX_SHIFT = 8, /* in transaction */
191− PERF_SAMPLE_BRANCH_NO_TX_SHIFT = 9, /* not in transaction */
185+ PERF_SAMPLE_BRANCH_USER_SHIFT = 0, /* user branches */
186+ PERF_SAMPLE_BRANCH_KERNEL_SHIFT = 1, /* kernel branches */
187+ PERF_SAMPLE_BRANCH_HV_SHIFT = 2, /* hypervisor branches */
188+
189+ PERF_SAMPLE_BRANCH_ANY_SHIFT = 3, /* any branch types */
190+ PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT = 4, /* any call branch */
191+ PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT = 5, /* any return branch */
192+ PERF_SAMPLE_BRANCH_IND_CALL_SHIFT = 6, /* indirect calls */
193+ PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT = 7, /* transaction aborts */
194+ PERF_SAMPLE_BRANCH_IN_TX_SHIFT = 8, /* in transaction */
195+ PERF_SAMPLE_BRANCH_NO_TX_SHIFT = 9, /* not in transaction */
192196 PERF_SAMPLE_BRANCH_COND_SHIFT = 10, /* conditional branches */
193197
194− PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* call/ret stack */
198+ PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* CALL/RET stack */
195199 PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT = 12, /* indirect jumps */
196200 PERF_SAMPLE_BRANCH_CALL_SHIFT = 13, /* direct call */
197201
@@ -210,96 +214,95 @@ enum perf_branch_sample_type_shift { · 12 unmodified lines
210214 };
211215
212216 enum perf_branch_sample_type {
213− PERF_SAMPLE_BRANCH_USER = 1U << PERF_SAMPLE_BRANCH_USER_SHIFT,
214− PERF_SAMPLE_BRANCH_KERNEL = 1U << PERF_SAMPLE_BRANCH_KERNEL_SHIFT,
215− PERF_SAMPLE_BRANCH_HV = 1U << PERF_SAMPLE_BRANCH_HV_SHIFT,
217+ PERF_SAMPLE_BRANCH_USER = 1U << PERF_SAMPLE_BRANCH_USER_SHIFT,
218+ PERF_SAMPLE_BRANCH_KERNEL = 1U << PERF_SAMPLE_BRANCH_KERNEL_SHIFT,
219+ PERF_SAMPLE_BRANCH_HV = 1U << PERF_SAMPLE_BRANCH_HV_SHIFT,
216220
217− PERF_SAMPLE_BRANCH_ANY = 1U << PERF_SAMPLE_BRANCH_ANY_SHIFT,
218− PERF_SAMPLE_BRANCH_ANY_CALL = 1U << PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,
219− PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,
220− PERF_SAMPLE_BRANCH_IND_CALL = 1U << PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,
221− PERF_SAMPLE_BRANCH_ABORT_TX = 1U << PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,
222− PERF_SAMPLE_BRANCH_IN_TX = 1U << PERF_SAMPLE_BRANCH_IN_TX_SHIFT,
223− PERF_SAMPLE_BRANCH_NO_TX = 1U << PERF_SAMPLE_BRANCH_NO_TX_SHIFT,
224− PERF_SAMPLE_BRANCH_COND = 1U << PERF_SAMPLE_BRANCH_COND_SHIFT,
221+ PERF_SAMPLE_BRANCH_ANY = 1U << PERF_SAMPLE_BRANCH_ANY_SHIFT,
222+ PERF_SAMPLE_BRANCH_ANY_CALL = 1U << PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,
223+ PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,
224+ PERF_SAMPLE_BRANCH_IND_CALL = 1U << PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,
225+ PERF_SAMPLE_BRANCH_ABORT_TX = 1U << PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,
226+ PERF_SAMPLE_BRANCH_IN_TX = 1U << PERF_SAMPLE_BRANCH_IN_TX_SHIFT,
227+ PERF_SAMPLE_BRANCH_NO_TX = 1U << PERF_SAMPLE_BRANCH_NO_TX_SHIFT,
228+ PERF_SAMPLE_BRANCH_COND = 1U << PERF_SAMPLE_BRANCH_COND_SHIFT,
225229
226− PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
227− PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
228− PERF_SAMPLE_BRANCH_CALL = 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT,
230+ PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
231+ PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
232+ PERF_SAMPLE_BRANCH_CALL = 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT,
229233
230− PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,
231− PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT,
234+ PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,
235+ PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT,
232236
233− PERF_SAMPLE_BRANCH_TYPE_SAVE =
234− 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT,
237+ PERF_SAMPLE_BRANCH_TYPE_SAVE = 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT,
235238
236− PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
239+ PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
237240
238− PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
241+ PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
239242
240− PERF_SAMPLE_BRANCH_COUNTERS = 1U << PERF_SAMPLE_BRANCH_COUNTERS_SHIFT,
243+ PERF_SAMPLE_BRANCH_COUNTERS = 1U << PERF_SAMPLE_BRANCH_COUNTERS_SHIFT,
241244
242− PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
245+ PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
243246 };
244247
245248 /*
246− * Common flow change classification
249+ * Common control flow change classifications:
247250 */
248251 enum {
249− PERF_BR_UNKNOWN = 0, /* unknown */
250− PERF_BR_COND = 1, /* conditional */
251− PERF_BR_UNCOND = 2, /* unconditional */
252− PERF_BR_IND = 3, /* indirect */
253− PERF_BR_CALL = 4, /* function call */
254− PERF_BR_IND_CALL = 5, /* indirect function call */
255− PERF_BR_RET = 6, /* function return */
256− PERF_BR_SYSCALL = 7, /* syscall */
257− PERF_BR_SYSRET = 8, /* syscall return */
258− PERF_BR_COND_CALL = 9, /* conditional function call */
259− PERF_BR_COND_RET = 10, /* conditional function return */
260− PERF_BR_ERET = 11, /* exception return */
261− PERF_BR_IRQ = 12, /* irq */
262− PERF_BR_SERROR = 13, /* system error */
263− PERF_BR_NO_TX = 14, /* not in transaction */
264− PERF_BR_EXTEND_ABI = 15, /* extend ABI */
252+ PERF_BR_UNKNOWN = 0, /* Unknown */
253+ PERF_BR_COND = 1, /* Conditional */
254+ PERF_BR_UNCOND = 2, /* Unconditional */
255+ PERF_BR_IND = 3, /* Indirect */
256+ PERF_BR_CALL = 4, /* Function call */
257+ PERF_BR_IND_CALL = 5, /* Indirect function call */
258+ PERF_BR_RET = 6, /* Function return */
259+ PERF_BR_SYSCALL = 7, /* Syscall */
260+ PERF_BR_SYSRET = 8, /* Syscall return */
261+ PERF_BR_COND_CALL = 9, /* Conditional function call */
262+ PERF_BR_COND_RET = 10, /* Conditional function return */
263+ PERF_BR_ERET = 11, /* Exception return */
264+ PERF_BR_IRQ = 12, /* IRQ */
265+ PERF_BR_SERROR = 13, /* System error */
266+ PERF_BR_NO_TX = 14, /* Not in transaction */
267+ PERF_BR_EXTEND_ABI = 15, /* Extend ABI */
265268 PERF_BR_MAX,
266269 };
267270
268271 /*
269− * Common branch speculation outcome classification
272+ * Common branch speculation outcome classifications:
270273 */
271274 enum {
272− PERF_BR_SPEC_NA = 0, /* Not available */
273− PERF_BR_SPEC_WRONG_PATH = 1, /* Speculative but on wrong path */
274− PERF_BR_NON_SPEC_CORRECT_PATH = 2, /* Non-speculative but on correct path */
275− PERF_BR_SPEC_CORRECT_PATH = 3, /* Speculative and on correct path */
275+ PERF_BR_SPEC_NA = 0, /* Not available */
276+ PERF_BR_SPEC_WRONG_PATH = 1, /* Speculative but on wrong path */
277+ PERF_BR_NON_SPEC_CORRECT_PATH = 2, /* Non-speculative but on correct path */
278+ PERF_BR_SPEC_CORRECT_PATH = 3, /* Speculative and on correct path */
276279 PERF_BR_SPEC_MAX,
277280 };
278281
279282 enum {
280− PERF_BR_NEW_FAULT_ALGN = 0, /* Alignment fault */
281− PERF_BR_NEW_FAULT_DATA = 1, /* Data fault */
282− PERF_BR_NEW_FAULT_INST = 2, /* Inst fault */
283− PERF_BR_NEW_ARCH_1 = 3, /* Architecture specific */
284− PERF_BR_NEW_ARCH_2 = 4, /* Architecture specific */
285− PERF_BR_NEW_ARCH_3 = 5, /* Architecture specific */
286− PERF_BR_NEW_ARCH_4 = 6, /* Architecture specific */
287− PERF_BR_NEW_ARCH_5 = 7, /* Architecture specific */
283+ PERF_BR_NEW_FAULT_ALGN = 0, /* Alignment fault */
284+ PERF_BR_NEW_FAULT_DATA = 1, /* Data fault */
285+ PERF_BR_NEW_FAULT_INST = 2, /* Inst fault */
286+ PERF_BR_NEW_ARCH_1 = 3, /* Architecture specific */
287+ PERF_BR_NEW_ARCH_2 = 4, /* Architecture specific */
288+ PERF_BR_NEW_ARCH_3 = 5, /* Architecture specific */
289+ PERF_BR_NEW_ARCH_4 = 6, /* Architecture specific */
290+ PERF_BR_NEW_ARCH_5 = 7, /* Architecture specific */
288291 PERF_BR_NEW_MAX,
289292 };
290293
291294 enum {
292− PERF_BR_PRIV_UNKNOWN = 0,
293− PERF_BR_PRIV_USER = 1,
294− PERF_BR_PRIV_KERNEL = 2,
295− PERF_BR_PRIV_HV = 3,
295+ PERF_BR_PRIV_UNKNOWN = 0,
296+ PERF_BR_PRIV_USER = 1,
297+ PERF_BR_PRIV_KERNEL = 2,
298+ PERF_BR_PRIV_HV = 3,
296299 };
297300
298−#define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1
299−#define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2
300−#define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3
301−#define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4
302−#define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5
301+#define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1
302+#define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2
303+#define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3
304+#define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4
305+#define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5
303306
304307 #define PERF_SAMPLE_BRANCH_PLM_ALL \
305308 (PERF_SAMPLE_BRANCH_USER|\
@@ -310,9 +313,9 @@ enum { · 4 unmodified lines
310313 * Values to determine ABI of the registers dump.
311314 */
312315 enum perf_sample_regs_abi {
313− PERF_SAMPLE_REGS_ABI_NONE = 0,
314− PERF_SAMPLE_REGS_ABI_32 = 1,
315− PERF_SAMPLE_REGS_ABI_64 = 2,
316+ PERF_SAMPLE_REGS_ABI_NONE = 0,
317+ PERF_SAMPLE_REGS_ABI_32 = 1,
318+ PERF_SAMPLE_REGS_ABI_64 = 2,
316319 };
317320
318321 /*
@@ -320,21 +323,21 @@ enum perf_sample_regs_abi { · 1 unmodified line
320323 * abort events. Multiple bits can be set.
321324 */
322325 enum {
323− PERF_TXN_ELISION = (1 << 0), /* From elision */
324− PERF_TXN_TRANSACTION = (1 << 1), /* From transaction */
325− PERF_TXN_SYNC = (1 << 2), /* Instruction is related */
326− PERF_TXN_ASYNC = (1 << 3), /* Instruction not related */
327− PERF_TXN_RETRY = (1 << 4), /* Retry possible */
328− PERF_TXN_CONFLICT = (1 << 5), /* Conflict abort */
329− PERF_TXN_CAPACITY_WRITE = (1 << 6), /* Capacity write abort */
330− PERF_TXN_CAPACITY_READ = (1 << 7), /* Capacity read abort */
326+ PERF_TXN_ELISION = (1 << 0), /* From elision */
327+ PERF_TXN_TRANSACTION = (1 << 1), /* From transaction */
328+ PERF_TXN_SYNC = (1 << 2), /* Instruction is related */
329+ PERF_TXN_ASYNC = (1 << 3), /* Instruction is not related */
330+ PERF_TXN_RETRY = (1 << 4), /* Retry possible */
331+ PERF_TXN_CONFLICT = (1 << 5), /* Conflict abort */
332+ PERF_TXN_CAPACITY_WRITE = (1 << 6), /* Capacity write abort */
333+ PERF_TXN_CAPACITY_READ = (1 << 7), /* Capacity read abort */
331334
332− PERF_TXN_MAX = (1 << 8), /* non-ABI */
335+ PERF_TXN_MAX = (1 << 8), /* non-ABI */
333336
334− /* bits 32..63 are reserved for the abort code */
337+ /* Bits 32..63 are reserved for the abort code */
335338
336− PERF_TXN_ABORT_MASK = (0xffffffffULL << 32),
337− PERF_TXN_ABORT_SHIFT = 32,
339+ PERF_TXN_ABORT_MASK = (0xffffffffULL << 32),
340+ PERF_TXN_ABORT_SHIFT = 32,
338341 };
339342
340343 /*
@@ -369,24 +372,22 @@ enum perf_event_read_format { · 28 unmodified lines
369372 PERF_FORMAT_MAX = 1U << 5, /* non-ABI */
370373 };
371374
372−#define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
373−#define PERF_ATTR_SIZE_VER1 72 /* add: config2 */
374−#define PERF_ATTR_SIZE_VER2 80 /* add: branch_sample_type */
375−#define PERF_ATTR_SIZE_VER3 96 /* add: sample_regs_user */
376− /* add: sample_stack_user */
377−#define PERF_ATTR_SIZE_VER4 104 /* add: sample_regs_intr */
378−#define PERF_ATTR_SIZE_VER5 112 /* add: aux_watermark */
379−#define PERF_ATTR_SIZE_VER6 120 /* add: aux_sample_size */
380−#define PERF_ATTR_SIZE_VER7 128 /* add: sig_data */
381−#define PERF_ATTR_SIZE_VER8 136 /* add: config3 */
375+#define PERF_ATTR_SIZE_VER0 64 /* Size of first published 'struct perf_event_attr' */
376+#define PERF_ATTR_SIZE_VER1 72 /* Add: config2 */
377+#define PERF_ATTR_SIZE_VER2 80 /* Add: branch_sample_type */
378+#define PERF_ATTR_SIZE_VER3 96 /* Add: sample_regs_user */
379+ /* Add: sample_stack_user */
380+#define PERF_ATTR_SIZE_VER4 104 /* Add: sample_regs_intr */
381+#define PERF_ATTR_SIZE_VER5 112 /* Add: aux_watermark */
382+#define PERF_ATTR_SIZE_VER6 120 /* Add: aux_sample_size */
383+#define PERF_ATTR_SIZE_VER7 128 /* Add: sig_data */
384+#define PERF_ATTR_SIZE_VER8 136 /* Add: config3 */
382385
383386 /*
384− * Hardware event_id to monitor via a performance monitoring event:
385− *
386− * @sample_max_stack: Max number of frame pointers in a callchain,
387− * should be < /proc/sys/kernel/perf_event_max_stack
388− * Max number of entries of branch stack
389− * should be < hardware limit
387+ * 'struct perf_event_attr' contains various attributes that define
388+ * a performance event - most of them hardware related configuration
389+ * details, but also a lot of behavioral switches and values implemented
390+ * by the kernel.
390391 */
391392 struct perf_event_attr {
392393
@@ -396,7 +397,7 @@ struct perf_event_attr { · 3 unmodified lines
396397 __u32 type;
397398
398399 /*
399− * Size of the attr structure, for fwd/bwd compat.
400+ * Size of the attr structure, for forward/backwards compatibility.
400401 */
401402 __u32 size;
402403
@@ -451,21 +452,21 @@ struct perf_event_attr { · 48 unmodified lines
451452 comm_exec : 1, /* flag comm events that are due to an exec */
452453 use_clockid : 1, /* use @clockid for time fields */
453454 context_switch : 1, /* context switch data */
454− write_backward : 1, /* Write ring buffer from end to beginning */
455+ write_backward : 1, /* write ring buffer from end to beginning */
455456 namespaces : 1, /* include namespaces data */
456457 ksymbol : 1, /* include ksymbol events */
457− bpf_event : 1, /* include bpf events */
458+ bpf_event : 1, /* include BPF events */
458459 aux_output : 1, /* generate AUX records instead of events */
459460 cgroup : 1, /* include cgroup events */
460461 text_poke : 1, /* include text poke events */
461− build_id : 1, /* use build id in mmap2 events */
462+ build_id : 1, /* use build ID in mmap2 events */
462463 inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD */
463464 remove_on_exec : 1, /* event is removed from task on exec */
464465 sigtrap : 1, /* send synchronous SIGTRAP on event */
465466 __reserved_1 : 26;
466467
467468 union {
468− __u32 wakeup_events; /* wakeup every n events */
469+ __u32 wakeup_events; /* wake up every n events */
469470 __u32 wakeup_watermark; /* bytes before wakeup */
470471 };
471472
@@ -474,13 +475,13 @@ struct perf_event_attr { · 2 unmodified lines
474475 __u64 bp_addr;
475476 __u64 kprobe_func; /* for perf_kprobe */
476477 __u64 uprobe_path; /* for perf_uprobe */
477− __u64 config1; /* extension of config */
478+ __u64 config1; /* extension of config */
478479 };
479480 union {
480481 __u64 bp_len;
481− __u64 kprobe_addr; /* when kprobe_func == NULL */
482+ __u64 kprobe_addr; /* when kprobe_func == NULL */
482483 __u64 probe_offset; /* for perf_[k,u]probe */
483− __u64 config2; /* extension of config1 */
484+ __u64 config2; /* extension of config1 */
484485 };
485486 __u64 branch_sample_type; /* enum perf_branch_sample_type */
486487
@@ -510,7 +511,16 @@ struct perf_event_attr { · 23 unmodified lines
510511 * Wakeup watermark for AUX area
511512 */
512513 __u32 aux_watermark;
514+
515+ /*
516+ * Max number of frame pointers in a callchain, should be
517+ * lower than /proc/sys/kernel/perf_event_max_stack.
518+ *
519+ * Max number of entries of branch stack should be lower
520+ * than the hardware limit.
521+ */
513522 __u16 sample_max_stack;
523+
514524 __u16 __reserved_2;
515525 __u32 aux_sample_size;
516526
@@ -537,7 +547,7 @@ struct perf_event_attr { · 20 unmodified lines
537547
538548 /*
539549 * Structure used by below PERF_EVENT_IOC_QUERY_BPF command
540− * to query bpf programs attached to the same perf tracepoint
550+ * to query BPF programs attached to the same perf tracepoint
541551 * as the given perf event.
542552 */
543553 struct perf_event_query_bpf {
@@ -559,21 +569,21 @@ struct perf_event_query_bpf { · 15 unmodified lines
559569 /*
560570 * Ioctls that can be done on a perf event fd:
561571 */
562−#define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
563−#define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
564−#define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
565−#define PERF_EVENT_IOC_RESET _IO ('$', 3)
566−#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
567−#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
568−#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
569−#define PERF_EVENT_IOC_ID _IOR('$', 7, __u64 *)
570−#define PERF_EVENT_IOC_SET_BPF _IOW('$', 8, __u32)
571−#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32)
572+#define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
573+#define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
574+#define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
575+#define PERF_EVENT_IOC_RESET _IO ('$', 3)
576+#define PERF_EVENT_IOC_PERIOD _IOW ('$', 4, __u64)
577+#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
578+#define PERF_EVENT_IOC_SET_FILTER _IOW ('$', 6, char *)
579+#define PERF_EVENT_IOC_ID _IOR ('$', 7, __u64 *)
580+#define PERF_EVENT_IOC_SET_BPF _IOW ('$', 8, __u32)
581+#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW ('$', 9, __u32)
572582 #define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *)
573−#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *)
583+#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW ('$', 11, struct perf_event_attr *)
574584
575585 enum perf_event_ioc_flags {
576− PERF_IOC_FLAG_GROUP = 1U << 0,
586+ PERF_IOC_FLAG_GROUP = 1U << 0,
577587 };
578588
579589 /*
@@ -584,7 +594,7 @@ struct perf_event_mmap_page { · 4 unmodified lines
584594 __u32 compat_version; /* lowest version this is compat with */
585595
586596 /*
587− * Bits needed to read the hw events in user-space.
597+ * Bits needed to read the HW events in user-space.
588598 *
589599 * u32 seq, time_mult, time_shift, index, width;
590600 * u64 count, enabled, running;
@@ -622,7 +632,7 @@ struct perf_event_mmap_page { · 31 unmodified lines
622632 __u32 index; /* hardware event identifier */
623633 __s64 offset; /* add to hardware event value */
624634 __u64 time_enabled; /* time event active */
625− __u64 time_running; /* time event on cpu */
635+ __u64 time_running; /* time event on CPU */
626636 union {
627637 __u64 capabilities;
628638 struct {
@@ -650,7 +660,7 @@ struct perf_event_mmap_page { · 21 unmodified lines
650660
651661 /*
652662 * If cap_usr_time the below fields can be used to compute the time
653− * delta since time_enabled (in ns) using rdtsc or similar.
663+ * delta since time_enabled (in ns) using RDTSC or similar.
654664 *
655665 * u64 quot, rem;
656666 * u64 delta;
@@ -723,7 +733,7 @@ struct perf_event_mmap_page { · 66 unmodified lines
723733 * after reading this value.
724734 *
725735 * When the mapping is PROT_WRITE the @data_tail value should be
726− * written by userspace to reflect the last read data, after issueing
736+ * written by user-space to reflect the last read data, after issuing
727737 * an smp_mb() to separate the data read from the ->data_tail store.
728738 * In this case the kernel will not over-write unread data.
729739 *
@@ -739,7 +749,7 @@ struct perf_event_mmap_page { · 9 unmodified lines
739749
740750 /*
741751 * AUX area is defined by aux_{offset,size} fields that should be set
742− * by the userspace, so that
752+ * by the user-space, so that
743753 *
744754 * aux_offset >= data_offset + data_size
745755 *
@@ -813,7 +823,7 @@ struct perf_event_mmap_page { · 67 unmodified lines
813823 * Indicates that thread was preempted in TASK_RUNNING state.
814824 *
815825 * PERF_RECORD_MISC_MMAP_BUILD_ID:
816− * Indicates that mmap2 event carries build id data.
826+ * Indicates that mmap2 event carries build ID data.
817827 */
818828 #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
819829 #define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
@@ -824,26 +834,26 @@ struct perf_event_mmap_page { · 4 unmodified lines
824834 #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15)
825835
826836 struct perf_event_header {
827− __u32 type;
828− __u16 misc;
829− __u16 size;
837+ __u32 type;
838+ __u16 misc;
839+ __u16 size;
830840 };
831841
832842 struct perf_ns_link_info {
833− __u64 dev;
834− __u64 ino;
843+ __u64 dev;
844+ __u64 ino;
835845 };
836846
837847 enum {
838− NET_NS_INDEX = 0,
839− UTS_NS_INDEX = 1,
840− IPC_NS_INDEX = 2,
841− PID_NS_INDEX = 3,
842− USER_NS_INDEX = 4,
843− MNT_NS_INDEX = 5,
844− CGROUP_NS_INDEX = 6,
845−
846− NR_NAMESPACES, /* number of available namespaces */
848+ NET_NS_INDEX = 0,
849+ UTS_NS_INDEX = 1,
850+ IPC_NS_INDEX = 2,
851+ PID_NS_INDEX = 3,
852+ USER_NS_INDEX = 4,
853+ MNT_NS_INDEX = 5,
854+ CGROUP_NS_INDEX = 6,
855+
856+ NR_NAMESPACES, /* number of available namespaces */
847857 };
848858
849859 enum perf_event_type {
@@ -859,11 +869,11 @@ enum perf_event_type { · 9 unmodified lines
859869 * optional fields being ignored.
860870 *
861871 * struct sample_id {
862− * { u32 pid, tid; } && PERF_SAMPLE_TID
863− * { u64 time; } && PERF_SAMPLE_TIME
864− * { u64 id; } && PERF_SAMPLE_ID
865− * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
866− * { u32 cpu, res; } && PERF_SAMPLE_CPU
872+ * { u32 pid, tid; } && PERF_SAMPLE_TID
873+ * { u64 time; } && PERF_SAMPLE_TIME
874+ * { u64 id; } && PERF_SAMPLE_ID
875+ * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
876+ * { u32 cpu, res; } && PERF_SAMPLE_CPU
867877 * { u64 id; } && PERF_SAMPLE_IDENTIFIER
868878 * } && perf_event_attr::sample_id_all
869879 *
@@ -874,7 +884,7 @@ enum perf_event_type { · 4 unmodified lines
874884
875885 /*
876886 * The MMAP events record the PROT_EXEC mappings so that we can
877− * correlate userspace IPs to code. They have the following structure:
887+ * correlate user-space IPs to code. They have the following structure:
878888 *
879889 * struct {
880890 * struct perf_event_header header;
@@ -884,7 +894,7 @@ enum perf_event_type { · 3 unmodified lines
884894 * u64 len;
885895 * u64 pgoff;
886896 * char filename[];
887− * struct sample_id sample_id;
897+ * struct sample_id sample_id;
888898 * };
889899 */
890900 PERF_RECORD_MMAP = 1,
@@ -894,7 +904,7 @@ enum perf_event_type { · 3 unmodified lines
894904 * struct perf_event_header header;
895905 * u64 id;
896906 * u64 lost;
897− * struct sample_id sample_id;
907+ * struct sample_id sample_id;
898908 * };
899909 */
900910 PERF_RECORD_LOST = 2,
@@ -905,7 +915,7 @@ enum perf_event_type { · 4 unmodified lines
905915 *
906916 * u32 pid, tid;
907917 * char comm[];
908− * struct sample_id sample_id;
918+ * struct sample_id sample_id;
909919 * };
910920 */
911921 PERF_RECORD_COMM = 3,
@@ -916,7 +926,7 @@ enum perf_event_type { · 4 unmodified lines
916926 * u32 pid, ppid;
917927 * u32 tid, ptid;
918928 * u64 time;
919− * struct sample_id sample_id;
929+ * struct sample_id sample_id;
920930 * };
921931 */
922932 PERF_RECORD_EXIT = 4,
@@ -927,7 +937,7 @@ enum perf_event_type { · 4 unmodified lines
927937 * u64 time;
928938 * u64 id;
929939 * u64 stream_id;
930− * struct sample_id sample_id;
940+ * struct sample_id sample_id;
931941 * };
932942 */
933943 PERF_RECORD_THROTTLE = 5,
@@ -939,7 +949,7 @@ enum perf_event_type { · 5 unmodified lines
939949 * u32 pid, ppid;
940950 * u32 tid, ptid;
941951 * u64 time;
942− * struct sample_id sample_id;
952+ * struct sample_id sample_id;
943953 * };
944954 */
945955 PERF_RECORD_FORK = 7,
@@ -950,7 +960,7 @@ enum perf_event_type { · 4 unmodified lines
950960 * u32 pid, tid;
951961 *
952962 * struct read_format values;
953− * struct sample_id sample_id;
963+ * struct sample_id sample_id;
954964 * };
955965 */
956966 PERF_RECORD_READ = 8,
@@ -1005,12 +1015,12 @@ enum perf_event_type { · 48 unmodified lines
10051015 * { u64 counters; } cntr[nr] && PERF_SAMPLE_BRANCH_COUNTERS
10061016 * } && PERF_SAMPLE_BRANCH_STACK
10071017 *
1008− * { u64 abi; # enum perf_sample_regs_abi
1009− * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER
1018+ * { u64 abi; # enum perf_sample_regs_abi
1019+ * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER
10101020 *
1011− * { u64 size;
1012− * char data[size];
1013− * u64 dyn_size; } && PERF_SAMPLE_STACK_USER
1021+ * { u64 size;
1022+ * char data[size];
1023+ * u64 dyn_size; } && PERF_SAMPLE_STACK_USER
10141024 *
10151025 * { union perf_sample_weight
10161026 * {
@@ -1035,10 +1045,11 @@ enum perf_event_type { · 18 unmodified lines
10351045 * { u64 abi; # enum perf_sample_regs_abi
10361046 * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
10371047 * { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR
1038− * { u64 size;
1039− * char data[size]; } && PERF_SAMPLE_AUX
1048+ * { u64 cgroup;} && PERF_SAMPLE_CGROUP
10401049 * { u64 data_page_size;} && PERF_SAMPLE_DATA_PAGE_SIZE
10411050 * { u64 code_page_size;} && PERF_SAMPLE_CODE_PAGE_SIZE
1051+ * { u64 size;
1052+ * char data[size]; } && PERF_SAMPLE_AUX
10421053 * };
10431054 */
10441055 PERF_RECORD_SAMPLE = 9,
@@ -1070,7 +1081,7 @@ enum perf_event_type { · 25 unmodified lines
10701081 * };
10711082 * u32 prot, flags;
10721083 * char filename[];
1073− * struct sample_id sample_id;
1084+ * struct sample_id sample_id;
10741085 * };
10751086 */
10761087 PERF_RECORD_MMAP2 = 10,
@@ -1079,12 +1090,12 @@ enum perf_event_type { · 2 unmodified lines
10791090 * Records that new data landed in the AUX buffer part.
10801091 *
10811092 * struct {
1082− * struct perf_event_header header;
1093+ * struct perf_event_header header;
10831094 *
1084− * u64 aux_offset;
1085− * u64 aux_size;
1095+ * u64 aux_offset;
1096+ * u64 aux_size;
10861097 * u64 flags;
1087− * struct sample_id sample_id;
1098+ * struct sample_id sample_id;
10881099 * };
10891100 */
10901101 PERF_RECORD_AUX = 11,
@@ -1167,7 +1178,7 @@ enum perf_event_type { · 76 unmodified lines
11671178 PERF_RECORD_KSYMBOL = 17,
11681179
11691180 /*
1170− * Record bpf events:
1181+ * Record BPF events:
11711182 * enum perf_bpf_event_type {
11721183 * PERF_BPF_EVENT_UNKNOWN = 0,
11731184 * PERF_BPF_EVENT_PROG_LOAD = 1,
@@ -1245,181 +1256,181 @@ enum perf_record_ksymbol_type { · 71 unmodified lines
12451256 #define PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER (1 << 0)
12461257
12471258 enum perf_bpf_event_type {
1248− PERF_BPF_EVENT_UNKNOWN = 0,
1249− PERF_BPF_EVENT_PROG_LOAD = 1,
1250− PERF_BPF_EVENT_PROG_UNLOAD = 2,
1251− PERF_BPF_EVENT_MAX, /* non-ABI */
1259+ PERF_BPF_EVENT_UNKNOWN = 0,
1260+ PERF_BPF_EVENT_PROG_LOAD = 1,
1261+ PERF_BPF_EVENT_PROG_UNLOAD = 2,
1262+ PERF_BPF_EVENT_MAX, /* non-ABI */
12521263 };
12531264
1254−#define PERF_MAX_STACK_DEPTH 127
1255−#define PERF_MAX_CONTEXTS_PER_STACK 8
1265+#define PERF_MAX_STACK_DEPTH 127
1266+#define PERF_MAX_CONTEXTS_PER_STACK 8
12561267
12571268 enum perf_callchain_context {
1258− PERF_CONTEXT_HV = (__u64)-32,
1259− PERF_CONTEXT_KERNEL = (__u64)-128,
1260− PERF_CONTEXT_USER = (__u64)-512,
1269+ PERF_CONTEXT_HV = (__u64)-32,
1270+ PERF_CONTEXT_KERNEL = (__u64)-128,
1271+ PERF_CONTEXT_USER = (__u64)-512,
12611272
1262− PERF_CONTEXT_GUEST = (__u64)-2048,
1263− PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
1264− PERF_CONTEXT_GUEST_USER = (__u64)-2560,
1273+ PERF_CONTEXT_GUEST = (__u64)-2048,
1274+ PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
1275+ PERF_CONTEXT_GUEST_USER = (__u64)-2560,
12651276
1266− PERF_CONTEXT_MAX = (__u64)-4095,
1277+ PERF_CONTEXT_MAX = (__u64)-4095,
12671278 };
12681279
12691280 /**
12701281 * PERF_RECORD_AUX::flags bits
12711282 */
1272−#define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */
1273−#define PERF_AUX_FLAG_OVERWRITE 0x02 /* snapshot from overwrite mode */
1274−#define PERF_AUX_FLAG_PARTIAL 0x04 /* record contains gaps */
1275−#define PERF_AUX_FLAG_COLLISION 0x08 /* sample collided with another */
1283+#define PERF_AUX_FLAG_TRUNCATED 0x0001 /* Record was truncated to fit */
1284+#define PERF_AUX_FLAG_OVERWRITE 0x0002 /* Snapshot from overwrite mode */
1285+#define PERF_AUX_FLAG_PARTIAL 0x0004 /* Record contains gaps */
1286+#define PERF_AUX_FLAG_COLLISION 0x0008 /* Sample collided with another */
12761287 #define PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK 0xff00 /* PMU specific trace format type */
12771288
12781289 /* CoreSight PMU AUX buffer formats */
1279−#define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000 /* Default for backward compatibility */
1280−#define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100 /* Raw format of the source */
1290+#define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000 /* Default for backward compatibility */
1291+#define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100 /* Raw format of the source */
12811292
1282−#define PERF_FLAG_FD_NO_GROUP (1UL << 0)
1283−#define PERF_FLAG_FD_OUTPUT (1UL << 1)
1284−#define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup id, per-cpu mode only */
1285−#define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */
1293+#define PERF_FLAG_FD_NO_GROUP (1UL << 0)
1294+#define PERF_FLAG_FD_OUTPUT (1UL << 1)
1295+#define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup ID, per-CPU mode only */
1296+#define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */
12861297
12871298 #if defined(__LITTLE_ENDIAN_BITFIELD)
12881299 union perf_mem_data_src {
12891300 __u64 val;
12901301 struct {
1291− __u64 mem_op:5, /* type of opcode */
1292− mem_lvl:14, /* memory hierarchy level */
1293− mem_snoop:5, /* snoop mode */
1294− mem_lock:2, /* lock instr */
1295− mem_dtlb:7, /* tlb access */
1296− mem_lvl_num:4, /* memory hierarchy level number */
1297− mem_remote:1, /* remote */
1298− mem_snoopx:2, /* snoop mode, ext */
1299− mem_blk:3, /* access blocked */
1300− mem_hops:3, /* hop level */
1301− mem_rsvd:18;
1302+ __u64 mem_op : 5, /* Type of opcode */
1303+ mem_lvl : 14, /* Memory hierarchy level */
1304+ mem_snoop : 5, /* Snoop mode */
1305+ mem_lock : 2, /* Lock instr */
1306+ mem_dtlb : 7, /* TLB access */
1307+ mem_lvl_num : 4, /* Memory hierarchy level number */
1308+ mem_remote : 1, /* Remote */
1309+ mem_snoopx : 2, /* Snoop mode, ext */
1310+ mem_blk : 3, /* Access blocked */
1311+ mem_hops : 3, /* Hop level */
1312+ mem_rsvd : 18;
13021313 };
13031314 };
13041315 #elif defined(__BIG_ENDIAN_BITFIELD)
13051316 union perf_mem_data_src {
13061317 __u64 val;
13071318 struct {
1308− __u64 mem_rsvd:18,
1309− mem_hops:3, /* hop level */
1310− mem_blk:3, /* access blocked */
1311− mem_snoopx:2, /* snoop mode, ext */
1312− mem_remote:1, /* remote */
1313− mem_lvl_num:4, /* memory hierarchy level number */
1314− mem_dtlb:7, /* tlb access */
1315− mem_lock:2, /* lock instr */
1316− mem_snoop:5, /* snoop mode */
1317− mem_lvl:14, /* memory hierarchy level */
1318− mem_op:5; /* type of opcode */
1319+ __u64 mem_rsvd : 18,
1320+ mem_hops : 3, /* Hop level */
1321+ mem_blk : 3, /* Access blocked */
1322+ mem_snoopx : 2, /* Snoop mode, ext */
1323+ mem_remote : 1, /* Remote */
1324+ mem_lvl_num : 4, /* Memory hierarchy level number */
1325+ mem_dtlb : 7, /* TLB access */
1326+ mem_lock : 2, /* Lock instr */
1327+ mem_snoop : 5, /* Snoop mode */
1328+ mem_lvl : 14, /* Memory hierarchy level */
1329+ mem_op : 5; /* Type of opcode */
13191330 };
13201331 };
13211332 #else
1322−#error "Unknown endianness"
1333+# error "Unknown endianness"
13231334 #endif
13241335
1325−/* type of opcode (load/store/prefetch,code) */
1326−#define PERF_MEM_OP_NA 0x01 /* not available */
1327−#define PERF_MEM_OP_LOAD 0x02 /* load instruction */
1328−#define PERF_MEM_OP_STORE 0x04 /* store instruction */
1329−#define PERF_MEM_OP_PFETCH 0x08 /* prefetch */
1330−#define PERF_MEM_OP_EXEC 0x10 /* code (execution) */
1331−#define PERF_MEM_OP_SHIFT 0
1336+/* Type of memory opcode: */
1337+#define PERF_MEM_OP_NA 0x0001 /* Not available */
1338+#define PERF_MEM_OP_LOAD 0x0002 /* Load instruction */
1339+#define PERF_MEM_OP_STORE 0x0004 /* Store instruction */
1340+#define PERF_MEM_OP_PFETCH 0x0008 /* Prefetch */
1341+#define PERF_MEM_OP_EXEC 0x0010 /* Code (execution) */
1342+#define PERF_MEM_OP_SHIFT 0
13321343
13331344 /*
1334− * PERF_MEM_LVL_* namespace being depricated to some extent in the
1345+ * The PERF_MEM_LVL_* namespace is being deprecated to some extent in
13351346 * favour of newer composite PERF_MEM_{LVLNUM_,REMOTE_,SNOOPX_} fields.
1336− * Supporting this namespace inorder to not break defined ABIs.
1347+ * We support this namespace in order to not break defined ABIs.
13371348 *
1338− * memory hierarchy (memory level, hit or miss)
1349+ * Memory hierarchy (memory level, hit or miss)
13391350 */
1340−#define PERF_MEM_LVL_NA 0x01 /* not available */
1341−#define PERF_MEM_LVL_HIT 0x02 /* hit level */
1342−#define PERF_MEM_LVL_MISS 0x04 /* miss level */
1343−#define PERF_MEM_LVL_L1 0x08 /* L1 */
1344−#define PERF_MEM_LVL_LFB 0x10 /* Line Fill Buffer */
1345−#define PERF_MEM_LVL_L2 0x20 /* L2 */
1346−#define PERF_MEM_LVL_L3 0x40 /* L3 */
1347−#define PERF_MEM_LVL_LOC_RAM 0x80 /* Local DRAM */
1348−#define PERF_MEM_LVL_REM_RAM1 0x100 /* Remote DRAM (1 hop) */
1349−#define PERF_MEM_LVL_REM_RAM2 0x200 /* Remote DRAM (2 hops) */
1350−#define PERF_MEM_LVL_REM_CCE1 0x400 /* Remote Cache (1 hop) */
1351−#define PERF_MEM_LVL_REM_CCE2 0x800 /* Remote Cache (2 hops) */
1352−#define PERF_MEM_LVL_IO 0x1000 /* I/O memory */
1353−#define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */
1354−#define PERF_MEM_LVL_SHIFT 5
1355−
1356−#define PERF_MEM_REMOTE_REMOTE 0x01 /* Remote */
1357−#define PERF_MEM_REMOTE_SHIFT 37
1358−
1359−#define PERF_MEM_LVLNUM_L1 0x01 /* L1 */
1360−#define PERF_MEM_LVLNUM_L2 0x02 /* L2 */
1361−#define PERF_MEM_LVLNUM_L3 0x03 /* L3 */
1362−#define PERF_MEM_LVLNUM_L4 0x04 /* L4 */
1363−#define PERF_MEM_LVLNUM_L2_MHB 0x05 /* L2 Miss Handling Buffer */
1364−#define PERF_MEM_LVLNUM_MSC 0x06 /* Memory-side Cache */
1365−/* 0x7 available */
1366−#define PERF_MEM_LVLNUM_UNC 0x08 /* Uncached */
1367−#define PERF_MEM_LVLNUM_CXL 0x09 /* CXL */
1368−#define PERF_MEM_LVLNUM_IO 0x0a /* I/O */
1369−#define PERF_MEM_LVLNUM_ANY_CACHE 0x0b /* Any cache */
1370−#define PERF_MEM_LVLNUM_LFB 0x0c /* LFB / L1 Miss Handling Buffer */
1371−#define PERF_MEM_LVLNUM_RAM 0x0d /* RAM */
1372−#define PERF_MEM_LVLNUM_PMEM 0x0e /* PMEM */
1373−#define PERF_MEM_LVLNUM_NA 0x0f /* N/A */
1374−
1375−#define PERF_MEM_LVLNUM_SHIFT 33
1376−
1377−/* snoop mode */
1378−#define PERF_MEM_SNOOP_NA 0x01 /* not available */
1379−#define PERF_MEM_SNOOP_NONE 0x02 /* no snoop */
1380−#define PERF_MEM_SNOOP_HIT 0x04 /* snoop hit */
1381−#define PERF_MEM_SNOOP_MISS 0x08 /* snoop miss */
1382−#define PERF_MEM_SNOOP_HITM 0x10 /* snoop hit modified */
1383−#define PERF_MEM_SNOOP_SHIFT 19
1384−
1385−#define PERF_MEM_SNOOPX_FWD 0x01 /* forward */
1386−#define PERF_MEM_SNOOPX_PEER 0x02 /* xfer from peer */
1387−#define PERF_MEM_SNOOPX_SHIFT 38
1388−
1389−/* locked instruction */
1390−#define PERF_MEM_LOCK_NA 0x01 /* not available */
1391−#define PERF_MEM_LOCK_LOCKED 0x02 /* locked transaction */
1392−#define PERF_MEM_LOCK_SHIFT 24
1351+#define PERF_MEM_LVL_NA 0x0001 /* Not available */
1352+#define PERF_MEM_LVL_HIT 0x0002 /* Hit level */
1353+#define PERF_MEM_LVL_MISS 0x0004 /* Miss level */
1354+#define PERF_MEM_LVL_L1 0x0008 /* L1 */
1355+#define PERF_MEM_LVL_LFB 0x0010 /* Line Fill Buffer */
1356+#define PERF_MEM_LVL_L2 0x0020 /* L2 */
1357+#define PERF_MEM_LVL_L3 0x0040 /* L3 */
1358+#define PERF_MEM_LVL_LOC_RAM 0x0080 /* Local DRAM */
1359+#define PERF_MEM_LVL_REM_RAM1 0x0100 /* Remote DRAM (1 hop) */
1360+#define PERF_MEM_LVL_REM_RAM2 0x0200 /* Remote DRAM (2 hops) */
1361+#define PERF_MEM_LVL_REM_CCE1 0x0400 /* Remote Cache (1 hop) */
1362+#define PERF_MEM_LVL_REM_CCE2 0x0800 /* Remote Cache (2 hops) */
1363+#define PERF_MEM_LVL_IO 0x1000 /* I/O memory */
1364+#define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */
1365+#define PERF_MEM_LVL_SHIFT 5
1366+
1367+#define PERF_MEM_REMOTE_REMOTE 0x0001 /* Remote */
1368+#define PERF_MEM_REMOTE_SHIFT 37
1369+
1370+#define PERF_MEM_LVLNUM_L1 0x0001 /* L1 */
1371+#define PERF_MEM_LVLNUM_L2 0x0002 /* L2 */
1372+#define PERF_MEM_LVLNUM_L3 0x0003 /* L3 */
1373+#define PERF_MEM_LVLNUM_L4 0x0004 /* L4 */
1374+#define PERF_MEM_LVLNUM_L2_MHB 0x0005 /* L2 Miss Handling Buffer */
1375+#define PERF_MEM_LVLNUM_MSC 0x0006 /* Memory-side Cache */
1376+/* 0x007 available */
1377+#define PERF_MEM_LVLNUM_UNC 0x0008 /* Uncached */
1378+#define PERF_MEM_LVLNUM_CXL 0x0009 /* CXL */
1379+#define PERF_MEM_LVLNUM_IO 0x000a /* I/O */
1380+#define PERF_MEM_LVLNUM_ANY_CACHE 0x000b /* Any cache */
1381+#define PERF_MEM_LVLNUM_LFB 0x000c /* LFB / L1 Miss Handling Buffer */
1382+#define PERF_MEM_LVLNUM_RAM 0x000d /* RAM */
1383+#define PERF_MEM_LVLNUM_PMEM 0x000e /* PMEM */
1384+#define PERF_MEM_LVLNUM_NA 0x000f /* N/A */
1385+
1386+#define PERF_MEM_LVLNUM_SHIFT 33
1387+
1388+/* Snoop mode */
1389+#define PERF_MEM_SNOOP_NA 0x0001 /* Not available */
1390+#define PERF_MEM_SNOOP_NONE 0x0002 /* No snoop */
1391+#define PERF_MEM_SNOOP_HIT 0x0004 /* Snoop hit */
1392+#define PERF_MEM_SNOOP_MISS 0x0008 /* Snoop miss */
1393+#define PERF_MEM_SNOOP_HITM 0x0010 /* Snoop hit modified */
1394+#define PERF_MEM_SNOOP_SHIFT 19
1395+
1396+#define PERF_MEM_SNOOPX_FWD 0x0001 /* Forward */
1397+#define PERF_MEM_SNOOPX_PEER 0x0002 /* Transfer from peer */
1398+#define PERF_MEM_SNOOPX_SHIFT 38
1399+
1400+/* Locked instruction */
1401+#define PERF_MEM_LOCK_NA 0x0001 /* Not available */
1402+#define PERF_MEM_LOCK_LOCKED 0x0002 /* Locked transaction */
1403+#define PERF_MEM_LOCK_SHIFT 24
13931404
13941405 /* TLB access */
1395−#define PERF_MEM_TLB_NA 0x01 /* not available */
1396−#define PERF_MEM_TLB_HIT 0x02 /* hit level */
1397−#define PERF_MEM_TLB_MISS 0x04 /* miss level */
1398−#define PERF_MEM_TLB_L1 0x08 /* L1 */
1399−#define PERF_MEM_TLB_L2 0x10 /* L2 */
1400−#define PERF_MEM_TLB_WK 0x20 /* Hardware Walker*/
1401−#define PERF_MEM_TLB_OS 0x40 /* OS fault handler */
1402−#define PERF_MEM_TLB_SHIFT 26
1406+#define PERF_MEM_TLB_NA 0x0001 /* Not available */
1407+#define PERF_MEM_TLB_HIT 0x0002 /* Hit level */
1408+#define PERF_MEM_TLB_MISS 0x0004 /* Miss level */
1409+#define PERF_MEM_TLB_L1 0x0008 /* L1 */
1410+#define PERF_MEM_TLB_L2 0x0010 /* L2 */
1411+#define PERF_MEM_TLB_WK 0x0020 /* Hardware Walker*/
1412+#define PERF_MEM_TLB_OS 0x0040 /* OS fault handler */
1413+#define PERF_MEM_TLB_SHIFT 26
14031414
14041415 /* Access blocked */
1405−#define PERF_MEM_BLK_NA 0x01 /* not available */
1406−#define PERF_MEM_BLK_DATA 0x02 /* data could not be forwarded */
1407−#define PERF_MEM_BLK_ADDR 0x04 /* address conflict */
1408−#define PERF_MEM_BLK_SHIFT 40
1409−
1410−/* hop level */
1411−#define PERF_MEM_HOPS_0 0x01 /* remote core, same node */
1412−#define PERF_MEM_HOPS_1 0x02 /* remote node, same socket */
1413−#define PERF_MEM_HOPS_2 0x03 /* remote socket, same board */
1414−#define PERF_MEM_HOPS_3 0x04 /* remote board */
1416+#define PERF_MEM_BLK_NA 0x0001 /* Not available */
1417+#define PERF_MEM_BLK_DATA 0x0002 /* Data could not be forwarded */
1418+#define PERF_MEM_BLK_ADDR 0x0004 /* Address conflict */
1419+#define PERF_MEM_BLK_SHIFT 40
1420+
1421+/* Hop level */
1422+#define PERF_MEM_HOPS_0 0x0001 /* Remote core, same node */
1423+#define PERF_MEM_HOPS_1 0x0002 /* Remote node, same socket */
1424+#define PERF_MEM_HOPS_2 0x0003 /* Remote socket, same board */
1425+#define PERF_MEM_HOPS_3 0x0004 /* Remote board */
14151426 /* 5-7 available */
1416−#define PERF_MEM_HOPS_SHIFT 43
1427+#define PERF_MEM_HOPS_SHIFT 43
14171428
14181429 #define PERF_MEM_S(a, s) \
14191430 (((__u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)
14201431
14211432 /*
1422− * single taken branch record layout:
1433+ * Layout of single taken branch records:
14231434 *
14241435 * from: source instruction (may not always be a branch insn)
14251436 * to: branch target
@@ -1438,37 +1449,37 @@ union perf_mem_data_src { · 12 unmodified lines
14381449 struct perf_branch_entry {
14391450 __u64 from;
14401451 __u64 to;
1441− __u64 mispred:1, /* target mispredicted */
1442− predicted:1,/* target predicted */
1443− in_tx:1, /* in transaction */
1444− abort:1, /* transaction abort */
1445− cycles:16, /* cycle count to last branch */
1446− type:4, /* branch type */
1447− spec:2, /* branch speculation info */
1448− new_type:4, /* additional branch type */
1449− priv:3, /* privilege level */
1450− reserved:31;
1452+ __u64 mispred : 1, /* target mispredicted */
1453+ predicted : 1, /* target predicted */
1454+ in_tx : 1, /* in transaction */
1455+ abort : 1, /* transaction abort */
1456+ cycles : 16, /* cycle count to last branch */
1457+ type : 4, /* branch type */
1458+ spec : 2, /* branch speculation info */
1459+ new_type : 4, /* additional branch type */
1460+ priv : 3, /* privilege level */
1461+ reserved : 31;
14511462 };
14521463
14531464 /* Size of used info bits in struct perf_branch_entry */
14541465 #define PERF_BRANCH_ENTRY_INFO_BITS_MAX 33
14551466
14561467 union perf_sample_weight {
1457− __u64 full;
1468+ __u64 full;
14581469 #if defined(__LITTLE_ENDIAN_BITFIELD)
14591470 struct {
1460− __u32 var1_dw;
1461− __u16 var2_w;
1462− __u16 var3_w;
1471+ __u32 var1_dw;
1472+ __u16 var2_w;
1473+ __u16 var3_w;
14631474 };
14641475 #elif defined(__BIG_ENDIAN_BITFIELD)
14651476 struct {
1466− __u16 var3_w;
1467− __u16 var2_w;
1468− __u32 var1_dw;
1477+ __u16 var3_w;
1478+ __u16 var2_w;
1479+ __u32 var1_dw;
14691480 };
14701481 #else
1471−#error "Unknown endianness"
1482+# error "Unknown endianness"
14721483 #endif
14731484 };
14741485
tools/testing/selftests/bpf/bench.c+12−0
@@ -526,6 +526,12 @@ extern const struct bench bench_trig_uprobe_multi_push; · 525 unmodified lines
526526 extern const struct bench bench_trig_uretprobe_multi_push;
527527 extern const struct bench bench_trig_uprobe_multi_ret;
528528 extern const struct bench bench_trig_uretprobe_multi_ret;
529+#ifdef __x86_64__
530+extern const struct bench bench_trig_uprobe_nop5;
531+extern const struct bench bench_trig_uretprobe_nop5;
532+extern const struct bench bench_trig_uprobe_multi_nop5;
533+extern const struct bench bench_trig_uretprobe_multi_nop5;
534+#endif
529535
530536 extern const struct bench bench_rb_libbpf;
531537 extern const struct bench bench_rb_custom;
@@ -586,6 +592,12 @@ static const struct bench *benchs[] = { · 54 unmodified lines
586592 &bench_trig_uretprobe_multi_push,
587593 &bench_trig_uprobe_multi_ret,
588594 &bench_trig_uretprobe_multi_ret,
595+#ifdef __x86_64__
596+ &bench_trig_uprobe_nop5,
597+ &bench_trig_uretprobe_nop5,
598+ &bench_trig_uprobe_multi_nop5,
599+ &bench_trig_uretprobe_multi_nop5,
600+#endif
589601 /* ringbuf/perfbuf benchmarks */
590602 &bench_rb_libbpf,
591603 &bench_rb_custom,
tools/testing/selftests/bpf/benchs/bench_trigger.c+42−0
@@ -333,6 +333,20 @@ static void *uprobe_producer_ret(void *input) · 332 unmodified lines
333333 return NULL;
334334 }
335335
336+#ifdef __x86_64__
337+__nocf_check __weak void uprobe_target_nop5(void)
338+{
339+ asm volatile (".byte 0x0f, 0x1f, 0x44, 0x00, 0x00");
340+}
341+
342+static void *uprobe_producer_nop5(void *input)
343+{
344+ while (true)
345+ uprobe_target_nop5();
346+ return NULL;
347+}
348+#endif
349+
336350 static void usetup(bool use_retprobe, bool use_multi, void *target_addr)
337351 {
338352 size_t uprobe_offset;
@@ -448,6 +462,28 @@ static void uretprobe_multi_ret_setup(void) · 109 unmodified lines
448462 usetup(true, true /* use_multi */, &uprobe_target_ret);
449463 }
450464
465+#ifdef __x86_64__
466+static void uprobe_nop5_setup(void)
467+{
468+ usetup(false, false /* !use_multi */, &uprobe_target_nop5);
469+}
470+
471+static void uretprobe_nop5_setup(void)
472+{
473+ usetup(true, false /* !use_multi */, &uprobe_target_nop5);
474+}
475+
476+static void uprobe_multi_nop5_setup(void)
477+{
478+ usetup(false, true /* use_multi */, &uprobe_target_nop5);
479+}
480+
481+static void uretprobe_multi_nop5_setup(void)
482+{
483+ usetup(true, true /* use_multi */, &uprobe_target_nop5);
484+}
485+#endif
486+
451487 const struct bench bench_trig_syscall_count = {
452488 .name = "trig-syscall-count",
453489 .validate = trigger_validate,
@@ -506,3 +542,9 @@ BENCH_TRIG_USERMODE(uprobe_multi_ret, ret, "uprobe-multi-ret"); · 52 unmodified lines
506542 BENCH_TRIG_USERMODE(uretprobe_multi_nop, nop, "uretprobe-multi-nop");
507543 BENCH_TRIG_USERMODE(uretprobe_multi_push, push, "uretprobe-multi-push");
508544 BENCH_TRIG_USERMODE(uretprobe_multi_ret, ret, "uretprobe-multi-ret");
545+#ifdef __x86_64__
546+BENCH_TRIG_USERMODE(uprobe_nop5, nop5, "uprobe-nop5");
547+BENCH_TRIG_USERMODE(uretprobe_nop5, nop5, "uretprobe-nop5");
548+BENCH_TRIG_USERMODE(uprobe_multi_nop5, nop5, "uprobe-multi-nop5");
549+BENCH_TRIG_USERMODE(uretprobe_multi_nop5, nop5, "uretprobe-multi-nop5");
550+#endif
tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22
33 set -eufo pipefail
44
5−for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret}
5+for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop5}
66 do
77 summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-)
88 printf "%-15s: %s\n" $i "$summary"