Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'perf-urgent-2024-09-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf event fixes from Ingo Molnar:
"Left over from the v6.11 cycle:

- Fix energy-pkg event enumeration on certain AMD CPUs

- Set up the LBR branch stack for BPF counting events too"

* tag 'perf-urgent-2024-09-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/x86/intel: Allow to setup LBR for counting event for BPF
perf/x86/rapl: Fix the energy-pkg event for AMD CPUs

+48 -7
+6 -2
arch/x86/events/intel/core.c
··· 3972 3972 x86_pmu.pebs_aliases(event); 3973 3973 } 3974 3974 3975 - if (needs_branch_stack(event) && is_sampling_event(event)) 3976 - event->hw.flags |= PERF_X86_EVENT_NEEDS_BRANCH_STACK; 3975 + if (needs_branch_stack(event)) { 3976 + /* Avoid branch stack setup for counting events in SAMPLE READ */ 3977 + if (is_sampling_event(event) || 3978 + !(event->attr.sample_type & PERF_SAMPLE_READ)) 3979 + event->hw.flags |= PERF_X86_EVENT_NEEDS_BRANCH_STACK; 3980 + } 3977 3981 3978 3982 if (branch_sample_counters(event)) { 3979 3983 struct perf_event *leader, *sibling;
+42 -5
arch/x86/events/rapl.c
··· 103 103 .event_str = str, \ 104 104 }; 105 105 106 + /* 107 + * RAPL Package energy counter scope: 108 + * 1. AMD/HYGON platforms have a per-PKG package energy counter 109 + * 2. For Intel platforms 110 + * 2.1. CLX-AP is multi-die and its RAPL MSRs are die-scope 111 + * 2.2. Other Intel platforms are single die systems so the scope can be 112 + * considered as either pkg-scope or die-scope, and we are considering 113 + * them as die-scope. 114 + */ 115 + #define rapl_pmu_is_pkg_scope() \ 116 + (boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \ 117 + boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) 118 + 106 119 struct rapl_pmu { 107 120 raw_spinlock_t lock; 108 121 int n_active; ··· 153 140 static u64 rapl_timer_ms; 154 141 static struct perf_msr *rapl_msrs; 155 142 143 + /* 144 + * Helper functions to get the correct topology macros according to the 145 + * RAPL PMU scope. 146 + */ 147 + static inline unsigned int get_rapl_pmu_idx(int cpu) 148 + { 149 + return rapl_pmu_is_pkg_scope() ? topology_logical_package_id(cpu) : 150 + topology_logical_die_id(cpu); 151 + } 152 + 153 + static inline const struct cpumask *get_rapl_pmu_cpumask(int cpu) 154 + { 155 + return rapl_pmu_is_pkg_scope() ? topology_core_cpumask(cpu) : 156 + topology_die_cpumask(cpu); 157 + } 158 + 156 159 static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu) 157 160 { 158 - unsigned int rapl_pmu_idx = topology_logical_die_id(cpu); 161 + unsigned int rapl_pmu_idx = get_rapl_pmu_idx(cpu); 159 162 160 163 /* 161 164 * The unsigned check also catches the '-1' return value for non ··· 581 552 582 553 pmu->cpu = -1; 583 554 /* Find a new cpu to collect rapl events */ 584 - target = cpumask_any_but(topology_die_cpumask(cpu), cpu); 555 + target = cpumask_any_but(get_rapl_pmu_cpumask(cpu), cpu); 585 556 586 557 /* Migrate rapl events to the new target */ 587 558 if (target < nr_cpu_ids) { ··· 594 565 595 566 static int rapl_cpu_online(unsigned int cpu) 596 567 { 568 + s32 rapl_pmu_idx = get_rapl_pmu_idx(cpu); 569 + if (rapl_pmu_idx < 0) { 570 + pr_err("topology_logical_(package/die)_id() returned a negative value"); 571 + return -EINVAL; 572 + } 597 573 struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); 598 574 int target; 599 575 ··· 613 579 pmu->timer_interval = ms_to_ktime(rapl_timer_ms); 614 580 rapl_hrtimer_init(pmu); 615 581 616 - rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu; 582 + rapl_pmus->pmus[rapl_pmu_idx] = pmu; 617 583 } 618 584 619 585 /* 620 586 * Check if there is an online cpu in the package which collects rapl 621 587 * events already. 622 588 */ 623 - target = cpumask_any_and(&rapl_cpu_mask, topology_die_cpumask(cpu)); 589 + target = cpumask_any_and(&rapl_cpu_mask, get_rapl_pmu_cpumask(cpu)); 624 590 if (target < nr_cpu_ids) 625 591 return 0; 626 592 ··· 709 675 710 676 static int __init init_rapl_pmus(void) 711 677 { 712 - int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package(); 678 + int nr_rapl_pmu = topology_max_packages(); 679 + 680 + if (!rapl_pmu_is_pkg_scope()) 681 + nr_rapl_pmu *= topology_max_dies_per_package(); 713 682 714 683 rapl_pmus = kzalloc(struct_size(rapl_pmus, pmus, nr_rapl_pmu), GFP_KERNEL); 715 684 if (!rapl_pmus)