qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Wu, Fei" <fei2.wu@intel.com>
To: Richard Henderson <richard.henderson@linaro.org>,
	<qemu-devel@nongnu.org>,  <alex.bennee@linaro.org>
Cc: "Vanderson M. do Rosario" <vandersonmr2@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v12 02/15] accel: collecting TB execution count
Date: Tue, 23 May 2023 21:08:04 +0800	[thread overview]
Message-ID: <fcdb02eb-1c35-d0b0-bd38-347193a41370@intel.com> (raw)
In-Reply-To: <0bf482cc-fb96-0ada-f166-50d99b4952a5@linaro.org>

On 5/23/2023 8:45 AM, Richard Henderson wrote:
> On 5/18/23 06:57, Fei Wu wrote:
>> +void HELPER(inc_exec_freq)(void *ptr)
>> +{
>> +    TBStatistics *stats = (TBStatistics *) ptr;
>> +    tcg_debug_assert(stats);
>> +    ++stats->executions.normal;
>> +}
> ...
>> +static inline void gen_tb_exec_count(TranslationBlock *tb)
>> +{
>> +    if (tb_stats_enabled(tb, TB_EXEC_STATS)) {
>> +        TCGv_ptr ptr = tcg_temp_new_ptr();
>> +        tcg_gen_movi_ptr(ptr, (intptr_t)tb->tb_stats);
>> +        gen_helper_inc_exec_freq(ptr);
>> +    }
>> +}
> 
> This is 3 host instructions, easily expanded inline:
> 
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -11,6 +11,7 @@
>  #include "qemu/error-report.h"
>  #include "tcg/tcg.h"
>  #include "tcg/tcg-op.h"
> +#include "tcg/tcg-temp-internal.h"
>  #include "exec/exec-all.h"
>  #include "exec/gen-icount.h"
>  #include "exec/log.h"
> @@ -18,6 +19,30 @@
>  #include "exec/plugin-gen.h"
>  #include "exec/replay-core.h"
> 
> +
> +static void gen_tb_exec_count(TranslationBlock *tb)
> +{
> +    if (tb_stats_enabled(tb, TB_EXEC_STATS)) {
> +        TCGv_ptr ptr = tcg_temp_ebb_new_ptr();
> +
> +        tcg_gen_movi_ptr(ptr, (intptr_t)&tb->tb_stats->executions.normal);
> +        if (sizeof(tb->tb_stats->executions.normal) == 4) {
> +            TCGv_i32 t = tcg_temp_ebb_new_i32();
> +            tcg_gen_ld_i32(t, ptr, 0);
> +            tcg_gen_addi_i32(t, t, 1);
> +            tcg_gen_st_i32(t, ptr, 0);
> +            tcg_temp_free_i32(t);
> +        } else {
> +            TCGv_i64 t = tcg_temp_ebb_new_i64();
> +            tcg_gen_ld_i64(t, ptr, 0);
> +            tcg_gen_addi_i64(t, t, 1);
> +            tcg_gen_st_i64(t, ptr, 0);
> +            tcg_temp_free_i64(t);
> +        }
> +        tcg_temp_free_ptr(ptr);
> +    }
> +}
> +
>  bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest)
>  {
>      /* Suppress goto_tb if requested. */
> 
> 
> I'm not expecially keen on embedding the TBStatistics pointer directly
> like this; for most hosts we will have to put this constant into the
> constant pool.  Whereas the pointer already exists at tb->tb_stats, and
> tb is at a constant displacement prior to the code, so we already have
> mechanisms for generating pc-relative addresses.
> 
> However, that's premature optimization.  Let's get it working first.
> 
Here is the coremark results on a 4c qemu-system-riscv64, coremark takes
1cpu in this test.

(tb_stats stop)                         Iterations/Sec   : 5358.012664
(tb_stats start all)
    helper - qatomic_inc(normal)        Iterations/Sec   : 2416.626390
    helper - ++normal                   Iterations/Sec   : 4307.559767
    no helper - inline add              Iterations/Sec   : 5168.930031

Also if coremark runs on 4cpu, tb_stats will cost much more even in the
inline case, it's an extreme case though.

Thanks,
Fei.

> 
> r~
> 



  parent reply	other threads:[~2023-05-23 13:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18 13:57 [PATCH v12 00/15] TCG code quality tracking Fei Wu
2023-05-18 13:57 ` [PATCH v12 01/15] accel/tcg: introduce TBStatistics structure Fei Wu
2023-05-18 14:16   ` Wu, Fei
2023-05-18 13:57 ` [PATCH v12 02/15] accel: collecting TB execution count Fei Wu
2023-05-23  0:45   ` Richard Henderson
2023-05-23  1:48     ` Wu, Fei
2023-05-23 13:08     ` Wu, Fei [this message]
2023-05-24 13:35     ` Wu, Fei
2023-05-24 17:02       ` Richard Henderson
2023-05-25  0:45         ` Wu, Fei
2023-05-25 13:27         ` Wu, Fei
2023-05-18 13:57 ` [PATCH v12 03/15] accel: collecting JIT statistics Fei Wu
2023-05-18 13:57 ` [PATCH v12 04/15] accel: replacing part of CONFIG_PROFILER with TBStats Fei Wu
2023-05-18 13:57 ` [PATCH v12 05/15] accel/tcg: move profiler dev_time to tb_stats Fei Wu
2023-05-18 13:57 ` [PATCH v12 06/15] accel/tcg: convert profiling of restore operations to TBStats Fei Wu
2023-05-18 13:57 ` [PATCH v12 07/15] accel/tcg: convert profiling of code generation " Fei Wu
2023-05-18 13:57 ` [PATCH v12 08/15] accel: adding TB_JIT_TIME and full replacing CONFIG_PROFILER Fei Wu
2023-05-18 13:57 ` [PATCH v12 09/15] debug: add -d tb_stats to control TBStatistics collection: Fei Wu
2023-05-18 13:57 ` [PATCH v12 10/15] monitor: adding tb_stats hmp command Fei Wu
2023-05-18 14:11   ` Wu, Fei
2023-05-18 13:57 ` [PATCH v12 11/15] tb-stats: reset the tracked TBs on a tb_flush Fei Wu
2023-05-18 13:57 ` [PATCH v12 12/15] Adding info [tb-list|tb] commands to HMP (WIP) Fei Wu
2023-05-18 14:30   ` Wu, Fei
2023-05-18 13:57 ` [PATCH v12 13/15] tb-stats: dump hot TBs at the end of the execution Fei Wu
2023-05-18 13:57 ` [PATCH v12 14/15] configure: remove the final bits of --profiler support Fei Wu
2023-05-18 13:57 ` [PATCH v12 15/15] docs/tb-stats: add how to Fei Wu
2023-05-22 10:25   ` Thomas Huth
2023-05-22 12:51     ` Wu, Fei

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=fcdb02eb-1c35-d0b0-bd38-347193a41370@intel.com \
    --to=fei2.wu@intel.com \
    --cc=alex.bennee@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).