I presume this is v2 of
https://lore.kernel.org/qemu-devel/[email protected]/
On 18/8/26 19:42, Matt Turner wrote:
Every translation block stores to cpu->neg.can_do_io twice: false before
the first instruction, true before the last one. Nothing reads it in a
user-only build. There is no memory-mapped I/O in linux-user, and every
reader is in system_ss: cputlb.c, watchpoint.c, icount-common.c and
tcg-accel-ops-icount.c.
Two stores per TB is not much on its own, but TBs are short. An emulated
alpha gcc 16.2.0 compiling the SQLite 3.45.1 amalgamation (255k lines,
-O2) executes 34.2 billion TBs at 6.04 guest instructions each, so this is
68 billion stores for nothing.
Measured on an x86-64 host, LTO build, on top of the preceding two
patches:
before: 1,469,729,281,442 instructions
after: 1,402,816,253,499 instructions -4.55%
before: 120.97s wall clock
after: 115.75s wall clock -4.32%
The emulated compiler produces byte-identical output.
Signed-off-by: Matt Turner <[email protected]>
---
accel/tcg/translator.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git ./accel/tcg/translator.c ./accel/tcg/translator.c
index cd7d079fe0..85bb21e911 100644
--- ./accel/tcg/translator.c
+++ ./accel/tcg/translator.c
@@ -23,6 +23,9 @@
static void set_can_do_io(DisasContextBase *db, bool val)
{
+ if (IS_ENABLED(CONFIG_USER_ONLY)) {
Excellent use of IS_ENABLED()!
+ return;
+ }
QEMU_BUILD_BUG_ON(sizeof_field(CPUState, neg.can_do_io) != 1);
tcg_gen_st8_i32(tcg_constant_i32(val), tcg_env,
offsetof(CPUState, neg.can_do_io) - sizeof(CPUState));
@@ -210,6 +213,10 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb,
int *max_insns,
/*
* Manage can_do_io for the translation block: set to false before
* the first insn and set to true before the last insn.
+ *
+ * Nothing reads can_do_io in user-only builds. There is no MMIO
+ * there, and every reader (cputlb.c, watchpoint.c, icount) is in
+ * system_ss, so skip the two stores per TB entirely.
*/
if (db->num_insns == 1) {
tcg_debug_assert(first_insn_start == db->insn_start);
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>