From: Richard Henderson <richard.henderson@linaro.org>
To: Fei Wu <fei2.wu@intel.com>,
alex.bennee@linaro.org, qemu-devel@nongnu.org
Cc: "Vanderson M. do Rosario" <vandersonmr2@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v11 02/14] accel: collecting TB execution count
Date: Wed, 3 May 2023 09:28:44 +0100 [thread overview]
Message-ID: <a8b66b75-c698-6247-0cfe-c9438df570b8@linaro.org> (raw)
In-Reply-To: <20230421132421.1617479-3-fei2.wu@intel.com>
On 4/21/23 14:24, Fei Wu wrote:
> From: "Vanderson M. do Rosario" <vandersonmr2@gmail.com>
>
> If a TB has a TBS (TBStatistics) with the TB_EXEC_STATS
> enabled, then we instrument the start code of this TB
> to atomically count the number of times it is executed.
> We count both the number of "normal" executions and atomic
> executions of a TB.
>
> The execution count of the TB is stored in its respective
> TBS.
>
> All TBStatistics are created by default with the flags from
> default_tbstats_flag.
>
> Signed-off-by: Vanderson M. do Rosario <vandersonmr2@gmail.com>
> Message-Id: <20190829173437.5926-3-vandersonmr2@gmail.com>
> [AJB: Fix author]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> accel/tcg/cpu-exec.c | 6 ++++++
> accel/tcg/tb-stats.c | 6 ++++++
> accel/tcg/tcg-runtime.c | 8 ++++++++
> accel/tcg/tcg-runtime.h | 2 ++
> accel/tcg/translate-all.c | 7 +++++--
> accel/tcg/translator.c | 10 ++++++++++
> include/exec/gen-icount.h | 1 +
> include/exec/tb-stats.h | 18 ++++++++++++++++++
> 8 files changed, 56 insertions(+), 2 deletions(-)
>
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index c815f2dbfd..d89f9fe493 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -25,6 +25,7 @@
> #include "trace.h"
> #include "disas/disas.h"
> #include "exec/exec-all.h"
> +#include "exec/tb-stats.h"
> #include "tcg/tcg.h"
> #include "qemu/atomic.h"
> #include "qemu/rcu.h"
> @@ -564,7 +565,12 @@ void cpu_exec_step_atomic(CPUState *cpu)
> mmap_unlock();
> }
>
> + if (tb_stats_enabled(tb, TB_EXEC_STATS)) {
> + tb->tb_stats->executions.atomic++;
> + }
The write is protected by the exclusive lock, but the read might be accessible from the
monitor, iiuc. Which means you should use atomic_set(), for non-tearable write after
non-atomic increment.
> @@ -148,3 +149,10 @@ void HELPER(exit_atomic)(CPUArchState *env)
> {
> cpu_loop_exit_atomic(env_cpu(env), GETPC());
> }
> +
> +void HELPER(inc_exec_freq)(void *ptr)
> +{
> + TBStatistics *stats = (TBStatistics *) ptr;
> + tcg_debug_assert(stats);
> + qatomic_inc(&stats->executions.normal);
> +}
Ug. Do we really need an atomic update?
If we have multiple threads executing through the same TB, we'll get significant slow-down
at the cost of not missing increments. If we allow a non-atomic update, we'll get much
less slow-down at the cost of missing a few increments. But this is statistical only, so
how much does it really matter?
r~
next prev parent reply other threads:[~2023-05-03 8:29 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-21 13:24 [PATCH v11 00/14] TCG code quality tracking Fei Wu
2023-04-21 13:24 ` [PATCH v11 01/14] accel/tcg: introduce TBStatistics structure Fei Wu
2023-05-03 8:12 ` Richard Henderson
2023-05-08 9:52 ` Wu, Fei
2023-04-21 13:24 ` [PATCH v11 02/14] accel: collecting TB execution count Fei Wu
2023-05-03 8:28 ` Richard Henderson [this message]
2023-05-08 10:02 ` Wu, Fei
2023-04-21 13:24 ` [PATCH v11 03/14] accel: collecting JIT statistics Fei Wu
2023-04-21 13:24 ` [PATCH v11 04/14] accel: replacing part of CONFIG_PROFILER with TBStats Fei Wu
2023-04-21 13:24 ` [PATCH v11 05/14] accel/tcg: move profiler dev_time to tb_stats Fei Wu
2023-04-21 13:24 ` [PATCH v11 06/14] accel/tcg: convert profiling of restore operations to TBStats Fei Wu
2023-04-21 13:24 ` [PATCH v11 07/14] accel/tcg: convert profiling of code generation " Fei Wu
2023-04-21 13:24 ` [PATCH v11 08/14] accel: adding TB_JIT_TIME and full replacing CONFIG_PROFILER Fei Wu
2023-04-21 13:24 ` [PATCH v11 09/14] debug: add -d tb_stats to control TBStatistics collection: Fei Wu
2023-04-21 13:24 ` [PATCH v11 10/14] monitor: adding tb_stats hmp command Fei Wu
2023-04-21 13:24 ` [PATCH v11 11/14] tb-stats: reset the tracked TBs on a tb_flush Fei Wu
2023-04-21 13:24 ` [PATCH v11 12/14] Adding info [tb-list|tb] commands to HMP (WIP) Fei Wu
2023-04-21 14:43 ` Wu, Fei
2023-04-21 13:24 ` [PATCH v11 13/14] tb-stats: dump hot TBs at the end of the execution Fei Wu
2023-04-21 13:24 ` [PATCH v11 14/14] configure: remove the final bits of --profiler support Fei Wu
2023-04-21 16:42 ` [PATCH v11 00/14] TCG code quality tracking Alex Bennée
2023-05-12 8:07 ` Wu, Fei
2023-05-12 8:42 ` Alex Bennée
2023-05-12 8:58 ` Wu, Fei
2023-05-12 9:29 ` Alex Bennée
2023-05-19 1:16 ` Wu, Fei
2023-05-19 22:01 ` 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=a8b66b75-c698-6247-0cfe-c9438df570b8@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=fei2.wu@intel.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vandersonmr2@gmail.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 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).