From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Subject: [PATCH v3 06/10] accel/tcg: Move post-load tb_flush to vm_change_state hook
Date: Tue, 23 Sep 2025 14:54:20 -0700 [thread overview]
Message-ID: <20250923215425.3685950-7-richard.henderson@linaro.org> (raw)
In-Reply-To: <20250923215425.3685950-1-richard.henderson@linaro.org>
We need not call tb_flush once per cpu, only once per vmload.
By moving the call from cpu_common_post_load to a tcg-specific
vm_change_state_handler, we do even better than that: we only
flush when called from HMP triggered loadvm, when we had old
state to flush.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/tcg-all.c | 21 +++++++++++++++++++++
hw/core/cpu-system.c | 9 ---------
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 5125e1a4e2..18ea0c58b0 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -38,6 +38,8 @@
#include "qemu/target-info.h"
#ifndef CONFIG_USER_ONLY
#include "hw/boards.h"
+#include "exec/tb-flush.h"
+#include "system/runstate.h"
#endif
#include "accel/accel-ops.h"
#include "accel/accel-cpu-ops.h"
@@ -82,6 +84,23 @@ static void tcg_accel_instance_init(Object *obj)
bool one_insn_per_tb;
+#ifndef CONFIG_USER_ONLY
+static void tcg_vm_change_state(void *opaque, bool running, RunState state)
+{
+ if (state == RUN_STATE_RESTORE_VM) {
+ /*
+ * loadvm will update the content of RAM, bypassing the usual
+ * mechanisms that ensure we flush TBs for writes to memory
+ * we've translated code from, so we must flush all TBs.
+ *
+ * vm_stop() has just stopped all cpus, so we are exclusive.
+ */
+ assert(!running);
+ tb_flush__exclusive_or_serial();
+ }
+}
+#endif
+
static int tcg_init_machine(AccelState *as, MachineState *ms)
{
TCGState *s = TCG_STATE(as);
@@ -124,6 +143,8 @@ static int tcg_init_machine(AccelState *as, MachineState *ms)
default:
g_assert_not_reached();
}
+
+ qemu_add_vm_change_state_handler(tcg_vm_change_state, NULL);
#endif
tcg_allowed = true;
diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c
index 09c928c1f9..f601a083d1 100644
--- a/hw/core/cpu-system.c
+++ b/hw/core/cpu-system.c
@@ -23,7 +23,6 @@
#include "system/address-spaces.h"
#include "exec/cputlb.h"
#include "system/memory.h"
-#include "exec/tb-flush.h"
#include "qemu/target-info.h"
#include "hw/qdev-core.h"
#include "hw/qdev-properties.h"
@@ -207,14 +206,6 @@ static int cpu_common_post_load(void *opaque, int version_id)
cpu_reset_interrupt(cpu, 0x01);
tlb_flush(cpu);
-
- /*
- * loadvm has just updated the content of RAM, bypassing the
- * usual mechanisms that ensure we flush TBs for writes to
- * memory we've translated code from. So we must flush all TBs,
- * which will now be stale.
- */
- tb_flush(cpu);
}
return 0;
--
2.43.0
next prev parent reply other threads:[~2025-09-23 21:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 21:54 [PATCH v3 00/10] accel/tcg: Improve tb_flush usage Richard Henderson
2025-09-23 21:54 ` [PATCH v3 01/10] gdbstub: Remove tb_flush uses Richard Henderson
2025-09-23 21:54 ` [PATCH v3 02/10] target/alpha: Simplify call_pal implementation Richard Henderson
2025-09-23 21:54 ` [PATCH v3 03/10] target/riscv: Record misa_ext in TCGTBCPUState.cs_base Richard Henderson
2025-09-23 21:54 ` [PATCH v3 04/10] hw/ppc/spapr: Use tb_invalidate_phys_range in h_page_init Richard Henderson
2025-09-24 3:20 ` Philippe Mathieu-Daudé
2025-09-23 21:54 ` [PATCH v3 05/10] accel/tcg: Split out tb_flush__exclusive_or_serial Richard Henderson
2025-09-25 2:15 ` Philippe Mathieu-Daudé
2025-09-23 21:54 ` Richard Henderson [this message]
2025-09-23 21:54 ` [PATCH v3 07/10] plugins: Use tb_flush__exclusive_or_serial Richard Henderson
2025-09-23 21:54 ` [PATCH v3 08/10] linux-user: Split out begin_parallel_context Richard Henderson
2025-09-24 3:23 ` Philippe Mathieu-Daudé
2025-09-23 21:54 ` [PATCH v3 09/10] accel/tcg: Create queue_tb_flush from tb_flush Richard Henderson
2025-09-24 3:26 ` Philippe Mathieu-Daudé
2025-09-23 21:54 ` [PATCH v3 10/10] accel/tcg: Improve buffer overflow in tb_gen_code Richard Henderson
2025-09-24 12:14 ` [PATCH v3 00/10] accel/tcg: Improve tb_flush usage Philippe Mathieu-Daudé
2025-09-24 16:39 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250923215425.3685950-7-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).