From: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
To: Matt Turner <mattst88@gmail.com>, qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, pbonzini@redhat.com,
philmd@mailo.com, zhao1.liu@intel.com, laurent@vivier.eu,
deller@gmx.de
Subject: Re: [PATCH 4/8] RFC: tcg: probe the TB jump cache inline instead of calling a helper
Date: Tue, 18 Aug 2026 14:51:46 -0700 [thread overview]
Message-ID: <23eaea1b-e3bf-4845-8942-0e6ffcf056ca@oss.qualcomm.com> (raw)
In-Reply-To: <20260818174247.649526-5-mattst88@gmail.com>
On 8/18/2026 10:42 AM, Matt Turner wrote:
> Every indirect branch that cannot use goto_tb ends in
> tcg_gen_lookup_and_goto_ptr(), which calls helper_lookup_tb_ptr(). For an
> emulated compiler that is 8.4 billion helper calls in a single translation
> unit: 24.6% of all TB exits take this path, because jsr/ret/jmp have a
> register destination and because goto_tb is restricted to same-page
> targets.
>
> The helper itself is already tight, but each call pays for a call frame,
> the can_do_io store, the get_tb_cpu_state() indirect call through
> TCGCPUOps, curr_cflags(), and a breakpoint check, before it gets to the
> jump cache probe that almost always hits (95.8% for this workload).
>
> Emit the probe inline instead. The destination PC is already in a TCG
> temp, and the flags and cflags the destination must match are constants at
> translation time, so the fast path is a hash, three guarded loads and a
> goto_ptr. Only a miss calls the helper, which still owns filling the cache.
>
> Two details matter for the generated code. The flags and cflags guards are
> folded into a single aligned 64-bit load and compare, since the fields are
> adjacent. And each path emits its own goto_ptr rather than branching to a
> shared one: a temp live across the label is spilled and reloaded on every
> dispatch, which cost 6.3% on its own.
>
> Measured with qemu-alpha running an emulated alpha gcc 16.2.0 compiling
> the SQLite 3.45.1 amalgamation (255k lines, -O2) on an x86-64 host, LTO
> build, on top of the preceding three patches:
>
> before: 1,402,816,253,499 instructions
> after: 890,713,633,237 instructions -36.51%
>
> before: 115.75s wall clock
> after: 84.44s wall clock -27.05%
>
> The gap between the two is the point at which this stops being a
> straight-line win: the helper call was highly predictable work that the
> host pipelined well, so removing it retires far fewer instructions than it
> saves time. IPC falls from 2.48 to 2.15 across this patch for that reason.
>
> Despite emitting more code, this also reduces instruction cache pressure,
> because a dispatch no longer jumps into qemu's .text and evicts translated
> code:
>
> before: 11,476,318,964 L1-icache-load-misses
> after: 6,990,186,701 L1-icache-load-misses -39.1%
>
> The mechanism is visible directly in a profile: helper_lookup_tb_ptr()
> falls from 30.97% of samples to 0.42%, and qemu's own .text falls from
> 38.9% to 5.4%, with the balance moving into generated code.
>
> Combined with the three preceding patches, against an unmodified LTO
> build, 1,647,901,588,726 instructions fall to 890,713,633,237, or -45.95%.
> The emulated compiler produces byte-identical output throughout.
>
> Open issues, hence RFC:
>
> - The flags/cflags guards use the *current* TB's values as constants. That
> assumes the CPU flags feeding get_tb_cpu_state() cannot change within a
> TB, and that curr_cflags() cannot change under a running TB (gdb
> attaching to enable single-step would). Both need to be established or
> the values need to be loaded at runtime.
> - tcg/tcg-op.c has no business including accel/tcg/tb-jmp-cache.h or
> knowing the CPUJumpCache layout. The probe likely belongs in accel/tcg
> with a small emit helper exported from tcg/.
> - The jump cache entry is read without qatomic_read(); entries are
> invalidated concurrently by setting tb to NULL.
> - Only wired up for alpha so far, and only for 64-bit guest PCs.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
> include/tcg/tcg-op-common.h | 2 +
> target/alpha/translate.c | 4 +-
> tcg/tcg-op.c | 79 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 83 insertions(+), 2 deletions(-)
>
This change breaks following tcg test:
alpha-linux-user/gdbstub-follow-fork-mode-child
Reproduce with:
ninja -C build &&
make -C build/tests/tcg/alpha-linux-user/ &&
make -C build/tests/tcg/alpha-linux-user/ run-gdbstub-follow-fork-mode-child
Need gdb-multiarch and gcc-alpha-linux-gnu installed on your machine.
Regards,
Pierrick
next prev parent reply other threads:[~2026-08-18 21:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 17:42 [RFC PATCH 0/8] accel/tcg: cut per-block dispatch overhead Matt Turner
2026-08-18 17:42 ` [PATCH 1/8] accel/tcg: cache the result of curr_cflags() Matt Turner
2026-08-18 22:45 ` Richard Henderson
2026-08-18 17:42 ` [PATCH 2/8] accel/tcg: enlarge the TB jump cache to 64K entries Matt Turner
2026-08-18 22:46 ` Richard Henderson
2026-08-18 17:42 ` [PATCH 3/8] accel/tcg: skip the can_do_io stores in user-only builds Matt Turner
2026-08-18 22:47 ` Richard Henderson
2026-08-18 17:42 ` [PATCH 4/8] RFC: tcg: probe the TB jump cache inline instead of calling a helper Matt Turner
2026-08-18 21:51 ` Pierrick Bouvier [this message]
2026-08-18 22:26 ` Mohamed Mediouni
2026-08-18 17:42 ` [PATCH 5/8] RFC: accel/tcg: allow cross-page goto_tb chaining in user-only builds Matt Turner
2026-08-18 17:42 ` [PATCH 6/8] RFC: accel/tcg: only poll for interrupts in blocks that can close a cycle Matt Turner
2026-08-18 17:42 ` [PATCH 7/8] RFC: accel/tcg: poison the jump cache instead of polling for indirect exits Matt Turner
2026-08-18 17:42 ` [PATCH 8/8] RFC: tcg: fold a guest displacement into the host addressing mode Matt Turner
2026-08-18 22:52 ` [RFC PATCH 0/8] accel/tcg: cut per-block dispatch overhead 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=23eaea1b-e3bf-4845-8942-0e6ffcf056ca@oss.qualcomm.com \
--to=pierrick.bouvier@oss.qualcomm.com \
--cc=deller@gmx.de \
--cc=laurent@vivier.eu \
--cc=mattst88@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@mailo.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=zhao1.liu@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.