More fully implement ARM PMUv3
v4 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 and filter them based on execution mode. 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.
Notable changes since v3:
* Detect counter overflow and send interrupts accordingly (adds a 'shadow' copy of both PMCCNTR and general-purpose counters, possibly/probably Doing It Wrong)
* Update counter filtering code to more closely resemble the ARM documentation in form and functionality
* Don't mix EL change hooks and KVM
* Don't call gen_io_start/end if not actually using icount
* Reorganized a few of the patches to more logically group changes
* Clarify and otherwise improve a few comments
* There are also a number of less significant changes scattered around
Thanks,
Aaron
Aaron Lindsay (21):
target/arm: Check PMCNTEN for whether PMCCNTR is enabled target/arm: Treat PMCCNTR as alias of PMCCNTR_EL0 target/arm: Reorganize PMCCNTR accesses
target/arm: Mask PMU register writes based on PMCR_EL0.N target/arm: Fetch GICv3 state directly from CPUARMState target/arm: Support multiple EL change hooks
target/arm: Add pre-EL change hooks
target/arm: Allow EL change hooks to do IO
target/arm: Fix bitmask for PMCCFILTR writes
target/arm: Filter cycle counter based on PMCCFILTR_EL0 target/arm: Allow AArch32 access for PMCCFILTR target/arm: Make PMOVSCLR and PMUSERENR 64 bits wide target/arm: Add ARM_FEATURE_V7VE for v7 Virtualization Extensions target/arm: Implement PMOVSSET
target/arm: Add array for supported PMU events, generate PMCEID[01] 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: Mark PMINTENSET accesses as possibly doing IO target/arm: Send interrupts on PMU counter overflow
hw/intc/arm_gicv3_cpuif.c | 10 +- target/arm/cpu.c | 68 +++- target/arm/cpu.h | 119 +++++-- target/arm/cpu64.c | 2 - target/arm/helper.c | 752 ++++++++++++++++++++++++++++++++++++++------- target/arm/internals.h | 14 +- target/arm/op_helper.c | 8 + target/arm/translate-a64.c | 6 + target/arm/translate.c | 12 + 9 files changed, 834 insertions(+), 157 deletions(-)
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 1/21 target/arm: Check PMCNTEN for whether PMCCNTR is enabled
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -994,7 +994,7 @@ static inline bool arm_ccnt_enabled(CPUARMState *env) {/* This does not support checking PMCCFILTR_EL0 register */ -if (!(env->cp15.c9_pmcr &PMCRE )) { +if (!(env->cp15.c9_pmcr &PMCRE ) || !(env->cp15.c9_pmcnten & (1 <<31 ))) {return false; }
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 2/21 target/arm: Treat PMCCNTR as alias of PMCCNTR_EL0
In reply to Aaron LindsayThey share the same underlying state
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -1318,7 +1318,7 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.c9_pmselr), .writefn = pmselr_write, .raw_writefn = raw_write, }, { .name = "PMCCNTR", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 0, - .access = PL0_RW, .resetvalue = 0, .type = ARM_CP_IO, + .access = PL0_RW, .resetvalue = 0, .type = ARM_CP_ALIAS | ARM_CP_IO, .readfn = pmccntr_read, .writefn = pmccntr_write32, .accessfn = pmreg_access_ccntr }, { .name = "PMCCNTR_EL0", .state = ARM_CP_STATE_AA64,
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 3/21 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 ensure 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 | 28 ++++++++++----- target/arm/helper.c | 100 ++++++++++++++++++++++++++++------------------------ 2 files changed, 73 insertions(+), 55 deletions(-)
target/arm/cpu.h +20 -8
@@ -454,10 +454,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-corect 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 */
@@ -890,15 +900,17 @@ int cpu_arm_signal_handler(int host_signum, void *pinfo, void *puc);/** -* pmccntr_sync +* pmccntr_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 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, and the return value +* from pmccntr_op_start must be supplied as the second argument to +* pmccntr_op_finish. */ -void pmccntr_sync (CPUARMState *env); +void pmccntr_op_start (CPUARMState *env); +void pmccntr_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 +53 -47
145 lines not on this page · raw message
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [Qemu-devel] [PATCH v4 03/21] target/arm: Reorganize PMCCNTR accesses
Quoted 29 lines · Aaron Lindsay
pmccntr_readandpmccntr_writecontained duplicate code that was already being handled bypmccntr_sync. Consolidate the duplicated code into two
functions:pmccntr_op_startandpmccntr_op_finish. Add a companion toc15_ccntin CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensure time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches.Signed-off-by Aaron Lindsay <[email protected]>--- target/arm/cpu.h | 28 ++++++++++----- target/arm/helper.c | 100 ++++++++++++++++++++++++++++------------------------ 2 files changed, 73 insertions(+), 55 deletions(-)target/arm/cpu.h +4
-2@@ -454,10 +454,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-corect value is being read/set.
target/arm/cpu.h typedef struct CPUARMState { · line 470
Quoted 10 lines
target/arm/cpu.h +8
-0*/ 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;
So the key question here is: how does this work for VM migration?
thanks
-- PMM
Re: [Qemu-arm] [PATCH v4 03/21] target/arm: Reorganize PMCCNTR accesses
Quoted 34 lines · Peter Maydell
Quoted 33 lines · Aaron Lindsay
pmccntr_readandpmccntr_writecontained duplicate code that was already being handled bypmccntr_sync. Consolidate the duplicated code into two
functions:pmccntr_op_startandpmccntr_op_finish. Add a companion toc15_ccntin CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensure time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches.Signed-off-by Aaron Lindsay <[email protected]>--- target/arm/cpu.h | 28 ++++++++++----- target/arm/helper.c | 100 ++++++++++++++++++++++++++++------------------------ 2 files changed, 73 insertions(+), 55 deletions(-)target/arm/cpu.h +6
-2@@ -454,10 +454,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-corect 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
Quoted 8 lines
target/arm/cpu.h typedef struct CPUARMState { · line 470
Quoted 6 lines
target/arm/cpu.h +6
-0+* 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;So the key question here is: how does this work for VM migration?
To be honest, I'm not sure I fully understand the things I need to be looking out for with VM migration.
My guess, though, is that this current implementation is not sufficient. Perhaps there needs to be logic to ensure that c15_ccnt is the current architectural value before migration and also to setup c15_ccnt_delta to be the delta between that architectural value and the underlying cycle count upon inbound migration. Does that sound like an approach which would fit well within the rest of the migration framework?
-Aaron
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [Qemu-arm] [PATCH v4 03/21] target/arm: Reorganize PMCCNTR accesses
Quoted 35 lines · Aaron Lindsay
Quoted 29 lines · Peter Maydell
Quoted 17 lines · Aaron Lindsay
pmccntr_readandpmccntr_writecontained duplicate code that was already being handled bypmccntr_sync. Consolidate the duplicated code into two
functions:pmccntr_op_startandpmccntr_op_finish. Add a companion toc15_ccntin CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensure time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches.Signed-off-by Aaron Lindsay <[email protected]>target/arm/cpu.h +4
-2-/* 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-corect value is being read/set. target/arm/cpu.h typedef struct CPUARMState { · line 470
Quoted 10 lines
target/arm/cpu.h +8
-0*/ 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;Quoted 1 line
So the key question here is: how does this work for VM migration?
To be honest, I'm not sure I fully understand the things I need to be looking out for with VM migration.
Quoted 6 lines
My guess, though, is that this current implementation is not sufficient. Perhaps there needs to be logic to ensure that
c15_ccntis the current architectural value before migration and also to setupc15_ccnt_deltato be the delta between that architectural value and the underlying cycle count upon inbound migration. Does that sound like an approach which would fit well within the rest of the migration framework?
You need to deal with two different situations:
(1) migration from an older QEMU which doesn't have this patchset
(2) migration from a QEMU with this patchset to one with this patchset
Either:
(a) all the architectural state can be expressed in our existing
state fields in whatever the previous format was -- in this case you just need to ensure that cpu_pre_save() and cpu_post_load() put the state there and unpack it again
(b) we were missing some architectural state and really do need
to transfer more over the wire than we were before -- in this case you need to add a new subsection to the vmstate which has the fields that contain that new state, and give the subsection a suitable 'needed' function to indicate when the subsection should be transferred plus pre_load and post_load functions that allow us to cope correctly with the case of the older QEMU that doesn't send the subsection.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 03/21] target/arm: Reorganize PMCCNTR accesses
Quoted 47 lines · Peter Maydell
Quoted 35 lines · Aaron Lindsay
Quoted 29 lines · Peter Maydell
Quoted 17 lines · Aaron Lindsay
pmccntr_readandpmccntr_writecontained duplicate code that was already being handled bypmccntr_sync. Consolidate the duplicated code into two
functions:pmccntr_op_startandpmccntr_op_finish. Add a companion toc15_ccntin CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensure time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches.Signed-off-by Aaron Lindsay <[email protected]>target/arm/cpu.h +4
-2-/* 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-corect value is being read/set. target/arm/cpu.h typedef struct CPUARMState { · line 470
Quoted 10 lines
target/arm/cpu.h +8
-0*/ 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;Quoted 1 line
So the key question here is: how does this work for VM migration?
To be honest, I'm not sure I fully understand the things I need to be looking out for with VM migration.
Quoted 6 lines
My guess, though, is that this current implementation is not sufficient. Perhaps there needs to be logic to ensure that
c15_ccntis the current architectural value before migration and also to setupc15_ccnt_deltato be the delta between that architectural value and the underlying cycle count upon inbound migration. Does that sound like an approach which would fit well within the rest of the migration framework?You need to deal with two different situations:
(1) migration from an older QEMU which doesn't have this patchset
(2) migration from a QEMU with this patchset to one with this patchset
Quoted 12 lines
Either:
(a) all the architectural state can be expressed in our existing
state fields in whatever the previous format was -- in this case you just need to ensure thatcpu_pre_save()andcpu_post_load()put the state there and unpack it again
(b) we were missing some architectural state and really do need
to transfer more over the wire than we were before -- in this case you need to add a new subsection to the vmstate which has the fields that contain that new state, and give the subsection a suitable 'needed' function to indicate when the subsection should be transferred pluspre_loadandpost_loadfunctions that allow us to cope correctly with the case of the older QEMU that doesn't send the subsection.
Okay, thanks! I didn't manage to get to this before v5, but look into it more for v6.
-Aaron
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [Qemu-arm] [PATCH v4 03/21] target/arm: Reorganize PMCCNTR accesses
In reply to Aaron LindsayQuoted 8 lines · Aaron Lindsay
pmccntr_readandpmccntr_writecontained duplicate code that was already being handled bypmccntr_sync. Consolidate the duplicated code into two
functions:pmccntr_op_startandpmccntr_op_finish. Add a companion toc15_ccntin CPUARMState so that we can simultaneously save both the architectural register value and the last underlying cycle count - this ensure time isn't lost and will also allow us to access the 'old' architectural register value in order to detect overflows in later patches.
Can we handle the overflow case by setting up a timer that will expire when the counter would overflow? We'll want that anyway to be able to signal an interrupt on overflows. That would avoid the need to have an extra field in the CPU state structure, I think. Since PMCCNTR_EL0 is 64 bits it's not going to overflow very often so the slight overhead of a timer firing is not going to be a problem...
thanks
-- PMM
PATCH v4 4/21 target/arm: Mask PMU register writes based on PMCR_EL0.N
In reply to Aaron LindsayThis is in preparation for enabling counters other than PMCCNTR
--- target/arm/helper.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
target/arm/helper.c +22 -9
@@ -52,11 +52,6 @@ typedef struct V8M_SAttributes {static void v8m_security_lookup (CPUARMState *env,uint32_t address,MMUAccessType access_type,ARMMMUIdx mmu_idx,V8M_SAttributes *sattrs); - -/* Definitions for the PMCCNTR and PMCR registers */ -#define PMCRD 0x8 -#define PMCRC 0x4 -#define PMCRE 0x1#endif static int vfp_gdb_get_reg (CPUARMState *env,uint8_t *buf,int reg)
@@ -906,6 +901,24 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { REGINFO_SENTINEL }; +/* Definitions for the PMU registers */ +#define PMCRN_MASK 0xf800 +#define PMCRN_SHIFT 11 +#define PMCRD 0x8 +#define PMCRC 0x4 +#define PMCRE 0x1 + +static inline uint32_t pmu_num_counters (CPUARMState *env) +{ +return (env->cp15.c9_pmcr &PMCRN_MASK ) >>PMCRN_SHIFT ; +} + +/* Bits allowed to be set/cleared for PMCNTEN* and PMINTEN* */ +static inline uint64_t pmu_counter_mask (CPUARMState *env) +{ +return (1 <<31 ) | ((1 <<pmu_num_counters (env)) -1 ); +} +static CPAccessResult pmreg_access (CPUARMState *env,const ARMCPRegInfo *ri,bool isread) {
@@ -1119,14 +1132,14 @@ static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri,static void pmcntenset_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { - value &= (1 <<31 ); + value &=pmu_counter_mask (env); env->cp15.c9_pmcnten |= value; }static void pmcntenclr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { - value &= (1 <<31 ); + value &=pmu_counter_mask (env); env->cp15.c9_pmcnten &= ~value; }
@@ -1174,14 +1187,14 @@ static void pmintenset_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {/* We have no event counters so only the C bit can be changed */ - value &= (1 <<31 ); + value &=pmu_counter_mask (env); env->cp15.c9_pminten |= value; }static void pmintenclr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { - value &= (1 <<31 ); + value &=pmu_counter_mask (env); env->cp15.c9_pminten &= ~value; }
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 5/21 target/arm: Fetch GICv3 state directly from CPUARMState
In reply to Aaron LindsayThis eliminates the need for fetching it from el_change_hook_opaque, and allows for supporting multiple el_change_hooks without having to hack something together to find the registered opaque belonging to GICv3.
--- hw/intc/arm_gicv3_cpuif.c | 10 ++-------- target/arm/cpu.h | 10 ---------- 2 files changed, 2 insertions(+), 18 deletions(-)
hw/intc/arm_gicv3_cpuif.c +2 -8
@@ -29,11 +29,7 @@ void gicv3_set_gicv3state(CPUState *cpu, GICv3CPUState *s)static GICv3CPUState *icc_cs_from_env (CPUARMState *env) { -/* Given the CPU, find the right GICv3CPUState struct. -* Since we registered the CPU interface with the EL change hook as -* the opaque pointer, we can just directly get from the CPU to it. -*/ -return arm_get_el_change_hook_opaque (arm_env_get_cpu (env)); +return env->gicv3state; }static bool gicv3_use_ns_bank (CPUARMState *env)
@@ -2615,9 +2611,7 @@ void gicv3_init_cpuif(GICv3State *s)* it might be with code translated by CPU 0 but run by CPU 1, in * which case we'd get the wrong value. * So instead we define the regs with no ri->opaque info, and -* get back to the GICv3CPUState from the ARMCPU by reading back -* the opaque pointer from the el_change_hook, which we're going -* to need to register anyway. +* get back to the GICv3CPUState from the CPUARMState. */ define_arm_cp_regs (cpu, gicv3_cpuif_reginfo); if (arm_feature(&cpu->env, ARM_FEATURE_EL2)
target/arm/cpu.h +0 -10
@@ -2915,16 +2915,6 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHook *hook, void *opaque);/** -* arm_get_el_change_hook_opaque: -* Return the opaque data that will be used by the el_change_hook -* for this CPU. -*/ -static inline void *arm_get_el_change_hook_opaque (ARMCPU *cpu) -{ -return cpu->el_change_hook_opaque; -} - -/** * aa32_vfp_dreg: * Return a pointer to the Dn register within env in 32-bit mode. */
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 6/21 target/arm: Support multiple EL change hooks
In reply to Aaron Lindsay--- target/arm/cpu.c | 21 ++++++++++++++++----- target/arm/cpu.h | 20 ++++++++++---------- target/arm/internals.h | 7 ++++--- 3 files changed, 30 insertions(+), 18 deletions(-)
target/arm/cpu.c +16 -5
@@ -55,13 +55,15 @@ static bool arm_cpu_has_work(CPUState *cs) | CPU_INTERRUPT_EXITTB); } -void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHook *hook, +void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook,void *opaque) { -/* We currently only support registering a single hook function */ -assert (!cpu->el_change_hook); - cpu->el_change_hook = hook; - cpu->el_change_hook_opaque = opaque; +ARMELChangeHook *entry =g_new0 (ARMELChangeHook,1 ); + + entry->hook = hook; + entry->opaque = opaque; + +QLIST_INSERT_HEAD (&cpu->el_change_hooks, entry, node); }static void cp_reg_reset (gpointer key,gpointer value,gpointer opaque)
@@ -552,6 +554,8 @@ static void arm_cpu_initfn(Object *obj) cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); +QLIST_INIT (&cpu->el_change_hooks); +#ifndef CONFIG_USER_ONLY /* Our inbound IRQ and FIQ lines */ if (kvm_enabled ()) {
@@ -713,7 +717,14 @@ static void arm_cpu_post_init(Object *obj)static void arm_cpu_finalizefn (Object *obj) {ARMCPU *cpu =ARM_CPU (obj); +ARMELChangeHook *hook, *next; +g_hash_table_destroy (cpu->cp_regs); + + QLIST_FOREACH_SAFE(hook, &cpu->el_change_hooks, node, next) { +QLIST_REMOVE (hook, node); +g_free (hook); + } }static void arm_cpu_realizefn (DeviceState *dev,Error **errp)
target/arm/cpu.h +10 -10
@@ -642,12 +642,17 @@ typedef struct CPUARMState { } CPUARMState;/** -* ARMELChangeHook: +* ARMELChangeHookFn: * type of a function which can be registered via arm_register_el_change_hook() * to get callbacks when the CPU changes its exception level or mode. */ -typedef void ARMELChangeHook (ARMCPU *cpu,void *opaque); - +typedef void ARMELChangeHookFn (ARMCPU *cpu,void *opaque); +typedef struct ARMELChangeHook ARMELChangeHook ; +struct ARMELChangeHook { +ARMELChangeHookFn *hook; +void *opaque; +QLIST_ENTRY (ARMELChangeHook) node; +};/* These values map onto the return values for * QEMU_PSCI_0_2_FN_AFFINITY_INFO */
@@ -836,8 +841,7 @@ struct ARMCPU {*/ bool cfgend; -ARMELChangeHook *el_change_hook; -void *el_change_hook_opaque; + QLIST_HEAD(, ARMELChangeHook) el_change_hooks;int32_t node_id;/* NUMA node this CPU belongs to */
@@ -2906,12 +2910,8 @@ static inline AddressSpace *arm_addressspace(CPUState *cs, MemTxAttrs attrs)* CPU changes exception level or mode. The hook function will be * passed a pointer to the ARMCPU and the opaque data pointer passed * to this function when the hook was registered. -* -* Note that we currently only support registering a single hook function, -* and will assert if this function is called twice. -* This facility is intended for the use of the GICv3 emulation. */ -void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHook *hook, +void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook,void *opaque);/**
target/arm/internals.h +4 -3
@@ -727,11 +727,12 @@ void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, int mmu_idx, MemTxAttrs attrs, MemTxResult response, uintptr_t retaddr); -/* Call the EL change hook if one has been registered */ +/* Call any registered EL change hooks */ static inline void arm_call_el_change_hook (ARMCPU *cpu) { -if (cpu->el_change_hook) { - cpu->el_change_hook (cpu, cpu->el_change_hook_opaque); +ARMELChangeHook *hook, *next; + QLIST_FOREACH_SAFE(hook, &cpu->el_change_hooks, node, next) { + hook->hook (cpu, hook->opaque); } }
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 7/21 target/arm: Add pre-EL change hooks
In reply to Aaron LindsayBecause the design of the PMU requires that the counter values be converted between their delta and guest-visible forms for mode filtering, an additional hook which occurs before the EL is changed is necessary.
--- target/arm/cpu.c | 16 ++++++++++++++++ target/arm/cpu.h | 22 +++++++++++++++++++--- target/arm/helper.c | 14 ++++++++------ target/arm/internals.h | 7 +++++++ target/arm/op_helper.c | 8 ++++++++ 5 files changed, 58 insertions(+), 9 deletions(-)
target/arm/cpu.c +16 -0
@@ -55,6 +55,17 @@ static bool arm_cpu_has_work(CPUState *cs) | CPU_INTERRUPT_EXITTB); } +void arm_register_pre_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook, +void *opaque) +{ +ARMELChangeHook *entry =g_new0 (ARMELChangeHook,1 ); + + entry->hook = hook; + entry->opaque = opaque; + +QLIST_INSERT_HEAD (&cpu->pre_el_change_hooks, entry, node); +} +void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook,void *opaque) {
@@ -554,6 +565,7 @@ static void arm_cpu_initfn(Object *obj) cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); +QLIST_INIT (&cpu->pre_el_change_hooks);QLIST_INIT (&cpu->el_change_hooks);#ifndef CONFIG_USER_ONLY
@@ -721,6 +733,10 @@ static void arm_cpu_finalizefn(Object *obj)g_hash_table_destroy (cpu->cp_regs); + QLIST_FOREACH_SAFE(hook, &cpu->pre_el_change_hooks, node, next) { +QLIST_REMOVE (hook, node); +g_free (hook); + } QLIST_FOREACH_SAFE(hook, &cpu->el_change_hooks, node, next) {QLIST_REMOVE (hook, node);g_free (hook);
target/arm/cpu.h +19 -3
@@ -841,6 +841,7 @@ struct ARMCPU {*/ bool cfgend; + QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks;int32_t node_id;/* NUMA node this CPU belongs to */
@@ -2905,14 +2906,29 @@ static inline AddressSpace *arm_addressspace(CPUState *cs, MemTxAttrs attrs)#endif /** -* arm_register_el_change_hook: -* Register a hook function which will be called back whenever this +* arm_register_pre_el_change_hook: +* Register a hook function which will be called immediately before this * CPU changes exception level or mode. The hook function will be * passed a pointer to the ARMCPU and the opaque data pointer passed * to this function when the hook was registered. +* +* Note that if a pre-change hook is called, any registered post-change hooks +* are guaranteed to subsequently be called. */ -void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook, +void arm_register_pre_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook,void *opaque); +/** +* arm_register_el_change_hook: +* Register a hook function which will be called immediately after this +* CPU changes exception level or mode. The hook function will be +* passed a pointer to the ARMCPU and the opaque data pointer passed +* to this function when the hook was registered. +* +* Note that any registered hooks registered here are guaranteed to be called +* if pre-change hooks have been. +*/ +void arm_register_el_change_hook (ARMCPU *cpu,ARMELChangeHookFn *hook,void + *opaque);/** * aa32_vfp_dreg:
target/arm/helper.c +8 -6
@@ -8254,6 +8254,14 @@ void arm_cpu_do_interrupt(CPUState *cs)return ; } +/* Hooks may change global state so BQL should be held, also the +* BQL needs to be held for any modification of +* cs->interrupt_request. +*/ +g_assert (qemu_mutex_iothread_locked ()); + +arm_call_pre_el_change_hook (cpu); +assert (!excp_is_internal (cs->exception_index));if (arm_el_is_aa64 (env, new_el)) {arm_cpu_do_interrupt_aarch64 (cs);
@@ -8261,12 +8269,6 @@ void arm_cpu_do_interrupt(CPUState *cs)arm_cpu_do_interrupt_aarch32 (cs); } -/* Hooks may change global state so BQL should be held, also the -* BQL needs to be held for any modification of -* cs->interrupt_request. -*/ -g_assert (qemu_mutex_iothread_locked ()); -arm_call_el_change_hook (cpu);if (!kvm_enabled ()) {
target/arm/internals.h +7 -0
@@ -728,6 +728,13 @@ void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, MemTxResult response, uintptr_t retaddr);/* Call any registered EL change hooks */ +static inline void arm_call_pre_el_change_hook (ARMCPU *cpu) +{ +ARMELChangeHook *hook, *next; + QLIST_FOREACH_SAFE(hook, &cpu->pre_el_change_hooks, node, next) { + hook->hook (cpu, hook->opaque); + } +}static inline void arm_call_el_change_hook (ARMCPU *cpu) {ARMELChangeHook *hook, *next;
target/arm/op_helper.c +8 -0
@@ -511,6 +511,10 @@ void HELPER(cpsr_write)(CPUARMState *env, uint32_t val, uint32_t mask)/* Write the CPSR for a 32-bit exception return */ void HELPER (cpsr_write_eret )(CPUARMState *env,uint32_t val) { +qemu_mutex_lock_iothread (); +arm_call_pre_el_change_hook (arm_env_get_cpu (env)); +qemu_mutex_unlock_iothread (); +cpsr_write (env, val,CPSR_ERET_MASK , CPSRWriteExceptionReturn);/* Generated code has already stored the new PC value, but
@@ -1028,6 +1032,10 @@ void HELPER(exception_return)(CPUARMState *env) goto illegal_return; } +qemu_mutex_lock_iothread (); +arm_call_pre_el_change_hook (arm_env_get_cpu (env)); +qemu_mutex_unlock_iothread (); +if (!return_to_aa64) { env->aarch64 =0 ;/* We do a raw CPSR write because aarch64_sync_64_to_32()
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 8/21 target/arm: Allow EL change hooks to do IO
In reply to Aaron LindsayDuring code generation, surround CPSR writes and exception returns which call the EL change hooks with gen_io_start/end. The immediate need is for the PMU to access the clock and icount during EL change to support mode filtering.
--- target/arm/translate-a64.c | 6 ++++++ target/arm/translate.c | 12 ++++++++++++ 2 files changed, 18 insertions(+)
target/arm/translate-a64.c +6 -0
@@ -1930,7 +1930,13 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)unallocated_encoding (s);return ; } +if (tb_cflags (s->base.tb) &CF_USE_ICOUNT ) { +gen_io_start (); + }gen_helper_exception_return (cpu_env); +if (tb_cflags (s->base.tb) &CF_USE_ICOUNT ) { +gen_io_end (); + }/* Must exit loop to check un-masked IRQs */ s->base.is_jmp =DISAS_EXIT ;return ;
target/arm/translate.c +12 -0
@@ -4548,7 +4548,13 @@ static void gen_rfe(DisasContext *s, TCGv_i32 pc, TCGv_i32 cpsr)* appropriately depending on the new Thumb bit, so it must * be called after storing the new PC. */ +if (tb_cflags (s->base.tb) &CF_USE_ICOUNT ) { +gen_io_start (); + }gen_helper_cpsr_write_eret (cpu_env, cpsr); +if (tb_cflags (s->base.tb) &CF_USE_ICOUNT ) { +gen_io_end (); + }tcg_temp_free_i32 (cpsr);/* Must exit loop to check un-masked IRQs */ s->base.is_jmp =DISAS_EXIT ;
@@ -9843,7 +9849,13 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)if (exc_return) {/* Restore CPSR from SPSR. */ tmp =load_cpu_field (spsr); +if (tb_cflags (s->base.tb) &CF_USE_ICOUNT ) { +gen_io_start (); + }gen_helper_cpsr_write_eret (cpu_env, tmp); +if (tb_cflags (s->base.tb) &CF_USE_ICOUNT ) { +gen_io_end (); + }tcg_temp_free_i32 (tmp);/* Must exit loop to check un-masked IRQs */ s->base.is_jmp =DISAS_EXIT ;
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 9/21 target/arm: Fix bitmask for PMCCFILTR writes
In reply to Aaron LindsayIt was shifted to the left one bit too few.
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -1125,7 +1125,7 @@ static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {pmccntr_op_start (env); - env->cp15.pmccfiltr_el0 = value &0x7E000000 ; + env->cp15.pmccfiltr_el0 = value &0xfc000000 ;pmccntr_op_finish (env); }
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 10/21 target/arm: Filter cycle counter based on PMCCFILTR_EL0
In reply to Aaron LindsayThe pmu_counter_enabled and pmu_op_start/finish functions are generic (as opposed to PMCCNTR-specific) to allow for the implementation of other events.
--- target/arm/cpu.c | 3 ++ target/arm/cpu.h | 22 +++++++++- target/arm/helper.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 129 insertions(+), 10 deletions(-)
target/arm/cpu.c +3 -0
@@ -896,6 +896,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 +21 -1
@@ -917,6 +917,24 @@ int cpu_arm_signal_handler(int host_signum, void *pinfo,void pmccntr_op_start (CPUARMState *env);void pmccntr_op_finish (CPUARMState *env); +/** +* pmu_op_start/finish +* @env: CPUARMState +* +* 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, and the return value +* from pmu_op_start must be supplied as the second argument to pmu_op_finish. +*/ +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
@@ -978,7 +996,8 @@ void pmccntr_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)
@@ -988,6 +1007,7 @@ void pmccntr_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 +105 -9
168 lines not on this page · raw message
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 11/21 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
@@ -918,6 +918,10 @@ static const ARMCPRegInfo v6_cp_reginfo[] = {#define PMXEVTYPER_MT 0x02000000#define PMXEVTYPER_EVTCOUNT 0x000003ff +#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 ;
@@ -1221,10 +1225,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) +{ +uint64_t saved_cycles =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, saved_cycles); +} + +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) {
@@ -1442,6 +1462,11 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .type = ARM_CP_IO, .readfn = pmccntr_read, .writefn = pmccntr_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,
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 12/21 target/arm: Make PMOVSCLR and PMUSERENR 64 bits wide
In reply to Aaron LindsayThis is a bug fix to ensure 64-bit reads of these registers don't read adjacent data.
--- target/arm/cpu.h | 4 ++-- target/arm/helper.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-)
target/arm/cpu.h +2 -2
@@ -367,8 +367,8 @@ typedef struct CPUARMState {uint32_t c9_data;uint64_t c9_pmcr;/* performance monitor control register */ uint64_t c9_pmcnten;/* perf monitor counter enables */ -uint32_t c9_pmovsr;/* perf monitor overflow status */ -uint32_t c9_pmuserenr;/* perf monitor user enable */ +uint64_t c9_pmovsr;/* perf monitor overflow status */ +uint64_t c9_pmuserenr;/* perf monitor user enable */ uint64_t c9_pmselr;/* perf monitor counter selection register */ uint64_t c9_pminten;/* perf monitor interrupt enables */ union {/* Memory attribute redirection */
target/arm/helper.c +3 -2
@@ -1427,7 +1427,8 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten), .writefn = pmcntenclr_write }, { .name = "PMOVSR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 3, - .access = PL0_RW, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), + .access = PL0_RW, + .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmovsr), .accessfn = pmreg_access, .writefn = pmovsr_write, .raw_writefn = raw_write },
@@ -1487,7 +1488,7 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .accessfn = pmreg_access_xevcntr }, { .name = "PMUSERENR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 0, .access = PL0_R | PL1_RW, .accessfn = access_tpm, - .fieldoffset = offsetof(CPUARMState, cp15.c9_pmuserenr), + .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmuserenr), .resetvalue = 0, .writefn = pmuserenr_write, .raw_writefn = raw_write }, { .name = "PMUSERENR_EL0", .state = ARM_CP_STATE_AA64,
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 13/21 target/arm: Add ARM_FEATURE_V7VE for v7 Virtualization Extensions
In reply to Aaron Lindsay--- target/arm/cpu.c | 3 +++ target/arm/cpu.h | 1 + 2 files changed, 4 insertions(+)
target/arm/cpu.c +3 -0
@@ -774,6 +774,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)/* Some features automatically imply others: */ if (arm_feature (env,ARM_FEATURE_V8 )) {set_feature (env,ARM_FEATURE_V7 ); +set_feature (env,ARM_FEATURE_V7VE );set_feature (env,ARM_FEATURE_ARM_DIV );set_feature (env,ARM_FEATURE_LPAE ); }
@@ -1490,6 +1491,7 @@ static void cortex_a7_initfn(Object *obj) cpu->dtb_compatible ="arm,cortex-a7" ;set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_V7VE );set_feature (&cpu->env,ARM_FEATURE_VFP4 );set_feature (&cpu->env,ARM_FEATURE_NEON );set_feature (&cpu->env,ARM_FEATURE_THUMB2EE );
@@ -1535,6 +1537,7 @@ static void cortex_a15_initfn(Object *obj) cpu->dtb_compatible ="arm,cortex-a15" ;set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_V7VE );set_feature (&cpu->env,ARM_FEATURE_VFP4 );set_feature (&cpu->env,ARM_FEATURE_NEON );set_feature (&cpu->env,ARM_FEATURE_THUMB2EE );
target/arm/cpu.h +1 -0
@@ -1445,6 +1445,7 @@ enum arm_features {ARM_FEATURE_OMAPCP ,/* OMAP specific CP15 ops handling. */ ARM_FEATURE_THUMB2EE ,ARM_FEATURE_V7MP ,/* v7 Multiprocessing Extensions */ +ARM_FEATURE_V7VE ,/* v7 with Virtualization Extensions */ ARM_FEATURE_V4T ,ARM_FEATURE_V5 , ARM_FEATURE_STRONGARM,
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 14/21 target/arm: Implement PMOVSSET
In reply to Aaron LindsayAdding an array for v7VE+ CP registers was necessary so that PMOVSSET wasn't defined for all v7 processors.
--- target/arm/helper.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
target/arm/helper.c +30 -0
@@ -1262,9 +1262,17 @@ static void pmcntenclr_write(CPUARMState *env, const ARMCPRegInfo *ri,static void pmovsr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { + value &=PMU_COUNTER_MASK (env); 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) {
@@ -1614,6 +1622,25 @@ static const ARMCPRegInfo v7mp_cp_reginfo[] = {REGINFO_SENTINEL }; +static const ARMCPRegInfo v7ve_cp_reginfo[] = { +/* Performance monitor registers which are not implemented in v7 before +* v7ve: +*/ + { .name ="PMOVSSET" , .cp =15 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =3 , + .access =PL0_RW , .accessfn = pmreg_access, + .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) {
@@ -4965,6 +4992,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, v7ve_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 · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 15/21 target/arm: Add array for supported PMU events, generate PMCEID[01]
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 | 20 +++++++++++++------- target/arm/cpu.h | 10 ++++++++++ target/arm/cpu64.c | 2 -- target/arm/helper.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 9 deletions(-)
target/arm/cpu.c +13 -7
@@ -897,9 +897,19 @@ 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_PMU )) { +uint64_t pmceid =get_pmceid (&cpu->env); + cpu->pmceid0 = pmceid &0xffffffff ; + cpu->pmceid1 = (pmceid >>32 ) &0xffffffff ; + +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->pmceid0 =0x00000000 ; + cpu->pmceid1 =0x00000000 ; }if (!arm_feature (env,ARM_FEATURE_EL2 )) {
@@ -1511,8 +1521,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 ;
@@ -1557,8 +1565,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
@@ -935,6 +935,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] register values corresponding to the counters which +* are supported given the current configuration (0 is low 32, 1 is high 32 +* bits) +*/ +uint64_t get_pmceid (CPUARMState *env); +/* 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 -2
@@ -141,8 +141,6 @@ static void aarch64_a57_initfn(Object *obj) cpu->id_isar5 =0x00011121 ; cpu->id_aa64pfr0 =0x00002222 ; cpu->id_aa64dfr0 =0x10305106 ; - cpu->pmceid0 =0x00000000 ; - cpu->pmceid1 =0x00000000 ; cpu->id_aa64isar0 =0x00011120 ; cpu->id_aa64mmfr0 =0x00001124 ; cpu->dbgdidr =0x3516d000 ;
target/arm/helper.c +37 -0
@@ -933,6 +933,43 @@ 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 10 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 ; + +#define SUPPORTED_EVENT_SENTINEL UINT16_MAX +static const pm_event pm_events[] = { + { .number =SUPPORTED_EVENT_SENTINEL } +}; +static uint16_t supported_event_map[0x3f ]; + +/* +* Called upon initialization to build PMCEID0 (low 32 bits) and PMCEID1 (high +* 32). We also use it to build a map of ARM event numbers to indices in +* our pm_events array. +*/ +uint64_t get_pmceid (CPUARMState *env) +{ +uint64_t pmceid =0 ; +unsigned int i =0 ; +while (pm_events[i].number !=SUPPORTED_EVENT_SENTINEL ) { +const pm_event *cnt = &pm_events[i]; +if (cnt->number <0x3f && cnt->supported (env)) { + pmceid |= (1 << cnt->number); + supported_event_map[cnt->number] = i; + }else { + supported_event_map[cnt->number] =SUPPORTED_EVENT_SENTINEL ; + } + i++; + } +return pmceid; +} +static CPAccessResult pmreg_access (CPUARMState *env,const ARMCPRegInfo *ri,bool isread) {
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 16/21 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.
--- target/arm/cpu.h | 3 + target/arm/helper.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 216 insertions(+), 25 deletions(-)
target/arm/cpu.h +3 -0
@@ -468,6 +468,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 +213 -25
347 lines not on this page · raw message
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 17/21 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 | 88 ++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 45 deletions(-)
target/arm/helper.c +43 -45
@@ -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"
@@ -943,8 +944,49 @@ 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 0 ; +#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 +#define SUPPORTED_EVENT_SENTINEL UINT16_MAXstatic 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 { .number =SUPPORTED_EVENT_SENTINEL } };static uint16_t supported_event_map[0x3f ];
@@ -1024,8 +1066,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)
@@ -1140,9 +1180,7 @@ static inline 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;
@@ -1285,42 +1323,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) {
@@ -1633,7 +1635,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),
@@ -1653,7 +1654,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .access = PL0_RW, .accessfn = pmreg_access_ccntr, .type = ARM_CP_IO, .readfn = pmccntr_read, .writefn = pmccntr_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,
@@ -5191,7 +5191,6 @@ void register_cp_regs_for_features(ARMCPU *cpu)* field as main ID register, and we implement only the cycle * count register. */ -#ifndef CONFIG_USER_ONLY ARMCPRegInfo pmcr = { .name ="PMCR" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =0 , .access =PL0_RW ,
@@ -5245,7 +5244,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 · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 18/21 target/arm: PMU: Set PMCR.N to 4
In reply to Aaron LindsayThis both advertises that we support four counters and adds them to the implementation because the PMU_NUM_COUNTERS macro reads this value from the PMCR.
--- target/arm/helper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/arm/helper.c +3 -2
@@ -1587,7 +1587,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)
@@ -5205,7 +5205,8 @@ 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, + /* 4 counters enabled */ + .resetvalue = (cpu->midr & 0xff000000) | (0x4 << PMCRN_SHIFT), .writefn = pmcr_write, .raw_writefn = raw_write, };define_one_arm_cp_reg (cpu, &pmcr);
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 19/21 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
@@ -949,6 +949,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.
@@ -977,6 +986,10 @@ static uint64_t instructions_get_count(CPUARMState *env)#define SUPPORTED_EVENT_SENTINEL UINT16_MAXstatic 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,
@@ -1287,6 +1300,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;
@@ -1632,9 +1663,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 · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 20/21 target/arm: Mark PMINTENSET accesses as possibly doing IO
In reply to Aaron LindsayThis makes it match its AArch64 equivalent, PMINTENSET_EL1
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -1732,7 +1732,7 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .writefn = pmuserenr_write, .raw_writefn = raw_write }, { .name = "PMINTENSET", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 1, .access = PL1_RW, .accessfn = access_tpm, - .type = ARM_CP_ALIAS, + .type = ARM_CP_ALIAS | ARM_CP_IO, .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pminten), .resetvalue = 0, .writefn = pmintenset_write, .raw_writefn = raw_write },
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 21/21 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 | 11 +++++ target/arm/cpu.h | 7 +++ target/arm/helper.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 137 insertions(+), 9 deletions(-)
target/arm/cpu.c +11 -0
@@ -741,6 +741,12 @@ 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 )) { +timer_deinit (cpu->pmu_timer); +timer_free (cpu->pmu_timer); + } +#endif }static void arm_cpu_realizefn (DeviceState *dev,Error **errp)
@@ -907,6 +913,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 (QEMU_CLOCK_VIRTUAL ,1 , arm_pmu_timer_cb, + cpu); +#endif }else { cpu->pmceid0 =0x00000000 ; cpu->pmceid1 =0x00000000 ;
target/arm/cpu.h +7 -0
@@ -702,6 +702,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 */
@@ -933,6 +935,11 @@ 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 */ void pmu_pre_el_change (ARMCPU *cpu,void *ignored);
target/arm/helper.c +119 -9
260 lines not on this page · raw message
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [Qemu-arm] [PATCH v4 21/21] target/arm: Send interrupts on PMU counter overflow
target/arm/helper.c static uint64_t cycles_get_count(CPUARMState *env) · line 992
Quoted 12 lines · Aaron Lindsay
target/arm/helper.c +4
-0@@ -973,6 +986,11 @@ static uint64_t cycles_get_count(CPUARMState *env) }#ifndef CONFIG_USER_ONLY +static int64_t cycles_ns_per (uint64_t cycles) +{ +return ARM_CPU_FREQ /NANOSECONDS_PER_SECOND ; +}
This should be:
return (ARM_CPU_FREQ / NANOSECONDS_PER_SECOND) * cycles;
This took me a while to catch because it doesn't actually affect functional correctness, but means QEMU slows down because the timer callback is called every ns...
target/arm/helper.c void pmccntr_op_start(CPUARMState *env) · line 1264
Quoted 8 lines
target/arm/helper.c +3
-1@@ -1215,13 +1259,24 @@ 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 = ((env->cp15.c9_pmcr &PMCRLC ) ? +UINT64_MAX :UINT32_MAX ) - (uint32_t )env->cp15.c15_ccnt +1 ;
I also shouldn't be casting to a uint32_t if PMCR.LC is set. I've fixed these locally for the next round.
-Aaron
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 9 lines · Aaron Lindsay
The ARM PMU implementation currently contains a basic cycle counter, but it is often useful to gather counts of other events and filter them based on execution mode. 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.
Notable changes since v3:
Quoted 10 lines
* Detect counter overflow and send interrupts accordingly (adds a 'shadow' copy of both PMCCNTR and general-purpose counters, possibly/probably Doing It Wrong)
* Update counter filtering code to more closely resemble the ARM documentation in form and functionality
* Don't mix EL change hooks and KVM
* Don't call gen_io_start/end if not actually using icount
* Reorganized a few of the patches to more logically group changes
* Clarify and otherwise improve a few comments
* There are also a number of less significant changes scattered around
In the interests of cutting down the size of this patchset for future rounds, I'm going to apply these patches to target-arm.next:
Quoted 9 lines
1 target/arm: Check PMCNTEN for whether PMCCNTR is enabled 2 target/arm: Treat PMCCNTR as alias of PMCCNTR_EL0 4 target/arm: Mask PMU register writes based on PMCR_EL0.N 5 target/arm: Fetch GICv3 state directly from CPUARMState 6 target/arm: Support multiple EL change hooks 7 target/arm: Add pre-EL change hooks 8 target/arm: Allow EL change hooks to do IO 9 target/arm: Fix bitmask for PMCCFILTR writes12 target/arm: Make PMOVSCLR and PMUSERENR 64 bits wide
thanks
-- PMM