diff mbox series

[RFC,02/19] system/cpus: Only kick running vCPUs

Message ID 20250606164418.98655-3-philmd@linaro.org
State New
Headers show
Series accel: Preparatory cleanups for split-accel | expand

Commit Message

Philippe Mathieu-Daudé June 6, 2025, 4:44 p.m. UTC
As an optimization, avoid kicking stopped vCPUs.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 system/cpus.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Richard Henderson June 7, 2025, 1:23 p.m. UTC | #1
On 6/6/25 17:44, Philippe Mathieu-Daudé wrote:
> As an optimization, avoid kicking stopped vCPUs.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   system/cpus.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/system/cpus.c b/system/cpus.c
> index d16b0dff989..4835e5ced48 100644
> --- a/system/cpus.c
> +++ b/system/cpus.c
> @@ -494,6 +494,11 @@ void cpus_kick_thread(CPUState *cpu)
>   void qemu_cpu_kick(CPUState *cpu)
>   {
>       qemu_cond_broadcast(cpu->halt_cond);
> +
> +    if (!cpu_can_run(cpu)) {
> +        return;
> +    }
> +

This would appear to be a race condition.  The evaluation of cpu_can_run should be done 
within the context of 'cpu', not here, and not *after* we've already woken 'cpu' via the 
broadcast.


r~
diff mbox series

Patch

diff --git a/system/cpus.c b/system/cpus.c
index d16b0dff989..4835e5ced48 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -494,6 +494,11 @@  void cpus_kick_thread(CPUState *cpu)
 void qemu_cpu_kick(CPUState *cpu)
 {
     qemu_cond_broadcast(cpu->halt_cond);
+
+    if (!cpu_can_run(cpu)) {
+        return;
+    }
+
     if (cpus_accel->kick_vcpu_thread) {
         cpus_accel->kick_vcpu_thread(cpu);
     } else { /* default */