Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tcg: round-robin: do not use mb_read for rr_current_cpu
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed May 16, 2023
1 parent 522da6d commit 2888b8c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions accel/tcg/tcg-accel-ops-rr.c
Expand Up @@ -72,11 +72,13 @@ static void rr_kick_next_cpu(void)
{
CPUState *cpu;
do {
cpu = qatomic_mb_read(&rr_current_cpu);
cpu = qatomic_read(&rr_current_cpu);
if (cpu) {
cpu_exit(cpu);
}
} while (cpu != qatomic_mb_read(&rr_current_cpu));
/* Finish kicking this cpu before reading again. */
smp_mb();
} while (cpu != qatomic_read(&rr_current_cpu));
}

static void rr_kick_thread(void *opaque)
Expand Down Expand Up @@ -241,8 +243,9 @@ static void *rr_cpu_thread_fn(void *arg)
}

while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {

/* Store rr_current_cpu before evaluating cpu_can_run(). */
qatomic_mb_set(&rr_current_cpu, cpu);

current_cpu = cpu;

qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
Expand Down Expand Up @@ -280,7 +283,7 @@ static void *rr_cpu_thread_fn(void *arg)
cpu = CPU_NEXT(cpu);
} /* while (cpu && !cpu->exit_request).. */

/* Does not need qatomic_mb_set because a spurious wakeup is okay. */
/* Does not need a memory barrier because a spurious wakeup is okay. */
qatomic_set(&rr_current_cpu, NULL);

if (cpu && cpu->exit_request) {
Expand Down

0 comments on commit 2888b8c

Please sign in to comment.