*** Enable -cpu <cpu>,help ***
cover *** Enable -cpu <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=<qbool>
3dnowext=<qbool>
3dnowprefetch=<qbool>
...
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 '<cpu>,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
Signature · 1 line
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
--- 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
MAINTAINERS +1 -0
@@ -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
cpu.c +20 -0
@@ -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) {
include/exec/cpu-common.h +8 -0
@@ -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 */
qapi/machine-target-common.json new file +129 -0
129 lines not on this page · raw message
qapi/machine-target.json +1 -128
141 lines not on this page · raw message
qapi/meson.build +1 -0
@@ -38,6 +38,7 @@ qapi_all_modules = [ 'job', 'machine', 'machine-target', + 'machine-target-common', 'migration', 'misc', 'misc-target',
target/arm/arm-qmp-cmds.c +4 -3
@@ -21,6 +21,7 @@*/ #include "qemu/osdep.h" +#include "cpu.h" #include "hw/boards.h" #include "kvm_arm.h" #include "qapi/error.h"
@@ -99,9 +100,9 @@ static const char *cpu_model_advertised_features[] = { NULL }; -CpuModelExpansionInfo *qmp_query_cpu_model_expansion (CpuModelExpansionType type, -CpuModelInfo *model, -Error **errp) +CpuModelExpansionInfo *get_cpu_model_expansion (CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) {CpuModelExpansionInfo *expansion_info;const QDict *qdict_in =NULL ;
target/arm/cpu.h +6 -1
@@ -2660,7 +2660,12 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync);#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU#define cpu_list arm_cpu_list - +#ifdef CONFIG_SOFTMMU +CpuModelExpansionInfo *get_cpu_model_expansion (CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); +#define cpu_model_expansion get_cpu_model_expansion +#endif /* ARM has the following "translation regimes" (as the ARM ARM calls them): * * If EL3 is 64-bit:
target/i386/cpu-sysemu.c +3 -4
@@ -176,10 +176,9 @@ out:return xc; } -CpuModelExpansionInfo * -qmp_query_cpu_model_expansion (CpuModelExpansionType type, -CpuModelInfo *model, -Error **errp) +CpuModelExpansionInfo *get_cpu_model_expansion (CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) {X86CPU *xc =NULL ;Error *err =NULL ;
target/i386/cpu.h +6 -0
@@ -2209,6 +2209,12 @@ uint64_t cpu_get_tsc(CPUX86State *env);#endif #define cpu_list x86_cpu_list +#ifdef CONFIG_SOFTMMU +CpuModelExpansionInfo *get_cpu_model_expansion (CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); +#define cpu_model_expansion get_cpu_model_expansion +#endif /* MMU modes definitions */ #define MMU_KSMAP_IDX 0
target/s390x/cpu.h +7 -0
@@ -799,6 +799,13 @@ void s390_cpu_list(void);void s390_set_qemu_cpu_model (uint16_t type,uint8_t gen,uint8_t ec_ga,const S390FeatInit feat_init); +#ifdef CONFIG_SOFTMMU +/* cpu_models-sysemu.c */ +CpuModelExpansionInfo *get_cpu_model_expansion (CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp); +#define cpu_model_expansion get_cpu_model_expansion +#endif /* helper.c */ #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
target/s390x/cpu_models_sysemu.c +3 -3
@@ -213,9 +213,9 @@ static void cpu_info_from_model(CpuModelInfo *info, const S390CPUModel *model, } } -CpuModelExpansionInfo *qmp_query_cpu_model_expansion (CpuModelExpansionType type, -CpuModelInfo *model, -Error **errp) +CpuModelExpansionInfo *get_cpu_model_expansion (CpuModelExpansionType type, +CpuModelInfo *model, +Error **errp) {Error *err =NULL ;CpuModelExpansionInfo *expansion_info =NULL ;
Signature · 1 line
2.30.2
Re: [PATCH 1/2] cpu, qapi, target/arm, i386, s390x: Refactor query-cpu-model-expansion
Quoted 9 lines · Dinah Baum
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
Quoted 7 lines
Signed-off-by Dinah Baum <[email protected]>--- MAINTAINERS | 1 + cpu.c | 20 +++++ include/exec/cpu-common.h | 8 ++ qapi/machine-target-common.json | 129 +++++++++++++++++++++++++++++++ qapi/machine-target.json | 129 +------------------------------
Could you please elaborate in the patch description, why you apparently had to move lots of code from one file to another? Why is that necessary?
Thomas
PATCH 2/2 cpu, qdict, vl: Enable printing options for CPU type
In reply to Dinah BaumChange 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
--- 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(-)
cpu.c +41 -0
@@ -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) {
include/exec/cpu-common.h +2 -0
@@ -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 */
include/qapi/qmp/qdict.h +2 -0
@@ -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 */
qemu-options.hx +4 -3
@@ -169,11 +169,12 @@ SRST ERST DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, - "-cpu cpu select CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) + "-cpu cpu select 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,
qobject/qdict.c +5 -0
@@ -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)); +}
softmmu/vl.c +34 -2
@@ -500,6 +500,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;
@@ -1147,6 +1156,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 (cpu_option); +return 1 ; + } + +if (!cpu_option || !qemu_opt_has_help_opt (opts)) { +return 0 ; + } + + model =g_new0 (CpuModelInfo,1 ); + model->name = (char *)qemu_opt_get (opts,"cpu" ); +/* TODO: handle other expansion cases */ +list_cpu_model_expansion (CPU_MODEL_EXPANSION_TYPE_FULL , model, errp); +return 1 ; +} +static int chardev_init_func (void *opaque,QemuOpts *opts,Error **errp) {Error *local_err =NULL ;
@@ -2431,8 +2460,9 @@ static void qemu_process_help_options(void)* type and the user did not specify one, so that the user doesn't need * to say '-cpu help -machine something'. */ -if (cpu_option &&is_help_option (cpu_option)) { -list_cpus (cpu_option); +Error *errp =NULL ; +if (qemu_opts_foreach (qemu_find_opts ("cpu" ), + cpu_help_func,NULL , &errp)) {exit (0 ); }
@@ -2672,6 +2702,7 @@ void qemu_init(int argc, char **argv)qemu_add_opts (&qemu_semihosting_config_opts);qemu_add_opts (&qemu_fw_cfg_opts);qemu_add_opts (&qemu_action_opts); +qemu_add_opts (&qemu_cpu_opts);module_call_init (MODULE_INIT_OPTS );error_init (argv[0 ]);
@@ -2723,6 +2754,7 @@ void qemu_init(int argc, char **argv)switch (popt->index) {case QEMU_OPTION_cpu:/* hw initialization will check this */ +qemu_opts_parse_noisily (qemu_find_opts ("cpu" ), optarg, true); cpu_option = optarg;break ;case QEMU_OPTION_hda:
Signature · 1 line
2.30.2