Hi Richard,

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);
          }


r~

I noticed that it was redundant (for user-mode at least), but it seemed too implicit to rely on this. As well, I didn't observe such a flush in system-mode, does it work the same as user-mode (regarding the CF_PARALLEL flag)?

Reply via email to