HALT_WFE will always be cleared when leaving halt via arm_cpu_leaving_halt so we don't need to worry about atomic games in the asynchronous timer callback. Furthermore, a WFET timeout or event-stream expiration is not an event that sets the event register; doing so causes a subsequent WFE to wake up immediately.
As we only need CPUState to call cpu_interrupt we can also simplify the user data and avoid needless casting to get to it. Suggested-by: Paolo Bonzini <[email protected]> Fixes: 01b223f895a7 ("target/arm: enable WFE sleeping for A-profile") Signed-off-by: Alex Bennée <[email protected]> --- target/arm/cpu.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 510fc9eeb3b..c690e2c8937 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -885,26 +885,12 @@ static void arm_cpu_leaving_halt(CPUState *cs) } #endif -/* - * Unlike almost everything else that messes with the halt_reason and - * event_register details the timer callbacks are not in the vCPU - * context. - * - * To prevent races we atomically consume a HALT_WFE and set the event - * register. Either way we trigger the an exit event. - */ static void arm_wfxt_timer_cb(void *opaque) { - ARMCPU *cpu = opaque; - CPUState *cs = CPU(cpu); - CPUARMState *env = &cpu->env; - - if (qatomic_cmpxchg(&env->halt_reason, HALT_WFE, NOT_HALTED)) { - qatomic_set(&env->event_register, true); - } + CPUState *cs = opaque; /* - * We expect the CPU to be halted; this will cause arm_cpu_is_work() + * We expect the CPU to be halted; this will cause arm_cpu_has_work() * to return true (so we will come out of halt even with no other * pending interrupt), and the TCG accelerator's cpu_exec_interrupt() * function auto-clears the CPU_INTERRUPT_EXITTB flag for us. @@ -2302,7 +2288,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) */ if (tcg_enabled() && arm_feature(env, ARM_FEATURE_V6K)) { cpu->wfxt_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, - arm_wfxt_timer_cb, cpu); + arm_wfxt_timer_cb, cs); } #endif -- 2.47.3
