All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Fei Wu <fei2.wu@intel.com>
Cc: richard.henderson@linaro.org, pbonzini@redhat.com,
	erdnaxe@crans.org, ma.mandourr@gmail.com, qemu-devel@nongnu.org
Subject: Re: [PATCH 2/2] plugins/hotblocks: add host insn size
Date: Thu, 06 Apr 2023 08:54:54 +0100	[thread overview]
Message-ID: <87r0sxjv7m.fsf@linaro.org> (raw)
In-Reply-To: <20230406022751.757980-3-fei2.wu@intel.com>


Fei Wu <fei2.wu@intel.com> writes:

> It's only valid when inline=false, otherwise it's default to 0.
>
> Signed-off-by: Fei Wu <fei2.wu@intel.com>
> ---
>  contrib/plugins/hotblocks.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
> index 062200a7a4..c9716da7fe 100644
> --- a/contrib/plugins/hotblocks.c
> +++ b/contrib/plugins/hotblocks.c
> @@ -37,6 +37,8 @@ typedef struct {
>      uint64_t exec_count;
>      int      trans_count;
>      unsigned long insns;
> +    void    *p_host_insn_size;
> +    uint64_t host_insn_size;
>  } ExecCount;
>  
>  static gint cmp_exec_count(gconstpointer a, gconstpointer b)
> @@ -59,13 +61,17 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
>      it = g_list_sort(counts, cmp_exec_count);
>  
>      if (it) {
> -        g_string_append_printf(report, "pc, tcount, icount, ecount\n");
> +        g_string_append_printf(report,
> +                               "host isize is only valid when inline=false\n"
> +                               "pc, tcount, icount, ecount, host isize\n");
>  
>          for (i = 0; i < limit && it->next; i++, it = it->next) {
>              ExecCount *rec = (ExecCount *) it->data;
> -            g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n",
> +            g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRId64
> +                                   ", %"PRIu64"\n",
>                                     rec->start_addr, rec->trans_count,
> -                                   rec->insns, rec->exec_count);
> +                                   rec->insns, rec->exec_count,
> +                                   rec->host_insn_size);
>          }
>  
>          g_list_free(it);
> @@ -82,14 +88,13 @@ static void plugin_init(void)
>  
>  static void vcpu_tb_exec(unsigned int cpu_index, void *udata)
>  {
> -    ExecCount *cnt;
> -    uint64_t hash = (uint64_t) udata;
> +    ExecCount *cnt = (ExecCount *) udata;
>  
>      g_mutex_lock(&lock);
> -    cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash);
> -    /* should always succeed */
> -    g_assert(cnt);
>      cnt->exec_count++;
> +    if (cnt->host_insn_size == 0) {
> +        cnt->host_insn_size = *((uint64_t *)cnt->p_host_insn_size);

No - passing an internal TCG pointer across different phases of
translation/execution is a definite no no. We explicitly state that
handles are only valid for callbacks in the docs:

  Lifetime of the query handle
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  Each callback provides an opaque anonymous information handle which
  can usually be further queried to find out information about a
  translation, instruction or operation. The handles themselves are only
  valid during the lifetime of the callback so it is important that any
  information that is needed is extracted during the callback and saved
  by the plugin.

to avoid this sort of tangling of implementation details into the
plugins.


> +    }
>      g_mutex_unlock(&lock);
>  }
>  
> @@ -114,6 +119,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>          cnt->start_addr = pc;
>          cnt->trans_count = 1;
>          cnt->insns = insns;
> +        cnt->p_host_insn_size = qemu_plugin_tb_host_insn_size(tb);
>          g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt);
>      }
>  
> @@ -125,7 +131,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>      } else {
>          qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec,
>                                               QEMU_PLUGIN_CB_NO_REGS,
> -                                             (void *)hash);
> +                                             (void *)cnt);
>      }
>  }


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


      reply	other threads:[~2023-04-06  8:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06  2:27 [PATCH 0/2] accel/tcg/plugin: host insn size for plugin Fei Wu
2023-04-06  2:27 ` [PATCH 1/2] accel/tcg/plugin: export host insn size Fei Wu
2023-04-06  7:46   ` Alex Bennée
2023-04-07  1:31     ` Wu, Fei
2023-04-10 10:46       ` Alex Bennée
2023-04-08  3:34     ` Richard Henderson
2023-04-10 10:36       ` Alex Bennée
2023-04-10 13:02         ` Wu, Fei
2023-04-11  7:27           ` Alex Bennée
2023-04-12 12:50             ` Wu, Fei
2023-04-12 13:28               ` Alex Bennée
2023-04-12 13:47                 ` Wu, Fei
2023-04-17 11:11             ` Wu, Fei
2023-04-17 12:11               ` Alex Bennée
2023-04-17 13:01                 ` Wu, Fei
2023-04-21 13:46                   ` Wu, Fei
2023-04-06  2:27 ` [PATCH 2/2] plugins/hotblocks: add " Fei Wu
2023-04-06  7:54   ` Alex Bennée [this message]

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=87r0sxjv7m.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=erdnaxe@crans.org \
    --cc=fei2.wu@intel.com \
    --cc=ma.mandourr@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.