TCG code quality tracking
v16 cover TCG code quality tracking
v16
--
* rebase to latest commit 4329d049d (Jun 26)
* original patch 1 (remove CONFIG_PROFILER) has already upstreamed so is removed from here
* add async_safe_run_on_cpu back for info tb-list/tb
* add ram_addr support to monitor_disas and use it to disassemble guest code
* update the commit logs and documents
* small change to do_hmp_tbstats_safe() to avoid memory leaking
Alex Bennée (1):
tb-stats: reset the tracked TBs on a tb_flush
Fei Wu (4):
accel/tcg: add jit stats to TBStatistics
debug: add -d tb_stats to control TBStatistics
tb-stats: dump hot TBs at the end of the execution
docs: add tb-stats how to
Vanderson M. do Rosario (4):
accel/tcg: introduce TBStatistics structure
accel: collecting TB execution count
monitor: adding tb_stats hmp command
tb-stats: Adding info [tb-list|tb] commands to HMP
MAINTAINERS | 1 + accel/tcg/cpu-exec.c | 6 + accel/tcg/meson.build | 1 + accel/tcg/monitor.c | 216 ++++++++++++++++++ accel/tcg/tb-context.h | 1 + accel/tcg/tb-hash.h | 7 + accel/tcg/tb-maint.c | 20 ++ accel/tcg/tb-stats.c | 366 +++++++++++++++++++++++++++++++ accel/tcg/tcg-runtime.c | 1 + accel/tcg/translate-all.c | 77 ++++++- accel/tcg/translator.c | 31 +++ disas/disas-mon.c | 15 +- disas/disas.c | 2 + docs/devel/index-tcg.rst | 1 + docs/devel/tcg-tbstats.rst | 126 +++++++++++ hmp-commands-info.hx | 16 ++ hmp-commands.hx | 16 ++ include/disas/disas.h | 8 +- include/exec/tb-stats-dump.h | 21 ++ include/exec/tb-stats-flags.h | 29 +++ include/exec/tb-stats.h | 130 +++++++++++ include/exec/translation-block.h | 3 + include/monitor/hmp.h | 3 + include/qemu/log.h | 1 + include/tcg/tcg-temp-internal.h | 2 + include/tcg/tcg.h | 10 + linux-user/exit.c | 2 + monitor/hmp-cmds-target.c | 3 +- softmmu/runstate.c | 2 + stubs/meson.build | 1 + stubs/tb-stats.c | 36 +++ tcg/tcg.c | 47 +++- util/log.c | 26 +++ 33 files changed, 1217 insertions(+), 10 deletions(-) create mode 100644 accel/tcg/tb-stats.c create mode 100644 docs/devel/tcg-tbstats.rst create mode 100644 include/exec/tb-stats-dump.h create mode 100644 include/exec/tb-stats-flags.h create mode 100644 include/exec/tb-stats.h create mode 100644 stubs/tb-stats.c
Signature · 1 line
2.25.1
PATCH v16 1/9 accel/tcg: introduce TBStatistics structure
From: "Vanderson M. do Rosario" <[email protected]>
To store statistics for each TB, we created a TBStatistics structure which is linked with the TBs. TBStatistics can stay alive after tb_flush and be relinked to a regenerated TB. So the statistics can be accumulated even through flushes.
The goal is to have all present and future qemu/tcg statistics and meta-data stored in this new structure.
Message-Id: <[email protected]>
--- MAINTAINERS | 1 + accel/tcg/meson.build | 1 + accel/tcg/tb-context.h | 1 + accel/tcg/tb-hash.h | 7 ++++ accel/tcg/tb-maint.c | 19 +++++++++++ accel/tcg/tb-stats.c | 46 ++++++++++++++++++++++++++ accel/tcg/translate-all.c | 44 +++++++++++++++++++++++++ include/exec/tb-stats-flags.h | 19 +++++++++++ include/exec/tb-stats.h | 56 ++++++++++++++++++++++++++++++++ include/exec/translation-block.h | 3 ++ 10 files changed, 197 insertions(+) create mode 100644 accel/tcg/tb-stats.c create mode 100644 include/exec/tb-stats-flags.h create mode 100644 include/exec/tb-stats.h
MAINTAINERS +1 -0
@@ -153,6 +153,7 @@ F: include/exec/cpu*.h F: include/exec/exec-all.h F: include/exec/tb-flush.h F: include/exec/target_long.h +F: include/exec/tb-stats*.h F: include/exec/helper*.h F: include/exec/helper*.h.inc F: include/exec/helper-info.c.inc
accel/tcg/meson.build +1 -0
@@ -4,6 +4,7 @@ tcg_ss.add(files( 'cpu-exec-common.c', 'cpu-exec.c', 'tb-maint.c', + 'tb-stats.c', 'tcg-runtime-gvec.c', 'tcg-runtime.c', 'translate-all.c',
accel/tcg/tb-context.h +1 -0
@@ -35,6 +35,7 @@ struct TBContext {/* statistics */ unsigned tb_flush_count;unsigned tb_phys_invalidate_count; +struct qht tb_stats; };extern TBContext tb_ctx;
accel/tcg/tb-hash.h +7 -0
@@ -67,4 +67,11 @@ uint32_t tb_hash_func(tb_page_addr_t phys_pc, vaddr pc, return qemu_xxhash8(phys_pc, pc, flags2, flags, cf_mask); } +static inline +uint32_t tb_stats_hash_func (tb_page_addr_t phys_pc,target_ulong pc, +uint32_t flags) +{ +return qemu_xxhash5 (phys_pc, pc, flags); +} +#endif
accel/tcg/tb-maint.c +19 -0
@@ -24,6 +24,7 @@#include "exec/log.h" #include "exec/exec-all.h" #include "exec/tb-flush.h" +#include "exec/tb-stats.h" #include "exec/translate-all.h" #include "sysemu/tcg.h" #include "tcg/tcg.h"
@@ -41,6 +42,23 @@#define TB_FOR_EACH_JMP (head_tb, tb, n) \ TB_FOR_EACH_TAGGED((head_tb)->jmp_list_head, tb, n, jmp_list_next) +/* +* This is the more or less the same compare as tb_cmp(), but the +* data persists over tb_flush. We also aggregate the various +* variations of cflags under one record and ignore the details of +* page overlap (although we can count it). +*/ +bool tb_stats_cmp (const void *ap,const void *bp) +{ +const TBStatistics *a = ap; +const TBStatistics *b = bp; + +return a->phys_pc == b->phys_pc && + a->pc == b->pc && + a->cs_base == b->cs_base && + a->flags == b->flags; +} +static bool tb_cmp (const void *ap,const void *bp) {const TranslationBlock *a = ap;
@@ -59,6 +77,7 @@ void tb_htable_init(void)unsigned int mode =QHT_MODE_AUTO_RESIZE ;qht_init (&tb_ctx.htable, tb_cmp,CODE_GEN_HTABLE_SIZE , mode); +init_tb_stats_htable (); }typedef struct PageDesc PageDesc ;
accel/tcg/tb-stats.c new file +46 -0
46 lines not on this page · raw message
accel/tcg/translate-all.c +44 -0
62 lines not on this page · raw message
include/exec/tb-stats-flags.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* QEMU System Emulator, Code Quality Monitor System +* +* We define the flags and control bits here to avoid complications of +* including TCG/CPU information in common code. +* +* Copyright (c) 2019 Vanderson M. do Rosario <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef TB_STATS_FLAGS +#define TB_STATS_FLAGS + +/* TBStatistic collection controls */ +void enable_collect_tb_stats (void ); +void disable_collect_tb_stats (void ); +bool tb_stats_collection_enabled (void ); + +#endif
include/exec/tb-stats.h new file +56 -0
56 lines not on this page · raw message
include/exec/translation-block.h +3 -0
@@ -141,6 +141,9 @@ struct TranslationBlock {uintptr_t jmp_list_head;uintptr_t jmp_list_next[2 ];uintptr_t jmp_dest[2 ]; + +/* Pointer to a struct where statistics from the TB is stored */ +struct TBStatistics *tb_stats; };/* The alignment given to TranslationBlock during allocation. */
Signature · 1 line
2.25.1
PATCH v16 2/9 accel: collecting TB execution count
In reply to Fei WuFrom: "Vanderson M. do Rosario" <[email protected]>
If a TB has a TBS (TBStatistics) with the TB_EXEC_STATS enabled, then we instrument the start code of this TB to atomically count the number of times it is executed. We count both the number of "normal" executions and atomic executions of a TB.
The execution count of the TB is stored in its respective TBS.
All TBStatistics are created by default with the flags from default_tbstats_flag.
[Richard Henderson created the inline gen_tb_exec_count]
Message-Id: <[email protected]>
--- accel/tcg/cpu-exec.c | 6 ++++++ accel/tcg/tb-stats.c | 18 ++++++++++++++++++ accel/tcg/tcg-runtime.c | 1 + accel/tcg/translate-all.c | 6 ++++-- accel/tcg/translator.c | 26 ++++++++++++++++++++++++++ include/exec/tb-stats-flags.h | 6 ++++++ include/exec/tb-stats.h | 7 +++++++ include/tcg/tcg-temp-internal.h | 2 ++ 8 files changed, 70 insertions(+), 2 deletions(-)
accel/tcg/cpu-exec.c +6 -0
@@ -25,6 +25,7 @@#include "trace.h" #include "disas/disas.h" #include "exec/exec-all.h" +#include "exec/tb-stats.h" #include "tcg/tcg.h" #include "qemu/atomic.h" #include "qemu/rcu.h"
@@ -562,7 +563,12 @@ void cpu_exec_step_atomic(CPUState *cpu)mmap_unlock (); } +if (tb_stats_enabled (tb,TB_EXEC_STATS )) { + tb->tb_stats->executions.atomic++; + } +cpu_exec_enter (cpu); +/* execute the generated code */ trace_exec_tb (tb, pc);cpu_tb_exec (cpu, tb, &tb_exit);
accel/tcg/tb-stats.c +18 -0
@@ -20,6 +20,7 @@ enum TBStatsStatus { };static enum TBStatsStatus tcg_collect_tb_stats; +static uint32_t tbstats_flag;void init_tb_stats_htable (void ) {
@@ -44,3 +45,20 @@ bool tb_stats_collection_enabled(void) {return tcg_collect_tb_stats ==TB_STATS_RUNNING ; } + +uint32_t get_tbstats_flag (void ) +{ +return tbstats_flag; +} + +void set_tbstats_flag (uint32_t flag) +{ + tbstats_flag = flag; +} + +bool tb_stats_enabled (TranslationBlock *tb,uint32_t flag) +{ +return tb_stats_collection_enabled () && + tb->tb_stats && + (tbstats_flag & flag); +}
accel/tcg/tcg-runtime.c +1 -0
@@ -27,6 +27,7 @@#include "exec/helper-proto-common.h" #include "exec/cpu_ldst.h" #include "exec/exec-all.h" +#include "exec/tb-stats.h" #include "disas/disas.h" #include "exec/log.h" #include "tcg/tcg.h"
accel/tcg/translate-all.c +4 -2
@@ -388,9 +388,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu,/* * We want to fetch the stats structure before we start code * generation so we can count interesting things about this -* generation. +* generation. If dfilter is in effect we will only collect stats +* for the specified range. */ -if (tb_stats_collection_enabled ()) { +if (tb_stats_collection_enabled () && +qemu_log_in_addr_range (tb->pc)) { tb->tb_stats =tb_get_stats (phys_pc, cflags &CF_PCREL ?0 : pc, cs_base, flags); }else {
accel/tcg/translator.c +26 -0
@@ -10,10 +10,12 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/error-report.h" +#include "tcg/tcg-temp-internal.h" #include "exec/exec-all.h" #include "exec/translator.h" #include "exec/translate-all.h" #include "exec/plugin-gen.h" +#include "exec/tb-stats.h" #include "tcg/tcg-op-common.h" static void gen_io_start (void )
@@ -117,6 +119,29 @@ static void gen_tb_end(const TranslationBlock *tb, uint32_t cflags, } } +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,vaddr dest) {/* Suppress goto_tb if requested. */
@@ -156,6 +181,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,/* Start translating. */ icount_start_insn =gen_tb_start (cflags); +gen_tb_exec_count (tb); ops->tb_start (db, cpu);tcg_debug_assert (db->is_jmp ==DISAS_NEXT );/* no early exit */
include/exec/tb-stats-flags.h +6 -0
@@ -11,9 +11,15 @@#ifndef TB_STATS_FLAGS #define TB_STATS_FLAGS +#define TB_NONE_STATS (0)/* no stats */ +#define TB_EXEC_STATS (1 << 0) +/* TBStatistic collection controls */ void enable_collect_tb_stats (void );void disable_collect_tb_stats (void );bool tb_stats_collection_enabled (void ); +uint32_t get_tbstats_flag (void ); +void set_tbstats_flag (uint32_t flag); +#endif
include/exec/tb-stats.h +7 -0
@@ -47,10 +47,17 @@ struct TBStatistics {uint32_t flags;/* cs_base isn't included in the hash but we do check for matches */ uint64_t cs_base; + +/* Execution stats */ +struct { +unsigned long normal; +unsigned long atomic; + } executions; };bool tb_stats_cmp (const void *ap,const void *bp);void init_tb_stats_htable (void ); +bool tb_stats_enabled (TranslationBlock *tb,uint32_t flag);#endif
include/tcg/tcg-temp-internal.h +2 -0
@@ -25,6 +25,8 @@#ifndef TCG_TEMP_INTERNAL_H #define TCG_TEMP_INTERNAL_H +#include "tcg.h" +/* * Allocation and freeing of EBB temps is reserved to TCG internals */
Signature · 1 line
2.25.1
PATCH v16 3/9 accel/tcg: add jit stats to TBStatistics
In reply to Fei WuThis collects all the statistics for TBStatistics, not only for the whole emulation but for each TB.
--- accel/tcg/monitor.c | 6 +++ accel/tcg/tb-stats.c | 69 +++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 31 ++++++++++++++-- accel/tcg/translator.c | 5 +++ include/exec/tb-stats-flags.h | 1 + include/exec/tb-stats.h | 30 +++++++++++++++ include/tcg/tcg.h | 10 +++++ tcg/tcg.c | 47 ++++++++++++++++++++++-- 8 files changed, 193 insertions(+), 6 deletions(-)
accel/tcg/monitor.c +6 -0
@@ -16,6 +16,7 @@#include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" +#include "exec/tb-stats.h" #include "internal.h"
@@ -70,6 +71,11 @@ HumanReadableText *qmp_x_query_opcount(Error **errp) {g_autoptr (GString) buf =g_string_new ("" ); +if (!tb_stats_collection_enabled ()) { +error_setg (errp,"TB information not being recorded" ); +return NULL ; + } +if (!tcg_enabled ()) {error_setg (errp,"Opcode count information is only available with accel=tcg" );
accel/tcg/tb-stats.c +69 -0
81 lines not on this page · raw message
accel/tcg/translate-all.c +28 -3
@@ -266,7 +266,7 @@ void page_init(void)*/ static int setjmp_gen_code (CPUArchState *env,TranslationBlock *tb,vaddr pc,void *host_pc, -int *max_insns,int64_t *ti) +int *max_insns) {int ret =sigsetjmp (tcg_ctx->jmp_trans,0 );if (unlikely (ret !=0 )) {
@@ -294,6 +294,8 @@ static TBStatistics *tb_get_stats(tb_page_addr_t phys_pc, target_ulong pc, new_stats->pc = pc; new_stats->cs_base = cs_base; new_stats->flags = flags; + new_stats->tbs =g_ptr_array_new (); +qemu_mutex_init (&new_stats->jit_stats_lock);/* * All initialisation must be complete before we insert into qht
@@ -307,6 +309,7 @@ static TBStatistics *tb_get_stats(tb_page_addr_t phys_pc, target_ulong pc,* If there is already a TBStatistic for this TB from a previous flush * then just make the new TB point to the older TBStatistic */ +g_ptr_array_free (new_stats->tbs, true);g_free (new_stats);return existing_stats; }else {
@@ -325,7 +328,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tb_page_addr_t phys_pc;tcg_insn_unit *gen_code_buf;int gen_code_size, search_size, max_insns; -int64_t ti;void *host_pc;assert_memory_lock ();
@@ -399,7 +401,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->tb_stats =NULL ; } - gen_code_size =setjmp_gen_code (env, tb, pc, host_pc, &max_insns, &ti); + gen_code_size =setjmp_gen_code (env, tb, pc, host_pc, &max_insns);if (unlikely (gen_code_size <0 )) {switch (gen_code_size) {case -1 :
@@ -553,6 +555,29 @@ TranslationBlock *tb_gen_code(CPUState *cpu,return tb; } +/* +* Collect JIT stats when enabled. We batch them all up here to +* avoid spamming the cache with atomic accesses +*/ +if (tb_stats_enabled (tb,TB_JIT_STATS )) { +TBStatistics *ts = tb->tb_stats; +qemu_mutex_lock (&ts->jit_stats_lock); + + ts->code.num_tcg_ops_opt += tcg_ctx->nb_ops; + ts->code.in_len += tb->size; + ts->code.out_len += tb->tc.size; + ts->code.search_out_len += search_size; + + ts->translations.total++; +if (tb_page_addr1 (tb) !=-1 ) { + ts->translations.spanning++; + } + +g_ptr_array_add (ts->tbs, tb); + +qemu_mutex_unlock (&ts->jit_stats_lock); + } +/* * Insert TB into the corresponding region tree before publishing it * through QHT. Otherwise rewinding happened in the TB might fail to
accel/tcg/translator.c +5 -0
@@ -248,6 +248,11 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, tb->size = db->pc_next - db->pc_first; tb->icount = db->num_insns; +/* Save number of guest instructions for TB_JIT_STATS */ +if (tb_stats_enabled (tb,TB_JIT_STATS )) { + tb->tb_stats->code.num_guest_inst += db->num_insns; + } +if (qemu_loglevel_mask (CPU_LOG_TB_IN_ASM ) &&qemu_log_in_addr_range (db->pc_first)) {FILE *logfile =qemu_log_trylock ();
include/exec/tb-stats-flags.h +1 -0
@@ -13,6 +13,7 @@#define TB_NONE_STATS (0)/* no stats */ #define TB_EXEC_STATS (1 << 0) +#define TB_JIT_STATS (1 << 1)/* TBStatistic collection controls */ void enable_collect_tb_stats (void );
include/exec/tb-stats.h +30 -0
@@ -53,6 +53,34 @@ struct TBStatistics {unsigned long normal;unsigned long atomic; } executions; + +/* JIT Stats - protected by lock */ +QemuMutex jit_stats_lock; + +/* Sum of all operations for all translations */ +struct { +unsigned num_guest_inst; +unsigned num_tcg_ops; +unsigned num_tcg_ops_opt; +unsigned spills; + +unsigned temps; +unsigned deleted_ops; +unsigned in_len; +unsigned out_len; +unsigned search_out_len; + } code; + +struct { +unsigned long total; +unsigned long spanning; + } translations; + +/* +* All persistent (cached) TranslationBlocks using +* this TBStats structure. Has to be reset on a tb_flush. +*/ +GPtrArray *tbs; };bool tb_stats_cmp (const void *ap,const void *bp);
@@ -60,4 +88,6 @@ bool tb_stats_cmp(const void *ap, const void *bp);void init_tb_stats_htable (void );bool tb_stats_enabled (TranslationBlock *tb,uint32_t flag); +void dump_jit_profile_info (GString *buf); +#endif
include/tcg/tcg.h +10 -0
@@ -478,6 +478,14 @@ static inline TCGRegSet output_pref(const TCGOp *op, unsigned i)return i <ARRAY_SIZE (op->output_pref) ? op->output_pref[i] :0 ; } +/* +* The TCGProfile structure holds data for the lifetime of the translator. +*/ +typedef struct TCGProfile { +/* Lifetime count of TCGOps per TCGContext when tb_stats enabled */ +size_t table_op_count[NB_OPS ]; +}TCGProfile ; +struct TCGContext {uint8_t *pool_cur, *pool_end;TCGPool *pool_first, *pool_current, *pool_first_large;
@@ -507,6 +515,8 @@ struct TCGContext {tcg_insn_unit *code_buf;/* pointer for start of tb */ tcg_insn_unit *code_ptr;/* pointer for running end of tb */ +TCGProfile prof; +#ifdef CONFIG_DEBUG_TCG int goto_tb_issue_mask;const TCGOpcode *vecop_list;
tcg/tcg.c +44 -3
92 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v16 4/9 monitor: adding tb_stats hmp command
In reply to Fei WuFrom: "Vanderson M. do Rosario" <[email protected]>
Adding tb_stats [start|stop|status] command to hmp. This allows controlling the collection of statistics. It is also possible to set the flag of collection:
all, jit, or exec.
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.
Message-Id: <[email protected]>
Message-Id: <[email protected]>
--- accel/tcg/monitor.c | 98 +++++++++++++++++++++++++++++++++++ accel/tcg/tb-stats.c | 17 ++++++ hmp-commands.hx | 16 ++++++ include/exec/tb-stats-flags.h | 1 + include/exec/tb-stats.h | 4 ++ include/monitor/hmp.h | 1 + 6 files changed, 137 insertions(+)
accel/tcg/monitor.c +98 -0
@@ -11,14 +11,19 @@#include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" +#include "qapi/qmp/qdict.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" #include "exec/tb-stats.h" +#include "exec/tb-flush.h" #include "internal.h" +#include "tb-context.h" +enum TbstatsCmd {TBS_CMD_START ,TBS_CMD_STOP ,TBS_CMD_STATUS };static void dump_drift_info (GString *buf) {
@@ -87,6 +92,99 @@ HumanReadableText *qmp_x_query_opcount(Error **errp)return human_readable_text_from_str (buf); } +struct TbstatsCommand { +enum TbstatsCmd cmd; +uint32_t flag; +Monitor *mon; +}; + +static void do_hmp_tbstats_safe (CPUState *cpu,run_on_cpu_data icmd) +{ +struct TbstatsCommand *cmdinfo = icmd.host_ptr; +int cmd = cmdinfo->cmd; +uint32_t flag = cmdinfo->flag; +Monitor *mon = cmdinfo->mon; + +switch (cmd) { +case TBS_CMD_START : +if (tb_stats_collection_enabled ()) { +monitor_printf (mon,"TB information already being recorded\n" ); +break ; + } + +set_tbstats_flag (flag); +enable_collect_tb_stats (); +tb_flush (cpu); +break ; +case TBS_CMD_STOP : +if (tb_stats_collection_disabled ()) { +monitor_printf (mon,"TB information not being recorded\n" ); +break ; + } + +/* Dissalloc all TBStatistics structures and stop creating new ones */ +disable_collect_tb_stats (); +clean_tbstats (); +tb_flush (cpu); +break ; +case TBS_CMD_STATUS : +if (tb_stats_collection_enabled ()) { +uint32_t flag =get_tbstats_flag (); +monitor_printf (mon,"tb_stats is enabled with flag:\n" ); +monitor_printf (mon," EXEC: %d\n" , !!(flag &TB_EXEC_STATS )); +monitor_printf (mon," JIT: %d\n" , !!(flag &TB_JIT_STATS )); + }else { +monitor_printf (mon,"tb_stats is disabled\n" ); + } +break ; +default :/* INVALID */ +g_assert_not_reached (); +break ; + } + +g_free (cmdinfo); +} + +void hmp_tbstats (Monitor *mon,const QDict *qdict) +{ +if (!tcg_enabled ()) { +monitor_printf (mon,"Only available with accel=tcg\n" ); +return ; + } + +char *cmd = (char *)qdict_get_try_str (qdict,"command" ); +enum TbstatsCmd icmd =-1 ; + +if (strcmp (cmd,"start" ) ==0 ) { + icmd =TBS_CMD_START ; + }else if (strcmp (cmd,"stop" ) ==0 ) { + icmd =TBS_CMD_STOP ; + }else if (strcmp (cmd,"status" ) ==0 ) { + icmd =TBS_CMD_STATUS ; + }else { +monitor_printf (mon,"Invalid command\n" ); +return ; + } + +char *sflag = (char *)qdict_get_try_str (qdict,"flag" ); +uint32_t flag =TB_EXEC_STATS |TB_JIT_STATS ; +if (sflag) { +if (strcmp (sflag,"jit" ) ==0 ) { + flag =TB_JIT_STATS ; + }else if (strcmp (sflag,"exec" ) ==0 ) { + flag =TB_EXEC_STATS ; + } + } + + struct TbstatsCommand *tbscommand = g_new0(struct TbstatsCommand, 1); + tbscommand->cmd = icmd; + tbscommand->flag = flag; + tbscommand->mon = mon; +async_safe_run_on_cpu (first_cpu, do_hmp_tbstats_safe, +RUN_ON_CPU_HOST_PTR (tbscommand)); + +} +static void hmp_tcg_register (void ) {monitor_register_hmp_info_hrt ("jit" , qmp_x_query_jit);
accel/tcg/tb-stats.c +17 -0
@@ -91,6 +91,18 @@ void dump_jit_profile_info(GString *buf)g_free (jpi); } +static void free_tbstats (void *p,uint32_t hash,void *userp) +{ +g_free (p); +} + +void clean_tbstats (void ) +{ +/* remove all tb_stats */ +qht_iter (&tb_ctx.tb_stats, free_tbstats,NULL ); +qht_destroy (&tb_ctx.tb_stats); +} +void init_tb_stats_htable (void ) {if (!tb_ctx.tb_stats.map &&tb_stats_collection_enabled ()) {
@@ -115,6 +127,11 @@ bool tb_stats_collection_enabled(void)return tcg_collect_tb_stats ==TB_STATS_RUNNING ; } +bool tb_stats_collection_disabled (void ) +{ +return tcg_collect_tb_stats ==TB_STATS_STOPPED ; +} +uint32_t get_tbstats_flag (void ) {return tbstats_flag;
hmp-commands.hx +16 -0
@@ -1670,6 +1670,22 @@ SRST Executes a qemu-io command on the given block device. ERST +#if defined(CONFIG_TCG) + { + .name = "tb_stats", + .args_type = "command:s,flag:s?", + .params = "command [flag]", + .help = "Control tb statistics collection:" + "tb_stats (start|stop|status) [all|jit|exec]", + .cmd = hmp_tbstats, + }, +#endif + +SRST +``tb_stats`` *command* *flag* + Control recording tb statistics +ERST + { .name = "qom-list", .args_type = "path:s?",
include/exec/tb-stats-flags.h +1 -0
@@ -19,6 +19,7 @@void enable_collect_tb_stats (void );void disable_collect_tb_stats (void );bool tb_stats_collection_enabled (void ); +bool tb_stats_collection_disabled (void );uint32_t get_tbstats_flag (void );void set_tbstats_flag (uint32_t flag);
include/exec/tb-stats.h +4 -0
@@ -31,6 +31,8 @@#include "exec/tb-stats-flags.h" #include "tcg/tcg.h" +enum SortBy {SORT_BY_HOTNESS ,SORT_BY_HG /* Host/Guest */ ,SORT_BY_SPILLS }; +typedef struct TBStatistics TBStatistics ;/*
@@ -90,4 +92,6 @@ bool tb_stats_enabled(TranslationBlock *tb, uint32_t flag);void dump_jit_profile_info (GString *buf); +void clean_tbstats (void ); +#endif
include/monitor/hmp.h +1 -0
@@ -181,5 +181,6 @@ void hmp_ioport_write(Monitor *mon, const QDict *qdict);void hmp_boot_set (Monitor *mon,const QDict *qdict);void hmp_info_mtree (Monitor *mon,const QDict *qdict);void hmp_info_cryptodev (Monitor *mon,const QDict *qdict); +void hmp_tbstats (Monitor *mon,const QDict *qdict);#endif
Signature · 1 line
2.25.1
PATCH v16 5/9 tb-stats: reset the tracked TBs on a tb_flush
In reply to Fei WuFrom: Alex Bennée <[email protected]>
We keep track of translations but can only do so up until the translation cache is flushed. At that point we really have no idea if we can re-create a translation because all the active tracking information has been reset.
--- accel/tcg/tb-maint.c | 1 + accel/tcg/tb-stats.c | 18 ++++++++++++++++++ include/exec/tb-stats.h | 8 ++++++++ 3 files changed, 27 insertions(+)
accel/tcg/tb-maint.c +1 -0
@@ -762,6 +762,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)qht_reset_size (&tb_ctx.htable,CODE_GEN_HTABLE_SIZE );tb_remove_all (); +tbstats_reset_tbs ();tcg_region_reset_all ();/* XXX: flush processor icache at this point if cache flush is expensive */ qatomic_inc (&tb_ctx.tb_flush_count);
accel/tcg/tb-stats.c +18 -0
@@ -103,6 +103,24 @@ void clean_tbstats(void)qht_destroy (&tb_ctx.tb_stats); } +/* +* We have to reset the tbs array on a tb_flush as those +* TranslationBlocks no longer exist. +*/ + +static void reset_tbs_array (void *p,uint32_t hash,void *userp) +{ +TBStatistics *tbs = p; +g_ptr_array_set_size (tbs->tbs,0 ); +} + +void tbstats_reset_tbs (void ) +{ +if (tb_ctx.tb_stats.map) { +qht_iter (&tb_ctx.tb_stats, reset_tbs_array,NULL ); + } +} +void init_tb_stats_htable (void ) {if (!tb_ctx.tb_stats.map &&tb_stats_collection_enabled ()) {
include/exec/tb-stats.h +8 -0
@@ -94,4 +94,12 @@ void dump_jit_profile_info(GString *buf);void clean_tbstats (void ); +/** +* tbstats_reset_tbs: reset the linked array of TBs +* +* Reset the list of tbs for a given array. Should be called from +* safe work during tb_flush. +*/ +void tbstats_reset_tbs (void ); +#endif
Signature · 1 line
2.25.1
PATCH v16 6/9 tb-stats: Adding info [tb-list|tb] commands to HMP
In reply to Fei WuFrom: "Vanderson M. do Rosario" <[email protected]>
These commands allow the exploration of TBs generated by the TCG. Understand which one hotter, with more guest/host instructions... and examine their guest code.
The goal of this command is to allow the dynamic exploration of TCG behavior and code quality. Therefore, for now, a corresponding QMP command is not worthwhile.
Example of output:
------------------------------
TB id:0 | phys:0xa21f562e virt:0x0000000000000000 flags:0x00028010 0 inv/1
| exec:6171503732/0 guest inst cov:94.77%
| trans:1 ints: g:8 op:28 op_opt:24 spills:0
| h/g (host bytes / guest insts): 37.0000000xa21f562e: 00002797 auipc a5,8192 # 0xa21f762e 0xa21f5632: a2278793 addi a5,a5,-1502 0xa21f5636: 639c ld a5,0(a5) 0xa21f5638: 00178713 addi a4,a5,1 0xa21f563c: 00002797 auipc a5,8192 # 0xa21f763c 0xa21f5640: a1478793 addi a5,a5,-1516 0xa21f5644: e398 sd a4,0(a5) 0xa21f5646: b7e5 j -24 # 0xa21f562e
------------------------------
Message-Id: <[email protected]>
--- accel/tcg/monitor.c | 112 ++++++++++++++++++++++++ accel/tcg/tb-stats.c | 177 ++++++++++++++++++++++++++++++++++++++ disas/disas-mon.c | 15 +++- disas/disas.c | 2 + hmp-commands-info.hx | 16 ++++ include/disas/disas.h | 8 +- include/exec/tb-stats.h | 25 ++++++ include/monitor/hmp.h | 2 + monitor/hmp-cmds-target.c | 3 +- 9 files changed, 356 insertions(+), 4 deletions(-)
accel/tcg/monitor.c +112 -0
@@ -8,18 +8,22 @@#include "qemu/osdep.h" #include "qemu/accel.h" +#include "qemu/log.h" #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qmp/qdict.h" #include "monitor/monitor.h" #include "monitor/hmp.h" +#include "monitor/hmp-target.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" #include "exec/tb-stats.h" #include "exec/tb-flush.h" +#include "disas/disas.h" +#include "tb-context.h" #include "internal.h" #include "tb-context.h"
@@ -185,6 +189,114 @@ void hmp_tbstats(Monitor *mon, const QDict *qdict) } +struct tblist_dump_info { +int count; +int sortedby; +Monitor *mon; +}; + +static void do_dump_tblist_info_safe (CPUState *cpu,run_on_cpu_data info) +{ +struct tblist_dump_info *tbdi = info.host_ptr; +g_autoptr (GString) buf =g_string_new ("" ); + +dump_tblist_info (buf, tbdi->count, tbdi->sortedby); +monitor_printf (tbdi->mon,"%s" , buf->str); + +g_free (tbdi); +} + +void hmp_info_tblist (Monitor *mon,const QDict *qdict) +{ +int number_int; +const char *sortedby_str =NULL ; + +if (!tcg_enabled ()) { +monitor_printf (mon,"Only available with accel=tcg\n" ); +return ; + } +if (!tb_ctx.tb_stats.map) { +monitor_printf (mon,"no TB information recorded\n" ); +return ; + } + + number_int =qdict_get_try_int (qdict,"number" ,10 ); + sortedby_str =qdict_get_try_str (qdict,"sortedby" ); + +int sortedby =SORT_BY_HOTNESS ; +if (sortedby_str ==NULL ||strcmp (sortedby_str,"hotness" ) ==0 ) { + sortedby =SORT_BY_HOTNESS ; + }else if (strcmp (sortedby_str,"hg" ) ==0 ) { + sortedby =SORT_BY_HG ; + }else if (strcmp (sortedby_str,"spills" ) ==0 ) { + sortedby =SORT_BY_SPILLS ; + }else { +monitor_printf (mon,"valid sort options are: hotness hg spills\n" ); +return ; + } + + struct tblist_dump_info *tbdi = g_new(struct tblist_dump_info, 1); + tbdi->count = number_int; + tbdi->sortedby = sortedby; + tbdi->mon = mon; +async_safe_run_on_cpu (first_cpu, do_dump_tblist_info_safe, +RUN_ON_CPU_HOST_PTR (tbdi)); +} + +struct tb_dump_info { +int id; +Monitor *mon; +}; + +static void do_dump_tb_info_safe (CPUState *cpu,run_on_cpu_data info) +{ +struct tb_dump_info *tbdi = info.host_ptr; +int id = tbdi->id; +Monitor *mon = tbdi->mon; +g_autoptr (GString) buf =g_string_new ("" ); + +TBStatistics *tbs =get_tbstats_by_id (id); +if (tbs ==NULL ) { +monitor_printf (mon,"TB %d information is not recorded\n" , id); +return ; + } + +monitor_printf (mon,"\n------------------------------\n\n" ); + +int valid_tb_num =dump_tb_info (buf, tbs, id); +monitor_printf (mon,"%s" , buf->str); + +if (valid_tb_num >0 ) { +for (int i = tbs->tbs->len -1 ; i >=0 ; --i) { +TranslationBlock *tb =g_ptr_array_index (tbs->tbs, i); +if (!(tb->cflags &CF_INVALID )) { +monitor_disas (mon,mon_get_cpu (mon), tbs->phys_pc, tb->icount, +DISAS_GRA ); +break ; + } + } + } +monitor_printf (mon,"\n------------------------------\n\n" ); + +g_free (tbdi); +} + +void hmp_info_tb (Monitor *mon,const QDict *qdict) +{ +const int id =qdict_get_int (qdict,"id" ); + +if (!tcg_enabled ()) { +monitor_printf (mon,"Only available with accel=tcg\n" ); +return ; + } + + struct tb_dump_info *tbdi = g_new(struct tb_dump_info, 1); + tbdi->id = id; + tbdi->mon = mon; +async_safe_run_on_cpu (first_cpu, do_dump_tb_info_safe, +RUN_ON_CPU_HOST_PTR (tbdi)); +} +static void hmp_tcg_register (void ) {monitor_register_hmp_info_hrt ("jit" , qmp_x_query_jit);
accel/tcg/tb-stats.c +177 -0
216 lines not on this page · raw message
disas/disas-mon.c +13 -2
@@ -23,9 +23,18 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,return res ==MEMTX_OK ?0 :EIO ; } +static int +ram_addr_read_memory (bfd_vma memaddr,bfd_byte *myaddr,int length, +struct disassemble_info *info) +{ +void *p =qemu_map_ram_ptr (0 , memaddr); +memcpy (myaddr, p, length); +return 0 ; +} +/* Disassembler for the monitor. */ void monitor_disas (Monitor *mon,CPUState *cpu,uint64_t pc, -int nb_insn,bool is_physical) +int nb_insn,int addr_kind) {int count, i;CPUDebug s;
@@ -35,8 +44,10 @@ void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc, s.info.fprintf_func = disas_gstring_printf; s.info.stream = (FILE *)ds;/* abuse this slot */ -if (is_physical) { +if (addr_kind ==DISAS_GPA ) { s.info.read_memory_func = physical_read_memory; + }else if (addr_kind ==DISAS_GRA ) { + s.info.read_memory_func = ram_addr_read_memory; } s.info.buffer_vma = pc;
disas/disas.c +2 -0
@@ -8,6 +8,8 @@#include "hw/core/cpu.h" #include "exec/memory.h" +#include "qemu/log-for-trace.h" +/* Filled in by elfload.c. Simplistic, but will do for now. */ struct syminfo *syminfos =NULL ;
hmp-commands-info.hx +16 -0
@@ -262,6 +262,22 @@ ERST .params = "", .help = "show dynamic compiler info", }, + { + .name = "tb-list", + .args_type = "number:i?,sortedby:s?", + .params = "[number sortedby]", + .help = "show a [number] translated blocks sorted by [sortedby]" + "sortedby opts: hotness hg spills", + .cmd = hmp_info_tblist, + }, + { + .name = "tb", + .args_type = "id:i,flags:s?", + .params = "id [flag1,flag2,...]", + .help = "show information about one translated block by id." + "dump flags can be used to set dump code level: out_asm in_asm op", + .cmd = hmp_info_tb, + }, #endif SRST
include/disas/disas.h +7 -1
@@ -1,12 +1,18 @@#ifndef QEMU_DISAS_H #define QEMU_DISAS_H +enum { +DISAS_GVA =0 , +DISAS_GPA , +DISAS_GRA ,/* guest ram addr */ +}; +/* Disassemble this for me please... (debugging). */ void disas (FILE *out,const void *code,size_t size);void target_disas (FILE *out,CPUState *cpu,uint64_t code,size_t size);void monitor_disas (Monitor *mon,CPUState *cpu,uint64_t pc, -int nb_insn,bool is_physical); +int nb_insn,int addr_kind);char *plugin_disas (CPUState *cpu,uint64_t addr,size_t size);
include/exec/tb-stats.h +25 -0
@@ -54,6 +54,8 @@ struct TBStatistics {struct {unsigned long normal;unsigned long atomic; +/* filled only when dumping x% cover set */ +uint16_t coverage; } executions;/* JIT Stats - protected by lock */
@@ -89,6 +91,7 @@ bool tb_stats_cmp(const void *ap, const void *bp);void init_tb_stats_htable (void );bool tb_stats_enabled (TranslationBlock *tb,uint32_t flag); +bool tbs_stats_enabled (struct TBStatistics *tbs,uint32_t flag);void dump_jit_profile_info (GString *buf);
@@ -102,4 +105,26 @@ void clean_tbstats(void);*/ void tbstats_reset_tbs (void ); +/** +* dump_tbs_info: report the hottest blocks +* +* @buf: output buffer +* @total: the limit of hotblocks +* @sort_by: property in which the dump will be sorted +* +* Report the hottest blocks to either the log or monitor +*/ +void dump_tblist_info (GString *buf,int total,int sort_by); + +/** +* dump_tb_info: dump information about one TB +* +* @buf: output buffer +* @tbs: the tbs to dump +* @id: the display id of the block (from previous search) +*/ +int dump_tb_info (GString *buf,TBStatistics *tbs,int id); + +TBStatistics *get_tbstats_by_id (int id); +#endif
include/monitor/hmp.h +2 -0
@@ -182,5 +182,7 @@ void hmp_boot_set(Monitor *mon, const QDict *qdict);void hmp_info_mtree (Monitor *mon,const QDict *qdict);void hmp_info_cryptodev (Monitor *mon,const QDict *qdict);void hmp_tbstats (Monitor *mon,const QDict *qdict); +void hmp_info_tblist (Monitor *mon,const QDict *qdict); +void hmp_info_tb (Monitor *mon,const QDict *qdict);#endif
monitor/hmp-cmds-target.c +2 -1
@@ -133,7 +133,8 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, }if (format =='i' ) { -monitor_disas (mon, cs, addr, count, is_physical); +monitor_disas (mon, cs, addr, count, + is_physical ?DISAS_GPA :DISAS_GVA );return ; }
Signature · 1 line
2.25.1
PATCH v16 7/9 debug: add -d tb_stats to control TBStatistics
In reply to Fei WuCapture TBS at startup instead of an explicit 'tb_stats start' command.
--- include/exec/tb-stats-flags.h | 1 + include/qemu/log.h | 1 + stubs/meson.build | 1 + stubs/tb-stats.c | 32 ++++++++++++++++++++++++++++++++ util/log.c | 18 ++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 stubs/tb-stats.c
include/exec/tb-stats-flags.h +1 -0
@@ -14,6 +14,7 @@#define TB_NONE_STATS (0)/* no stats */ #define TB_EXEC_STATS (1 << 0)#define TB_JIT_STATS (1 << 1) +#define TB_ALL_STATS (TB_EXEC_STATS | TB_JIT_STATS)/* TBStatistic collection controls */ void enable_collect_tb_stats (void );
include/qemu/log.h +1 -0
@@ -36,6 +36,7 @@ bool qemu_log_separate(void);#define LOG_STRACE (1 << 19)#define LOG_PER_THREAD (1 << 20)#define CPU_LOG_TB_VPU (1 << 21) +#define CPU_LOG_TB_STATS (1 << 22)/* Lock/unlock output. */
stubs/meson.build +1 -0
@@ -65,3 +65,4 @@ else endif stub_ss.add(files('semihost-all.c')) stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) +stub_ss.add(files('tb-stats.c'))
stubs/tb-stats.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* TB Stats Stubs +* +* Copyright (c) 2019 +* Written by Alex Bennée <[email protected]> +* +* This code is licensed under the GNU GPL v2, or later. +*/ + + +#include "qemu/osdep.h" +#include "exec/tb-stats-flags.h" + +void enable_collect_tb_stats (void ) +{ +return ; +} + +void disable_collect_tb_stats (void ) +{ +return ; +} + +bool tb_stats_collection_enabled (void ) +{ +return false; +} + +void set_tbstats_flag (uint32_t flag) +{ +return ; +}
util/log.c +18 -0
@@ -27,6 +27,7 @@#include "qemu/thread.h" #include "qemu/lockable.h" #include "qemu/rcu.h" +#include "exec/tb-stats-flags.h" #ifdef CONFIG_LINUX #include <sys/syscall.h> #endif
@@ -497,6 +498,8 @@ const QEMULogItem qemu_log_items[] = { "open a separate log file per thread; filename must contain '%d'" }, {CPU_LOG_TB_VPU ,"vpu" , "include VPU registers in the 'cpu' logging" }, + { CPU_LOG_TB_STATS, "tb_stats_{all,jit,exec}", + "enable collection of TBs statistics at startup" }, { 0, NULL, NULL }, };
@@ -518,6 +521,21 @@ 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_" )) { +char *p = *tmp +9 ; +uint32_t flag =TB_NONE_STATS ; +if (g_str_has_prefix (p,"all" )) { + flag =TB_ALL_STATS ; + }else if (g_str_has_prefix (p,"jit" )) { + flag =TB_JIT_STATS ; + }else if (g_str_has_prefix (p,"exec" )) { + flag =TB_EXEC_STATS ; + } +if (flag !=TB_NONE_STATS ) { + mask |=CPU_LOG_TB_STATS ; +set_tbstats_flag (flag); +enable_collect_tb_stats (); + } }else {for (item = qemu_log_items; item->mask !=0 ; item++) {if (g_str_equal (*tmp, item->name)) {
Signature · 1 line
2.25.1
PATCH v16 8/9 tb-stats: dump hot TBs at the end of the execution
In reply to Fei WuDump the hottest TBs if -d tb_stats_{all,jit,exec}[:dump_num_at_exit]
--- accel/tcg/tb-stats.c | 21 +++++++++++++++++++++ include/exec/tb-stats-dump.h | 21 +++++++++++++++++++++ include/exec/tb-stats-flags.h | 1 + linux-user/exit.c | 2 ++ softmmu/runstate.c | 2 ++ stubs/tb-stats.c | 4 ++++ util/log.c | 12 ++++++++++-- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 include/exec/tb-stats-dump.h
accel/tcg/tb-stats.c +21 -0
@@ -17,6 +17,7 @@#include "qemu/log.h" #include "exec/tb-stats.h" +#include "exec/tb-stats-dump.h" #include "tb-context.h" #include "internal.h"
@@ -29,6 +30,7 @@ enum TBStatsStatus {static enum TBStatsStatus tcg_collect_tb_stats;static uint32_t tbstats_flag; +static int max_dump_tbs;static GPtrArray *last_search;
@@ -300,6 +302,20 @@ void dump_tblist_info(GString *buf, int total, int sort_by) } } +/* +* Dump the final stats +*/ +void tb_stats_dump (void ) +{ +if (!tb_stats_collection_enabled ()) { +return ; + } + +g_autoptr (GString) buf =g_string_new ("" ); +dump_tblist_info (buf, max_dump_tbs,SORT_BY_HOTNESS ); +qemu_printf ("%s" , buf->str); +} +void enable_collect_tb_stats (void ) { tcg_collect_tb_stats =TB_STATS_RUNNING ;
@@ -343,3 +359,8 @@ bool tbs_stats_enabled(struct TBStatistics *tbs, uint32_t flag)return tb_stats_collection_enabled () && (tbstats_flag & flag); } + +void set_tbstats_max_tbs (int max) +{ + max_dump_tbs = max; +}
include/exec/tb-stats-dump.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* TB Stats common dump functions across sysemu/linux-user +* +* Copyright (c) 2019 Linaro +* +* SPDX-License-Identifier: GPL-3.0-or-later +*/ + +#ifndef _TB_STATS_DUMP_H_ +#define _TB_STATS_DUMP_H_ + +/** +* tb_stats_dump: dump final tb_stats at end of execution +*/ +#ifdef CONFIG_TCG +void tb_stats_dump (void ); +#else +static inline void tb_stats_dump (void ) {/* do nothing */ }; +#endif + +#endif /* _TB_STATS_DUMP_H_ */
include/exec/tb-stats-flags.h +1 -0
@@ -24,5 +24,6 @@ bool tb_stats_collection_disabled(void);uint32_t get_tbstats_flag (void );void set_tbstats_flag (uint32_t flag); +void set_tbstats_max_tbs (int max);#endif
linux-user/exit.c +2 -0
@@ -25,6 +25,7 @@#ifdef CONFIG_GPROF #include <sys/gmon.h> #endif +#include "exec/tb-stats-dump.h" #ifdef CONFIG_GCOV extern void __gcov_dump (void );
@@ -41,4 +42,5 @@ void preexit_cleanup(CPUArchState *env, int code)gdb_exit (code);qemu_plugin_user_exit ();perf_exit (); +tb_stats_dump (); }
softmmu/runstate.c +2 -0
@@ -30,6 +30,7 @@#include "crypto/cipher.h" #include "crypto/init.h" #include "exec/cpu-common.h" +#include "exec/tb-stats-dump.h" #include "gdbstub/syscalls.h" #include "hw/boards.h" #include "migration/misc.h"
@@ -817,6 +818,7 @@ void qemu_cleanup(void)vm_shutdown ();replay_finish (); +tb_stats_dump ();job_cancel_sync_all ();bdrv_close_all ();
stubs/tb-stats.c +4 -0
@@ -30,3 +30,7 @@ void set_tbstats_flag(uint32_t flag) {return ; } + +void set_tbstats_max_tbs (int max) { +return ; +}
util/log.c +10 -2
@@ -498,8 +498,9 @@ const QEMULogItem qemu_log_items[] = { "open a separate log file per thread; filename must contain '%d'" }, {CPU_LOG_TB_VPU ,"vpu" , "include VPU registers in the 'cpu' logging" }, - { CPU_LOG_TB_STATS, "tb_stats_{all,jit,exec}", - "enable collection of TBs statistics at startup" }, + { CPU_LOG_TB_STATS, "tb_stats_{all,jit,exec}[:dump_num_at_exit]", +"enable collection of TBs statistics at startup " + "and dump at exit until given a limit" }, { 0, NULL, NULL }, };
@@ -526,16 +527,23 @@ int qemu_str_to_log_mask(const char *str)uint32_t flag =TB_NONE_STATS ;if (g_str_has_prefix (p,"all" )) { flag =TB_ALL_STATS ; + p +=3 ; }else if (g_str_has_prefix (p,"jit" )) { flag =TB_JIT_STATS ; + p +=3 ; }else if (g_str_has_prefix (p,"exec" )) { flag =TB_EXEC_STATS ; + p +=4 ; }if (flag !=TB_NONE_STATS ) { mask |=CPU_LOG_TB_STATS ;set_tbstats_flag (flag);enable_collect_tb_stats (); } +if (p[0 ] ==':' ) { +int max_to_dump =atoi (p +1 ); +set_tbstats_max_tbs (max_to_dump); + } }else {for (item = qemu_log_items; item->mask !=0 ; item++) {if (g_str_equal (*tmp, item->name)) {
Signature · 1 line
2.25.1
PATCH v16 9/9 docs: add tb-stats how to
In reply to Fei Wu--- docs/devel/index-tcg.rst | 1 + docs/devel/tcg-tbstats.rst | 126 +++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 docs/devel/tcg-tbstats.rst
docs/devel/index-tcg.rst +1 -0
@@ -14,4 +14,5 @@ are only implementing things for HW accelerated hypervisors. multi-thread-tcg tcg-icount tcg-plugins + tcg-tbstats replay
docs/devel/tcg-tbstats.rst new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 5 lines · Fei Wu
v16
--
* rebase to latest commit4329d049d(Jun 26)
* original patch 1 (removeCONFIG_PROFILER) has already upstreamed so is removed from here
Hi Richard,
As CONFIG_PROFILER has been removed in upstream, could you please take a look again at this revision?
Thanks,
Fei.
Quoted 62 lines
* add
async_safe_run_on_cpuback for info tb-list/tb
* addram_addrsupport tomonitor_disasand use it to disassemble guest code
* update the commit logs and documents
* small change todo_hmp_tbstats_safe()to avoid memory leakingAlex Bennée (1):
tb-stats: reset the tracked TBs on atb_flushFei Wu (4):
accel/tcg: add jit stats to TBStatistics
debug: add -dtb_statsto control TBStatistics
tb-stats: dump hot TBs at the end of the execution
docs: add tb-stats how toVanderson M. do Rosario (4):
accel/tcg: introduce TBStatistics structure
accel: collecting TB execution count
monitor: addingtb_statshmp command
tb-stats: Adding info [tb-list|tb] commands to HMPMAINTAINERS | 1 + accel/tcg/cpu-exec.c | 6 + accel/tcg/meson.build | 1 + accel/tcg/monitor.c | 216 ++++++++++++++++++ accel/tcg/tb-context.h | 1 + accel/tcg/tb-hash.h | 7 + accel/tcg/tb-maint.c | 20 ++ accel/tcg/tb-stats.c | 366 +++++++++++++++++++++++++++++++ accel/tcg/tcg-runtime.c | 1 + accel/tcg/translate-all.c | 77 ++++++- accel/tcg/translator.c | 31 +++ disas/disas-mon.c | 15 +- disas/disas.c | 2 + docs/devel/index-tcg.rst | 1 + docs/devel/tcg-tbstats.rst | 126 +++++++++++ hmp-commands-info.hx | 16 ++ hmp-commands.hx | 16 ++ include/disas/disas.h | 8 +- include/exec/tb-stats-dump.h | 21 ++ include/exec/tb-stats-flags.h | 29 +++ include/exec/tb-stats.h | 130 +++++++++++ include/exec/translation-block.h | 3 + include/monitor/hmp.h | 3 + include/qemu/log.h | 1 + include/tcg/tcg-temp-internal.h | 2 + include/tcg/tcg.h | 10 + linux-user/exit.c | 2 + monitor/hmp-cmds-target.c | 3 +- softmmu/runstate.c | 2 + stubs/meson.build | 1 + stubs/tb-stats.c | 36 +++ tcg/tcg.c | 47 +++- util/log.c | 26 +++ 33 files changed, 1217 insertions(+), 10 deletions(-) create mode 100644 accel/tcg/tb-stats.c create mode 100644 docs/devel/tcg-tbstats.rst create mode 100644 include/exec/tb-stats-dump.h create mode 100644 include/exec/tb-stats-flags.h create mode 100644 include/exec/tb-stats.h create mode 100644 stubs/tb-stats.c