accel/system: Add 'info accel' on human monitor
v5 cover accel/system: Add 'info accel' on human monitor
Missing review: #1 and #5
Philippe Mathieu-Daudé (7):
Revert "accel/tcg: Unregister the RCU before exiting RR thread" accel/tcg: Extract statistic related code to tcg-stats.c accel/system: Introduce @x-accel-stats QMP command accel/system: Add 'info accel' on human monitor accel/tcg: Propagate AccelState to tcg_dump_stats() accel/tcg: Implement get_[vcpu]_stats()
accel/hvf: Implement get_vcpu_stats()
qapi/accelerator.json | 17 +++ accel/tcg/internal-common.h | 2 +- include/accel/accel-cpu-ops.h | 3 + include/accel/accel-ops.h | 2 + accel/accel-qmp.c | 35 ++++++ accel/accel-system.c | 9 ++ accel/hvf/hvf-accel-ops.c | 24 ++++ accel/tcg/monitor.c | 202 +------------------------------- accel/tcg/tcg-accel-ops-rr.c | 2 - accel/tcg/tcg-all.c | 6 + accel/tcg/tcg-stats.c | 214 ++++++++++++++++++++++++++++++++++ accel/meson.build | 2 +- accel/tcg/meson.build | 1 + hmp-commands-info.hx | 12 ++ 14 files changed, 326 insertions(+), 205 deletions(-) create mode 100644 accel/accel-qmp.c create mode 100644 accel/tcg/tcg-stats.c
Signature · 1 line
2.49.0
PATCH v5 1/7 Revert "accel/tcg: Unregister the RCU before exiting RR thread"
This reverts commit bc93332fe460211c2d2f4ff50e1a0e030c7b5159, which was merged prematurely, re-introducing Coverity CID 1547782 (unreachable code).
--- accel/tcg/tcg-accel-ops-rr.c | 2 -- 1 file changed, 2 deletions(-)
accel/tcg/tcg-accel-ops-rr.c +0 -2
@@ -302,8 +302,6 @@ static void *rr_cpu_thread_fn(void *arg)rr_deal_with_unplugged_cpus (); } -rcu_unregister_thread (); -g_assert_not_reached (); }
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 v5 1/7] Revert "accel/tcg: Unregister the RCU before exiting RR thread"
Quoted 25 lines · Philippe Mathieu-Daudé
This reverts commit
bc93332fe460211c2d2f4ff50e1a0e030c7b5159, which was merged prematurely, re-introducing Coverity CID 1547782 (unreachable code).Reported-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/tcg-accel-ops-rr.c | 2 -- 1 file changed, 2 deletions(-)accel/tcg/tcg-accel-ops-rr.c +0
-3@@ -302,8 +302,6 @@ static void *rr_cpu_thread_fn(void *arg)rr_deal_with_unplugged_cpus (); } -rcu_unregister_thread (); -g_assert_not_reached (); } --
Quoted 2 lines
2.49.0
Re: [PATCH-for-10.1 v5 1/7] Revert "accel/tcg: Unregister the RCU before exiting RR thread"
In reply to Philippe Mathieu-DaudéQuoted 15 lines · Philippe Mathieu-Daudé
This reverts commit
bc93332fe460211c2d2f4ff50e1a0e030c7b5159, which was merged prematurely, re-introducing Coverity CID 1547782 (unreachable code).Reported-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/tcg-accel-ops-rr.c | 2 -- 1 file changed, 2 deletions(-)accel/tcg/tcg-accel-ops-rr.c +0
-0
accel/tcg/tcg-accel-ops-rr.c static void *rr_cpu_thread_fn(void *arg) · line 307
Quoted 8 lines
accel/tcg/tcg-accel-ops-rr.c +0
-2@@ -302,8 +302,6 @@ static void *rr_cpu_thread_fn(void *arg)rr_deal_with_unplugged_cpus (); } -rcu_unregister_thread (); -g_assert_not_reached (); }
r~
PATCH v5 2/7 accel/tcg: Extract statistic related code to tcg-stats.c
In reply to Philippe Mathieu-DaudéStatistic code is not specific to system emulation (except cross-page checks) and can be used to analyze user-mode binaries. Extract statistic related code to its own file: tcg-stats.c, keeping the original LGPL-2.1-or-later license tag.
--- accel/tcg/monitor.c | 201 --------------------------------------- accel/tcg/tcg-stats.c | 215 ++++++++++++++++++++++++++++++++++++++++++ accel/tcg/meson.build | 1 + 3 files changed, 216 insertions(+), 201 deletions(-) create mode 100644 accel/tcg/tcg-stats.c
accel/tcg/monitor.c +0 -201
@@ -7,213 +7,12 @@*/ #include "qemu/osdep.h" -#include "qemu/accel.h" -#include "qemu/qht.h" #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" #include "monitor/monitor.h" -#include "system/cpu-timers.h" -#include "exec/icount.h" #include "system/tcg.h" -#include "tcg/tcg.h" #include "internal-common.h" -#include "tb-context.h" -#include <math.h> - -static void dump_drift_info (GString *buf) -{ -if (!icount_enabled ()) { -return ; - } - -g_string_append_printf (buf,"Host - Guest clock %" PRIi64" ms\n" , - (cpu_get_clock () -icount_get ()) /SCALE_MS ); -if (icount_align_option) { -g_string_append_printf (buf,"Max guest delay %" PRIi64" ms\n" , - -max_delay /SCALE_MS ); -g_string_append_printf (buf,"Max guest advance %" PRIi64" ms\n" , - max_advance /SCALE_MS ); - }else { -g_string_append_printf (buf,"Max guest delay NA\n" ); -g_string_append_printf (buf,"Max guest advance NA\n" ); - } -} - -static void dump_accel_info (GString *buf) -{ -AccelState *accel =current_accel (); -bool one_insn_per_tb =object_property_get_bool (OBJECT (accel), -"one-insn-per-tb" , - &error_fatal); - -g_string_append_printf (buf,"Accelerator settings:\n" ); -g_string_append_printf (buf,"one-insn-per-tb: %s\n\n" , - one_insn_per_tb ?"on" :"off" ); -} - -static void print_qht_statistics (struct qht_stats hst,GString *buf) -{ -uint32_t hgram_opts; -size_t hgram_bins; -char *hgram; -double avg; - -if (!hst.head_buckets) { -return ; - } -g_string_append_printf (buf,"TB hash buckets %zu/%zu " -"(%0.2f%% head buckets used)\n" , - hst.used_head_buckets, hst.head_buckets, - (double )hst.used_head_buckets / - hst.head_buckets *100 ); - - hgram_opts =QDIST_PR_BORDER |QDIST_PR_LABELS ; - hgram_opts |=QDIST_PR_100X |QDIST_PR_PERCENT ; -if (qdist_xmax (&hst.occupancy) -qdist_xmin (&hst.occupancy) ==1 ) { - hgram_opts |=QDIST_PR_NODECIMAL ; - } - hgram =qdist_pr (&hst.occupancy,10 , hgram_opts); - avg =qdist_avg (&hst.occupancy); -if (!isnan (avg)) { -g_string_append_printf (buf,"TB hash occupancy " -"%0.2f%% avg chain occ. " -"Histogram: %s\n" , - avg *100 , hgram); - } -g_free (hgram); - - hgram_opts =QDIST_PR_BORDER |QDIST_PR_LABELS ; - hgram_bins =qdist_xmax (&hst.chain) -qdist_xmin (&hst.chain); -if (hgram_bins >10 ) { - hgram_bins =10 ; - }else { - hgram_bins =0 ; - hgram_opts |=QDIST_PR_NODECIMAL |QDIST_PR_NOBINRANGE ; - } - hgram =qdist_pr (&hst.chain, hgram_bins, hgram_opts); - avg =qdist_avg (&hst.chain); -if (!isnan (avg)) { -g_string_append_printf (buf,"TB hash avg chain %0.3f buckets. " -"Histogram: %s\n" , - avg, hgram); - } -g_free (hgram); -} - -struct tb_tree_stats { -size_t nb_tbs; -size_t host_size; -size_t target_size; -size_t max_target_size; -size_t direct_jmp_count; -size_t direct_jmp2_count; -size_t cross_page; -}; - -static gboolean tb_tree_stats_iter (gpointer key,gpointer value,gpointer data) -{ -const TranslationBlock *tb = value; -struct tb_tree_stats *tst = data; - - tst->nb_tbs++; - tst->host_size += tb->tc.size; - tst->target_size += tb->size; -if (tb->size > tst->max_target_size) { - tst->max_target_size = tb->size; - } -if (tb->page_addr[1 ] !=-1 ) { - tst->cross_page++; - } -if (tb->jmp_reset_offset[0 ] !=TB_JMP_OFFSET_INVALID ) { - tst->direct_jmp_count++; -if (tb->jmp_reset_offset[1 ] !=TB_JMP_OFFSET_INVALID ) { - tst->direct_jmp2_count++; - } - } -return false; -} - -static void tlb_flush_counts (size_t *pfull,size_t *ppart,size_t *pelide) -{ -CPUState *cpu; -size_t full =0 , part =0 , elide =0 ; - -CPU_FOREACH (cpu) { - full +=qatomic_read (&cpu->neg.tlb.c.full_flush_count); - part +=qatomic_read (&cpu->neg.tlb.c.part_flush_count); - elide +=qatomic_read (&cpu->neg.tlb.c.elide_flush_count); - } - *pfull = full; - *ppart = part; - *pelide = elide; -} - -static void tcg_dump_flush_info (GString *buf) -{ -size_t flush_full, flush_part, flush_elide; - -g_string_append_printf (buf,"TB flush count %u\n" , -qatomic_read (&tb_ctx.tb_flush_count)); -g_string_append_printf (buf,"TB invalidate count %u\n" , -qatomic_read (&tb_ctx.tb_phys_invalidate_count)); - -tlb_flush_counts (&flush_full, &flush_part, &flush_elide); -g_string_append_printf (buf,"TLB full flushes %zu\n" , flush_full); -g_string_append_printf (buf,"TLB partial flushes %zu\n" , flush_part); -g_string_append_printf (buf,"TLB elided flushes %zu\n" , flush_elide); -} - -static void dump_exec_info (GString *buf) -{ -struct tb_tree_stats tst = {}; -struct qht_stats hst; -size_t nb_tbs; - -tcg_tb_foreach (tb_tree_stats_iter, &tst); - nb_tbs = tst.nb_tbs; -/* XXX: avoid using doubles ? */ -g_string_append_printf (buf,"Translation buffer state:\n" ); -/* -* Report total code size including the padding and TB structs; -* otherwise users might think "-accel tcg,tb-size" is not honoured. -* For avg host size we use the precise numbers from tb_tree_stats though. -*/ -g_string_append_printf (buf,"gen code size %zu/%zu\n" , -tcg_code_size (),tcg_code_capacity ()); -g_string_append_printf (buf,"TB count %zu\n" , nb_tbs); -g_string_append_printf (buf,"TB avg target size %zu max=%zu bytes\n" , - nb_tbs ? tst.target_size / nb_tbs :0 , - tst.max_target_size); -g_string_append_printf (buf,"TB avg host size %zu bytes " -"(expansion ratio: %0.1f)\n" , - nb_tbs ? tst.host_size / nb_tbs :0 , - tst.target_size ? - (double )tst.host_size / tst.target_size :0 ); -g_string_append_printf (buf,"cross page TB count %zu (%zu%%)\n" , - tst.cross_page, - nb_tbs ? (tst.cross_page *100 ) / nb_tbs :0 ); -g_string_append_printf (buf,"direct jump count %zu (%zu%%) " -"(2 jumps=%zu %zu%%)\n" , - tst.direct_jmp_count, - nb_tbs ? (tst.direct_jmp_count *100 ) / nb_tbs :0 , - tst.direct_jmp2_count, - nb_tbs ? (tst.direct_jmp2_count *100 ) / nb_tbs :0 ); - -qht_statistics_init (&tb_ctx.htable, &hst); -print_qht_statistics (hst, buf); -qht_statistics_destroy (&hst); - -g_string_append_printf (buf,"\nStatistics:\n" ); -tcg_dump_flush_info (buf); -} - -void tcg_dump_stats (GString *buf) -{ -dump_accel_info (buf); -dump_exec_info (buf); -dump_drift_info (buf); -}HumanReadableText *qmp_x_query_jit (Error **errp) {
accel/tcg/tcg-stats.c new file +215 -0
215 lines not on this page · raw message
accel/tcg/meson.build +1 -0
@@ -11,6 +11,7 @@ tcg_ss.add(files( 'tcg-runtime-gvec.c', 'tb-maint.c', 'tcg-all.c', + 'tcg-stats.c', 'translate-all.c', 'translator.c', ))
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 v5 2/7] accel/tcg: Extract statistic related code to tcg-stats.c
Quoted 2 lines · Philippe Mathieu-Daudé
Statistic code is not specific to system emulation (except cross-page checks) and can be used to analyze user-mode binaries.
But it's not callable from user-mode. At least so far, and within this series. So, split out the new file if you like, but ...
accel/tcg/meson.build tcg_ss.add(files( · line 17
Quoted 12 lines
accel/tcg/meson.build +1
-0@@ -11,6 +11,7 @@ tcg_ss.add(files( 'tcg-runtime-gvec.c', 'tb-maint.c', 'tcg-all.c', + 'tcg-stats.c', 'translate-all.c', 'translator.c', ))
... leave it within system_ss.
r~
Re: [PATCH-for-10.1 v5 2/7] accel/tcg: Extract statistic related code to tcg-stats.c
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Statistic code is not specific to system emulation (except cross-page checks) and can be used to analyze user-mode binaries. Extract statistic related code to its own file:
tcg-stats.c, keeping the original LGPL-2.1-or-later license tag.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>Reviewed-by Zhao Liu<[email protected]>--- accel/tcg/monitor.c | 201 --------------------------------------- accel/tcg/tcg-stats.c | 215 ++++++++++++++++++++++++++++++++++++++++++ accel/tcg/meson.build | 1 + 3 files changed, 216 insertions(+), 201 deletions(-)create mode 100644
accel/tcg/tcg-stats.c
r~
PATCH v5 3/7 accel/system: Introduce @x-accel-stats QMP command
In reply to Philippe Mathieu-DaudéUnstable QMP 'x-accel-stats' dispatches to the AccelOpsClass::get_stats() and get_vcpu_stats() handlers.
--- qapi/accelerator.json | 17 +++++++++++++++++ include/accel/accel-cpu-ops.h | 3 +++ include/accel/accel-ops.h | 2 ++ accel/accel-qmp.c | 35 +++++++++++++++++++++++++++++++++++ accel/accel-system.c | 1 + accel/meson.build | 2 +- 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 accel/accel-qmp.c
qapi/accelerator.json +17 -0
@@ -37,3 +37,20 @@ # <- { "return": { "enabled": true, "present": true } } ## { 'command': 'query-kvm', 'returns': 'KvmInfo' } + +## +# @x-accel-stats: +# +# Query accelerator statistics +# +# Features: +# +# @unstable: This command is meant for debugging. +# +# Returns: accelerator statistics +# +# Since: 10.1 +## +{ 'command': 'x-accel-stats', + 'returns': 'HumanReadableText', + 'features': [ 'unstable' ] }
include/accel/accel-cpu-ops.h +3 -0
@@ -65,6 +65,9 @@ struct AccelOpsClass {/* handle_interrupt is mandatory. */ void (*handle_interrupt)(CPUState *cpu,int mask); +/* get_vcpu_stats: Append statistics of this @cpu to @buf */ +void (*get_vcpu_stats)(CPUState *cpu,GString *buf); +/** * @get_virtual_clock: fetch virtual clock * @set_virtual_clock: set virtual clock
include/accel/accel-ops.h +2 -0
@@ -25,6 +25,8 @@ struct AccelClass {int (*init_machine)(AccelState *as,MachineState *ms);bool (*cpu_common_realize)(CPUState *cpu,Error **errp);void (*cpu_common_unrealize)(CPUState *cpu); +/* get_stats: Append statistics to @buf */ +void (*get_stats)(AccelState *as,GString *buf);/* system related hooks */ void (*setup_post)(AccelState *as);
accel/accel-qmp.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* QMP commands related to accelerators +* +* Copyright (c) Linaro +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/accel.h" +#include "qapi/type-helpers.h" +#include "qapi/qapi-commands-accelerator.h" +#include "accel/accel-ops.h" +#include "accel/accel-cpu-ops.h" +#include "hw/core/cpu.h" + +HumanReadableText *qmp_x_accel_stats (Error **errp) +{ +AccelState *accel =current_accel (); +AccelClass *acc =ACCEL_GET_CLASS (accel); +g_autoptr (GString) buf =g_string_new ("" ); + +if (acc->get_stats) { + acc->get_stats (accel, buf); + } +if (acc->ops->get_vcpu_stats) { +CPUState *cpu; + +CPU_FOREACH (cpu) { + acc->ops->get_vcpu_stats (cpu, buf); + } + } + +return human_readable_text_from_str (buf); +}
accel/accel-system.c +1 -0
@@ -26,6 +26,7 @@#include "qemu/osdep.h" #include "qemu/accel.h" #include "hw/boards.h" +#include "hw/core/cpu.h" #include "accel/accel-ops.h" #include "accel/accel-cpu-ops.h" #include "system/cpus.h"
accel/meson.build +1 -1
@@ -1,6 +1,6 @@ common_ss.add(files('accel-common.c')) specific_ss.add(files('accel-target.c')) -system_ss.add(files('accel-system.c', 'accel-blocker.c')) +system_ss.add(files('accel-system.c', 'accel-blocker.c', 'accel-qmp.c')) user_ss.add(files('accel-user.c')) subdir('tcg')
Signature · 1 line
2.49.0
PATCH v5 4/7 accel/system: Add 'info accel' on human monitor
In reply to Philippe Mathieu-Daudé'info accel' dispatches to the AccelOpsClass::get_stats() and get_vcpu_stats() handlers.
--- accel/accel-system.c | 8 ++++++++ hmp-commands-info.hx | 12 ++++++++++++ 2 files changed, 20 insertions(+)
accel/accel-system.c +8 -0
@@ -25,6 +25,8 @@#include "qemu/osdep.h" #include "qemu/accel.h" +#include "qapi/qapi-commands-accelerator.h" +#include "monitor/monitor.h" #include "hw/boards.h" #include "hw/core/cpu.h" #include "accel/accel-ops.h"
@@ -103,11 +105,17 @@ void accel_init_ops_interfaces(AccelClass *ac)cpus_register_accel (ops); } +static void accel_ops_class_init (ObjectClass *oc,const void *data) +{ +monitor_register_hmp_info_hrt ("accel" , qmp_x_accel_stats); +} +static const TypeInfo accel_ops_type_info = { .name =TYPE_ACCEL_OPS , .parent =TYPE_OBJECT , .abstract = true, .class_size =sizeof (AccelOpsClass), + .class_init = accel_ops_class_init, };static void accel_system_register_types (void )
hmp-commands-info.hx +12 -0
@@ -267,6 +267,18 @@ ERST .cmd = hmp_info_sync_profile, }, + { + .name = "accel", + .args_type = "", + .params = "", + .help = "show accelerator info", + }, + +SRST + ``info accel`` + Show accelerator info. +ERST + SRST ``info sync-profile [-m|-n]`` [*max*] Show synchronization profiling info, up to *max* entries (default: 10),
Signature · 1 line
2.49.0
PATCH v5 5/7 accel/tcg: Propagate AccelState to tcg_dump_stats()
In reply to Philippe Mathieu-DaudéNext commit will register tcg_dump_stats() as AccelClass::get_stats handler. Since we want this handler to be called with the correct accelerator state, propagate it along.
--- accel/tcg/internal-common.h | 2 +- accel/tcg/monitor.c | 3 ++- accel/tcg/tcg-stats.c | 7 +++---- 3 files changed, 6 insertions(+), 6 deletions(-)
accel/tcg/internal-common.h +1 -1
@@ -139,6 +139,6 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr);void tb_set_jmp_target (TranslationBlock *tb,int n,uintptr_t addr); -void tcg_dump_stats (GString *buf); +void tcg_dump_stats (AccelState *accel,GString *buf);#endif
accel/tcg/monitor.c +2 -1
@@ -7,6 +7,7 @@*/ #include "qemu/osdep.h" +#include "qemu/accel.h" #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h"
@@ -23,7 +24,7 @@ HumanReadableText *qmp_x_query_jit(Error **errp)return NULL ; } -tcg_dump_stats (buf); +tcg_dump_stats (current_accel (), buf);return human_readable_text_from_str (buf); }
accel/tcg/tcg-stats.c +3 -4
@@ -37,9 +37,8 @@ static void dump_drift_info(GString *buf) } } -static void dump_accel_info (GString *buf) +static void dump_accel_info (AccelState *accel,GString *buf) { -AccelState *accel =current_accel ();bool one_insn_per_tb =object_property_get_bool (OBJECT (accel),"one-insn-per-tb" , &error_fatal);
@@ -207,9 +206,9 @@ static void dump_exec_info(GString *buf)tcg_dump_flush_info (buf); } -void tcg_dump_stats (GString *buf) +void tcg_dump_stats (AccelState *accel,GString *buf) { -dump_accel_info (buf); +dump_accel_info (accel, buf);dump_exec_info (buf);dump_drift_info (buf); }
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 v5 5/7] accel/tcg: Propagate AccelState to tcg_dump_stats()
Quoted 73 lines · Philippe Mathieu-Daudé
Next commit will register
tcg_dump_stats()asAccelClass::get_statshandler. Since we want this handler to be called with the correct accelerator state, propagate it along.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/internal-common.h | 2 +- accel/tcg/monitor.c | 3 ++- accel/tcg/tcg-stats.c | 7 +++---- 3 files changed, 6 insertions(+), 6 deletions(-)accel/tcg/internal-common.h +1
-1@@ -139,6 +139,6 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr);void tb_set_jmp_target (TranslationBlock *tb,int n,uintptr_t addr); -void tcg_dump_stats (GString *buf); +void tcg_dump_stats (AccelState *accel,GString *buf);#endif accel/tcg/monitor.c +2
-1@@ -7,6 +7,7 @@*/ #include "qemu/osdep.h" +#include "qemu/accel.h" #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" @@ -23,7 +24,7 @@ HumanReadableText *qmp_x_query_jit(Error **errp)return NULL ; } -tcg_dump_stats (buf); +tcg_dump_stats (current_accel (), buf);return human_readable_text_from_str (buf); }accel/tcg/tcg-stats.c +3
-5@@ -37,9 +37,8 @@ static void dump_drift_info(GString *buf) } } -static void dump_accel_info (GString *buf) +static void dump_accel_info (AccelState *accel,GString *buf) { -AccelState *accel =current_accel ();bool one_insn_per_tb =object_property_get_bool (OBJECT (accel),"one-insn-per-tb" , &error_fatal);@@ -207,9 +206,9 @@ static void dump_exec_info(GString *buf)tcg_dump_flush_info (buf); } -void tcg_dump_stats (GString *buf) +void tcg_dump_stats (AccelState *accel,GString *buf) { -dump_accel_info (buf); +dump_accel_info (accel, buf);dump_exec_info (buf);dump_drift_info (buf); } --
Quoted 2 lines
2.49.0
Re: [PATCH-for-10.1 v5 5/7] accel/tcg: Propagate AccelState to tcg_dump_stats()
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
Next commit will register
tcg_dump_stats()asAccelClass::get_statshandler. Since we want this handler to be called with the correct accelerator state, propagate it along.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- accel/tcg/internal-common.h | 2 +- accel/tcg/monitor.c | 3 ++- accel/tcg/tcg-stats.c | 7 +++---- 3 files changed, 6 insertions(+), 6 deletions(-)
I suppose you could at the same time rename to tcg_get_stats to match the accel hook. But either way,
r~
PATCH v5 6/7 accel/tcg: Implement get_[vcpu]_stats()
In reply to Philippe Mathieu-Daudé--- accel/tcg/tcg-all.c | 6 ++++++ 1 file changed, 6 insertions(+)
accel/tcg/tcg-all.c +6 -0
@@ -236,6 +236,11 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as) } } +static void tcg_get_stats (AccelState *as,GString *buf) +{ +tcg_dump_stats (as, buf); +} +static void tcg_accel_class_init (ObjectClass *oc,const void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -243,6 +248,7 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data) ac->init_machine = tcg_init_machine; ac->cpu_common_realize = tcg_exec_realizefn; ac->cpu_common_unrealize = tcg_exec_unrealizefn; + ac->get_stats = tcg_get_stats; ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 v5 6/7] accel/tcg: Implement get_[vcpu]_stats()
Maybe "accel/tcg: Implement get_stats()" is a better subject.
Quoted 30 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- accel/tcg/tcg-all.c | 6 ++++++ 1 file changed, 6 insertions(+)accel/tcg/tcg-all.c +6
-0@@ -236,6 +236,11 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as) } } +static void tcg_get_stats (AccelState *as,GString *buf) +{ +tcg_dump_stats (as, buf); +} +static void tcg_accel_class_init (ObjectClass *oc,const void *data) {AccelClass *ac =ACCEL_CLASS (oc);@@ -243,6 +248,7 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data) ac->init_machine = tcg_init_machine; ac->cpu_common_realize = tcg_exec_realizefn; ac->cpu_common_unrealize = tcg_exec_unrealizefn; + ac->get_stats = tcg_get_stats; ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
Re: [PATCH-for-10.1 v5 6/7] accel/tcg: Implement get_[vcpu]_stats()
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- accel/tcg/tcg-all.c | 6 ++++++ 1 file changed, 6 insertions(+)
Oh, this is what causes tcg-stats to be used by user-only binaries, is it?
accel/tcg/tcg-all.c static int tcg_gdbstub_supported_sstep_flags(AccelState *as) · line 242
Quoted 13 lines
accel/tcg/tcg-all.c +4
-0@@ -236,6 +236,11 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as) } } +static void tcg_get_stats (AccelState *as,GString *buf) +{ +tcg_dump_stats (as, buf); +}
Is this shim preparatory for something else?
Otherwise...
accel/tcg/tcg-all.c static void tcg_accel_class_init(ObjectClass *oc, const void *data) · line 251
Quoted 9 lines
accel/tcg/tcg-all.c +2
-0+static void tcg_accel_class_init (ObjectClass *oc,const void *data) {AccelClass *ac =ACCEL_CLASS (oc);@@ -243,6 +248,7 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data) ac->init_machine = tcg_init_machine; ac->cpu_common_realize = tcg_exec_realizefn; ac->cpu_common_unrealize = tcg_exec_unrealizefn; + ac->get_stats = tcg_get_stats;
... assign tcg_dump_stats directly?
r~
Quoted 3 lines
accel/tcg/tcg-all.c +0
-0ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
Re: [PATCH-for-10.1 v5 6/7] accel/tcg: Implement get_[vcpu]_stats()
Quoted 8 lines · Richard Henderson
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
accel/tcg/tcg-all.c| 6 ++++++1 file changed, 6 insertions(+)Oh, this is what causes tcg-stats to be used by user-only binaries, is it?
Indeed, otherwise we'd have to use #ifdef'ry or stubs; and there is no good reason to not dump TCG stats on user emulation (except indeed this code path is currently unreachable there).
Quoted 16 lines
Quoted 7 lines
accel/tcg/tcg-all.c +0
-0accel/tcg/tcg-all.c static int · line 242
Quoted 7 lines
accel/tcg/tcg-all.c +4
-0@@ -236,6 +236,11 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as) } } +static void tcg_get_stats (AccelState *as,GString *buf) +{ + tcg_dump_stats(as, buf); +}Is this shim preparatory for something else?
No, I didn't realize during rebase this can be simplified.
Quoted 21 lines
Otherwise...
accel/tcg/tcg-all.c static void tcg_accel_class_init(ObjectClass *oc, · line 252
Quoted 10 lines
accel/tcg/tcg-all.c +2
-0+ static void tcg_accel_class_init(ObjectClass *oc, const void *data) { AccelClass *ac = ACCEL_CLASS(oc);@@ -243,6 +248,7 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data) ac->init_machine = tcg_init_machine; ac->cpu_common_realize = tcg_exec_realizefn; ac->cpu_common_unrealize = tcg_exec_unrealizefn; + ac->get_stats = tcg_get_stats;... assign
tcg_dump_statsdirectly?r~
Quoted 2 lines
accel/tcg/tcg-all.c +0
-0ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
Re: [PATCH-for-10.1 v5 6/7] accel/tcg: Implement get_[vcpu]_stats()
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
accel/tcg/tcg-all.c| 6 ++++++1 file changed, 6 insertions(+)
Quoted 5 lines
Quoted 1 line
Oh, this is what causes tcg-stats to be used by user-only binaries, is it?
Indeed, otherwise we'd have to use #ifdef'ry or stubs; and there is no good reason to not dump TCG stats on user emulation (except indeed this code path is currently unreachable there).
Ok, that's fine. Let's avoid the ifdefs.
r~
Quoted 40 lines
Quoted 16 lines
Quoted 8 lines
accel/tcg/tcg-all.c +0
-0accel/tcg/tcg-all.c static int tcg_gdbstub_supported_sstep_flags(AccelState *as) · line 241
Quoted 6 lines
accel/tcg/tcg-all.c +4
-0@@ -236,6 +236,11 @@ static int tcg_gdbstub_supported_sstep_flags(AccelState *as) } } +static void tcg_get_stats (AccelState *as,GString *buf) +{ + tcg_dump_stats(as, buf); +}Is this shim preparatory for something else?
No, I didn't realize during rebase this can be simplified.
Quoted 20 lines
Otherwise...
accel/tcg/tcg-all.c static void tcg_accel_class_init(ObjectClass *oc, const void *data) · line 251
Quoted 9 lines
accel/tcg/tcg-all.c +2
-0+ static void tcg_accel_class_init(ObjectClass *oc, const void *data) { AccelClass *ac = ACCEL_CLASS(oc);@@ -243,6 +248,7 @@ static void tcg_accel_class_init(ObjectClass *oc, const void *data) ac->init_machine = tcg_init_machine; ac->cpu_common_realize = tcg_exec_realizefn; ac->cpu_common_unrealize = tcg_exec_unrealizefn; + ac->get_stats = tcg_get_stats;... assign
tcg_dump_statsdirectly?r~
Quoted 2 lines
accel/tcg/tcg-all.c +0
-0ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
Re: [PATCH-for-10.1 v5 6/7] accel/tcg: Implement get_[vcpu]_stats()
Quoted 9 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
accel/tcg/tcg-all.c| 6 ++++++1 file changed, 6 insertions(+)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Oh, this is what causes tcg-stats to be used by user-only binaries, is it?
Indeed, otherwise we'd have to use #ifdef'ry or stubs; and there is no good reason to not dump TCG stats on user emulation (except indeed this code path is currently unreachable there).
Ok, that's fine. Let's avoid the ifdefs.
This works for Linux (qemu-foo -d stats.log ...):
-- >8 --
linux-user/exit.c +7 -0
@@ -21,7 +21,10 @@#include "gdbstub/syscalls.h" #include "qemu.h" #include "user-internals.h" +#include "qemu/accel.h" +#include "qemu/log.h" #include "qemu/plugin.h" +#include "accel/tcg/internal-common.h" #ifdef CONFIG_GCOV extern void __gcov_dump (void );
@@ -29,10 +32,14 @@ extern void __gcov_dump(void);void preexit_cleanup (CPUArchState *env,int code) { +g_autoptr (GString) buf =g_string_new ("" ); +#ifdef CONFIG_GCOV __gcov_dump ();#endif gdb_exit (code);qemu_plugin_user_exit ();perf_exit (); +tcg_dump_stats (current_accel (), buf); +qemu_log ("TCG stats: %s" , buf->str); }
---
PATCH v5 7/7 accel/hvf: Implement get_vcpu_stats()
In reply to Philippe Mathieu-Daudé---
Mads, I welcome your Signed-off-by tag on top :)
--- accel/hvf/hvf-accel-ops.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
accel/hvf/hvf-accel-ops.c +24 -0
@@ -58,6 +58,7 @@#include "system/cpus.h" #include "system/hvf.h" #include "system/hvf_int.h" +#include <mach/mach_time.h> HVFState *hvf_state;
@@ -118,6 +119,12 @@ static void dummy_signal(int sig) { } +static void do_hvf_get_vcpu_exec_time (CPUState *cpu,run_on_cpu_data arg) +{ +int r =hv_vcpu_get_exec_time (cpu->accel->fd, arg.host_ptr); +assert_hvf_ok (r); +} +static void hvf_vcpu_destroy (CPUState *cpu) {hv_return_t ret =hv_vcpu_destroy (cpu->accel->fd);
@@ -347,6 +354,20 @@ static void hvf_remove_all_breakpoints(CPUState *cpu) } } +static void hvf_get_vcpu_stats (CPUState *cpu,GString *buf) +{ +uint64_t time_mach;/* units of mach_absolute_time() */ + +run_on_cpu (cpu, do_hvf_get_vcpu_exec_time,RUN_ON_CPU_HOST_PTR (&time_mach)); + +mach_timebase_info_data_t timebase; +mach_timebase_info (&timebase); +uint64_t time_ns = time_mach * timebase.numer / timebase.denom; + +g_string_append_printf (buf,"HVF cumulative execution time: %llu.%.3llus\n" , + time_ns /1000000000 , (time_ns %1000000000 ) /1000000 ); +} +static void hvf_accel_ops_class_init (ObjectClass *oc,const void *data) {AccelOpsClass *ops =ACCEL_OPS_CLASS (oc);
@@ -365,7 +386,10 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data) ops->remove_all_breakpoints = hvf_remove_all_breakpoints; ops->update_guest_debug = hvf_update_guest_debug; ops->supports_guest_debug = hvf_arch_supports_guest_debug; + + ops->get_vcpu_stats = hvf_get_vcpu_stats; }; +static const TypeInfo hvf_accel_ops_type = { .name =ACCEL_OPS_NAME ("hvf" ),
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 v5 7/7] accel/hvf: Implement get_vcpu_stats()
Quoted 12 lines · Philippe Mathieu-Daudé
Co-developed-by Mads Ynddal <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
Mads, I welcome your Signed-off-by tag on top :)
---accel/hvf/hvf-accel-ops.c| 24 ++++++++++++++++++++++++1 file changed, 24 insertions(+)
Looks great :)