Add a QMP command that shows all specific properties of the current
accelerator in use.
This can be used as a complement of other APIs like query-machines and
query-cpu-model-expansion, allowing management to get a more complete
picture of the running QEMU process.
This is the output with a x86_64 TCG guest:
$ ./build/qemu-system-x86_64 -S -display none -accel tcg -qmp
tcp:localhost:1234,server,wait=off
$ ./scripts/qmp/qmp-shell localhost:1234
Welcome to the QMP low-level shell!
Connected to QEMU 9.1.50
(QEMU) query-accelerator
{"return": {"name": "tcg", "props": {"one-insn-per-tb": false, "thread":
"multi", "tb-size": 0, "split-wx": false, "type": "tcg-accel"}}}
And for a x86_64 KVM guest:
$ ./build/qemu-system-x86_64 -S -display none -accel kvm -qmp
tcp:localhost:1234,server,wait=off
$ ./scripts/qmp/qmp-shell localhost:1234
Welcome to the QMP low-level shell!
Connected to QEMU 9.1.50
(QEMU) query-accelerator
{"return": {"name": "KVM", "props": {"mem-container-smram[0]": "",
"xen-gnttab-max-frames": 64, "device": "", "xen-version": 0, "mem-smram[0]":
"", "notify-window": 0, "dirty-ring-size": 0, "kvm-shadow-mem": -1, "type":
"kvm-accel", "notify-vmexit": "run", "xen-evtchn-max-pirq": 256}}}
Signed-off-by: Daniel Henrique Barboza <[email protected]>
---
hw/core/machine-qmp-cmds.c | 34 ++++++++++++++++++++++++++++++++++
qapi/machine.json | 27 +++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 130217da8f..eac803bf36 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -15,6 +15,7 @@
#include "qapi/error.h"
#include "qapi/qapi-builtin-visit.h"
#include "qapi/qapi-commands-machine.h"
+#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/type-helpers.h"
@@ -406,3 +407,36 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp)
info->guid = qemu_uuid_unparse_strdup(&vms->guid);
return info;
}
+
+AccelInfo *qmp_query_accelerator(Error **errp)
+{
+ AccelState *accel = current_accel();
+ AccelClass *acc = ACCEL_GET_CLASS(accel);
+ AccelInfo *info = g_new0(AccelInfo, 1);
+ QDict *qdict_out = qdict_new();
+ ObjectPropertyIterator iter;
+ ObjectProperty *prop;
+
+ info->name = g_strdup(acc->name);
+
+ object_property_iter_init(&iter, OBJECT(accel));
+ while ((prop = object_property_iter_next(&iter))) {
+ QObject *value;
+
+ if (!prop->get) {
+ continue;
+ }
+
+ value = object_property_get_qobject(OBJECT(accel), prop->name,
+ &error_abort);
+ qdict_put_obj(qdict_out, prop->name, value);
+ }
+
+ if (!qdict_size(qdict_out)) {
+ qobject_unref(qdict_out);
+ } else {
+ info->props = QOBJECT(qdict_out);
+ }
+
+ return info;
+}
diff --git a/qapi/machine.json b/qapi/machine.json
index a6b8795b09..d0d527d1eb 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -1898,3 +1898,30 @@
{ 'command': 'x-query-interrupt-controllers',
'returns': 'HumanReadableText',
'features': [ 'unstable' ]}
+
+##
+# @AccelInfo:
+#
+# Information about the current accelerator.
+#
+# @name: the name of the current accelerator being used
+#
+# @props: a dictionary of the accelerator properties
+#
+# Since: 9.2
+##
+{ 'struct': 'AccelInfo',
+ 'data': { 'name': 'str',
+ '*props': 'any' } }
+
+##
+# @query-accelerator:
+#
+# Shows information about the accelerator in use.
+#
+# Returns: a CpuModelExpansionInfo describing the expanded CPU model
+#
+# Since: 9.2
+##
+{ 'command': 'query-accelerator',
+ 'returns': 'AccelInfo' }
--
2.45.2