qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	vandersonmr <vandersonmr2@gmail.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v6 06/10] log: adding -d tb_stats to control tbstats
Date: Tue, 27 Aug 2019 14:31:21 +0100	[thread overview]
Message-ID: <87o90a68gm.fsf@linaro.org> (raw)
In-Reply-To: <20190821172329.2062-7-vandersonmr2@gmail.com>


vandersonmr <vandersonmr2@gmail.com> writes:

> Adding -d tb_stats to control TBStatistics collection:
>
>  -d tb_stats[[,level=(+all+jit+exec+time)][,dump_limit=<number>]]
>
> "dump_limit" is used to limit the number of dumped TBStats in
> linux-user mode.
>
> [all+jit+exec+time] control the profilling level used
> by the TBStats. Can be used as follow:
>
> -d tb_stats
> -d tb_stats,level=jit+time
> -d tb_stats,dump_limit=15
> ...
>
> Signed-off-by: Vanderson M. do Rosario <vandersonmr2@gmail.com>
> ---
>  accel/tcg/tb-stats.c      |  1 +
>  accel/tcg/translator.c    |  1 +
>  include/exec/gen-icount.h |  1 +
>  include/exec/tb-stats.h   | 15 ---------------
>  include/qemu-common.h     | 15 +++++++++++++++
>  include/qemu/log.h        |  1 +
>  tcg/tcg.c                 |  1 +
>  util/log.c                | 35 +++++++++++++++++++++++++++++++++++
>  8 files changed, 55 insertions(+), 15 deletions(-)
>
> diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c
> index e0ac254fc1..8554174360 100644
> --- a/accel/tcg/tb-stats.c
> +++ b/accel/tcg/tb-stats.c
> @@ -3,6 +3,7 @@
>  #include "disas/disas.h"
>  #include "exec/exec-all.h"
>  #include "tcg.h"
> +#include "qemu-common.h"
>
>  #include "qemu/qemu-print.h"
>
> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
> index 834265d5be..ea7c3a9f77 100644
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -16,6 +16,7 @@
>  #include "exec/gen-icount.h"
>  #include "exec/log.h"
>  #include "exec/translator.h"
> +#include "qemu-common.h"
>
>  /* Pairs with tcg_clear_temp_count.
>     To be called by #TranslatorOps.{translate_insn,tb_stop} if
> diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h
> index b3efe41894..6f54586dd6 100644
> --- a/include/exec/gen-icount.h
> +++ b/include/exec/gen-icount.h
> @@ -2,6 +2,7 @@
>  #define GEN_ICOUNT_H
>
>  #include "qemu/timer.h"
> +#include "qemu-common.h"
>
>  /* Helpers for instruction counting code generation.  */
>
> diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h
> index 0ea2639fd2..a607ceaa53 100644
> --- a/include/exec/tb-stats.h
> +++ b/include/exec/tb-stats.h
> @@ -79,21 +79,6 @@ void init_tb_stats_htable_if_not(void);
>  void dump_jit_profile_info(TCGProfile *s);
>
>  /* TBStatistic collection controls */
> -enum TBStatsStatus {
> -    TB_STATS_DISABLED = 0,
> -    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)
> -#define TB_JIT_STATS  (1 << 3)
> -
> -extern int tcg_collect_tb_stats;
> -extern uint32_t default_tbstats_flag;
> -
>  void enable_collect_tb_stats(void);
>  void disable_collect_tb_stats(void);
>  void pause_collect_tb_stats(void);
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 0235cd3b91..3930b61ec0 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -130,4 +130,19 @@ void page_size_init(void);
>   * returned. */
>  bool dump_in_progress(void);
>
> +enum TBStatsStatus {
> +    TB_STATS_DISABLED = 0,
> +    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)
> +#define TB_JIT_TIME   (1 << 3)
> +
> +extern int tcg_collect_tb_stats;
> +extern uint32_t default_tbstats_flag;
> +

This seems like a regression, why move from tb-stats.h? We should
certainly resist dumping more stuff in qemu-common.h.

>  #endif
> diff --git a/include/qemu/log.h b/include/qemu/log.h
> index b097a6cae1..a8d1997cde 100644
> --- a/include/qemu/log.h
> +++ b/include/qemu/log.h
> @@ -45,6 +45,7 @@ static inline bool qemu_log_separate(void)
>  /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */
>  #define CPU_LOG_TB_OP_IND  (1 << 16)
>  #define CPU_LOG_TB_FPU     (1 << 17)
> +#define CPU_LOG_TB_STATS   (1 << 18)
>
>  /* Lock output for a series of related logs.  Since this is not needed
>   * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 1a306e1ec9..08f3d50199 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -35,6 +35,7 @@
>  #include "qemu/host-utils.h"
>  #include "qemu/qemu-print.h"
>  #include "qemu/timer.h"
> +#include "qemu-common.h"
>
>  /* Note: the long term plan is to reduce the dependencies on the QEMU
>     CPU definitions. Currently they are used for qemu_ld/st
> diff --git a/util/log.c b/util/log.c
> index 29021a4584..09cfb13b45 100644
> --- a/util/log.c
> +++ b/util/log.c
> @@ -19,17 +19,20 @@
>
>  #include "qemu/osdep.h"
>  #include "qemu/log.h"
> +#include "qemu/qemu-print.h"
>  #include "qemu/range.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
>  #include "qemu/cutils.h"
>  #include "trace/control.h"
> +#include "qemu-common.h"

So the root problem you are trying to get around is we can't pollute
common code like logging with CPU definitions (which are required for
ram_addr_t stuff).

The solution for this is to split the enums and "common code facing" API
functions into another header (tb-stats-flags.h?) which doesn't need to
pull in the target specific bits.

>
>  static char *logfilename;
>  FILE *qemu_logfile;
>  int qemu_loglevel;
>  static int log_append = 0;
>  static GArray *debug_regions;
> +int32_t max_num_hot_tbs_to_dump;
>
>  int tcg_collect_tb_stats;
>  uint32_t default_tbstats_flag;
> @@ -276,6 +279,9 @@ const QEMULogItem qemu_log_items[] = {
>      { CPU_LOG_TB_NOCHAIN, "nochain",
>        "do not chain compiled TBs so that \"exec\" and \"cpu\" show\n"
>        "complete traces" },
> +    { CPU_LOG_TB_STATS, "tb_stats[[,level=(+all+jit+exec+time)][,dump_limit=<number>]]",
> +      "enable collection of TBs statistics"
> +      "(and dump until given a limit if in user mode).\n" },
>      { 0, NULL, NULL },
>  };
>
> @@ -297,6 +303,35 @@ int qemu_str_to_log_mask(const char *str)
>              trace_enable_events((*tmp) + 6);
>              mask |= LOG_TRACE;
>  #endif
> +        } else if (g_str_has_prefix(*tmp, "tb_stats")) {
> +            mask |= CPU_LOG_TB_STATS;
> +            default_tbstats_flag = TB_JIT_STATS | TB_EXEC_STATS | TB_JIT_TIME;
> +            tcg_collect_tb_stats = TB_STATS_RUNNING;
> +        } else if (tcg_collect_tb_stats == TB_STATS_RUNNING &&
> +                g_str_has_prefix(*tmp, "dump_limit=")) {
> +
> +            max_num_hot_tbs_to_dump = atoi((*tmp) + 11);
> +        } else if (tcg_collect_tb_stats == TB_STATS_RUNNING &&
> +                g_str_has_prefix(*tmp, "level=")) {
> +
> +            default_tbstats_flag = 0;
> +            char **level_parts = g_strsplit(*tmp + 6, "+", 0);
> +            char **level_tmp;
> +            for (level_tmp = level_parts; level_tmp && *level_tmp; level_tmp++) {
> +                if (g_str_equal(*level_tmp, "jit")) {
> +                    default_tbstats_flag |= TB_JIT_STATS;
> +                } else if (g_str_equal(*level_tmp, "exec")) {
> +                    default_tbstats_flag |= TB_EXEC_STATS;
> +                } else if (g_str_equal(*level_tmp, "time")) {
> +                    default_tbstats_flag |= TB_JIT_TIME;
> +                } else if (g_str_equal(*level_tmp, "all")) {
> +                    default_tbstats_flag |= TB_JIT_STATS | TB_EXEC_STATS | TB_JIT_TIME;
> +                } else {
> +                    fprintf(stderr, "no option level=%s, valid options are:"
> +                            "all, jit, exec or/and time\n", *level_tmp);
> +                    exit(1);
> +                }
> +            }

I'm pretty sure the string vector needs freeing once your done (g_strfreev())

>          } else {
>              for (item = qemu_log_items; item->mask != 0; item++) {
>                  if (g_str_equal(*tmp, item->name)) {


--
Alex Bennée


  reply	other threads:[~2019-08-27 13:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21 17:23 [Qemu-devel] [PATCH v6 00/10] Measure Tiny Code Generation Quality vandersonmr
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 01/10] accel: introducing TBStatistics structure vandersonmr
2019-08-26 16:24   ` Alex Bennée
2019-08-26 16:25   ` Alex Bennée
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 02/10] accel: collecting TB execution count vandersonmr
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 03/10] accel: collecting JIT statistics vandersonmr
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 04/10] accel: replacing part of CONFIG_PROFILER with TBStats vandersonmr
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 05/10] accel: adding TB_JIT_TIME and full replacing CONFIG_PROFILER vandersonmr
2019-08-27 13:11   ` Alex Bennée
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 06/10] log: adding -d tb_stats to control tbstats vandersonmr
2019-08-27 13:31   ` Alex Bennée [this message]
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 07/10] monitor: adding tb_stats hmp command vandersonmr
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 08/10] Adding info [tb-list|tb|coverset] commands to HMP vandersonmr
2019-08-22  9:52   ` Dr. David Alan Gilbert
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 09/10] monitor: adding new info cfg command vandersonmr
2019-08-22 10:00   ` Dr. David Alan Gilbert
2019-08-21 17:23 ` [Qemu-devel] [PATCH v6 10/10] linux-user: dumping hot TBs at the end of the execution vandersonmr

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=87o90a68gm.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).