Skip to content

Commit 6c4aa89

Browse files
committed
Merge tag 'perf-core-2025-01-20' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull performance events updates from Ingo Molnar: "Seqlock optimizations that arose in a perf context and were merged into the perf tree: - seqlock: Add raw_seqcount_try_begin (Suren Baghdasaryan) - mm: Convert mm_lock_seq to a proper seqcount (Suren Baghdasaryan) - mm: Introduce mmap_lock_speculate_{try_begin|retry} (Suren Baghdasaryan) - mm/gup: Use raw_seqcount_try_begin() (Peter Zijlstra) Core perf enhancements: - Reduce 'struct page' footprint of perf by mapping pages in advance (Lorenzo Stoakes) - Save raw sample data conditionally based on sample type (Yabin Cui) - Reduce sampling overhead by checking sample_type in perf_sample_save_callchain() and perf_sample_save_brstack() (Yabin Cui) - Export perf_exclude_event() (Namhyung Kim) Uprobes scalability enhancements: (Andrii Nakryiko) - Simplify find_active_uprobe_rcu() VMA checks - Add speculative lockless VMA-to-inode-to-uprobe resolution - Simplify session consumer tracking - Decouple return_instance list traversal and freeing - Ensure return_instance is detached from the list before freeing - Reuse return_instances between multiple uretprobes within task - Guard against kmemdup() failing in dup_return_instance() AMD core PMU driver enhancements: - Relax privilege filter restriction on AMD IBS (Namhyung Kim) AMD RAPL energy counters support: (Dhananjay Ugwekar) - Introduce topology_logical_core_id() (K Prateek Nayak) - Remove the unused get_rapl_pmu_cpumask() function - Remove the cpu_to_rapl_pmu() function - Rename rapl_pmu variables - Make rapl_model struct global - Add arguments to the init and cleanup functions - Modify the generic variable names to *_pkg* - Remove the global variable rapl_msrs - Move the cntr_mask to rapl_pmus struct - Add core energy counter support for AMD CPUs Intel core PMU driver enhancements: - Support RDPMC 'metrics clear mode' feature (Kan Liang) - Clarify adaptive PEBS processing (Kan Liang) - Factor out functions for PEBS records processing (Kan Liang) - Simplify the PEBS records processing for adaptive PEBS (Kan Liang) Intel uncore driver enhancements: (Kan Liang) - Convert buggy pmu->func_id use to pmu->registered - Support more units on Granite Rapids" * tag 'perf-core-2025-01-20' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (33 commits) perf: map pages in advance perf/x86/intel/uncore: Support more units on Granite Rapids perf/x86/intel/uncore: Clean up func_id perf/x86/intel: Support RDPMC metrics clear mode uprobes: Guard against kmemdup() failing in dup_return_instance() perf/x86: Relax privilege filter restriction on AMD IBS perf/core: Export perf_exclude_event() uprobes: Reuse return_instances between multiple uretprobes within task uprobes: Ensure return_instance is detached from the list before freeing uprobes: Decouple return_instance list traversal and freeing uprobes: Simplify session consumer tracking uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution uprobes: simplify find_active_uprobe_rcu() VMA checks mm: introduce mmap_lock_speculate_{try_begin|retry} mm: convert mm_lock_seq to a proper seqcount mm/gup: Use raw_seqcount_try_begin() seqlock: add raw_seqcount_try_begin perf/x86/rapl: Add core energy counter support for AMD CPUs perf/x86/rapl: Move the cntr_mask to rapl_pmus struct perf/x86/rapl: Remove the global variable rapl_msrs ...
2 parents a6640c8 + b709eb8 commit 6c4aa89

36 files changed

+938
-479
lines changed

Documentation/arch/x86/topology.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ Thread-related topology information in the kernel:
135135
The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
136136
"core_id."
137137

138+
- topology_logical_core_id();
139+
140+
The logical core ID to which a thread belongs.
141+
138142

139143

140144
System topology examples

arch/s390/kernel/perf_cpum_cf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ static int cfdiag_push_sample(struct perf_event *event,
981981
if (event->attr.sample_type & PERF_SAMPLE_RAW) {
982982
raw.frag.size = cpuhw->usedss;
983983
raw.frag.data = cpuhw->stop;
984-
perf_sample_save_raw_data(&data, &raw);
984+
perf_sample_save_raw_data(&data, event, &raw);
985985
}
986986

987987
overflow = perf_event_overflow(event, &data, &regs);

arch/s390/kernel/perf_cpum_sf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ static void cpumsf_pmu_disable(struct pmu *pmu)
981981
cpuhw->flags &= ~PMU_F_ENABLED;
982982
}
983983

984-
/* perf_exclude_event() - Filter event
984+
/* perf_event_exclude() - Filter event
985985
* @event: The perf event
986986
* @regs: pt_regs structure
987987
* @sde_regs: Sample-data-entry (sde) regs structure
@@ -990,7 +990,7 @@ static void cpumsf_pmu_disable(struct pmu *pmu)
990990
*
991991
* Return non-zero if the event shall be excluded.
992992
*/
993-
static int perf_exclude_event(struct perf_event *event, struct pt_regs *regs,
993+
static int perf_event_exclude(struct perf_event *event, struct pt_regs *regs,
994994
struct perf_sf_sde_regs *sde_regs)
995995
{
996996
if (event->attr.exclude_user && user_mode(regs))
@@ -1073,7 +1073,7 @@ static int perf_push_sample(struct perf_event *event,
10731073
data.tid_entry.pid = basic->hpp & LPP_PID_MASK;
10741074

10751075
overflow = 0;
1076-
if (perf_exclude_event(event, &regs, sde_regs))
1076+
if (perf_event_exclude(event, &regs, sde_regs))
10771077
goto out;
10781078
if (perf_event_overflow(event, &data, &regs)) {
10791079
overflow = 1;

arch/s390/kernel/perf_pai_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static int paicrypt_push_sample(size_t rawsize, struct paicrypt_map *cpump,
478478
if (event->attr.sample_type & PERF_SAMPLE_RAW) {
479479
raw.frag.size = rawsize;
480480
raw.frag.data = cpump->save;
481-
perf_sample_save_raw_data(&data, &raw);
481+
perf_sample_save_raw_data(&data, event, &raw);
482482
}
483483

484484
overflow = perf_event_overflow(event, &data, &regs);

arch/s390/kernel/perf_pai_ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ static int paiext_push_sample(size_t rawsize, struct paiext_map *cpump,
503503
if (event->attr.sample_type & PERF_SAMPLE_RAW) {
504504
raw.frag.size = rawsize;
505505
raw.frag.data = cpump->save;
506-
perf_sample_save_raw_data(&data, &raw);
506+
perf_sample_save_raw_data(&data, event, &raw);
507507
}
508508

509509
overflow = perf_event_overflow(event, &data, &regs);

arch/x86/events/amd/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
10011001
if (!x86_perf_event_set_period(event))
10021002
continue;
10031003

1004-
if (has_branch_stack(event))
1005-
perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
1004+
perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
10061005

10071006
if (perf_event_overflow(event, &data, regs))
10081007
x86_pmu_stop(event, 0);

arch/x86/events/amd/ibs.c

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ static u32 ibs_caps;
3131
#define IBS_FETCH_CONFIG_MASK (IBS_FETCH_RAND_EN | IBS_FETCH_MAX_CNT)
3232
#define IBS_OP_CONFIG_MASK IBS_OP_MAX_CNT
3333

34+
/* attr.config2 */
35+
#define IBS_SW_FILTER_MASK 1
3436

3537
/*
3638
* IBS states:
@@ -290,6 +292,16 @@ static int perf_ibs_init(struct perf_event *event)
290292
if (has_branch_stack(event))
291293
return -EOPNOTSUPP;
292294

295+
/* handle exclude_{user,kernel} in the IRQ handler */
296+
if (event->attr.exclude_host || event->attr.exclude_guest ||
297+
event->attr.exclude_idle)
298+
return -EINVAL;
299+
300+
if (!(event->attr.config2 & IBS_SW_FILTER_MASK) &&
301+
(event->attr.exclude_kernel || event->attr.exclude_user ||
302+
event->attr.exclude_hv))
303+
return -EINVAL;
304+
293305
ret = validate_group(event);
294306
if (ret)
295307
return ret;
@@ -550,24 +562,14 @@ static struct attribute *attrs_empty[] = {
550562
NULL,
551563
};
552564

553-
static struct attribute_group empty_format_group = {
554-
.name = "format",
555-
.attrs = attrs_empty,
556-
};
557-
558565
static struct attribute_group empty_caps_group = {
559566
.name = "caps",
560567
.attrs = attrs_empty,
561568
};
562569

563-
static const struct attribute_group *empty_attr_groups[] = {
564-
&empty_format_group,
565-
&empty_caps_group,
566-
NULL,
567-
};
568-
569570
PMU_FORMAT_ATTR(rand_en, "config:57");
570571
PMU_FORMAT_ATTR(cnt_ctl, "config:19");
572+
PMU_FORMAT_ATTR(swfilt, "config2:0");
571573
PMU_EVENT_ATTR_STRING(l3missonly, fetch_l3missonly, "config:59");
572574
PMU_EVENT_ATTR_STRING(l3missonly, op_l3missonly, "config:16");
573575
PMU_EVENT_ATTR_STRING(zen4_ibs_extensions, zen4_ibs_extensions, "1");
@@ -578,8 +580,9 @@ zen4_ibs_extensions_is_visible(struct kobject *kobj, struct attribute *attr, int
578580
return ibs_caps & IBS_CAPS_ZEN4 ? attr->mode : 0;
579581
}
580582

581-
static struct attribute *rand_en_attrs[] = {
583+
static struct attribute *fetch_attrs[] = {
582584
&format_attr_rand_en.attr,
585+
&format_attr_swfilt.attr,
583586
NULL,
584587
};
585588

@@ -593,9 +596,9 @@ static struct attribute *zen4_ibs_extensions_attrs[] = {
593596
NULL,
594597
};
595598

596-
static struct attribute_group group_rand_en = {
599+
static struct attribute_group group_fetch_formats = {
597600
.name = "format",
598-
.attrs = rand_en_attrs,
601+
.attrs = fetch_attrs,
599602
};
600603

601604
static struct attribute_group group_fetch_l3missonly = {
@@ -611,7 +614,7 @@ static struct attribute_group group_zen4_ibs_extensions = {
611614
};
612615

613616
static const struct attribute_group *fetch_attr_groups[] = {
614-
&group_rand_en,
617+
&group_fetch_formats,
615618
&empty_caps_group,
616619
NULL,
617620
};
@@ -628,6 +631,11 @@ cnt_ctl_is_visible(struct kobject *kobj, struct attribute *attr, int i)
628631
return ibs_caps & IBS_CAPS_OPCNT ? attr->mode : 0;
629632
}
630633

634+
static struct attribute *op_attrs[] = {
635+
&format_attr_swfilt.attr,
636+
NULL,
637+
};
638+
631639
static struct attribute *cnt_ctl_attrs[] = {
632640
&format_attr_cnt_ctl.attr,
633641
NULL,
@@ -638,6 +646,11 @@ static struct attribute *op_l3missonly_attrs[] = {
638646
NULL,
639647
};
640648

649+
static struct attribute_group group_op_formats = {
650+
.name = "format",
651+
.attrs = op_attrs,
652+
};
653+
641654
static struct attribute_group group_cnt_ctl = {
642655
.name = "format",
643656
.attrs = cnt_ctl_attrs,
@@ -650,6 +663,12 @@ static struct attribute_group group_op_l3missonly = {
650663
.is_visible = zen4_ibs_extensions_is_visible,
651664
};
652665

666+
static const struct attribute_group *op_attr_groups[] = {
667+
&group_op_formats,
668+
&empty_caps_group,
669+
NULL,
670+
};
671+
653672
static const struct attribute_group *op_attr_update[] = {
654673
&group_cnt_ctl,
655674
&group_op_l3missonly,
@@ -667,7 +686,6 @@ static struct perf_ibs perf_ibs_fetch = {
667686
.start = perf_ibs_start,
668687
.stop = perf_ibs_stop,
669688
.read = perf_ibs_read,
670-
.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
671689
},
672690
.msr = MSR_AMD64_IBSFETCHCTL,
673691
.config_mask = IBS_FETCH_CONFIG_MASK,
@@ -691,7 +709,6 @@ static struct perf_ibs perf_ibs_op = {
691709
.start = perf_ibs_start,
692710
.stop = perf_ibs_stop,
693711
.read = perf_ibs_read,
694-
.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
695712
},
696713
.msr = MSR_AMD64_IBSOPCTL,
697714
.config_mask = IBS_OP_CONFIG_MASK,
@@ -1111,14 +1128,20 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
11111128
regs.flags |= PERF_EFLAGS_EXACT;
11121129
}
11131130

1131+
if ((event->attr.config2 & IBS_SW_FILTER_MASK) &&
1132+
perf_exclude_event(event, &regs)) {
1133+
throttle = perf_event_account_interrupt(event);
1134+
goto out;
1135+
}
1136+
11141137
if (event->attr.sample_type & PERF_SAMPLE_RAW) {
11151138
raw = (struct perf_raw_record){
11161139
.frag = {
11171140
.size = sizeof(u32) + ibs_data.size,
11181141
.data = ibs_data.data,
11191142
},
11201143
};
1121-
perf_sample_save_raw_data(&data, &raw);
1144+
perf_sample_save_raw_data(&data, event, &raw);
11221145
}
11231146

11241147
if (perf_ibs == &perf_ibs_op)
@@ -1129,8 +1152,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
11291152
* recorded as part of interrupt regs. Thus we need to use rip from
11301153
* interrupt regs while unwinding call stack.
11311154
*/
1132-
if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN)
1133-
perf_sample_save_callchain(&data, event, iregs);
1155+
perf_sample_save_callchain(&data, event, iregs);
11341156

11351157
throttle = perf_event_overflow(event, &data, &regs);
11361158
out:
@@ -1228,7 +1250,7 @@ static __init int perf_ibs_op_init(void)
12281250
if (ibs_caps & IBS_CAPS_ZEN4)
12291251
perf_ibs_op.config_mask |= IBS_OP_L3MISSONLY;
12301252

1231-
perf_ibs_op.pmu.attr_groups = empty_attr_groups;
1253+
perf_ibs_op.pmu.attr_groups = op_attr_groups;
12321254
perf_ibs_op.pmu.attr_update = op_attr_update;
12331255

12341256
return perf_ibs_pmu_init(&perf_ibs_op, "ibs_op");

arch/x86/events/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,8 +1707,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs)
17071707

17081708
perf_sample_data_init(&data, 0, event->hw.last_period);
17091709

1710-
if (has_branch_stack(event))
1711-
perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
1710+
perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
17121711

17131712
if (perf_event_overflow(event, &data, regs))
17141713
x86_pmu_stop(event, 0);

arch/x86/events/intel/core.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,9 @@ static void intel_pmu_enable_fixed(struct perf_event *event)
28262826
return;
28272827

28282828
idx = INTEL_PMC_IDX_FIXED_SLOTS;
2829+
2830+
if (event->attr.config1 & INTEL_TD_CFG_METRIC_CLEAR)
2831+
bits |= INTEL_FIXED_3_METRICS_CLEAR;
28292832
}
28302833

28312834
intel_set_masks(event, idx);
@@ -4081,7 +4084,12 @@ static int intel_pmu_hw_config(struct perf_event *event)
40814084
* is used in a metrics group, it too cannot support sampling.
40824085
*/
40834086
if (intel_pmu_has_cap(event, PERF_CAP_METRICS_IDX) && is_topdown_event(event)) {
4084-
if (event->attr.config1 || event->attr.config2)
4087+
/* The metrics_clear can only be set for the slots event */
4088+
if (event->attr.config1 &&
4089+
(!is_slots_event(event) || (event->attr.config1 & ~INTEL_TD_CFG_METRIC_CLEAR)))
4090+
return -EINVAL;
4091+
4092+
if (event->attr.config2)
40854093
return -EINVAL;
40864094

40874095
/*
@@ -4690,6 +4698,8 @@ PMU_FORMAT_ATTR(in_tx, "config:32" );
46904698
PMU_FORMAT_ATTR(in_tx_cp, "config:33" );
46914699
PMU_FORMAT_ATTR(eq, "config:36" ); /* v6 + */
46924700

4701+
PMU_FORMAT_ATTR(metrics_clear, "config1:0"); /* PERF_CAPABILITIES.RDPMC_METRICS_CLEAR */
4702+
46934703
static ssize_t umask2_show(struct device *dev,
46944704
struct device_attribute *attr,
46954705
char *page)
@@ -4709,6 +4719,7 @@ static struct device_attribute format_attr_umask2 =
47094719
static struct attribute *format_evtsel_ext_attrs[] = {
47104720
&format_attr_umask2.attr,
47114721
&format_attr_eq.attr,
4722+
&format_attr_metrics_clear.attr,
47124723
NULL
47134724
};
47144725

@@ -4733,6 +4744,13 @@ evtsel_ext_is_visible(struct kobject *kobj, struct attribute *attr, int i)
47334744
if (i == 1)
47344745
return (mask & ARCH_PERFMON_EVENTSEL_EQ) ? attr->mode : 0;
47354746

4747+
/* PERF_CAPABILITIES.RDPMC_METRICS_CLEAR */
4748+
if (i == 2) {
4749+
union perf_capabilities intel_cap = hybrid(dev_get_drvdata(dev), intel_cap);
4750+
4751+
return intel_cap.rdpmc_metrics_clear ? attr->mode : 0;
4752+
}
4753+
47364754
return 0;
47374755
}
47384756

0 commit comments

Comments
 (0)