diff mbox series

[RFC,v2,15/48] accel/system: Add 'info accel' on human monitor

Message ID 20250620171342.92678-16-philmd@linaro.org
State New
Headers show
Series accel: Preparatory cleanups for split-accel | expand

Commit Message

Philippe Mathieu-Daudé June 20, 2025, 5:13 p.m. UTC
'info accel' dispatches to the AccelOpsClass::get_stats()
and get_vcpu_stats() handlers.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/accel.h       |  1 +
 include/system/accel-ops.h |  2 ++
 accel/accel-system.c       | 28 ++++++++++++++++++++++++++++
 hmp-commands-info.hx       | 12 ++++++++++++
 4 files changed, 43 insertions(+)

Comments

Richard Henderson June 22, 2025, 1:26 a.m. UTC | #1
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> 'info accel' dispatches to theAccelOpsClass::get_stats()
> and get_vcpu_stats() handlers.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   include/qemu/accel.h       |  1 +
>   include/system/accel-ops.h |  2 ++
>   accel/accel-system.c       | 28 ++++++++++++++++++++++++++++
>   hmp-commands-info.hx       | 12 ++++++++++++
>   4 files changed, 43 insertions(+)

Acked-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/include/qemu/accel.h b/include/qemu/accel.h
index aee0a2e3309..4ed5f264a88 100644
--- a/include/qemu/accel.h
+++ b/include/qemu/accel.h
@@ -41,6 +41,7 @@  typedef struct AccelClass {
     AccelOpsClass *ops;
 
     int (*init_machine)(MachineState *ms, AccelState *as);
+    void (*get_stats)(AccelState *as, GString *buf);
 
     /* system related hooks */
     void (*setup_post)(MachineState *ms, AccelState *accel);
diff --git a/include/system/accel-ops.h b/include/system/accel-ops.h
index fb199dc78f0..5c5171ea5b5 100644
--- a/include/system/accel-ops.h
+++ b/include/system/accel-ops.h
@@ -51,6 +51,8 @@  struct AccelOpsClass {
 
     void (*handle_interrupt)(CPUState *cpu, int mask);
 
+    void (*get_vcpu_stats)(CPUState *cpu, GString *buf);
+
     /**
      * @get_virtual_clock: fetch virtual clock
      * @set_virtual_clock: set virtual clock
diff --git a/accel/accel-system.c b/accel/accel-system.c
index 1db146139c4..b37889b84f0 100644
--- a/accel/accel-system.c
+++ b/accel/accel-system.c
@@ -25,6 +25,8 @@ 
 
 #include "qemu/osdep.h"
 #include "qemu/accel.h"
+#include "qapi/type-helpers.h"
+#include "monitor/monitor.h"
 #include "hw/boards.h"
 #include "system/accel-ops.h"
 #include "system/cpus.h"
@@ -72,6 +74,26 @@  bool cpus_are_resettable(void)
     return true;
 }
 
+static HumanReadableText *hmp_info_accel(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);
+}
+
 /* initialize the arch-independent accel operation interfaces */
 void accel_init_ops_interfaces(AccelClass *ac)
 {
@@ -102,11 +124,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", hmp_info_accel);
+}
+
 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)
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 639a450ee51..0496be6abfb 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -281,6 +281,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),