qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"Dr. David Alan Gilbert" <dave@treblig.org>
Subject: Re: [PATCH v14 06/10] monitor: adding tb_stats hmp command
Date: Wed, 31 May 2023 18:23:26 -0700	[thread overview]
Message-ID: <f37aae7f-7b90-af71-a188-bac4e7bf851f@linaro.org> (raw)
In-Reply-To: <20230530083526.2174430-7-fei2.wu@intel.com>

On 5/30/23 01:35, Fei Wu wrote:
> From: "Vanderson M. do Rosario" <vandersonmr2@gmail.com>
> 
> Adding tb_stats [start|pause|stop|filter] command to hmp.
> This allows controlling the collection of statistics.
> It is also possible to set the level of collection:
> all, jit, or exec.
> 
> tb_stats filter allow to only collect statistics for the TB
> in the last_search list.
> 
> The goal of this command is to allow the dynamic exploration
> of the TCG behavior and quality. Therefore, for now, a
> corresponding QMP command is not worthwhile.
> 
> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Vanderson M. do Rosario <vandersonmr2@gmail.com>
> Message-Id: <20190829173437.5926-8-vandersonmr2@gmail.com>
> Message-Id: <20190829173437.5926-9-vandersonmr2@gmail.com>
> [AJB: fix authorship]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Fei Wu <fei2.wu@intel.com>
> ---


I still don't see what pause does.

> diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c
> index 68ac7d3f73..805e1fc74d 100644
> --- a/accel/tcg/tb-stats.c
> +++ b/accel/tcg/tb-stats.c
> @@ -16,18 +16,20 @@
>   #include "qemu/timer.h"
>   
>   #include "exec/tb-stats.h"
> +#include "exec/tb-flush.h"
>   #include "tb-context.h"
>   
>   /* TBStatistic collection controls */
>   enum TBStatsStatus {
>       TB_STATS_DISABLED = 0,
>       TB_STATS_RUNNING,
> -    TB_STATS_PAUSED,
> -    TB_STATS_STOPPED
> +    TB_STATS_PAUSED
>   };

Why?

>   
>   static enum TBStatsStatus tcg_collect_tb_stats;
>   static uint32_t default_tbstats_flag;
> +/* only accessed in safe work */
> +static GList *last_search;
>   
>   uint64_t dev_time;
>   
> @@ -170,6 +172,101 @@ void dump_jit_profile_info(TCGProfile *s, GString *buf)
>       g_free(jpi);
>   }
>   
> +static void free_tbstats(void *p, uint32_t hash, void *userp)
> +{
> +    g_free(p);
> +}
> +
> +static void clean_tbstats(void)
> +{
> +    /* remove all tb_stats */
> +    qht_iter(&tb_ctx.tb_stats, free_tbstats, NULL);
> +    qht_destroy(&tb_ctx.tb_stats);
> +}
> +
> +void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd)
> +{
> +    struct TbstatsCommand *cmdinfo = icmd.host_ptr;
> +    int cmd = cmdinfo->cmd;
> +    uint32_t level = cmdinfo->level;
> +
> +    switch (cmd) {
> +    case START:
> +        if (tb_stats_collection_enabled()) {
> +            qemu_printf("TB information already being recorded");
> +            return;
> +        } else if (tb_stats_collection_paused()) {
> +            set_tbstats_flags(level);
> +        } else {
> +            qht_init(&tb_ctx.tb_stats, tb_stats_cmp, CODE_GEN_HTABLE_SIZE,
> +                     QHT_MODE_AUTO_RESIZE);
> +        }
> +
> +        set_default_tbstats_flag(level);
> +        enable_collect_tb_stats();
> +        tb_flush(cpu);
> +        break;
> +    case PAUSE:
> +        if (!tb_stats_collection_enabled()) {
> +            qemu_printf("TB information not being recorded");
> +            return;
> +        }
> +
> +        /*
> +         * Continue to create TBStatistic structures but stop collecting
> +         * statistics
> +         */
> +        pause_collect_tb_stats();
> +        set_default_tbstats_flag(TB_NOTHING);
> +        set_tbstats_flags(TB_PAUSED);
> +        tb_flush(cpu);
> +        break;
> +    case STOP:
> +        if (tb_stats_collection_disabled()) {
> +            qemu_printf("TB information not being recorded");
> +            return;
> +        }
> +
> +        /* Dissalloc all TBStatistics structures and stop creating new ones */
> +        disable_collect_tb_stats();
> +        clean_tbstats();
> +        tb_flush(cpu);
> +        break;
> +    case FILTER:
> +        if (!tb_stats_collection_enabled()) {
> +            qemu_printf("TB information not being recorded");
> +            return;
> +        }
> +        if (!last_search) {
> +            qemu_printf(
> +                    "no search on record! execute info tbs before filtering!");
> +            return;
> +        }
> +
> +        set_default_tbstats_flag(TB_NOTHING);
> +
> +        /*
> +         * Set all tbstats as paused, then return only the ones from last_search
> +         */
> +        pause_collect_tb_stats();
> +        set_tbstats_flags(TB_PAUSED);
> +
> +        for (GList *iter = last_search; iter; iter = g_list_next(iter)) {
> +            TBStatistics *tbs = iter->data;
> +            tbs->stats_enabled = level;
> +        }
> +
> +        tb_flush(cpu);
> +
> +        break;
> +    default: /* INVALID */
> +        g_assert_not_reached();
> +        break;
> +    }
> +
> +    g_free(cmdinfo);
> +}

Why isn't all of this in monitor.c?
It's not used or usable from user-only mode.

> +void set_tbstats_flags(uint32_t flag)
> +{
> +    /* iterate over tbstats setting their flag as TB_NOTHING */
> +    qht_iter(&tb_ctx.tb_stats, reset_tbstats_flag, &flag);
> +}

Again, I question why a global variable is not more appropriate.


r~


  reply	other threads:[~2023-06-01  1:24 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  8:35 [PATCH v14 00/10] TCG code quality tracking Fei Wu
2023-05-30  8:35 ` [PATCH v14 01/10] accel/tcg: remove CONFIG_PROFILER Fei Wu
2023-05-30  8:35 ` [PATCH v14 02/10] accel/tcg: introduce TBStatistics structure Fei Wu
2023-05-31 23:59   ` Richard Henderson
2023-06-01  1:30     ` Wu, Fei
2023-06-01  2:48       ` Richard Henderson
2023-06-01  0:01   ` Richard Henderson
2023-06-01  3:19     ` Wu, Fei
2023-06-01  4:16       ` Richard Henderson
2023-06-01  5:36         ` Wu, Fei
2023-05-30  8:35 ` [PATCH v14 03/10] accel: collecting TB execution count Fei Wu
2023-06-01  0:05   ` Richard Henderson
2023-06-01  5:44     ` Wu, Fei
2023-06-01 14:03       ` Richard Henderson
2023-06-02  1:54         ` Wu, Fei
2023-06-02  4:02           ` Richard Henderson
2023-05-30  8:35 ` [PATCH v14 04/10] accel/tcg: add jit stats and time to TBStatistics Fei Wu
2023-05-30  9:37   ` Markus Armbruster
2023-05-31  0:54     ` Wu, Fei
2023-06-01  1:08   ` Richard Henderson
2023-06-01  6:48     ` Wu, Fei
2023-06-01 14:10       ` Richard Henderson
2023-06-01 15:10       ` Richard Henderson
2023-05-30  8:35 ` [PATCH v14 05/10] debug: add -d tb_stats to control TBStatistics collection: Fei Wu
2023-06-01  1:18   ` Richard Henderson
2023-06-01  6:59     ` Wu, Fei
2023-05-30  8:35 ` [PATCH v14 06/10] monitor: adding tb_stats hmp command Fei Wu
2023-06-01  1:23   ` Richard Henderson [this message]
2023-06-01  7:20     ` Wu, Fei
2023-06-01 14:25       ` Richard Henderson
2023-05-30  8:35 ` [PATCH v14 07/10] tb-stats: reset the tracked TBs on a tb_flush Fei Wu
2023-06-01  1:30   ` Richard Henderson
2023-06-01  7:22     ` Wu, Fei
2023-05-30  8:35 ` [PATCH v14 08/10] Adding info [tb-list|tb] commands to HMP (WIP) Fei Wu
2023-06-01  2:40   ` Richard Henderson
2023-06-01 12:12     ` Wu, Fei
2023-06-06  7:30       ` Wu, Fei
2023-06-07 12:49     ` Wu, Fei
2023-06-08  7:38       ` Wu, Fei
2023-06-08  9:23         ` Peter Maydell
2023-06-08 12:06           ` Dr. David Alan Gilbert
2023-06-08 12:22             ` Peter Maydell
2023-06-09 14:32           ` Wu, Fei
2023-06-09 15:51             ` Peter Maydell
2023-06-12  1:20               ` Wu, Fei
2023-05-30  8:35 ` [PATCH v14 09/10] tb-stats: dump hot TBs at the end of the execution Fei Wu
2023-05-30  8:35 ` [PATCH v14 10/10] docs: add tb-stats how to Fei Wu

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=f37aae7f-7b90-af71-a188-bac4e7bf851f@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=dave@treblig.org \
    --cc=dgilbert@redhat.com \
    --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).