From: "Alex Bennée" <alex.bennee@linaro.org>
To: vandersonmr <vandersonmr2@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v8 03/11] accel: collecting JIT statistics
Date: Fri, 30 Aug 2019 14:10:01 +0100 [thread overview]
Message-ID: <871rx294uu.fsf@linaro.org> (raw)
In-Reply-To: <20190829173437.5926-4-vandersonmr2@gmail.com>
vandersonmr <vandersonmr2@gmail.com> writes:
> If a TB has a TBS (TBStatistics) with the TB_JIT_STATS
> enabled then we collect statistics of its translation
> processes and code translation.
>
> Collecting the number of host instructions seems to be
> not simple as it would imply in having to modify several
> target source files. So, for now, we are only collecting
> the size of the host gen code.
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Vanderson M. do Rosario <vandersonmr2@gmail.com>
> ---
> accel/tcg/translate-all.c | 15 ++++++++++++++-
> accel/tcg/translator.c | 4 ++++
> include/exec/tb-stats.h | 15 +++++++++++++++
> tcg/tcg.c | 23 +++++++++++++++++++++++
> tcg/tcg.h | 2 ++
> 5 files changed, 58 insertions(+), 1 deletion(-)
>
> diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
> index e72aeba682..fb2fe0fa1f 100644
> --- a/accel/tcg/translate-all.c
> +++ b/accel/tcg/translate-all.c
> @@ -1705,6 +1705,7 @@ static TBStatistics *tb_get_stats(tb_page_addr_t phys_pc, target_ulong pc,
> * then just make the new TB point to the older TBStatistic
> */
> g_free(new_stats);
> + ((TBStatistics *) existing_stats)->tb = current_tb;
This seems out of place and again I can't see what we are doing with
this information yet.
> return existing_stats;
> } else {
> return new_stats;
> @@ -1785,13 +1786,18 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
> */
> if (tb_stats_collection_enabled()) {
> tb->tb_stats = tb_get_stats(phys_pc, pc, cs_base, flags, tb);
> + uint32_t flag = get_default_tbstats_flag();
>
> if (qemu_log_in_addr_range(tb->pc)) {
> - uint32_t flag = get_default_tbstats_flag();
> if (flag & TB_EXEC_STATS) {
> tb->tb_stats->stats_enabled |= TB_EXEC_STATS;
> }
> }
> +
> + if (flag & TB_JIT_STATS) {
> + tb->tb_stats->stats_enabled |= TB_JIT_STATS;
> + atomic_inc(&tb->tb_stats->translations.total);
> + }
> } else {
> tb->tb_stats = NULL;
> }
> @@ -1869,6 +1875,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
> atomic_set(&prof->search_out_len, prof->search_out_len + search_size);
> #endif
>
> + if (tb_stats_enabled(tb, TB_JIT_STATS)) {
> + atomic_add(&tb->tb_stats->code.out_len, gen_code_size);
> + }
> +
> #ifdef DEBUG_DISAS
> if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) &&
> qemu_log_in_addr_range(tb->pc)) {
> @@ -1926,6 +1936,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
> phys_page2 = -1;
> if ((pc & TARGET_PAGE_MASK) != virt_page2) {
> phys_page2 = get_page_addr_code(env, virt_page2);
> + if (tb_stats_enabled(tb, TB_JIT_STATS)) {
> + atomic_inc(&tb->tb_stats->translations.spanning);
> + }
> }
> /*
> * No explicit memory barrier is required -- tb_link_page() makes the
> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
> index ec6bd829a0..9b2e248b09 100644
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -116,6 +116,10 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
> db->tb->size = db->pc_next - db->pc_first;
> db->tb->icount = db->num_insns;
>
> + if (tb_stats_enabled(tb, TB_JIT_STATS)) {
> + atomic_add(&db->tb->tb_stats->code.num_guest_inst, db->num_insns);
> + }
> +
> #ifdef DEBUG_DISAS
> if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
> && qemu_log_in_addr_range(db->pc_first)) {
> diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h
> index c4a8715400..b68edd5d24 100644
> --- a/include/exec/tb-stats.h
> +++ b/include/exec/tb-stats.h
> @@ -58,6 +58,20 @@ struct TBStatistics {
> unsigned long atomic;
> } executions;
>
> + struct {
> + unsigned num_guest_inst;
> + unsigned num_tcg_ops;
> + unsigned num_tcg_ops_opt;
> + unsigned spills;
> + unsigned out_len;
> + } code;
> +
> + struct {
> + unsigned long total;
> + unsigned long uncached;
> + unsigned long spanning;
> + } translations;
> +
> /* current TB linked to this TBStatistics */
> TranslationBlock *tb;
> };
> @@ -71,6 +85,7 @@ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED };
>
> #define TB_NOTHING (1 << 0)
> #define TB_EXEC_STATS (1 << 1)
> +#define TB_JIT_STATS (1 << 2)
>
> extern int tcg_collect_tb_stats;
> extern uint32_t default_tbstats_flag;
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 0458eaec57..ae3e7a2217 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -3125,6 +3125,11 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs,
> case TEMP_VAL_REG:
> tcg_out_st(s, ts->type, ts->reg,
> ts->mem_base->reg, ts->mem_offset);
> +
> + /* Count number of spills */
> + if (tb_stats_enabled(s->current_tb, TB_JIT_STATS)) {
> + atomic_inc(&s->current_tb->tb_stats->code.spills);
> + }
> break;
>
> case TEMP_VAL_MEM:
> @@ -3996,6 +4001,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
> int i, num_insns;
> TCGOp *op;
>
> + s->current_tb = tb;
> +
> #ifdef CONFIG_PROFILER
> {
> int n = 0;
> @@ -4027,6 +4034,14 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
> }
> #endif
>
> + if (tb_stats_enabled(tb, TB_JIT_STATS)) {
> + int n = 0;
> + QTAILQ_FOREACH(op, &s->ops, link) {
> + n++;
> + }
> + atomic_add(&tb->tb_stats->code.num_tcg_ops, n);
> + }
> +
> #ifdef CONFIG_DEBUG_TCG
> /* Ensure all labels referenced have been emitted. */
> {
> @@ -4093,6 +4108,14 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
> }
> #endif
>
> + if (tb_stats_enabled(tb, TB_JIT_STATS)) {
> + int n = 0;
> + QTAILQ_FOREACH(op, &s->ops, link) {
> + n++;
> + }
> + atomic_add(&tb->tb_stats->code.num_tcg_ops_opt, n);
> + }
> +
> tcg_reg_alloc_start(s);
>
> s->code_buf = tb->tc.ptr;
> diff --git a/tcg/tcg.h b/tcg/tcg.h
> index 529acb2ed8..b4601162f8 100644
> --- a/tcg/tcg.h
> +++ b/tcg/tcg.h
> @@ -740,6 +740,8 @@ struct TCGContext {
>
> uint16_t gen_insn_end_off[TCG_MAX_INSNS];
> target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS];
> +
> + TranslationBlock *current_tb;
As we are only using this to get to tb_stats why not skip the middle man
and go directly to:
TBStatistics *current_stats;
?
You already have a tbs_stats_enabled() helper
> };
>
> extern TCGContext tcg_init_ctx;
--
Alex Bennée
next prev parent reply other threads:[~2019-08-30 13:36 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 17:34 [Qemu-devel] [PATCH v8 00/11] Measure Tiny Code Generation Quality vandersonmr
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 01/11] accel: introducing TBStatistics structure vandersonmr
2019-08-30 12:59 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 02/11] accel: collecting TB execution count vandersonmr
2019-08-30 10:21 ` Alex Bennée
2019-08-30 12:31 ` Vanderson Martins do Rosario
2019-08-30 13:01 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 03/11] accel: collecting JIT statistics vandersonmr
2019-08-30 13:10 ` Alex Bennée [this message]
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 04/11] accel: replacing part of CONFIG_PROFILER with TBStats vandersonmr
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 05/11] accel: adding TB_JIT_TIME and full replacing CONFIG_PROFILER vandersonmr
2019-08-30 13:12 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 06/11] Adding -d tb_stats to control TBStatistics collection: vandersonmr
2019-08-30 14:45 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 07/11] monitor: adding tb_stats hmp command vandersonmr
2019-08-30 15:11 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 08/11] Adding tb_stats [start|pause|stop|filter] command to hmp vandersonmr
2019-08-29 17:54 ` Vanderson Martins do Rosario
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 09/11] Adding info [tb-list|tb|coverset] commands to HMP vandersonmr
2019-08-30 16:17 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 10/11] monitor: adding new info cfg command vandersonmr
2019-08-30 16:26 ` Alex Bennée
2019-08-29 17:34 ` [Qemu-devel] [PATCH v8 11/11] linux-user: dumping hot TBs at the end of the execution vandersonmr
2019-11-21 15:38 ` [Qemu-devel] [PATCH v8 00/11] Measure Tiny Code Generation Quality Markus Armbruster
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=871rx294uu.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--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).