Skip to contentSkip to conversation

accel/system: Add 'info accel' on human monitor

PATCH In review Philippe Mathieu-Daudé 1 participant 10 messages Jul 15, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v6 cover accel/system: Add 'info accel' on human monitor

Since v5:
- Addressed rth review comments
- Added R-b tags

Philippe Mathieu-Daudé (8):
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 dump_accel_info() accel/tcg: Implement AccelClass::get_stats() handler accel/hvf: Implement AccelClass::get_vcpu_stats() [NOTFORMERGE] linux-user: Dump TCG stats to logfile

 qapi/accelerator.json         |  17 +++
 accel/tcg/internal-common.h   |   2 +-
 include/accel/accel-cpu-ops.h |   3 +
 include/accel/accel-ops.h     |   2 +
 include/tcg/tcg.h             |   2 +
 accel/accel-qmp.c             |  35 ++++++
 accel/accel-system.c          |   9 ++
 accel/hvf/hvf-accel-ops.c     |  24 ++++
 accel/tcg/monitor.c           | 200 -------------------------------
 accel/tcg/tcg-accel-ops-rr.c  |   2 -
 accel/tcg/tcg-all.c           |   1 +
 accel/tcg/tcg-stats.c         | 219 ++++++++++++++++++++++++++++++++++
 linux-user/exit.c             |   6 +
 accel/meson.build             |   2 +-
 accel/tcg/meson.build         |   1 +
 hmp-commands-info.hx          |  12 ++
 16 files changed, 333 insertions(+), 204 deletions(-)
 create mode 100644 accel/accel-qmp.c
 create mode 100644 accel/tcg/tcg-stats.c
Signature · 1 line
2.49.0
#1 lore raw

PATCH v6 1/8 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
index a578698d071..6eec5c9eee9 100644
@@ -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
#2 lore raw

PATCH v6 2/8 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. Note, this code is not yet reachable by user-mode.

---
 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
index 778b12613f4..adb9de5a1c6 100644
@@ -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
index 575e92bb9e8..002aa8f4588 100644
@@ -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
#3 lore raw

PATCH v6 3/8 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
index d55fe1aa0a3..6029e7307a7 100644
@@ -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
index a9191dded7e..0674764914f 100644
@@ -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
index 86a27c30fa4..23a8c246e15 100644
@@ -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
new file mode 100644
index 00000000000..5fb70c6631f
@@ -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
index 8df561b9539..76cf4e7ef7a 100644
@@ -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
index 52909314bfa..25b0f100b51 100644
@@ -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
#4 lore raw

PATCH v6 4/8 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
index 76cf4e7ef7a..1e97c64fdca 100644
@@ -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
index d7979222752..6142f60e7b1 100644
@@ -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
#5 lore raw

PATCH v6 5/8 accel/tcg: Propagate AccelState to dump_accel_info()

In reply to Philippe Mathieu-Daudé

Declare tcg_dump_stats() in "tcg/tcg.h" so it can be used out of accel/tcg/, like by {bsd,linux}-user.

Next commit will register the TCG AccelClass::get_stats handler, which expects a AccelState, so propagate it to dump_accel_info().

---
 accel/tcg/internal-common.h | 2 --
 include/tcg/tcg.h           | 2 ++
 accel/tcg/monitor.c         | 1 +
 accel/tcg/tcg-stats.c       | 5 ++---
 4 files changed, 5 insertions(+), 5 deletions(-)
accel/tcg/internal-common.h +0 -2
index 77a3a0684a5..1dbc45dd955 100644
@@ -139,6 +139,4 @@ 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);
-
 #endif
include/tcg/tcg.h +2 -0
index 0c2a319c11d..a6d9aa50d47 100644
@@ -1005,5 +1005,7 @@ static inline const TCGOpcode *tcg_swap_vecop_list(const TCGOpcode *n)
 
 bool tcg_can_emit_vecop_list(const TCGOpcode *, TCGType, unsigned);
 void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs);
+/* tcg_dump_stats: Append TCG statistics to @buf */
+void tcg_dump_stats(GString *buf);
 
 #endif /* TCG_H */
accel/tcg/monitor.c +1 -0
index adb9de5a1c6..be5c1950177 100644
@@ -12,6 +12,7 @@
 #include "qapi/qapi-commands-machine.h"
 #include "monitor/monitor.h"
 #include "system/tcg.h"
+#include "tcg/tcg.h"
 #include "internal-common.h"
 
 HumanReadableText *qmp_x_query_jit(Error **errp)
accel/tcg/tcg-stats.c +2 -3
index eb6e20ae985..e1a1c4cf4ac 100644
@@ -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);
@@ -209,7 +208,7 @@ static void dump_exec_info(GString *buf)
 
 void tcg_dump_stats(GString *buf)
 {
-    dump_accel_info(buf);
+    dump_accel_info(current_accel(), buf);
     dump_exec_info(buf);
     dump_drift_info(buf);
 }
Signature · 1 line
2.49.0
#6 lore raw

PATCH v6 6/8 accel/tcg: Implement AccelClass::get_stats() handler

In reply to Philippe Mathieu-Daudé

Factor tcg_get_stats() out of tcg_dump_stats(),
passing the current accelerator argument to match
the AccelClass::get_stats() prototype.

---
 accel/tcg/internal-common.h | 2 ++
 accel/tcg/tcg-all.c         | 1 +
 accel/tcg/tcg-stats.c       | 9 +++++++--
 3 files changed, 10 insertions(+), 2 deletions(-)
accel/tcg/internal-common.h +2 -0
index 1dbc45dd955..6adfeefe131 100644
@@ -139,4 +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_get_stats(AccelState *accel, GString *buf);
+
 #endif
accel/tcg/tcg-all.c +1 -0
index eaeb465dfd5..5125e1a4e27 100644
@@ -243,6 +243,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;
 
accel/tcg/tcg-stats.c +7 -2
index e1a1c4cf4ac..ced5dec0c4f 100644
@@ -206,9 +206,14 @@ static void dump_exec_info(GString *buf)
     tcg_dump_flush_info(buf);
 }
 
-void tcg_dump_stats(GString *buf)
+void tcg_get_stats(AccelState *accel, GString *buf)
 {
-    dump_accel_info(current_accel(), buf);
+    dump_accel_info(accel, buf);
     dump_exec_info(buf);
     dump_drift_info(buf);
 }
+
+void tcg_dump_stats(GString *buf)
+{
+    tcg_get_stats(current_accel(), buf);
+}
Signature · 1 line
2.49.0
#7 lore raw

PATCH v6 7/8 accel/hvf: Implement AccelClass::get_vcpu_stats()

In reply to Philippe Mathieu-Daudé
---
 accel/hvf/hvf-accel-ops.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
accel/hvf/hvf-accel-ops.c +24 -0
index 214454bd0b4..94a5bffb44e 100644
@@ -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
#8 lore raw

PATCH v6 8/8 linux-user: Dump TCG stats to logfile

In reply to Philippe Mathieu-Daudé

Running 'qemu-user -D stats.log' will dump TCG statistics to 'stats.log' before exiting.

---
 linux-user/exit.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/exit.c +6 -0
index 1ff8fe4f072..17d2ad0517b 100644
@@ -21,7 +21,9 @@
 #include "gdbstub/syscalls.h"
 #include "qemu.h"
 #include "user-internals.h"
+#include "qemu/log.h"
 #include "qemu/plugin.h"
+#include "tcg/tcg.h"
 
 #ifdef CONFIG_GCOV
 extern void __gcov_dump(void);
@@ -29,10 +31,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(buf);
+        qemu_log("TCG stats: %s", buf->str);
 }
Signature · 1 line
2.49.0
#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (8):
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 dump_accel_info() accel/tcg: Implement AccelClass::get_stats() handler accel/hvf: Implement AccelClass::get_vcpu_stats()

1-7 queued, thanks.