More fully implement ARM PMUv3
v10 cover More fully implement ARM PMUv3
The ARM PMU implementation currently contains a basic cycle counter, but it is often useful to gather counts of other events, filter them based on execution mode, and/or be notified on counter overflow. These patches flesh out the implementations of various PMU registers including PM[X]EVCNTR and PM[X]EVTYPER, add a struct definition to represent arbitrary counter types, implement mode filtering, send interrupts on counter overflow, and add instruction, cycle, and software increment events.
Since v9 [1] I have made the following changes:
* Added a clarifying comment about how the PMU timer's migration is handled
* Added a check against implementing PMCEID[23] if ID_DFR0.PerfMon == 0xf
* Added TRACEFILT to the ID_DFR0 field definitions
[1] - https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg00805.html
Aaron Lindsay (14):
migration: Add post_save function to VMStateDescription target/arm: Reorganize PMCCNTR accesses
target/arm: Swap PMU values before/after migrations target/arm: Filter cycle counter based on PMCCFILTR_EL0 target/arm: Allow AArch32 access for PMCCFILTR target/arm: Implement PMOVSSET
target/arm: Define FIELDs for ID_DFR0
target/arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23] target/arm: Add array for supported PMU events, generate
PMCEID[01]_EL0
target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER target/arm: PMU: Add instruction and cycle events target/arm: PMU: Set PMCR.N to 4
target/arm: Implement PMSWINC
target/arm: Send interrupts on PMU counter overflow
docs/devel/migration.rst | 9 +- include/migration/vmstate.h | 1 + migration/vmstate.c | 13 +- target/arm/cpu.c | 28 +- target/arm/cpu.h | 81 +++- target/arm/cpu64.c | 4 - target/arm/helper.c | 808 ++++++++++++++++++++++++++++++++---- target/arm/machine.c | 24 ++ 8 files changed, 863 insertions(+), 105 deletions(-)
Signature · 1 line
2.19.2
PATCH v10 1/14 migration: Add post_save function to VMStateDescription
In some cases it may be helpful to modify state before saving it for migration, and then modify the state back after it has been saved. The existing pre_save function provides half of this functionality. This patch adds a post_save function to provide the second half.
--- docs/devel/migration.rst | 9 +++++++-- include/migration/vmstate.h | 1 + migration/vmstate.c | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-)
docs/devel/migration.rst +7 -2
@@ -419,8 +419,13 @@ The functions to do that are inside a vmstate definition, and are called: This function is called before we save the state of one device. -Example: You can look at hpet.c, that uses the three function to -massage the state that is transferred. +- ``int (*post_save)(void *opaque);`` + + This function is called after we save the state of one device + (even upon failure, unless the call to pre_save returned an error). + +Example: You can look at hpet.c, that uses the first three functions +to massage the state that is transferred. The ``VMSTATE_WITH_TMP`` macro may be useful when the migration data doesn't match the stored device data well; it allows an
include/migration/vmstate.h +1 -0
@@ -185,6 +185,7 @@ struct VMStateDescription {int (*pre_load)(void *opaque);int (*post_load)(void *opaque,int version_id);int (*pre_save)(void *opaque); +int (*post_save)(void *opaque);bool (*needed)(void *opaque);const VMStateField *fields;const VMStateDescription **subsections;
migration/vmstate.c +12 -1
@@ -390,6 +390,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,if (ret) {error_report ("Save of field %s/%s failed" , vmsd->name, field->name); +if (vmsd->post_save) { + vmsd->post_save (opaque); + }return ret; }
@@ -415,7 +418,15 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,json_end_array (vmdesc); } -return vmstate_subsection_save (f, vmsd, opaque, vmdesc); + ret =vmstate_subsection_save (f, vmsd, opaque, vmdesc); + +if (vmsd->post_save) { +int ps_ret = vmsd->post_save (opaque); +if (!ret) { + ret = ps_ret; + } + } +return ret; } static const VMStateDescription *
Signature · 1 line
2.19.2
PATCH v10 2/14 target/arm: Reorganize PMCCNTR accesses
In reply to Aaron Lindsaypmccntr_read and pmccntr_write contained duplicate code that was already being handled by pmccntr_sync. Consolidate the duplicated code into two
functions: pmccntr_op_start and pmccntr_op_finish. Add a companion to c15_ccnt in CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensures time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches.
--- target/arm/cpu.h | 37 ++++++++++---- target/arm/helper.c | 114 +++++++++++++++++++++++++++----------------- 2 files changed, 98 insertions(+), 53 deletions(-)
target/arm/cpu.h +29 -8
@@ -468,10 +468,20 @@ typedef struct CPUARMState {uint64_t oslsr_el1;/* OS Lock Status */ uint64_t mdcr_el2;uint64_t mdcr_el3; -/* If the counter is enabled, this stores the last time the counter -* was reset. Otherwise it stores the counter value +/* Stores the architectural value of the counter *the last time it was +* updated* by pmccntr_op_start. Accesses should always be surrounded +* by pmccntr_op_start/pmccntr_op_finish to guarantee the latest +* architecturally-correct value is being read/set. */ uint64_t c15_ccnt; +/* Stores the delta between the architectural value and the underlying +* cycle count during normal operation. It is used to update c15_ccnt +* to be the correct architectural value before accesses. During +* accesses, c15_ccnt_delta contains the underlying count being used +* for the access, after which it reverts to the delta value in +* pmccntr_op_finish. +*/ +uint64_t c15_ccnt_delta;uint64_t pmccfiltr_el0;/* Performance Monitor Filter Register */ uint64_t vpidr_el2;/* Virtualization Processor ID Register */ uint64_t vmpidr_el2;/* Virtualization Multiprocessor ID Register */
@@ -956,15 +966,26 @@ int cpu_arm_signal_handler(int host_signum, void *pinfo, void *puc);/** -* pmccntr_sync +* pmccntr_op_start/finish +* @env: CPUARMState +* +* Convert the counter in the PMCCNTR between its delta form (the typical mode +* when it's enabled) and the guest-visible value. These two calls must always +* surround any action which might affect the counter. +*/ +void pmccntr_op_start (CPUARMState *env); +void pmccntr_op_finish (CPUARMState *env); + +/** +* pmu_op_start/finish * @env: CPUARMState * -* Synchronises the counter in the PMCCNTR. This must always be called twice, -* once before any action that might affect the timer and again afterwards. -* The function is used to swap the state of the register if required. -* This only happens when not in user mode (!CONFIG_USER_ONLY) +* Convert all PMU counters between their delta form (the typical mode when +* they are enabled) and the guest-visible values. These two calls must +* surround any action which might affect the counters. */ -void pmccntr_sync (CPUARMState *env); +void pmu_op_start (CPUARMState *env); +void pmu_op_finish (CPUARMState *env);/* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants
target/arm/helper.c +69 -45
161 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH v10 3/14 target/arm: Swap PMU values before/after migrations
In reply to Aaron LindsayBecause of the PMU's design, many register accesses have side effects which are inter-related, meaning that the normal method of saving CP registers can result in inconsistent state. These side-effects are largely handled in pmu_op_start/finish functions which can be called before and after the state is saved/restored. By doing this and adding raw read/write functions for the affected registers, we avoid migration-related inconsistencies.
--- target/arm/helper.c | 6 ++++-- target/arm/machine.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-)
target/arm/helper.c +4 -2
@@ -1450,11 +1450,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 0, .access = PL0_RW, .accessfn = pmreg_access_ccntr, .type = ARM_CP_IO, - .readfn = pmccntr_read, .writefn = pmccntr_write, }, + .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), + .readfn = pmccntr_read, .writefn = pmccntr_write, + .raw_readfn = raw_read, .raw_writefn = raw_write, },#endif { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, - .writefn = pmccfiltr_write, + .writefn = pmccfiltr_write, .raw_writefn = raw_write, .access = PL0_RW, .accessfn = pmreg_access, .type = ARM_CP_IO, .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0),
target/arm/machine.c +24 -0
@@ -620,6 +620,10 @@ static int cpu_pre_save(void *opaque) {ARMCPU *cpu = opaque; +if (!kvm_enabled ()) { +pmu_op_start (&cpu->env); + } +if (kvm_enabled ()) {if (!write_kvmstate_to_list (cpu)) {/* This should never fail */
@@ -641,6 +645,17 @@ static int cpu_pre_save(void *opaque)return 0 ; } +static int cpu_post_save (void *opaque) +{ +ARMCPU *cpu = opaque; + +if (!kvm_enabled ()) { +pmu_op_finish (&cpu->env); + } + +return 0 ; +} +static int cpu_pre_load (void *opaque) {ARMCPU *cpu = opaque;
@@ -653,6 +668,10 @@ static int cpu_pre_load(void *opaque)*/ env->irq_line_state =UINT32_MAX ; +if (!kvm_enabled ()) { +pmu_op_start (&cpu->env); + } +return 0 ; }
@@ -721,6 +740,10 @@ static int cpu_post_load(void *opaque, int version_id)hw_breakpoint_update_all (cpu);hw_watchpoint_update_all (cpu); +if (!kvm_enabled ()) { +pmu_op_finish (&cpu->env); + } +return 0 ; }
@@ -729,6 +752,7 @@ const VMStateDescription vmstate_arm_cpu = { .version_id = 22, .minimum_version_id = 22, .pre_save = cpu_pre_save, + .post_save = cpu_post_save, .pre_load = cpu_pre_load, .post_load = cpu_post_load, .fields = (VMStateField []) {
Signature · 1 line
2.19.2
PATCH v10 4/14 target/arm: Filter cycle counter based on PMCCFILTR_EL0
In reply to Aaron LindsayRename arm_ccnt_enabled to pmu_counter_enabled, and add logic to only return 'true' if the specified counter is enabled and neither prohibited or filtered.
--- target/arm/cpu.c | 3 ++ target/arm/cpu.h | 10 ++++- target/arm/helper.c | 96 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 101 insertions(+), 8 deletions(-)
target/arm/cpu.c +3 -0
@@ -1020,6 +1020,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)if (!cpu->has_pmu) {unset_feature (env,ARM_FEATURE_PMU ); cpu->id_aa64dfr0 &= ~0xf00 ; + }else if (!kvm_enabled ()) { +arm_register_pre_el_change_hook (cpu, &pmu_pre_el_change,0 ); +arm_register_el_change_hook (cpu, &pmu_post_el_change,0 ); }if (!arm_feature (env,ARM_FEATURE_EL2 )) {
target/arm/cpu.h +9 -1
@@ -987,6 +987,12 @@ void pmccntr_op_finish(CPUARMState *env);void pmu_op_start (CPUARMState *env);void pmu_op_finish (CPUARMState *env); +/** +* Functions to register as EL change hooks for PMU mode filtering +*/ +void pmu_pre_el_change (ARMCPU *cpu,void *ignored); +void pmu_post_el_change (ARMCPU *cpu,void *ignored); +/* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants * for both old and new bit meanings. Code which tests against those
@@ -1048,7 +1054,8 @@ void pmu_op_finish(CPUARMState *env);#define MDCR_EPMAD (1U << 21)#define MDCR_EDAD (1U << 20) -#define MDCR_SPME (1U << 17) +#define MDCR_SPME (1U << 17)/* MDCR_EL3 */ +#define MDCR_HPMD (1U << 17)/* MDCR_EL2 */ #define MDCR_SDD (1U << 16)#define MDCR_SPD (3U << 14)#define MDCR_TDRA (1U << 11)
@@ -1058,6 +1065,7 @@ void pmu_op_finish(CPUARMState *env);#define MDCR_HPME (1U << 7)#define MDCR_TPM (1U << 6)#define MDCR_TPMCR (1U << 5) +#define MDCR_HPMN (0x1fU)/* Not all of the MDCR_EL3 bits are present in the 32-bit SDCR */ #define SDCR_VALID_MASK (MDCR_EPMAD | MDCR_EDAD | MDCR_SPME | MDCR_SPD)
target/arm/helper.c +89 -7
141 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH v10 5/14 target/arm: Allow AArch32 access for PMCCFILTR
In reply to Aaron Lindsay--- target/arm/helper.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
target/arm/helper.c +26 -1
@@ -994,6 +994,10 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { PMXEVTYPER_M | PMXEVTYPER_MT | \ PMXEVTYPER_EVTCOUNT) +#define PMCCFILTR 0xf8000000 +#define PMCCFILTR_M PMXEVTYPER_M +#define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M) +static inline uint32_t pmu_num_counters (CPUARMState *env) {return (env->cp15.c9_pmcr &PMCRN_MASK ) >>PMCRN_SHIFT ;
@@ -1297,10 +1301,26 @@ static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {pmccntr_op_start (env); - env->cp15.pmccfiltr_el0 = value &0xfc000000 ; + env->cp15.pmccfiltr_el0 = value &PMCCFILTR_EL0 ; +pmccntr_op_finish (env); +} + +static void pmccfiltr_write_a32 (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmccntr_op_start (env); +/* M is not accessible from AArch32 */ + env->cp15.pmccfiltr_el0 = (env->cp15.pmccfiltr_el0 &PMCCFILTR_M ) | + (value &PMCCFILTR );pmccntr_op_finish (env); } +static uint64_t pmccfiltr_read_a32 (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* M is not visible in AArch32 */ +return env->cp15.pmccfiltr_el0 &PMCCFILTR ; +} +static void pmcntenset_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
@@ -1536,6 +1556,11 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .readfn = pmccntr_read, .writefn = pmccntr_write, .raw_readfn = raw_read, .raw_writefn = raw_write, },#endif + { .name = "PMCCFILTR", .cp = 15, .opc1 = 0, .crn = 14, .crm = 15, .opc2 = 7, + .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, + .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_ALIAS | ARM_CP_IO, + .resetvalue = 0, }, { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, .writefn = pmccfiltr_write, .raw_writefn = raw_write,
Signature · 1 line
2.19.2
PATCH v10 6/14 target/arm: Implement PMOVSSET
In reply to Aaron LindsayAdd an array for PMOVSSET so we only define it for v7ve+ platforms
--- target/arm/helper.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
target/arm/helper.c +28 -0
@@ -1342,6 +1342,13 @@ static void pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri, env->cp15.c9_pmovsr &= ~value; } +static void pmovsset_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ + value &=pmu_counter_mask (env); + env->cp15.c9_pmovsr |= value; +} +static void pmxevtyper_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
@@ -1709,6 +1716,24 @@ static const ARMCPRegInfo v7mp_cp_reginfo[] = {REGINFO_SENTINEL }; +static const ARMCPRegInfo pmovsset_cp_reginfo[] = { +/* PMOVSSET is not implemented in v7 before v7ve */ + { .name ="PMOVSSET" , .cp =15 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =3 , + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsset_write, + .raw_writefn = raw_write }, + { .name ="PMOVSSET_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =14 , .opc2 =3 , + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsset_write, + .raw_writefn = raw_write }, +REGINFO_SENTINEL +}; +static void teecr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
@@ -5191,6 +5216,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) !arm_feature(env, ARM_FEATURE_PMSA)) {define_arm_cp_regs (cpu, v7mp_cp_reginfo); } +if (arm_feature (env,ARM_FEATURE_V7VE )) { +define_arm_cp_regs (cpu, pmovsset_cp_reginfo); + }if (arm_feature (env,ARM_FEATURE_V7 )) {/* v7 performance monitor control register: same implementor * field as main ID register, and we implement only the cycle
Signature · 1 line
2.19.2
PATCH v10 7/14 target/arm: Define FIELDs for ID_DFR0
In reply to Aaron LindsayThis is immediately necessary for the PMUv3 implementation to check ID_DFR0.PerfMon to enable/disable specific features, but defines the full complement of fields for possible future use elsewhere.
--- target/arm/cpu.h | 9 +++++++++ 1 file changed, 9 insertions(+)
target/arm/cpu.h +9 -0
@@ -1586,6 +1586,15 @@ FIELD(ID_AA64PFR0, GIC, 24, 4) FIELD(ID_AA64PFR0, RAS, 28, 4) FIELD(ID_AA64PFR0, SVE, 32, 4) +FIELD(ID_DFR0, COPDBG, 0, 4) +FIELD(ID_DFR0, COPSDBG, 4, 4) +FIELD(ID_DFR0, MMAPDBG, 8, 4) +FIELD(ID_DFR0, COPTRC, 12, 4) +FIELD(ID_DFR0, MMAPTRC, 16, 4) +FIELD(ID_DFR0, MPROFDBG, 20, 4) +FIELD(ID_DFR0, PERFMON, 24, 4) +FIELD(ID_DFR0, TRACEFILT, 28, 4) +QEMU_BUILD_BUG_ON (ARRAY_SIZE (((ARMCPU *)0 )->ccsidr) <=R_V7M_CSSELR_INDEX_MASK );/* If adding a feature bit which corresponds to a Linux ELF
Signature · 1 line
2.19.2
PATCH v10 8/14 target/arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
In reply to Aaron Lindsay--- target/arm/cpu.h | 4 ++-- target/arm/helper.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-)
target/arm/cpu.h +2 -2
@@ -837,8 +837,8 @@ struct ARMCPU {uint32_t id_pfr0;uint32_t id_pfr1;uint32_t id_dfr0; -uint32_t pmceid0; -uint32_t pmceid1; +uint64_t pmceid0; +uint64_t pmceid1;uint32_t id_afr0;uint32_t id_mmfr0;uint32_t id_mmfr1;
target/arm/helper.c +17 -2
@@ -5256,6 +5256,21 @@ void register_cp_regs_for_features(ARMCPU *cpu) }else {define_arm_cp_regs (cpu, not_v7_cp_reginfo); } +if (FIELD_EX32 (cpu->id_dfr0,ID_DFR0 ,PERFMON ) >=4 && +FIELD_EX32 (cpu->id_dfr0,ID_DFR0 ,PERFMON ) !=0xf ) { +ARMCPRegInfo v81_pmu_regs[] = { + { .name ="PMCEID2" , .state =ARM_CP_STATE_AA32 , + .cp =15 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =4 , + .access =PL0_R , .accessfn = pmreg_access, .type =ARM_CP_CONST , + .resetvalue =extract64 (cpu->pmceid0,32 ,32 ) }, + { .name ="PMCEID3" , .state =ARM_CP_STATE_AA32 , + .cp =15 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =5 , + .access =PL0_R , .accessfn = pmreg_access, .type =ARM_CP_CONST , + .resetvalue =extract64 (cpu->pmceid1,32 ,32 ) }, +REGINFO_SENTINEL + }; +define_arm_cp_regs (cpu, v81_pmu_regs); + }if (arm_feature (env,ARM_FEATURE_V8 )) {/* AArch64 ID registers, which all have impdef reset values. * Note that within the ID register ranges the unused slots
@@ -5432,7 +5447,7 @@ void register_cp_regs_for_features(ARMCPU *cpu) { .name = "PMCEID0", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 0, .crn = 9, .crm = 12, .opc2 = 6, .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, - .resetvalue = cpu->pmceid0 }, + .resetvalue = extract64(cpu->pmceid0, 0, 32) }, { .name = "PMCEID0_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 6, .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST,
@@ -5440,7 +5455,7 @@ void register_cp_regs_for_features(ARMCPU *cpu) { .name = "PMCEID1", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 0, .crn = 9, .crm = 12, .opc2 = 7, .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, - .resetvalue = cpu->pmceid1 }, + .resetvalue = extract64(cpu->pmceid1, 0, 32) }, { .name = "PMCEID1_EL0", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 7, .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST,
Signature · 1 line
2.19.2
PATCH v10 9/14 target/arm: Add array for supported PMU events, generate PMCEID[01]_EL0
In reply to Aaron LindsayThis commit doesn't add any supported events, but provides the framework for adding them. We store the pm_event structs in a simple array, and provide the mapping from the event numbers to array indexes in the supported_event_map array. Because the value of PMCEID[01] depends upon which events are supported at runtime, generate it dynamically.
--- target/arm/cpu.c | 19 +++++++++------ target/arm/cpu.h | 10 ++++++++ target/arm/cpu64.c | 4 ---- target/arm/helper.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 11 deletions(-)
target/arm/cpu.c +12 -7
@@ -1019,10 +1019,19 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)if (!cpu->has_pmu) {unset_feature (env,ARM_FEATURE_PMU ); + } +if (arm_feature (env,ARM_FEATURE_PMU )) { + cpu->pmceid0 =get_pmceid (&cpu->env,0 ); + cpu->pmceid1 =get_pmceid (&cpu->env,1 ); + +if (!kvm_enabled ()) { +arm_register_pre_el_change_hook (cpu, &pmu_pre_el_change,0 ); +arm_register_el_change_hook (cpu, &pmu_post_el_change,0 ); + } + }else { cpu->id_aa64dfr0 &= ~0xf00 ; - }else if (!kvm_enabled ()) { -arm_register_pre_el_change_hook (cpu, &pmu_pre_el_change,0 ); -arm_register_el_change_hook (cpu, &pmu_post_el_change,0 ); + cpu->pmceid0 =0 ; + cpu->pmceid1 =0 ; }if (!arm_feature (env,ARM_FEATURE_EL2 )) {
@@ -1665,8 +1674,6 @@ static void cortex_a7_initfn(Object *obj) cpu->id_pfr0 =0x00001131 ; cpu->id_pfr1 =0x00011011 ; cpu->id_dfr0 =0x02010555 ; - cpu->pmceid0 =0x00000000 ; - cpu->pmceid1 =0x00000000 ; cpu->id_afr0 =0x00000000 ; cpu->id_mmfr0 =0x10101105 ; cpu->id_mmfr1 =0x40000000 ;
@@ -1712,8 +1719,6 @@ static void cortex_a15_initfn(Object *obj) cpu->id_pfr0 =0x00001131 ; cpu->id_pfr1 =0x00011011 ; cpu->id_dfr0 =0x02010555 ; - cpu->pmceid0 =0x0000000 ; - cpu->pmceid1 =0x00000000 ; cpu->id_afr0 =0x00000000 ; cpu->id_mmfr0 =0x10201105 ; cpu->id_mmfr1 =0x20000000 ;
target/arm/cpu.h +10 -0
@@ -993,6 +993,16 @@ void pmu_op_finish(CPUARMState *env);void pmu_pre_el_change (ARMCPU *cpu,void *ignored);void pmu_post_el_change (ARMCPU *cpu,void *ignored); +/* +* get_pmceid +* @env: CPUARMState +* @which: which PMCEID register to return (0 or 1) +* +* Return the PMCEID[01]_EL0 register values corresponding to the counters +* which are supported given the current configuration +*/ +uint64_t get_pmceid (CPUARMState *env,unsigned which); +/* SCTLR bit meanings. Several bits have been reused in newer * versions of the architecture; in that case we define constants * for both old and new bit meanings. Code which tests against those
target/arm/cpu64.c +0 -4
@@ -138,8 +138,6 @@ static void aarch64_a57_initfn(Object *obj) cpu->isar.id_isar6 =0 ; cpu->isar.id_aa64pfr0 =0x00002222 ; cpu->id_aa64dfr0 =0x10305106 ; - cpu->pmceid0 =0x00000000 ; - cpu->pmceid1 =0x00000000 ; cpu->isar.id_aa64isar0 =0x00011120 ; cpu->id_aa64mmfr0 =0x00001124 ; cpu->dbgdidr =0x3516d000 ;
@@ -246,8 +244,6 @@ static void aarch64_a72_initfn(Object *obj) cpu->isar.id_isar5 =0x00011121 ; cpu->isar.id_aa64pfr0 =0x00002222 ; cpu->id_aa64dfr0 =0x10305106 ; - cpu->pmceid0 =0x00000000 ; - cpu->pmceid1 =0x00000000 ; cpu->isar.id_aa64isar0 =0x00011120 ; cpu->id_aa64mmfr0 =0x00001124 ; cpu->dbgdidr =0x3516d000 ;
target/arm/helper.c +57 -0
63 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH v10 10/14 target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER
In reply to Aaron LindsayAdd arrays to hold the registers, the definitions themselves, access functions, and logic to reset counters when PMCR.P is set. Update filtering code to support counters other than PMCCNTR. Support migration with raw read/write functions.
--- target/arm/cpu.h | 3 + target/arm/helper.c | 296 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 282 insertions(+), 17 deletions(-)
target/arm/cpu.h +3 -0
@@ -482,6 +482,9 @@ typedef struct CPUARMState {* pmccntr_op_finish. */ uint64_t c15_ccnt_delta; +uint64_t c14_pmevcntr[31 ]; +uint64_t c14_pmevcntr_delta[31 ]; +uint64_t c14_pmevtyper[31 ];uint64_t pmccfiltr_el0;/* Performance Monitor Filter Register */ uint64_t vpidr_el2;/* Virtualization Processor ID Register */ uint64_t vmpidr_el2;/* Virtualization Multiprocessor ID Register */
target/arm/helper.c +279 -17
397 lines not on this page · raw message
Signature · 1 line
2.19.2
Re: [Qemu-devel] [Qemu-arm] [PATCH v10 10/14] target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER
Hello,
Quoted 13 lines · Aaron Lindsay
Add arrays to hold the registers, the definitions themselves, access functions, and logic to reset counters when PMCR.P is set. Update filtering code to support counters other than PMCCNTR. Support migration with raw read/write functions.
Signed-off-by Aaron Lindsay <[email protected]>Signed-off-by Aaron Lindsay <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 3 + target/arm/helper.c | 296 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 282 insertions(+), 17 deletions(-)
[...]
Quoted 4 lines
target/arm/helper.c +0
-0
[...]
Quoted 19 lines
target/arm/helper.c +15
-0@@ -5301,6 +5526,43 @@ void register_cp_regs_for_features(ARMCPU *cpu) };define_one_arm_cp_reg (cpu, &pmcr);define_one_arm_cp_reg (cpu, &pmcr64); +for (i =0 ; i < pmcrn; i++) { +char *pmevcntr_name =g_strdup_printf ("PMEVCNTR%d" , i); +char *pmevcntr_el0_name =g_strdup_printf ("PMEVCNTR%d_EL0" , i); +char *pmevtyper_name =g_strdup_printf ("PMEVTYPER%d" , i); +char *pmevtyper_el0_name =g_strdup_printf ("PMEVTYPER%d_EL0" , i); +ARMCPRegInfo pmev_regs[] = { + { .name = pmevcntr_name, .cp =15 , .crn =15 , + .crm =8 | (3 & (i >>3 )), .opc1 =0 , .opc2 = i &7 , + .access =PL0_RW , .type =ARM_CP_IO |ARM_CP_ALIAS , + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .accessfn = pmreg_access }, + { .name = pmevcntr_el0_name, .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =15 , .crm =8 | (3 & (i >>3 )), + .opc2 = i &7 , .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_IO ,
target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 5553
Quoted 10 lines
target/arm/helper.c +10
-0+ .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .raw_readfn = pmevcntr_rawread, + .raw_writefn = pmevcntr_rawwrite }, + { .name = pmevtyper_name, .cp = 15, .crn = 15, + .crm = 12 | (3 & (i >> 3)), .opc1 = 0, .opc2 = i & 7, + .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, + .accessfn = pmreg_access }, + { .name = pmevtyper_el0_name, .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 12 | (3 & (i >> 3)),
Looking at ARM documentation, I think the value for crn should be 14 for PMEVCNTR<n>_EL0 and PMEVTYPER<n>_EL0.
Thanks,
Laurent
Quoted 19 lines
target/arm/helper.c +12
-1+ .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access, + .type = ARM_CP_IO, + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, + .raw_writefn = pmevtyper_rawwrite }, +REGINFO_SENTINEL + }; +define_arm_cp_regs (cpu, pmev_regs); +g_free (pmevcntr_name); +g_free (pmevcntr_el0_name); +g_free (pmevtyper_name); +g_free (pmevtyper_el0_name); + }#endif ARMCPRegInfo clidr = { .name ="CLIDR" , .state =ARM_CP_STATE_BOTH , --2.19.2
Re: [Qemu-arm] [PATCH v10 10/14] target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER
Quoted 47 lines · Laurent Desnogues
Hello,
Quoted 13 lines · Aaron Lindsay
Add arrays to hold the registers, the definitions themselves, access functions, and logic to reset counters when PMCR.P is set. Update filtering code to support counters other than PMCCNTR. Support migration with raw read/write functions.
Signed-off-by Aaron Lindsay <[email protected]>Signed-off-by Aaron Lindsay <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 3 + target/arm/helper.c | 296 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 282 insertions(+), 17 deletions(-)[...]
Quoted 4 lines
target/arm/helper.c +0
-0[...]
Quoted 24 lines
target/arm/helper.c +20
-0@@ -5301,6 +5526,43 @@ void register_cp_regs_for_features(ARMCPU *cpu) };define_one_arm_cp_reg (cpu, &pmcr);define_one_arm_cp_reg (cpu, &pmcr64); +for (i =0 ; i < pmcrn; i++) { +char *pmevcntr_name =g_strdup_printf ("PMEVCNTR%d" , i); +char *pmevcntr_el0_name =g_strdup_printf ("PMEVCNTR%d_EL0" , i); +char *pmevtyper_name =g_strdup_printf ("PMEVTYPER%d" , i); +char *pmevtyper_el0_name =g_strdup_printf ("PMEVTYPER%d_EL0" , i); +ARMCPRegInfo pmev_regs[] = { + { .name = pmevcntr_name, .cp =15 , .crn =15 , + .crm =8 | (3 & (i >>3 )), .opc1 =0 , .opc2 = i &7 , + .access =PL0_RW , .type =ARM_CP_IO |ARM_CP_ALIAS , + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .accessfn = pmreg_access }, + { .name = pmevcntr_el0_name, .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =15 , .crm =8 | (3 & (i >>3 )), + .opc2 = i &7 , .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_IO , + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .raw_readfn = pmevcntr_rawread, + .raw_writefn = pmevcntr_rawwrite }, + { .name = pmevtyper_name, .cp =15 , .crn =15 , + .crm =12 | (3 & (i >>3 )), .opc1 =0 , .opc2 = i &7 ,
Quoted 8 lines
target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 5553
Quoted 5 lines
target/arm/helper.c +5
-0+ .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, + .accessfn = pmreg_access }, + { .name = pmevtyper_el0_name, .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 12 | (3 & (i >> 3)),Looking at ARM documentation, I think the value for crn should be 14 for PMEVCNTR<n>_EL0 and PMEVTYPER<n>_EL0.
You are correct. I'll post a fix momentarily.
Out of curiosity, how did you discover this? I've been using recent Linux kernels for testing, and thought it used these registers, but I guess it must only be using PMSELR/PMXEVCNTR/PMXEVTYPER.
-Aaron
Re: [Qemu-arm] [PATCH v10 10/14] target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER
Quoted 58 lines · Aaron Lindsay OS
Quoted 47 lines · Laurent Desnogues
Hello,
Quoted 13 lines · Aaron Lindsay
Add arrays to hold the registers, the definitions themselves, access functions, and logic to reset counters when PMCR.P is set. Update filtering code to support counters other than PMCCNTR. Support migration with raw read/write functions.
Signed-off-by Aaron Lindsay <[email protected]>Signed-off-by Aaron Lindsay <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/arm/cpu.h | 3 + target/arm/helper.c | 296 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 282 insertions(+), 17 deletions(-)[...]
Quoted 4 lines
target/arm/helper.c +0
-0[...]
Quoted 24 lines
target/arm/helper.c +20
-0@@ -5301,6 +5526,43 @@ void register_cp_regs_for_features(ARMCPU *cpu) };define_one_arm_cp_reg (cpu, &pmcr);define_one_arm_cp_reg (cpu, &pmcr64); +for (i =0 ; i < pmcrn; i++) { +char *pmevcntr_name =g_strdup_printf ("PMEVCNTR%d" , i); +char *pmevcntr_el0_name =g_strdup_printf ("PMEVCNTR%d_EL0" , i); +char *pmevtyper_name =g_strdup_printf ("PMEVTYPER%d" , i); +char *pmevtyper_el0_name =g_strdup_printf ("PMEVTYPER%d_EL0" , i); +ARMCPRegInfo pmev_regs[] = { + { .name = pmevcntr_name, .cp =15 , .crn =15 , + .crm =8 | (3 & (i >>3 )), .opc1 =0 , .opc2 = i &7 , + .access =PL0_RW , .type =ARM_CP_IO |ARM_CP_ALIAS , + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .accessfn = pmreg_access }, + { .name = pmevcntr_el0_name, .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =15 , .crm =8 | (3 & (i >>3 )), + .opc2 = i &7 , .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_IO , + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, + .raw_readfn = pmevcntr_rawread, + .raw_writefn = pmevcntr_rawwrite }, + { .name = pmevtyper_name, .cp =15 , .crn =15 , + .crm =12 | (3 & (i >>3 )), .opc1 =0 , .opc2 = i &7 ,Quoted 8 lines
target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 5553
Quoted 5 lines
target/arm/helper.c +5
-0+ .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, + .accessfn = pmreg_access }, + { .name = pmevtyper_el0_name, .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 12 | (3 & (i >> 3)),Looking at ARM documentation, I think the value for crn should be 14 for PMEVCNTR<n>_EL0 and PMEVTYPER<n>_EL0.
Quoted 5 lines
You are correct. I'll post a fix momentarily.
Out of curiosity, how did you discover this? I've been using recent Linux kernels for testing, and thought it used these registers, but I guess it must only be using PMSELR/PMXEVCNTR/PMXEVTYPER.
There regs are used in a proprietary bare metal bootloader on a virtual platform my company uses for performance measurements.
Thanks,
Laurent
PATCH v10 11/14 target/arm: PMU: Add instruction and cycle events
In reply to Aaron LindsayThe instruction event is only enabled when icount is used, cycles are always supported. Always defining get_cycle_count (but altering its behavior depending on CONFIG_USER_ONLY) allows us to remove some CONFIG_USER_ONLY #defines throughout the rest of the code.
--- target/arm/helper.c | 90 ++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 46 deletions(-)
target/arm/helper.c +44 -46
@@ -15,6 +15,7 @@#include "arm_ldst.h" #include <zlib.h> /* For crc32 */ #include "exec/semihost.h" +#include "sysemu/cpus.h" #include "sysemu/kvm.h" #include "fpu/softfloat.h" #include "qemu/range.h"
@@ -1021,7 +1022,48 @@ typedef struct pm_event {uint64_t (*get_count)(CPUARMState *); } pm_event; +static bool event_always_supported (CPUARMState *env) +{ +return true; +} + +/* +* Return the underlying cycle count for the PMU cycle counters. If we're in +* usermode, simply return 0. +*/ +static uint64_t cycles_get_count (CPUARMState *env) +{ +#ifndef CONFIG_USER_ONLY +return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), +ARM_CPU_FREQ ,NANOSECONDS_PER_SECOND ); +#else +return cpu_get_host_ticks (); +#endif +} + +#ifndef CONFIG_USER_ONLY +static bool instructions_supported (CPUARMState *env) +{ +return use_icount ==1 /* Precise instruction counting */ ; +} + +static uint64_t instructions_get_count (CPUARMState *env) +{ +return (uint64_t )cpu_get_icount_raw (); +} +#endif +static const pm_event pm_events[] = { +#ifndef CONFIG_USER_ONLY + { .number =0x008 ,/* INST_RETIRED, Instruction architecturally executed */ + .supported = instructions_supported, + .get_count = instructions_get_count, + }, + { .number =0x011 ,/* CPU_CYCLES, Cycle */ + .supported = event_always_supported, + .get_count = cycles_get_count, + } +#endif };/*
@@ -1030,7 +1072,7 @@ static const pm_event pm_events[] = {* should first be updated to something sparse instead of the current * supported_event_map[] array. */ -#define MAX_EVENT_ID 0x0 +#define MAX_EVENT_ID 0x11#define UNSUPPORTED_EVENT UINT16_MAXstatic uint16_t supported_event_map[MAX_EVENT_ID +1 ];
@@ -1131,8 +1173,6 @@ static CPAccessResult pmreg_access_swinc(CPUARMState *env,return pmreg_access (env, ri, isread); } -#ifndef CONFIG_USER_ONLY -static CPAccessResult pmreg_access_selr (CPUARMState *env,const ARMCPRegInfo *ri,bool isread)
@@ -1243,9 +1283,7 @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)*/ void pmccntr_op_start (CPUARMState *env) { -uint64_t cycles =0 ; - cycles =muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), -ARM_CPU_FREQ ,NANOSECONDS_PER_SECOND ); +uint64_t cycles =cycles_get_count (env);if (pmu_counter_enabled (env,31 )) {uint64_t eff_cycles = cycles;
@@ -1391,42 +1429,6 @@ static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri,pmccntr_write (env, ri,deposit64 (cur_val,0 ,32 , value)); } -#else /* CONFIG_USER_ONLY */ - -void pmccntr_op_start (CPUARMState *env) -{ -} - -void pmccntr_op_finish (CPUARMState *env) -{ -} - -void pmevcntr_op_start (CPUARMState *env,uint8_t i) -{ -} - -void pmevcntr_op_finish (CPUARMState *env,uint8_t i) -{ -} - -void pmu_op_start (CPUARMState *env) -{ -} - -void pmu_op_finish (CPUARMState *env) -{ -} - -void pmu_pre_el_change (ARMCPU *cpu,void *ignored) -{ -} - -void pmu_post_el_change (ARMCPU *cpu,void *ignored) -{ -} - -#endif -static void pmccfiltr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
@@ -1814,7 +1816,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {/* Unimplemented so WI. */ { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4, .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NOP }, -#ifndef CONFIG_USER_ONLY { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5, .access = PL0_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmselr),
@@ -1836,7 +1837,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), .readfn = pmccntr_read, .writefn = pmccntr_write, .raw_readfn = raw_read, .raw_writefn = raw_write, }, -#endif { .name = "PMCCFILTR", .cp = 15, .opc1 = 0, .crn = 14, .crm = 15, .opc2 = 7, .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, .access = PL0_RW, .accessfn = pmreg_access,
@@ -5506,7 +5506,6 @@ void register_cp_regs_for_features(ARMCPU *cpu)* count register. */ unsigned int i, pmcrn =0 ; -#ifndef CONFIG_USER_ONLY ARMCPRegInfo pmcr = { .name ="PMCR" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =0 , .access =PL0_RW ,
@@ -5563,7 +5562,6 @@ void register_cp_regs_for_features(ARMCPU *cpu)g_free (pmevtyper_name);g_free (pmevtyper_el0_name); } -#endif ARMCPRegInfo clidr = { .name ="CLIDR" , .state =ARM_CP_STATE_BOTH , .opc0 =3 , .crn =0 , .crm =0 , .opc1 =1 , .opc2 =1 ,
Signature · 1 line
2.19.2
PATCH v10 12/14 target/arm: PMU: Set PMCR.N to 4
In reply to Aaron LindsayThis both advertises that we support four counters and enables them because the pmu_num_counters() reads this value from PMCR.
--- target/arm/helper.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/arm/helper.c +5 -5
@@ -1768,7 +1768,7 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .access = PL1_W, .type = ARM_CP_NOP },/* Performance monitors are implementation defined in v7, * but with an ARM recommended set of registers, which we -* follow (although we don't actually implement any counters) +* follow. * * Performance registers fall into three categories: * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
@@ -5502,10 +5502,10 @@ void register_cp_regs_for_features(ARMCPU *cpu) }if (arm_feature (env,ARM_FEATURE_V7 )) {/* v7 performance monitor control register: same implementor -* field as main ID register, and we implement only the cycle -* count register. +* field as main ID register, and we implement four counters in +* addition to the cycle count register. */ -unsigned int i, pmcrn =0 ; +unsigned int i, pmcrn =4 ;ARMCPRegInfo pmcr = { .name ="PMCR" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =0 , .access =PL0_RW ,
@@ -5520,7 +5520,7 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL0_RW, .accessfn = pmreg_access, .type = ARM_CP_IO, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcr), - .resetvalue = cpu->midr & 0xff000000, + .resetvalue = (cpu->midr & 0xff000000) | (pmcrn << PMCRN_SHIFT), .writefn = pmcr_write, .raw_writefn = raw_write, };define_one_arm_cp_reg (cpu, &pmcr);
Signature · 1 line
2.19.2
PATCH v10 13/14 target/arm: Implement PMSWINC
In reply to Aaron Lindsay--- target/arm/helper.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-)
target/arm/helper.c +37 -2
@@ -1027,6 +1027,15 @@ static bool event_always_supported(CPUARMState *env)return true; } +static uint64_t swinc_get_count (CPUARMState *env) +{ +/* +* SW_INCR events are written directly to the pmevcntr's by writes to +* PMSWINC, so there is no underlying count maintained by the PMU itself +*/ +return 0 ; +} +/* * Return the underlying cycle count for the PMU cycle counters. If we're in * usermode, simply return 0.
@@ -1054,6 +1063,10 @@ static uint64_t instructions_get_count(CPUARMState *env)#endif static const pm_event pm_events[] = { + { .number =0x000 ,/* SW_INCR */ + .supported = event_always_supported, + .get_count = swinc_get_count, + }, #ifndef CONFIG_USER_ONLY { .number =0x008 ,/* INST_RETIRED, Instruction architecturally executed */ .supported = instructions_supported,
@@ -1393,6 +1406,24 @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,pmu_op_finish (env); } +static void pmswinc_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +unsigned int i; +for (i =0 ; i <pmu_num_counters (env); i++) { +/* Increment a counter's count iff: */ +if ((value & (1 << i)) &&/* counter's bit is set */ +/* counter is enabled and not filtered */ +pmu_counter_enabled (env, i) && +/* counter is SW_INCR */ + (env->cp15.c14_pmevtyper[i] &PMXEVTYPER_EVTCOUNT ) ==0x0 ) { +pmevcntr_op_start (env, i); + env->cp15.c14_pmevcntr[i]++; +pmevcntr_op_finish (env, i); + } + } +} +static uint64_t pmccntr_read (CPUARMState *env,const ARMCPRegInfo *ri) {uint64_t ret;
@@ -1813,9 +1844,13 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), .writefn = pmovsr_write, .raw_writefn = raw_write }, -/* Unimplemented so WI. */ { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4, - .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NOP }, + .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW, + .writefn = pmswinc_write }, + { .name = "PMSWINC_EL0", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 4, + .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW, + .writefn = pmswinc_write }, { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5, .access = PL0_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmselr),
Signature · 1 line
2.19.2
PATCH v10 14/14 target/arm: Send interrupts on PMU counter overflow
In reply to Aaron LindsaySetup a QEMUTimer to get a callback when we expect counters to next overflow and trigger an interrupt at that time.
--- target/arm/cpu.c | 12 +++++ target/arm/cpu.h | 8 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 140 insertions(+), 6 deletions(-)
target/arm/cpu.c +12 -0
@@ -827,6 +827,13 @@ static void arm_cpu_finalizefn(Object *obj)QLIST_REMOVE (hook, node);g_free (hook); } +#ifndef CONFIG_USER_ONLY +if (cpu->pmu_timer) { +timer_del (cpu->pmu_timer); +timer_deinit (cpu->pmu_timer); +timer_free (cpu->pmu_timer); + } +#endif }static void arm_cpu_realizefn (DeviceState *dev,Error **errp)
@@ -1028,6 +1035,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)arm_register_pre_el_change_hook (cpu, &pmu_pre_el_change,0 );arm_register_el_change_hook (cpu, &pmu_post_el_change,0 ); } + +#ifndef CONFIG_USER_ONLY + cpu->pmu_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , arm_pmu_timer_cb, + cpu); +#endif }else { cpu->id_aa64dfr0 &= ~0xf00 ; cpu->pmceid0 =0 ;
target/arm/cpu.h +8 -0
@@ -733,6 +733,9 @@ struct ARMCPU {/* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS ]; +/* Timer used by the PMU. Its state is restored after migration by +* pmu_op_finish() - it does not need other handling during migration */ +QEMUTimer *pmu_timer;/* GPIO outputs for generic timer */ qemu_irq gt_timer_outputs[NUM_GTIMERS ];/* GPIO output for GICv3 maintenance interrupt signal */
@@ -990,6 +993,11 @@ void pmccntr_op_finish(CPUARMState *env);void pmu_op_start (CPUARMState *env);void pmu_op_finish (CPUARMState *env); +/** +* Called when a PMU counter is due to overflow +*/ +void arm_pmu_timer_cb (void *opaque); +/** * Functions to register as EL change hooks for PMU mode filtering */
target/arm/helper.c +120 -6
260 lines not on this page · raw message
Signature · 1 line
2.19.2
Re: [Qemu-arm] [PATCH v10 14/14] target/arm: Send interrupts on PMU counter overflow
Quoted 10 lines · Aaron Lindsay
Setup a QEMUTimer to get a callback when we expect counters to next overflow and trigger an interrupt at that time.
Signed-off-by Aaron Lindsay <[email protected]>Signed-off-by Aaron Lindsay <[email protected]>--- target/arm/cpu.c | 12 +++++ target/arm/cpu.h | 8 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 140 insertions(+), 6 deletions(-)
Well, this patch is doing several things at once -- adding the timer, adding the ns_per_count hook, updating irqs. Not ideal, but I won't insist it be split.
You'll need to re-run against scripts/checkpatch, it would seem. The goal-posts with respect to comments have been changed since you started this.
target/arm/helper.c void pmccntr_op_start(CPUARMState *env) · line 1344
Quoted 9 lines
target/arm/helper.c +4
-1@@ -1305,7 +1338,19 @@ void pmccntr_op_start(CPUARMState *env) eff_cycles /=64 ; } - env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta; +uint64_t new_pmccntr = eff_cycles - env->cp15.c15_ccnt_delta; + +unsigned int overflow_bit = (env->cp15.c9_pmcr &PMCRLC ) ?63 :31 ; +uint64_t overflow_mask = (uint64_t )1 << overflow_bit;
Could just as easily be
uint64_t overflow_mask = env->cp15.c9_pmcr & PMCRLC ? INT64_MIN : INT32_MIN;
target/arm/helper.c void pmccntr_op_start(CPUARMState *env) · line 1349
Quoted 5 lines
target/arm/helper.c +5
-0+if (env->cp15.c15_ccnt & ~new_pmccntr & overflow_mask) { + env->cp15.c9_pmovsr |= (1 <<31 ); +if (!(env->cp15.c9_pmcr &PMCRLC )) { + new_pmccntr &=0xffffffff ; + }
Why is this truncation buried within the overflow condition? Simply because the high bits can't be set without overflow being noticed? That could use a comment, because it looks odd.
target/arm/helper.c static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) · line 1407
Quoted 12 lines
target/arm/helper.c +6
-2@@ -1340,8 +1399,15 @@ static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) }if (pmu_counter_enabled (env, counter)) { - env->cp15.c14_pmevcntr[counter] = - count - env->cp15.c14_pmevcntr_delta[counter]; +uint64_t new_pmevcntr = count - env->cp15.c14_pmevcntr_delta[counter]; + +if (!(new_pmevcntr &PMEVCNTR_OVERFLOW_MASK ) && + (env->cp15.c14_pmevcntr[counter] &PMEVCNTR_OVERFLOW_MASK )) { + env->cp15.c9_pmovsr |= (1 << counter); + new_pmevcntr &= ~PMEVCNTR_OVERFLOW_MASK ;
That, surely, does not do what you intend. I can only imagine that you meant
new_pmevcntr = (uint32_t)new_pmevcntr;
or
new_pmevcntr &= PMEVCNTR_OVERFLOW_MASK - 1;depending on how much you want to depend on the symbol defining the width. Given that it is architecturally defined to 32-bits, I think you could really just drop the define and use
uint32_t new_pmevcntr = ...;
if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & INT32_MIN)with equal clarity. The type of new_pmevcntr means you don't have to clear any high bits either.
target/arm/helper.c static void pmswinc_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1524
Quoted 9 lines
target/arm/helper.c +9
-0+/* Detect if this write causes an overflow since we can't predict +* PMSWINC overflows like we can for other events +*/ +uint64_t new_pmswinc = env->cp15.c14_pmevcntr[i] +1 ; + +if (!(new_pmswinc &PMEVCNTR_OVERFLOW_MASK ) && + (env->cp15.c14_pmevcntr[i] &PMEVCNTR_OVERFLOW_MASK )) { + env->cp15.c9_pmovsr |= (1 << i); + new_pmswinc &= ~PMEVCNTR_OVERFLOW_MASK ;
Likewise.
r~
Re: [Qemu-arm] [PATCH v10 14/14] target/arm: Send interrupts on PMU counter overflow
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Aaron Lindsay
Setup a QEMUTimer to get a callback when we expect counters to next overflow and trigger an interrupt at that time.
Signed-off-by Aaron Lindsay <[email protected]>Signed-off-by Aaron Lindsay <[email protected]>--- target/arm/cpu.c | 12 +++++ target/arm/cpu.h | 8 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 140 insertions(+), 6 deletions(-)
Quoted 6 lines
Well, this patch is doing several things at once -- adding the timer, adding the
ns_per_counthook, updating irqs. Not ideal, but I won't insist it be split.You'll need to re-run against
scripts/checkpatch, it would seem. The goal-posts with respect to comments have been changed since you started this.
Okay, I'll check that again before I send the next version out.
Quoted 12 lines
target/arm/helper.c void pmccntr_op_start(CPUARMState *env) · line 1344
Quoted 9 lines
target/arm/helper.c +4
-1@@ -1305,7 +1338,19 @@ void pmccntr_op_start(CPUARMState *env) eff_cycles /=64 ; } - env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta; +uint64_t new_pmccntr = eff_cycles - env->cp15.c15_ccnt_delta; + +unsigned int overflow_bit = (env->cp15.c9_pmcr &PMCRLC ) ?63 :31 ; +uint64_t overflow_mask = (uint64_t )1 << overflow_bit;Could just as easily be
Quoted 1 line
uint64_t overflow_mask = env->cp15.c9_pmcr & PMCRLC ? INT64_MIN : INT32_MIN;
Updated.
Quoted 9 lines
target/arm/helper.c void pmccntr_op_start(CPUARMState *env) · line 1349
Quoted 5 lines
target/arm/helper.c +5
-0+if (env->cp15.c15_ccnt & ~new_pmccntr & overflow_mask) { + env->cp15.c9_pmovsr |= (1 <<31 ); +if (!(env->cp15.c9_pmcr &PMCRLC )) { + new_pmccntr &=0xffffffff ; + }Why is this truncation buried within the overflow condition? Simply because the high bits can't be set without overflow being noticed? That could use a comment, because it looks odd.
Upon re-reading the spec, I don't think this is needed (or even correct behavior). I must've been thinking that PMCR.LC == 0 implied that upper 32 bits could never be updated by the hardware and made PMCCNTR act like its high bits didn't even exist, like one of the PMXEVCNTRs. I no longer believe that is true and I'll remove this.
Quoted 15 lines
target/arm/helper.c static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) · line 1407
Quoted 12 lines
target/arm/helper.c +6
-2@@ -1340,8 +1399,15 @@ static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) }if (pmu_counter_enabled (env, counter)) { - env->cp15.c14_pmevcntr[counter] = - count - env->cp15.c14_pmevcntr_delta[counter]; +uint64_t new_pmevcntr = count - env->cp15.c14_pmevcntr_delta[counter]; + +if (!(new_pmevcntr &PMEVCNTR_OVERFLOW_MASK ) && + (env->cp15.c14_pmevcntr[counter] &PMEVCNTR_OVERFLOW_MASK )) { + env->cp15.c9_pmovsr |= (1 << counter); + new_pmevcntr &= ~PMEVCNTR_OVERFLOW_MASK ;That, surely, does not do what you intend. I can only imagine that you meant
Quoted 5 lines
new_pmevcntr = (uint32_t)new_pmevcntr; or new_pmevcntr &= PMEVCNTR_OVERFLOW_MASK - 1;depending on how much you want to depend on the symbol defining the width.
In practice, I think only the 32nd bit would ever need to be cleared, but I agree it is more correct to clear them all.
Quoted 7 lines
Given that it is architecturally defined to 32-bits, I think you could really just drop the define and use
uint32_t new_pmevcntr = ...; if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & INT32_MIN)with equal clarity.
I don't know whether it is important for the resolution of this patch, but what did you mean by the following?:
Quoted 13 lines
The type of
new_pmevcntrmeans you don't have to clear any high bits either.target/arm/helper.c static void pmswinc_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1524
Quoted 9 lines
target/arm/helper.c +9
-0+/* Detect if this write causes an overflow since we can't predict +* PMSWINC overflows like we can for other events +*/ +uint64_t new_pmswinc = env->cp15.c14_pmevcntr[i] +1 ; + +if (!(new_pmswinc &PMEVCNTR_OVERFLOW_MASK ) && + (env->cp15.c14_pmevcntr[i] &PMEVCNTR_OVERFLOW_MASK )) { + env->cp15.c9_pmovsr |= (1 << i); + new_pmswinc &= ~PMEVCNTR_OVERFLOW_MASK ;
Quoted 1 line
Likewise.
Thanks,
Aaron
Re: [Qemu-arm] [PATCH v10 14/14] target/arm: Send interrupts on PMU counter overflow
Quoted 6 lines · Aaron Lindsay
In practice, I think only the 32nd bit would ever need to be cleared, but I agree it is more correct to clear them all.
Quoted 3 lines
Given that it is architecturally defined to 32-bits, I think you could really just drop the define and use
Quoted 10 lines
Quoted 4 lines
uint32_t new_pmevcntr = ...; if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & INT32_MIN)with equal clarity.
I don't know whether it is important for the resolution of this patch, but what did you mean by the following?:
Quoted 2 lines
The type of
new_pmevcntrmeans you don't have to clear any high bits either.
If you use uint32_t, then no *explicit* clearing of the high bits is necessary, and is implied by the assignment back to env->cp15.c14_pmevcntr[counter].
r~
Ping, just in case this got buried over the holidays...
-Aaron
Quoted 48 lines · Aaron Lindsay
The ARM PMU implementation currently contains a basic cycle counter, but it is often useful to gather counts of other events, filter them based on execution mode, and/or be notified on counter overflow. These patches flesh out the implementations of various PMU registers including PM[X]EVCNTR and PM[X]EVTYPER, add a struct definition to represent arbitrary counter types, implement mode filtering, send interrupts on counter overflow, and add instruction, cycle, and software increment events.
Since v9 [1] I have made the following changes:
* Added a clarifying comment about how the PMU timer's migration is handled
* Added a check against implementing PMCEID[23] if ID_DFR0.PerfMon ==0xf
* Added TRACEFILT to theID_DFR0field definitions[1] - https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg00805.html
Aaron Lindsay (14):
migration: Addpost_savefunction to VMStateDescription target/arm: Reorganize PMCCNTR accesses
target/arm: Swap PMU values before/after migrations target/arm: Filter cycle counter based onPMCCFILTR_EL0target/arm: Allow AArch32 access for PMCCFILTR target/arm: Implement PMOVSSET
target/arm: Define FIELDs forID_DFR0
target/arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23] target/arm: Add array for supported PMU events, generatePMCEID[01]_EL0target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER target/arm: PMU: Add instruction and cycle events target/arm: PMU: Set PMCR.N to 4
target/arm: Implement PMSWINC
target/arm: Send interrupts on PMU counter overflowdocs/devel/migration.rst | 9 +- include/migration/vmstate.h | 1 + migration/vmstate.c | 13 +- target/arm/cpu.c | 28 +- target/arm/cpu.h | 81 +++- target/arm/cpu64.c | 4 - target/arm/helper.c | 808 ++++++++++++++++++++++++++++++++---- target/arm/machine.c | 24 ++ 8 files changed, 863 insertions(+), 105 deletions(-)Signature · 1 line
2.19.2
Quoted 10 lines · Aaron Lindsay
The ARM PMU implementation currently contains a basic cycle counter, but it is often useful to gather counts of other events, filter them based on execution mode, and/or be notified on counter overflow. These patches flesh out the implementations of various PMU registers including PM[X]EVCNTR and PM[X]EVTYPER, add a struct definition to represent arbitrary counter types, implement mode filtering, send interrupts on counter overflow, and add instruction, cycle, and software increment events.
Quoted 9 lines
Since v9 [1] I have made the following changes:
* Added a clarifying comment about how the PMU timer's migration is handled
* Added a check against implementing PMCEID[23] if ID_DFR0.PerfMon ==0xf
* Added TRACEFILT to theID_DFR0field definitions[1] - https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg00805.html
Richard has made some comments on patch 14; since 1-13 have all been reviewed now I'm going to apply those to target-arm.next.
thanks
-- PMM
Quoted 19 lines · Peter Maydell
Quoted 17 lines · Aaron Lindsay
The ARM PMU implementation currently contains a basic cycle counter, but it is often useful to gather counts of other events, filter them based on execution mode, and/or be notified on counter overflow. These patches flesh out the implementations of various PMU registers including PM[X]EVCNTR and PM[X]EVTYPER, add a struct definition to represent arbitrary counter types, implement mode filtering, send interrupts on counter overflow, and add instruction, cycle, and software increment events.
Since v9 [1] I have made the following changes:
* Added a clarifying comment about how the PMU timer's migration is handled
* Added a check against implementing PMCEID[23] if ID_DFR0.PerfMon ==0xf
* Added TRACEFILT to theID_DFR0field definitions
Quoted 5 lines
Quoted 2 lines
[1] - https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg00805.html
Richard has made some comments on patch 14; since 1-13 have all been reviewed now I'm going to apply those to target-arm.next.
Thanks.
I also apologize - I just uncovered a bug I should've caught sooner, and sent out a fix to the list as:
Subject: [PATCH] target/arm: Don't clear supported PMU events when initializing PMCEID1
-Aaron