On 11/27/24 09:53, Richard Henderson wrote:
On 11/26/24 13:02, Pierrick Bouvier wrote:
@@ -266,6 +266,19 @@ static void qemu_plugin_vcpu_init__async(CPUState *cpu, 
run_on_cpu_data unused)
assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX);
       qemu_rec_mutex_lock(&plugin.lock);
+
+    /*
+     * We want to flush tb when a second cpu appear.
+     * When generating plugin code, we optimize cpu_index for num_vcpus == 1.
+     */
+    if (plugin.num_vcpus == 1) {
+        qemu_rec_mutex_unlock(&plugin.lock);
+        start_exclusive();
+        qemu_rec_mutex_lock(&plugin.lock);
+        tb_flush(cpu);
+        end_exclusive();
+    }

We already did this when creating the new thread.
Though we're using slightly different tests:

          /*
           * If this is our first additional thread, we need to ensure we
           * generate code for parallel execution and flush old translations.
           * Do this now so that the copy gets CF_PARALLEL too.
           */
          if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
              tcg_cflags_set(cpu, CF_PARALLEL);
              tb_flush(cpu);
          }


After removing the explicit flush, and relying on flush to honor CF_PARALLEL flags, I ran into random errors on values expected by 'inline' plugin, when running a program that spawns multiple threads.

It seems that, when spawning them at once, we may execute old code waiting for the flush to happen.


r~


Reply via email to