[PATCH v3 2/3] qapi, target/: Enable 'query-cpu-model-expansion' on all architectures
Only architectures that implement the command will return results, others will return an error message as before. Signed-off-by: Dinah Baum --- cpu.c| 20 +++ include/exec/cpu-common.h| 7 qapi/machine-target.json | 60 qapi/machine.json| 53 target/arm/arm-qmp-cmds.c| 7 ++-- target/arm/cpu.h | 7 target/i386/cpu-sysemu.c | 7 ++-- target/i386/cpu.h| 6 target/s390x/cpu.h | 7 target/s390x/cpu_models_sysemu.c | 6 ++-- 10 files changed, 110 insertions(+), 70 deletions(-) diff --git a/cpu.c b/cpu.c index 1c948d1161..a99d09cd47 100644 --- a/cpu.c +++ b/cpu.c @@ -292,6 +292,26 @@ void list_cpus(void) #endif } +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) +{ +/* XXX: implement cpu_model_expansion for targets that still miss it */ +#if defined(cpu_model_expansion) +return cpu_model_expansion(type, model, errp); +#else +error_setg(errp, "Could not query cpu model information"); +return NULL; +#endif +} + +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +return get_cpu_model_expansion_info(type, model, errp); +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(hwaddr addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 87dc9a752c..653f8a9d2b 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -6,6 +6,7 @@ #ifndef CONFIG_USER_ONLY #include "exec/hwaddr.h" #endif +#include "qapi/qapi-commands-machine.h" /** * vaddr: @@ -167,4 +168,10 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, /* vl.c */ void list_cpus(void); +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, Error **errp); + #endif /* CPU_COMMON_H */ diff --git a/qapi/machine-target.json b/qapi/machine-target.json index 3ee2f7ca6b..a658b1754b 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -139,66 +139,6 @@ 'returns': 'CpuModelBaselineInfo', 'if': 'TARGET_S390X' } -## -# @CpuModelExpansionInfo: -# -# The result of a cpu model expansion. -# -# @model: the expanded CpuModelInfo. -# -# Since: 2.8 -## -{ 'struct': 'CpuModelExpansionInfo', - 'data': { 'model': 'CpuModelInfo' }, - 'if': { 'any': [ 'TARGET_S390X', - 'TARGET_I386', - 'TARGET_ARM' ] } } - -## -# @query-cpu-model-expansion: -# -# Expands a given CPU model (or a combination of CPU model + -# additional options) to different granularities, allowing tooling to -# get an understanding what a specific CPU model looks like in QEMU -# under a certain configuration. -# -# This interface can be used to query the "host" CPU model. -# -# The data returned by this command may be affected by: -# -# * QEMU version: CPU models may look different depending on the QEMU -# version. (Except for CPU models reported as "static" in -# query-cpu-definitions.) -# * machine-type: CPU model may look different depending on the -# machine-type. (Except for CPU models reported as "static" in -# query-cpu-definitions.) -# * machine options (including accelerator): in some architectures, -# CPU models may look different depending on machine and accelerator -# options. (Except for CPU models reported as "static" in -# query-cpu-definitions.) -# * "-cpu" arguments and global properties: arguments to the -cpu -# option and global properties may affect expansion of CPU models. -# Using query-cpu-model-expansion while using these is not advised. -# -# Some architectures may not support all expansion types. s390x -# supports "full" and "static". Arm only supports "full". -# -# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU -# models is not supported, if the model cannot be expanded, if the -# model contains an unknown CPU definition name, unknown -# properties or properties with a wrong type. Also returns an -# error if an expansion type is not supported. -# -# Since: 2.8 -## -{ 'command': 'query-cpu-model-expansion', - 'data': { 'type': 'CpuModelExpansionType', -'model': 'CpuModelInfo' }, - 'returns': 'CpuModelExpansio
[PATCH v3 3/3] cpu, softmmu/vl.c: Change parsing of -cpu argument to allow -cpu cpu, help to print options for the CPU type similar to how the '-device' option works.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum Signed-off-by: Dinah Baum --- cpu.c| 41 include/qapi/qmp/qdict.h | 1 + qemu-options.hx | 7 --- qobject/qdict.c | 5 + softmmu/vl.c | 35 +- 5 files changed, 85 insertions(+), 4 deletions(-) diff --git a/cpu.c b/cpu.c index a99d09cd47..9971ffeeba 100644 --- a/cpu.c +++ b/cpu.c @@ -43,6 +43,10 @@ #include "trace/trace-root.h" #include "qemu/accel.h" #include "qemu/plugin.h" +#include "qemu/cutils.h" +#include "qemu/qemu-print.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -312,6 +316,43 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, return get_cpu_model_expansion_info(type, model, errp); } +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +CpuModelExpansionInfo *expansion_info; +QDict *qdict; +QDictEntry *qdict_entry; +const char *key; +QObject *obj; +QType q_type; +GPtrArray *array; +int i; +const char *type_name; + +expansion_info = get_cpu_model_expansion_info(type, model, errp); +if (expansion_info) { +qdict = qobject_to(QDict, expansion_info->model->props); +if (qdict) { +qemu_printf("%s features:\n", model->name); +array = g_ptr_array_new(); +for (qdict_entry = (QDictEntry *)qdict_first(qdict); qdict_entry; + qdict_entry = (QDictEntry *)qdict_next(qdict, qdict_entry)) { +g_ptr_array_add(array, qdict_entry); +} +g_ptr_array_sort(array, (GCompareFunc)dict_key_compare); +for (i = 0; i < array->len; i++) { +qdict_entry = array->pdata[i]; +key = qdict_entry_key(qdict_entry); +obj = qdict_get(qdict, key); +q_type = qobject_type(obj); +type_name = QType_str(q_type); +qemu_printf(" %s=<%s>\n", key, type_name); +} +} +} +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(hwaddr addr) { diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 82e90fc072..d0b6c3d358 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -67,5 +67,6 @@ bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value); const char *qdict_get_try_str(const QDict *qdict, const char *key); QDict *qdict_clone_shallow(const QDict *src); +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2); #endif /* QDICT_H */ diff --git a/qemu-options.hx b/qemu-options.hx index 29b98c3d4c..e0f0284927 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -169,11 +169,12 @@ SRST ERST DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, -"-cpu cpuselect CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) +"-cpu cpuselect CPU ('-cpu help' for list)\n" +"use '-cpu cpu,help' to print possible properties\n", QEMU_ARCH_ALL) SRST ``-cpu model`` -Select CPU model (``-cpu help`` for list and additional feature -selection) +Select CPU model (``-cpu help`` and ``-cpu cpu,help``) for list and additional feature +selection ERST DEF("accel", HAS_ARG, QEMU_OPTION_accel, diff --git a/qobject/qdict.c b/qobject/qdict.c index 8faff230d3..31407e62f6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -447,3 +447,8 @@ void qdict_unref(QDict *q) { qobject_unref(q); } + +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2) +{ +return g_strcmp0(qdict_entry_key(*entry1), qdict_entry_key(*entry2)); +} diff --git a/softmmu/vl.c b/softmmu/vl.c index b0b96f67fa..1fd87f2c06 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -501,6 +501,15 @@ static QemuOptsList qemu_action_opts = { }, }; +static QemuOptsList qemu_cpu_opts = { +.name = "cpu", +.implied_opt_name = "cpu", +.head = QTAILQ_HEAD_INITIALIZER(qemu_cpu_opts.head), +.desc = { +{ /* end of list */ } +}, +}; + const char *qemu_get_vm_name(void) { return qemu_name; @@ -1159,6 +1168,26 @@ static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) return 0; } +static int cpu_help_func(void *opaque, QemuOpts *opts, Error **errp) +{ +CpuModelInfo *model; + +if (cpu_option && is_help_option(cpu_option)) { +list_cpus(); +return 1; +} + +if (!cpu_option || !qemu_opt_has_help_opt(opts)) { +return 0; +} + +model = g_new0(CpuModelInfo, 1); +model->
[PATCH v3 1/3] qapi: Moved architecture agnostic data types to `machine`
Signed-off-by: Dinah Baum --- qapi/machine-target.json | 78 +--- qapi/machine.json| 77 +++ 2 files changed, 78 insertions(+), 77 deletions(-) diff --git a/qapi/machine-target.json b/qapi/machine-target.json index f0a6b72414..3ee2f7ca6b 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -4,83 +4,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. -## -# @CpuModelInfo: -# -# Virtual CPU model. -# -# A CPU model consists of the name of a CPU definition, to which delta -# changes are applied (e.g. features added/removed). Most magic values -# that an architecture might require should be hidden behind the name. -# However, if required, architectures can expose relevant properties. -# -# @name: the name of the CPU definition the model is based on -# -# @props: a dictionary of QOM properties to be applied -# -# Since: 2.8 -## -{ 'struct': 'CpuModelInfo', - 'data': { 'name': 'str', -'*props': 'any' } } - -## -# @CpuModelExpansionType: -# -# An enumeration of CPU model expansion types. -# -# @static: Expand to a static CPU model, a combination of a static -# base model name and property delta changes. As the static base -# model will never change, the expanded CPU model will be the -# same, independent of QEMU version, machine type, machine -# options, and accelerator options. Therefore, the resulting -# model can be used by tooling without having to specify a -# compatibility machine - e.g. when displaying the "host" model. -# The @static CPU models are migration-safe. -# -# @full: Expand all properties. The produced model is not guaranteed -# to be migration-safe, but allows tooling to get an insight and -# work with model details. -# -# Note: When a non-migration-safe CPU model is expanded in static -# mode, some features enabled by the CPU model may be omitted, -# because they can't be implemented by a static CPU model -# definition (e.g. cache info passthrough and PMU passthrough in -# x86). If you need an accurate representation of the features -# enabled by a non-migration-safe CPU model, use @full. If you -# need a static representation that will keep ABI compatibility -# even when changing QEMU version or machine-type, use @static -# (but keep in mind that some features may be omitted). -# -# Since: 2.8 -## -{ 'enum': 'CpuModelExpansionType', - 'data': [ 'static', 'full' ] } - -## -# @CpuModelCompareResult: -# -# An enumeration of CPU model comparison results. The result is -# usually calculated using e.g. CPU features or CPU generations. -# -# @incompatible: If model A is incompatible to model B, model A is not -# guaranteed to run where model B runs and the other way around. -# -# @identical: If model A is identical to model B, model A is -# guaranteed to run where model B runs and the other way around. -# -# @superset: If model A is a superset of model B, model B is -# guaranteed to run where model A runs. There are no guarantees -# about the other way. -# -# @subset: If model A is a subset of model B, model A is guaranteed to -# run where model B runs. There are no guarantees about the other -# way. -# -# Since: 2.8 -## -{ 'enum': 'CpuModelCompareResult', - 'data': [ 'incompatible', 'identical', 'superset', 'subset' ] } +{ 'include': 'machine.json' } ## # @CpuModelBaselineInfo: diff --git a/qapi/machine.json b/qapi/machine.json index a08b6576ca..192c781310 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1691,3 +1691,80 @@ { 'command': 'dumpdtb', 'data': { 'filename': 'str' }, 'if': 'CONFIG_FDT' } + +## +# @CpuModelInfo: +# +# Virtual CPU model. +# +# A CPU model consists of the name of a CPU definition, to which delta +# changes are applied (e.g. features added/removed). Most magic values +# that an architecture might require should be hidden behind the name. +# However, if required, architectures can expose relevant properties. +# +# @name: the name of the CPU definition the model is based on +# +# @props: a dictionary of QOM properties to be applied +# +# Since: 2.8 +## +{ 'struct': 'CpuModelInfo', + 'data': { 'name': 'str', '*props': 'any' } } + +## +# @CpuModelExpansionType: +# +# An enumeration of CPU model expansion types. +# +# @static: Expand to a static CPU model, a combination of a static +# base model name and property delta changes. As the static base +# model will never change, the expanded CPU model will be the +# same, independent of QEMU version, machine type, machine +# options, and accelerator options. Therefore, the resulting +# model can be used by tooling without having to specify a +# compatibility machine - e.g. when displaying the "host" model. +# The @static CPU models are migration-safe. +# +# @full: E
[PATCH v3 0/3] Enable -cpu ,help
This patch adds the ability to query for CPU features. Currently it is limited to the architecture that support feature probing (arm, i386, and s390x). Ex: athlon features: 3dnow= 3dnowext= 3dnowprefetch= ... Suggested-by: Peter Maydell Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1480 Dinah Baum (3): qapi: Moved architecture agnostic data types to `machine` qapi, target/: Enable 'query-cpu-model-expansion' on all architectures cpu, softmmu/vl.c: Change parsing of -cpu argument to allow -cpu cpu,help to print options for the CPU type similar to how the '-device' option works. cpu.c| 61 ++ include/exec/cpu-common.h| 7 ++ include/qapi/qmp/qdict.h | 1 + qapi/machine-target.json | 138 +-- qapi/machine.json| 130 + qemu-options.hx | 7 +- qobject/qdict.c | 5 ++ softmmu/vl.c | 35 +++- target/arm/arm-qmp-cmds.c| 7 +- target/arm/cpu.h | 7 ++ target/i386/cpu-sysemu.c | 7 +- target/i386/cpu.h| 6 ++ target/s390x/cpu.h | 7 ++ target/s390x/cpu_models_sysemu.c | 6 +- 14 files changed, 273 insertions(+), 151 deletions(-) -- 2.30.2
[PATCH v2 1/3] qapi/machine-target: refactor machine-target
Moved architecture agnostic data types to their own file to avoid "attempt to use poisoned TARGET_*" error that results when including qapi header with commands that aren't defined for all architectures. Required to implement enabling `query-cpu-model-expansion` on all architectures Signed-off-by: Dinah Baum Reviewed-by: Philippe Mathieu-Daudé --- MAINTAINERS | 1 + qapi/machine-target-common.json | 79 + qapi/machine-target.json| 73 +- qapi/meson.build| 1 + 4 files changed, 82 insertions(+), 72 deletions(-) create mode 100644 qapi/machine-target-common.json diff --git a/MAINTAINERS b/MAINTAINERS index ef45b5e71e..fbc4d7be66 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1751,6 +1751,7 @@ F: hw/core/numa.c F: hw/cpu/cluster.c F: qapi/machine.json F: qapi/machine-target.json +F: qapi/machine-target-common.json F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h diff --git a/qapi/machine-target-common.json b/qapi/machine-target-common.json new file mode 100644 index 00..1e6da3177d --- /dev/null +++ b/qapi/machine-target-common.json @@ -0,0 +1,79 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Common data types for machine target commands +## + +## +# @CpuModelInfo: +# +# Virtual CPU model. +# +# A CPU model consists of the name of a CPU definition, to which +# delta changes are applied (e.g. features added/removed). Most magic values +# that an architecture might require should be hidden behind the name. +# However, if required, architectures can expose relevant properties. +# +# @name: the name of the CPU definition the model is based on +# @props: a dictionary of QOM properties to be applied +# +# Since: 2.8 +## +{ 'struct': 'CpuModelInfo', +'data': { 'name': 'str', + '*props': 'any' } } + +## +# @CpuModelExpansionType: +# +# An enumeration of CPU model expansion types. +# +# @static: Expand to a static CPU model, a combination of a static base +# model name and property delta changes. As the static base model will +# never change, the expanded CPU model will be the same, independent of +# QEMU version, machine type, machine options, and accelerator options. +# Therefore, the resulting model can be used by tooling without having +# to specify a compatibility machine - e.g. when displaying the "host" +# model. The @static CPU models are migration-safe. + +# @full: Expand all properties. The produced model is not guaranteed to be +#migration-safe, but allows tooling to get an insight and work with +#model details. +# +# Note: When a non-migration-safe CPU model is expanded in static mode, some +# features enabled by the CPU model may be omitted, because they can't be +# implemented by a static CPU model definition (e.g. cache info passthrough and +# PMU passthrough in x86). If you need an accurate representation of the +# features enabled by a non-migration-safe CPU model, use @full. If you need a +# static representation that will keep ABI compatibility even when changing QEMU +# version or machine-type, use @static (but keep in mind that some features may +# be omitted). +# +# Since: 2.8 +## +{ 'enum': 'CpuModelExpansionType', + 'data': [ 'static', 'full' ] } + +## +# @CpuModelCompareResult: +# +# An enumeration of CPU model comparison results. The result is usually +# calculated using e.g. CPU features or CPU generations. +# +# @incompatible: If model A is incompatible to model B, model A is not +#guaranteed to run where model B runs and the other way around. +# +# @identical: If model A is identical to model B, model A is guaranteed to run +# where model B runs and the other way around. +# +# @superset: If model A is a superset of model B, model B is guaranteed to run +#where model A runs. There are no guarantees about the other way. +# +# @subset: If model A is a subset of model B, model A is guaranteed to run +# where model B runs. There are no guarantees about the other way. +# +# Since: 2.8 +## +{ 'enum': 'CpuModelCompareResult', + 'data': [ 'incompatible', 'identical', 'superset', 'subset' ] } diff --git a/qapi/machine-target.json b/qapi/machine-target.json index 2e267fa458..1cacfde88e 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -4,78 +4,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. -## -# @CpuModelInfo: -# -# Virtual CPU model. -# -# A CPU model consists of the name of a CPU definition, to which -# delta changes are applied (e.g. features added/removed). Most magic values -# that an architecture might require should be hidden behind the name. -# However, if required, architectures can expose relevant properties. -# -# @name:
[PATCH v2 2/3] cpu, qapi, target/arm, i386, s390x: Generalize query-cpu-model-expansion
This patch enables 'query-cpu-model-expansion' on all architectures. Only architectures that implement the command will return results, others will return an error message as before. This patch lays the groundwork for parsing a -cpu cpu,help option as specified in https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- cpu.c| 20 include/exec/cpu-common.h| 8 + qapi/machine-target-common.json | 51 + qapi/machine-target.json | 56 target/arm/arm-qmp-cmds.c| 7 ++-- target/arm/cpu.h | 7 +++- target/i386/cpu-sysemu.c | 7 ++-- target/i386/cpu.h| 6 target/s390x/cpu.h | 7 target/s390x/cpu_models_sysemu.c | 6 ++-- 10 files changed, 108 insertions(+), 67 deletions(-) diff --git a/cpu.c b/cpu.c index 849bac062c..daf4e1ff0d 100644 --- a/cpu.c +++ b/cpu.c @@ -292,6 +292,26 @@ void list_cpus(const char *optarg) #endif } +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) +{ +/* XXX: implement cpu_model_expansion for targets that still miss it */ +#if defined(cpu_model_expansion) +return cpu_model_expansion(type, model, errp); +#else +error_setg(errp, "Could not query cpu model information"); +return NULL; +#endif +} + +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +return get_cpu_model_expansion_info(type, model, errp); +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 6feaa40ca7..ec6024dfde 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -7,6 +7,8 @@ #include "exec/hwaddr.h" #endif +#include "qapi/qapi-commands-machine-target-common.h" + /** * vaddr: * Type wide enough to contain any #target_ulong virtual address. @@ -166,5 +168,11 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, extern int singlestep; void list_cpus(const char *optarg); +typedef void (*cpu_model_expansion_func)(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp); +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); #endif /* CPU_COMMON_H */ diff --git a/qapi/machine-target-common.json b/qapi/machine-target-common.json index 1e6da3177d..44713e9935 100644 --- a/qapi/machine-target-common.json +++ b/qapi/machine-target-common.json @@ -77,3 +77,54 @@ ## { 'enum': 'CpuModelCompareResult', 'data': [ 'incompatible', 'identical', 'superset', 'subset' ] } + +## +# @CpuModelExpansionInfo: +# +# The result of a cpu model expansion. +# +# @model: the expanded CpuModelInfo. +# +# Since: 2.8 +## +{ 'struct': 'CpuModelExpansionInfo', + 'data': { 'model': 'CpuModelInfo' } } + +## +# @query-cpu-model-expansion: +# +# Expands a given CPU model (or a combination of CPU model + additional options) +# to different granularities, allowing tooling to get an understanding what a +# specific CPU model looks like in QEMU under a certain configuration. +# +# This interface can be used to query the "host" CPU model. +# +# The data returned by this command may be affected by: +# +# * QEMU version: CPU models may look different depending on the QEMU version. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine-type: CPU model may look different depending on the machine-type. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine options (including accelerator): in some architectures, CPU models +# may look different depending on machine and accelerator options. (Except for +# CPU models reported as "static" in query-cpu-definitions.) +# * "-cpu" arguments and global properties: arguments to the -cpu option and +# global properties may affect expansion of CPU models. Using +# query-cpu-model-expansion while using these is not advised. +# +# Some architectures may not support all expansion types. s390x supports +# "full" and "static". Arm only supports "full". +# +# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU models is +# not supported, if the model cannot be expanded, if the model contains +# an unknown CPU definition na
[PATCH v2 3/3] cpu, qdict, vl: Enable printing options for CPU type
Change parsing of -cpu argument to allow -cpu cpu,help to print options for the CPU type similar to how the '-device' option works. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- cpu.c | 41 +++ include/exec/cpu-common.h | 2 ++ include/qapi/qmp/qdict.h | 2 ++ qemu-options.hx | 7 --- qobject/qdict.c | 5 + softmmu/vl.c | 36 -- 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/cpu.c b/cpu.c index daf4e1ff0d..5f8a72e51f 100644 --- a/cpu.c +++ b/cpu.c @@ -23,7 +23,9 @@ #include "exec/target_page.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" +#include "qemu/qemu-print.h" #include "migration/vmstate.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -43,6 +45,8 @@ #include "trace/trace-root.h" #include "qemu/accel.h" #include "qemu/plugin.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -312,6 +316,43 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, return get_cpu_model_expansion_info(type, model, errp); } +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +CpuModelExpansionInfo *expansion_info; +QDict *qdict; +QDictEntry *qdict_entry; +const char *key; +QObject *obj; +QType q_type; +GPtrArray *array; +int i; +const char *type_name; + +expansion_info = get_cpu_model_expansion_info(type, model, errp); +if (expansion_info) { +qdict = qobject_to(QDict, expansion_info->model->props); +if (qdict) { +qemu_printf("%s features:\n", model->name); +array = g_ptr_array_new(); +for (qdict_entry = (QDictEntry *)qdict_first(qdict); qdict_entry; + qdict_entry = (QDictEntry *)qdict_next(qdict, qdict_entry)) { +g_ptr_array_add(array, qdict_entry); +} +g_ptr_array_sort(array, (GCompareFunc)dict_key_compare); +for (i = 0; i < array->len; i++) { +qdict_entry = array->pdata[i]; +key = qdict_entry_key(qdict_entry); +obj = qdict_get(qdict, key); +q_type = qobject_type(obj); +type_name = QType_str(q_type); +qemu_printf(" %s=<%s>\n", key, type_name); +} +} +} +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index ec6024dfde..8fc05307ad 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -174,5 +174,7 @@ typedef void (*cpu_model_expansion_func)(CpuModelExpansionType type, CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, CpuModelInfo *model, Error **errp); +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, Error **errp); #endif /* CPU_COMMON_H */ diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 82e90fc072..1ff9523a13 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -68,4 +68,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key); QDict *qdict_clone_shallow(const QDict *src); +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2); + #endif /* QDICT_H */ diff --git a/qemu-options.hx b/qemu-options.hx index 59bdf67a2c..10601626b7 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -169,11 +169,12 @@ SRST ERST DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, -"-cpu cpuselect CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) +"-cpu cpuselect CPU ('-cpu help' for list)\n" +"use '-cpu cpu,help' to print possible properties\n", QEMU_ARCH_ALL) SRST ``-cpu model`` -Select CPU model (``-cpu help`` for list and additional feature -selection) +Select CPU model (``-cpu help`` and ``-cpu cpu,help``) for list and additional feature +selection ERST DEF("accel", HAS_ARG, QEMU_OPTION_accel, diff --git a/qobject/qdict.c b/qobject/qdict.c index 8faff230d3..31407e62f6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -447,3 +447,8 @@ void qdict_unref(QDict *q) { qobject_unref(q); } + +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2) +{ +return g_strcmp0(qdic
[RESEND PATCH v2 0/3] Enable -cpu ,help
Part 1 is a refactor/code motion patch for qapi/machine target required for setup of Part 2 which enables query-cpu-model-expansion on all architectures Part 3 implements the ',help' feature Limitations: Currently only 'FULL' expansion queries are implemented since that's the only type enabled on the architectures that allow feature probing Unlike the 'device,help' command, default values aren't printed Changes since v2: Rebase Dinah Baum (3): qapi/machine-target: refactor machine-target cpu, qapi, target/arm, i386, s390x: Generalize query-cpu-model-expansion cpu, qdict, vl: Enable printing options for CPU type MAINTAINERS | 1 + cpu.c| 61 +++ include/exec/cpu-common.h| 10 +++ include/qapi/qmp/qdict.h | 2 + qapi/machine-target-common.json | 130 +++ qapi/machine-target.json | 129 +- qapi/meson.build | 1 + qemu-options.hx | 7 +- qobject/qdict.c | 5 ++ softmmu/vl.c | 36 - target/arm/arm-qmp-cmds.c| 7 +- target/arm/cpu.h | 7 +- target/i386/cpu-sysemu.c | 7 +- target/i386/cpu.h| 6 ++ target/s390x/cpu.h | 7 ++ target/s390x/cpu_models_sysemu.c | 6 +- 16 files changed, 278 insertions(+), 144 deletions(-) create mode 100644 qapi/machine-target-common.json -- 2.30.2
[PATCH v2 2/3] cpu, qapi, target/arm, i386, s390x: Generalize query-cpu-model-expansion
This patch enables 'query-cpu-model-expansion' on all architectures. Only architectures that implement the command will return results, others will return an error message as before. This patch lays the groundwork for parsing a -cpu cpu,help option as specified in https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- cpu.c| 20 include/exec/cpu-common.h| 8 + qapi/machine-target-common.json | 51 + qapi/machine-target.json | 56 target/arm/arm-qmp-cmds.c| 7 ++-- target/arm/cpu.h | 7 +++- target/i386/cpu-sysemu.c | 7 ++-- target/i386/cpu.h| 6 target/s390x/cpu.h | 7 target/s390x/cpu_models_sysemu.c | 6 ++-- 10 files changed, 108 insertions(+), 67 deletions(-) diff --git a/cpu.c b/cpu.c index 567b23af46..c09edc4556 100644 --- a/cpu.c +++ b/cpu.c @@ -291,6 +291,26 @@ void list_cpus(const char *optarg) #endif } +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) +{ +/* XXX: implement cpu_model_expansion for targets that still miss it */ +#if defined(cpu_model_expansion) +return cpu_model_expansion(type, model, errp); +#else +error_setg(errp, "Could not query cpu model information"); +return NULL; +#endif +} + +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +return get_cpu_model_expansion_info(type, model, errp); +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 6feaa40ca7..ec6024dfde 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -7,6 +7,8 @@ #include "exec/hwaddr.h" #endif +#include "qapi/qapi-commands-machine-target-common.h" + /** * vaddr: * Type wide enough to contain any #target_ulong virtual address. @@ -166,5 +168,11 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, extern int singlestep; void list_cpus(const char *optarg); +typedef void (*cpu_model_expansion_func)(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp); +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); #endif /* CPU_COMMON_H */ diff --git a/qapi/machine-target-common.json b/qapi/machine-target-common.json index 1e6da3177d..44713e9935 100644 --- a/qapi/machine-target-common.json +++ b/qapi/machine-target-common.json @@ -77,3 +77,54 @@ ## { 'enum': 'CpuModelCompareResult', 'data': [ 'incompatible', 'identical', 'superset', 'subset' ] } + +## +# @CpuModelExpansionInfo: +# +# The result of a cpu model expansion. +# +# @model: the expanded CpuModelInfo. +# +# Since: 2.8 +## +{ 'struct': 'CpuModelExpansionInfo', + 'data': { 'model': 'CpuModelInfo' } } + +## +# @query-cpu-model-expansion: +# +# Expands a given CPU model (or a combination of CPU model + additional options) +# to different granularities, allowing tooling to get an understanding what a +# specific CPU model looks like in QEMU under a certain configuration. +# +# This interface can be used to query the "host" CPU model. +# +# The data returned by this command may be affected by: +# +# * QEMU version: CPU models may look different depending on the QEMU version. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine-type: CPU model may look different depending on the machine-type. +# (Except for CPU models reported as "static" in query-cpu-definitions.) +# * machine options (including accelerator): in some architectures, CPU models +# may look different depending on machine and accelerator options. (Except for +# CPU models reported as "static" in query-cpu-definitions.) +# * "-cpu" arguments and global properties: arguments to the -cpu option and +# global properties may affect expansion of CPU models. Using +# query-cpu-model-expansion while using these is not advised. +# +# Some architectures may not support all expansion types. s390x supports +# "full" and "static". Arm only supports "full". +# +# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU models is +# not supported, if the model cannot be expanded, if the model contains +# an unknown CPU definition na
[PATCH v2 3/3] cpu, qdict, vl: Enable printing options for CPU type
Change parsing of -cpu argument to allow -cpu cpu,help to print options for the CPU type similar to how the '-device' option works. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- cpu.c | 41 +++ include/exec/cpu-common.h | 2 ++ include/qapi/qmp/qdict.h | 2 ++ qemu-options.hx | 7 --- qobject/qdict.c | 5 + softmmu/vl.c | 36 -- 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/cpu.c b/cpu.c index c09edc4556..fe33c51061 100644 --- a/cpu.c +++ b/cpu.c @@ -23,7 +23,9 @@ #include "exec/target_page.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" +#include "qemu/qemu-print.h" #include "migration/vmstate.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -42,6 +44,8 @@ #include "hw/core/accel-cpu.h" #include "trace/trace-root.h" #include "qemu/accel.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -311,6 +315,43 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, return get_cpu_model_expansion_info(type, model, errp); } +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +CpuModelExpansionInfo *expansion_info; +QDict *qdict; +QDictEntry *qdict_entry; +const char *key; +QObject *obj; +QType q_type; +GPtrArray *array; +int i; +const char *type_name; + +expansion_info = get_cpu_model_expansion_info(type, model, errp); +if (expansion_info) { +qdict = qobject_to(QDict, expansion_info->model->props); +if (qdict) { +qemu_printf("%s features:\n", model->name); +array = g_ptr_array_new(); +for (qdict_entry = (QDictEntry *)qdict_first(qdict); qdict_entry; + qdict_entry = (QDictEntry *)qdict_next(qdict, qdict_entry)) { +g_ptr_array_add(array, qdict_entry); +} +g_ptr_array_sort(array, (GCompareFunc)dict_key_compare); +for (i = 0; i < array->len; i++) { +qdict_entry = array->pdata[i]; +key = qdict_entry_key(qdict_entry); +obj = qdict_get(qdict, key); +q_type = qobject_type(obj); +type_name = QType_str(q_type); +qemu_printf(" %s=<%s>\n", key, type_name); +} +} +} +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index ec6024dfde..8fc05307ad 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -174,5 +174,7 @@ typedef void (*cpu_model_expansion_func)(CpuModelExpansionType type, CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, CpuModelInfo *model, Error **errp); +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, Error **errp); #endif /* CPU_COMMON_H */ diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 82e90fc072..1ff9523a13 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -68,4 +68,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key); QDict *qdict_clone_shallow(const QDict *src); +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2); + #endif /* QDICT_H */ diff --git a/qemu-options.hx b/qemu-options.hx index d42f60fb91..d5284b9330 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -169,11 +169,12 @@ SRST ERST DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, -"-cpu cpuselect CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) +"-cpu cpuselect CPU ('-cpu help' for list)\n" +"use '-cpu cpu,help' to print possible properties\n", QEMU_ARCH_ALL) SRST ``-cpu model`` -Select CPU model (``-cpu help`` for list and additional feature -selection) +Select CPU model (``-cpu help`` and ``-cpu cpu,help``) for list and additional feature +selection ERST DEF("accel", HAS_ARG, QEMU_OPTION_accel, diff --git a/qobject/qdict.c b/qobject/qdict.c index 8faff230d3..31407e62f6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -447,3 +447,8 @@ void qdict_unref(QDict *q) { qobject_unref(q); } + +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2) +{ +return g_strcmp0(qdic
[PATCH v2 1/3] qapi/machine-target: refactor machine-target
Moved architecture agnostic data types to their own file to avoid "attempt to use poisoned TARGET_*" error that results when including qapi header with commands that aren't defined for all architectures. Required to implement enabling `query-cpu-model-expansion` on all architectures Signed-off-by: Dinah Baum --- MAINTAINERS | 1 + qapi/machine-target-common.json | 79 + qapi/machine-target.json| 73 +- qapi/meson.build| 1 + 4 files changed, 82 insertions(+), 72 deletions(-) create mode 100644 qapi/machine-target-common.json diff --git a/MAINTAINERS b/MAINTAINERS index 95c957d587..bc4a6ba399 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1750,6 +1750,7 @@ F: hw/core/numa.c F: hw/cpu/cluster.c F: qapi/machine.json F: qapi/machine-target.json +F: qapi/machine-target-common.json F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h diff --git a/qapi/machine-target-common.json b/qapi/machine-target-common.json new file mode 100644 index 00..1e6da3177d --- /dev/null +++ b/qapi/machine-target-common.json @@ -0,0 +1,79 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Common data types for machine target commands +## + +## +# @CpuModelInfo: +# +# Virtual CPU model. +# +# A CPU model consists of the name of a CPU definition, to which +# delta changes are applied (e.g. features added/removed). Most magic values +# that an architecture might require should be hidden behind the name. +# However, if required, architectures can expose relevant properties. +# +# @name: the name of the CPU definition the model is based on +# @props: a dictionary of QOM properties to be applied +# +# Since: 2.8 +## +{ 'struct': 'CpuModelInfo', +'data': { 'name': 'str', + '*props': 'any' } } + +## +# @CpuModelExpansionType: +# +# An enumeration of CPU model expansion types. +# +# @static: Expand to a static CPU model, a combination of a static base +# model name and property delta changes. As the static base model will +# never change, the expanded CPU model will be the same, independent of +# QEMU version, machine type, machine options, and accelerator options. +# Therefore, the resulting model can be used by tooling without having +# to specify a compatibility machine - e.g. when displaying the "host" +# model. The @static CPU models are migration-safe. + +# @full: Expand all properties. The produced model is not guaranteed to be +#migration-safe, but allows tooling to get an insight and work with +#model details. +# +# Note: When a non-migration-safe CPU model is expanded in static mode, some +# features enabled by the CPU model may be omitted, because they can't be +# implemented by a static CPU model definition (e.g. cache info passthrough and +# PMU passthrough in x86). If you need an accurate representation of the +# features enabled by a non-migration-safe CPU model, use @full. If you need a +# static representation that will keep ABI compatibility even when changing QEMU +# version or machine-type, use @static (but keep in mind that some features may +# be omitted). +# +# Since: 2.8 +## +{ 'enum': 'CpuModelExpansionType', + 'data': [ 'static', 'full' ] } + +## +# @CpuModelCompareResult: +# +# An enumeration of CPU model comparison results. The result is usually +# calculated using e.g. CPU features or CPU generations. +# +# @incompatible: If model A is incompatible to model B, model A is not +#guaranteed to run where model B runs and the other way around. +# +# @identical: If model A is identical to model B, model A is guaranteed to run +# where model B runs and the other way around. +# +# @superset: If model A is a superset of model B, model B is guaranteed to run +#where model A runs. There are no guarantees about the other way. +# +# @subset: If model A is a subset of model B, model A is guaranteed to run +# where model B runs. There are no guarantees about the other way. +# +# Since: 2.8 +## +{ 'enum': 'CpuModelCompareResult', + 'data': [ 'incompatible', 'identical', 'superset', 'subset' ] } diff --git a/qapi/machine-target.json b/qapi/machine-target.json index 2e267fa458..1cacfde88e 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -4,78 +4,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. -## -# @CpuModelInfo: -# -# Virtual CPU model. -# -# A CPU model consists of the name of a CPU definition, to which -# delta changes are applied (e.g. features added/removed). Most magic values -# that an architecture might require should be hidden behind the name. -# However, if required, architectures can expose relevant properties. -# -# @name: the name of the CPU definitio
[PATCH v2 0/3] Enable -cpu ,help
Part 1 is a refactor/code motion patch for qapi/machine target required for setup of Part 2 which enables query-cpu-model-expansion on all architectures Part 3 implements the ',help' feature Limitations: Currently only 'FULL' expansion queries are implemented since that's the only type enabled on the architectures that allow feature probing Unlike the 'device,help' command, default values aren't printed Dinah Baum (3): qapi/machine-target: refactor machine-target cpu, qapi, target/arm, i386, s390x: Generalize query-cpu-model-expansion cpu, qdict, vl: Enable printing options for CPU type MAINTAINERS | 1 + cpu.c| 61 +++ include/exec/cpu-common.h| 10 +++ include/qapi/qmp/qdict.h | 2 + qapi/machine-target-common.json | 130 +++ qapi/machine-target.json | 129 +- qapi/meson.build | 1 + qemu-options.hx | 7 +- qobject/qdict.c | 5 ++ softmmu/vl.c | 36 - target/arm/arm-qmp-cmds.c| 7 +- target/arm/cpu.h | 7 +- target/i386/cpu-sysemu.c | 7 +- target/i386/cpu.h| 6 ++ target/s390x/cpu.h | 7 ++ target/s390x/cpu_models_sysemu.c | 6 +- 16 files changed, 278 insertions(+), 144 deletions(-) create mode 100644 qapi/machine-target-common.json -- 2.30.2
[PATCH 1/2] cpu, qapi, target/arm, i386, s390x: Refactor query-cpu-model-expansion
This patch enables 'query-cpu-model-expansion' on all architectures. Only architectures that implement the command will return results, others will return an error message as before. This patch lays the groundwork for parsing a -cpu cpu,help option as specified in https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- MAINTAINERS | 1 + cpu.c| 20 + include/exec/cpu-common.h| 8 ++ qapi/machine-target-common.json | 129 +++ qapi/machine-target.json | 129 +-- qapi/meson.build | 1 + target/arm/arm-qmp-cmds.c| 7 +- target/arm/cpu.h | 7 +- target/i386/cpu-sysemu.c | 7 +- target/i386/cpu.h| 6 ++ target/s390x/cpu.h | 7 ++ target/s390x/cpu_models_sysemu.c | 6 +- 12 files changed, 189 insertions(+), 139 deletions(-) create mode 100644 qapi/machine-target-common.json diff --git a/MAINTAINERS b/MAINTAINERS index 2f2f4de7cc..d025df477e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1750,6 +1750,7 @@ F: hw/core/numa.c F: hw/cpu/cluster.c F: qapi/machine.json F: qapi/machine-target.json +F: qapi/machine-target-common.json F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h diff --git a/cpu.c b/cpu.c index 567b23af46..c09edc4556 100644 --- a/cpu.c +++ b/cpu.c @@ -291,6 +291,26 @@ void list_cpus(const char *optarg) #endif } +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) +{ +/* XXX: implement cpu_model_expansion for targets that still miss it */ +#if defined(cpu_model_expansion) +return cpu_model_expansion(type, model, errp); +#else +error_setg(errp, "Could not query cpu model information"); +return NULL; +#endif +} + +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +return get_cpu_model_expansion_info(type, model, errp); +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 6feaa40ca7..ec6024dfde 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -7,6 +7,8 @@ #include "exec/hwaddr.h" #endif +#include "qapi/qapi-commands-machine-target-common.h" + /** * vaddr: * Type wide enough to contain any #target_ulong virtual address. @@ -166,5 +168,11 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, extern int singlestep; void list_cpus(const char *optarg); +typedef void (*cpu_model_expansion_func)(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp); +CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); #endif /* CPU_COMMON_H */ diff --git a/qapi/machine-target-common.json b/qapi/machine-target-common.json new file mode 100644 index 00..e0374c5366 --- /dev/null +++ b/qapi/machine-target-common.json @@ -0,0 +1,129 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Common data types for machine target commands +## + +## +# @CpuModelInfo: +# +# Virtual CPU model. +# +# A CPU model consists of the name of a CPU definition, to which +# delta changes are applied (e.g. features added/removed). Most magic values +# that an architecture might require should be hidden behind the name. +# However, if required, architectures can expose relevant properties. +# +# @name: the name of the CPU definition the model is based on +# @props: a dictionary of QOM properties to be applied +# +# Since: 2.8 +## +{ 'struct': 'CpuModelInfo', +'data': { 'name': 'str', + '*props': 'any' } } + +## +# @CpuModelExpansionType: +# +# An enumeration of CPU model expansion types. +# +# @static: Expand to a static CPU model, a combination of a static base +# model name and property delta changes. As the static base model will +# never change, the expanded CPU model will be the same, independent of +# QEMU version, machine type, machine options, and accelerator options. +# Therefore, the resulting model can be used by tooling without having +# to specify a compatibility machine - e.g. when displaying the "host" +# model. The @static CPU models are migration-safe. + +# @full: Expand all properties. The produced model is not guaranteed to be +#migration-safe, but a
[PATCH 0/2] *** Enable -cpu ,help ***
This patch series enables printing the CPU options using '-cpu cpu,help' as requested in https://gitlab.com/qemu-project/qemu/-/issues/1480 Sample output: athlon features: 3dnow= 3dnowext= 3dnowprefetch= ... Part 1 is a refactor patch that enables query-cpu-model-expansion on all architectures, but doesn't implement any additional feature probing. Currently only arm, i386, and s390x support full feature probing. This lays for the groundwork for Part 2 which actually implements the ',help' feature Limitations: Currently only 'FULL' expansion queries are implemented since that's the only type enabled on the architectures that allow feature probing Unlike the 'device,help' command, default values aren't printed Dinah Baum (2): cpu, qapi, target/arm, i386, s390x: Refactor query-cpu-model-expansion cpu, qdict, vl: Enable printing options for CPU type MAINTAINERS | 1 + cpu.c| 61 +++ include/exec/cpu-common.h| 10 +++ include/qapi/qmp/qdict.h | 2 + qapi/machine-target-common.json | 129 +++ qapi/machine-target.json | 129 +-- qapi/meson.build | 1 + qemu-options.hx | 7 +- qobject/qdict.c | 5 ++ softmmu/vl.c | 36 - target/arm/arm-qmp-cmds.c| 7 +- target/arm/cpu.h | 7 +- target/i386/cpu-sysemu.c | 7 +- target/i386/cpu.h| 6 ++ target/s390x/cpu.h | 7 ++ target/s390x/cpu_models_sysemu.c | 6 +- 16 files changed, 277 insertions(+), 144 deletions(-) create mode 100644 qapi/machine-target-common.json -- 2.30.2
[PATCH 2/2] cpu, qdict, vl: Enable printing options for CPU type
Change parsing of -cpu argument to allow -cpu cpu,help to print options for the CPU type similar to how the '-device' option works. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- cpu.c | 41 +++ include/exec/cpu-common.h | 2 ++ include/qapi/qmp/qdict.h | 2 ++ qemu-options.hx | 7 --- qobject/qdict.c | 5 + softmmu/vl.c | 36 -- 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/cpu.c b/cpu.c index c09edc4556..fe33c51061 100644 --- a/cpu.c +++ b/cpu.c @@ -23,7 +23,9 @@ #include "exec/target_page.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" +#include "qemu/qemu-print.h" #include "migration/vmstate.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -42,6 +44,8 @@ #include "hw/core/accel-cpu.h" #include "trace/trace-root.h" #include "qemu/accel.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -311,6 +315,43 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, return get_cpu_model_expansion_info(type, model, errp); } +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ +CpuModelExpansionInfo *expansion_info; +QDict *qdict; +QDictEntry *qdict_entry; +const char *key; +QObject *obj; +QType q_type; +GPtrArray *array; +int i; +const char *type_name; + +expansion_info = get_cpu_model_expansion_info(type, model, errp); +if (expansion_info) { +qdict = qobject_to(QDict, expansion_info->model->props); +if (qdict) { +qemu_printf("%s features:\n", model->name); +array = g_ptr_array_new(); +for (qdict_entry = (QDictEntry *)qdict_first(qdict); qdict_entry; + qdict_entry = (QDictEntry *)qdict_next(qdict, qdict_entry)) { +g_ptr_array_add(array, qdict_entry); +} +g_ptr_array_sort(array, (GCompareFunc)dict_key_compare); +for (i = 0; i < array->len; i++) { +qdict_entry = array->pdata[i]; +key = qdict_entry_key(qdict_entry); +obj = qdict_get(qdict, key); +q_type = qobject_type(obj); +type_name = QType_str(q_type); +qemu_printf(" %s=<%s>\n", key, type_name); +} +} +} +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index ec6024dfde..8fc05307ad 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -174,5 +174,7 @@ typedef void (*cpu_model_expansion_func)(CpuModelExpansionType type, CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType type, CpuModelInfo *model, Error **errp); +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, Error **errp); #endif /* CPU_COMMON_H */ diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 82e90fc072..1ff9523a13 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -68,4 +68,6 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key); QDict *qdict_clone_shallow(const QDict *src); +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2); + #endif /* QDICT_H */ diff --git a/qemu-options.hx b/qemu-options.hx index d42f60fb91..d5284b9330 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -169,11 +169,12 @@ SRST ERST DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, -"-cpu cpuselect CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) +"-cpu cpuselect CPU ('-cpu help' for list)\n" +"use '-cpu cpu,help' to print possible properties\n", QEMU_ARCH_ALL) SRST ``-cpu model`` -Select CPU model (``-cpu help`` for list and additional feature -selection) +Select CPU model (``-cpu help`` and ``-cpu cpu,help``) for list and additional feature +selection ERST DEF("accel", HAS_ARG, QEMU_OPTION_accel, diff --git a/qobject/qdict.c b/qobject/qdict.c index 8faff230d3..31407e62f6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -447,3 +447,8 @@ void qdict_unref(QDict *q) { qobject_unref(q); } + +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2) +{ +return g_strcmp0(qdic
[PATCH v4] configure: Add 'mkdir build' check
QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created. Checking if 'mkdir dir' succeeds prevents this error. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321 Signed-off-by: Dinah Baum Reviewed-by: Peter Maydell --- configure | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/configure b/configure index cf6db3d551..1ef3e7f77d 100755 --- a/configure +++ b/configure @@ -31,7 +31,12 @@ then fi fi -mkdir build +if ! mkdir build || ! touch $MARKER +then +echo "ERROR: Could not create ./build directory. Check the permissions on" +echo "your source directory, or try doing an out-of-tree build." +exit 1 +fi touch $MARKER cat > GNUmakefile <<'EOF' -- 2.30.2
[PATCH v3] configure: Add 'mkdir build' check
QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created. Checking if 'mkdir dir' succeeds prevents this error. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321 Signed-off-by: Dinah Baum --- Changes since v2: Updated error message Reverted changes to 'help' command configure | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 00415f0b48..784f9d18a5 100755 --- a/configure +++ b/configure @@ -31,7 +31,12 @@ then fi fi -mkdir build +if ! mkdir build || ! touch $MARKER +then +echo "ERROR: Could not create ./build directory. Check the permissions on +your source directory, or try doing an out-of-tree build." +exit 1 +fi touch $MARKER cat > GNUmakefile <<'EOF' -- 2.30.2
[PATCH 1/2] configure: Add 'mkdir build' check
QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created. Checking if 'mkdir dir' succeeds prevents this error. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321 --- configure | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 64960c6000..3b384914ce 100755 --- a/configure +++ b/configure @@ -31,10 +31,11 @@ then fi fi -mkdir build -touch $MARKER +if mkdir build +then +touch $MARKER -cat > GNUmakefile <<'EOF' +cat > GNUmakefile <<'EOF' # This file is auto-generated by configure to support in-source tree # 'make' command invocation @@ -56,8 +57,12 @@ force: ; GNUmakefile: ; EOF -cd build -exec "$source_path/configure" "$@" +cd build +exec "$source_path/configure" "$@" +else +echo "ERROR: Unable to use ./build dir, try using a ../qemu/configure build" +exit 1 +fi fi # Temporary directory used for files created while -- 2.30.2
[PATCH 2/2] configure: './configure --help' should work
Always initialize --help display option Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321 --- configure | 676 +++--- 1 file changed, 338 insertions(+), 338 deletions(-) diff --git a/configure b/configure index 3b384914ce..1fb4d145f1 100755 --- a/configure +++ b/configure @@ -14,6 +14,344 @@ export CCACHE_RECACHE=yes # make source path absolute source_path=$(cd "$(dirname -- "$0")"; pwd) +werror="" + +print_error() { +(echo +echo "ERROR: $1" +while test -n "$2"; do +echo " $2" +shift +done +echo) >&2 +} + +error_exit() { +print_error "$@" +exit 1 +} + +meson_option_build_array() { + printf '[' + (if test "$targetos" = windows; then +IFS=\; + else +IFS=: + fi + for e in $1; do +printf '"""' +# backslash escape any '\' and '"' characters +printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g' +printf '""",' + done) + printf ']\n' +} + +. "$source_path/scripts/meson-buildoptions.sh" + +quote_sh() { +printf "%s" "$1" | sed "s,',''',g; s,.*,'&'," +} + +meson_options= +meson_option_add() { + meson_options="$meson_options $(quote_sh "$1")" +} +meson_option_parse() { + meson_options="$meson_options $(_meson_option_parse "$@")" + if test $? -eq 1; then +echo "ERROR: unknown option $1" +echo "Try '$0 --help' for more information" +exit 1 + fi +} + +for opt do + optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') + case "$opt" in + --help|-h) show_help=yes + ;; + --version|-V) exec cat "$source_path/VERSION" + ;; + --prefix=*) prefix="$optarg" + ;; + --cross-prefix=*) + ;; + --cc=*) + ;; + --host-cc=*) host_cc="$optarg" + ;; + --cxx=*) + ;; + --objcc=*) objcc="$optarg" + ;; + --make=*) make="$optarg" + ;; + --install=*) + ;; + --python=*) python="$optarg" ; explicit_python=yes + ;; + --skip-meson) skip_meson=yes + ;; + --meson=*) meson="$optarg" + ;; + --ninja=*) ninja="$optarg" + ;; + --smbd=*) smbd="$optarg" + ;; + --extra-cflags=*) + ;; + --extra-cxxflags=*) + ;; + --extra-objcflags=*) + ;; + --extra-ldflags=*) + ;; + --cross-cc-*) + ;; + --cross-prefix-*) + ;; + --enable-debug-info) meson_option_add -Ddebug=true + ;; + --disable-debug-info) meson_option_add -Ddebug=false + ;; + --enable-modules) + modules="yes" + ;; + --disable-modules) + modules="no" + ;; + --cpu=*) + ;; + --target-list=*) target_list="$optarg" + if test "$target_list_exclude"; then + error_exit "Can't mix --target-list with --target-list-exclude" + fi + ;; + --target-list-exclude=*) target_list_exclude="$optarg" + if test "$target_list"; then + error_exit "Can't mix --target-list-exclude with --target-list" + fi + ;; + --with-default-devices) meson_option_add -Ddefault_devices=true + ;; + --without-default-devices) meson_option_add -Ddefault_devices=false + ;; + --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option" + ;; + --with-devices-*) device_arch=${opt#--with-devices-}; +device_arch=${device_arch%%=*} + cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak +if test -f "$cf"; then +device_archs="$device_archs $device_arch" +eval "devices_${device_arch}=\$optarg" +else +error_exit "File $cf does not exist" +fi + ;; + --without-default-features) # processed above + ;; + --static) +static="yes" +QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS" + ;; + --bindir=*) bindir="$optarg" + ;; + --with-suffix=*) qemu_suffix="$optarg" + ;; + --host=*|--build=*|\ + --disable-dependency-tracking|\ + --sbindir=*|--sharedstatedir=*|\ + --oldincludedir=*|--datarootdir=*|--infodir=*|\ + --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*) +# These switches are silently ignored, for compatibility with +# autoconf-generated configure scripts. This allows QEMU's +# configure to be used by RPM and similar macros that set +# lots of directory switches by default. + ;; + --enable-debug-tcg) debug_tcg="yes" + ;; + --disable-debug-tcg) debug_tcg="no" + ;; + --enable-debug) + # Enable debugging options that aren't excessively noisy + debug_tcg="yes" + meson_option_parse --enable-debug-mutex "" + meson_option_add -Doptimization=0 + fortify_source="no" + ;; + --enable-sanitizers) sanitizers="yes" + ;; + --disable-sanitizers) sanitizers="no" + ;; + --enable-tsan) tsan="yes" + ;; + --disable-tsan) tsan="no" + ;; + --disable-tcg) tcg="disabled" + plugins="no" + ;; + --enable-tcg) tcg="enabled" + ;; + --disable-system) softmmu="no" + ;; + --enable-system) softmmu="yes" + ;; + --disable-user) + linux_user="no" ; +
[PATCH 0/2] *** configure: Add 'mkdir build' check ***
QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created. 1 - Checking if 'mkdir dir' succeeds and if the directory is writeable prevents this error. 2 - Since we exit early on error in (1), code for reading in arguments has been moved before that Changes since v1: - Fix review comments from Peter Maydell Dinah Baum (2): configure: Add 'mkdir build' check configure: './configure --help' should work configure | 691 +++--- 1 file changed, 348 insertions(+), 343 deletions(-) -- 2.30.2
[PATCH] configure: Add 'mkdir build' check
QEMU configure script goes into an infinite error printing loop when in read only directory due to 'build' dir never being created. Checking if 'mkdir dir' succeeds and if the directory is writeable prevents this error. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/321 Signed-off-by: Dinah Baum --- configure | 37 ++--- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 64960c6000..fe9028991f 100755 --- a/configure +++ b/configure @@ -32,9 +32,11 @@ then fi mkdir build -touch $MARKER +if [ -d build ] && [ -w build ] +then +touch $MARKER -cat > GNUmakefile <<'EOF' +cat > GNUmakefile <<'EOF' # This file is auto-generated by configure to support in-source tree # 'make' command invocation @@ -56,8 +58,15 @@ force: ; GNUmakefile: ; EOF -cd build -exec "$source_path/configure" "$@" +cd build +exec "$source_path/configure" "$@" +elif ! [ -d build ] +then +echo "ERROR: Unable to create ./build dir, try using a ../qemu/configure build" +elif ! [ -w build ] +then +echo "ERROR: ./build dir not writeable, try using a ../qemu/configure build" +fi fi # Temporary directory used for files created while @@ -181,9 +190,12 @@ compile_prog() { # symbolically link $1 to $2. Portable version of "ln -sf". symlink() { - rm -rf "$2" - mkdir -p "$(dirname "$2")" - ln -s "$1" "$2" + if [ -d $source_path/build ] && [ -w $source_path/build ] + then + rm -rf "$2" + mkdir -p "$(dirname "$2")" + ln -s "$1" "$2" + fi } # check whether a command is available to this shell (may be either an @@ -2287,7 +2299,18 @@ fi ### # generate config-host.mak +if ! [ -d $source_path/build ] || ! [ -w $source_path/build ] +then +echo "ERROR: ./build dir unusable, exiting" +# cleanup +rm -f config.log +rm -f Makefile.prereqs +rm -r "$TMPDIR1" +exit 1 +fi + if ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then +echo "BAD" exit 1 fi -- 2.30.2