Skip to contentSkip to conversation

cpus-common: stop using mb_set/mb_read

PATCH In review Paolo Bonzini 2 participants 2 messages Apr 28, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpus-common: stop using mb_set/mb_read

Use a store-release at the end of the work item, and a load-acquire when waiting for the item to be completed. This is the standard message passing pattern and is both enough and clearer than mb_read/mb_set.

---
 cpus-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cpus-common.c +2 -2
index b0047e456f93..a53716deb437 100644
@@ -157,7 +157,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
     wi.exclusive = false;
 
     queue_work_on_cpu(cpu, &wi);
-    while (!qatomic_mb_read(&wi.done)) {
+    while (!qatomic_load_acquire(&wi.done)) {
         CPUState *self_cpu = current_cpu;
 
         qemu_cond_wait(&qemu_work_cond, mutex);
@@ -363,7 +363,7 @@ void process_queued_cpu_work(CPUState *cpu)
         if (wi->free) {
             g_free(wi);
         } else {
-            qatomic_mb_set(&wi->done, true);
+            qatomic_store_release(&wi->done, true);
         }
     }
     qemu_mutex_unlock(&cpu->work_mutex);
Signature · 1 line
2.40.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Paolo Bonzini

Use a store-release at the end of the work item, and a load-acquire when waiting for the item to be completed. This is the standard message passing pattern and is both enough and clearer than mb_read/mb_set.

---

r~

Quoted 25 lines
  cpus-common.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
cpus-common.c +2 -2
index b0047e456f93..a53716deb437 100644
@@ -157,7 +157,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
      wi.exclusive = false;
 
      queue_work_on_cpu(cpu, &wi);
-    while (!qatomic_mb_read(&wi.done)) {
+    while (!qatomic_load_acquire(&wi.done)) {
          CPUState *self_cpu = current_cpu;
 
          qemu_cond_wait(&qemu_work_cond, mutex);
@@ -363,7 +363,7 @@ void process_queued_cpu_work(CPUState *cpu)
          if (wi->free) {
              g_free(wi);
          } else {
-            qatomic_mb_set(&wi->done, true);
+            qatomic_store_release(&wi->done, true);
          }
      }
      qemu_mutex_unlock(&cpu->work_mutex);