More fully implement ARM PMUv3
v8 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 v7 [1] I have made the following changes:
* Updated pmu_op_start/finish to not be called upon migration under KVM
* Added a patch updating PMCEID* to be 64-bit registers for AArch64 and added PMCEID2/3 for AArch32
* Changed get_pmceid() return two full 64-bit register values (since the underlying registers are now 64-bit post-ARMv8.1)
* Updated the comment for pmu_op_start/finish to match the implementation
* Added a check so the pmu_timer is not freed if it was not originally allocated
[1] - https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg00837.html
Aaron Lindsay (13):
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: 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 | 71 +++- target/arm/cpu64.c | 4 - target/arm/helper.c | 801 ++++++++++++++++++++++++++++++++---- target/arm/machine.c | 24 ++ 8 files changed, 846 insertions(+), 105 deletions(-)
Signature · 1 line
2.19.1
PATCH v8 1/13 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);VMStateField *fields;const VMStateDescription **subsections;
migration/vmstate.c +12 -1
@@ -387,6 +387,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; }
@@ -412,7 +415,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.1
PATCH v8 2/13 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.1
PATCH v8 3/13 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.1
Re: [Qemu-arm] [PATCH v8 03/13] target/arm: Swap PMU values before/after migrations
Quoted 11 lines · Aaron Lindsay
Because 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.
Signed-off-by Aaron Lindsay <[email protected]>Signed-off-by Aaron Lindsay <[email protected]>
thanks
-- PMM
PATCH v8 4/13 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.1
PATCH v8 5/13 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.1
PATCH v8 6/13 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.1
PATCH v8 7/13 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 | 12 ++++++++++-- 2 files changed, 12 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 +10 -2
@@ -5432,7 +5432,11 @@ 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 = "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 = "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 +5444,11 @@ 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 = "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) }, { .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.1
Re: [Qemu-arm] [PATCH v8 07/13] target-arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
Quoted 43 lines · Aaron Lindsay
Signed-off-by Aaron Lindsay <[email protected]>--- target/arm/cpu.h | 4 ++-- target/arm/helper.c | 12 ++++++++++-- 2 files changed, 12 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 +5
-1@@ -5432,7 +5432,11 @@ 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 = "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 = "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 +5444,11 @@ 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,
target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu)
Quoted 10 lines
target/arm/helper.c +5
-2- .resetvalue = cpu->pmceid1 }, + .resetvalue = extract64(cpu->pmceid1, 0, 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) }, { .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, --
PMCEID2 and PMCEID3 are only defined from ARMv8.1; before that they are UNDEFINED. So these registers need to be only defined if a suitable feature bit or ID register field check passes.
thanks
-- PMM
Re: [Qemu-arm] [PATCH v8 07/13] target-arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
Quoted 51 lines · Peter Maydell
Quoted 49 lines · Aaron Lindsay
Signed-off-by Aaron Lindsay <[email protected]>--- target/arm/cpu.h | 4 ++-- target/arm/helper.c | 12 ++++++++++-- 2 files changed, 12 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 +10
-2@@ -5432,7 +5432,11 @@ 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 = "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 = "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 +5444,11 @@ 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 = "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) },
Quoted 8 lines
target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu)
Quoted 4 lines
target/arm/helper.c +0
-1{ .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, --PMCEID2 and PMCEID3 are only defined from ARMv8.1; before that they are UNDEFINED. So these registers need to be only defined if a suitable feature bit or ID register field check passes.
It looks like we don't currently support any ARMv8.1+ CPUs and don't have an entry in the arm_features enum for it. I'll plan to add ARM_FEATURE_V81 and make defining these registers depend on it, assuming any future CPUs supporting it will use that, unless you feel I should do something different.
-Aaron
Re: [Qemu-arm] [PATCH v8 07/13] target-arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
Quoted 11 lines · Aaron Lindsay
Quoted 3 lines · Peter Maydell
PMCEID2 and PMCEID3 are only defined from ARMv8.1; before that they are UNDEFINED. So these registers need to be only defined if a suitable feature bit or ID register field check passes.
It looks like we don't currently support any ARMv8.1+ CPUs and don't have an entry in the
arm_featuresenum for it. I'll plan to addARM_FEATURE_V81and make defining these registers depend on it, assuming any future CPUs supporting it will use that, unless you feel I should do something different.
I think that the idea going forward is to prefer an ID register check of some kind -- Richard ?
thanks
-- PMM
Re: [Qemu-arm] [PATCH v8 07/13] target-arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Aaron Lindsay
Quoted 3 lines · Peter Maydell
PMCEID2 and PMCEID3 are only defined from ARMv8.1; before that they are UNDEFINED. So these registers need to be only defined if a suitable feature bit or ID register field check passes.
Quoted 8 lines
Quoted 5 lines
It looks like we don't currently support any ARMv8.1+ CPUs and don't have an entry in the
arm_featuresenum for it. I'll plan to addARM_FEATURE_V81and make defining these registers depend on it, assuming any future CPUs supporting it will use that, unless you feel I should do something different.I think that the idea going forward is to prefer an ID register check of some kind -- Richard ?
Yes. It would appear that this feature should be controlled by ID_DFR0.PerfMon. So,
if (FIELD_EX32(cpu->id_dfr0, ID_DFR0, PERFMON) >= 4)
once the appropriate FIELDs are added to cpu.h.
Since this test is not used within translate*.c, there is no need to move id_dfr* into ARMISARegisters. Since these are only aliases, they do not affect migration, and so do not (yet) need to be filled in by kvm.
r~
Re: [Qemu-arm] [PATCH v8 07/13] target-arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
Quoted 20 lines · Richard Henderson
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Aaron Lindsay
Quoted 3 lines · Peter Maydell
PMCEID2 and PMCEID3 are only defined from ARMv8.1; before that they are UNDEFINED. So these registers need to be only defined if a suitable feature bit or ID register field check passes.
Quoted 8 lines
Quoted 5 lines
It looks like we don't currently support any ARMv8.1+ CPUs and don't have an entry in the
arm_featuresenum for it. I'll plan to addARM_FEATURE_V81and make defining these registers depend on it, assuming any future CPUs supporting it will use that, unless you feel I should do something different.I think that the idea going forward is to prefer an ID register check of some kind -- Richard ?
Yes. It would appear that this feature should be controlled by ID_DFR0.PerfMon. So,
Quoted 7 lines
if (
FIELD_EX32(cpu->id_dfr0, ID_DFR0, PERFMON)>= 4)once the appropriate FIELDs are added to
cpu.h.Since this test is not used within translate*.c, there is no need to move id_dfr* into ARMISARegisters. Since these are only aliases, they do not affect migration, and so do not (yet) need to be filled in by kvm.
Sounds reasonable to me. One clarification - do we also need to guard against the 0b1111 value for ID_DFR0.PerfMon, which implies an implementation-defined, non-PMUv3 PMU, or is it safe to assume no one will attempt that flavor in QEMU?
-Aaron
Re: [Qemu-arm] [PATCH v8 07/13] target-arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23]
Quoted 9 lines · Aaron Lindsay
Quoted 7 lines · Richard Henderson
Yes. It would appear that this feature should be controlled by ID_DFR0.PerfMon. So,
if (
FIELD_EX32(cpu->id_dfr0, ID_DFR0, PERFMON)>= 4)once the appropriate FIELDs are added to
cpu.h.
Quoted 8 lines
Quoted 3 lines
Since this test is not used within translate*.c, there is no need to move id_dfr* into ARMISARegisters. Since these are only aliases, they do not affect migration, and so do not (yet) need to be filled in by kvm.
Sounds reasonable to me. One clarification - do we also need to guard against the 0b1111 value for ID_DFR0.PerfMon, which implies an implementation-defined, non-PMUv3 PMU, or is it safe to assume no one will attempt that flavor in QEMU?
We should check for 0xf, yes, following the recommended check logic described in the Arm ARM section "Alternative ID scheme used for the Performance Monitors Extension version". It doesn't seem likely that we'll end up with the 0xf case but we might as well avoid the question in advance...
thanks
-- PMM
PATCH v8 8/13 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 +* +* Return the PMCEID[01]_EL0 register values corresponding to the counters +* which are supported given the current configuration (`which` is 0 or 1 to +* indicate which PMCEID should be returned) +*/ +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.1
Re: [Qemu-arm] [PATCH v8 08/13] target/arm: Add array for supported PMU events, generate PMCEID[01]_EL0
Quoted 66 lines · Aaron Lindsay
This commit doesn't add any supported events, but provides the framework for adding them. We store the
pm_eventstructs in a simple array, and provide the mapping from the event numbers to array indexes in thesupported_event_maparray. Because the value of PMCEID[01] depends upon which events are supported at runtime, generate it dynamically.Signed-off-by Aaron Lindsay <[email protected]>--- 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 +0
-0@@ -993,6 +993,16 @@ void pmu_op_finish(CPUARMState *env);void pmu_pre_el_change (ARMCPU *cpu,void *ignored);
target/arm/cpu.h void pmu_op_finish(CPUARMState *env); · line 1003
Quoted 10 lines
target/arm/cpu.h +8
-0void pmu_post_el_change (ARMCPU *cpu,void *ignored); +/* +* get_pmceid +* @env: CPUARMState +* +* Return the PMCEID[01]_EL0 register values corresponding to the counters +* which are supported given the current configuration (`which` is 0 or 1 to +* indicate which PMCEID should be returned) +*/
Nit: you should have a line here below the one for "@env" for the "@which" parameter, and the reference to it in the text should just be "@which", not "which" (or just put that description in the line saying what @which is rather than having it in a parenthetical).
Quoted 82 lines
target/arm/cpu.h +2
-0+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 +47
-0@@ -1009,6 +1009,63 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)return (1 <<31 ) | ((1 <<pmu_num_counters (env)) -1 ); } +typedef struct pm_event { +uint16_t number;/* PMEVTYPER.evtCount is 16 bits wide */ +/* If the event is supported on this CPU (used to generate PMCEID[01]) */ +bool (*supported)(CPUARMState *); +/* +* Retrieve the current count of the underlying event. The programmed +* counters hold a difference from the return value from this function +*/ +uint64_t (*get_count)(CPUARMState *); +}pm_event ; + +static const pm_event pm_events[] = { +}; + +/* +* Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of +* events (i.e. the statistical profiling extension), this implementation +* should first be updated to something sparse instead of the current +* supported_event_map[] array. +*/ +#define MAX_EVENT_ID 0x0 +#define UNSUPPORTED_EVENT UINT16_MAX +static uint16_t supported_event_map[MAX_EVENT_ID +1 ]; + +/* +* Called upon initialization to build PMCEID0_EL0 or PMCEID1_EL0 (indicated by +* 'which'). We also use it to build a map of ARM event numbers to indices in +* our pm_events array. +* +* Note: Events in the 0x40XX range are not currently supported. +*/ +uint64_t get_pmceid (CPUARMState *env,unsigned which) +{ +uint64_t pmceid =0 ; +unsigned int i; + +assert (which <=1 ); + +for (i =0 ; i <ARRAY_SIZE (supported_event_map); i++) { + supported_event_map[i] =UNSUPPORTED_EVENT ; + } + +for (i =0 ; i <ARRAY_SIZE (pm_events); i++) { +const pm_event *cnt = &pm_events[i]; +assert (cnt->number <=MAX_EVENT_ID ); +/* We do not currently support events in the 0x40xx range */ +assert (cnt->number <=0x3f );
target/arm/helper.c static inline uint64_t pmu_counter_mask(CPUARMState *env) · line 1068
Quoted 10 lines
target/arm/helper.c +10
-0+ +if ((cnt->number &0x20 ) == (which <<6 ) && + cnt->supported (env)) { + pmceid |= (1 << (cnt->number &0x1f )); + supported_event_map[cnt->number] = i; + } + } +return pmceid; +} +
Otherwise
thanks
-- PMM
Re: [Qemu-arm] [PATCH v8 08/13] target/arm: Add array for supported PMU events, generate PMCEID[01]_EL0
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Aaron Lindsay
target/arm/cpu.h +0
-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);
Quoted 14 lines
target/arm/cpu.h void pmu_op_finish(CPUARMState *env); · line 1003
Quoted 8 lines
target/arm/cpu.h +8
-0+/* +* get_pmceid +* @env: CPUARMState +* +* Return the PMCEID[01]_EL0 register values corresponding to the counters +* which are supported given the current configuration (`which` is 0 or 1 to +* indicate which PMCEID should be returned) +*/ Nit: you should have a line here below the one for "@env" for the "@which" parameter, and the reference to it in the text should just be "@which", not "
which" (or just put that description in the line saying what @which is rather than having it in a parenthetical).
Thanks, I've fixed this for v9.
-Aaron
PATCH v8 9/13 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.1
PATCH v8 10/13 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.1
PATCH v8 11/13 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.1
PATCH v8 12/13 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.1
PATCH v8 13/13 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 | 7 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 139 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 (arm_feature (&cpu->env,ARM_FEATURE_PMU ) && 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 +7 -0
@@ -733,6 +733,8 @@ struct ARMCPU {/* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS ]; +/* Timer used by the PMU */ +QEMUTimer *pmu_timer;/* GPIO outputs for generic timer */ qemu_irq gt_timer_outputs[NUM_GTIMERS ];/* GPIO output for GICv3 maintenance interrupt signal */
@@ -990,6 +992,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.1
Re: [Qemu-devel] [PATCH v8 13/13] target/arm: Send interrupts on PMU counter overflow
Quoted 16 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 | 7 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 139 insertions(+), 6 deletions(-)target/arm/cpu.c +0
-0
target/arm/cpu.c static void arm_cpu_finalizefn(Object *obj) · line 831
Quoted 5 lines
target/arm/cpu.c +2
-0@@ -827,6 +827,13 @@ static void arm_cpu_finalizefn(Object *obj)QLIST_REMOVE (hook, node);g_free (hook); } +#ifndef CONFIG_USER_ONLY +if (arm_feature (&cpu->env,ARM_FEATURE_PMU ) && cpu->pmu_timer) {
No need for two tests here. Just check cpu->pmu_timer. (If it's set for any reason it should be freed, surely.)
target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1346
Quoted 11 lines
target/arm/cpu.c +6
-1@@ -1305,7 +1338,18 @@ 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; +if (!(new_pmccntr & overflow_mask) && + (env->cp15.c15_ccnt & overflow_mask)) {
Fyi, this expression is
env->cp15.c15_ccnt & ~new_pmccntr & overflow_mask
target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1348
Quoted 2 lines
target/arm/cpu.c +2
-0+ env->cp15.c9_pmovsr |= (1 <<31 ); + new_pmccntr &= ~overflow_mask;
Why this line? You just checked that overflow_mask was unset in new_pmccntr above.
target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1371
Quoted 12 lines
target/arm/cpu.c +7
-1@@ -1318,13 +1362,28 @@ void pmccntr_op_start(CPUARMState *env)void pmccntr_op_finish (CPUARMState *env) {if (pmu_counter_enabled (env,31 )) { -uint64_t prev_cycles = env->cp15.c15_ccnt_delta; +#ifndef CONFIG_USER_ONLY +uint64_t delta; +if (env->cp15.c9_pmcr &PMCRLC ) { + delta =UINT64_MAX - env->cp15.c15_ccnt +1 ; + }else { + delta =UINT32_MAX - (uint32_t )env->cp15.c15_ccnt +1 ; + }
FWIW, this is the same as
delta = -env->cp15.c15_ccnt;
if (!(env->cp15.c9_pmcr & PMCRLC)) {
delta = (uint32_t)delta;
}r~
Re: [Qemu-arm] [PATCH v8 13/13] target/arm: Send interrupts on PMU counter overflow
Quoted 40 lines · Richard Henderson
Quoted 16 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 | 7 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 139 insertions(+), 6 deletions(-)target/arm/cpu.c +0
-0target/arm/cpu.c static void arm_cpu_finalizefn(Object *obj) · line 831
Quoted 5 lines
target/arm/cpu.c +2
-0@@ -827,6 +827,13 @@ static void arm_cpu_finalizefn(Object *obj)QLIST_REMOVE (hook, node);g_free (hook); } +#ifndef CONFIG_USER_ONLY +if (arm_feature (&cpu->env,ARM_FEATURE_PMU ) && cpu->pmu_timer) {No need for two tests here. Just check
cpu->pmu_timer. (If it's set for any reason it should be freed, surely.)target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1346
Quoted 11 lines
target/arm/cpu.c +6
-1@@ -1305,7 +1338,18 @@ 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; +if (!(new_pmccntr & overflow_mask) && + (env->cp15.c15_ccnt & overflow_mask)) {Fyi, this expression is
Quoted 6 lines
env->cp15.c15_ccnt & ~new_pmccntr & overflow_masktarget/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1348
Quoted 2 lines
target/arm/cpu.c +2
-0+ env->cp15.c9_pmovsr |= (1 <<31 ); + new_pmccntr &= ~overflow_mask;Why this line? You just checked that
overflow_maskwas unset innew_pmccntrabove.
This ensures that when overflow_bit == 31 (because PMCR.LC is not set) the high 32 bits remain 0 even after an overflow has occurred. As you point out, it's silly when overflow_bit == 64, but I didn't think it was worth the extra conditional to avoid it.
Quoted 15 lines
target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1371
Quoted 12 lines
target/arm/cpu.c +7
-1@@ -1318,13 +1362,28 @@ void pmccntr_op_start(CPUARMState *env)void pmccntr_op_finish (CPUARMState *env) {if (pmu_counter_enabled (env,31 )) { -uint64_t prev_cycles = env->cp15.c15_ccnt_delta; +#ifndef CONFIG_USER_ONLY +uint64_t delta; +if (env->cp15.c9_pmcr &PMCRLC ) { + delta =UINT64_MAX - env->cp15.c15_ccnt +1 ; + }else { + delta =UINT32_MAX - (uint32_t )env->cp15.c15_ccnt +1 ; + }FWIW, this is the same as
Quoted 4 lines
delta = -env->cp15.c15_ccnt;
if (!(env->cp15.c9_pmcr & PMCRLC)) {
delta = (uint32_t)delta;
}Thanks for your review. I'll take a look at your suggested logic simplifications for v9, do you think that this patch looks OK at the big-picture level?
-Aaron
Re: [Qemu-arm] [PATCH v8 13/13] target/arm: Send interrupts on PMU counter overflow
Quoted 46 lines · Aaron Lindsay
Quoted 45 lines · Richard Henderson
Quoted 16 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 | 7 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 139 insertions(+), 6 deletions(-)target/arm/cpu.c +0
-0target/arm/cpu.c static void arm_cpu_finalizefn(Object *obj) · line 831
Quoted 5 lines
target/arm/cpu.c +2
-0@@ -827,6 +827,13 @@ static void arm_cpu_finalizefn(Object *obj)QLIST_REMOVE (hook, node);g_free (hook); } +#ifndef CONFIG_USER_ONLY +if (arm_feature (&cpu->env,ARM_FEATURE_PMU ) && cpu->pmu_timer) {No need for two tests here. Just check
cpu->pmu_timer. (If it's set for any reason it should be freed, surely.)target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1346
Quoted 11 lines
target/arm/cpu.c +6
-1@@ -1305,7 +1338,18 @@ 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; +if (!(new_pmccntr & overflow_mask) && + (env->cp15.c15_ccnt & overflow_mask)) {Fyi, this expression is
env->cp15.c15_ccnt & ~new_pmccntr & overflow_maskQuoted 2 lines
target/arm/cpu.c +2
-0+ env->cp15.c9_pmovsr |= (1 <<31 ); + new_pmccntr &= ~overflow_mask;
Quoted 6 lines
Quoted 1 line
Why this line? You just checked that
overflow_maskwas unset innew_pmccntrabove.This ensures that when
overflow_bit== 31 (because PMCR.LC is not set) the high 32 bits remain 0 even after an overflow has occurred. As you point out, it's silly whenoverflow_bit== 64, but I didn't think it was worth the extra conditional to avoid it.
Eh? But we've set overflow_mask based on PMCR.LC, so what you say here doesn't make sense.
Quoted 3 lines
Thanks for your review. I'll take a look at your suggested logic simplifications for v9, do you think that this patch looks OK at the big-picture level?
Yes, big picture looks good.
r~
Re: [Qemu-arm] [PATCH v8 13/13] target/arm: Send interrupts on PMU counter overflow
Quoted 49 lines · Richard Henderson
Quoted 48 lines · Aaron Lindsay
Quoted 46 lines · Richard Henderson
Quoted 16 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 | 7 +++ target/arm/helper.c | 126 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 139 insertions(+), 6 deletions(-)target/arm/cpu.c +0
-0target/arm/cpu.c static void arm_cpu_finalizefn(Object *obj) · line 831
Quoted 5 lines
target/arm/cpu.c +2
-0@@ -827,6 +827,13 @@ static void arm_cpu_finalizefn(Object *obj)QLIST_REMOVE (hook, node);g_free (hook); } +#ifndef CONFIG_USER_ONLY +if (arm_feature (&cpu->env,ARM_FEATURE_PMU ) && cpu->pmu_timer) {No need for two tests here. Just check
cpu->pmu_timer. (If it's set for any reason it should be freed, surely.)target/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1346
Quoted 11 lines
target/arm/cpu.c +6
-1@@ -1305,7 +1338,18 @@ 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; +if (!(new_pmccntr & overflow_mask) && + (env->cp15.c15_ccnt & overflow_mask)) {Fyi, this expression is
env->cp15.c15_ccnt & ~new_pmccntr & overflow_masktarget/arm/cpu.c void pmccntr_op_start(CPUARMState *env) · line 1348
Quoted 2 lines
target/arm/cpu.c +2
-0+ env->cp15.c9_pmovsr |= (1 <<31 ); + new_pmccntr &= ~overflow_mask;Why this line? You just checked that
overflow_maskwas unset innew_pmccntrabove.
Quoted 7 lines
Quoted 4 lines
This ensures that when
overflow_bit== 31 (because PMCR.LC is not set) the high 32 bits remain 0 even after an overflow has occurred. As you point out, it's silly whenoverflow_bit== 64, but I didn't think it was worth the extra conditional to avoid it.Eh? But we've set
overflow_maskbased on PMCR.LC, so what you say here doesn't make sense.
Sorry, I had an off-by-one-bit think-o I couldn't get past until I started typing a concrete example to explain myself. I'll change this line to be:
if (!(env->cp15.c9_pmcr & PMCRLC))
new_pmccntr &= 0xffffffff;
-Aaron
Re: [Qemu-devel] [PATCH v8 13/13] target/arm: Send interrupts on PMU counter overflow
Quoted 9 lines · Aaron Lindsay
Quoted 2 lines
Eh? But we've set
overflow_maskbased on PMCR.LC, so what you say here doesn't make sense.Sorry, I had an off-by-one-bit think-o I couldn't get past until I started typing a concrete example to explain myself. I'll change this line to be:
if (!(env->cp15.c9_pmcr & PMCRLC))
new_pmccntr &= 0xffffffff;
Ah, much better. Thanks.
r~