Expose a routine to be called when no cpus are running. Simplify the do_tb_flush run_on_cpu callback, because that is explicitly called with start_exclusive; there is no need for the mmap_lock as well.
Signed-off-by: Richard Henderson <[email protected]> --- include/exec/tb-flush.h | 1 + accel/tcg/tb-maint.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/exec/tb-flush.h b/include/exec/tb-flush.h index 142c240d94..f3898d1826 100644 --- a/include/exec/tb-flush.h +++ b/include/exec/tb-flush.h @@ -23,6 +23,7 @@ */ void tb_flush(CPUState *cs); +void tb_flush__exclusive(void); void tcg_flush_jmp_cache(CPUState *cs); #endif /* _TB_FLUSH_H_ */ diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 0048316f99..d1695be00b 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -756,17 +756,14 @@ static void tb_remove(TranslationBlock *tb) } #endif /* CONFIG_USER_ONLY */ -/* flush all the translation blocks */ -static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) +/* + * Flush all the translation blocks. + * Must be called from a context in which no cpus are running, + * e.g. start_exclusive() or vm_stop(). + */ +void tb_flush__exclusive(void) { - bool did_flush = false; - - mmap_lock(); - /* If it is already been done on request of another CPU, just retry. */ - if (tb_ctx.tb_flush_count != tb_flush_count.host_int) { - goto done; - } - did_flush = true; + CPUState *cpu; CPU_FOREACH(cpu) { tcg_flush_jmp_cache(cpu); @@ -778,11 +775,14 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) tcg_region_reset_all(); /* XXX: flush processor icache at this point if cache flush is expensive */ qatomic_inc(&tb_ctx.tb_flush_count); + qemu_plugin_flush_cb(); +} -done: - mmap_unlock(); - if (did_flush) { - qemu_plugin_flush_cb(); +static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) +{ + /* If it is already been done on request of another CPU, just retry. */ + if (tb_ctx.tb_flush_count == tb_flush_count.host_int) { + tb_flush__exclusive(); } } -- 2.43.0
