* [PATCH v2 1/4] accel: Introduce 'query-accels' QMP command
2021-03-16 17:24 [PATCH v2 0/4] qtests: Check accelerator available at runtime via QMP 'query-accels' Philippe Mathieu-Daudé
@ 2021-03-16 17:24 ` Philippe Mathieu-Daudé
2021-03-16 17:29 ` Eric Blake
2021-03-16 17:24 ` [PATCH v2 2/4] tests/qtest: Add qtest_has_accel() method Philippe Mathieu-Daudé
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-03-16 17:24 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Thomas Huth, Andrew Jones, Eduardo Habkost,
Michael S. Tsirkin, Daniel P . Berrangé,
Richard Henderson, Markus Armbruster, Philippe Mathieu-Daudé,
qemu-arm, Claudio Fontana, Igor Mammedov, Paolo Bonzini
Introduce the 'query-accels' QMP command which returns a list
of built-in accelerator names.
- Accelerator is a QAPI enum of all existing accelerators,
- AcceleratorInfo is a QAPI structure providing accelerator
specific information. Currently the common structure base
provides the name of the accelerator, while the specific
part is empty, but each accelerator can expand it.
- 'query-accels' QMP command returns a list of @AcceleratorInfo
For example on a KVM-only build we get:
{ "execute": "query-accels" }
{
"return": [
{
"name": "qtest"
},
{
"name": "kvm"
}
]
}
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Since v1: 'type' -> 'name' in comments
---
qapi/machine.json | 55 +++++++++++++++++++++++++++++++++++++++++++++++
accel/accel-qmp.c | 49 +++++++++++++++++++++++++++++++++++++++++
accel/meson.build | 2 +-
3 files changed, 105 insertions(+), 1 deletion(-)
create mode 100644 accel/accel-qmp.c
diff --git a/qapi/machine.json b/qapi/machine.json
index 330189efe3d..610252fc25c 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -1471,3 +1471,58 @@
##
{ 'event': 'MEM_UNPLUG_ERROR',
'data': { 'device': 'str', 'msg': 'str' } }
+
+##
+# @Accelerator:
+#
+# An enumeration of accelerator names.
+#
+# Since: 6.0
+##
+{ 'enum': 'Accelerator',
+ 'data': [ { 'name': 'qtest' },
+ { 'name': 'tcg' },
+ { 'name': 'kvm' },
+ { 'name': 'hax' },
+ { 'name': 'hvf' },
+ { 'name': 'whpx' },
+ { 'name': 'xen' } ] }
+
+##
+# @AcceleratorInfo:
+#
+# Accelerator information.
+#
+# @name: The accelerator name.
+#
+# Since: 6.0
+##
+{ 'union': 'AcceleratorInfo',
+ 'base': {'name': 'Accelerator'},
+ 'discriminator': 'name',
+ 'data': { } }
+
+##
+# @query-accels:
+#
+# Get a list of AcceleratorInfo for all built-in accelerators.
+#
+# Returns: a list of @AcceleratorInfo describing each accelerator.
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "query-accels" }
+# <- { "return": [
+# {
+# "name": "qtest"
+# },
+# {
+# "name": "kvm"
+# }
+# ] }
+#
+##
+{ 'command': 'query-accels',
+ 'returns': ['AcceleratorInfo'] }
diff --git a/accel/accel-qmp.c b/accel/accel-qmp.c
new file mode 100644
index 00000000000..426737b3f9a
--- /dev/null
+++ b/accel/accel-qmp.c
@@ -0,0 +1,49 @@
+/*
+ * QEMU accelerators, QMP commands
+ *
+ * Copyright (c) 2021 Red Hat Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/qapi-commands-machine.h"
+
+static const bool accel_builtin_list[ACCELERATOR__MAX] = {
+ [ACCELERATOR_QTEST] = true,
+#ifdef CONFIG_TCG
+ [ACCELERATOR_TCG] = true,
+#endif
+#ifdef CONFIG_KVM
+ [ACCELERATOR_KVM] = true,
+#endif
+#ifdef CONFIG_HAX
+ [ACCELERATOR_HAX] = true,
+#endif
+#ifdef CONFIG_HVF
+ [ACCELERATOR_HVF] = true,
+#endif
+#ifdef CONFIG_WHPX
+ [ACCELERATOR_WHPX] = true,
+#endif
+#ifdef CONFIG_XEN_BACKEND
+ [ACCELERATOR_XEN] = true,
+#endif
+};
+
+AcceleratorInfoList *qmp_query_accels(Error **errp)
+{
+ AcceleratorInfoList *list = NULL, **tail = &list;
+
+ for (Accelerator accel = 0; accel < ACCELERATOR__MAX; accel++) {
+ if (accel_builtin_list[accel]) {
+ AcceleratorInfo *info = g_new0(AcceleratorInfo, 1);
+
+ info->name = accel;
+
+ QAPI_LIST_APPEND(tail, info);
+ }
+ }
+
+ return list;
+}
diff --git a/accel/meson.build b/accel/meson.build
index b44ba30c864..7a48f6d568d 100644
--- a/accel/meson.build
+++ b/accel/meson.build
@@ -1,4 +1,4 @@
-specific_ss.add(files('accel-common.c'))
+specific_ss.add(files('accel-common.c', 'accel-qmp.c'))
softmmu_ss.add(files('accel-softmmu.c'))
user_ss.add(files('accel-user.c'))
--
2.26.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/4] tests/qtest: Add qtest_has_accel() method
2021-03-16 17:24 [PATCH v2 0/4] qtests: Check accelerator available at runtime via QMP 'query-accels' Philippe Mathieu-Daudé
2021-03-16 17:24 ` [PATCH v2 1/4] accel: Introduce 'query-accels' QMP command Philippe Mathieu-Daudé
@ 2021-03-16 17:24 ` Philippe Mathieu-Daudé
2021-03-16 17:31 ` Eric Blake
2021-03-16 17:24 ` [PATCH v2 3/4] qtest/bios-tables-test: Make test build-independent from accelerator Philippe Mathieu-Daudé
2021-03-16 17:24 ` [PATCH v2 4/4] tests/qtest: Do not restrict bios-tables-test to Aarch64 hosts anymore Philippe Mathieu-Daudé
3 siblings, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-03-16 17:24 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Thomas Huth, Andrew Jones, Eduardo Habkost,
Michael S. Tsirkin, Daniel P . Berrangé,
Richard Henderson, Markus Armbruster, Philippe Mathieu-Daudé,
qemu-arm, Claudio Fontana, Igor Mammedov, Paolo Bonzini
Introduce the qtest_has_accel() method which allows
to query at runtime if a QEMU instance has an accelerator
built-in.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Since v1:
- rename qtest_probe_accel() -> qtest_has_accel()
- run with -machine none before creating QTestState
---
tests/qtest/libqos/libqtest.h | 8 ++++++++
tests/qtest/libqtest.c | 29 +++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
index a68dcd79d44..d80c618c18d 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -763,6 +763,14 @@ void qmp_expect_error_and_unref(QDict *rsp, const char *class);
*/
bool qtest_probe_child(QTestState *s);
+/**
+ * qtest_has_accel:
+ * @accel_name: Accelerator name to check for.
+ *
+ * Returns: true if the accelerator is built in.
+ */
+bool qtest_has_accel(const char *accel_name);
+
/**
* qtest_set_expected_status:
* @s: QTestState instance to operate on.
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 71e359efcd3..2156b7e3972 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -393,6 +393,35 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
return qts;
}
+bool qtest_has_accel(const char *accel_name)
+{
+ bool has_accel = false;
+ QDict *response;
+ QList *accels;
+ QListEntry *accel;
+ QTestState *qts;
+
+ qts = qtest_initf("-accel qtest -machine none");
+ response = qtest_qmp(qts, "{'execute': 'query-accels'}");
+ accels = qdict_get_qlist(response, "return");
+
+ QLIST_FOREACH_ENTRY(accels, accel) {
+ QDict *accel_dict = qobject_to(QDict, qlist_entry_obj(accel));
+ const char *name = qdict_get_str(accel_dict, "name");
+
+ if (g_str_equal(name, accel_name)) {
+ has_accel = true;
+ break;
+ }
+ }
+ qobject_unref(response);
+
+ qtest_quit(qts);
+
+ return has_accel;
+}
+
+
void qtest_quit(QTestState *s)
{
qtest_remove_abrt_handler(s);
--
2.26.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/4] qtest/bios-tables-test: Make test build-independent from accelerator
2021-03-16 17:24 [PATCH v2 0/4] qtests: Check accelerator available at runtime via QMP 'query-accels' Philippe Mathieu-Daudé
2021-03-16 17:24 ` [PATCH v2 1/4] accel: Introduce 'query-accels' QMP command Philippe Mathieu-Daudé
2021-03-16 17:24 ` [PATCH v2 2/4] tests/qtest: Add qtest_has_accel() method Philippe Mathieu-Daudé
@ 2021-03-16 17:24 ` Philippe Mathieu-Daudé
2021-03-16 17:32 ` Eric Blake
2021-03-16 17:24 ` [PATCH v2 4/4] tests/qtest: Do not restrict bios-tables-test to Aarch64 hosts anymore Philippe Mathieu-Daudé
3 siblings, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-03-16 17:24 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Thomas Huth, Andrew Jones, Eduardo Habkost,
Michael S. Tsirkin, Daniel P . Berrangé,
Richard Henderson, Markus Armbruster, Philippe Mathieu-Daudé,
qemu-arm, Claudio Fontana, Igor Mammedov, Paolo Bonzini
Now than we can probe if the TCG accelerator is available
at runtime with a QMP command, do it once at the beginning
and only register the tests we can run.
We can then replace the #ifdef'ry by an assertion.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2: use global tcg_accel_available, call qtest_has_accel() once
---
tests/qtest/bios-tables-test.c | 99 ++++++++++++++++++----------------
1 file changed, 52 insertions(+), 47 deletions(-)
diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index e020c83d2a5..52587aeb6b1 100644
--- a/tests/qtest/bios-tables-test.c
+++ b/tests/qtest/bios-tables-test.c
@@ -97,6 +97,7 @@ typedef struct {
QTestState *qts;
} test_data;
+static bool tcg_accel_available;
static char disk[] = "tests/acpi-test-disk-XXXXXX";
static const char *data_dir = "tests/data/acpi";
#ifdef CONFIG_IASL
@@ -718,15 +719,11 @@ static void test_acpi_one(const char *params, test_data *data)
char *args;
bool use_uefi = data->uefi_fl1 && data->uefi_fl2;
-#ifndef CONFIG_TCG
- if (data->tcg_only) {
- g_test_skip("TCG disabled, skipping ACPI tcg_only test");
- return;
- }
-#endif /* CONFIG_TCG */
+ assert(!data->tcg_only || tcg_accel_available);
args = test_acpi_create_args(data, params, use_uefi);
data->qts = qtest_init(args);
+
test_acpi_load_tables(data, use_uefi);
if (getenv(ACPI_REBUILD_EXPECTED_AML)) {
@@ -1504,6 +1501,8 @@ int main(int argc, char *argv[])
const char *arch = qtest_get_arch();
int ret;
+ tcg_accel_available = qtest_has_accel("tcg");
+
g_test_init(&argc, &argv, NULL);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
@@ -1512,56 +1511,62 @@ int main(int argc, char *argv[])
return ret;
}
qtest_add_func("acpi/q35/oem-fields", test_acpi_oem_fields_q35);
- qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis);
- qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
qtest_add_func("acpi/oem-fields", test_acpi_oem_fields_pc);
- qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
+ qtest_add_func("acpi/microvm/oem-fields", test_acpi_oem_fields_microvm);
qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug",
test_acpi_piix4_no_root_hotplug);
qtest_add_func("acpi/piix4/pci-hotplug/no_bridge_hotplug",
test_acpi_piix4_no_bridge_hotplug);
qtest_add_func("acpi/piix4/pci-hotplug/off",
test_acpi_piix4_no_acpi_pci_hotplug);
- qtest_add_func("acpi/q35", test_acpi_q35_tcg);
- qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
- qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
- qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
- qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
- qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
- qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
- qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
- qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
- qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
- qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
- qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm);
- qtest_add_func("acpi/piix4/smm-compat",
- test_acpi_piix4_tcg_smm_compat);
- qtest_add_func("acpi/piix4/smm-compat-nosmm",
- test_acpi_piix4_tcg_smm_compat_nosmm);
- qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet);
- qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
- qtest_add_func("acpi/q35/smm-compat",
- test_acpi_q35_tcg_smm_compat);
- qtest_add_func("acpi/q35/smm-compat-nosmm",
- test_acpi_q35_tcg_smm_compat_nosmm);
- qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
- qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
- qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
- qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
- qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
- qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
- qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
- qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
- qtest_add_func("acpi/microvm/ioapic2", test_acpi_microvm_ioapic2_tcg);
- qtest_add_func("acpi/microvm/oem-fields", test_acpi_oem_fields_microvm);
- if (strcmp(arch, "x86_64") == 0) {
- qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg);
+ if (tcg_accel_available) {
+ qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis);
+ qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
+ qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
+ qtest_add_func("acpi/q35", test_acpi_q35_tcg);
+ qtest_add_func("acpi/q35/bridge", test_acpi_q35_tcg_bridge);
+ qtest_add_func("acpi/q35/mmio64", test_acpi_q35_tcg_mmio64);
+ qtest_add_func("acpi/piix4/ipmi", test_acpi_piix4_tcg_ipmi);
+ qtest_add_func("acpi/q35/ipmi", test_acpi_q35_tcg_ipmi);
+ qtest_add_func("acpi/piix4/cpuhp", test_acpi_piix4_tcg_cphp);
+ qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
+ qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
+ qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
+ qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
+ qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
+ qtest_add_func("acpi/piix4/nosmm", test_acpi_piix4_tcg_nosmm);
+ qtest_add_func("acpi/piix4/smm-compat",
+ test_acpi_piix4_tcg_smm_compat);
+ qtest_add_func("acpi/piix4/smm-compat-nosmm",
+ test_acpi_piix4_tcg_smm_compat_nosmm);
+ qtest_add_func("acpi/piix4/nohpet", test_acpi_piix4_tcg_nohpet);
+ qtest_add_func("acpi/q35/nosmm", test_acpi_q35_tcg_nosmm);
+ qtest_add_func("acpi/q35/smm-compat",
+ test_acpi_q35_tcg_smm_compat);
+ qtest_add_func("acpi/q35/smm-compat-nosmm",
+ test_acpi_q35_tcg_smm_compat_nosmm);
+ qtest_add_func("acpi/q35/nohpet", test_acpi_q35_tcg_nohpet);
+ qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
+ qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
+ qtest_add_func("acpi/piix4/acpihmat",
+ test_acpi_piix4_tcg_acpi_hmat);
+ qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
+ qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
+ qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
+ qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
+ qtest_add_func("acpi/microvm/ioapic2",
+ test_acpi_microvm_ioapic2_tcg);
+ if (strcmp(arch, "x86_64") == 0) {
+ qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg);
+ }
}
} else if (strcmp(arch, "aarch64") == 0) {
- qtest_add_func("acpi/virt", test_acpi_virt_tcg);
- qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
- qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
- qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb);
+ if (tcg_accel_available) {
+ qtest_add_func("acpi/virt", test_acpi_virt_tcg);
+ qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem);
+ qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp);
+ qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb);
+ }
qtest_add_func("acpi/virt/oem-fields", test_acpi_oem_fields_virt);
}
ret = g_test_run();
--
2.26.2
^ permalink raw reply related [flat|nested] 10+ messages in thread