diff mbox series

[RFC,1/9] accel/tcg: Simplify use of &first_cpu in rr_cpu_thread_fn()

Message ID 20250128142152.9889-2-philmd@linaro.org
State New
Headers show
Series accel: Only include qdev-realized vCPUs in global &cpus_queue | expand

Commit Message

Philippe Mathieu-Daudé Jan. 28, 2025, 2:21 p.m. UTC
Let vCPUs wait for themselves being ready first, then other ones.
This allows the first thread to starts without the global vcpu
queue (thus &first_cpu) being populated.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/tcg/tcg-accel-ops-rr.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Richard Henderson Jan. 28, 2025, 7:44 p.m. UTC | #1
On 1/28/25 06:21, Philippe Mathieu-Daudé wrote:
> Let vCPUs wait for themselves being ready first, then other ones.
> This allows the first thread to starts without the global vcpu
> queue (thus &first_cpu) being populated.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   accel/tcg/tcg-accel-ops-rr.c | 15 ++++++++-------
>   1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
> index 028b385af9a..5ad3d617bce 100644
> --- a/accel/tcg/tcg-accel-ops-rr.c
> +++ b/accel/tcg/tcg-accel-ops-rr.c
> @@ -197,20 +197,21 @@ static void *rr_cpu_thread_fn(void *arg)
>       qemu_guest_random_seed_thread_part2(cpu->random_seed);
>   
>       /* wait for initial kick-off after machine start */
> -    while (first_cpu->stopped) {
> -        qemu_cond_wait_bql(first_cpu->halt_cond);
> +    while (cpu->stopped) {
> +        CPUState *iter_cpu;
> +
> +        qemu_cond_wait_bql(cpu->halt_cond);
>   
>           /* process any pending work */
> -        CPU_FOREACH(cpu) {
> -            current_cpu = cpu;
> -            qemu_wait_io_event_common(cpu);
> +        CPU_FOREACH(iter_cpu) {
> +            current_cpu = iter_cpu;
> +            qemu_wait_io_event_common(iter_cpu);
>           }
>       }
>   
> +    g_assert(first_cpu);
>       rr_start_kick_timer();
>   
> -    cpu = first_cpu;

This final line seems to be unrelated.

I'm not saying it's wrong, but it's certainly a change in behaviour.  We no longer execute 
from first_cpu first.


r~
diff mbox series

Patch

diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index 028b385af9a..5ad3d617bce 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -197,20 +197,21 @@  static void *rr_cpu_thread_fn(void *arg)
     qemu_guest_random_seed_thread_part2(cpu->random_seed);
 
     /* wait for initial kick-off after machine start */
-    while (first_cpu->stopped) {
-        qemu_cond_wait_bql(first_cpu->halt_cond);
+    while (cpu->stopped) {
+        CPUState *iter_cpu;
+
+        qemu_cond_wait_bql(cpu->halt_cond);
 
         /* process any pending work */
-        CPU_FOREACH(cpu) {
-            current_cpu = cpu;
-            qemu_wait_io_event_common(cpu);
+        CPU_FOREACH(iter_cpu) {
+            current_cpu = iter_cpu;
+            qemu_wait_io_event_common(iter_cpu);
         }
     }
 
+    g_assert(first_cpu);
     rr_start_kick_timer();
 
-    cpu = first_cpu;
-
     /* process any pending work */
     cpu->exit_request = 1;