From: "Alex Bennée" <alex.bennee@linaro.org>
To: Matt Turner <mattst88@gmail.com>
Cc: qemu-devel@nongnu.org, richard.henderson@linaro.org,
pbonzini@redhat.com, philmd@mailo.com, zhao1.liu@intel.com,
laurent@vivier.eu, deller@gmx.de,
pierrick.bouvier@oss.qualcomm.com
Subject: Re: [RFC PATCH 1/8] accel/tcg: cache the result of curr_cflags()
Date: Tue, 18 Aug 2026 18:43:14 +0100 [thread overview]
Message-ID: <8733wbs4st.fsf@draig.linaro.org> (raw)
In-Reply-To: <20260817190038.580257-2-mattst88@gmail.com> (Matt Turner's message of "Mon, 17 Aug 2026 15:00:31 -0400")
Matt Turner <mattst88@gmail.com> writes:
> curr_cflags() is called once per TB dispatch, from helper_lookup_tb_ptr()
> and from the cpu_exec() loop. It recomputes the same value every time:
>
> uint32_t cflags = cpu->tcg_cflags;
> if (unlikely(cpu_single_stepping(cpu))) { ... }
> else if (qatomic_read(&one_insn_per_tb)) { ... }
> else if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { ... }
>
> That is three loads and three branches on the hottest path in the
> interpreter, for state that changes only when gdb enables single-step,
> when one-insn-per-tb is toggled, or when the log mask changes.
I agree this would be useful to remove but...
>
> static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb)
> diff --git ./include/hw/core/cpu.h ./include/hw/core/cpu.h
> index b54035fb13..172872d005 100644
> --- ./include/hw/core/cpu.h
> +++ ./include/hw/core/cpu.h
> @@ -411,10 +411,16 @@ struct qemu_work_item;
> * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
> * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
> * QOM parent.
> - * Under TCG this value is propagated to @tcg_cflags.
> + * Under TCG this value is propagated to @tcg_cflags_priv.
> * See TranslationBlock::TCG CF_CLUSTER_MASK.
> * @start_powered_off: Indicates whether the CPU starts in powered-off state.
> - * @tcg_cflags: Pre-computed cflags for this cpu.
> + * @tcg_cflags_priv: Pre-computed cflags for this cpu. Private to
> + * tcg_cflags_has() and tcg_cflags_set(): @tcg_curr_cflags is derived from
> + * it and is refreshed by the setter, so a direct assignment here would
> + * leave the two out of step. The name is deliberately awkward to make an
> + * open-coded access fail to compile rather than silently go stale.
> + * @tcg_curr_cflags: Cached result of curr_cflags(), recomputed by
> + * tcg_update_curr_cflags() whenever any of its inputs change.
This seems like introducing additional cache state to track. Why not
just provide a helper to call when ss/gdb/log conditions change and
change the current curr_cflags() code to only validate the helper has
been called when TCG debugging is turned on. See ppc_get_tb_cpu_state or
assert_hflags_rebuild_correctly for examples.
> * @nr_threads: Number of threads within this CPU core.
> * @thread: Host thread details, only live once @created is #true
> * @sem: WIN32 only semaphore used only for qtest
> @@ -557,7 +563,8 @@ struct CPUState {
> /* TODO Move common fields from CPUArchState here. */
> int cpu_index;
> int cluster_index;
> - uint32_t tcg_cflags;
> + uint32_t tcg_cflags_priv;
> + uint32_t tcg_curr_cflags;
> uint32_t halted;
> int32_t exception_index;
>
<snip>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2026-08-18 17:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 19:00 [RFC PATCH 0/8] accel/tcg: cut per-block dispatch overhead Matt Turner
2026-08-17 19:00 ` [RFC PATCH 1/8] accel/tcg: cache the result of curr_cflags() Matt Turner
2026-08-18 17:43 ` Alex Bennée [this message]
2026-08-17 19:00 ` [RFC PATCH 2/8] accel/tcg: enlarge the TB jump cache to 64K entries Matt Turner
2026-08-18 18:12 ` Alex Bennée
2026-08-17 19:00 ` [RFC PATCH 3/8] accel/tcg: skip the can_do_io stores in user-only builds Matt Turner
2026-08-18 6:00 ` Philippe Mathieu-Daudé
2026-08-17 19:00 ` [RFC PATCH 4/8] RFC: tcg: probe the TB jump cache inline instead of calling a helper Matt Turner
2026-08-18 6:05 ` Philippe Mathieu-Daudé
2026-08-17 19:00 ` [RFC PATCH 5/8] RFC: accel/tcg: allow cross-page goto_tb chaining in user-only builds Matt Turner
2026-08-18 6:07 ` Philippe Mathieu-Daudé
2026-08-17 19:00 ` [RFC PATCH 6/8] RFC: accel/tcg: only poll for interrupts in blocks that can close a cycle Matt Turner
2026-08-17 19:00 ` [RFC PATCH 7/8] RFC: accel/tcg: poison the jump cache instead of polling for indirect exits Matt Turner
2026-08-17 19:00 ` [RFC PATCH 8/8] RFC: tcg: fold a guest displacement into the host addressing mode Matt Turner
2026-08-18 16:38 ` [RFC PATCH 0/8] accel/tcg: cut per-block dispatch overhead Pierrick Bouvier
2026-08-18 17:13 ` Matt Turner
2026-08-18 17:43 ` Matt Turner
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=8733wbs4st.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=deller@gmx.de \
--cc=laurent@vivier.eu \
--cc=mattst88@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@mailo.com \
--cc=pierrick.bouvier@oss.qualcomm.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.