Add support for the ARMv8.2 Statistical Profiling Extension
Subsystems (9)
v2 cover Add support for the ARMv8.2 Statistical Profiling Extension
Hello,
This is RFCv2 of the patches originally posted here:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/476450.html
Changes since RFCv1 include:
* Use EXPORT_SYMBOL_GPL instead of EXPORT_SYMBOL
* Remove unused CPP macro
* Added tags for the first couple of patches (which are now queued in arm64)
* Added a brief overview of SPE to the commit log for the perf driver
All feedback welcome,
Will
--->8
Will Deacon (10):
arm64: cpufeature: allow for version discrepancy in PMU
implementations
arm64: cpufeature: Don't enforce system-wide SPE capability
arm64: KVM: Save/restore the host SPE state when entering/leaving a VM
arm64: head.S: Enable EL1 (host) access to SPE when entered at EL2
genirq: export irq_get_percpu_devid_partition to modules perf/core: Export AUX buffer helpers to modules
perf: Directly pass PERF_AUX_* flags to perf_aux_output_end perf/core: Add PERF_AUX_FLAG_COLLISION to report colliding samples drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
dt-bindings: Document devicetree binding for ARM SPE
Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 + arch/arm64/include/asm/kvm_arm.h | 3 + arch/arm64/include/asm/kvm_host.h | 7 +- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 9 +- arch/arm64/kernel/head.S | 14 +- arch/arm64/kvm/debug.c | 6 + arch/arm64/kvm/hyp/debug-sr.c | 66 +- arch/arm64/kvm/hyp/switch.c | 13 +- arch/x86/events/intel/bts.c | 11 +- arch/x86/events/intel/pt.c | 11 +- drivers/hwtracing/coresight/coresight-etm-perf.c | 5 +- drivers/perf/Kconfig | 8 + drivers/perf/Makefile | 1 + drivers/perf/arm_spe_pmu.c | 1244 +++++++++++++++++++++ include/linux/perf_event.h | 4 +- include/uapi/linux/perf_event.h | 1 + kernel/events/ring_buffer.c | 16 +- kernel/irq/irqdesc.c | 1 + 19 files changed, 1413 insertions(+), 28 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txt create mode 100644 drivers/perf/arm_spe_pmu.c
Signature · 1 line
2.1.4
RFC PATCH v2 1/10 arm64: cpufeature: allow for version discrepancy in PMU implementations
Perf already supports multiple PMU instances for heterogeneous systems, so there's no need to be strict in the cpufeature checking, particularly as the PMU extension is optional in the architecture.
--- arch/arm64/kernel/cpufeature.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpufeature.c +5 -1
@@ -184,7 +184,11 @@ static const struct arm64_ftr_bits ftr_id_aa64dfr0[] = {ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_CTX_CMPS_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_WRPS_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_BRPS_SHIFT ,4 ,0 ), -S_ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,ID_AA64DFR0_PMUVER_SHIFT ,4 ,0 ), +/* +* We can instantiate multiple PMU instances with different levels +* of support. +* */ +S_ARM64_FTR_BITS (FTR_NONSTRICT ,FTR_EXACT ,ID_AA64DFR0_PMUVER_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,ID_AA64DFR0_TRACEVER_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,ID_AA64DFR0_DEBUGVER_SHIFT ,4 ,0x6 ), ARM64_FTR_END,
Signature · 1 line
2.1.4
RFC PATCH v2 2/10 arm64: cpufeature: Don't enforce system-wide SPE capability
In reply to Will DeaconThe statistical profiling extension (SPE) is an optional feature of ARMv8.1 and is unlikely to be supported by all of the CPUs in a heterogeneous system.
This patch updates the cpufeature checks so that such systems are not tainted as unsupported.
--- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kernel/cpufeature.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +1 -0
@@ -190,6 +190,7 @@#define ID_AA64MMFR2_CNP_SHIFT 0/* id_aa64dfr0 */ +#define ID_AA64DFR0_PMSVER_SHIFT 32#define ID_AA64DFR0_CTX_CMPS_SHIFT 28#define ID_AA64DFR0_WRPS_SHIFT 20#define ID_AA64DFR0_BRPS_SHIFT 12
arch/arm64/kernel/cpufeature.c +2 -1
@@ -180,7 +180,8 @@ static const struct arm64_ftr_bits ftr_id_mmfr0[] = { };static const struct arm64_ftr_bits ftr_id_aa64dfr0[] = { -ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,32 ,32 ,0 ), +ARM64_FTR_BITS (FTR_STRICT ,FTR_EXACT ,36 ,28 ,0 ), +ARM64_FTR_BITS (FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_PMSVER_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_CTX_CMPS_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_WRPS_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_STRICT ,FTR_LOWER_SAFE ,ID_AA64DFR0_BRPS_SHIFT ,4 ,0 ),
Signature · 1 line
2.1.4
RFC PATCH v2 3/10 arm64: KVM: Save/restore the host SPE state when entering/leaving a VM
In reply to Will DeaconThe SPE buffer is virtually addressed, using the page tables of the CPU MMU. Unusually, this means that the EL0/1 page table may be live whilst we're executing at EL2 on non-VHE configurations. When VHE is in use, we can use the same property to profile the guest behind its back.
This patch adds the relevant disabling and flushing code to KVM so that the host can make use of SPE without corrupting guest memory, and any attempts by a guest to use SPE will result in a trap.
--- arch/arm64/include/asm/kvm_arm.h | 3 ++ arch/arm64/include/asm/kvm_host.h | 7 ++++- arch/arm64/kvm/debug.c | 6 ++++ arch/arm64/kvm/hyp/debug-sr.c | 66 +++++++++++++++++++++++++++++++++++++-- arch/arm64/kvm/hyp/switch.c | 13 +++++++- 5 files changed, 91 insertions(+), 4 deletions(-)
arch/arm64/include/asm/kvm_arm.h +3 -0
@@ -188,6 +188,9 @@#define CPTR_EL2_DEFAULT 0x000033ff/* Hyp Debug Configuration Register bits */ +#define MDCR_EL2_TPMS (1 << 14) +#define MDCR_EL2_E2PB_MASK (UL(0x3)) +#define MDCR_EL2_E2PB_SHIFT (UL(12))#define MDCR_EL2_TDRA (1 << 11)#define MDCR_EL2_TDOSA (1 << 10)#define MDCR_EL2_TDA (1 << 9)
arch/arm64/include/asm/kvm_host.h +6 -1
@@ -229,7 +229,12 @@ struct kvm_vcpu_arch {/* Pointer to host CPU context */ kvm_cpu_context_t *host_cpu_context; -struct kvm_guest_debug_arch host_debug_state; +struct { +/* {Break,watch}point registers */ +struct kvm_guest_debug_arch regs; +/* Statistical profiling extension */ +u64 pmscr_el1; + } host_debug_state;/* VGIC state */ struct vgic_cpu vgic_cpu;
arch/arm64/kvm/debug.c +6 -0
@@ -95,6 +95,7 @@ void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu)* - Performance monitors (MDCR_EL2_TPM/MDCR_EL2_TPMCR) * - Debug ROM Address (MDCR_EL2_TDRA) * - OS related registers (MDCR_EL2_TDOSA) +* - Statistical profiler (MDCR_EL2_TPMS/MDCR_EL2_E2PB) * * Additionally, KVM only traps guest accesses to the debug registers if * the guest is not actively using them (see the KVM_ARM64_DEBUG_DIRTY
@@ -110,8 +111,13 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)trace_kvm_arm_setup_debug (vcpu, vcpu->guest_debug); +/* +* This also clears MDCR_EL2_E2PB_MASK to disable guest access +* to the profiling buffer. +*/ vcpu->arch.mdcr_el2 =__this_cpu_read (mdcr_el2) &MDCR_EL2_HPMN_MASK ; vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | +MDCR_EL2_TPMS |MDCR_EL2_TPMCR |MDCR_EL2_TDRA |MDCR_EL2_TDOSA );
arch/arm64/kvm/hyp/debug-sr.c +64 -2
83 lines not on this page · raw message
arch/arm64/kvm/hyp/switch.c +12 -1
@@ -103,7 +103,13 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) static void __hyp_text __deactivate_traps_vhe(void) {extern char vectors[];/* kernel exception vectors */ +u64 mdcr_el2 =read_sysreg (mdcr_el2); + mdcr_el2 &=MDCR_EL2_HPMN_MASK | +MDCR_EL2_E2PB_MASK <<MDCR_EL2_E2PB_SHIFT | +MDCR_EL2_TPMS ; + +write_sysreg (mdcr_el2, mdcr_el2);write_sysreg (HCR_HOST_VHE_FLAGS , hcr_el2);write_sysreg (CPACR_EL1_FPEN , cpacr_el1);write_sysreg (vectors, vbar_el1);
@@ -111,6 +117,12 @@ static void __hyp_text __deactivate_traps_vhe(void) static void __hyp_text __deactivate_traps_nvhe(void) { +u64 mdcr_el2 =read_sysreg (mdcr_el2); + + mdcr_el2 &=MDCR_EL2_HPMN_MASK ; + mdcr_el2 |=MDCR_EL2_E2PB_MASK <<MDCR_EL2_E2PB_SHIFT ; + +write_sysreg (mdcr_el2, mdcr_el2);write_sysreg (HCR_RW , hcr_el2);write_sysreg (CPTR_EL2_DEFAULT , cptr_el2); }
@@ -132,7 +144,6 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)__deactivate_traps_arch ()();write_sysreg (0 , hstr_el2); -write_sysreg (read_sysreg (mdcr_el2) &MDCR_EL2_HPMN_MASK , mdcr_el2);write_sysreg (0 , pmuserenr_el0); }
Signature · 1 line
2.1.4
Re: [RFC PATCH v2 03/10] arm64: KVM: Save/restore the host SPE state when entering/leaving a VM
Hi Will,
Quoted 66 lines · Will Deacon
The SPE buffer is virtually addressed, using the page tables of the CPU MMU. Unusually, this means that the EL0/1 page table may be live whilst we're executing at EL2 on non-VHE configurations. When VHE is in use, we can use the same property to profile the guest behind its back.
This patch adds the relevant disabling and flushing code to KVM so that the host can make use of SPE without corrupting guest memory, and any attempts by a guest to use SPE will result in a trap.
Cc Marc Zyngier <[email protected]>Cc Alex Benn?e <[email protected]>Cc Christoffer Dall <[email protected]>Signed-off-by Will Deacon <[email protected]>--- arch/arm64/include/asm/kvm_arm.h | 3 ++ arch/arm64/include/asm/kvm_host.h | 7 ++++- arch/arm64/kvm/debug.c | 6 ++++ arch/arm64/kvm/hyp/debug-sr.c | 66 +++++++++++++++++++++++++++++++++++++-- arch/arm64/kvm/hyp/switch.c | 13 +++++++- 5 files changed, 91 insertions(+), 4 deletions(-)arch/arm64/include/asm/kvm_arm.h +3
-0@@ -188,6 +188,9 @@#define CPTR_EL2_DEFAULT 0x000033ff/* Hyp Debug Configuration Register bits */ +#define MDCR_EL2_TPMS (1 << 14) +#define MDCR_EL2_E2PB_MASK (UL(0x3)) +#define MDCR_EL2_E2PB_SHIFT (UL(12))#define MDCR_EL2_TDRA (1 << 11)#define MDCR_EL2_TDOSA (1 << 10)#define MDCR_EL2_TDA (1 << 9)arch/arm64/include/asm/kvm_host.h +6
-1@@ -229,7 +229,12 @@ struct kvm_vcpu_arch {/* Pointer to host CPU context */ kvm_cpu_context_t *host_cpu_context; -struct kvm_guest_debug_arch host_debug_state; +struct { +/* {Break,watch}point registers */ +struct kvm_guest_debug_arch regs; +/* Statistical profiling extension */ +u64 pmscr_el1; + } host_debug_state;/* VGIC state */ struct vgic_cpu vgic_cpu;arch/arm64/kvm/debug.c +1
-0@@ -95,6 +95,7 @@ void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu)* - Performance monitors (MDCR_EL2_TPM/MDCR_EL2_TPMCR) * - Debug ROM Address (MDCR_EL2_TDRA) * - OS related registers (MDCR_EL2_TDOSA) +* - Statistical profiler (MDCR_EL2_TPMS/MDCR_EL2_E2PB) * * Additionally, KVM only traps guest accesses to the debug registers if * the guest is not actively using them (see the KVM_ARM64_DEBUG_DIRTY
arch/arm64/kvm/debug.c void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) · line 120
Quoted 10 lines
arch/arm64/kvm/debug.c +5
-0@@ -110,8 +111,13 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)trace_kvm_arm_setup_debug (vcpu, vcpu->guest_debug); +/* +* This also clears MDCR_EL2_E2PB_MASK to disable guest access +* to the profiling buffer. +*/ vcpu->arch.mdcr_el2 =__this_cpu_read (mdcr_el2) &MDCR_EL2_HPMN_MASK ; vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | + MDCR_EL2_TPMS |
This is RES0 on CPUs that do not implement SPE. Can we make this conditional on SPE being available?
Quoted 10 lines
arch/arm64/kvm/debug.c +0
-0MDCR_EL2_TPMCR |MDCR_EL2_TDRA | MDCR_EL2_TDOSA);arch/arm64/kvm/hyp/debug-sr.c +0
-0@@ -65,6 +65,66 @@default :write_debug (ptr[0 ], reg,0 ); \ }
arch/arm64/kvm/hyp/debug-sr.c line 76
Quoted 10 lines
arch/arm64/kvm/hyp/debug-sr.c +9
-0+#define PMSCR_EL1 sys_reg(3, 0, 9, 9, 0) + +#define PMBLIMITR_EL1 sys_reg(3, 0, 9, 10, 0) +#define PMBLIMITR_EL1_E BIT(0) + +#define PMBIDR_EL1 sys_reg(3, 0, 9, 10, 7) +#define PMBIDR_EL1_P BIT(4) + +#define psb_csync () asm volatile("hint #17")
Cute... ;-)
Quoted 23 lines
arch/arm64/kvm/hyp/debug-sr.c +23
-0+ +static void __hyp_text __debug_save_spe_vhe(u64 *pmscr_el1) +{ +/* The vcpu can run. but it can't hide. */ +} + +static void __hyp_text __debug_save_spe_nvhe(u64 *pmscr_el1) +{ +u64 reg; + +/* SPE present on this CPU? */ +if (!cpuid_feature_extract_unsigned_field (read_sysreg (id_aa64dfr0_el1), +ID_AA64DFR0_PMSVER_SHIFT )) +return ; + +/* Yes; is it owned by EL3? */ + reg =read_sysreg_s (PMBIDR_EL1 ); +if (reg &PMBIDR_EL1_P ) +return ; + +/* No; is the host actually using the thing? */ + reg =read_sysreg_s (PMBLIMITR_EL1 ); +if (!(reg &PMBLIMITR_EL1_E ))
arch/arm64/kvm/hyp/debug-sr.c line 109
Quoted 10 lines
arch/arm64/kvm/hyp/debug-sr.c +10
-0+return ; + +/* Yes; save the control register and disable data generation */ + *pmscr_el1 =read_sysreg_s (PMSCR_EL1 ); +write_sysreg_s (0 ,PMSCR_EL1 ); +isb (); + +/* Now drain all buffered data to memory */ +psb_csync (); +dsb (nsh);
So let's hope that nobody will build a non-VHE, SPE capable system. Because this feels like hitting the brakes each time we enter the guest (if SPE is in use, that is...).
arch/arm64/kvm/hyp/debug-sr.c line 122
Quoted 13 lines
arch/arm64/kvm/hyp/debug-sr.c +13
-0+} + +static hyp_alternate_select(__debug_save_spe, + __debug_save_spe_nvhe, __debug_save_spe_vhe, + ARM64_HAS_VIRT_HOST_EXTN); + +static void __hyp_text __debug_restore_spe(u64 pmscr_el1) +{ +if (!pmscr_el1) +return ; + +/* The host page table is installed, but not yet synchronised */ +isb ();
I believe you can avoid that on VHE (host page tables haven't changed). Also, if you now depend on the debug restore being run after the rest of the sysregs, please add a comment in switch.c::__kvm_vcpu_run so that we remember about that dependency.
arch/arm64/kvm/hyp/debug-sr.c line 125
Quoted 3 lines
arch/arm64/kvm/hyp/debug-sr.c +3
-0+ +/* Re-enable data generation */ +write_sysreg_s (pmscr_el1,PMSCR_EL1 );
Same thing here, as we never disabled SPE the first place on VHE (and we're probably only writing zeroes there).
Quoted 42 lines
arch/arm64/kvm/hyp/debug-sr.c +6
-2+} + void __hyp_text __debug_save_state(struct kvm_vcpu *vcpu,struct kvm_guest_debug_arch *dbg,struct kvm_cpu_context *ctxt)@@ -118,13 +178,15 @@ void __hyp_text __debug_cond_save_host_state(struct kvm_vcpu *vcpu) (vcpu->arch.ctxt.sys_regs[MDSCR_EL1] & DBG_MDSCR_MDE)) vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY; -__debug_save_state (vcpu, &vcpu->arch.host_debug_state, +__debug_save_state (vcpu, &vcpu->arch.host_debug_state.regs,kern_hyp_va (vcpu->arch.host_cpu_context)); +__debug_save_spe ()(&vcpu->arch.host_debug_state.pmscr_el1); } void __hyp_text __debug_cond_restore_host_state(struct kvm_vcpu *vcpu) { -__debug_restore_state (vcpu, &vcpu->arch.host_debug_state, +__debug_restore_spe (vcpu->arch.host_debug_state.pmscr_el1); +__debug_restore_state (vcpu, &vcpu->arch.host_debug_state.regs,kern_hyp_va (vcpu->arch.host_cpu_context));if (vcpu->arch.debug_flags &KVM_ARM64_DEBUG_DIRTY )arch/arm64/kvm/hyp/switch.c +6
-0@@ -103,7 +103,13 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) static void __hyp_text __deactivate_traps_vhe(void) {extern char vectors[];/* kernel exception vectors */ +u64 mdcr_el2 =read_sysreg (mdcr_el2); + mdcr_el2 &=MDCR_EL2_HPMN_MASK | +MDCR_EL2_E2PB_MASK <<MDCR_EL2_E2PB_SHIFT | +MDCR_EL2_TPMS ; + +write_sysreg (mdcr_el2, mdcr_el2);write_sysreg (HCR_HOST_VHE_FLAGS , hcr_el2);write_sysreg (CPACR_EL1_FPEN , cpacr_el1);write_sysreg (vectors, vbar_el1);
arch/arm64/kvm/hyp/switch.c static void __hyp_text __deactivate_traps_vhe(void) · line 123
Quoted 7 lines
arch/arm64/kvm/hyp/switch.c +4
-0@@ -111,6 +117,12 @@ static void __hyp_text __deactivate_traps_vhe(void) static void __hyp_text __deactivate_traps_nvhe(void) { +u64 mdcr_el2 =read_sysreg (mdcr_el2); + + mdcr_el2 &=MDCR_EL2_HPMN_MASK ; + mdcr_el2 |=MDCR_EL2_E2PB_MASK <<MDCR_EL2_E2PB_SHIFT ;
Same remark as above. I'm not completely confident writing new bits to registers that do not necessarily implement the feature.
Quoted 7 lines
arch/arm64/kvm/hyp/switch.c +2
-0+ +write_sysreg (mdcr_el2, mdcr_el2);write_sysreg (HCR_RW , hcr_el2);write_sysreg (CPTR_EL2_DEFAULT , cptr_el2); }
arch/arm64/kvm/hyp/switch.c static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) · line 149
Quoted 7 lines
arch/arm64/kvm/hyp/switch.c +0
-1@@ -132,7 +144,6 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)__deactivate_traps_arch ()();write_sysreg (0 , hstr_el2); -write_sysreg (read_sysreg (mdcr_el2) &MDCR_EL2_HPMN_MASK , mdcr_el2);write_sysreg (0 , pmuserenr_el0); }
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [RFC PATCH v2 03/10] arm64: KVM: Save/restore the host SPE state when entering/leaving a VM
Hi Marc,
Thanks for having a look.
Quoted 70 lines · Marc Zyngier
Quoted 69 lines · Will Deacon
The SPE buffer is virtually addressed, using the page tables of the CPU MMU. Unusually, this means that the EL0/1 page table may be live whilst we're executing at EL2 on non-VHE configurations. When VHE is in use, we can use the same property to profile the guest behind its back.
This patch adds the relevant disabling and flushing code to KVM so that the host can make use of SPE without corrupting guest memory, and any attempts by a guest to use SPE will result in a trap.
Cc Marc Zyngier <[email protected]>Cc Alex Benn?e <[email protected]>Cc Christoffer Dall <[email protected]>Signed-off-by Will Deacon <[email protected]>--- arch/arm64/include/asm/kvm_arm.h | 3 ++ arch/arm64/include/asm/kvm_host.h | 7 ++++- arch/arm64/kvm/debug.c | 6 ++++ arch/arm64/kvm/hyp/debug-sr.c | 66 +++++++++++++++++++++++++++++++++++++-- arch/arm64/kvm/hyp/switch.c | 13 +++++++- 5 files changed, 91 insertions(+), 4 deletions(-)arch/arm64/include/asm/kvm_arm.h +3
-0@@ -188,6 +188,9 @@#define CPTR_EL2_DEFAULT 0x000033ff/* Hyp Debug Configuration Register bits */ +#define MDCR_EL2_TPMS (1 << 14) +#define MDCR_EL2_E2PB_MASK (UL(0x3)) +#define MDCR_EL2_E2PB_SHIFT (UL(12))#define MDCR_EL2_TDRA (1 << 11)#define MDCR_EL2_TDOSA (1 << 10)#define MDCR_EL2_TDA (1 << 9)arch/arm64/include/asm/kvm_host.h +6
-1@@ -229,7 +229,12 @@ struct kvm_vcpu_arch {/* Pointer to host CPU context */ kvm_cpu_context_t *host_cpu_context; -struct kvm_guest_debug_arch host_debug_state; +struct { +/* {Break,watch}point registers */ +struct kvm_guest_debug_arch regs; +/* Statistical profiling extension */ +u64 pmscr_el1; + } host_debug_state;/* VGIC state */ struct vgic_cpu vgic_cpu;arch/arm64/kvm/debug.c +1
-0@@ -95,6 +95,7 @@ void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu)* - Performance monitors (MDCR_EL2_TPM/MDCR_EL2_TPMCR) * - Debug ROM Address (MDCR_EL2_TDRA) * - OS related registers (MDCR_EL2_TDOSA) +* - Statistical profiler (MDCR_EL2_TPMS/MDCR_EL2_E2PB) * * Additionally, KVM only traps guest accesses to the debug registers if * the guest is not actively using them (see the KVM_ARM64_DEBUG_DIRTY @@ -110,8 +111,13 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)trace_kvm_arm_setup_debug (vcpu, vcpu->guest_debug);
Quoted 10 lines
arch/arm64/kvm/debug.c void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) · line 120
Quoted 7 lines
arch/arm64/kvm/debug.c +5
-0+/* +* This also clears MDCR_EL2_E2PB_MASK to disable guest access +* to the profiling buffer. +*/ vcpu->arch.mdcr_el2 =__this_cpu_read (mdcr_el2) &MDCR_EL2_HPMN_MASK ; vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | + MDCR_EL2_TPMS |This is RES0 on CPUs that do not implement SPE. Can we make this conditional on SPE being available?
I could, but it would introduce a runtime ID register check for the physical CPU on the fastpath, because big/little systems are not required to be symmetric in this regard. We already have code that writes to bits that might be RES0 but have been defined by later versions of the architecture. In fact, setting the TPM bit here is RES0 if the PMU is not implemented.
Furthermore, the architecture does state that writing a value to a RES0 field "must have no effect on the operation of the PE". The purpose of the fields is for future architecture extension, which in this case has been defined by SPE.
Quoted 23 lines
Quoted 23 lines
arch/arm64/kvm/debug.c +23
-0+static void __hyp_text __debug_save_spe_nvhe(u64 *pmscr_el1) +{ +u64 reg; + +/* SPE present on this CPU? */ +if (!cpuid_feature_extract_unsigned_field (read_sysreg (id_aa64dfr0_el1), +ID_AA64DFR0_PMSVER_SHIFT )) +return ; + +/* Yes; is it owned by EL3? */ + reg =read_sysreg_s (PMBIDR_EL1 ); +if (reg &PMBIDR_EL1_P ) +return ; + +/* No; is the host actually using the thing? */ + reg =read_sysreg_s (PMBLIMITR_EL1 ); +if (!(reg &PMBLIMITR_EL1_E )) +return ; + +/* Yes; save the control register and disable data generation */ + *pmscr_el1 =read_sysreg_s (PMSCR_EL1 ); +write_sysreg_s (0 ,PMSCR_EL1 ); +isb ();
Quoted 8 lines
arch/arm64/kvm/debug.c
Quoted 4 lines
arch/arm64/kvm/debug.c +4
-0+ +/* Now drain all buffered data to memory */ +psb_csync (); +dsb (nsh);So let's hope that nobody will build a non-VHE, SPE capable system. Because this feels like hitting the brakes each time we enter the guest (if SPE is in use, that is...).
Yup, not much we can do about that :(
Quoted 5 lines
Quoted 5 lines
arch/arm64/kvm/debug.c +5
-0+static hyp_alternate_select(__debug_save_spe, + __debug_save_spe_nvhe, __debug_save_spe_vhe, + ARM64_HAS_VIRT_HOST_EXTN); + +static void __hyp_text __debug_restore_spe(u64 pmscr_el1)
Quoted 8 lines
arch/arm64/kvm/debug.c
Quoted 6 lines
arch/arm64/kvm/debug.c +6
-0+{ +if (!pmscr_el1) +return ; + +/* The host page table is installed, but not yet synchronised */ +isb ();I believe you can avoid that on VHE (host page tables haven't changed).
It should already be skipped because pmscr_el1 is never set for VHE (__debug_save_spe_vhe is a NOP).
Quoted 3 lines
Also, if you now depend on the debug restore being run after the rest of the sysregs, please add a comment in
switch.c::__kvm_vcpu_runso that we remember about that dependency.
Sure.
Quoted 6 lines
arch/arm64/kvm/debug.c
Quoted 3 lines
arch/arm64/kvm/debug.c +3
-0+ +/* Re-enable data generation */ +write_sysreg_s (pmscr_el1,PMSCR_EL1 );Same thing here, as we never disabled SPE the first place on VHE (and we're probably only writing zeroes there).
Yup, check the conditional :)
Will
RFC PATCH v2 4/10 arm64: head.S: Enable EL1 (host) access to SPE when entered at EL2
In reply to Will DeaconThe SPE architecture requires each exception level to enable access to the SPE controls for the exception level below it, since additional context-switch logic may be required to handle the buffer safely.
This patch allows EL1 (host) access to the SPE controls when entered at EL2.
--- arch/arm64/kernel/head.S | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/arm64/kernel/head.S +12 -2
@@ -592,8 +592,8 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems #endif /* EL2 debug */ - mrs x0, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer - sbfx x0, x0, #8, #4 + mrs x1, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer + sbfx x0, x1, #8, #4 cmp x0, #1 b.lt 4f // Skip if no PMU present mrs x0, pmcr_el0 // Disable debug access traps
@@ -601,6 +601,16 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems 4: csel x0, xzr, x0, lt // all PMU counters from EL1 msr mdcr_el2, x0 // (if they exist) + /* Statistical profiling */ + ubfx x0, x1, #32, #4 // Check ID_AA64DFR0_EL1 PMSVer + cbz x0, 5f // Skip if SPE not present + mrs x0, mdcr_el2 // Preserve HPMN field + cmp x2, xzr // If VHE is not enabled, + mov x1, #3 // use EL1&0 translations, + cinc x1, x1, ne // otherwise use EL2 and + bfi x0, x1, #12, #3 // enable/disable access + msr mdcr_el2, x0 // traps accordingly. +5: /* Stage-2 translation */ msr vttbr_el2, xzr
Signature · 1 line
2.1.4
Re: [RFC PATCH v2 04/10] arm64: head.S: Enable EL1 (host) access to SPE when entered at EL2
Quoted 31 lines · Will Deacon
The SPE architecture requires each exception level to enable access to the SPE controls for the exception level below it, since additional context-switch logic may be required to handle the buffer safely.
This patch allows EL1 (host) access to the SPE controls when entered at EL2.
Cc Marc Zyngier <[email protected]>Signed-off-by Will Deacon <[email protected]>--- arch/arm64/kernel/head.S | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)arch/arm64/kernel/head.S +2
-2@@ -592,8 +592,8 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems #endif /* EL2 debug */ - mrs x0, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer - sbfx x0, x0, #8, #4 + mrs x1, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer + sbfx x0, x1, #8, #4 cmp x0, #1 b.lt 4f // Skip if no PMU present mrs x0, pmcr_el0 // Disable debug access traps@@ -601,6 +601,16 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems 4: csel x0, xzr, x0, lt // all PMU counters from EL1
arch/arm64/kernel/head.S CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems · line 612
Quoted 10 lines
arch/arm64/kernel/head.S +9
-0msr mdcr_el2, x0 // (if they exist) + /* Statistical profiling */ + ubfx x0, x1, #32, #4 // Check ID_AA64DFR0_EL1 PMSVer + cbz x0, 5f // Skip if SPE not present + mrs x0, mdcr_el2 // Preserve HPMN field + cmp x2, xzr // If VHE is not enabled, + mov x1, #3 // use EL1&0 translations, + cinc x1, x1, ne // otherwise use EL2 and + bfi x0, x1, #12, #3 // enable/disable access + msr mdcr_el2, x0 // traps accordingly.
Man, this hack to set TPMS and E2PB is horrid. It does the trick, but it took me a couple of minutes to realize what it was doing. Can't we just have named flags and a some form of conditional select instead? It would hurt a lot less...
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
RFC PATCH v2 5/10 genirq: export irq_get_percpu_devid_partition to modules
In reply to Will DeaconAny modular driver using cluster-affine PPIs needs to be able to call irq_get_percpu_devid_partition so that it can enable the IRQ on the correct subset of CPUs.
This patch exports the symbol so that it can be called from within a module.
--- kernel/irq/irqdesc.c | 1 + 1 file changed, 1 insertion(+)
kernel/irq/irqdesc.c +1 -0
@@ -856,6 +856,7 @@ int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity)return 0 ; } +EXPORT_SYMBOL_GPL (irq_get_percpu_devid_partition);void kstat_incr_irq_this_cpu (unsigned int irq) {
Signature · 1 line
2.1.4
Re: [RFC PATCH v2 05/10] genirq: export irq_get_percpu_devid_partition to modules
Quoted 20 lines · Will Deacon
Any modular driver using cluster-affine PPIs needs to be able to call
irq_get_percpu_devid_partitionso that it can enable the IRQ on the correct subset of CPUs.This patch exports the symbol so that it can be called from within a module.
Cc Marc Zyngier <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Will Deacon <[email protected]>--- kernel/irq/irqdesc.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/irqdesc.c +0
-0
kernel/irq/irqdesc.c int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity) · line 862
Quoted 7 lines
kernel/irq/irqdesc.c +1
-0@@ -856,6 +856,7 @@ int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity)return 0 ; } +EXPORT_SYMBOL_GPL (irq_get_percpu_devid_partition);void kstat_incr_irq_this_cpu (unsigned int irq) {
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [RFC PATCH v2 05/10] genirq: export irq_get_percpu_devid_partition to modules
In reply to Will DeaconQuoted 19 lines · Will Deacon
Any modular driver using cluster-affine PPIs needs to be able to call
irq_get_percpu_devid_partitionso that it can enable the IRQ on the correct subset of CPUs.This patch exports the symbol so that it can be called from within a module.
Cc Marc Zyngier <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Will Deacon <[email protected]>--- kernel/irq/irqdesc.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/irqdesc.c +0
-0
kernel/irq/irqdesc.c int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity) · line 859
Quoted 4 lines
kernel/irq/irqdesc.c +1
-0@@ -856,6 +856,7 @@ int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity)return 0 ; } +EXPORT_SYMBOL_GPL (irq_get_percpu_devid_partition);
RFC PATCH v2 6/10 perf/core: Export AUX buffer helpers to modules
In reply to Will DeaconPerf PMU drivers using AUX buffers cannot be built as modules unless the AUX helpers are exported.
This patch exports perf_aux_output_{begin,end,skip} and perf_get_aux to modules.
--- kernel/events/ring_buffer.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/events/ring_buffer.c +4 -0
@@ -397,6 +397,7 @@ void *perf_aux_output_begin(struct perf_output_handle *handle,return NULL ; } +EXPORT_SYMBOL_GPL (perf_aux_output_begin);/* * Commit the data written by hardware into the ring buffer by adjusting
@@ -458,6 +459,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,rb_free_aux (rb);ring_buffer_put (rb); } +EXPORT_SYMBOL_GPL (perf_aux_output_end);/* * Skip over a given number of bytes in the AUX buffer, due to, for example,
@@ -486,6 +488,7 @@ int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size)return 0 ; } +EXPORT_SYMBOL_GPL (perf_aux_output_skip);void *perf_get_aux (struct perf_output_handle *handle) {
@@ -495,6 +498,7 @@ void *perf_get_aux(struct perf_output_handle *handle)return handle->rb->aux_priv; } +EXPORT_SYMBOL_GPL (perf_get_aux);#define PERF_AUX_GFP (GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY)
Signature · 1 line
2.1.4
RFC PATCH v2 7/10 perf: Directly pass PERF_AUX_* flags to perf_aux_output_end
In reply to Will DeaconIn preparation for adding additional flags to perf AUX records, allow the flags for a session to be passed directly to perf_aux_output_end, rather than extend the function to take a bool for each one.
--- arch/x86/events/intel/bts.c | 11 ++++++----- arch/x86/events/intel/pt.c | 11 +++++++---- drivers/hwtracing/coresight/coresight-etm-perf.c | 5 +++-- include/linux/perf_event.h | 4 ++-- kernel/events/ring_buffer.c | 12 +++++------- 5 files changed, 23 insertions(+), 20 deletions(-)
arch/x86/events/intel/bts.c +6 -5
@@ -276,7 +276,7 @@ static void bts_event_start(struct perf_event *event, int flags)return ; fail_end_stop: -perf_aux_output_end (&bts->handle,0 , false); +perf_aux_output_end (&bts->handle,0 ,0 ); fail_stop: event->hw.state =PERF_HES_STOPPED ;
@@ -319,9 +319,9 @@ static void bts_event_stop(struct perf_event *event, int flags) bts->handle.head =local_xchg (&buf->data_size, buf->nr_pages <<PAGE_SHIFT ); -perf_aux_output_end (&bts->handle,local_xchg (&buf->data_size,0 ), - !!local_xchg (&buf->lost,0 )); +local_xchg (&buf->lost,0 ) ? +PERF_AUX_FLAG_TRUNCATED :0 ); } cpuc->ds->bts_index = bts->ds_back.bts_buffer_base;
@@ -485,7 +485,8 @@ int intel_bts_interrupt(void)return handled;perf_aux_output_end (&bts->handle,local_xchg (&buf->data_size,0 ), - !!local_xchg (&buf->lost,0 )); +local_xchg (&buf->lost,0 ) ? +PERF_AUX_FLAG_OVERWRITE :0 ); buf =perf_aux_output_begin (&bts->handle, event);if (buf)
@@ -500,7 +501,7 @@ int intel_bts_interrupt(void)* cleared handle::event */ barrier (); -perf_aux_output_end (&bts->handle,0 , false); +perf_aux_output_end (&bts->handle,0 ,0 ); } }
arch/x86/events/intel/pt.c +7 -4
@@ -1187,7 +1187,8 @@ void intel_pt_interrupt(void)pt_update_head (pt);perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 ), -local_xchg (&buf->lost,0 )); +local_xchg (&buf->lost,0 ) ? +PERF_AUX_FLAG_TRUNCATED :0 );if (!event->hw.state) {int ret;
@@ -1202,7 +1203,8 @@ void intel_pt_interrupt(void)/* snapshot counters don't use PMI, so it's safe */ ret =pt_buffer_reset_markers (buf, &pt->handle);if (ret) { -perf_aux_output_end (&pt->handle,0 , true); +perf_aux_output_end (&pt->handle,0 , +PERF_AUX_FLAG_TRUNCATED );return ; }
@@ -1274,7 +1276,7 @@ static void pt_event_start(struct perf_event *event, int mode)return ; fail_end_stop: -perf_aux_output_end (&pt->handle,0 , true); +perf_aux_output_end (&pt->handle,0 ,PERF_AUX_FLAG_TRUNCATED ); fail_stop: hwc->state =PERF_HES_STOPPED ; }
@@ -1316,7 +1318,8 @@ static void pt_event_stop(struct perf_event *event, int mode)local_xchg (&buf->data_size, buf->nr_pages <<PAGE_SHIFT );perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 ), -local_xchg (&buf->lost,0 )); +local_xchg (&buf->lost,0 ) ? +PERF_AUX_FLAG_TRUNCATED :0 ); } }
drivers/hwtracing/coresight/coresight-etm-perf.c +3 -2
@@ -301,7 +301,7 @@ static void etm_event_start(struct perf_event *event, int flags)return ; fail_end_stop: -perf_aux_output_end (handle,0 , true); +perf_aux_output_end (handle,0 ,PERF_AUX_FLAG_TRUNCATED ); fail: event->hw.state =PERF_HES_STOPPED ; goto out;
@@ -350,7 +350,8 @@ static void etm_event_stop(struct perf_event *event, int mode) event_data->snk_config, &lost); -perf_aux_output_end (handle, size, lost); +perf_aux_output_end (handle, size, + lost ?PERF_AUX_FLAG_TRUNCATED :0 ); }/* Disabling the path make its elements available to other sessions */
include/linux/perf_event.h +2 -2
@@ -847,7 +847,7 @@ perf_cgroup_from_task(struct task_struct *task, struct perf_event_context *ctx)extern void *perf_aux_output_begin (struct perf_output_handle *handle,struct perf_event *event);extern void perf_aux_output_end (struct perf_output_handle *handle, -unsigned long size,bool truncated); +unsigned long size,u64 flags);extern int perf_aux_output_skip (struct perf_output_handle *handle,unsigned long size);extern void *perf_get_aux (struct perf_output_handle *handle);
@@ -1265,7 +1265,7 @@ perf_aux_output_begin(struct perf_output_handle *handle, struct perf_event *event) { return NULL; }static inline void perf_aux_output_end (struct perf_output_handle *handle,unsigned long size, -bool truncated) { } +u64 flags) { }static inline int perf_aux_output_skip (struct perf_output_handle *handle,unsigned long size) {return -EINVAL ; }
kernel/events/ring_buffer.c +5 -7
@@ -410,15 +410,11 @@ EXPORT_SYMBOL_GPL(perf_aux_output_begin);* transaction must be stopped and therefore drop the AUX reference count. */ void perf_aux_output_end (struct perf_output_handle *handle,unsigned long size, -bool truncated) +u64 flags) {struct ring_buffer *rb = handle->rb; -bool wakeup = truncated; +bool wakeup = !!flags;unsigned long aux_head; -u64 flags =0 ; - -if (truncated) - flags |=PERF_AUX_FLAG_TRUNCATED ;/* in overwrite mode, driver provides aux_head via handle */ if (rb->aux_overwrite) {
@@ -427,6 +423,8 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size, aux_head = handle->head;local_set (&rb->aux_head, aux_head); }else { + flags &= ~PERF_AUX_FLAG_OVERWRITE ; + aux_head =local_read (&rb->aux_head);local_add (size, &rb->aux_head); }
@@ -447,7 +445,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size, }if (wakeup) { -if (truncated) +if (flags &PERF_AUX_FLAG_TRUNCATED ) handle->event->pending_disable =1 ;perf_output_wakeup (handle); }
Signature · 1 line
2.1.4
RFC PATCH v2 8/10 perf/core: Add PERF_AUX_FLAG_COLLISION to report colliding samples
In reply to Will DeaconThe ARM SPE architecture permits an implementation to ignore a sample if the sample is due to be taken whilst another sample is already being produced. In this case, it is desirable to report the collision to userspace, as they may want to lower the sample period.
This patch adds a PERF_AUX_FLAG_COLLISION flag, so that such events can be relayed to userspace.
--- include/uapi/linux/perf_event.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/perf_event.h +1 -0
@@ -885,6 +885,7 @@ enum perf_callchain_context {*/ #define PERF_AUX_FLAG_TRUNCATED 0x01/* record was truncated to fit */ #define PERF_AUX_FLAG_OVERWRITE 0x02/* snapshot from overwrite mode */ +#define PERF_AUX_FLAG_COLLISION 0x03/* sample collided with another */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)
Signature · 1 line
2.1.4
RFC PATCH v2 9/10 drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Will DeaconThe ARMv8.2 architecture introduces the optional Statistical Profiling Extension (SPE).
SPE can be used to profile a population of operations in the CPU pipeline after instruction decode. These are either architected instructions (i.e. a dynamic instruction trace) or CPU-specific uops and the choice is fixed statically in the hardware and advertised to userspace via caps/. Sampling is controlled using a sampling interval, similar to a regular PMU counter, but also with an optional random perturbation to avoid falling into patterns where you continuously profile the same instruction in a hot loop.
After each operation is decoded, the interval counter is decremented. When it hits zero, an operation is chosen for profiling and tracked within the pipeline until it retires. Along the way, information such as TLB lookups, cache misses, time spent to issue etc is captured in the form of a sample. The sample is then filtered according to certain criteria (e.g. load latency) that can be specified in the event config (described under format/) and, if the sample satisfies the filter, it is written out to memory as a record, otherwise it is discarded. Only one operation can be sampled at a time.
The in-memory buffer is linear and virtually addressed, raising an interrupt when it fills up. The PMU driver handles these interrupts to give the appearance of a ring buffer, as expected by the AUX code.
The in-memory trace-like format is self-describing (though not parseable in reverse) and written as a series of records, with each record corresponding to a sample and consisting of a sequence of packets. These packets are defined by the architecture, although some have CPU-specific fields for recording information specific to the microarchitecture.
As a simple example, a record generated for a branch instruction may consist of the following packets:
0 (Address) : Virtual PC of the branch instruction
1 (Type) : Conditional direct branch
2 (Counter) : Number of cycles taken from Dispatch to Issue 3 (Address) : Virtual branch target + condition flags 4 (Counter) : Number of cycles taken from Dispatch to Complete 5 (Events) : Mispredicted as not-taken
6 (END) : End of record
It is also possible to toggle properties such as timestamp packets in each record.
This patch adds support for SPE in the form of a new perf driver.
--- drivers/perf/Kconfig | 8 + drivers/perf/Makefile | 1 + drivers/perf/arm_spe_pmu.c | 1244 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1253 insertions(+) create mode 100644 drivers/perf/arm_spe_pmu.c
drivers/perf/Kconfig +8 -0
@@ -19,4 +19,12 @@ config XGENE_PMU help Say y if you want to use APM X-Gene SoC performance monitors. +config ARM_SPE_PMU + tristate "Enable support for the ARMv8.2 Statistical Profiling Extension" + depends on PERF_EVENTS && ARM64 + help + Enable perf support for the ARMv8.2 Statistical Profiling + Extension, which provides periodic sampling of operations in + the CPU pipeline and reports this via the perf AUX interface. + endmenu
drivers/perf/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_ARM_PMU) += arm_pmu.o obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o +obj-$(CONFIG_ARM_SPE_PMU) += arm_spe_pmu.o
drivers/perf/arm_spe_pmu.c new file +1244 -0
1,244 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [RFC PATCH v2 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 1 line · On Fri, 13 Jan 2017 16:03:48 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"
PMU is implied. "arm_spe"?
Quoted 46 lines
drivers/perf/arm_spe_pmu.c new file +46
-0+static int arm_spe_pmu_event_init (struct perf_event *event) +{ +u64 reg; +struct perf_event_attr *attr = &event->attr; +struct arm_spe_pmu *spe_pmu =to_spe_pmu (event->pmu); + +/* This is, of course, deeply driver-specific */ +if (attr->type != event->pmu->type) +return -ENOENT ; + +if (event->cpu >=0 && + !cpumask_test_cpu (event->cpu, &spe_pmu->supported_cpus)) +return -ENOENT ; + +if (arm_spe_event_to_pmsevfr (event) &PMSEVFR_EL1_RES0 ) +return -EOPNOTSUPP ; + +if (event->hw.sample_period < spe_pmu->min_period || + event->hw.sample_period &PMSIRR_EL1_IVAL_MASK ) +return -EOPNOTSUPP ; + +if (attr->exclude_idle) +return -EOPNOTSUPP ; + +/* +* Feedback-directed frequency throttling doesn't work when we +* have a buffer of samples. We'd need to manually count the +* samples in the buffer when it fills up and adjust the event +* count to reflect that. Instead, force the user to specify a +* sample period instead. +*/ +if (attr->freq) +return -EINVAL ; + +if (is_kernel_in_hyp_mode ()) { +if (attr->exclude_kernel != attr->exclude_hv) +return -EOPNOTSUPP ; + }else if (!attr->exclude_hv) { +return -EOPNOTSUPP ; + } + + reg =arm_spe_event_to_pmsfcr (event); +if ((reg &BIT (PMSFCR_EL1_FE_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_EVT )) +return -EOPNOTSUPP ; +
drivers/perf/arm_spe_pmu.c line 707
Quoted 10 lines
drivers/perf/arm_spe_pmu.c new file +10
-0+if ((reg &BIT (PMSFCR_EL1_FT_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_TYP )) +return -EOPNOTSUPP ; + +if ((reg &BIT (PMSFCR_EL1_FL_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_LAT )) +return -EOPNOTSUPP ; + +return 0 ; +}
Please insert pr_* statements before blindly returning errors before a better facility becomes available.
Thanks,
Kim
Re: [RFC PATCH v2 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 6 lines · Kim Phillips
Quoted 1 line · On Fri, 13 Jan 2017 16:03:48 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"PMU is implied. "
arm_spe"?
As stated before, I'm going for consistency here. Is it causing any real issues on the tooling side?
Quoted 17 lines
Quoted 17 lines
drivers/perf/arm_spe_pmu.c new file +17
-0+if (is_kernel_in_hyp_mode ()) { +if (attr->exclude_kernel != attr->exclude_hv) +return -EOPNOTSUPP ; + }else if (!attr->exclude_hv) { +return -EOPNOTSUPP ; + } + + reg =arm_spe_event_to_pmsfcr (event); +if ((reg &BIT (PMSFCR_EL1_FE_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_EVT )) +return -EOPNOTSUPP ; + +if ((reg &BIT (PMSFCR_EL1_FT_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_TYP )) +return -EOPNOTSUPP ; + + if ((reg & BIT(PMSFCR_EL1_FL_SHIFT)) &&
Quoted 8 lines
drivers/perf/arm_spe_pmu.c line 707
Quoted 5 lines
drivers/perf/arm_spe_pmu.c new file +5
-0+ !(spe_pmu->features & SPE_PMU_FEAT_FILT_LAT)) + return -EOPNOTSUPP; + +return 0 ; +}Please insert pr_* statements before blindly returning errors before a better facility becomes available.
That was discussed in the thread I linked to last time:
https://lkml.org/lkml/2015/8/26/661
and there are good reasons not to add those prints.
Will
Re: [RFC PATCH v2 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 9 lines · On Fri, 13 Jan 2017 17:03:07 +0000 Will Deacon <[email protected]> wrote:
Quoted 6 lines · Kim Phillips
Quoted 1 line · On Fri, 13 Jan 2017 16:03:48 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"PMU is implied. "
arm_spe"?As stated before, I'm going for consistency here.
me too, but apparently under the user-visible interface domain rather than the driver source path domain.
Quoted 2 lines
Is it causing any
real issues on the tooling side?
Intel has a consistent "intel_pt", "intel_bts", and 'pmu' occurs nowhere in their nomenclature.
Whether good or bad, we currently have "cs_etm". This patch now gives us "arm_spe_pmu". I'm just trying to save the suffix consistency for now, esp. since IDK how amenable "cs_etm" is to change, and 'perf list' calls things "PMU event"s anyway.
I think the root cause might be the device tree node's "arm,arm-spe-pmu-v1" compatiblity string, which I also find a bit self-redundant ("arm,arm-"), but I'm not familiar with what's being denoted there either (e.g., if the latter 'arm-' is an arch reference, then SPE's might be 'armv8'?). The device tree node isn't exposed to the user, however.
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
drivers/perf/arm_spe_pmu.c new file +17
-0+if (is_kernel_in_hyp_mode ()) { +if (attr->exclude_kernel != attr->exclude_hv) +return -EOPNOTSUPP ; + }else if (!attr->exclude_hv) { +return -EOPNOTSUPP ; + } + + reg =arm_spe_event_to_pmsfcr (event); +if ((reg &BIT (PMSFCR_EL1_FE_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_EVT )) +return -EOPNOTSUPP ; + +if ((reg &BIT (PMSFCR_EL1_FT_SHIFT )) && + !(spe_pmu->features &SPE_PMU_FEAT_FILT_TYP )) +return -EOPNOTSUPP ; + + if ((reg & BIT(PMSFCR_EL1_FL_SHIFT)) &&Quoted 8 lines
drivers/perf/arm_spe_pmu.c line 707
Quoted 5 lines
drivers/perf/arm_spe_pmu.c new file +5
-0+ !(spe_pmu->features & SPE_PMU_FEAT_FILT_LAT)) + return -EOPNOTSUPP; + +return 0 ; +}Please insert pr_* statements before blindly returning errors before a better facility becomes available.
Quoted 3 lines
That was discussed in the thread I linked to last time:
ok, thanks for pinpointing the exact message this time.
Quoted 1 line
and there are good reasons not to add those prints.
Processing that message (indentations are now quoting Peter Zijlstra):
Quoted 2 lines
Not really. That is something that's limited to root. Whereas the problem is very much wider than that.
For the purposes of the SPE driver discussion, I'm ok limiting the context of using the SPE as root.
Quoted 3 lines
If you set one bit wrong in the pretty large
perf_event_attryou've got a fair chance of getting-EINVALon trying to create the event. Good luck finding what you did wrong.
yes, this is the problem, and the SPE introduces a whole new set of validity requirements that should be being communicated clearly, e.g., its restrictive event frequency specification.
Quoted 2 lines
Any user can create events (for their own tasks), this does not require root.
I don't think this is relevant to our discussion.
Quoted 1 line
Allowing users to flip your @debugging flag would be an insta DoS.
I think this is a reference to the non-root case, and might be mitigated by either using dynamic or ratelimited pr_ versions if it were.
Quoted 2 lines
Furthermore, its very unfriendly in that you have to (manually) go correlate random dmesg output with some program action.
Andrew Morton addresses this, and I did read all other follow-ups and still conclude that adding pr_ messages is 1000x better than not, for the user, and at least for the time being.
Kim
RFC PATCH v2 10/10 dt-bindings: Document devicetree binding for ARM SPE
In reply to Will DeaconThis patch documents the devicetree binding in use for ARM SPE.
--- Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txt
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +20 -0
@@ -0,0 +1,20 @@ +* ARMv8.2 Statistical Profiling Extension (SPE) Performance Monitor Units (PMU) + +ARMv8.2 introduces the optional Statistical Profiling Extension for collecting +performance sample data using an in-memory trace buffer. + +** SPE Required properties: + +- compatible : should be one of: + "arm,arm-spe-pmu-v1" + +- interrupts : Exactly 1 PPI must be listed. For heterogeneous systems where + SPE is only supported on a subset of the CPUs, please consult + the arm,gic-v3 binding for details on describing a PPI partition. + +** Example: + +spe-pmu { + compatible = "arm,arm-spe-pmu-v1"; + interrupts = <GIC_PPI 05 IRQ_TYPE_EDGE_RISING &part1>; +};
Signature · 1 line
2.1.4
Mark Rutland
maintainerRe: [RFC PATCH v2 10/10] dt-bindings: Document devicetree binding for ARM SPE
Quoted 16 lines · Will Deacon
This patch documents the devicetree binding in use for ARM SPE.
Cc Mark Rutland <[email protected]>Cc Rob Herring <[email protected]>Signed-off-by Will Deacon <[email protected]>--- Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txtDocumentation/devicetree/bindings/arm/spe-pmu.txt new file +0
-0
Documentation/devicetree/bindings/arm/spe-pmu.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +9
-0@@ -0,0 +1,20 @@ +* ARMv8.2 Statistical Profiling Extension (SPE) Performance Monitor Units (PMU) + +ARMv8.2 introduces the optional Statistical Profiling Extension for collecting +performance sample data using an in-memory trace buffer. + +** SPE Required properties: + +- compatible : should be one of: + "arm,arm-spe-pmu-v1"
The second "arm" here doesn't seem to add much. Should that be "armv8.2" instead?
That would roughly match what we do with the architected timers to describe the specific architectural version.
Otherwise, this looks fine to me.
Thanks,
Mark.
Quoted 13 lines
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +10
-0+- interrupts : Exactly 1 PPI must be listed. For heterogeneous systems where + SPE is only supported on a subset of the CPUs, please consult + the arm,gic-v3 binding for details on describing a PPI partition. + +** Example: + +spe-pmu { + compatible = "arm,arm-spe-pmu-v1"; + interrupts = <GIC_PPI 05 IRQ_TYPE_EDGE_RISING &part1>; +};Signature · 1 line
2.1.4
Re: [RFC PATCH v2 10/10] dt-bindings: Document devicetree binding for ARM SPE
Quoted 21 lines · Mark Rutland
Quoted 20 lines · Will Deacon
This patch documents the devicetree binding in use for ARM SPE.
Cc Mark Rutland <[email protected]>Cc Rob Herring <[email protected]>Signed-off-by Will Deacon <[email protected]>--- Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txtDocumentation/devicetree/bindings/arm/spe-pmu.txt new file +4
-0@@ -0,0 +1,20 @@ +* ARMv8.2 Statistical Profiling Extension (SPE) Performance Monitor Units (PMU) + +ARMv8.2 introduces the optional Statistical Profiling Extension for collecting +performance sample data using an in-memory trace buffer.
Quoted 8 lines
Documentation/devicetree/bindings/arm/spe-pmu.txt line 9
Quoted 5 lines
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +5
-0+ +** SPE Required properties: + +- compatible : should be one of: + "arm,arm-spe-pmu-v1"The second "arm" here doesn't seem to add much. Should that be "armv8.2" instead?
I don't think armv8.2 is particularly helpful, because that effectively ties together the SPE version and the architecture version, which I don't think is strictly required. The reason I added it was so that you could describe a partner implementation as something like:
acme,arm-spe-pmu-v1
and know that it was acme's implementation of an ARM architectural feature.
If I drop the second "arm", I was worried that it might conflict with other namespaces (e.g. acme's signal-processing-element's power-management-unit).
What do you reckon?
Will
Re: [RFC PATCH v2 10/10] dt-bindings: Document devicetree binding for ARM SPE
Quoted 8 lines · On Mon, 16 Jan 2017 10:59:04 +0000 Will Deacon <[email protected]> wrote:
Quoted 6 lines · Mark Rutland
Documentation/devicetree/bindings/arm/spe-pmu.txt line 9
Quoted 2 lines · Will Deacon
+- compatible : should be one of:
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +1
-0+ "arm,arm-spe-pmu-v1"The second "arm" here doesn't seem to add much. Should that be "armv8.2" instead?
Quoted 8 lines
I don't think armv8.2 is particularly helpful, because that effectively ties together the SPE version and the architecture version, which I don't think is strictly required. The reason I added it was so that you could describe a partner implementation as something like:
acme,arm-spe-pmu-v1
and know that it was acme's implementation of an ARM architectural feature.
Wouldn't such an implementation be compatible with an "arm,arm-spe-pmu-v1" (or one with less "arm"s)?
Quoted 2 lines
If I drop the second "arm", I was worried that it might conflict with other namespaces (e.g. acme's signal-processing-element's power-management-unit).
I'd personally let them worry about that, esp. because this problem would come up first and hopefully be fixed in the marketing domain before it reaches its device tree specification stage.
Kim
Mark Rutland
maintainerRe: [RFC PATCH v2 10/10] dt-bindings: Document devicetree binding for ARM SPE
Quoted 14 lines · Kim Phillips
Quoted 13 lines · On Mon, 16 Jan 2017 10:59:04 +0000 Will Deacon <[email protected]> wrote:
Quoted 6 lines · Mark Rutland
Documentation/devicetree/bindings/arm/spe-pmu.txt line 9
Quoted 2 lines · Will Deacon
+- compatible : should be one of:
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +1
-0+ "arm,arm-spe-pmu-v1"The second "arm" here doesn't seem to add much. Should that be "armv8.2" instead?
I don't think armv8.2 is particularly helpful, because that effectively ties together the SPE version and the architecture version, which I don't think is strictly required. The reason I added it was so that you could describe a partner implementation as something like:
Quoted 6 lines
Quoted 3 lines
acme,arm-spe-pmu-v1
and know that it was acme's implementation of an ARM architectural feature.
Wouldn't such an implementation be compatible with an "arm,arm-spe-pmu-v1" (or one with less "arm"s)?
We'd expect that, but in the case of significant divergence (e.g. errata), we may not expect the fallback to the ARM compatible string.
That said, I'm not keen on the duplicate "arm" here, regardless.
Quoted 6 lines
Quoted 2 lines
If I drop the second "arm", I was worried that it might conflict with other namespaces (e.g. acme's signal-processing-element's power-management-unit).
I'd personally let them worry about that, esp. because this problem would come up first and hopefully be fixed in the marketing domain before it reaches its device tree specification stage.
FWIW, I think that marketing is completely unrelated.
I can imagine we might have a clash, but I suspect it's unlikely if we have enough oversight of the bindings (i.e. so long as we keep an eye out, and the DT maintainers get Cc'd on anything likely to clash).
Thanks,
Mark.
Mark Rutland
maintainerRe: [RFC PATCH v2 10/10] dt-bindings: Document devicetree binding for ARM SPE
In reply to Will DeaconQuoted 31 lines · Will Deacon
Quoted 21 lines · Mark Rutland
Quoted 20 lines · Will Deacon
This patch documents the devicetree binding in use for ARM SPE.
Cc Mark Rutland <[email protected]>Cc Rob Herring <[email protected]>Signed-off-by Will Deacon <[email protected]>--- Documentation/devicetree/bindings/arm/spe-pmu.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/spe-pmu.txtDocumentation/devicetree/bindings/arm/spe-pmu.txt new file +4
-0@@ -0,0 +1,20 @@ +* ARMv8.2 Statistical Profiling Extension (SPE) Performance Monitor Units (PMU) + +ARMv8.2 introduces the optional Statistical Profiling Extension for collecting +performance sample data using an in-memory trace buffer.Quoted 8 lines
Documentation/devicetree/bindings/arm/spe-pmu.txt line 9
Quoted 5 lines
Documentation/devicetree/bindings/arm/spe-pmu.txt new file +5
-0+ +** SPE Required properties: + +- compatible : should be one of: + "arm,arm-spe-pmu-v1"The second "arm" here doesn't seem to add much. Should that be "armv8.2" instead?
Quoted 3 lines
I don't think armv8.2 is particularly helpful, because that effectively ties together the SPE version and the architecture version, which I don't think is strictly required.
Sure; I was mostly going by the example of the generic timer (which changed somewhat between ARMv7 and ARMv8), but if SPE is somewhat decoupled from ARMv8.2 that's not a big concern.
Quoted 6 lines
The reason I added it was so that you could describe a partner implementation as something like:
acme,arm-spe-pmu-v1
and know that it was acme's implementation of an ARM architectural feature.
We don't seem to do this for the SMMU, or elsewhere that I am aware of.
Quoted 2 lines
If I drop the second "arm", I was worried that it might conflict with other namespaces (e.g. acme's signal-processing-element's power-management-unit).
That does sound possible.
Another way of avoiding this would be to expand "spe" (and we can drop "pmu", since that's not actually part of the SPE name, and implied anyhow).
How would you feel about:
"arm,statisitical-profiling-extension-v1"
Thanks,
Mark.