Add support for the ARMv8.2 Statistical Profiling Extension
Subsystems (9)
cover Add support for the ARMv8.2 Statistical Profiling Extension
Hi all,
This RFC series adds support for the ARMv8.2 Statistical Profiling Extension (SPE) to Linux in the form of a perf PMU driver. There aren't any userspace patches for perf tool yet, but Kim (on CC) is working on those and I thought posting the kernel side as an RFC was still worth it in the meantime.
The series is structured as:
1-2: Tweak arm64 CPU feature detection to support heterogeneous
configurations where CPUs have differ in debug and profiling capabilities.
3-4: Add EL2 SPE support (KVM world switch and initialisation)
5-6: Export some functions to modules, so this driver can be built as
a loadable module.
7-8: Introduce PERF_AUX_FLAG_COLLISION
9-10: Add the actual PMU driver and devicetree binding
Like intel-pt, the interface to the PMU is via the perf AUX area and the profiling hardware writes directly to the pages mapped by userspace. The hardware capabilities (caps/) and config field encodings (format/) are advertised via sysfs.
Patches based on v4.10-rc2 and tested on an ARM FastModel.
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 | 1247 +++++++++++++++++++++ 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, 1416 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 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
Re: [RFC PATCH 01/10] arm64: cpufeature: allow for version discrepancy in PMU implementations
Quoted 6 lines · Will Deacon
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.
Reviewed-by Suzuki K Poulose <[email protected]>Signed-off-by Will Deacon <[email protected]>
There are remaining issues with PMU support exposed to KVM guests in hetereogeneous systems, but I think that's a larger issue with KVM and heterogeneous CPUs (and we're already aware of it), so FWIW:
Thanks,
Mark.
Quoted 24 lines
--- 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 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
Re: [RFC PATCH 02/10] arm64: cpufeature: Don't enforce system-wide SPE capability
Quoted 9 lines · Will Deacon
The 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.
Reviewed-by Suzuki Poulose <[email protected]>Signed-off-by Will Deacon <[email protected]>
I couldn't find this in the ARMV8.1 supplement, but it is in the SPE spec. FWIW:
Quoted 22 lines
--- 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 12arch/arm64/kernel/cpufeature.c +0
-0
arch/arm64/kernel/cpufeature.c static const struct arm64_ftr_bits ftr_id_mmfr0[] = { · line 183
Quoted 5 lines
arch/arm64/kernel/cpufeature.c +1
-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 ),
As a heads-up, this line will disappear with Suzuki's cpufeature updates series, so you may spot a clash later on.
Thanks,
Mark.
Quoted 7 lines
arch/arm64/kernel/cpufeature.c +1
-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 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
RFC PATCH 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
RFC PATCH 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
RFC PATCH 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 (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 (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 (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 (perf_get_aux);#define PERF_AUX_GFP (GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY)
Signature · 1 line
2.1.4
Peter Zijlstra
maintainerRe: [RFC PATCH 06/10] perf/core: Export AUX buffer helpers to modules
Review
Quoted 4 lines · Will Deacon
(quoted diff) +4
-0+EXPORT_SYMBOL(perf_aux_output_begin); +EXPORT_SYMBOL(perf_aux_output_end); +EXPORT_SYMBOL(perf_aux_output_skip); +EXPORT_SYMBOL(perf_get_aux);
$ git grep EXPORT kernel/events/ kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_disable); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_enable); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_addr_filters_sync); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_refresh); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_release_kernel); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_read_value); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_swevent_get_recursion_context); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_trace_run_bpf_submit); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_tp_event); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_pmu_register); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_pmu_unregister); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_create_kernel_counter); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_pmu_migrate_context); kernel/events/core.c:EXPORT_SYMBOL_GPL(perf_event_sysfs_show); kernel/events/hw_breakpoint.c:EXPORT_SYMBOL_GPL(register_user_hw_breakpoint); kernel/events/hw_breakpoint.c:EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint); kernel/events/hw_breakpoint.c:EXPORT_SYMBOL_GPL(unregister_hw_breakpoint); kernel/events/hw_breakpoint.c:EXPORT_SYMBOL_GPL(register_wide_hw_breakpoint); kernel/events/hw_breakpoint.c:EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint); kernel/events/uprobes.c:EXPORT_SYMBOL_GPL(uprobe_register); kernel/events/uprobes.c:EXPORT_SYMBOL_GPL(uprobe_unregister);
I see a distinct difference here... :-)
RFC PATCH 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(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 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 9/10 drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Will DeaconThe ARMv8.2 architecture introduces the Statistical Profiling Extension (SPE). SPE provides a way to configure and collect profiling samples from the CPU in the form of a trace buffer, which can be mapped directly into userspace using the perf AUX buffer infrastructure.
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 | 1247 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1256 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 +1247 -0
1,247 lines not on this page · raw message
Signature · 1 line
2.1.4
Peter Zijlstra
maintainerRe: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 7 lines · Will Deacon
The ARMv8.2 architecture introduces the Statistical Profiling Extension (SPE). SPE provides a way to configure and collect profiling samples from the CPU in the form of a trace buffer, which can be mapped directly into userspace using the perf AUX buffer infrastructure.
This patch adds support for SPE in the form of a new perf driver.
Can you give a little high level overview of what exactly SPE is?
Re: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Hi Peter,
Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · Will Deacon
The ARMv8.2 architecture introduces the Statistical Profiling Extension (SPE). SPE provides a way to configure and collect profiling samples from the CPU in the form of a trace buffer, which can be mapped directly into userspace using the perf AUX buffer infrastructure.
This patch adds support for SPE in the form of a new perf driver.
Can you give a little high level overview of what exactly SPE is?
Sure, I can try, although there is no public documentation yet so it's a bit fiddly.
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
You can also toggle things like timestamp packets in each record.
Since SPE is an optional extension to the architecture, I'm sure there will be big.LITTLE systems where only one of the clusters has SPE support, so the driver is slightly complicated by handling that.
Will
Peter Zijlstra
maintainerRe: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 56 lines · Will Deacon
Hi Peter,
Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · Will Deacon
The ARMv8.2 architecture introduces the Statistical Profiling Extension (SPE). SPE provides a way to configure and collect profiling samples from the CPU in the form of a trace buffer, which can be mapped directly into userspace using the perf AUX buffer infrastructure.
This patch adds support for SPE in the form of a new perf driver.
Can you give a little high level overview of what exactly SPE is?
Sure, I can try, although there is no public documentation yet so it's a bit fiddly.
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
Quoted 5 lines
You can also toggle things like timestamp packets in each record.
Since SPE is an optional extension to the architecture, I'm sure there will be big.LITTLE systems where only one of the clusters has SPE support, so the driver is slightly complicated by handling that.
Hmm, on first reading that sounds a bit like a combination of AMD-IBS and Intel-PEBS. PEBS has the memory buffer, but we keep that private to the implementation, we rewrite the events into 'normal' perf SAMPLE records on interrupt and context switch. IBS otoh doesn't have the memory buffer but does similar things like tagging u-ops and providing various metrics, which are exposed as is through SAMPLE_RAW.
I have no immediate objection to using AUX for this though, its arguably similar to SAMPLE_RAW and makes sense since you have a memory buffer already.
We also have an AUX enabled driver for Intel-BTS, which is similar to PEBS but records branch traces (the precursor to PT in a sense).
Re: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Will DeaconQuoted 1 line · On Tue, 3 Jan 2017 18:10:26 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"
Based on Intel naming "intel_pt" and "intel_bts', I had expected "arm-spe" as the universal basename for SPE. I don't really care about whether '_pmu' is included, but it's yet another naming inconsistency we have with coresight's "cs_etm" (the other being prefixed with "arm_").
Also, nit, since I don't know why perf userspace tools can't handle dashes in PMU names (commit 3d1ff755e367 "arm: perf: clean up PMU names" doesn't say), can we at least start to use dashes in our filenames? arm-spe-pmu.c is easier to type than arm_spe_pmu.c.
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 710
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 ; +}
Without being provided instructions on how to use, I had to add debug printks here to find out e.g., an event period *must* be specified with record -c, and then again to find out that only a certain set of numbers is allowed by the h/w (256, 512, etc.). Is it possible to report why the driver is returning an error before it does? Otherwise, all the user sees is, e.g.:
Error:
The sys_perf_event_open() syscall returned with 19 (No such device) for event (arm_spe_pmu_0). /bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?
...and, in this case, with nothing in dmesg. And, IIRC, the above text is emitted only if perf is run with -v and/or built with DEBUG set. Granted, *that* problem is not explicitly relevant to this patch, but new drivers should nevertheless express their usage details better.
Also, curiously, arm_spe_pmu doesn't appear in 'perf list' (even when SPE h/w is present).
Other than that, this gets my:
Thanks,
Kim
Re: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Hi Kim,
Quoted 9 lines · Kim Phillips
Quoted 1 line · On Tue, 3 Jan 2017 18:10:26 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"Based on Intel naming "
intel_pt" and "intel_bts', I had expected "arm-spe" as the universal basename for SPE. I don't really care about whether '_pmu' is included, but it's yet another naming inconsistency we have with coresight's "cs_etm" (the other being prefixed with "arm_").
It's consistent with the other PMUs under drivers/perf.
Quoted 4 lines
Also, nit, since I don't know why perf userspace tools can't handle dashes in PMU names (commit
3d1ff755e367"arm: perf: clean up PMU names" doesn't say), can we at least start to use dashes in our filenames?arm-spe-pmu.cis easier to type thanarm_spe_pmu.c.
I'd rather go for consistency both with the other PMU drivers under drivers/perf, but also with the PMU name itself.
Quoted 69 lines
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 710
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 ; +}Without being provided instructions on how to use, I had to add debug printks here to find out e.g., an event period *must* be specified with record -c, and then again to find out that only a certain set of numbers is allowed by the h/w (256, 512, etc.). Is it possible to report why the driver is returning an error before it does? Otherwise, all the user sees is, e.g.:
Error:
Thesys_perf_event_open()syscall returned with 19 (No such device) for event (arm_spe_pmu_0)./bin/dmesgmay provide additional information.
NoCONFIG_PERF_EVENTS=ykernel support configured?
Quoted 4 lines
...and, in this case, with nothing in dmesg. And, IIRC, the above text is emitted only if perf is run with -v and/or built with DEBUG set. Granted, *that* problem is not explicitly relevant to this patch, but new drivers should nevertheless express their usage details better.
I don't disagree that the error reporting from the driver up to userspace leaves much to be desired, but there currently isn't a sensible way to communicate the exact reason for failure back from event_init and I don't think we're different to other PMU drivers in this respect. Yes, you can paper around the problem using pr_debug, but that really only helps the developer writing the perf tool support, and much of the constraints can also be inferred from the architecture spec.
There were patches to allow providing strings back via perf_err:
https://lkml.org/lkml/2015/8/24/506
but I don't think it ended up getting merged. Other subsystems wanted to use the same approach, and there are ABI considerations with all of this (the thread is worth a read).
Quoted 2 lines
Also, curiously,
arm_spe_pmudoesn't appear in 'perf list' (even when SPE h/w is present).
Weird, it would be nice to understand why that is. The sysfs plumbing should all be there, so I'd expect to see something. On my laptop, for example, intel_pt appears as:
intel_pt// [Kernel PMU event]
and strace show perf doing the following:
stat("/sys/bus/event_source/devices/intel_pt/format", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0 open("/sys/bus/event_source/devices/intel_pt/format", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 82 open("/sys/bus/event_source/devices/intel_pt/format/psb_period", O_RDONLY) = 83 open("/sys/bus/event_source/devices/intel_pt/format/noretcomp", O_RDONLY) = 83 open("/sys/bus/event_source/devices/intel_pt/format/tsc", O_RDONLY) = 83 open("/sys/bus/event_source/devices/intel_pt/format/cyc_thresh", O_RDONLY) = 83 open("/sys/bus/event_source/devices/intel_pt/format/mtc_period", O_RDONLY) = 83 open("/sys/bus/event_source/devices/intel_pt/format/cyc", O_RDONLY) = 83 open("/sys/bus/event_source/devices/intel_pt/format/mtc", O_RDONLY) = 83 stat("/sys/bus/event_source/devices/intel_pt/events", 0x7ffe54eebb40) = -1 ENOENT (No such file or directory) stat("/sys/bus/event_source/devices/intel_pt/type", {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0 open("/sys/bus/event_source/devices/intel_pt/type", O_RDONLY) = 82 stat("/sys/bus/event_source/devices/intel_pt/cpumask", 0x7ffe54eedd60) = -1 ENOENT (No such file or directory) stat("/sys/bus/event_source/devices/intel_pt/cpus", 0x7ffe54eedd60) = -1 ENOENT (No such file or directory) stat("/sys/bus/event_source/devices/intel_pt/caps/mtc", {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0 open("/sys/bus/event_source/devices/intel_pt/caps/mtc", O_RDONLY) = 82 stat("/sys/bus/event_source/devices/intel_pt/caps/psb_cyc", {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0 open("/sys/bus/event_source/devices/intel_pt/caps/psb_cyc", O_RDONLY) = 82
What do you see for SPE?
Quoted 3 lines
Other than that, this gets my:
Tested-by Kim Phillips <[email protected]>
Thanks!
Will
Re: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 15 lines · On Wed, 11 Jan 2017 12:37:15 +0000 Will Deacon <[email protected]> wrote:
Hi Kim,
Quoted 9 lines · Kim Phillips
Quoted 1 line · On Tue, 3 Jan 2017 18:10:26 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"Based on Intel naming "
intel_pt" and "intel_bts', I had expected "arm-spe" as the universal basename for SPE. I don't really care about whether '_pmu' is included, but it's yet another naming inconsistency we have with coresight's "cs_etm" (the other being prefixed with "arm_").It's consistent with the other PMUs under
drivers/perf.
Quoted 7 lines
Quoted 4 lines
Also, nit, since I don't know why perf userspace tools can't handle dashes in PMU names (commit
3d1ff755e367"arm: perf: clean up PMU names" doesn't say), can we at least start to use dashes in our filenames?arm-spe-pmu.cis easier to type thanarm_spe_pmu.c.I'd rather go for consistency both with the other PMU drivers under
drivers/perf, but also with the PMU name itself.
Selecting a PMU naming consistency domain based on its driver's source path doesn't accurately represent the naming consistency the user expects. Not to mention there are only 2 out of 44 PMU device registration callsites under drivers/perf...
Quoted 74 lines
Quoted 69 lines
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 710
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 ; +}Without being provided instructions on how to use, I had to add debug printks here to find out e.g., an event period *must* be specified with record -c, and then again to find out that only a certain set of numbers is allowed by the h/w (256, 512, etc.). Is it possible to report why the driver is returning an error before it does? Otherwise, all the user sees is, e.g.:
Error:
Thesys_perf_event_open()syscall returned with 19 (No such device) for event (arm_spe_pmu_0)./bin/dmesgmay provide additional information.
NoCONFIG_PERF_EVENTS=ykernel support configured?Quoted 4 lines
...and, in this case, with nothing in dmesg. And, IIRC, the above text is emitted only if perf is run with -v and/or built with DEBUG set. Granted, *that* problem is not explicitly relevant to this patch, but new drivers should nevertheless express their usage details better.
Quoted 7 lines
I don't disagree that the error reporting from the driver up to userspace leaves much to be desired, but there currently isn't a sensible way to communicate the exact reason for failure back from
event_initand I don't think we're different to other PMU drivers in this respect. Yes, you can paper around the problem usingpr_debug, but that really only helps the developer writing the perf tool support, and much of the constraints can also be inferred from the architecture spec.
This applies to all users of the driver, not just the developer writing the perf tool support. And users definitely shouldn't need to read the architecture spec in order to use the feature.
Quoted 7 lines
There were patches to allow providing strings back via
perf_err:https://lkml.org/lkml/2015/8/24/506
but I don't think it ended up getting merged. Other subsystems wanted to use the same approach, and there are ABI considerations with all of this (the thread is worth a read).
OK I didn't read everything, but meanwhile, we need to be making perf - esp. as it's so clearly pointed out already - to be easier to use in the time being. Like one of the threads' responses, *anything* is better than blindly returning -EINVAL/-ENOTSUPP, etc. Please insert pr_* statements before returning errors.
We can easily migrate from pr_* to perf_err (or equivalent) when perf_err becomes available. Maintenance-wise, it is much more efficient to do this at driver submission time, rather than waiting for perf_err to be merged, since it's likely the code will be in the same place.
Quoted 30 lines
Quoted 2 lines
Also, curiously,
arm_spe_pmudoesn't appear in 'perf list' (even when SPE h/w is present).Weird, it would be nice to understand why that is. The sysfs plumbing should all be there, so I'd expect to see something. On my laptop, for example,
intel_ptappears as:intel_pt// [Kernel PMU event]
and strace show perf doing the following:
stat("/sys/bus/event_source/devices/intel_pt/format", {st_mode=S_IFDIR|0755, st_size=0, ...})= 0open("/sys/bus/event_source/devices/intel_pt/format", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC)= 82open("/sys/bus/event_source/devices/intel_pt/format/psb_period", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/noretcomp", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/tsc", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/cyc_thresh", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/mtc_period", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/cyc", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/mtc", O_RDONLY)= 83stat("/sys/bus/event_source/devices/intel_pt/events", 0x7ffe54eebb40)= -1 ENOENT (No such file or directory)stat("/sys/bus/event_source/devices/intel_pt/type", {st_mode=S_IFREG|0444, st_size=4096, ...})= 0open("/sys/bus/event_source/devices/intel_pt/type", O_RDONLY)= 82stat("/sys/bus/event_source/devices/intel_pt/cpumask", 0x7ffe54eedd60)= -1 ENOENT (No such file or directory)stat("/sys/bus/event_source/devices/intel_pt/cpus", 0x7ffe54eedd60)= -1 ENOENT (No such file or directory)stat("/sys/bus/event_source/devices/intel_pt/caps/mtc", {st_mode=S_IFREG|0444, st_size=4096, ...})= 0open("/sys/bus/event_source/devices/intel_pt/caps/mtc", O_RDONLY)= 82stat("/sys/bus/event_source/devices/intel_pt/caps/psb_cyc", {st_mode=S_IFREG|0444, st_size=4096, ...})= 0open("/sys/bus/event_source/devices/intel_pt/caps/psb_cyc", O_RDONLY)= 82
Quoted 1 line
What do you see for SPE?
2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format", {st_mode=S_IFDIR|0755, st_size=0, ...}, 0) = 0
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 58
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/branch_filter", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/ts_enable", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/pa_enable", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/event_filter", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/load_filter", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/jitter", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/store_filter", O_RDONLY) = 59
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/min_latency", O_RDONLY) = 59
2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/events", 0xffffcd6bb078, 0) = -1 ENOENT (No such file or directory)
2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/type", {st_mode=S_IFREG|0444, st_size=4096, ...}, 0) = 0
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/type", O_RDONLY) = 58
2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/cpumask", {st_mode=S_IFREG|0444, st_size=4096, ...}, 0) = 0
2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/cpumask", O_RDONLY) = 58they're identical up until /.../cpumask's stat, which exists on the ARM SPE run (as opposed to the Intel run).
Kim
Re: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
Quoted 51 lines · Kim Phillips
Quoted 31 lines · On Wed, 11 Jan 2017 12:37:15 +0000 Will Deacon <[email protected]> wrote:
Quoted 2 lines · Kim Phillips
Also, curiously,
arm_spe_pmudoesn't appear in 'perf list' (even when SPE h/w is present).Weird, it would be nice to understand why that is. The sysfs plumbing should all be there, so I'd expect to see something. On my laptop, for example,
intel_ptappears as:intel_pt// [Kernel PMU event]
and strace show perf doing the following:
stat("/sys/bus/event_source/devices/intel_pt/format", {st_mode=S_IFDIR|0755, st_size=0, ...})= 0open("/sys/bus/event_source/devices/intel_pt/format", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC)= 82open("/sys/bus/event_source/devices/intel_pt/format/psb_period", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/noretcomp", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/tsc", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/cyc_thresh", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/mtc_period", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/cyc", O_RDONLY)= 83open("/sys/bus/event_source/devices/intel_pt/format/mtc", O_RDONLY)= 83stat("/sys/bus/event_source/devices/intel_pt/events", 0x7ffe54eebb40)= -1 ENOENT (No such file or directory)stat("/sys/bus/event_source/devices/intel_pt/type", {st_mode=S_IFREG|0444, st_size=4096, ...})= 0open("/sys/bus/event_source/devices/intel_pt/type", O_RDONLY)= 82stat("/sys/bus/event_source/devices/intel_pt/cpumask", 0x7ffe54eedd60)= -1 ENOENT (No such file or directory)stat("/sys/bus/event_source/devices/intel_pt/cpus", 0x7ffe54eedd60)= -1 ENOENT (No such file or directory)stat("/sys/bus/event_source/devices/intel_pt/caps/mtc", {st_mode=S_IFREG|0444, st_size=4096, ...})= 0open("/sys/bus/event_source/devices/intel_pt/caps/mtc", O_RDONLY)= 82stat("/sys/bus/event_source/devices/intel_pt/caps/psb_cyc", {st_mode=S_IFREG|0444, st_size=4096, ...})= 0open("/sys/bus/event_source/devices/intel_pt/caps/psb_cyc", O_RDONLY)= 82Quoted 1 line
What do you see for SPE?
2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format", {st_mode=S_IFDIR|0755, st_size=0, ...}, 0) = 0 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 58 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/branch_filter", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/ts_enable", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/pa_enable", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/event_filter", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/load_filter", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/jitter", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/store_filter", O_RDONLY) = 59 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/format/min_latency", O_RDONLY) = 59 2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/events", 0xffffcd6bb078, 0) = -1 ENOENT (No such file or directory) 2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/type", {st_mode=S_IFREG|0444, st_size=4096, ...}, 0) = 0 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/type", O_RDONLY) = 58 2154 newfstatat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/cpumask", {st_mode=S_IFREG|0444, st_size=4096, ...}, 0) = 0 2154 openat(AT_FDCWD, "/sys/bus/event_source/devices/arm_spe_pmu_0/cpumask", O_RDONLY) = 58
Quoted 4 lines
they're identical up until /.../cpumask's stat, which exists on the ARM SPE run (as opposed to the Intel run).
From a quick look at the perf tool code, it looks like you need to ensure
that pmu->selectable is set to true for SPE, since it doesn't advertise any events (the intel pt and coresight code does this already).
Will
Re: [RFC PATCH 09/10] drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension
In reply to Kim PhillipsQuoted 10 lines · Kim Phillips
Quoted 1 line · On Tue, 3 Jan 2017 18:10:26 +0000 Will Deacon <[email protected]> wrote:
+#define DRVNAME "
arm_spe_pmu"Based on Intel naming "
intel_pt" and "intel_bts', I had expected "arm-spe" as the universal basename for SPE. I don't really care about whether '_pmu' is included, but it's yet another naming inconsistency we have with coresight's "cs_etm" (the other being prefixed with "arm_").
Quoted 4 lines
Also, nit, since I don't know why perf userspace tools can't handle dashes in PMU names (commit
3d1ff755e367"arm: perf: clean up PMU names" doesn't say), can we at least start to use dashes in our filenames?arm-spe-pmu.cis easier to type thanarm_spe_pmu.c.
Fortunately, not everyone is using a UK/US keyboard... ;-)
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
RFC PATCH 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