diff mbox series

[v2,2/3] softmmu: Introduce AddressSpaceDispatch generation numbers

Message ID 20230915163254.123338-3-richard.henderson@linaro.org
State New
Headers show
Series accel/tcg: Alternate fix for #1866 | expand

Commit Message

Richard Henderson Sept. 15, 2023, 4:32 p.m. UTC
Allow the cpu to easily check if an address space update
is required.  The acquire/release semantics will be used
by a subsequent patch.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 softmmu/physmem.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 88fafec1da..e1c535380a 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -163,6 +163,8 @@  struct CPUAddressSpace {
     AddressSpace *as;
     struct AddressSpaceDispatch *memory_dispatch;
     MemoryListener tcg_as_listener;
+    uint32_t commit_gen;
+    uint32_t layout_gen;
 };
 
 struct DirtyBitmapSnapshot {
@@ -2486,14 +2488,23 @@  static void tcg_log_global_after_sync(MemoryListener *listener)
     }
 }
 
-static void tcg_commit_cpu(CPUState *cpu, run_on_cpu_data data)
+static void tcg_commit_cpu_0(CPUState *cpu, CPUAddressSpace *cpuas)
 {
-    CPUAddressSpace *cpuas = data.host_ptr;
-
     cpuas->memory_dispatch = address_space_to_dispatch(cpuas->as);
     tlb_flush(cpu);
 }
 
+static void tcg_commit_cpu_1(CPUState *cpu, run_on_cpu_data data)
+{
+    CPUAddressSpace *cpuas = data.host_ptr;
+    uint32_t gen = qatomic_load_acquire(&cpuas->layout_gen);
+
+    if (cpuas->commit_gen != gen) {
+        cpuas->commit_gen = gen;
+        tcg_commit_cpu_0(cpu, cpuas);
+    }
+}
+
 static void tcg_commit(MemoryListener *listener)
 {
     CPUAddressSpace *cpuas;
@@ -2518,9 +2529,10 @@  static void tcg_commit(MemoryListener *listener)
      * all of the tcg machinery for run-on is initialized: thus created.
      */
     if (cpu->created) {
-        async_run_on_cpu(cpu, tcg_commit_cpu, RUN_ON_CPU_HOST_PTR(cpuas));
+        qatomic_store_release(&cpuas->layout_gen, cpuas->layout_gen + 1);
+        async_run_on_cpu(cpu, tcg_commit_cpu_1, RUN_ON_CPU_HOST_PTR(cpuas));
     } else {
-        tcg_commit_cpu(cpu, RUN_ON_CPU_HOST_PTR(cpuas));
+        tcg_commit_cpu_0(cpu, cpuas);
     }
 }