Add Alder Lake support for perf (kernel)
Subsystems (2)
v5 cover Add Alder Lake support for perf (kernel)
From: Kan Liang <[email protected]>
Changes since V4:
- Put the X86_HYBRID_CPU_TYPE_ID_SHIFT over the function where it is used (Boris) (Patch 2)
- Add Acked-by from Boris for Patch 1 & 2
- Fix a smatch warning, "allocate_fake_cpuc() warn: possible memory leak of 'cpuc'" (0-DAY test) (Patch 16)
Changes since V3:
- Check whether the supported_cpus is empty in allocate_fake_cpuc(). A user may offline all the CPUs of a certain type. Perf should not create an event for that PMU. (Patch 16)
- Don't clear a cpuc->pmu when the cpu is offlined in intel_pmu_cpu_dead(). We never unregister a PMU, even all the CPUs of a certain type are offlined. A cpuc->pmu should be always valid and unchanged. There is no harm to keep the pointer of the PMU. Also, some functions, e.g., release_lbr_buffers(), require a valid cpuc->pmu for each possible CPU. (Patch 16)
- ADL may have an alternative configuration. With that configuration X86_FEATURE_HYBRID_CPU is not set. Perf cannot retrieve the core type from the CPUID leaf 0x1a either.
Use the number of hybrid PMUs, which implies a hybrid system, to replace the check of the X86_FEATURE_HYBRID_CPU. (Patch 4)
Introduce a platform specific get_hybrid_cpu_type to retrieve the core type if the generic one doesn't return a valid core type. (Patch 16 & 20)
Changes since V2:
- Don't show "hybrid_cpu" in /proc/cpuinfo (Boris) (Patch 1)
- Use get_this_hybrid_cpu_type() to replace get_hybrid_cpu_type() to avoid the trouble of IPIs. The new function retrieves the type of the current hybrid CPU. It's good enough for perf. (Dave) (Patch 2)
- Remove definitions for Atom and Core CPU types. Perf will define a enum for the hybrid CPU type in the perf_event.h (Peter) (Patch 2 & 16)
- Remove X86_HYBRID_CPU_NATIVE_MODEL_ID_MASK. Not used in the patch set (Kan)(Patch 2)
- Update the description of the patch 2 accordingly. (Boris) (Patch 2)
- All the hybrid PMUs are registered at boot time. (Peter) (Patch 16)
- Align all ATTR things. (Peter) (Patch 20)
- The patchset doesn't change the caps/pmu_name. The perf tool doesn't rely on it to distinguish the event list. The caps/pmu_name is only to indicate the microarchitecture, which is the hybrid Alder Lake for both PMUs.
Changes since V1:
- Drop all user space patches, which will be reviewed later separately.
- Don't save the CPU type in struct cpuinfo_x86. Instead, provide helper functions to get parameters of hybrid CPUs. (Boris)
- Rework the perf kernel patches according to Peter's suggestion. The key changes include,
- Code style changes. Drop all the macro which names in capital letters.
- Drop the hybrid PMU index, track the pointer of the hybrid PMU in the per-CPU struct cpu_hw_events.
- Fix the x86_get_pmu() support
- Fix the allocate_fake_cpuc() support
- Fix validate_group() support
- Dynamically allocate the *hybrid_pmu for each hybrid PMU
Alder Lake uses a hybrid architecture utilizing Golden Cove cores and Gracemont cores. On such architectures, all CPUs support the same, homogeneous and symmetric, instruction set. Also, CPUID enumerate the same features for all CPUs. There may be model-specific differences, such as those addressed in this patchset.
The first two patches enumerate the hybrid CPU feature bit and provide a helper function to get the CPU type of hybrid CPUs. (The initial idea
[1] was to save the CPU type in a new field x86_cpu_type in struct cpuinfo_x86. Since the only user of the new field is perf, querying the X86_FEATURE_HYBRID_CPU at the call site is a simpler alternative.[2]) Compared with the initial submission, the below two concerns[3][4] are also addressed,
- Provide a good use case, PMU.
- Clarify what Intel Hybrid Technology is and is not.
The PMU capabilities for Golden Cove core and Gracemont core are not the same. The key differences include the number of counters, events, perf metrics feature, and PEBS-via-PT feature. A dedicated hybrid PMU has to be registered for each of them. However, the current perf X86 assumes that there is only one CPU PMU. To handle the hybrid PMUs, the patchset
- Introduce a new struct x86_hybrid_pmu to save the unique capabilities from different PMUs. It's part of the global x86_pmu. The architecture capabilities, which are available for all PMUs, are still saved in the global x86_pmu. To save the space, the x86_hybrid_pmu is dynamically allocated.
- The hybrid PMU registration has been moved to the cpu_starting(), because only boot CPU is available when invoking the init_hw_perf_events().
- Hybrid PMUs have different events and formats. Add new structures and helpers for events attribute and format attribute which take the PMU type into account.
- Add a PMU aware version PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU to facilitate user space tools
The uncore, MSR and cstate are the same between hybrid CPUs. Don't need to register hybrid PMUs for them.
The generic code kernel/events/core.c is not hybrid friendly either, especially for the per-task monitoring. Peter once proposed a patchset[5], but it hasn't been merged. This patchset doesn't intend to improve the generic code (which can be improved later separately). It still uses the capability PERF_PMU_CAP_HETEROGENEOUS_CPUS for each hybrid PMUs. For per-task and system-wide monitoring, user space tools have to create events on all available hybrid PMUs. The events which are from different hybrid PMUs cannot be included in the same group.
[1]. https://lore.kernel.org/lkml/[email protected]/
[2]. https://lore.kernel.org/lkml/[email protected]/
[3]. https://lore.kernel.org/lkml/[email protected]/
[4]. https://lore.kernel.org/lkml/[email protected]/
[5]. https://lkml.kernel.org/r/[email protected]/
The kernel codes can also be found at
https://github.com/kliang2/perf.git adl_enabling
Kan Liang (22):
perf/x86: Track pmu in per-CPU cpu_hw_events perf/x86/intel: Hybrid PMU support for perf capabilities perf/x86: Hybrid PMU support for intel_ctrl
perf/x86: Hybrid PMU support for counters
perf/x86: Hybrid PMU support for unconstrained perf/x86: Hybrid PMU support for hardware cache event perf/x86: Hybrid PMU support for event constraints perf/x86: Hybrid PMU support for extra_regs perf/x86/intel: Factor out intel_pmu_check_num_counters perf/x86/intel: Factor out intel_pmu_check_event_constraints perf/x86/intel: Factor out intel_pmu_check_extra_regs perf/x86: Remove temporary pmu assignment in event_init perf/x86: Factor out x86_pmu_show_pmu_cap
perf/x86: Register hybrid PMUs
perf/x86: Add structures for the attributes of Hybrid PMUs perf/x86/intel: Add attr_update for Hybrid PMUs perf/x86: Support filter_match callback perf/x86/intel: Add Alder Lake Hybrid support
perf: Introduce PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU perf/x86/intel/uncore: Add Alder Lake support perf/x86/msr: Add Alder Lake CPU support perf/x86/cstate: Add Alder Lake CPU support
Ricardo Neri (2):
x86/cpufeatures: Enumerate Intel Hybrid Technology feature bit x86/cpu: Add helper function to get the type of the current hybrid CPU
Zhang Rui (1):
perf/x86/rapl: Add support for Intel Alder Lake
arch/x86/events/core.c | 342 ++++++++++++++---- arch/x86/events/intel/core.c | 696 ++++++++++++++++++++++++++++++++----- arch/x86/events/intel/cstate.c | 39 ++- arch/x86/events/intel/ds.c | 32 +- arch/x86/events/intel/lbr.c | 9 +- arch/x86/events/intel/uncore.c | 7 + arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_snb.c | 131 +++++++ arch/x86/events/msr.c | 2 + arch/x86/events/perf_event.h | 108 +++++- arch/x86/events/rapl.c | 2 + arch/x86/include/asm/cpu.h | 6 + arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 3 + arch/x86/kernel/cpu/intel.c | 16 + include/linux/perf_event.h | 12 + include/uapi/linux/perf_event.h | 26 ++ kernel/events/core.c | 14 +- 18 files changed, 1252 insertions(+), 195 deletions(-)
Signature · 1 line
2.7.4
PATCH v5 1/25 x86/cpufeatures: Enumerate Intel Hybrid Technology feature bit
From: Ricardo Neri <[email protected]>
Add feature enumeration to identify a processor with Intel Hybrid
Technology: one in which CPUs of more than one type are the same package. On a hybrid processor, all CPUs support the same homogeneous (i.e., symmetric) instruction set. All CPUs enumerate the same features in CPUID. Thus, software (user space and kernel) can run and migrate to any CPU in the system as well as utilize any of the enumerated features without any change or special provisions. The main difference among CPUs in a hybrid processor are power and performance properties.
---
Changes since v4 (as part of patchset for perf change for Alderlake)
* Add Acked-by
Changes since v3 (as part of patchset for perf change for Alderlake)
* None
Changes since V2 (as part of patchset for perf change for Alderlake)
* Don't show "hybrid_cpu" in /proc/cpuinfo (Boris)
Changes since v1 (as part of patchset for perf change for Alderlake)
* None
Changes since v1 (in a separate posting):
* Reworded commit message to clearly state what is Intel Hybrid Technology. Stress that all CPUs can run the same instruction set and support the same features.
--- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -374,6 +374,7 @@#define X86_FEATURE_MD_CLEAR (18*32+10)/* VERW clears CPU buffers */ #define X86_FEATURE_TSX_FORCE_ABORT (18*32+13)/* "" TSX_FORCE_ABORT */ #define X86_FEATURE_SERIALIZE (18*32+14)/* SERIALIZE instruction */ +#define X86_FEATURE_HYBRID_CPU (18*32+15)/* "" This part has CPUs of more than one type */ #define X86_FEATURE_TSXLDTRK (18*32+16)/* TSX Suspend Load Address Tracking */ #define X86_FEATURE_PCONFIG (18*32+18)/* Intel PCONFIG */ #define X86_FEATURE_ARCH_LBR (18*32+19)/* Intel ARCH LBR */
Signature · 1 line
2.7.4
PATCH v5 2/25 x86/cpu: Add helper function to get the type of the current hybrid CPU
In reply to [email protected]From: Ricardo Neri <[email protected]>
On processors with Intel Hybrid Technology (i.e., one having more than one type of CPU in the same package), all CPUs support the same instruction set and enumerate the same features on CPUID. Thus, all software can run on any CPU without restrictions. However, there may be model-specific differences among types of CPUs. For instance, each type of CPU may support a different number of performance counters. Also, machine check error banks may be wired differently. Even though most software will not care about these differences, kernel subsystems dealing with these differences must know.
Add and expose a new helper function get_this_hybrid_cpu_type() to query the type of the current hybrid CPU. The function will be used later in the perf subsystem.
The Intel Software Developer's Manual defines the CPU type as 8-bit identifier.
---
Changes since v4 (as part of patchset for perf change for Alderlake)
* Put the X86_HYBRID_CPU_TYPE_ID_SHIFT over the function where it is used (Boris)
* Add Acked-by
Changes since v3 (as part of patchset for perf change for Alderlake)
* None
Changes since v2 (as part of patchset for perf change for Alderlake)
* Use get_this_hybrid_cpu_type() to replace get_hybrid_cpu_type() to avoid the trouble of IPIs. The new function retrieves the type of the current hybrid CPU. It's good enough for perf. (Dave)
* Remove definitions for Atom and Core CPU types. Perf will define a enum for the hybrid CPU type in the perf_event.h (Peter)
* Remove X86_HYBRID_CPU_NATIVE_MODEL_ID_MASK. Not used in the patch set. (Kan)
* Update the description accordingly. (Boris)
Changes since v1 (as part of patchset for perf change for Alderlake)
* Removed cpuinfo_x86.x86_cpu_type. It can be added later if needed. Instead, implement helper functions that subsystems can use.(Boris)
* Add definitions for Atom and Core CPU types. (Kan)
Changes since v1 (in a separate posting)
* Simplify code by using cpuid_eax(). (Boris)
* Reworded the commit message to clarify the concept of Intel Hybrid Technology. Stress that all CPUs can run the same instruction set and support the same features.
--- arch/x86/include/asm/cpu.h | 6 ++++++ arch/x86/kernel/cpu/intel.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+)
arch/x86/include/asm/cpu.h +6 -0
@@ -45,6 +45,7 @@ extern void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c);extern void switch_to_sld (unsigned long tifn);extern bool handle_user_split_lock (struct pt_regs *regs,long error_code);extern bool handle_guest_split_lock (unsigned long ip); +u8 get_this_hybrid_cpu_type (void );#else static inline void __init cpu_set_core_cap_bits (struct cpuinfo_x86 *c) {}static inline void switch_to_sld (unsigned long tifn) {}
@@ -57,6 +58,11 @@ static inline bool handle_guest_split_lock(unsigned long ip) {return false; } + +static inline u8 get_this_hybrid_cpu_type (void ) +{ +return 0 ; +}#endif #ifdef CONFIG_IA32_FEAT_CTL void init_ia32_feat_ctl (struct cpuinfo_x86 *c);
arch/x86/kernel/cpu/intel.c +16 -0
@@ -1195,3 +1195,19 @@ void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c) cpu_model_supports_sld = true;split_lock_setup (); } + +#define X86_HYBRID_CPU_TYPE_ID_SHIFT 24 + +/** +* get_this_hybrid_cpu_type() - Get the type of this hybrid CPU +* +* Returns the CPU type [31:24] (i.e., Atom or Core) of a CPU in +* a hybrid processor. If the processor is not hybrid, returns 0. +*/ +u8 get_this_hybrid_cpu_type (void ) +{ +if (!cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) +return 0 ; + +return cpuid_eax (0x0000001a ) >>X86_HYBRID_CPU_TYPE_ID_SHIFT ; +}
Signature · 1 line
2.7.4
PATCH v5 3/25 perf/x86: Track pmu in per-CPU cpu_hw_events
In reply to [email protected]From: Kan Liang <[email protected]>
Some platforms, e.g. Alder Lake, have hybrid architecture. In the same package, there may be more than one type of CPU. The PMU capabilities are different among different types of CPU. Perf will register a dedicated PMU for each type of CPU.
Add a 'pmu' variable in the struct cpu_hw_events to track the dedicated PMU of the current CPU.
Current x86_get_pmu() use the global 'pmu', which will be broken on a hybrid platform. Modify it to apply the 'pmu' of the specific CPU.
Initialize the per-CPU 'pmu' variable with the global 'pmu'. There is nothing changed for the non-hybrid platforms.
The is_x86_event() will be updated in the later patch ("perf/x86:
Register hybrid PMUs") for hybrid platforms. For the non-hybrid platforms, nothing is changed here.
--- arch/x86/events/core.c | 17 +++++++++++++---- arch/x86/events/intel/core.c | 2 +- arch/x86/events/intel/ds.c | 4 ++-- arch/x86/events/intel/lbr.c | 9 +++++---- arch/x86/events/perf_event.h | 4 +++- 5 files changed, 24 insertions(+), 12 deletions(-)
arch/x86/events/core.c +13 -4
@@ -45,9 +45,11 @@#include "perf_event.h" struct x86_pmu x86_pmu__read_mostly ; +static struct pmu pmu; DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled =1 , + .pmu = &pmu, };DEFINE_STATIC_KEY_FALSE (rdpmc_never_available_key);
@@ -724,16 +726,23 @@ void x86_pmu_enable_all(int added) } } -static struct pmu pmu; -static inline int is_x86_event (struct perf_event *event) {return event->pmu == &pmu; } -struct pmu *x86_get_pmu (void ) +struct pmu *x86_get_pmu (unsigned int cpu) { -return &pmu; +struct cpu_hw_events *cpuc = &per_cpu (cpu_hw_events, cpu); + +/* +* All CPUs of the hybrid type have been offline. +* The x86_get_pmu() should not be invoked. +*/ +if (WARN_ON_ONCE (!cpuc->pmu)) +return &pmu; + +return cpuc->pmu; }/* * Event scheduler state:
arch/x86/events/intel/core.c +1 -1
@@ -4876,7 +4876,7 @@ static void update_tfa_sched(void *ignored)* and if so force schedule out for all event types all contexts */ if (test_bit (3 , cpuc->active_mask)) -perf_pmu_resched (x86_get_pmu ()); +perf_pmu_resched (x86_get_pmu (smp_processor_id ())); } static ssize_t show_sysctl_tfa(struct device *cdev,
arch/x86/events/intel/ds.c +2 -2
@@ -2192,7 +2192,7 @@ void __init intel_ds_init(void)PERF_SAMPLE_TIME ; x86_pmu.flags |=PMU_FL_PEBS_ALL ; pebs_qual ="-baseline" ; -x86_get_pmu ()->capabilities |=PERF_PMU_CAP_EXTENDED_REGS ; +x86_get_pmu (smp_processor_id ())->capabilities |=PERF_PMU_CAP_EXTENDED_REGS ; }else {/* Only basic record supported */ x86_pmu.large_pebs_flags &=
@@ -2207,7 +2207,7 @@ void __init intel_ds_init(void)if (x86_pmu.intel_cap.pebs_output_pt_available) {pr_cont ("PEBS-via-PT, " ); -x86_get_pmu ()->capabilities |=PERF_PMU_CAP_AUX_OUTPUT ; +x86_get_pmu (smp_processor_id ())->capabilities |=PERF_PMU_CAP_AUX_OUTPUT ; }break ;
arch/x86/events/intel/lbr.c +5 -4
@@ -705,7 +705,7 @@ void intel_pmu_lbr_add(struct perf_event *event)void release_lbr_buffers (void ) { -struct kmem_cache *kmem_cache =x86_get_pmu ()->task_ctx_cache; +struct kmem_cache *kmem_cache;struct cpu_hw_events *cpuc;int cpu;
@@ -714,6 +714,7 @@ void release_lbr_buffers(void)for_each_possible_cpu (cpu) { cpuc =per_cpu_ptr (&cpu_hw_events, cpu); + kmem_cache =x86_get_pmu (cpu)->task_ctx_cache;if (kmem_cache && cpuc->lbr_xsave) {kmem_cache_free (kmem_cache, cpuc->lbr_xsave); cpuc->lbr_xsave =NULL ;
@@ -1609,7 +1610,7 @@ void intel_pmu_lbr_init_hsw(void) x86_pmu.lbr_sel_mask =LBR_SEL_MASK ; x86_pmu.lbr_sel_map = hsw_lbr_sel_map; -x86_get_pmu ()->task_ctx_cache =create_lbr_kmem_cache (size,0 ); +x86_get_pmu (smp_processor_id ())->task_ctx_cache =create_lbr_kmem_cache (size,0 );if (lbr_from_signext_quirk_needed ())static_branch_enable (&lbr_from_quirk_key);
@@ -1629,7 +1630,7 @@ __init void intel_pmu_lbr_init_skl(void) x86_pmu.lbr_sel_mask =LBR_SEL_MASK ; x86_pmu.lbr_sel_map = hsw_lbr_sel_map; -x86_get_pmu ()->task_ctx_cache =create_lbr_kmem_cache (size,0 ); +x86_get_pmu (smp_processor_id ())->task_ctx_cache =create_lbr_kmem_cache (size,0 );/* * SW branch filter usage:
@@ -1726,7 +1727,7 @@ static bool is_arch_lbr_xsave_available(void)void __init intel_pmu_arch_lbr_init (void ) { -struct pmu *pmu =x86_get_pmu (); +struct pmu *pmu =x86_get_pmu (smp_processor_id ());union cpuid28_eax eax;union cpuid28_ebx ebx;union cpuid28_ecx ecx;
arch/x86/events/perf_event.h +3 -1
@@ -327,6 +327,8 @@ struct cpu_hw_events {int n_pair;/* Large increment events */ void *kfree_on_online[X86_PERF_KFREE_MAX ]; + +struct pmu *pmu; };#define __EVENT_CONSTRAINT_RANGE (c, e, n, m, w, o, f) { \
@@ -905,7 +907,7 @@ static struct perf_pmu_events_ht_attr event_attr_##v = { \ .event_str_ht = ht, \ } -struct pmu *x86_get_pmu (void ); +struct pmu *x86_get_pmu (unsigned int cpu);extern struct x86_pmu x86_pmu__read_mostly ; static __always_inline struct x86_perf_task_context_opt *task_context_opt(void *ctx)
Signature · 1 line
2.7.4
PATCH v5 4/25 perf/x86/intel: Hybrid PMU support for perf capabilities
In reply to [email protected]From: Kan Liang <[email protected]>
Some platforms, e.g. Alder Lake, have hybrid architecture. Although most PMU capabilities are the same, there are still some unique PMU capabilities for different hybrid PMUs. Perf should register a dedicated pmu for each hybrid PMU.
Add a new struct x86_hybrid_pmu, which saves the dedicated pmu and capabilities for each hybrid PMU.
The architecture MSR, MSR_IA32_PERF_CAPABILITIES, only indicates the architecture features which are available on all hybrid PMUs. The architecture features are stored in the global x86_pmu.intel_cap.
For Alder Lake, the model-specific features are perf metrics and PEBS-via-PT. The corresponding bits of the global x86_pmu.intel_cap should be 0 for these two features. Perf should not use the global intel_cap to check the features on a hybrid system.
Add a dedicated intel_cap in the x86_hybrid_pmu to store the model-specific capabilities. Use the dedicated intel_cap to replace the global intel_cap for thse two features. The dedicated intel_cap will be set in the following "Add Alder Lake Hybrid support" patch.
Add is_hybrid() to distinguish a hybrid system. ADL may have an alternative configuration. With that configuration, the X86_FEATURE_HYBRID_CPU is not set. Perf cannot rely on the feature bit. The number of hybrid PMUs implies whether it's a hybrid system. The number will be assigned in the following "Add Alder Lake Hybrid support" patch as well.
--- arch/x86/events/core.c | 6 ++++-- arch/x86/events/intel/core.c | 27 ++++++++++++++++++++++----- arch/x86/events/intel/ds.c | 2 +- arch/x86/events/perf_event.h | 34 ++++++++++++++++++++++++++++++++++ arch/x86/include/asm/msr-index.h | 3 +++ 5 files changed, 64 insertions(+), 8 deletions(-)
arch/x86/events/core.c +4 -2
@@ -1105,8 +1105,9 @@ static void del_nr_metric_event(struct cpu_hw_events *cpuc,static int collect_event (struct cpu_hw_events *cpuc,struct perf_event *event,int max_count,int n) { +union perf_capabilities intel_cap =hybrid (cpuc->pmu, intel_cap); -if (x86_pmu.intel_cap.perf_metrics &&add_nr_metric_event (cpuc, event)) +if (intel_cap.perf_metrics &&add_nr_metric_event (cpuc, event))return -EINVAL ;if (n >= max_count + cpuc->n_metric)
@@ -1582,6 +1583,7 @@ void x86_pmu_stop(struct perf_event *event, int flags)static void x86_pmu_del (struct perf_event *event,int flags) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +union perf_capabilities intel_cap =hybrid (cpuc->pmu, intel_cap);int i;/*
@@ -1621,7 +1623,7 @@ static void x86_pmu_del(struct perf_event *event, int flags) } cpuc->event_constraint[i-1 ] =NULL ; --cpuc->n_events; -if (x86_pmu.intel_cap.perf_metrics) +if (intel_cap.perf_metrics)del_nr_metric_event (cpuc, event);perf_event_update_userpage (event);
arch/x86/events/intel/core.c +22 -5
@@ -3646,6 +3646,15 @@ static inline bool is_mem_loads_aux_event(struct perf_event *event) return (event->attr.config & INTEL_ARCH_EVENT_MASK) == X86_CONFIG(.event=0x03, .umask=0x82); } +static inline bool intel_pmu_has_cap (struct perf_event *event,int idx) +{ +union perf_capabilities *intel_cap; + + intel_cap =is_hybrid () ? &hybrid_pmu (event->pmu)->intel_cap : + &x86_pmu.intel_cap; + +return test_bit (idx, (unsigned long *)&intel_cap->capabilities); +}static int intel_pmu_hw_config (struct perf_event *event) {
@@ -3712,7 +3721,7 @@ static int intel_pmu_hw_config(struct perf_event *event)* with a slots event as group leader. When the slots event * is used in a metrics group, it too cannot support sampling. */ -if (x86_pmu.intel_cap.perf_metrics &&is_topdown_event (event)) { +if (intel_pmu_has_cap (event,PERF_CAP_METRICS_IDX ) &&is_topdown_event (event)) {if (event->attr.config1 || event->attr.config2)return -EINVAL ;
@@ -4219,8 +4228,16 @@ static void intel_pmu_cpu_starting(int cpu)if (x86_pmu.version >1 )flip_smm_bit (&x86_pmu.attr_freeze_on_smi); -/* Disable perf metrics if any added CPU doesn't support it. */ -if (x86_pmu.intel_cap.perf_metrics) { +/* +* Disable perf metrics if any added CPU doesn't support it. +* +* Turn off the check for a hybrid architecture, because the +* architecture MSR, MSR_IA32_PERF_CAPABILITIES, only indicate +* the architecture features. The perf metrics is a model-specific +* feature for now. The corresponding bit should always be 0 on +* a hybrid platform, e.g., Alder Lake. +*/ +if (!is_hybrid () && x86_pmu.intel_cap.perf_metrics) {union perf_capabilities perf_cap;rdmsrl (MSR_IA32_PERF_CAPABILITIES , perf_cap.capabilities);
@@ -4330,7 +4347,7 @@ static int intel_pmu_check_period(struct perf_event *event, u64 value)static int intel_pmu_aux_output_match (struct perf_event *event) { -if (!x86_pmu.intel_cap.pebs_output_pt_available) +if (!intel_pmu_has_cap (event,PERF_CAP_PT_IDX ))return 0 ;return is_intel_pt_event (event);
@@ -5770,7 +5787,7 @@ __init int intel_pmu_init(void)pr_cont ("full-width counters, " ); } -if (x86_pmu.intel_cap.perf_metrics) +if (!is_hybrid () && x86_pmu.intel_cap.perf_metrics) x86_pmu.intel_ctrl |=1ULL <<GLOBAL_CTRL_EN_PERF_METRICS ;return 0 ;
arch/x86/events/intel/ds.c +1 -1
@@ -2205,7 +2205,7 @@ void __init intel_ds_init(void) }pr_cont ("PEBS fmt4%c%s, " , pebs_type, pebs_qual); -if (x86_pmu.intel_cap.pebs_output_pt_available) { +if (!is_hybrid () && x86_pmu.intel_cap.pebs_output_pt_available) {pr_cont ("PEBS-via-PT, " );x86_get_pmu (smp_processor_id ())->capabilities |=PERF_PMU_CAP_AUX_OUTPUT ; }
arch/x86/events/perf_event.h +34 -0
@@ -632,6 +632,29 @@ enum { x86_lbr_exclusive_max, }; +struct x86_hybrid_pmu { +struct pmu pmu; +union perf_capabilities intel_cap; +}; + +static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu) +{ + return container_of(pmu, struct x86_hybrid_pmu, pmu); +} + +/* The number of hybrid PMUs implies whether it's a hybrid system */ +#define is_hybrid () (!!x86_pmu.num_hybrid_pmus) + +#define hybrid (_pmu, _field) \ +({ \ + typeof(x86_pmu._field) __F = x86_pmu._field; \ + \ + if (is_hybrid() && (_pmu)) \ + __F = hybrid_pmu(_pmu)->_field; \ + \ + __F; \ +}) +/* * struct x86_pmu - generic x86 pmu */
@@ -818,6 +841,17 @@ struct x86_pmu {int (*check_period) (struct perf_event *event,u64 period);int (*aux_output_match) (struct perf_event *event); + +/* +* Hybrid support +* +* Most PMU capabilities are the same among different hybrid PMUs. +* The global x86_pmu saves the architecture capabilities, which +* are available for all PMUs. The hybrid_pmu only includes the +* unique capabilities. +*/ +int num_hybrid_pmus; +struct x86_hybrid_pmu *hybrid_pmu; };struct x86_perf_task_context_opt {
arch/x86/include/asm/msr-index.h +3 -0
@@ -185,6 +185,9 @@#define MSR_PEBS_DATA_CFG 0x000003f2#define MSR_IA32_DS_AREA 0x00000600#define MSR_IA32_PERF_CAPABILITIES 0x00000345 +#define PERF_CAP_METRICS_IDX 15 +#define PERF_CAP_PT_IDX 16 +#define MSR_PEBS_LD_LAT_THRESHOLD 0x000003f6#define MSR_IA32_RTIT_CTL 0x00000570
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerRe: [PATCH V5 04/25] perf/x86/intel: Hybrid PMU support for perf capabilities
arch/x86/events/intel/core.c static inline bool is_mem_loads_aux_event(struct perf_event *event) · line 3654
Quoted 6 lines · On Mon, Apr 05, 2021 at 08:10:46AM -0700, [email protected] wrote:
arch/x86/events/intel/core.c +6
-0+static inline bool intel_pmu_has_cap (struct perf_event *event,int idx) +{ +union perf_capabilities *intel_cap; + + intel_cap =is_hybrid () ? &hybrid_pmu (event->pmu)->intel_cap : + &x86_pmu.intel_cap;
This isn't:
intel_cap = &hybrid_pmu(event->pmu)->intel_cap;
because..
Quoted 16 lines
arch/x86/events/intel/core.c +4
-1+ +return test_bit (idx, (unsigned long *)&intel_cap->capabilities); +}@@ -3712,7 +3721,7 @@ static int intel_pmu_hw_config(struct perf_event *event)* with a slots event as group leader. When the slots event * is used in a metrics group, it too cannot support sampling. */ -if (x86_pmu.intel_cap.perf_metrics &&is_topdown_event (event)) { +if (intel_pmu_has_cap (event,PERF_CAP_METRICS_IDX ) &&is_topdown_event (event)) {if (event->attr.config1 || event->attr.config2)return -EINVAL ;
arch/x86/events/intel/core.c static int intel_pmu_check_period(struct perf_event *event, u64 value) · line 4353
Quoted 8 lines
arch/x86/events/intel/core.c +1
-1@@ -4330,7 +4347,7 @@ static int intel_pmu_check_period(struct perf_event *event, u64 value)static int intel_pmu_aux_output_match (struct perf_event *event) { -if (!x86_pmu.intel_cap.pebs_output_pt_available) +if (!intel_pmu_has_cap (event,PERF_CAP_PT_IDX ))return 0 ;return is_intel_pt_event (event);
these sites can have !event->pmu ?
Peter Zijlstra
maintainerRe: [PATCH V5 04/25] perf/x86/intel: Hybrid PMU support for perf capabilities
Quoted 11 lines · Peter Zijlstra
arch/x86/events/intel/core.c static inline bool is_mem_loads_aux_event(struct perf_event *event) · line 3654
Quoted 6 lines · On Mon, Apr 05, 2021 at 08:10:46AM -0700, [email protected] wrote:
arch/x86/events/intel/core.c +6
-0+static inline bool intel_pmu_has_cap (struct perf_event *event,int idx) +{ +union perf_capabilities *intel_cap; + + intel_cap =is_hybrid () ? &hybrid_pmu (event->pmu)->intel_cap : + &x86_pmu.intel_cap;This isn't:
intel_cap = &hybrid_pmu(event->pmu)->intel_cap;
Ah no, its because you want a pointer and GCC is being silly about that.
I have something for that, hold on ;-)
Re: [PATCH V5 04/25] perf/x86/intel: Hybrid PMU support for perf capabilities
In reply to Peter ZijlstraQuoted 10 lines · Peter Zijlstra
arch/x86/events/intel/core.c static int intel_pmu_check_period(struct perf_event *event, u64 value) · line 4353
Quoted 9 lines
arch/x86/events/intel/core.c +1
-1@@ -4330,7 +4347,7 @@ static int intel_pmu_check_period(struct perf_event *event, u64 value)static int intel_pmu_aux_output_match (struct perf_event *event) { -if (!x86_pmu.intel_cap.pebs_output_pt_available) +if (!intel_pmu_has_cap (event,PERF_CAP_PT_IDX ))return 0 ;return is_intel_pt_event (event);these sites can have !event->pmu ?
I don't think the event->pmu can be NULL, but it could be pt_pmu.pmu. If so, it should be a problem.
I think I will still use the x86_pmu.intel_cap.pebs_output_pt_available here in V6. The worst case is that we lost the PEBS via PT support on the small core for now.
I guess Alexander may provide a separate patch later to enable the PEBS via PT support on the ADL small core.
Thanks,
Kan
Peter Zijlstra
maintainerRe: [PATCH V5 04/25] perf/x86/intel: Hybrid PMU support for perf capabilities
In reply to [email protected]Quoted 1 line · On Mon, Apr 05, 2021 at 08:10:46AM -0700, [email protected] wrote:
+#define
is_hybrid()(!!x86_pmu.num_hybrid_pmus)
Given this is sprinkled all over the place, can you make this a static_key_false + static_branch_unlikely() such that the hybrid case is out-of-line?
Re: [PATCH V5 04/25] perf/x86/intel: Hybrid PMU support for perf capabilities
Quoted 7 lines · Peter Zijlstra
Quoted 1 line · On Mon, Apr 05, 2021 at 08:10:46AM -0700, [email protected] wrote:
+#define
is_hybrid()(!!x86_pmu.num_hybrid_pmus)Given this is sprinkled all over the place, can you make this a
static_key_false+static_branch_unlikely()such that the hybrid case is out-of-line?
Sure, I will add a new static_key_false "perf_is_hybrid" to indicate a hybrid system as below (not test yet).
arch/x86/events/core.c +1 -0
@@ -54,6 +54,7 @@ DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {DEFINE_STATIC_KEY_FALSE (rdpmc_never_available_key);DEFINE_STATIC_KEY_FALSE (rdpmc_always_available_key); +DEFINE_STATIC_KEY_FALSE (perf_is_hybrid);/* * This here uses DEFINE_STATIC_CALL_NULL() to get a static_call defined
arch/x86/events/intel/core.c +1 -0
@@ -6119,6 +6119,7 @@ __init int intel_pmu_init(void) GFP_KERNEL);if (!x86_pmu.hybrid_pmu)return -ENOMEM ; +static_branch_enable (&perf_is_hybrid); x86_pmu.num_hybrid_pmus =X86_HYBRID_NUM_PMUS ; x86_pmu.late_ack = true;
arch/x86/events/perf_event.h +2 -2
@@ -663,8 +663,8 @@ static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu) return container_of(pmu, struct x86_hybrid_pmu, pmu); } -/* The number of hybrid PMUs implies whether it's a hybrid system */ -#define is_hybrid () (!!x86_pmu.num_hybrid_pmus) +extern struct static_key_false perf_is_hybrid; +#define is_hybrid () static_branch_unlikely(&perf_is_hybrid)#define hybrid (_pmu, _field) \ ({ \
Thanks,
Kan
PATCH v5 5/25 perf/x86: Hybrid PMU support for intel_ctrl
In reply to [email protected]From: Kan Liang <[email protected]>
The intel_ctrl is the counter mask of a PMU. The PMU counter information may be different among hybrid PMUs, each hybrid PMU should use its own intel_ctrl to check and access the counters.
When handling a certain hybrid PMU, apply the intel_ctrl from the corresponding hybrid PMU.
When checking the HW existence, apply the PMU and number of counters from the corresponding hybrid PMU as well. Perf will check the HW existence for each Hybrid PMU before registration. Expose the check_hw_exists() for a later patch.
--- arch/x86/events/core.c | 14 +++++++------- arch/x86/events/intel/core.c | 14 +++++++++----- arch/x86/events/perf_event.h | 10 ++++++++-- 3 files changed, 24 insertions(+), 14 deletions(-)
arch/x86/events/core.c +7 -7
@@ -230,7 +230,7 @@ static void release_pmc_hardware(void) {}#endif -static bool check_hw_exists (void ) +bool check_hw_exists (struct pmu *pmu,int num_counters,int num_counters_fixed) {u64 val, val_fail =-1 , val_new= ~0 ;int i, reg, reg_fail =-1 , ret =0 ;
@@ -241,7 +241,7 @@ static bool check_hw_exists(void)* Check to see if the BIOS enabled any of the counters, if so * complain and bail. */ -for (i =0 ; i < x86_pmu.num_counters; i++) { +for (i =0 ; i < num_counters; i++) { reg =x86_pmu_config_addr (i); ret =rdmsrl_safe (reg, &val);if (ret)
@@ -255,13 +255,13 @@ static bool check_hw_exists(void) } } -if (x86_pmu.num_counters_fixed) { +if (num_counters_fixed) { reg =MSR_ARCH_PERFMON_FIXED_CTR_CTRL ; ret =rdmsrl_safe (reg, &val);if (ret) goto msr_fail; -for (i =0 ; i < x86_pmu.num_counters_fixed; i++) { -if (fixed_counter_disabled (i)) +for (i =0 ; i < num_counters_fixed; i++) { +if (fixed_counter_disabled (i, pmu))continue ;if (val & (0x03 << i*4 )) { bios_fail =1 ;
@@ -1547,7 +1547,7 @@ void perf_event_print_debug(void) cpu, idx, prev_left); }for (idx =0 ; idx < x86_pmu.num_counters_fixed; idx++) { -if (fixed_counter_disabled (idx)) +if (fixed_counter_disabled (idx, cpuc->pmu))continue ;rdmsrl (MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count);
@@ -1992,7 +1992,7 @@ static int __init init_hw_perf_events(void)pmu_check_apic ();/* sanity check that the hardware exists or is emulated */ -if (!check_hw_exists ()) +if (!check_hw_exists (&pmu, x86_pmu.num_counters, x86_pmu.num_counters_fixed))return 0 ;pr_cont ("%s PMU driver.\n" , x86_pmu.name);
arch/x86/events/intel/core.c +9 -5
@@ -2153,10 +2153,11 @@ static void intel_pmu_disable_all(void)static void __intel_pmu_enable_all (int added,bool pmi) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +u64 intel_ctrl =hybrid (cpuc->pmu, intel_ctrl);intel_pmu_lbr_enable_all (pmi);wrmsrl (MSR_CORE_PERF_GLOBAL_CTRL , - x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask); + intel_ctrl & ~cpuc->intel_ctrl_guest_mask);if (test_bit (INTEL_PMC_IDX_FIXED_BTS , cpuc->active_mask)) { struct perf_event *event =
@@ -2709,6 +2710,7 @@ int intel_pmu_save_and_restart(struct perf_event *event)static void intel_pmu_reset (void ) {struct debug_store *ds =__this_cpu_read (cpu_hw_events.ds); +struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);unsigned long flags;int idx;
@@ -2724,7 +2726,7 @@ static void intel_pmu_reset(void)wrmsrl_safe (x86_pmu_event_addr (idx),0ull ); }for (idx =0 ; idx < x86_pmu.num_counters_fixed; idx++) { -if (fixed_counter_disabled (idx)) +if (fixed_counter_disabled (idx, cpuc->pmu))continue ;wrmsrl_safe (MSR_ARCH_PERFMON_FIXED_CTR0 + idx,0ull ); }
@@ -2753,6 +2755,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);int bit;int handled =0 ; +u64 intel_ctrl =hybrid (cpuc->pmu, intel_ctrl);inc_irq_stat (apic_perf_irqs);
@@ -2798,7 +2801,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) handled++; x86_pmu.drain_pebs (regs, &data); - status &= x86_pmu.intel_ctrl |GLOBAL_STATUS_TRACE_TOPAPMI ; + status &= intel_ctrl |GLOBAL_STATUS_TRACE_TOPAPMI ;/* * PMI throttle may be triggered, which stops the PEBS event.
@@ -3807,10 +3810,11 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; +u64 intel_ctrl =hybrid (cpuc->pmu, intel_ctrl); arr[0 ].msr =MSR_CORE_PERF_GLOBAL_CTRL ; - arr[0 ].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; - arr[0 ].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; + arr[0 ].host = intel_ctrl & ~cpuc->intel_ctrl_guest_mask; + arr[0 ].guest = intel_ctrl & ~cpuc->intel_ctrl_host_mask;if (x86_pmu.flags &PMU_FL_PEBS_ALL ) arr[0 ].guest &= ~cpuc->pebs_enabled;else
arch/x86/events/perf_event.h +8 -2
@@ -635,6 +635,7 @@ enum {struct x86_hybrid_pmu {struct pmu pmu;union perf_capabilities intel_cap; +u64 intel_ctrl; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
@@ -1000,6 +1001,9 @@ static inline int x86_pmu_rdpmc_index(int index)return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index (index) : index; } +bool check_hw_exists (struct pmu *pmu,int num_counters, +int num_counters_fixed); +int x86_add_exclusive (unsigned int what);void x86_del_exclusive (unsigned int what);
@@ -1104,9 +1108,11 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,ssize_t events_ht_sysfs_show (struct device *dev,struct device_attribute *attr,char *page); -static inline bool fixed_counter_disabled (int i) +static inline bool fixed_counter_disabled (int i,struct pmu *pmu) { -return !(x86_pmu.intel_ctrl >> (i +INTEL_PMC_IDX_FIXED )); +u64 intel_ctrl =hybrid (pmu, intel_ctrl); + +return !(intel_ctrl >> (i +INTEL_PMC_IDX_FIXED )); }#ifdef CONFIG_CPU_SUP_AMD
Signature · 1 line
2.7.4
PATCH v5 6/25 perf/x86: Hybrid PMU support for counters
In reply to [email protected]From: Kan Liang <[email protected]>
The number of GP and fixed counters are different among hybrid PMUs. Each hybrid PMU should use its own counter related information.
When handling a certain hybrid PMU, apply the number of counters from the corresponding hybrid PMU.
When reserving the counters in the initialization of a new event, reserve all possible counters.
The number of counter recored in the global x86_pmu is for the architecture counters which are available for all hybrid PMUs. KVM doesn't support the hybrid PMU yet. Return the number of the architecture counters for now.
For the functions only available for the old platforms, e.g., intel_pmu_drain_pebs_nhm(), nothing is changed.
--- arch/x86/events/core.c | 55 ++++++++++++++++++++++++++++++-------------- arch/x86/events/intel/core.c | 8 ++++--- arch/x86/events/intel/ds.c | 14 +++++++---- arch/x86/events/perf_event.h | 3 +++ 4 files changed, 55 insertions(+), 25 deletions(-)
arch/x86/events/core.c +38 -17
@@ -184,16 +184,29 @@ static DEFINE_MUTEX(pmc_reserve_mutex);#ifdef CONFIG_X86_LOCAL_APIC +static inline int get_possible_num_counters (void ) +{ +int i, num_counters = x86_pmu.num_counters; + +if (!is_hybrid ()) +return num_counters; + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) + num_counters =max_t (int, num_counters, x86_pmu.hybrid_pmu[i].num_counters); + +return num_counters; +} +static bool reserve_pmc_hardware (void ) { -int i; +int i, num_counters =get_possible_num_counters (); -for (i =0 ; i < x86_pmu.num_counters; i++) { +for (i =0 ; i < num_counters; i++) {if (!reserve_perfctr_nmi (x86_pmu_event_addr (i))) goto perfctr_fail; } -for (i =0 ; i < x86_pmu.num_counters; i++) { +for (i =0 ; i < num_counters; i++) {if (!reserve_evntsel_nmi (x86_pmu_config_addr (i))) goto eventsel_fail; }
@@ -204,7 +217,7 @@ static bool reserve_pmc_hardware(void)for (i--; i >=0 ; i--)release_evntsel_nmi (x86_pmu_config_addr (i)); - i = x86_pmu.num_counters; + i = num_counters; perfctr_fail:for (i--; i >=0 ; i--)
@@ -215,9 +228,9 @@ static bool reserve_pmc_hardware(void)static void release_pmc_hardware (void ) { -int i; +int i, num_counters =get_possible_num_counters (); -for (i =0 ; i < x86_pmu.num_counters; i++) { +for (i =0 ; i < num_counters; i++) {release_perfctr_nmi (x86_pmu_event_addr (i));release_evntsel_nmi (x86_pmu_config_addr (i)); }
@@ -945,6 +958,7 @@ EXPORT_SYMBOL_GPL(perf_assign_events);int x86_schedule_events (struct cpu_hw_events *cpuc,int n,int *assign) { +int num_counters =hybrid (cpuc->pmu, num_counters);struct event_constraint *c;struct perf_event *e;int n0, i, wmin, wmax, unsched =0 ;
@@ -1020,7 +1034,7 @@ int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)/* slow path */ if (i != n) { -int gpmax = x86_pmu.num_counters; +int gpmax = num_counters;/* * Do not allow scheduling of more than half the available
@@ -1041,7 +1055,7 @@ int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)* the extra Merge events needed by large increment events. */ if (x86_pmu.flags &PMU_FL_PAIR ) { - gpmax = x86_pmu.num_counters - cpuc->n_pair; + gpmax = num_counters - cpuc->n_pair;WARN_ON (gpmax <=0 ); }
@@ -1128,10 +1142,12 @@ static int collect_event(struct cpu_hw_events *cpuc, struct perf_event *event,*/ static int collect_events (struct cpu_hw_events *cpuc,struct perf_event *leader,bool dogrp) { +int num_counters =hybrid (cpuc->pmu, num_counters); +int num_counters_fixed =hybrid (cpuc->pmu, num_counters_fixed);struct perf_event *event;int n, max_count; - max_count = x86_pmu.num_counters + x86_pmu.num_counters_fixed; + max_count = num_counters + num_counters_fixed;/* current number of events already accepted */ n = cpuc->n_events;
@@ -1499,18 +1515,18 @@ void perf_event_print_debug(void) {u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed;u64 pebs, debugctl; -struct cpu_hw_events *cpuc; +int cpu =smp_processor_id (); +struct cpu_hw_events *cpuc = &per_cpu (cpu_hw_events, cpu); +int num_counters =hybrid (cpuc->pmu, num_counters); +int num_counters_fixed =hybrid (cpuc->pmu, num_counters_fixed);unsigned long flags; -int cpu, idx; +int idx; -if (!x86_pmu.num_counters) +if (!num_counters)return ;local_irq_save (flags); - cpu =smp_processor_id (); - cpuc = &per_cpu (cpu_hw_events, cpu); -if (x86_pmu.version >=2 ) {rdmsrl (MSR_CORE_PERF_GLOBAL_CTRL , ctrl);rdmsrl (MSR_CORE_PERF_GLOBAL_STATUS , status);
@@ -1533,7 +1549,7 @@ void perf_event_print_debug(void) }pr_info ("CPU#%d: active: %016llx\n" , cpu, *(u64 *)cpuc->active_mask); -for (idx =0 ; idx < x86_pmu.num_counters; idx++) { +for (idx =0 ; idx < num_counters; idx++) {rdmsrl (x86_pmu_config_addr (idx), pmc_ctrl);rdmsrl (x86_pmu_event_addr (idx), pmc_count);
@@ -1546,7 +1562,7 @@ void perf_event_print_debug(void)pr_info ("CPU#%d: gen-PMC%d left: %016llx\n" , cpu, idx, prev_left); } -for (idx =0 ; idx < x86_pmu.num_counters_fixed; idx++) { +for (idx =0 ; idx < num_counters_fixed; idx++) {if (fixed_counter_disabled (idx, cpuc->pmu))continue ;rdmsrl (MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count);
@@ -2781,6 +2797,11 @@ unsigned long perf_misc_flags(struct pt_regs *regs)void perf_get_x86_pmu_capability (struct x86_pmu_capability *cap) { cap->version = x86_pmu.version; +/* +* KVM doesn't support the hybrid PMU yet. +* Return the common value in global x86_pmu, +* which available for all cores. +*/ cap->num_counters_gp = x86_pmu.num_counters; cap->num_counters_fixed = x86_pmu.num_counters_fixed; cap->bit_width_gp = x86_pmu.cntval_bits;
arch/x86/events/intel/core.c +5 -3
@@ -2711,21 +2711,23 @@ static void intel_pmu_reset(void) {struct debug_store *ds =__this_cpu_read (cpu_hw_events.ds);struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +int num_counters_fixed =hybrid (cpuc->pmu, num_counters_fixed); +int num_counters =hybrid (cpuc->pmu, num_counters);unsigned long flags;int idx; -if (!x86_pmu.num_counters) +if (!num_counters)return ;local_irq_save (flags);pr_info ("clearing PMU state on CPU#%d\n" ,smp_processor_id ()); -for (idx =0 ; idx < x86_pmu.num_counters; idx++) { +for (idx =0 ; idx < num_counters; idx++) {wrmsrl_safe (x86_pmu_config_addr (idx),0ull );wrmsrl_safe (x86_pmu_event_addr (idx),0ull ); } -for (idx =0 ; idx < x86_pmu.num_counters_fixed; idx++) { +for (idx =0 ; idx < num_counters_fixed; idx++) {if (fixed_counter_disabled (idx, cpuc->pmu))continue ;wrmsrl_safe (MSR_ARCH_PERFMON_FIXED_CTR0 + idx,0ull );
arch/x86/events/intel/ds.c +9 -5
@@ -1007,6 +1007,8 @@ void intel_pmu_pebs_sched_task(struct perf_event_context *ctx, bool sched_in)static inline void pebs_update_threshold (struct cpu_hw_events *cpuc) {struct debug_store *ds = cpuc->ds; +int max_pebs_events =hybrid (cpuc->pmu, max_pebs_events); +int num_counters_fixed =hybrid (cpuc->pmu, num_counters_fixed);u64 threshold;int reserved;
@@ -1014,9 +1016,9 @@ static inline void pebs_update_threshold(struct cpu_hw_events *cpuc)return ;if (x86_pmu.flags &PMU_FL_PEBS_ALL ) - reserved = x86_pmu.max_pebs_events + x86_pmu.num_counters_fixed; + reserved = max_pebs_events + num_counters_fixed;else - reserved = x86_pmu.max_pebs_events; + reserved = max_pebs_events;if (cpuc->n_pebs == cpuc->n_large_pebs) { threshold = ds->pebs_absolute_maximum -
@@ -2072,6 +2074,8 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_d {short counts[INTEL_PMC_IDX_FIXED +MAX_FIXED_PEBS_EVENTS ] = {};struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +int max_pebs_events =hybrid (cpuc->pmu, max_pebs_events); +int num_counters_fixed =hybrid (cpuc->pmu, num_counters_fixed);struct debug_store *ds = cpuc->ds;struct perf_event *event;void *base, *at, *top;
@@ -2086,9 +2090,9 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_d ds->pebs_index = ds->pebs_buffer_base; - mask = ((1ULL << x86_pmu.max_pebs_events) -1 ) | - (((1ULL << x86_pmu.num_counters_fixed) -1 ) <<INTEL_PMC_IDX_FIXED ); - size =INTEL_PMC_IDX_FIXED + x86_pmu.num_counters_fixed; + mask = ((1ULL << max_pebs_events) -1 ) | + (((1ULL << num_counters_fixed) -1 ) <<INTEL_PMC_IDX_FIXED ); + size =INTEL_PMC_IDX_FIXED + num_counters_fixed;if (unlikely (base >= top)) {intel_pmu_pebs_event_update_no_drain (cpuc, size);
arch/x86/events/perf_event.h +3 -0
@@ -636,6 +636,9 @@ struct x86_hybrid_pmu {struct pmu pmu;union perf_capabilities intel_cap;u64 intel_ctrl; +int max_pebs_events; +int num_counters; +int num_counters_fixed; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
Signature · 1 line
2.7.4
PATCH v5 7/25 perf/x86: Hybrid PMU support for unconstrained
In reply to [email protected]From: Kan Liang <[email protected]>
The unconstrained value depends on the number of GP and fixed counters. Each hybrid PMU should use its own unconstrained.
--- arch/x86/events/intel/core.c | 5 ++++- arch/x86/events/perf_event.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +4 -1
@@ -3147,7 +3147,10 @@ x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx, } } -return &unconstrained; +if (!is_hybrid () || !cpuc->pmu) +return &unconstrained; + +return &hybrid_pmu (cpuc->pmu)->unconstrained; } static struct event_constraint *
arch/x86/events/perf_event.h +1 -0
@@ -639,6 +639,7 @@ struct x86_hybrid_pmu {int max_pebs_events;int num_counters;int num_counters_fixed; +struct event_constraint unconstrained; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
Signature · 1 line
2.7.4
PATCH v5 8/25 perf/x86: Hybrid PMU support for hardware cache event
In reply to [email protected]From: Kan Liang <[email protected]>
The hardware cache events are different among hybrid PMUs. Each hybrid PMU should have its own hw cache event table.
The hw_cache_extra_regs is not part of the struct x86_pmu, the hybrid() cannot be applied here.
--- arch/x86/events/core.c | 11 +++++++++-- arch/x86/events/perf_event.h | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)
arch/x86/events/core.c +9 -2
@@ -356,6 +356,7 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event) {struct perf_event_attr *attr = &event->attr;unsigned int cache_type, cache_op, cache_result; +struct x86_hybrid_pmu *pmu =is_hybrid () ?hybrid_pmu (event->pmu) :NULL ;u64 config, val; config = attr->config;
@@ -375,7 +376,10 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)return -EINVAL ; cache_result =array_index_nospec (cache_result,PERF_COUNT_HW_CACHE_RESULT_MAX ); - val = hw_cache_event_ids[cache_type][cache_op][cache_result]; +if (pmu) + val = pmu->hw_cache_event_ids[cache_type][cache_op][cache_result]; +else + val = hw_cache_event_ids[cache_type][cache_op][cache_result];if (val ==0 )return -ENOENT ;
@@ -384,7 +388,10 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)return -EINVAL ; hwc->config |= val; - attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result]; +if (pmu) + attr->config1 = pmu->hw_cache_extra_regs[cache_type][cache_op][cache_result]; +else + attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result];return x86_pmu_extra_regs (val, event); }
arch/x86/events/perf_event.h +9 -0
@@ -640,6 +640,15 @@ struct x86_hybrid_pmu {int num_counters;int num_counters_fixed;struct event_constraint unconstrained; + +u64 hw_cache_event_ids + [PERF_COUNT_HW_CACHE_MAX ] + [PERF_COUNT_HW_CACHE_OP_MAX ] + [PERF_COUNT_HW_CACHE_RESULT_MAX ]; +u64 hw_cache_extra_regs + [PERF_COUNT_HW_CACHE_MAX ] + [PERF_COUNT_HW_CACHE_OP_MAX ] + [PERF_COUNT_HW_CACHE_RESULT_MAX ]; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerRe: [PATCH V5 08/25] perf/x86: Hybrid PMU support for hardware cache event
Quoted 25 lines · On Mon, Apr 05, 2021 at 08:10:50AM -0700, [email protected] wrote:
arch/x86/events/core.c +5
-1@@ -356,6 +356,7 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event) {struct perf_event_attr *attr = &event->attr;unsigned int cache_type, cache_op, cache_result; +struct x86_hybrid_pmu *pmu =is_hybrid () ?hybrid_pmu (event->pmu) :NULL ;u64 config, val; config = attr->config;@@ -375,7 +376,10 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)return -EINVAL ; cache_result =array_index_nospec (cache_result,PERF_COUNT_HW_CACHE_RESULT_MAX ); - val = hw_cache_event_ids[cache_type][cache_op][cache_result]; +if (pmu) + val = pmu->hw_cache_event_ids[cache_type][cache_op][cache_result]; +else + val = hw_cache_event_ids[cache_type][cache_op][cache_result];if (val ==0 )return -ENOENT ;
arch/x86/events/core.c set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event) · line 396
Quoted 10 lines
arch/x86/events/core.c +4
-1@@ -384,7 +388,10 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event)return -EINVAL ; hwc->config |= val; - attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result]; +if (pmu) + attr->config1 = pmu->hw_cache_extra_regs[cache_type][cache_op][cache_result]; +else + attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result];return x86_pmu_extra_regs (val, event); }
So I'm still bugged by this, and you have the same pattern for unconstrained, plus that other issue you couldn't use hybrid() for.
How's something like this on top?
---
arch/x86/events/core.c +3 -10
@@ -356,7 +356,6 @@ set_ext_hw_attr(struct hw_perf_event *hw {struct perf_event_attr *attr = &event->attr;unsigned int cache_type, cache_op, cache_result; -struct x86_hybrid_pmu *pmu =is_hybrid () ?hybrid_pmu (event->pmu) :NULL ;u64 config, val; config = attr->config;
@@ -376,11 +375,7 @@ set_ext_hw_attr(struct hw_perf_event *hwreturn -EINVAL ; cache_result =array_index_nospec (cache_result,PERF_COUNT_HW_CACHE_RESULT_MAX ); -if (pmu) - val = pmu->hw_cache_event_ids[cache_type][cache_op][cache_result]; -else - val = hw_cache_event_ids[cache_type][cache_op][cache_result]; - + val =hybrid_var (event->pmu, hw_cache_event_ids)[cache_type][cache_op][cache_result];if (val ==0 )return -ENOENT ;
@@ -388,10 +383,8 @@ set_ext_hw_attr(struct hw_perf_event *hwreturn -EINVAL ; hwc->config |= val; -if (pmu) - attr->config1 = pmu->hw_cache_extra_regs[cache_type][cache_op][cache_result]; -else - attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result]; + attr->config1 =hybrid_var (event->pmu, hw_cache_extra_regs)[cache_type][cache_op][cache_result]; +return x86_pmu_extra_regs (val, event); }
arch/x86/events/perf_event.h +15 -5
@@ -660,14 +660,24 @@ static __always_inline struct x86_hybrid#define is_hybrid () (!!x86_pmu.num_hybrid_pmus)#define hybrid (_pmu, _field) \ -({ \ - typeof(x86_pmu._field) __F = x86_pmu._field; \ +(*({ \ + typeof(&x86_pmu._field) __Fp = &x86_pmu._field; \ \ if (is_hybrid() && (_pmu)) \ - __F = hybrid_pmu(_pmu)->_field; \ + __Fp = &hybrid_pmu(_pmu)->_field; \ \ - __F; \ -}) + __Fp; \ +})) + +#define hybrid_var (_pmu, _var) \ +(*({ \ + typeof(&_var) __Fp = &_var; \ + \ + if (is_hybrid() && (_pmu)) \ + __Fp = &hybrid_pmu(_pmu)->_var; \ + \ + __Fp; \ +}))/* * struct x86_pmu - generic x86 pmu
arch/x86/events/intel/core.c +2 -8
@@ -3147,10 +3147,7 @@ x86_get_event_constraints(struct cpu_hw_ } } -if (!is_hybrid () || !cpuc->pmu) -return &unconstrained; - -return &hybrid_pmu (cpuc->pmu)->unconstrained; +return &hybrid_var (cpuc->pmu, unconstrained); } static struct event_constraint *
@@ -3656,10 +3653,7 @@ static inline bool is_mem_loads_aux_evenstatic inline bool intel_pmu_has_cap (struct perf_event *event,int idx) { -union perf_capabilities *intel_cap; - - intel_cap =is_hybrid () ? &hybrid_pmu (event->pmu)->intel_cap : - &x86_pmu.intel_cap; +union perf_capabilities *intel_cap = &hybrid (event->pmu, intel_cap);return test_bit (idx, (unsigned long *)&intel_cap->capabilities); }
PATCH v5 9/25 perf/x86: Hybrid PMU support for event constraints
In reply to [email protected]From: Kan Liang <[email protected]>
The events are different among hybrid PMUs. Each hybrid PMU should use its own event constraints.
--- arch/x86/events/core.c | 3 ++- arch/x86/events/intel/core.c | 5 +++-- arch/x86/events/intel/ds.c | 5 +++-- arch/x86/events/perf_event.h | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-)
arch/x86/events/core.c +2 -1
@@ -1526,6 +1526,7 @@ void perf_event_print_debug(void)struct cpu_hw_events *cpuc = &per_cpu (cpu_hw_events, cpu);int num_counters =hybrid (cpuc->pmu, num_counters);int num_counters_fixed =hybrid (cpuc->pmu, num_counters_fixed); +struct event_constraint *pebs_constraints =hybrid (cpuc->pmu, pebs_constraints);unsigned long flags;int idx;
@@ -1545,7 +1546,7 @@ void perf_event_print_debug(void)pr_info ("CPU#%d: status: %016llx\n" , cpu, status);pr_info ("CPU#%d: overflow: %016llx\n" , cpu, overflow);pr_info ("CPU#%d: fixed: %016llx\n" , cpu, fixed); -if (x86_pmu.pebs_constraints) { +if (pebs_constraints) {rdmsrl (MSR_IA32_PEBS_ENABLE , pebs);pr_info ("CPU#%d: pebs: %016llx\n" , cpu, pebs); }
arch/x86/events/intel/core.c +3 -2
@@ -3136,10 +3136,11 @@ struct event_constraint * x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx, struct perf_event *event) { + struct event_constraint *event_constraints = hybrid(cpuc->pmu, event_constraints);struct event_constraint *c; -if (x86_pmu.event_constraints) { -for_each_event_constraint (c, x86_pmu.event_constraints) { +if (event_constraints) { +for_each_event_constraint (c, event_constraints) {if (constraint_match (c, event->hw.config)) { event->hw.flags |= c->flags;return c;
arch/x86/events/intel/ds.c +3 -2
@@ -959,13 +959,14 @@ struct event_constraint intel_spr_pebs_event_constraints[] = {struct event_constraint *intel_pebs_constraints (struct perf_event *event) { +struct event_constraint *pebs_constraints =hybrid (event->pmu, pebs_constraints);struct event_constraint *c;if (!event->attr.precise_ip)return NULL ; -if (x86_pmu.pebs_constraints) { -for_each_event_constraint (c, x86_pmu.pebs_constraints) { +if (pebs_constraints) { +for_each_event_constraint (c, pebs_constraints) {if (constraint_match (c, event->hw.config)) { event->hw.flags |= c->flags;return c;
arch/x86/events/perf_event.h +2 -0
@@ -649,6 +649,8 @@ struct x86_hybrid_pmu { [PERF_COUNT_HW_CACHE_MAX ] [PERF_COUNT_HW_CACHE_OP_MAX ] [PERF_COUNT_HW_CACHE_RESULT_MAX ]; +struct event_constraint *event_constraints; +struct event_constraint *pebs_constraints; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
Signature · 1 line
2.7.4
PATCH v5 10/25 perf/x86: Hybrid PMU support for extra_regs
In reply to [email protected]From: Kan Liang <[email protected]>
Different hybrid PMU may have different extra registers, e.g. Core PMU may have offcore registers, frontend register and ldlat register. Atom core may only have offcore registers and ldlat register. Each hybrid PMU should use its own extra_regs.
An Intel Hybrid system should always have extra registers. Unconditionally allocate shared_regs for Intel Hybrid system.
--- arch/x86/events/core.c | 5 +++-- arch/x86/events/intel/core.c | 15 +++++++++------ arch/x86/events/perf_event.h | 1 + 3 files changed, 13 insertions(+), 8 deletions(-)
arch/x86/events/core.c +3 -2
@@ -153,15 +153,16 @@ u64 x86_perf_event_update(struct perf_event *event)*/ static int x86_pmu_extra_regs (u64 config,struct perf_event *event) { +struct extra_reg *extra_regs =hybrid (event->pmu, extra_regs);struct hw_perf_event_extra *reg;struct extra_reg *er; reg = &event->hw.extra_reg; -if (!x86_pmu.extra_regs) +if (!extra_regs)return 0 ; -for (er = x86_pmu.extra_regs; er->msr; er++) { +for (er = extra_regs; er->msr; er++) {if (er->event != (config & er->config_mask))continue ;if (event->attr.config1 & ~er->valid_mask)
arch/x86/events/intel/core.c +9 -6
@@ -2966,8 +2966,10 @@ intel_vlbr_constraints(struct perf_event *event)return NULL ; } -static int intel_alt_er (int idx,u64 config) +static int intel_alt_er (struct cpu_hw_events *cpuc, +int idx,u64 config) { +struct extra_reg *extra_regs =hybrid (cpuc->pmu, extra_regs);int alt_idx = idx;if (!(x86_pmu.flags &PMU_FL_HAS_RSP_1 ))
@@ -2979,7 +2981,7 @@ static int intel_alt_er(int idx, u64 config)if (idx ==EXTRA_REG_RSP_1 ) alt_idx =EXTRA_REG_RSP_0 ; -if (config & ~x86_pmu.extra_regs[alt_idx].valid_mask) +if (config & ~extra_regs[alt_idx].valid_mask)return idx;return alt_idx;
@@ -2987,15 +2989,16 @@ static int intel_alt_er(int idx, u64 config)static void intel_fixup_er (struct perf_event *event,int idx) { +struct extra_reg *extra_regs =hybrid (event->pmu, extra_regs); event->hw.extra_reg.idx = idx;if (idx ==EXTRA_REG_RSP_0 ) { event->hw.config &= ~INTEL_ARCH_EVENT_MASK ; - event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_0 ].event; + event->hw.config |= extra_regs[EXTRA_REG_RSP_0 ].event; event->hw.extra_reg.reg =MSR_OFFCORE_RSP_0 ; }else if (idx ==EXTRA_REG_RSP_1 ) { event->hw.config &= ~INTEL_ARCH_EVENT_MASK ; - event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_1 ].event; + event->hw.config |= extra_regs[EXTRA_REG_RSP_1 ].event; event->hw.extra_reg.reg =MSR_OFFCORE_RSP_1 ; } }
@@ -3071,7 +3074,7 @@ __intel_shared_reg_get_constraints(struct cpu_hw_events *cpuc,*/ c =NULL ; }else { - idx =intel_alt_er (idx, reg->config); + idx =intel_alt_er (cpuc, idx, reg->config);if (idx != reg->idx) {raw_spin_unlock_irqrestore (&era->lock, flags); goto again;
@@ -4161,7 +4164,7 @@ int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu) { cpuc->pebs_record_size = x86_pmu.pebs_record_size; -if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) { +if (is_hybrid () || x86_pmu.extra_regs || x86_pmu.lbr_sel_map) { cpuc->shared_regs =allocate_shared_regs (cpu);if (!cpuc->shared_regs) goto err;
arch/x86/events/perf_event.h +1 -0
@@ -651,6 +651,7 @@ struct x86_hybrid_pmu { [PERF_COUNT_HW_CACHE_RESULT_MAX ];struct event_constraint *event_constraints;struct event_constraint *pebs_constraints; +struct extra_reg *extra_regs; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
Signature · 1 line
2.7.4
PATCH v5 11/25 perf/x86/intel: Factor out intel_pmu_check_num_counters
In reply to [email protected]From: Kan Liang <[email protected]>
Each Hybrid PMU has to check its own number of counters and mask fixed counters before registration.
The intel_pmu_check_num_counters will be reused later to check the number of the counters for each hybrid PMU.
--- arch/x86/events/intel/core.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
arch/x86/events/intel/core.c +24 -14
@@ -5070,6 +5070,26 @@ static const struct attribute_group *attr_update[] = {static struct attribute *empty_attrs; +static void intel_pmu_check_num_counters (int *num_counters, +int *num_counters_fixed, +u64 *intel_ctrl,u64 fixed_mask) +{ +if (*num_counters >INTEL_PMC_MAX_GENERIC ) { +WARN (1 ,KERN_ERR "hw perf events %d > max(%d), clipping!" , + *num_counters,INTEL_PMC_MAX_GENERIC ); + *num_counters =INTEL_PMC_MAX_GENERIC ; + } + *intel_ctrl = (1ULL << *num_counters) -1 ; + +if (*num_counters_fixed >INTEL_PMC_MAX_FIXED ) { +WARN (1 ,KERN_ERR "hw perf events fixed %d > max(%d), clipping!" , + *num_counters_fixed,INTEL_PMC_MAX_FIXED ); + *num_counters_fixed =INTEL_PMC_MAX_FIXED ; + } + + *intel_ctrl |= fixed_mask <<INTEL_PMC_IDX_FIXED ; +} +__init int intel_pmu_init (void ) {struct attribute **extra_skl_attr = &empty_attrs;
@@ -5709,20 +5729,10 @@ __init int intel_pmu_init(void) x86_pmu.attr_update = attr_update; -if (x86_pmu.num_counters >INTEL_PMC_MAX_GENERIC ) { -WARN (1 ,KERN_ERR "hw perf events %d > max(%d), clipping!" , - x86_pmu.num_counters,INTEL_PMC_MAX_GENERIC ); - x86_pmu.num_counters =INTEL_PMC_MAX_GENERIC ; - } - x86_pmu.intel_ctrl = (1ULL << x86_pmu.num_counters) -1 ; - -if (x86_pmu.num_counters_fixed >INTEL_PMC_MAX_FIXED ) { -WARN (1 ,KERN_ERR "hw perf events fixed %d > max(%d), clipping!" , - x86_pmu.num_counters_fixed,INTEL_PMC_MAX_FIXED ); - x86_pmu.num_counters_fixed =INTEL_PMC_MAX_FIXED ; - } - - x86_pmu.intel_ctrl |= (u64 )fixed_mask <<INTEL_PMC_IDX_FIXED ; +intel_pmu_check_num_counters (&x86_pmu.num_counters, + &x86_pmu.num_counters_fixed, + &x86_pmu.intel_ctrl, + (u64 )fixed_mask);/* AnyThread may be deprecated on arch perfmon v5 or later */ if (x86_pmu.intel_cap.anythread_deprecated)
Signature · 1 line
2.7.4
PATCH v5 12/25 perf/x86/intel: Factor out intel_pmu_check_event_constraints
In reply to [email protected]From: Kan Liang <[email protected]>
Each Hybrid PMU has to check and update its own event constraints before registration.
The intel_pmu_check_event_constraints will be reused later to check the event constraints of each hybrid PMU.
--- arch/x86/events/intel/core.c | 82 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 35 deletions(-)
arch/x86/events/intel/core.c +47 -35
@@ -5090,6 +5090,49 @@ static void intel_pmu_check_num_counters(int *num_counters, *intel_ctrl |= fixed_mask <<INTEL_PMC_IDX_FIXED ; } +static void intel_pmu_check_event_constraints (struct event_constraint *event_constraints, +int num_counters, +int num_counters_fixed, +u64 intel_ctrl) +{ +struct event_constraint *c; + +if (!event_constraints) +return ; + +/* +* event on fixed counter2 (REF_CYCLES) only works on this +* counter, so do not extend mask to generic counters +*/ +for_each_event_constraint (c, event_constraints) { +/* +* Don't extend the topdown slots and metrics +* events to the generic counters. +*/ +if (c->idxmsk64 &INTEL_PMC_MSK_TOPDOWN ) { +/* +* Disable topdown slots and metrics events, +* if slots event is not in CPUID. +*/ +if (!(INTEL_PMC_MSK_FIXED_SLOTS & intel_ctrl)) + c->idxmsk64 =0 ; + c->weight =hweight64 (c->idxmsk64); +continue ; + } + +if (c->cmask ==FIXED_EVENT_FLAGS ) { +/* Disabled fixed counters which are not in CPUID */ + c->idxmsk64 &= intel_ctrl; + +if (c->idxmsk64 !=INTEL_PMC_MSK_FIXED_REF_CYCLES ) + c->idxmsk64 |= (1ULL << num_counters) -1 ; + } + c->idxmsk64 &= + ~(~0ULL << (INTEL_PMC_IDX_FIXED + num_counters_fixed)); + c->weight =hweight64 (c->idxmsk64); + } +} +__init int intel_pmu_init (void ) {struct attribute **extra_skl_attr = &empty_attrs;
@@ -5100,7 +5143,6 @@ __init int intel_pmu_init(void)union cpuid10_edx edx;union cpuid10_eax eax;union cpuid10_ebx ebx; -struct event_constraint *c;unsigned int fixed_mask;struct extra_reg *er;bool pmem = false;
@@ -5738,40 +5780,10 @@ __init int intel_pmu_init(void)if (x86_pmu.intel_cap.anythread_deprecated) x86_pmu.format_attrs = intel_arch_formats_attr; -if (x86_pmu.event_constraints) { -/* -* event on fixed counter2 (REF_CYCLES) only works on this -* counter, so do not extend mask to generic counters -*/ -for_each_event_constraint (c, x86_pmu.event_constraints) { -/* -* Don't extend the topdown slots and metrics -* events to the generic counters. -*/ -if (c->idxmsk64 &INTEL_PMC_MSK_TOPDOWN ) { -/* -* Disable topdown slots and metrics events, -* if slots event is not in CPUID. -*/ -if (!(INTEL_PMC_MSK_FIXED_SLOTS & x86_pmu.intel_ctrl)) - c->idxmsk64 =0 ; - c->weight =hweight64 (c->idxmsk64); -continue ; - } - -if (c->cmask ==FIXED_EVENT_FLAGS ) { -/* Disabled fixed counters which are not in CPUID */ - c->idxmsk64 &= x86_pmu.intel_ctrl; - -if (c->idxmsk64 !=INTEL_PMC_MSK_FIXED_REF_CYCLES ) - c->idxmsk64 |= (1ULL << x86_pmu.num_counters) -1 ; - } - c->idxmsk64 &= - ~(~0ULL << (INTEL_PMC_IDX_FIXED + x86_pmu.num_counters_fixed)); - c->weight =hweight64 (c->idxmsk64); - } - } - +intel_pmu_check_event_constraints (x86_pmu.event_constraints, + x86_pmu.num_counters, + x86_pmu.num_counters_fixed, + x86_pmu.intel_ctrl);/* * Access LBR MSR may cause #GP under certain circumstances. * E.g. KVM doesn't support LBR MSR
Signature · 1 line
2.7.4
PATCH v5 13/25 perf/x86/intel: Factor out intel_pmu_check_extra_regs
In reply to [email protected]From: Kan Liang <[email protected]>
Each Hybrid PMU has to check and update its own extra registers before registration.
The intel_pmu_check_extra_regs will be reused later to check the extra registers of each hybrid PMU.
--- arch/x86/events/intel/core.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
arch/x86/events/intel/core.c +21 -14
@@ -5133,6 +5133,26 @@ static void intel_pmu_check_event_constraints(struct event_constraint *event_con } } +static void intel_pmu_check_extra_regs (struct extra_reg *extra_regs) +{ +struct extra_reg *er; + +/* +* Access extra MSR may cause #GP under certain circumstances. +* E.g. KVM doesn't support offcore event +* Check all extra_regs here. +*/ +if (!extra_regs) +return ; + +for (er = extra_regs; er->msr; er++) { + er->extra_msr_access =check_msr (er->msr,0x11UL ); +/* Disable LBR select mapping */ +if ((er->idx ==EXTRA_REG_LBR ) && !er->extra_msr_access) + x86_pmu.lbr_sel_map =NULL ; + } +} +__init int intel_pmu_init (void ) {struct attribute **extra_skl_attr = &empty_attrs;
@@ -5144,7 +5164,6 @@ __init int intel_pmu_init(void)union cpuid10_eax eax;union cpuid10_ebx ebx;unsigned int fixed_mask; -struct extra_reg *er;bool pmem = false;int version, i;char *name;
@@ -5801,19 +5820,7 @@ __init int intel_pmu_init(void)if (x86_pmu.lbr_nr)pr_cont ("%d-deep LBR, " , x86_pmu.lbr_nr); -/* -* Access extra MSR may cause #GP under certain circumstances. -* E.g. KVM doesn't support offcore event -* Check all extra_regs here. -*/ -if (x86_pmu.extra_regs) { -for (er = x86_pmu.extra_regs; er->msr; er++) { - er->extra_msr_access =check_msr (er->msr,0x11UL ); -/* Disable LBR select mapping */ -if ((er->idx ==EXTRA_REG_LBR ) && !er->extra_msr_access) - x86_pmu.lbr_sel_map =NULL ; - } - } +intel_pmu_check_extra_regs (x86_pmu.extra_regs);/* Support full width counters using alternative MSR range */ if (x86_pmu.intel_cap.full_width_write) {
Signature · 1 line
2.7.4
PATCH v5 14/25 perf/x86: Remove temporary pmu assignment in event_init
In reply to [email protected]From: Kan Liang <[email protected]>
The temporary pmu assignment in event_init is unnecessary.
The assignment was introduced by commit 8113070d6639 ("perf_events:
Add fast-path to the rescheduling code"). At that time, event->pmu is not assigned yet when initializing an event. The assignment is required. However, from commit 7e5b2a01d2ca ("perf: provide PMU when initing events"), the event->pmu is provided before event_init is invoked. The temporary pmu assignment in event_init should be removed.
--- arch/x86/events/core.c | 11 ----------- 1 file changed, 11 deletions(-)
arch/x86/events/core.c +0 -11
@@ -2299,7 +2299,6 @@ static int validate_group(struct perf_event *event)static int x86_pmu_event_init (struct perf_event *event) { -struct pmu *tmp;int err;switch (event->attr.type) {
@@ -2314,20 +2313,10 @@ static int x86_pmu_event_init(struct perf_event *event) err =__x86_pmu_event_init (event);if (!err) { -/* -* we temporarily connect event to its pmu -* such that validate_group() can classify -* it as an x86 event using is_x86_event() -*/ - tmp = event->pmu; - event->pmu = &pmu; -if (event->group_leader != event) err =validate_group (event);else err =validate_event (event); - - event->pmu = tmp; }if (err) {if (event->destroy)
Signature · 1 line
2.7.4
PATCH v5 15/25 perf/x86: Factor out x86_pmu_show_pmu_cap
In reply to [email protected]From: Kan Liang <[email protected]>
The PMU capabilities are different among hybrid PMUs. Perf should dump the PMU capabilities information for each hybrid PMU.
Factor out x86_pmu_show_pmu_cap() which shows the PMU capabilities information. The function will be reused later when registering a dedicated hybrid PMU.
--- arch/x86/events/core.c | 25 ++++++++++++++++--------- arch/x86/events/perf_event.h | 3 +++ 2 files changed, 19 insertions(+), 9 deletions(-)
arch/x86/events/core.c +16 -9
@@ -1984,6 +1984,20 @@ static void _x86_pmu_read(struct perf_event *event)x86_perf_event_update (event); } +void x86_pmu_show_pmu_cap (int num_counters,int num_counters_fixed, +u64 intel_ctrl) +{ +pr_info ("... version: %d\n" , x86_pmu.version); +pr_info ("... bit width: %d\n" , x86_pmu.cntval_bits); +pr_info ("... generic registers: %d\n" , num_counters); +pr_info ("... value mask: %016Lx\n" , x86_pmu.cntval_mask); +pr_info ("... max period: %016Lx\n" , x86_pmu.max_period); +pr_info ("... fixed-purpose events: %lu\n" , +hweight64 ((((1ULL << num_counters_fixed) -1 ) + <<INTEL_PMC_IDX_FIXED ) & intel_ctrl)); +pr_info ("... event mask: %016Lx\n" , intel_ctrl); +} +static int __init init_hw_perf_events (void ) {struct x86_pmu_quirk *quirk;
@@ -2044,15 +2058,8 @@ static int __init init_hw_perf_events(void) pmu.attr_update = x86_pmu.attr_update; -pr_info ("... version: %d\n" , x86_pmu.version); -pr_info ("... bit width: %d\n" , x86_pmu.cntval_bits); -pr_info ("... generic registers: %d\n" , x86_pmu.num_counters); -pr_info ("... value mask: %016Lx\n" , x86_pmu.cntval_mask); -pr_info ("... max period: %016Lx\n" , x86_pmu.max_period); -pr_info ("... fixed-purpose events: %lu\n" , -hweight64 ((((1ULL << x86_pmu.num_counters_fixed) -1 ) - <<INTEL_PMC_IDX_FIXED ) & x86_pmu.intel_ctrl)); -pr_info ("... event mask: %016Lx\n" , x86_pmu.intel_ctrl); +x86_pmu_show_pmu_cap (x86_pmu.num_counters, x86_pmu.num_counters_fixed, + x86_pmu.intel_ctrl);if (!x86_pmu.read) x86_pmu.read = _x86_pmu_read;
arch/x86/events/perf_event.h +3 -0
@@ -1083,6 +1083,9 @@ void x86_pmu_enable_event(struct perf_event *event);int x86_pmu_handle_irq (struct pt_regs *regs); +void x86_pmu_show_pmu_cap (int num_counters,int num_counters_fixed, +u64 intel_ctrl); +extern struct event_constraint emptyconstraint;extern struct event_constraint unconstrained;
Signature · 1 line
2.7.4
PATCH v5 16/25 perf/x86: Register hybrid PMUs
In reply to [email protected]From: Kan Liang <[email protected]>
Different hybrid PMUs have different PMU capabilities and events. Perf should registers a dedicated PMU for each of them.
To check the X86 event, perf has to go through all possible hybrid pmus.
All the hybrid PMUs are registered at boot time. Before the registration, add intel_pmu_check_hybrid_pmus() to check and update the counters information, the event constraints, the extra registers and the unique capabilities for each hybrid PMUs.
Postpone the display of the PMU information and HW check to CPU_STARTING, because the boot CPU is the only online CPU in the init_hw_perf_events(). Perf doesn't know the availability of the other PMUs. Perf should display the PMU information only if the counters of the PMU are available.
One type of CPUs may be all offline. For this case, users can still observe the PMU in /sys/devices, but its CPU mask is 0.
All hybrid PMUs have capability PERF_PMU_CAP_HETEROGENEOUS_CPUS. The PMU name for hybrid PMUs will be "cpu_XXX", which will be assigned later in a separated patch.
The PMU type id for the core PMU is still PERF_TYPE_RAW. For the other hybrid PMUs, the PMU type id is not hard code.
The event->cpu must be compatitable with the supported CPUs of the PMU. Add a check in the x86_pmu_event_init().
The events in a group must be from the same type of hybrid PMU. The fake cpuc used in the validation must be from the supported CPU of the event->pmu.
Perf may not retrieve a valid core type from get_this_hybrid_cpu_type(). For example, ADL may have an alternative configuration. With that configuration, Perf cannot retrieve the core type from the CPUID leaf 0x1a. Add a platform specific get_hybrid_cpu_type(). If the generic way fails, invoke the platform specific get_hybrid_cpu_type().
--- arch/x86/events/core.c | 138 +++++++++++++++++++++++++++++++++++++------ arch/x86/events/intel/core.c | 93 ++++++++++++++++++++++++++++- arch/x86/events/perf_event.h | 14 +++++ 3 files changed, 224 insertions(+), 21 deletions(-)
arch/x86/events/core.c +119 -19
@@ -485,7 +485,7 @@ int x86_setup_perfctr(struct perf_event *event)local64_set (&hwc->period_left, hwc->sample_period); } -if (attr->type ==PERF_TYPE_RAW ) +if (attr->type == event->pmu->type)return x86_pmu_extra_regs (event->attr.config, event);if (attr->type ==PERF_TYPE_HW_CACHE )
@@ -620,7 +620,7 @@ int x86_pmu_hw_config(struct perf_event *event)if (!event->attr.exclude_kernel) event->hw.config |=ARCH_PERFMON_EVENTSEL_OS ; -if (event->attr.type ==PERF_TYPE_RAW ) +if (event->attr.type == event->pmu->type) event->hw.config |= event->attr.config &X86_RAW_EVENT_MASK ;if (event->attr.sample_period && x86_pmu.limit_period) {
@@ -749,7 +749,17 @@ void x86_pmu_enable_all(int added)static inline int is_x86_event (struct perf_event *event) { -return event->pmu == &pmu; +int i; + +if (!is_hybrid ()) +return event->pmu == &pmu; + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { +if (event->pmu == &x86_pmu.hybrid_pmu[i].pmu) +return true; + } + +return false; }struct pmu *x86_get_pmu (unsigned int cpu)
@@ -1998,6 +2008,23 @@ void x86_pmu_show_pmu_cap(int num_counters, int num_counters_fixed,pr_info ("... event mask: %016Lx\n" , intel_ctrl); } +/* +* The generic code is not hybrid friendly. The hybrid_pmu->pmu +* of the first registered PMU is unconditionally assigned to +* each possible cpuctx->ctx.pmu. +* Update the correct hybrid PMU to the cpuctx->ctx.pmu. +*/ +void x86_pmu_update_cpu_context (struct pmu *pmu,int cpu) +{ +struct perf_cpu_context *cpuctx; + +if (!pmu->pmu_cpu_context) +return ; + + cpuctx =per_cpu_ptr (pmu->pmu_cpu_context, cpu); + cpuctx->ctx.pmu = pmu; +} +static int __init init_hw_perf_events (void ) {struct x86_pmu_quirk *quirk;
@@ -2058,8 +2085,11 @@ static int __init init_hw_perf_events(void) pmu.attr_update = x86_pmu.attr_update; -x86_pmu_show_pmu_cap (x86_pmu.num_counters, x86_pmu.num_counters_fixed, - x86_pmu.intel_ctrl); +if (!is_hybrid ()) { +x86_pmu_show_pmu_cap (x86_pmu.num_counters, + x86_pmu.num_counters_fixed, + x86_pmu.intel_ctrl); + }if (!x86_pmu.read) x86_pmu.read = _x86_pmu_read;
@@ -2089,9 +2119,46 @@ static int __init init_hw_perf_events(void)if (err) goto out1; - err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); -if (err) - goto out2; +if (!is_hybrid ()) { + err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); +if (err) + goto out2; + }else { +u8 cpu_type =get_this_hybrid_cpu_type (); +struct x86_hybrid_pmu *hybrid_pmu; +bool registered = false; +int i; + +if (!cpu_type && x86_pmu.get_hybrid_cpu_type) + cpu_type = x86_pmu.get_hybrid_cpu_type (); + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { + hybrid_pmu = &x86_pmu.hybrid_pmu[i]; + + hybrid_pmu->pmu = pmu; + hybrid_pmu->pmu.type =-1 ; + hybrid_pmu->pmu.attr_update = x86_pmu.attr_update; + hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_HETEROGENEOUS_CPUS ; + + err =perf_pmu_register (&hybrid_pmu->pmu, hybrid_pmu->name, + (hybrid_pmu->cpu_type == hybrid_big) ?PERF_TYPE_RAW :-1 ); +if (err) +continue ; + +if (cpu_type == hybrid_pmu->cpu_type) +x86_pmu_update_cpu_context (&hybrid_pmu->pmu,raw_smp_processor_id ()); + + registered = true; + } + +if (!registered) { +pr_warn ("Failed to register hybrid PMUs\n" ); +kfree (x86_pmu.hybrid_pmu); + x86_pmu.hybrid_pmu =NULL ; + x86_pmu.num_hybrid_pmus =0 ; + goto out2; + } + }return 0 ;
@@ -2216,16 +2283,27 @@ static void free_fake_cpuc(struct cpu_hw_events *cpuc)kfree (cpuc); } -static struct cpu_hw_events *allocate_fake_cpuc (void ) +static struct cpu_hw_events *allocate_fake_cpuc (struct pmu *event_pmu) {struct cpu_hw_events *cpuc; -int cpu =raw_smp_processor_id (); +int cpu; cpuc =kzalloc (sizeof (*cpuc),GFP_KERNEL );if (!cpuc)return ERR_PTR (-ENOMEM ); cpuc->is_fake =1 ; +if (is_hybrid ()) { +struct x86_hybrid_pmu *h_pmu; + + h_pmu =hybrid_pmu (event_pmu); +if (cpumask_empty (&h_pmu->supported_cpus)) + goto error; + cpu =cpumask_first (&h_pmu->supported_cpus); + }else + cpu =raw_smp_processor_id (); + cpuc->pmu = event_pmu; +if (intel_cpuc_prepare (cpuc, cpu)) goto error;
@@ -2244,7 +2322,7 @@ static int validate_event(struct perf_event *event)struct event_constraint *c;int ret =0 ; - fake_cpuc =allocate_fake_cpuc (); + fake_cpuc =allocate_fake_cpuc (event->pmu);if (IS_ERR (fake_cpuc))return PTR_ERR (fake_cpuc);
@@ -2278,7 +2356,27 @@ static int validate_group(struct perf_event *event)struct cpu_hw_events *fake_cpuc;int ret = -EINVAL , n; - fake_cpuc =allocate_fake_cpuc (); +/* +* Reject events from different hybrid PMUs. +*/ +if (is_hybrid ()) { +struct perf_event *sibling; +struct pmu *pmu =NULL ; + +if (is_x86_event (leader)) + pmu = leader->pmu; + +for_each_sibling_event (sibling, leader) { +if (!is_x86_event (sibling)) +continue ; +if (!pmu) + pmu = sibling->pmu; +else if (pmu != sibling->pmu) +return ret; + } + } + + fake_cpuc =allocate_fake_cpuc (event->pmu);if (IS_ERR (fake_cpuc))return PTR_ERR (fake_cpuc);/*
@@ -2306,16 +2404,18 @@ static int validate_group(struct perf_event *event)static int x86_pmu_event_init (struct perf_event *event) { +struct x86_hybrid_pmu *pmu =NULL ;int err; -switch (event->attr.type) { -case PERF_TYPE_RAW : -case PERF_TYPE_HARDWARE : -case PERF_TYPE_HW_CACHE : -break ; - -default : +if ((event->attr.type != event->pmu->type) && + (event->attr.type !=PERF_TYPE_HARDWARE ) && + (event->attr.type !=PERF_TYPE_HW_CACHE ))return -ENOENT ; + +if (is_hybrid () && (event->cpu !=-1 )) { + pmu =hybrid_pmu (event->pmu); +if (!cpumask_test_cpu (event->cpu, &pmu->supported_cpus)) +return -ENOENT ; } err =__x86_pmu_event_init (event);
arch/x86/events/intel/core.c +91 -2
129 lines not on this page · raw message
arch/x86/events/perf_event.h +14 -0
@@ -15,6 +15,7 @@#include <linux/perf_event.h> #include <asm/intel_ds.h> +#include <asm/cpu.h> /* To enable MSR tracing please use the generic trace points. */
@@ -634,6 +635,9 @@ enum {struct x86_hybrid_pmu {struct pmu pmu; +const char *name; +u8 cpu_type; +cpumask_t supported_cpus;union perf_capabilities intel_cap;u64 intel_ctrl;int max_pebs_events;
@@ -672,6 +676,13 @@ static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu) __F; \ }) +enum hybrid_pmu_type { + hybrid_big =0x40 , + hybrid_small =0x20 , + + hybrid_big_small = hybrid_big | hybrid_small, +}; +/* * struct x86_pmu - generic x86 pmu */
@@ -869,6 +880,7 @@ struct x86_pmu {*/ int num_hybrid_pmus;struct x86_hybrid_pmu *hybrid_pmu; +u8 (*get_hybrid_cpu_type) (void); };struct x86_perf_task_context_opt {
@@ -1086,6 +1098,8 @@ int x86_pmu_handle_irq(struct pt_regs *regs);void x86_pmu_show_pmu_cap (int num_counters,int num_counters_fixed,u64 intel_ctrl); +void x86_pmu_update_cpu_context (struct pmu *pmu,int cpu); +extern struct event_constraint emptyconstraint;extern struct event_constraint unconstrained;
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerRe: [PATCH V5 16/25] perf/x86: Register hybrid PMUs
Quoted 36 lines · On Mon, Apr 05, 2021 at 08:10:58AM -0700, [email protected] wrote:
arch/x86/events/core.c +29
-3@@ -2089,9 +2119,46 @@ static int __init init_hw_perf_events(void)if (err) goto out1; - err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); -if (err) - goto out2; +if (!is_hybrid ()) { + err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); +if (err) + goto out2; + }else { +u8 cpu_type =get_this_hybrid_cpu_type (); +struct x86_hybrid_pmu *hybrid_pmu; +bool registered = false; +int i; + +if (!cpu_type && x86_pmu.get_hybrid_cpu_type) + cpu_type = x86_pmu.get_hybrid_cpu_type (); + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { + hybrid_pmu = &x86_pmu.hybrid_pmu[i]; + + hybrid_pmu->pmu = pmu; + hybrid_pmu->pmu.type =-1 ; + hybrid_pmu->pmu.attr_update = x86_pmu.attr_update; + hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_HETEROGENEOUS_CPUS ; + + err =perf_pmu_register (&hybrid_pmu->pmu, hybrid_pmu->name, + (hybrid_pmu->cpu_type == hybrid_big) ?PERF_TYPE_RAW :-1 ); +if (err) +continue ; + +if (cpu_type == hybrid_pmu->cpu_type) +x86_pmu_update_cpu_context (&hybrid_pmu->pmu,raw_smp_processor_id ()); +
arch/x86/events/core.c static int __init init_hw_perf_events(void) · line 2160
Quoted 10 lines
arch/x86/events/core.c +10
-0+ registered = true; + } + +if (!registered) { +pr_warn ("Failed to register hybrid PMUs\n" ); +kfree (x86_pmu.hybrid_pmu); + x86_pmu.hybrid_pmu =NULL ; + x86_pmu.num_hybrid_pmus =0 ; + goto out2; + }
I don't think this is quite right. registered will be true even if one fails, while I think you meant to only have it true when all (both) types registered correctly.
Quoted 4 lines
arch/x86/events/core.c +1
-0+ }return 0 ;
Re: [PATCH V5 16/25] perf/x86: Register hybrid PMUs
Quoted 43 lines · Peter Zijlstra
Quoted 42 lines · On Mon, Apr 05, 2021 at 08:10:58AM -0700, [email protected] wrote:
arch/x86/events/core.c +35
-3@@ -2089,9 +2119,46 @@ static int __init init_hw_perf_events(void)if (err) goto out1; - err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); -if (err) - goto out2; +if (!is_hybrid ()) { + err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); +if (err) + goto out2; + }else { +u8 cpu_type =get_this_hybrid_cpu_type (); +struct x86_hybrid_pmu *hybrid_pmu; +bool registered = false; +int i; + +if (!cpu_type && x86_pmu.get_hybrid_cpu_type) + cpu_type = x86_pmu.get_hybrid_cpu_type (); + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { + hybrid_pmu = &x86_pmu.hybrid_pmu[i]; + + hybrid_pmu->pmu = pmu; + hybrid_pmu->pmu.type =-1 ; + hybrid_pmu->pmu.attr_update = x86_pmu.attr_update; + hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_HETEROGENEOUS_CPUS ; + + err =perf_pmu_register (&hybrid_pmu->pmu, hybrid_pmu->name, + (hybrid_pmu->cpu_type == hybrid_big) ?PERF_TYPE_RAW :-1 ); +if (err) +continue ; + +if (cpu_type == hybrid_pmu->cpu_type) +x86_pmu_update_cpu_context (&hybrid_pmu->pmu,raw_smp_processor_id ()); + + registered = true; + } + +if (!registered) { +pr_warn ("Failed to register hybrid PMUs\n" ); +kfree (x86_pmu.hybrid_pmu);
Quoted 8 lines
arch/x86/events/core.c static int __init init_hw_perf_events(void) · line 2160
Quoted 4 lines
arch/x86/events/core.c +4
-0+ x86_pmu.hybrid_pmu =NULL ; + x86_pmu.num_hybrid_pmus =0 ; + goto out2; + }I don't think this is quite right. registered will be true even if one fails, while I think you meant to only have it true when all (both) types registered correctly.
No, I mean that perf error out only when all types fail to be registered.
For the case (1 failure, 1 success), users can still access the registered PMU.
When a CPU belongs to the unregistered PMU online, a warning will be displayed. Because in init_hybrid_pmu(), we will check the PMU type before update the CPU mask.
if (WARN_ON_ONCE(!pmu || (pmu->pmu.type == -1))) {
cpuc->pmu = NULL;
return false;
}Thanks,
Kan
Peter Zijlstra
maintainerRe: [PATCH V5 16/25] perf/x86: Register hybrid PMUs
Quoted 54 lines · Kan
Quoted 42 lines · Peter Zijlstra
Quoted 41 lines · On Mon, Apr 05, 2021 at 08:10:58AM -0700, [email protected] wrote:
arch/x86/events/core.c +35
-3@@ -2089,9 +2119,46 @@ static int __init init_hw_perf_events(void)if (err) goto out1; - err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); -if (err) - goto out2; +if (!is_hybrid ()) { + err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); +if (err) + goto out2; + }else { +u8 cpu_type =get_this_hybrid_cpu_type (); +struct x86_hybrid_pmu *hybrid_pmu; +bool registered = false; +int i; + +if (!cpu_type && x86_pmu.get_hybrid_cpu_type) + cpu_type = x86_pmu.get_hybrid_cpu_type (); + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { + hybrid_pmu = &x86_pmu.hybrid_pmu[i]; + + hybrid_pmu->pmu = pmu; + hybrid_pmu->pmu.type =-1 ; + hybrid_pmu->pmu.attr_update = x86_pmu.attr_update; + hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_HETEROGENEOUS_CPUS ; + + err =perf_pmu_register (&hybrid_pmu->pmu, hybrid_pmu->name, + (hybrid_pmu->cpu_type == hybrid_big) ?PERF_TYPE_RAW :-1 ); +if (err) +continue ; + +if (cpu_type == hybrid_pmu->cpu_type) +x86_pmu_update_cpu_context (&hybrid_pmu->pmu,raw_smp_processor_id ()); + + registered = true; + } + +if (!registered) { +pr_warn ("Failed to register hybrid PMUs\n" ); +kfree (x86_pmu.hybrid_pmu);Quoted 8 lines
arch/x86/events/core.c static int __init init_hw_perf_events(void) · line 2160
Quoted 4 lines
arch/x86/events/core.c +4
-0+ x86_pmu.hybrid_pmu =NULL ; + x86_pmu.num_hybrid_pmus =0 ; + goto out2; + }I don't think this is quite right. registered will be true even if one fails, while I think you meant to only have it true when all (both) types registered correctly.
Quoted 1 line
No, I mean that perf error out only when all types fail to be registered.
All or nothing seems a better approach to me. There really isn't a good reason for any one of them to fail.
Re: [PATCH V5 16/25] perf/x86: Register hybrid PMUs
Quoted 55 lines · Peter Zijlstra
Quoted 54 lines · Kan
Quoted 50 lines · Peter Zijlstra
Quoted 35 lines · On Mon, Apr 05, 2021 at 08:10:58AM -0700, [email protected] wrote:
arch/x86/events/core.c +29
-3@@ -2089,9 +2119,46 @@ static int __init init_hw_perf_events(void)if (err) goto out1; - err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); -if (err) - goto out2; +if (!is_hybrid ()) { + err =perf_pmu_register (&pmu,"cpu" ,PERF_TYPE_RAW ); +if (err) + goto out2; + }else { +u8 cpu_type =get_this_hybrid_cpu_type (); +struct x86_hybrid_pmu *hybrid_pmu; +bool registered = false; +int i; + +if (!cpu_type && x86_pmu.get_hybrid_cpu_type) + cpu_type = x86_pmu.get_hybrid_cpu_type (); + +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { + hybrid_pmu = &x86_pmu.hybrid_pmu[i]; + + hybrid_pmu->pmu = pmu; + hybrid_pmu->pmu.type =-1 ; + hybrid_pmu->pmu.attr_update = x86_pmu.attr_update; + hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_HETEROGENEOUS_CPUS ; + + err =perf_pmu_register (&hybrid_pmu->pmu, hybrid_pmu->name, + (hybrid_pmu->cpu_type == hybrid_big) ?PERF_TYPE_RAW :-1 ); +if (err) +continue ; + +if (cpu_type == hybrid_pmu->cpu_type) +x86_pmu_update_cpu_context (&hybrid_pmu->pmu,raw_smp_processor_id ()); +arch/x86/events/core.c static int __init init_hw_perf_events(void) · line 2159
Quoted 10 lines
arch/x86/events/core.c +10
-0+ registered = true; + } + +if (!registered) { +pr_warn ("Failed to register hybrid PMUs\n" ); +kfree (x86_pmu.hybrid_pmu); + x86_pmu.hybrid_pmu =NULL ; + x86_pmu.num_hybrid_pmus =0 ; + goto out2; + }I don't think this is quite right. registered will be true even if one fails, while I think you meant to only have it true when all (both) types registered correctly.
Quoted 5 lines
Quoted 1 line
No, I mean that perf error out only when all types fail to be registered.
All or nothing seems a better approach to me. There really isn't a good reason for any one of them to fail.
Sure. I will change it in V6.
Thanks,
Kan
PATCH v5 17/25 perf/x86: Add structures for the attributes of Hybrid PMUs
In reply to [email protected]From: Kan Liang <[email protected]>
Hybrid PMUs have different events and formats. In theory, Hybrid PMU specific attributes should be maintained in the dedicated struct x86_hybrid_pmu, but it wastes space because the events and formats are similar among Hybrid PMUs.
To reduce duplication, all hybrid PMUs will share a group of attributes in the following patch. To distinguish an attribute from different Hybrid PMUs, a PMU aware attribute structure is introduced. A PMU type is required for the attribute structure. The type is internal usage. It is not visible in the sysfs API.
Hybrid PMUs may support the same event name, but with different event encoding, e.g., the mem-loads event on an Atom PMU has different event encoding from a Core PMU. It brings issue if two attributes are created for them. Current sysfs_update_group finds an attribute by searching the attr name (aka event name). If two attributes have the same event name, the first attribute will be replaced.
To address the issue, only one attribute is created for the event. The event_str is extended and stores event encodings from all Hybrid PMUs. Each event encoding is divided by ";". The order of the event encodings must follow the order of the hybrid PMU index. The event_str is internal usage as well. When a user wants to show the attribute of a Hybrid PMU, only the corresponding part of the string is displayed.
--- arch/x86/events/core.c | 43 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/events/perf_event.h | 19 +++++++++++++++++++ include/linux/perf_event.h | 12 ++++++++++++ 3 files changed, 74 insertions(+)
arch/x86/events/core.c +43 -0
@@ -1868,6 +1868,49 @@ ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr, pmu_attr->event_str_noht); } +ssize_t events_hybrid_sysfs_show (struct device *dev, +struct device_attribute *attr, +char *page) +{ +struct perf_pmu_events_hybrid_attr *pmu_attr = + container_of(attr, struct perf_pmu_events_hybrid_attr, attr); +struct x86_hybrid_pmu *pmu; +const char *str, *next_str; +int i; + +if (hweight64 (pmu_attr->pmu_type) ==1 ) +return sprintf (page,"%s" , pmu_attr->event_str); + +/* +* Hybrid PMUs may support the same event name, but with different +* event encoding, e.g., the mem-loads event on an Atom PMU has +* different event encoding from a Core PMU. +* +* The event_str includes all event encodings. Each event encoding +* is divided by ";". The order of the event encodings must follow +* the order of the hybrid PMU index. +*/ + pmu = container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + + str = pmu_attr->event_str; +for (i =0 ; i < x86_pmu.num_hybrid_pmus; i++) { +if (!(x86_pmu.hybrid_pmu[i].cpu_type & pmu_attr->pmu_type)) +continue ; +if (x86_pmu.hybrid_pmu[i].cpu_type & pmu->cpu_type) { + next_str =strchr (str,';' ); +if (next_str) +return snprintf (page, next_str - str +1 ,"%s" , str); +else +return sprintf (page,"%s" , str); + } + str =strchr (str,';' ); + str++; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (events_hybrid_sysfs_show); +EVENT_ATTR (cpu-cycles,CPU_CYCLES );EVENT_ATTR (instructions,INSTRUCTIONS );EVENT_ATTR (cache-references,CACHE_REFERENCES );
arch/x86/events/perf_event.h +19 -0
@@ -970,6 +970,22 @@ static struct perf_pmu_events_ht_attr event_attr_##v = { \ .event_str_ht = ht, \ } +#define EVENT_ATTR_STR_HYBRID (_name, v, str, _pmu) \ +static struct perf_pmu_events_hybrid_attr event_attr_##v = { \ + .attr = __ATTR(_name, 0444, events_hybrid_sysfs_show, NULL),\ + .id = 0, \ + .event_str = str, \ + .pmu_type = _pmu, \ +} + +#define FORMAT_HYBRID_PTR (_id) (&format_attr_hybrid_##_id.attr.attr) + +#define FORMAT_ATTR_HYBRID (_name, _pmu) \ +static struct perf_pmu_format_hybrid_attr format_attr_hybrid_##_name = {\ + .attr = __ATTR_RO(_name), \ + .pmu_type = _pmu, \ +} +struct pmu *x86_get_pmu (unsigned int cpu);extern struct x86_pmu x86_pmu__read_mostly ;
@@ -1140,6 +1156,9 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page);ssize_t events_ht_sysfs_show (struct device *dev,struct device_attribute *attr,char *page); +ssize_t events_hybrid_sysfs_show (struct device *dev, +struct device_attribute *attr, +char *page);static inline bool fixed_counter_disabled (int i,struct pmu *pmu) {
include/linux/perf_event.h +12 -0
@@ -1548,6 +1548,18 @@ struct perf_pmu_events_ht_attr {const char *event_str_noht; }; +struct perf_pmu_events_hybrid_attr { +struct device_attribute attr; +u64 id; +const char *event_str; +u64 pmu_type; +}; + +struct perf_pmu_format_hybrid_attr { +struct device_attribute attr; +u64 pmu_type; +}; +ssize_t perf_event_sysfs_show (struct device *dev,struct device_attribute *attr,char *page);
Signature · 1 line
2.7.4
PATCH v5 18/25 perf/x86/intel: Add attr_update for Hybrid PMUs
In reply to [email protected]From: Kan Liang <[email protected]>
The attribute_group for Hybrid PMUs should be different from the previous
cpu PMU. For example, cpumask is required for a Hybrid PMU. The PMU type should be included in the event and format attribute.
Add hybrid_attr_update for the Hybrid PMU.
Check the PMU type in is_visible() function. Only display the event or format for the matched Hybrid PMU.
--- arch/x86/events/intel/core.c | 120 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 6 deletions(-)
arch/x86/events/intel/core.c +114 -6
@@ -5124,6 +5124,106 @@ static const struct attribute_group *attr_update[] = { NULL, }; +static bool is_attr_for_this_pmu (struct kobject *kobj,struct attribute *attr) +{ +struct device *dev =kobj_to_dev (kobj); +struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); +struct perf_pmu_events_hybrid_attr *pmu_attr = + container_of(attr, struct perf_pmu_events_hybrid_attr, attr.attr); + +return pmu->cpu_type & pmu_attr->pmu_type; +} + +static umode_t hybrid_events_is_visible (struct kobject *kobj, +struct attribute *attr,int i) +{ +return is_attr_for_this_pmu (kobj, attr) ? attr->mode :0 ; +} + +static inline int hybrid_find_supported_cpu (struct x86_hybrid_pmu *pmu) +{ +int cpu =cpumask_first (&pmu->supported_cpus); + +return (cpu >= nr_cpu_ids) ?-1 : cpu; +} + +static umode_t hybrid_tsx_is_visible (struct kobject *kobj, +struct attribute *attr,int i) +{ +struct device *dev =kobj_to_dev (kobj); +struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); +int cpu =hybrid_find_supported_cpu (pmu); + +return (cpu >=0 ) &&is_attr_for_this_pmu (kobj, attr) &&cpu_has (&cpu_data (cpu),X86_FEATURE_RTM ) ? attr->mode :0 ; +} + +static umode_t hybrid_format_is_visible (struct kobject *kobj, +struct attribute *attr,int i) +{ +struct device *dev =kobj_to_dev (kobj); +struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); +struct perf_pmu_format_hybrid_attr *pmu_attr = + container_of(attr, struct perf_pmu_format_hybrid_attr, attr.attr); +int cpu =hybrid_find_supported_cpu (pmu); + +return (cpu >=0 ) && (pmu->cpu_type & pmu_attr->pmu_type) ? attr->mode :0 ; +} + +static struct attribute_group hybrid_group_events_td = { + .name ="events" , + .is_visible = hybrid_events_is_visible, +}; + +static struct attribute_group hybrid_group_events_mem = { + .name ="events" , + .is_visible = hybrid_events_is_visible, +}; + +static struct attribute_group hybrid_group_events_tsx = { + .name ="events" , + .is_visible = hybrid_tsx_is_visible, +}; + +static struct attribute_group hybrid_group_format_extra = { + .name ="format" , + .is_visible = hybrid_format_is_visible, +}; + +static ssize_t intel_hybrid_get_attr_cpus (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + +return cpumap_print_to_pagebuf (true, buf, &pmu->supported_cpus); +} + +static DEVICE_ATTR(cpus, S_IRUGO, intel_hybrid_get_attr_cpus, NULL); +static struct attribute *intel_hybrid_cpus_attrs[] = { + &dev_attr_cpus.attr, +NULL , +}; + +static struct attribute_group hybrid_group_cpus = { + .attrs = intel_hybrid_cpus_attrs, +}; + +static const struct attribute_group *hybrid_attr_update[] = { + &hybrid_group_events_td, + &hybrid_group_events_mem, + &hybrid_group_events_tsx, + &group_caps_gen, + &group_caps_lbr, + &hybrid_group_format_extra, + &group_default, + &hybrid_group_cpus, +NULL , +}; +static struct attribute *empty_attrs; static void intel_pmu_check_num_counters(int *num_counters,
@@ -5867,14 +5967,22 @@ __init int intel_pmu_init(void)snprintf (pmu_name_str,sizeof (pmu_name_str),"%s" , name); +if (!is_hybrid ()) { + group_events_td.attrs = td_attr; + group_events_mem.attrs = mem_attr; + group_events_tsx.attrs = tsx_attr; + group_format_extra.attrs = extra_attr; + group_format_extra_skl.attrs = extra_skl_attr; - group_events_td.attrs = td_attr; - group_events_mem.attrs = mem_attr; - group_events_tsx.attrs = tsx_attr; - group_format_extra.attrs = extra_attr; - group_format_extra_skl.attrs = extra_skl_attr; + x86_pmu.attr_update = attr_update; + }else { + hybrid_group_events_td.attrs = td_attr; + hybrid_group_events_mem.attrs = mem_attr; + hybrid_group_events_tsx.attrs = tsx_attr; + hybrid_group_format_extra.attrs = extra_attr; - x86_pmu.attr_update = attr_update; + x86_pmu.attr_update = hybrid_attr_update; + } intel_pmu_check_num_counters(&x86_pmu.num_counters, &x86_pmu.num_counters_fixed,
Signature · 1 line
2.7.4
PATCH v5 19/25 perf/x86: Support filter_match callback
In reply to [email protected]From: Kan Liang <[email protected]>
Implement filter_match callback for X86, which check whether an event is schedulable on the current CPU.
--- arch/x86/events/core.c | 10 ++++++++++ arch/x86/events/perf_event.h | 1 + 2 files changed, 11 insertions(+)
arch/x86/events/core.c +10 -0
@@ -2650,6 +2650,14 @@ static int x86_pmu_aux_output_match(struct perf_event *event)return 0 ; } +static int x86_pmu_filter_match (struct perf_event *event) +{ +if (x86_pmu.filter_match) +return x86_pmu.filter_match (event); + +return 1 ; +} +static struct pmu pmu = { .pmu_enable = x86_pmu_enable, .pmu_disable = x86_pmu_disable,
@@ -2677,6 +2685,8 @@ static struct pmu pmu = { .check_period = x86_pmu_check_period, .aux_output_match = x86_pmu_aux_output_match, + + .filter_match = x86_pmu_filter_match, }; void arch_perf_update_userpage(struct perf_event *event,
arch/x86/events/perf_event.h +1 -0
@@ -870,6 +870,7 @@ struct x86_pmu {int (*aux_output_match) (struct perf_event *event); +int (*filter_match)(struct perf_event *event);/* * Hybrid support *
Signature · 1 line
2.7.4
PATCH v5 20/25 perf/x86/intel: Add Alder Lake Hybrid support
In reply to [email protected]From: Kan Liang <[email protected]>
Alder Lake Hybrid system has two different types of core, Golden Cove core and Gracemont core. The Golden Cove core is registered to "cpu_core" PMU. The Gracemont core is registered to "cpu_atom" PMU.
The difference between the two PMUs include:
- Number of GP and fixed counters
- Events
- The "cpu_core" PMU supports Topdown metrics.
The "cpu_atom" PMU supports PEBS-via-PT.
The "cpu_core" PMU is similar to the Sapphire Rapids PMU, but without PMEM.
The "cpu_atom" PMU is similar to Tremont, but with different events, event_constraints, extra_regs and number of counters.
The mem-loads AUX event workaround only applies to the Golden Cove core.
Users may disable all CPUs of the same CPU type on the command line or in the BIOS. For this case, perf still register a PMU for the CPU type but the CPU mask is 0.
Current caps/pmu_name is usually the microarch codename. Assign the "alderlake_hybrid" to the caps/pmu_name of both PMUs to indicate the hybrid Alder Lake microarchitecture.
--- arch/x86/events/intel/core.c | 254 ++++++++++++++++++++++++++++++++++++++++++- arch/x86/events/intel/ds.c | 7 ++ arch/x86/events/perf_event.h | 7 ++ 3 files changed, 267 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +253 -1
@@ -2076,6 +2076,14 @@ static struct extra_reg intel_tnt_extra_regs[] __read_mostly = { EVENT_EXTRA_END }; +static struct extra_reg intel_grt_extra_regs[]__read_mostly = { +/* must define OFFCORE_RSP_X first, see intel_fixup_er() */ +INTEL_UEVENT_EXTRA_REG (0x01b7 ,MSR_OFFCORE_RSP_0 ,0x3fffffffffull ,RSP_0 ), +INTEL_UEVENT_EXTRA_REG (0x02b7 ,MSR_OFFCORE_RSP_1 ,0x3fffffffffull ,RSP_1 ), +INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG (0x5d0 ), +EVENT_EXTRA_END +}; +#define KNL_OT_L2_HITE BIT_ULL(19)/* Other Tile L2 Hit */ #define KNL_OT_L2_HITF BIT_ULL(20)/* Other Tile L2 Hit */ #define KNL_MCDRAM_LOCAL BIT_ULL(21)
@@ -2430,6 +2438,16 @@ static int icl_set_topdown_event_period(struct perf_event *event)return 0 ; } +static int adl_set_topdown_event_period (struct perf_event *event) +{ +struct x86_hybrid_pmu *pmu =hybrid_pmu (event->pmu); + +if (pmu->cpu_type != hybrid_big) +return 0 ; + +return icl_set_topdown_event_period (event); +} +static inline u64 icl_get_metrics_event_value (u64 metric,u64 slots,int idx) {u32 val;
@@ -2570,6 +2588,17 @@ static u64 icl_update_topdown_event(struct perf_event *event) x86_pmu.num_topdown_events - 1); } +static u64 adl_update_topdown_event (struct perf_event *event) +{ +struct x86_hybrid_pmu *pmu =hybrid_pmu (event->pmu); + +if (pmu->cpu_type != hybrid_big) +return 0 ; + +return icl_update_topdown_event (event); +} + +static void intel_pmu_read_topdown_event (struct perf_event *event) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);
@@ -3658,6 +3687,17 @@ static inline bool is_mem_loads_aux_event(struct perf_event *event) return (event->attr.config & INTEL_ARCH_EVENT_MASK) == X86_CONFIG(.event=0x03, .umask=0x82); } +static inline bool require_mem_loads_aux_event (struct perf_event *event) +{ +if (!(x86_pmu.flags &PMU_FL_MEM_LOADS_AUX )) +return false; + +if (is_hybrid ()) +return hybrid_pmu (event->pmu)->cpu_type == hybrid_big; + +return true; +} +static inline bool intel_pmu_has_cap (struct perf_event *event,int idx) {union perf_capabilities *intel_cap;
@@ -3785,7 +3825,7 @@ static int intel_pmu_hw_config(struct perf_event *event)* event. The rule is to simplify the implementation of the check. * That's because perf cannot have a complete group at the moment. */ -if (x86_pmu.flags &PMU_FL_MEM_LOADS_AUX && +if (require_mem_loads_aux_event (event) && (event->attr.sample_type &PERF_SAMPLE_DATA_SRC ) &&is_mem_loads_event (event)) {struct perf_event *leader = event->group_leader;
@@ -4062,6 +4102,39 @@ tfa_get_event_constraints(struct cpu_hw_events *cpuc, int idx,return c; } +static struct event_constraint * +adl_get_event_constraints (struct cpu_hw_events *cpuc,int idx, +struct perf_event *event) +{ +struct x86_hybrid_pmu *pmu =hybrid_pmu (event->pmu); + +if (pmu->cpu_type == hybrid_big) +return spr_get_event_constraints (cpuc, idx, event); +else if (pmu->cpu_type == hybrid_small) +return tnt_get_event_constraints (cpuc, idx, event); + +WARN_ON (1 ); +return &emptyconstraint; +} + +static int adl_hw_config (struct perf_event *event) +{ +struct x86_hybrid_pmu *pmu =hybrid_pmu (event->pmu); + +if (pmu->cpu_type == hybrid_big) +return hsw_hw_config (event); +else if (pmu->cpu_type == hybrid_small) +return intel_pmu_hw_config (event); + +WARN_ON (1 ); +return -EOPNOTSUPP ; +} + +static u8 adl_get_hybrid_cpu_type (void ) +{ +return hybrid_big; +} +/* * Broadwell: *
@@ -4422,6 +4495,14 @@ static int intel_pmu_aux_output_match(struct perf_event *event)return is_intel_pt_event (event); } +static int intel_pmu_filter_match (struct perf_event *event) +{ +struct x86_hybrid_pmu *pmu =hybrid_pmu (event->pmu); +unsigned int cpu =smp_processor_id (); + +return cpumask_test_cpu (cpu, &pmu->supported_cpus); +} +PMU_FORMAT_ATTR (offcore_rsp,"config1:0-63" );PMU_FORMAT_ATTR (ldlat,"config1:0-15" );
@@ -5124,6 +5205,84 @@ static const struct attribute_group *attr_update[] = {NULL , }; +EVENT_ATTR_STR_HYBRID (slots, slots_adl,"event=0x00,umask=0x4" , hybrid_big); +EVENT_ATTR_STR_HYBRID (topdown-retiring, td_retiring_adl,"event=0xc2,umask=0x0;event=0x00,umask=0x80" , hybrid_big_small); +EVENT_ATTR_STR_HYBRID (topdown-bad-spec, td_bad_spec_adl,"event=0x73,umask=0x0;event=0x00,umask=0x81" , hybrid_big_small); +EVENT_ATTR_STR_HYBRID (topdown-fe-bound, td_fe_bound_adl,"event=0x71,umask=0x0;event=0x00,umask=0x82" , hybrid_big_small); +EVENT_ATTR_STR_HYBRID (topdown-be-bound, td_be_bound_adl,"event=0x74,umask=0x0;event=0x00,umask=0x83" , hybrid_big_small); +EVENT_ATTR_STR_HYBRID (topdown-heavy-ops, td_heavy_ops_adl,"event=0x00,umask=0x84" , hybrid_big); +EVENT_ATTR_STR_HYBRID (topdown-br-mispredict, td_br_mis_adl,"event=0x00,umask=0x85" , hybrid_big); +EVENT_ATTR_STR_HYBRID (topdown-fetch-lat, td_fetch_lat_adl,"event=0x00,umask=0x86" , hybrid_big); +EVENT_ATTR_STR_HYBRID (topdown-mem-bound, td_mem_bound_adl,"event=0x00,umask=0x87" , hybrid_big); + +static struct attribute *adl_hybrid_events_attrs[] = { +EVENT_PTR (slots_adl), +EVENT_PTR (td_retiring_adl), +EVENT_PTR (td_bad_spec_adl), +EVENT_PTR (td_fe_bound_adl), +EVENT_PTR (td_be_bound_adl), +EVENT_PTR (td_heavy_ops_adl), +EVENT_PTR (td_br_mis_adl), +EVENT_PTR (td_fetch_lat_adl), +EVENT_PTR (td_mem_bound_adl), +NULL , +}; + +/* Must be in IDX order */ +EVENT_ATTR_STR_HYBRID (mem-loads, mem_ld_adl,"event=0xd0,umask=0x5,ldlat=3;event=0xcd,umask=0x1,ldlat=3" , hybrid_big_small); +EVENT_ATTR_STR_HYBRID (mem-stores, mem_st_adl,"event=0xd0,umask=0x6;event=0xcd,umask=0x2" , hybrid_big_small); +EVENT_ATTR_STR_HYBRID (mem-loads-aux, mem_ld_aux_adl,"event=0x03,umask=0x82" , hybrid_big); + +static struct attribute *adl_hybrid_mem_attrs[] = { +EVENT_PTR (mem_ld_adl), +EVENT_PTR (mem_st_adl), +EVENT_PTR (mem_ld_aux_adl), +NULL , +}; + +EVENT_ATTR_STR_HYBRID (tx-start, tx_start_adl,"event=0xc9,umask=0x1" , hybrid_big); +EVENT_ATTR_STR_HYBRID (tx-commit, tx_commit_adl,"event=0xc9,umask=0x2" , hybrid_big); +EVENT_ATTR_STR_HYBRID (tx-abort, tx_abort_adl,"event=0xc9,umask=0x4" , hybrid_big); +EVENT_ATTR_STR_HYBRID (tx-conflict, tx_conflict_adl,"event=0x54,umask=0x1" , hybrid_big); +EVENT_ATTR_STR_HYBRID (cycles-t, cycles_t_adl,"event=0x3c,in_tx=1" , hybrid_big); +EVENT_ATTR_STR_HYBRID (cycles-ct, cycles_ct_adl,"event=0x3c,in_tx=1,in_tx_cp=1" , hybrid_big); +EVENT_ATTR_STR_HYBRID (tx-capacity-read, tx_capacity_read_adl,"event=0x54,umask=0x80" , hybrid_big); +EVENT_ATTR_STR_HYBRID (tx-capacity-write, tx_capacity_write_adl,"event=0x54,umask=0x2" , hybrid_big); + +static struct attribute *adl_hybrid_tsx_attrs[] = { +EVENT_PTR (tx_start_adl), +EVENT_PTR (tx_abort_adl), +EVENT_PTR (tx_commit_adl), +EVENT_PTR (tx_capacity_read_adl), +EVENT_PTR (tx_capacity_write_adl), +EVENT_PTR (tx_conflict_adl), +EVENT_PTR (cycles_t_adl), +EVENT_PTR (cycles_ct_adl), +NULL , +}; + +FORMAT_ATTR_HYBRID (in_tx, hybrid_big); +FORMAT_ATTR_HYBRID (in_tx_cp, hybrid_big); +FORMAT_ATTR_HYBRID (offcore_rsp, hybrid_big_small); +FORMAT_ATTR_HYBRID (ldlat, hybrid_big_small); +FORMAT_ATTR_HYBRID (frontend, hybrid_big); + +static struct attribute *adl_hybrid_extra_attr_rtm[] = { +FORMAT_HYBRID_PTR (in_tx), +FORMAT_HYBRID_PTR (in_tx_cp), +FORMAT_HYBRID_PTR (offcore_rsp), +FORMAT_HYBRID_PTR (ldlat), +FORMAT_HYBRID_PTR (frontend), +NULL , +}; + +static struct attribute *adl_hybrid_extra_attr[] = { +FORMAT_HYBRID_PTR (offcore_rsp), +FORMAT_HYBRID_PTR (ldlat), +FORMAT_HYBRID_PTR (frontend), +NULL , +}; +static bool is_attr_for_this_pmu (struct kobject *kobj,struct attribute *attr) {struct device *dev =kobj_to_dev (kobj);
@@ -5353,6 +5512,7 @@ __init int intel_pmu_init(void)bool pmem = false;int version, i;char *name; +struct x86_hybrid_pmu *pmu;if (!cpu_has (&boot_cpu_data,X86_FEATURE_ARCH_PERFMON )) {switch (boot_cpu_data.x86) {
@@ -5947,6 +6107,98 @@ __init int intel_pmu_init(void) name ="sapphire_rapids" ;break ; +case INTEL_FAM6_ALDERLAKE : +case INTEL_FAM6_ALDERLAKE_L : +/* +* Alder Lake has 2 types of CPU, core and atom. +* +* Initialize the common PerfMon capabilities here. +*/ + x86_pmu.hybrid_pmu =kcalloc (X86_HYBRID_NUM_PMUS , +sizeof (struct x86_hybrid_pmu ), +GFP_KERNEL ); +if (!x86_pmu.hybrid_pmu) +return -ENOMEM ; + x86_pmu.num_hybrid_pmus =X86_HYBRID_NUM_PMUS ; + + x86_pmu.late_ack = true; + x86_pmu.pebs_aliases =NULL ; + x86_pmu.pebs_prec_dist = true; + x86_pmu.pebs_block = true; + x86_pmu.flags |=PMU_FL_HAS_RSP_1 ; + x86_pmu.flags |=PMU_FL_NO_HT_SHARING ; + x86_pmu.flags |=PMU_FL_PEBS_ALL ; + x86_pmu.flags |=PMU_FL_INSTR_LATENCY ; + x86_pmu.flags |=PMU_FL_MEM_LOADS_AUX ; + x86_pmu.lbr_pt_coexist = true; +intel_pmu_pebs_data_source_skl (false); + x86_pmu.num_topdown_events =8 ; + x86_pmu.update_topdown_event = adl_update_topdown_event; + x86_pmu.set_topdown_event_period = adl_set_topdown_event_period; + + x86_pmu.filter_match = intel_pmu_filter_match; + x86_pmu.get_event_constraints = adl_get_event_constraints; + x86_pmu.hw_config = adl_hw_config; + x86_pmu.limit_period = spr_limit_period; + x86_pmu.get_hybrid_cpu_type = adl_get_hybrid_cpu_type; +/* +* The rtm_abort_event is used to check whether to enable GPRs +* for the RTM abort event. Atom doesn't have the RTM abort +* event. There is no harmful to set it in the common +* x86_pmu.rtm_abort_event. +*/ + x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xc9, .umask=0x04); + + td_attr = adl_hybrid_events_attrs; + mem_attr = adl_hybrid_mem_attrs; + tsx_attr = adl_hybrid_tsx_attrs; + extra_attr =boot_cpu_has (X86_FEATURE_RTM ) ? + adl_hybrid_extra_attr_rtm : adl_hybrid_extra_attr; + +/* Initialize big core specific PerfMon capabilities.*/ + pmu = &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX ]; + pmu->name ="cpu_core" ; + pmu->cpu_type = hybrid_big; + pmu->num_counters = x86_pmu.num_counters +2 ; + pmu->num_counters_fixed = x86_pmu.num_counters_fixed +1 ; + pmu->max_pebs_events =min_t (unsigned,MAX_PEBS_EVENTS , pmu->num_counters); + pmu->unconstrained = (struct event_constraint ) +__EVENT_CONSTRAINT (0 , (1ULL << pmu->num_counters) -1 , +0 , pmu->num_counters,0 ,0 ); + pmu->intel_cap.capabilities = x86_pmu.intel_cap.capabilities; + pmu->intel_cap.perf_metrics =1 ; + pmu->intel_cap.pebs_output_pt_available =0 ; + +memcpy (pmu->hw_cache_event_ids, spr_hw_cache_event_ids,sizeof (pmu->hw_cache_event_ids)); +memcpy (pmu->hw_cache_extra_regs, spr_hw_cache_extra_regs,sizeof (pmu->hw_cache_extra_regs)); + pmu->event_constraints = intel_spr_event_constraints; + pmu->pebs_constraints = intel_spr_pebs_event_constraints; + pmu->extra_regs = intel_spr_extra_regs; + +/* Initialize Atom core specific PerfMon capabilities.*/ + pmu = &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_ATOM_IDX ]; + pmu->name ="cpu_atom" ; + pmu->cpu_type = hybrid_small; + pmu->num_counters = x86_pmu.num_counters; + pmu->num_counters_fixed = x86_pmu.num_counters_fixed; + pmu->max_pebs_events = x86_pmu.max_pebs_events; + pmu->unconstrained = (struct event_constraint ) +__EVENT_CONSTRAINT (0 , (1ULL << pmu->num_counters) -1 , +0 , pmu->num_counters,0 ,0 ); + pmu->intel_cap.capabilities = x86_pmu.intel_cap.capabilities; + pmu->intel_cap.perf_metrics =0 ; + pmu->intel_cap.pebs_output_pt_available =1 ; + +memcpy (pmu->hw_cache_event_ids, glp_hw_cache_event_ids,sizeof (pmu->hw_cache_event_ids)); +memcpy (pmu->hw_cache_extra_regs, tnt_hw_cache_extra_regs,sizeof (pmu->hw_cache_extra_regs)); + pmu->hw_cache_event_ids[C (ITLB )][C (OP_READ )][C (RESULT_ACCESS )] =-1 ; + pmu->event_constraints = intel_slm_event_constraints; + pmu->pebs_constraints = intel_grt_pebs_event_constraints; + pmu->extra_regs = intel_grt_extra_regs; +pr_cont ("Alderlake Hybrid events, " ); + name ="alderlake_hybrid" ; +break ; +default :switch (x86_pmu.version) {case 1 :
arch/x86/events/intel/ds.c +7 -0
@@ -779,6 +779,13 @@ struct event_constraint intel_glm_pebs_event_constraints[] = {EVENT_CONSTRAINT_END }; +struct event_constraint intel_grt_pebs_event_constraints[] = { +/* Allow all events as PEBS with no flags */ +INTEL_PLD_CONSTRAINT (0x5d0 ,0xf ), +INTEL_PSD_CONSTRAINT (0x6d0 ,0xf ), +EVENT_CONSTRAINT_END +}; +struct event_constraint intel_nehalem_pebs_event_constraints[] = {INTEL_PLD_CONSTRAINT (0x100b ,0xf ),/* MEM_INST_RETIRED.* */ INTEL_FLAGS_EVENT_CONSTRAINT (0x0f ,0xf ),/* MEM_UNCORE_RETIRED.* */
arch/x86/events/perf_event.h +7 -0
@@ -683,6 +683,11 @@ enum hybrid_pmu_type { hybrid_big_small = hybrid_big | hybrid_small, }; +#define X86_HYBRID_PMU_ATOM_IDX 0 +#define X86_HYBRID_PMU_CORE_IDX 1 + +#define X86_HYBRID_NUM_PMUS 2 +/* * struct x86_pmu - generic x86 pmu */
@@ -1249,6 +1254,8 @@ extern struct event_constraint intel_glm_pebs_event_constraints[];extern struct event_constraint intel_glp_pebs_event_constraints[]; +extern struct event_constraint intel_grt_pebs_event_constraints[]; +extern struct event_constraint intel_nehalem_pebs_event_constraints[];extern struct event_constraint intel_westmere_pebs_event_constraints[];
Signature · 1 line
2.7.4
PATCH v5 21/25 perf: Introduce PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU
In reply to [email protected]From: Kan Liang <[email protected]>
Current Hardware events and Hardware cache events have special perf types, PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE. The two types don't pass the PMU type in the user interface. For a hybrid system, the perf subsystem doesn't know which PMU the events belong to. The first capable PMU will always be assigned to the events. The events never get a chance to run on the other capable PMUs.
Add a PMU aware version PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU. The PMU type ID is stored at attr.config[40:32]. Support the new types for X86.
--- arch/x86/events/core.c | 10 ++++++++-- include/uapi/linux/perf_event.h | 26 ++++++++++++++++++++++++++ kernel/events/core.c | 14 +++++++++++++- 3 files changed, 47 insertions(+), 3 deletions(-)
arch/x86/events/core.c +8 -2
@@ -488,7 +488,7 @@ int x86_setup_perfctr(struct perf_event *event)if (attr->type == event->pmu->type)return x86_pmu_extra_regs (event->attr.config, event); -if (attr->type ==PERF_TYPE_HW_CACHE ) +if ((attr->type ==PERF_TYPE_HW_CACHE ) || (attr->type ==PERF_TYPE_HW_CACHE_PMU ))return set_ext_hw_attr (hwc, event);if (attr->config >= x86_pmu.max_events)
@@ -2452,9 +2452,15 @@ static int x86_pmu_event_init(struct perf_event *event)if ((event->attr.type != event->pmu->type) && (event->attr.type !=PERF_TYPE_HARDWARE ) && - (event->attr.type !=PERF_TYPE_HW_CACHE )) + (event->attr.type !=PERF_TYPE_HW_CACHE ) && + (event->attr.type !=PERF_TYPE_HARDWARE_PMU ) && + (event->attr.type !=PERF_TYPE_HW_CACHE_PMU ))return -ENOENT ; +if ((event->attr.type ==PERF_TYPE_HARDWARE_PMU ) || + (event->attr.type ==PERF_TYPE_HW_CACHE_PMU )) + event->attr.config &=PERF_HW_CACHE_EVENT_MASK ; +if (is_hybrid () && (event->cpu !=-1 )) { pmu =hybrid_pmu (event->pmu);if (!cpumask_test_cpu (event->cpu, &pmu->supported_cpus))
include/uapi/linux/perf_event.h +26 -0
@@ -33,6 +33,8 @@ enum perf_type_id {PERF_TYPE_HW_CACHE =3 ,PERF_TYPE_RAW =4 ,PERF_TYPE_BREAKPOINT =5 , +PERF_TYPE_HARDWARE_PMU =6 , +PERF_TYPE_HW_CACHE_PMU =7 , PERF_TYPE_MAX, /* non-ABI */ };
@@ -95,6 +97,30 @@ enum perf_hw_cache_op_result_id { };/* +* attr.config layout for type PERF_TYPE_HARDWARE* and PERF_TYPE_HW_CACHE* +* PERF_TYPE_HARDWARE: 0xAA +* AA: hardware event ID +* PERF_TYPE_HW_CACHE: 0xCCBBAA +* AA: hardware cache ID +* BB: hardware cache op ID +* CC: hardware cache op result ID +* PERF_TYPE_HARDWARE_PMU: 0xDD000000AA +* AA: hardware event ID +* DD: PMU type ID +* PERF_TYPE_HW_CACHE_PMU: 0xDD00CCBBAA +* AA: hardware cache ID +* BB: hardware cache op ID +* CC: hardware cache op result ID +* DD: PMU type ID +*/ +#define PERF_HW_CACHE_ID_SHIFT 0 +#define PERF_HW_CACHE_OP_ID_SHIFT 8 +#define PERF_HW_CACHE_OP_RESULT_ID_SHIFT 16 +#define PERF_HW_CACHE_EVENT_MASK 0xffffff + +#define PERF_PMU_TYPE_SHIFT 32 + +/* * Special "software" events provided by the kernel, even if the hardware * does not support performance events. These events measure various * physical and sw events of the kernel (and allow the profiling of them as
kernel/events/core.c +13 -1
@@ -11093,6 +11093,14 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)return ret; } +static bool perf_event_is_hw_pmu_type (struct perf_event *event) +{ +int type = event->attr.type; + +return type ==PERF_TYPE_HARDWARE_PMU || + type ==PERF_TYPE_HW_CACHE_PMU ; +} +static struct pmu *perf_init_event (struct perf_event *event) {int idx, type, ret;
@@ -11116,13 +11124,17 @@ static struct pmu *perf_init_event(struct perf_event *event)if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) type =PERF_TYPE_RAW ; +if (perf_event_is_hw_pmu_type (event)) + type = event->attr.config >>PERF_PMU_TYPE_SHIFT ; + again:rcu_read_lock (); pmu =idr_find (&pmu_idr, type);rcu_read_unlock ();if (pmu) { ret =perf_try_init_event (pmu, event); -if (ret == -ENOENT && event->attr.type != type) { +if (ret == -ENOENT && event->attr.type != type && + !perf_event_is_hw_pmu_type (event)) { type = event->attr.type; goto again; }
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerRe: [PATCH V5 21/25] perf: Introduce PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU
Quoted 9 lines · On Mon, Apr 05, 2021 at 08:11:03AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
Current Hardware events and Hardware cache events have special perf types,
PERF_TYPE_HARDWAREandPERF_TYPE_HW_CACHE. The two types don't pass the PMU type in the user interface. For a hybrid system, the perf subsystem doesn't know which PMU the events belong to. The first capable PMU will always be assigned to the events. The events never get a chance to run on the other capable PMUs.
Quoted 3 lines
Add a PMU aware version
PERF_TYPE_HARDWARE_PMUandPERF_TYPE_HW_CACHE_PMU. The PMU type ID is stored at attr.config[40:32]. Support the new types for X86.
Obviously ARM would need the same, but also, I don't think I see the need to introduce new types. AFAICT there is nothing that stops this scheme from working for the existing types.
Also, pmu type is 32bit, not 8bit.
So how about something like this?
---
include/linux/perf_event.h +10 -9
@@ -260,15 +260,16 @@ struct perf_event;/** * pmu::capabilities flags */ -#define PERF_PMU_CAP_NO_INTERRUPT 0x01 -#define PERF_PMU_CAP_NO_NMI 0x02 -#define PERF_PMU_CAP_AUX_NO_SG 0x04 -#define PERF_PMU_CAP_EXTENDED_REGS 0x08 -#define PERF_PMU_CAP_EXCLUSIVE 0x10 -#define PERF_PMU_CAP_ITRACE 0x20 -#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40 -#define PERF_PMU_CAP_NO_EXCLUDE 0x80 -#define PERF_PMU_CAP_AUX_OUTPUT 0x100 +#define PERF_PMU_CAP_NO_INTERRUPT 0x0001 +#define PERF_PMU_CAP_NO_NMI 0x0002 +#define PERF_PMU_CAP_AUX_NO_SG 0x0004 +#define PERF_PMU_CAP_EXTENDED_REGS 0x0008 +#define PERF_PMU_CAP_EXCLUSIVE 0x0010 +#define PERF_PMU_CAP_ITRACE 0x0020 +#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x0040 +#define PERF_PMU_CAP_NO_EXCLUDE 0x0080 +#define PERF_PMU_CAP_AUX_OUTPUT 0x0100 +#define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x0200struct perf_output_handle ;
kernel/events/core.c +10 -2
@@ -11113,14 +11113,21 @@ static struct pmu *perf_init_event(struct perf_event *event)* are often aliases for PERF_TYPE_RAW. */ type = event->attr.type; -if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) - type =PERF_TYPE_RAW ; +if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) { + type = event->attr.config >>32 ; +if (!type) + type =PERF_TYPE_RAW ; + } again:rcu_read_lock (); pmu =idr_find (&pmu_idr, type);rcu_read_unlock ();if (pmu) { +if (event->attr.type != type && type !=PERF_TYPE_RAW && + !(pmu->capabilities &PERF_PMU_CAP_EXTENDED_HW_TYPE )) + goto fail; + ret =perf_try_init_event (pmu, event);if (ret == -ENOENT && event->attr.type != type) { type = event->attr.type;
@@ -11143,6 +11150,7 @@ static struct pmu *perf_init_event(struct perf_event *event) goto unlock; } } +fail: pmu =ERR_PTR (-ENOENT ); unlock:srcu_read_unlock (&pmus_srcu, idx);
Re: [PATCH V5 21/25] perf: Introduce PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU
Quoted 58 lines · Peter Zijlstra
Quoted 9 lines · On Mon, Apr 05, 2021 at 08:11:03AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
Current Hardware events and Hardware cache events have special perf types,
PERF_TYPE_HARDWAREandPERF_TYPE_HW_CACHE. The two types don't pass the PMU type in the user interface. For a hybrid system, the perf subsystem doesn't know which PMU the events belong to. The first capable PMU will always be assigned to the events. The events never get a chance to run on the other capable PMUs.Quoted 3 lines
Add a PMU aware version
PERF_TYPE_HARDWARE_PMUandPERF_TYPE_HW_CACHE_PMU. The PMU type ID is stored at attr.config[40:32]. Support the new types for X86.Obviously ARM would need the same, but also, I don't think I see the need to introduce new types. AFAICT there is nothing that stops this scheme from working for the existing types.
Also, pmu type is 32bit, not 8bit.
So how about something like this?
---
include/linux/perf_event.h +10
-9@@ -260,15 +260,16 @@ struct perf_event;/** * pmu::capabilities flags */ -#define PERF_PMU_CAP_NO_INTERRUPT 0x01 -#define PERF_PMU_CAP_NO_NMI 0x02 -#define PERF_PMU_CAP_AUX_NO_SG 0x04 -#define PERF_PMU_CAP_EXTENDED_REGS 0x08 -#define PERF_PMU_CAP_EXCLUSIVE 0x10 -#define PERF_PMU_CAP_ITRACE 0x20 -#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40 -#define PERF_PMU_CAP_NO_EXCLUDE 0x80 -#define PERF_PMU_CAP_AUX_OUTPUT 0x100 +#define PERF_PMU_CAP_NO_INTERRUPT 0x0001 +#define PERF_PMU_CAP_NO_NMI 0x0002 +#define PERF_PMU_CAP_AUX_NO_SG 0x0004 +#define PERF_PMU_CAP_EXTENDED_REGS 0x0008 +#define PERF_PMU_CAP_EXCLUSIVE 0x0010 +#define PERF_PMU_CAP_ITRACE 0x0020 +#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x0040 +#define PERF_PMU_CAP_NO_EXCLUDE 0x0080 +#define PERF_PMU_CAP_AUX_OUTPUT 0x0100 +#define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x0200struct perf_output_handle ;kernel/events/core.c +0
-0
kernel/events/core.c static struct pmu *perf_init_event(struct perf_event *event) · line 11120
Quoted 10 lines
kernel/events/core.c +5
-2@@ -11113,14 +11113,21 @@ static struct pmu *perf_init_event(struct perf_event *event)* are often aliases for PERF_TYPE_RAW. */ type = event->attr.type; -if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) - type =PERF_TYPE_RAW ; +if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) { + type = event->attr.config >>32 ; +if (!type) + type =PERF_TYPE_RAW ; + }
For the old tool, the default PMU will be the big core. I think it's OK for X86.
Since only the low 32 bit of event->attr.config contains the 'real' config value, I think all the ARCHs will do event->attr.config &= 0xffffffff. Maybe we should move it to the generic code.
+ if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) {
+ type = event->attr.config >> 32;
+ if (!type)
+ type = PERF_TYPE_RAW;
+ else
+ event->attr.config &= 0xffffffff;
kernel/events/core.c
Quoted 12 lines
Quoted 1 line
again:
rcu_read_lock();
pmu =idr_find(&pmu_idr, type);
rcu_read_unlock();
if (pmu) {kernel/events/core.c +4
-0+if (event->attr.type != type && type !=PERF_TYPE_RAW && + !(pmu->capabilities &PERF_PMU_CAP_EXTENDED_HW_TYPE )) + goto fail; + ret =perf_try_init_event (pmu, event);if (ret == -ENOENT && event->attr.type != type) { type = event->attr.type;
I don't think we want to go through all available PMUs again if users already specify a PMU.
I update the patch a little bit. (Not test yet. I will do some tests then.)
arch/x86/events/core.c +1 -0
@@ -2175,6 +2175,7 @@ static int __init init_hw_perf_events(void) hybrid_pmu->pmu.type =-1 ; hybrid_pmu->pmu.attr_update = x86_pmu.attr_update; hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_HETEROGENEOUS_CPUS ; + hybrid_pmu->pmu.capabilities |=PERF_PMU_CAP_EXTENDED_HW_TYPE ; err =perf_pmu_register (&hybrid_pmu->pmu, hybrid_pmu->name, (hybrid_pmu->cpu_type == hybrid_big) ?PERF_TYPE_RAW :-1 );
include/linux/perf_event.h +1 -0
@@ -269,6 +269,7 @@ struct perf_event;#define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40#define PERF_PMU_CAP_NO_EXCLUDE 0x80#define PERF_PMU_CAP_AUX_OUTPUT 0x100 +#define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x200struct perf_output_handle ;
include/uapi/linux/perf_event.h +14 -0
@@ -38,6 +38,20 @@ enum perf_type_id { };/* +* attr.config layout for type PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE +* PERF_TYPE_HARDWARE: 0xEE000000AA +* AA: hardware event ID +* EE: PMU type ID +* PERF_TYPE_HW_CACHE: 0xEE00DDCCBB +* BB: hardware cache ID +* CC: hardware cache op ID +* DD: hardware cache op result ID +* EE: PMU type ID +* If the PMU type ID is 0, the PERF_TYPE_RAW will be applied. +*/ +#define PERF_HW_EVENT_MASK 0xffffffff + +/* * Generalized performance event event_id types, used by the * attr.event_id parameter of the sys_perf_event_open() * syscall:
kernel/events/core.c +15 -3
@@ -11093,6 +11093,8 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)return ret; } +#define PERF_EXTENDED_HW_TYPE (event->attr.config >> 32) +static struct pmu *perf_init_event (struct perf_event *event) {int idx, type, ret;
@@ -11113,16 +11115,25 @@ static struct pmu *perf_init_event(struct perf_event *event)* are often aliases for PERF_TYPE_RAW. */ type = event->attr.type; -if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) - type =PERF_TYPE_RAW ; +if (type ==PERF_TYPE_HARDWARE || type ==PERF_TYPE_HW_CACHE ) { + type =PERF_EXTENDED_HW_TYPE ; +if (!type) + type =PERF_TYPE_RAW ; +else + event->attr.config &=PERF_HW_EVENT_MASK ; + } again:rcu_read_lock (); pmu =idr_find (&pmu_idr, type);rcu_read_unlock ();if (pmu) { +if (event->attr.type != type && type !=PERF_TYPE_RAW && + !(pmu->capabilities &PERF_PMU_CAP_EXTENDED_HW_TYPE )) + goto fail; + ret =perf_try_init_event (pmu, event); -if (ret == -ENOENT && event->attr.type != type) { +if (ret == -ENOENT && event->attr.type != type && !PERF_EXTENDED_HW_TYPE ) { type = event->attr.type; goto again; }
@@ -11143,6 +11154,7 @@ static struct pmu *perf_init_event(struct perf_event *event) goto unlock; } } +fail: pmu =ERR_PTR (-ENOENT ); unlock:srcu_read_unlock (&pmus_srcu, idx);
Thanks,
Kan
Peter Zijlstra
maintainerRe: [PATCH V5 21/25] perf: Introduce PERF_TYPE_HARDWARE_PMU and PERF_TYPE_HW_CACHE_PMU
Quoted 8 lines · Kan
include/uapi/linux/perf_event.h +0
-0@@ -38,6 +38,20 @@ enum perf_type_id { };
include/uapi/linux/perf_event.h enum perf_type_id { · line 49
Quoted 10 lines
include/uapi/linux/perf_event.h +9
-0/* +* attr.config layout for type PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE +* PERF_TYPE_HARDWARE: 0xEE000000AA +* AA: hardware event ID +* EE: PMU type ID +* PERF_TYPE_HW_CACHE: 0xEE00DDCCBB +* BB: hardware cache ID +* CC: hardware cache op ID +* DD: hardware cache op result ID +* EE: PMU type ID
it's: 0xEEEEEEEE00DDCCBB and 0xEEEEEEEE000000AA
PATCH v5 22/25 perf/x86/intel/uncore: Add Alder Lake support
In reply to [email protected]From: Kan Liang <[email protected]>
The uncore subsystem for Alder Lake is similar to the previous Tiger Lake.
The difference includes:
- New MSR addresses for global control, fixed counters, CBOX and ARB. Add a new adl_uncore_msr_ops for uncore operations.
- Add a new threshold field for CBOX.
- New PCIIDs for IMC devices.
--- arch/x86/events/intel/uncore.c | 7 ++ arch/x86/events/intel/uncore.h | 1 + arch/x86/events/intel/uncore_snb.c | 131 +++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+)
arch/x86/events/intel/uncore.c +7 -0
@@ -1740,6 +1740,11 @@ static const struct intel_uncore_init_fun rkl_uncore_init __initconst = { .pci_init = skl_uncore_pci_init, }; +static const struct intel_uncore_init_fun adl_uncore_init__initconst = { + .cpu_init = adl_uncore_cpu_init, + .mmio_init = tgl_uncore_mmio_init, +}; +static const struct intel_uncore_init_fun icx_uncore_init__initconst = { .cpu_init = icx_uncore_cpu_init, .pci_init = icx_uncore_pci_init,
@@ -1794,6 +1799,8 @@ static const struct x86_cpu_id intel_uncore_match[] __initconst = {X86_MATCH_INTEL_FAM6_MODEL (TIGERLAKE_L , &tgl_l_uncore_init),X86_MATCH_INTEL_FAM6_MODEL (TIGERLAKE , &tgl_uncore_init),X86_MATCH_INTEL_FAM6_MODEL (ROCKETLAKE , &rkl_uncore_init), +X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE , &adl_uncore_init), +X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE_L , &adl_uncore_init), X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D, &snr_uncore_init), {}, };
arch/x86/events/intel/uncore.h +1 -0
@@ -575,6 +575,7 @@ void snb_uncore_cpu_init(void);void nhm_uncore_cpu_init (void );void skl_uncore_cpu_init (void );void icl_uncore_cpu_init (void ); +void adl_uncore_cpu_init (void );void tgl_uncore_cpu_init (void );void tgl_uncore_mmio_init (void );void tgl_l_uncore_mmio_init (void );
arch/x86/events/intel/uncore_snb.c +131 -0
161 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v5 23/25 perf/x86/msr: Add Alder Lake CPU support
In reply to [email protected]From: Kan Liang <[email protected]>
PPERF and SMI_COUNT MSRs are also supported on Alder Lake.
The External Design Specification (EDS) is not published yet. It comes from an authoritative internal source.
The patch has been tested on real hardware.
--- arch/x86/events/msr.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/events/msr.c +2 -0
@@ -100,6 +100,8 @@ static bool test_intel(int idx, void *data)case INTEL_FAM6_TIGERLAKE_L :case INTEL_FAM6_TIGERLAKE :case INTEL_FAM6_ROCKETLAKE : +case INTEL_FAM6_ALDERLAKE : +case INTEL_FAM6_ALDERLAKE_L :if (idx ==PERF_MSR_SMI || idx ==PERF_MSR_PPERF )return true;break ;
Signature · 1 line
2.7.4
Peter Zijlstra
maintainerRe: [PATCH V5 23/25] perf/x86/msr: Add Alder Lake CPU support
Quoted 20 lines · On Mon, Apr 05, 2021 at 08:11:05AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
PPERF and
SMI_COUNTMSRs are also supported on Alder Lake.The External Design Specification (EDS) is not published yet. It comes from an authoritative internal source.
The patch has been tested on real hardware.
Reviewed-by Andi Kleen <[email protected]>Signed-off-by Kan Liang <[email protected]>--- arch/x86/events/msr.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/events/msr.c +0
-0
arch/x86/events/msr.c static bool test_intel(int idx, void *data) · line 107
Quoted 8 lines
arch/x86/events/msr.c +2
-0@@ -100,6 +100,8 @@ static bool test_intel(int idx, void *data)case INTEL_FAM6_TIGERLAKE_L :case INTEL_FAM6_TIGERLAKE :case INTEL_FAM6_ROCKETLAKE : +case INTEL_FAM6_ALDERLAKE : +case INTEL_FAM6_ALDERLAKE_L :if (idx ==PERF_MSR_SMI || idx ==PERF_MSR_PPERF )return true;break ;
If only it would be sanely enumerated... What about sapphire rapids?
Re: [PATCH V5 23/25] perf/x86/msr: Add Alder Lake CPU support
Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · On Mon, Apr 05, 2021 at 08:11:05AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
PPERF and
SMI_COUNTMSRs are also supported on Alder Lake.The External Design Specification (EDS) is not published yet. It comes from an authoritative internal source.
The patch has been tested on real hardware.
Reviewed-by Andi Kleen <[email protected]>Signed-off-by Kan Liang <[email protected]>--- arch/x86/events/msr.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 16 lines
arch/x86/events/msr.c static bool test_intel(int idx, void *data) · line 107
Quoted 13 lines
arch/x86/events/msr.c +2
-0@@ -100,6 +100,8 @@ static bool test_intel(int idx, void *data)case INTEL_FAM6_TIGERLAKE_L :case INTEL_FAM6_TIGERLAKE :case INTEL_FAM6_ROCKETLAKE : +case INTEL_FAM6_ALDERLAKE : +case INTEL_FAM6_ALDERLAKE_L :if (idx ==PERF_MSR_SMI || idx ==PERF_MSR_PPERF )return true;break ;If only it would be sanely enumerated... What about sapphire rapids?
SPR also supports the MSRs. I will submit a patch separately to support SPR.
Thanks,
Kan
PATCH v5 24/25 perf/x86/cstate: Add Alder Lake CPU support
In reply to [email protected]From: Kan Liang <[email protected]>
Compared with the Rocket Lake, the CORE C1 Residency Counter is added for Alder Lake, but the CORE C3 Residency Counter is removed. Other counters are the same.
Create a new adl_cstates for Alder Lake. Update the comments accordingly.
The External Design Specification (EDS) is not published yet. It comes from an authoritative internal source.
The patch has been tested on real hardware.
--- arch/x86/events/intel/cstate.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-)
arch/x86/events/intel/cstate.c +29 -10
@@ -40,7 +40,7 @@* Model specific counters: * MSR_CORE_C1_RES: CORE C1 Residency Counter * perf code: 0x00 -* Available model: SLM,AMT,GLM,CNL,TNT +* Available model: SLM,AMT,GLM,CNL,TNT,ADL * Scope: Core (each processor core has a MSR) * MSR_CORE_C3_RESIDENCY: CORE C3 Residency Counter * perf code: 0x01
@@ -51,46 +51,49 @@* perf code: 0x02 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW, * SKL,KNL,GLM,CNL,KBL,CML,ICL,TGL, -* TNT,RKL +* TNT,RKL,ADL * Scope: Core * MSR_CORE_C7_RESIDENCY: CORE C7 Residency Counter * perf code: 0x03 * Available model: SNB,IVB,HSW,BDW,SKL,CNL,KBL,CML, -* ICL,TGL,RKL +* ICL,TGL,RKL,ADL * Scope: Core * MSR_PKG_C2_RESIDENCY: Package C2 Residency Counter. * perf code: 0x00 * Available model: SNB,IVB,HSW,BDW,SKL,KNL,GLM,CNL, -* KBL,CML,ICL,TGL,TNT,RKL +* KBL,CML,ICL,TGL,TNT,RKL,ADL * Scope: Package (physical package) * MSR_PKG_C3_RESIDENCY: Package C3 Residency Counter. * perf code: 0x01 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,KNL, -* GLM,CNL,KBL,CML,ICL,TGL,TNT,RKL +* GLM,CNL,KBL,CML,ICL,TGL,TNT,RKL, +* ADL * Scope: Package (physical package) * MSR_PKG_C6_RESIDENCY: Package C6 Residency Counter. * perf code: 0x02 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW, * SKL,KNL,GLM,CNL,KBL,CML,ICL,TGL, -* TNT,RKL +* TNT,RKL,ADL * Scope: Package (physical package) * MSR_PKG_C7_RESIDENCY: Package C7 Residency Counter. * perf code: 0x03 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL,CNL, -* KBL,CML,ICL,TGL,RKL +* KBL,CML,ICL,TGL,RKL,ADL * Scope: Package (physical package) * MSR_PKG_C8_RESIDENCY: Package C8 Residency Counter. * perf code: 0x04 -* Available model: HSW ULT,KBL,CNL,CML,ICL,TGL,RKL +* Available model: HSW ULT,KBL,CNL,CML,ICL,TGL,RKL, +* ADL * Scope: Package (physical package) * MSR_PKG_C9_RESIDENCY: Package C9 Residency Counter. * perf code: 0x05 -* Available model: HSW ULT,KBL,CNL,CML,ICL,TGL,RKL +* Available model: HSW ULT,KBL,CNL,CML,ICL,TGL,RKL, +* ADL * Scope: Package (physical package) * MSR_PKG_C10_RESIDENCY: Package C10 Residency Counter. * perf code: 0x06 * Available model: HSW ULT,KBL,GLM,CNL,CML,ICL,TGL, -* TNT,RKL +* TNT,RKL,ADL * Scope: Package (physical package) * */
@@ -563,6 +566,20 @@ static const struct cstate_model icl_cstates __initconst = { BIT(PERF_CSTATE_PKG_C10_RES), }; +static const struct cstate_model adl_cstates__initconst = { + .core_events =BIT (PERF_CSTATE_CORE_C1_RES ) | +BIT (PERF_CSTATE_CORE_C6_RES ) | +BIT (PERF_CSTATE_CORE_C7_RES ), + + .pkg_events =BIT (PERF_CSTATE_PKG_C2_RES ) | +BIT (PERF_CSTATE_PKG_C3_RES ) | +BIT (PERF_CSTATE_PKG_C6_RES ) | +BIT (PERF_CSTATE_PKG_C7_RES ) | +BIT (PERF_CSTATE_PKG_C8_RES ) | +BIT (PERF_CSTATE_PKG_C9_RES ) | +BIT (PERF_CSTATE_PKG_C10_RES ), +}; +static const struct cstate_model slm_cstates__initconst = { .core_events =BIT (PERF_CSTATE_CORE_C1_RES ) |BIT (PERF_CSTATE_CORE_C6_RES ),
@@ -650,6 +667,8 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {X86_MATCH_INTEL_FAM6_MODEL (TIGERLAKE_L , &icl_cstates),X86_MATCH_INTEL_FAM6_MODEL (TIGERLAKE , &icl_cstates),X86_MATCH_INTEL_FAM6_MODEL (ROCKETLAKE , &icl_cstates), +X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE , &adl_cstates), +X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE_L , &adl_cstates), { }, };MODULE_DEVICE_TABLE (x86cpu, intel_cstates_match);
Signature · 1 line
2.7.4
PATCH v5 25/25 perf/x86/rapl: Add support for Intel Alder Lake
In reply to [email protected]From: Zhang Rui <[email protected]>
Alder Lake RAPL support is the same as previous Sky Lake. Add Alder Lake model for RAPL.
--- arch/x86/events/rapl.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/events/rapl.c +2 -0
@@ -800,6 +800,8 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = {X86_MATCH_INTEL_FAM6_MODEL (ICELAKE_X , &model_hsx),X86_MATCH_INTEL_FAM6_MODEL (COMETLAKE_L , &model_skl),X86_MATCH_INTEL_FAM6_MODEL (COMETLAKE , &model_skl), +X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE , &model_skl), +X86_MATCH_INTEL_FAM6_MODEL (ALDERLAKE_L , &model_skl),X86_MATCH_INTEL_FAM6_MODEL (SAPPHIRERAPIDS_X , &model_spr),X86_MATCH_VENDOR_FAM (AMD ,0x17 , &model_amd_fam17h), X86_MATCH_VENDOR_FAM(HYGON, 0x18, &model_amd_fam17h),
Signature · 1 line
2.7.4