[PATCH v3 09/10] accel/tcg: Create queue_tb_flush from tb_flush

Richard Henderson posted 10 patches 4 days, 18 hours ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Laurent Vivier <laurent@vivier.eu>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
[PATCH v3 09/10] accel/tcg: Create queue_tb_flush from tb_flush
Posted by Richard Henderson 4 days, 18 hours ago
Rename the function and remove the path which
performs the flush immediately.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/exec/tb-flush.h   | 17 ++++++-----------
 accel/tcg/tb-maint.c      | 11 +++--------
 accel/tcg/translate-all.c |  2 +-
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/include/exec/tb-flush.h b/include/exec/tb-flush.h
index 090ffc8818..e971d4ba6d 100644
--- a/include/exec/tb-flush.h
+++ b/include/exec/tb-flush.h
@@ -24,19 +24,14 @@
 void tb_flush__exclusive_or_serial(void);
 
 /**
- * tb_flush() - flush all translation blocks
- * @cs: CPUState (must be valid, but treated as anonymous pointer)
+ * queue_tb_flush() - add flush to the cpu work queue
+ * @cs: CPUState
  *
- * Used to flush all the translation blocks in the system. Sometimes
- * it is simpler to flush everything than work out which individual
- * translations are now invalid and ensure they are not called
- * anymore.
- *
- * tb_flush() takes care of running the flush in an exclusive context
- * if it is not already running in one. This means no guest code will
- * run until this complete.
+ * Flush all translation blocks the next time @cs processes the work queue.
+ * This should generally be followed by cpu_loop_exit(), so that the work
+ * queue is processed promptly.
  */
-void tb_flush(CPUState *cs);
+void queue_tb_flush(CPUState *cs);
 
 void tcg_flush_jmp_cache(CPUState *cs);
 
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index 7be9a1c4de..5b1a5b599e 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -797,17 +797,12 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)
     }
 }
 
-void tb_flush(CPUState *cpu)
+void queue_tb_flush(CPUState *cs)
 {
     if (tcg_enabled()) {
         unsigned tb_flush_count = qatomic_read(&tb_ctx.tb_flush_count);
-
-        if (cpu_in_serial_context(cpu)) {
-            do_tb_flush(cpu, RUN_ON_CPU_HOST_INT(tb_flush_count));
-        } else {
-            async_safe_run_on_cpu(cpu, do_tb_flush,
-                                  RUN_ON_CPU_HOST_INT(tb_flush_count));
-        }
+        async_safe_run_on_cpu(cs, do_tb_flush,
+                              RUN_ON_CPU_HOST_INT(tb_flush_count));
     }
 }
 
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index d468667b0d..31bc0f8bc5 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -289,7 +289,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
     tb = tcg_tb_alloc(tcg_ctx);
     if (unlikely(!tb)) {
         /* flush must be done */
-        tb_flush(cpu);
+        queue_tb_flush(cpu);
         mmap_unlock();
         /* Make the execution loop process the flush as soon as possible.  */
         cpu->exception_index = EXCP_INTERRUPT;
-- 
2.43.0
Re: [PATCH v3 09/10] accel/tcg: Create queue_tb_flush from tb_flush
Posted by Philippe Mathieu-Daudé 4 days, 12 hours ago
On 23/9/25 23:54, Richard Henderson wrote:
> Rename the function and remove the path which
> performs the flush immediately.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   include/exec/tb-flush.h   | 17 ++++++-----------
>   accel/tcg/tb-maint.c      | 11 +++--------
>   accel/tcg/translate-all.c |  2 +-
>   3 files changed, 10 insertions(+), 20 deletions(-)
> 
> diff --git a/include/exec/tb-flush.h b/include/exec/tb-flush.h
> index 090ffc8818..e971d4ba6d 100644
> --- a/include/exec/tb-flush.h
> +++ b/include/exec/tb-flush.h
> @@ -24,19 +24,14 @@
>   void tb_flush__exclusive_or_serial(void);
>   
>   /**
> - * tb_flush() - flush all translation blocks
> - * @cs: CPUState (must be valid, but treated as anonymous pointer)
> + * queue_tb_flush() - add flush to the cpu work queue
> + * @cs: CPUState
>    *
> - * Used to flush all the translation blocks in the system. Sometimes
> - * it is simpler to flush everything than work out which individual
> - * translations are now invalid and ensure they are not called
> - * anymore.
> - *
> - * tb_flush() takes care of running the flush in an exclusive context
> - * if it is not already running in one. This means no guest code will
> - * run until this complete.
> + * Flush all translation blocks the next time @cs processes the work queue.
> + * This should generally be followed by cpu_loop_exit(), so that the work
> + * queue is processed promptly.
>    */
> -void tb_flush(CPUState *cs);
> +void queue_tb_flush(CPUState *cs);
>   
>   void tcg_flush_jmp_cache(CPUState *cs);

Preferably rename as tcg_queue_tb_flush(), regardless:

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>