From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
qemu-arm@nongnu.org
Subject: Re: [PATCH 3/4] target/arm: simplify wfxt_timer_cb to only trigger cpu_interrupt
Date: Fri, 30 Oct 2026 16:43:12 +0000 [thread overview]
Message-ID: <877biz87hb.fsf@draig.linaro.org> (raw)
In-Reply-To: <CAFEAcA_vh2WhO8wAX8=6cmZx0Fe2UQYJBoRjaJb1YVAG-Lm8Jw@mail.gmail.com> (Peter Maydell's message of "Fri, 30 Oct 2026 14:41:47 +0000")
Peter Maydell <peter.maydell@linaro.org> writes:
> On Fri, 30 Oct 2026 at 14:10, Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>> 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;
>
> No, this is still not true. WFET timeouts don't set the
> event register, but event-stream expiration does.
Oops I missed that comment, how about something like this:
--8<---------------cut here---------------start------------->8---
modified target/arm/cpu.h
@@ -984,8 +984,12 @@ struct ArchCPU {
* pmu_op_finish() - it does not need other handling during migration
*/
QEMUTimer *pmu_timer;
- /* Timer used for WFxT timeouts OR event stream events */
+ /*
+ * Timer used for WFxT timeouts OR event stream events,
+ * wfxt_triggers_event set depending on what will come first.
+ */
QEMUTimer *wfxt_timer;
+ bool wfxt_triggers_event;
/* GPIO outputs for generic timer */
qemu_irq gt_timer_outputs[NUM_GTIMERS];
modified target/arm/cpu.c
@@ -885,26 +885,17 @@ 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)) {
+ if (cpu->wfxt_triggers_event) {
qatomic_set(&env->event_register, true);
}
-
/*
- * 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.
modified target/arm/tcg/op_helper.c
@@ -377,6 +377,7 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len)
return;
#else
CPUState *cs = env_cpu(env);
+ ARMCPU *cpu = env_archcpu(env);
uint32_t excp;
int target_el = check_wfx_trap(env, false, &excp);
@@ -398,6 +399,7 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len)
target_el);
}
+ cpu->wfxt_triggers_event = false;
qatomic_set(&env->halt_reason, HALT_WFI);
cs->exception_index = EXCP_HLT;
cs->halted = 1;
@@ -461,6 +463,7 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)
} else {
timer_mod(cpu->wfxt_timer, nexttick);
}
+ cpu->wfxt_triggers_event = false;
qatomic_set(&env->halt_reason, HALT_WFI);
cs->exception_index = EXCP_HLT;
cs->halted = 1;
@@ -720,12 +723,14 @@ void HELPER(wfet)(CPUARMState *env, uint32_t rd)
next_event = gt_calc_next_event_stream(env);
if (next_event > 0 && next_event < nexttick) {
timer_mod(cpu->wfxt_timer, next_event);
+ cpu->wfxt_triggers_event = true;
} else {
if (nexttick == INT64_MAX) {
timer_mod_ns(cpu->wfxt_timer, INT64_MAX);
} else {
timer_mod(cpu->wfxt_timer, nexttick);
}
+ cpu->wfxt_triggers_event = false;
}
qatomic_set(&env->halt_reason, HALT_WFE);
--8<---------------cut here---------------end--------------->8---
>
> -- PMM
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2026-10-30 16:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 14:10 [PATCH 0/4] arm fixes (WxFT, bcm2835_fb) Alex Bennée
2026-10-30 14:10 ` [PATCH 1/4] target/arm: hold bql when SEV sets the event_register Alex Bennée
2026-11-01 17:29 ` Lorand Marton
2026-11-01 17:55 ` Alex Bennée
2026-10-30 14:10 ` [PATCH 2/4] target/arm: don't pass env to the sev helper Alex Bennée
2026-10-30 14:10 ` [PATCH 3/4] target/arm: simplify wfxt_timer_cb to only trigger cpu_interrupt Alex Bennée
2026-10-30 14:41 ` Peter Maydell
2026-10-30 16:43 ` Alex Bennée [this message]
2026-10-30 14:10 ` [PATCH 4/4] target/arm: fix bcm2835 migration issue Alex Bennée
2026-11-02 11:41 ` [PATCH 0/4] arm fixes (WxFT, bcm2835_fb) Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877biz87hb.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.