From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: Peter Maydell <peter.maydell@linaro.org>,
Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Subject: Re: [PATCH 06/11] target/arm: Extract halt-to-exec transition out of arm_cpu_exec_halt()
Date: Wed, 2 Sep 2026 20:02:17 +0200 [thread overview]
Message-ID: <7766d96b-4065-4917-9d7d-094bd6d1f29c@oss.qualcomm.com> (raw)
In-Reply-To: <bbe4b7d0-96ad-45d8-a5a9-0be2c5479d51@oss.qualcomm.com>
On 20/8/26 09:29, Philippe Mathieu-Daudé wrote:
> On 2026-08-19 23:40, Peter Maydell wrote:
>> On Wed, 19 Aug 2026 at 21:14, Richard Henderson
>> <richard.henderson@linaro.org> wrote:
>>>
>>> On 8/19/26 07:56, Philippe Mathieu-Daudé wrote:
>>>> Refactor the target-specific halt-to-execution transition
>>>> logic (disable WFE/WFI timers, clear the halt_reason flag)
>>>> into a separate arm_cpu_transition_halt_to_exec() function.
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>>>> ---
>>>> target/arm/cpu.c | 22 +++++++++++++++-------
>>>> 1 file changed, 15 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
>>>> index 77aa78f00e2..8e9b584559d 100644
>>>> --- a/target/arm/cpu.c
>>>> +++ b/target/arm/cpu.c
>>>> @@ -870,18 +870,26 @@ static bool
>>>> arm_cpu_internal_is_big_endian(CPUState *cs)
>>>> }
>>>>
>>>> #ifdef CONFIG_TCG
>>>> +static void arm_cpu_transition_halt_to_exec(CPUState *cs)
>>>> +{
>>>> + ARMCPU *cpu = ARM_CPU(cs);
>>>> +
>>>> + assert(cpu_has_work(cs));
>>>
>>> In reply to patch 11 you suggest removing this.
>>> I wonder why you added it in the first place.
>>
>> Does the accel loop enforce that we hold the BQL when
>> arm_cpu_exec_halt() is called?
>
> For MTTCG:
>
> mttcg_cpu_thread_fn()
> {
> bql_lock();
> while (1)
> qemu_process_cpu_events(cpu);
> if (cpu_can_run(cpu)) {
> bql_unlock();
> tcg_cpu_exec(cpu);
> cpu_exec(cpu);
> if (cpu->halted) {
> cpu_has_work_after_processing_async_events(cpu);
> process_async_events(cpu);
> x86_cpu_process_async_events(); // APIC takes BQL
> cpu_has_work(cpu);
> transition_halt_to_exec(cpu);
> arm_cpu_transition_halt_to_exec(); // timer_lock
> x86_cpu_transition_halt_to_exec();
> ...
> bql_lock();
> ...
> }
>
> void x86_cpu_process_async_events()
> {
> /* (BQL not held) */
> if (cpu_test_interrupt()) {
> bql_lock();
> apic_poll_irq();
> apic_sync_vapic();
> apic_update_irq();
> cpu_interrupt();
> cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL);
> bql_unlock();
> }
> }
>> If not then the assertion
>> is racy, because something might get in and e.g. lower
>> an IRQ line so that cpu_has_work() is no longer true
>> (which would be fine -- it just means we made the decision
>> to wake up and that won vs the incoming interrupt).
>>
>> On the one hand, if we don't have the BQL in has_work and
>> exec_halt then we should be a lot more careful about how
>> we code them (e.g. use of the right kind of atomics, and
>> there's no way the call to do_interrupt_all() in the x86
>> exec_halt can be safe without the BQL, surely).
>>
>> On the other hand, if we do have the BQL in exec_halt
>> then why is the x86 implementation explicitly taking
>> the BQL when it calls apic_poll_irq()?
Trying harder, my understanding is apic_poll_irq() only requires
the BQL for the apic_update_irq() call, not apic_sync_vapic().
So maybe only apic_sync_vapic() belongs to process_async_events(),
leaving apic_update_irq() to transition_halt_to_exec().
Paolo does that sound like going in the good direction?
next prev parent reply other threads:[~2026-09-02 18:03 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 14:56 [PATCH 00/11] accel/tcg: Make halt-to-exec transition explicit and remove cpu_exec_halt Philippe Mathieu-Daudé
2026-08-19 14:56 ` [PATCH 01/11] accel/tcg: Rename for exception codes named @ret as @excp Philippe Mathieu-Daudé
2026-08-19 19:55 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 02/11] accel/tcg: Restrict EXCP_HALTED handling to system emulation Philippe Mathieu-Daudé
2026-08-19 20:01 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 03/11] accel/tcg: Check %halted field in cpu_handle_halt() caller Philippe Mathieu-Daudé
2026-08-19 20:02 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 04/11] accel/tcg: Refactor halt-to-execution flow in cpu_exec() Philippe Mathieu-Daudé
2026-08-19 20:03 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 05/11] accel/tcg: Introduce .process_async_events and .transition_halt_to_exec Philippe Mathieu-Daudé
2026-08-19 20:06 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 06/11] target/arm: Extract halt-to-exec transition out of arm_cpu_exec_halt() Philippe Mathieu-Daudé
2026-08-19 20:13 ` Richard Henderson
2026-08-19 21:40 ` Peter Maydell
2026-08-20 7:29 ` Philippe Mathieu-Daudé
2026-09-01 9:53 ` Philippe Mathieu-Daudé
2026-09-02 18:02 ` Philippe Mathieu-Daudé [this message]
2026-08-19 14:56 ` [PATCH 07/11] target/arm: Convert cpu_exec_halt() to transition_halt_to_exec() Philippe Mathieu-Daudé
2026-08-19 20:15 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 08/11] target/i386: Extract async event processing out of x86_cpu_exec_halt() Philippe Mathieu-Daudé
2026-08-19 20:16 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 09/11] target/i386: Extract halt-to-exec transition " Philippe Mathieu-Daudé
2026-08-19 20:17 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 10/11] target/i386: Convert cpu_exec_halt() to transition_halt_to_exec() Philippe Mathieu-Daudé
2026-08-19 20:18 ` Richard Henderson
2026-08-19 20:19 ` Richard Henderson
2026-08-19 14:56 ` [PATCH 11/11] accel/tcg: Remove the now redundant cpu_exec_halt() hook Philippe Mathieu-Daudé
2026-08-19 15:05 ` Philippe Mathieu-Daudé
2026-08-19 20:20 ` Richard Henderson
2026-08-20 9:26 ` [PATCH 00/11] accel/tcg: Make halt-to-exec transition explicit and remove cpu_exec_halt Mark Cave-Ayland
2026-08-20 9:56 ` Philippe Mathieu-Daudé
2026-08-24 21:31 ` Philippe Mathieu-Daudé
2026-08-25 10:54 ` Mark Cave-Ayland
2026-09-03 9:56 ` Philippe Mathieu-Daudé
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=7766d96b-4065-4917-9d7d-094bd6d1f29c@oss.qualcomm.com \
--to=philmd@oss.qualcomm.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=pierrick.bouvier@oss.qualcomm.com \
--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.