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: vandersonmr <vandersonmr2@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v8 06/11] Adding -d tb_stats to control TBStatistics collection:
Date: Fri, 30 Aug 2019 15:45:27 +0100	[thread overview]
Message-ID: <87v9ue7lvc.fsf@linaro.org> (raw)
In-Reply-To: <20190829173437.5926-7-vandersonmr2@gmail.com>


vandersonmr <vandersonmr2@gmail.com> writes:

>  -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>
> ---
>  include/exec/gen-icount.h     |  1 +
>  include/exec/tb-stats-flags.h | 42 +++++++++++++++++++++++++++++++++++
>  include/exec/tb-stats.h       | 18 +++------------
>  include/qemu/log.h            |  1 +
>  util/log.c                    | 35 +++++++++++++++++++++++++++++
>  5 files changed, 82 insertions(+), 15 deletions(-)
>  create mode 100644 include/exec/tb-stats-flags.h
>
> diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h
> index be006383b9..3987adfb0e 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 "tb-stats-flags.h"
>
>  /* Helpers for instruction counting code generation.  */
>
> diff --git a/include/exec/tb-stats-flags.h b/include/exec/tb-stats-flags.h
> new file mode 100644
> index 0000000000..c936ac1084
> --- /dev/null
> +++ b/include/exec/tb-stats-flags.h
> @@ -0,0 +1,42 @@
> +/*
> + * QEMU System Emulator, Code Quality Monitor System
> + *
> + * Copyright (c) 2019 Vanderson M. do Rosario <vandersonmr2@gmail.com>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.

Any reason not to use GPLv2 or later here?

> + */
> +#ifndef TB_STATS_FLAGS
> +#define TB_STATS_FLAGS
> +
> +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;
> +
> +#endif
> diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h
> index 0b9a6e2f72..6a53bef31b 100644
> --- a/include/exec/tb-stats.h
> +++ b/include/exec/tb-stats.h
> @@ -30,6 +30,8 @@
>  #include "exec/tb-context.h"
>  #include "tcg.h"
>
> +#include "exec/tb-stats-flags.h"
> +
>  #define tb_stats_enabled(tb, JIT_STATS) \
>      (tb && tb->tb_stats && (tb->tb_stats->stats_enabled & JIT_STATS))
>
> @@ -98,26 +100,12 @@ bool tb_stats_cmp(const void *ap, const void *bp);
>
>  void dump_jit_exec_time_info(uint64_t dev_time);
>
> +void set_tbstats_flags(uint32_t flags);
>  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_TIME   (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/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/util/log.c b/util/log.c
> index 29021a4584..c3805b331b 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 "exec/tb-stats-flags.h"
>
>  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);

You can't exit here - for one thing a typo on the HMP will kill your
machine. You should pass Error **err to the helper and use error_setg to
report the failure.

From vl.c/main.c you can pass &error_fatal and it will report and
error out as you expect.

From the HMP hooks:

    Error *err = NULL;

    ...
    qemu_str_to_log_mask(flags, &err)
    ...
    if (err) {
        hmp_handle_error(mon, &err);
        return;
    }

You'll need to fix up the existing calls to do this instead of the if
!mask error_report they currently do.


> +                }
> +            }
>          } 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-30 14:50 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
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 [this message]
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=87v9ue7lvc.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --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).