From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Eric Blake" <eblake@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Cameron Esfahani" <dirty@apple.com>,
"Mads Ynddal" <mads@ynddal.dk>,
"Phil Dennis-Jordan" <phil@philjordan.eu>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Roman Bolshakov" <rbolshakov@ddn.com>,
"Zhao Liu" <zhao1.liu@intel.com>
Subject: [PATCH-for-10.1 v5 3/7] accel/system: Introduce @x-accel-stats QMP command
Date: Tue, 15 Jul 2025 12:40:11 +0200 [thread overview]
Message-ID: <20250715104015.72663-4-philmd@linaro.org> (raw)
In-Reply-To: <20250715104015.72663-1-philmd@linaro.org>
Unstable QMP 'x-accel-stats' dispatches to the
AccelOpsClass::get_stats() and get_vcpu_stats() handlers.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
---
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
diff --git a/qapi/accelerator.json b/qapi/accelerator.json
index d55fe1aa0a3..6029e7307a7 100644
--- a/qapi/accelerator.json
+++ b/qapi/accelerator.json
@@ -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' ] }
diff --git a/include/accel/accel-cpu-ops.h b/include/accel/accel-cpu-ops.h
index a9191dded7e..0674764914f 100644
--- a/include/accel/accel-cpu-ops.h
+++ b/include/accel/accel-cpu-ops.h
@@ -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
diff --git a/include/accel/accel-ops.h b/include/accel/accel-ops.h
index 86a27c30fa4..23a8c246e15 100644
--- a/include/accel/accel-ops.h
+++ b/include/accel/accel-ops.h
@@ -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);
diff --git a/accel/accel-qmp.c b/accel/accel-qmp.c
new file mode 100644
index 00000000000..5fb70c6631f
--- /dev/null
+++ b/accel/accel-qmp.c
@@ -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);
+}
diff --git a/accel/accel-system.c b/accel/accel-system.c
index 8df561b9539..76cf4e7ef7a 100644
--- a/accel/accel-system.c
+++ b/accel/accel-system.c
@@ -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"
diff --git a/accel/meson.build b/accel/meson.build
index 52909314bfa..25b0f100b51 100644
--- a/accel/meson.build
+++ b/accel/meson.build
@@ -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')
--
2.49.0
next prev parent reply other threads:[~2025-07-15 10:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 10:40 [PATCH-for-10.1 v5 0/7] accel/system: Add 'info accel' on human monitor Philippe Mathieu-Daudé
2025-07-15 10:40 ` [PATCH-for-10.1 v5 1/7] Revert "accel/tcg: Unregister the RCU before exiting RR thread" Philippe Mathieu-Daudé
2025-07-15 11:19 ` Manos Pitsidianakis
2025-07-15 12:38 ` Richard Henderson
2025-07-15 10:40 ` [PATCH-for-10.1 v5 2/7] accel/tcg: Extract statistic related code to tcg-stats.c Philippe Mathieu-Daudé
2025-07-15 12:44 ` Richard Henderson
2025-07-15 13:18 ` Richard Henderson
2025-07-15 10:40 ` Philippe Mathieu-Daudé [this message]
2025-07-15 10:40 ` [PATCH-for-10.1 v5 4/7] accel/system: Add 'info accel' on human monitor Philippe Mathieu-Daudé
2025-07-15 10:40 ` [PATCH-for-10.1 v5 5/7] accel/tcg: Propagate AccelState to tcg_dump_stats() Philippe Mathieu-Daudé
2025-07-15 11:19 ` Manos Pitsidianakis
2025-07-15 13:20 ` Richard Henderson
2025-07-15 10:40 ` [PATCH-for-10.1 v5 6/7] accel/tcg: Implement get_[vcpu]_stats() Philippe Mathieu-Daudé
2025-07-15 10:42 ` Philippe Mathieu-Daudé
2025-07-15 12:48 ` Richard Henderson
2025-07-15 13:06 ` Philippe Mathieu-Daudé
2025-07-15 13:18 ` Richard Henderson
2025-07-15 13:26 ` Philippe Mathieu-Daudé
2025-07-15 10:40 ` [PATCH-for-10.1 v5 7/7] accel/hvf: Implement get_vcpu_stats() Philippe Mathieu-Daudé
2025-07-15 10:57 ` Mads Ynddal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250715104015.72663-4-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=dirty@apple.com \
--cc=eblake@redhat.com \
--cc=mads@ynddal.dk \
--cc=manos.pitsidianakis@linaro.org \
--cc=pbonzini@redhat.com \
--cc=phil@philjordan.eu \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rbolshakov@ddn.com \
--cc=richard.henderson@linaro.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).