diff options
-rw-r--r-- | cpus.c | 87 | ||||
-rw-r--r-- | qapi/misc.json | 62 |
2 files changed, 110 insertions, 39 deletions
@@ -2187,6 +2187,59 @@ CpuInfoList *qmp_query_cpus(Error **errp) return head; } +static CpuInfoArch sysemu_target_to_cpuinfo_arch(SysEmuTarget target) +{ + /* + * The @SysEmuTarget -> @CpuInfoArch mapping below is based on the + * TARGET_ARCH -> TARGET_BASE_ARCH mapping in the "configure" script. + */ + switch (target) { + case SYS_EMU_TARGET_I386: + case SYS_EMU_TARGET_X86_64: + return CPU_INFO_ARCH_X86; + + case SYS_EMU_TARGET_PPC: + case SYS_EMU_TARGET_PPCEMB: + case SYS_EMU_TARGET_PPC64: + return CPU_INFO_ARCH_PPC; + + case SYS_EMU_TARGET_SPARC: + case SYS_EMU_TARGET_SPARC64: + return CPU_INFO_ARCH_SPARC; + + case SYS_EMU_TARGET_MIPS: + case SYS_EMU_TARGET_MIPSEL: + case SYS_EMU_TARGET_MIPS64: + case SYS_EMU_TARGET_MIPS64EL: + return CPU_INFO_ARCH_MIPS; + + case SYS_EMU_TARGET_TRICORE: + return CPU_INFO_ARCH_TRICORE; + + case SYS_EMU_TARGET_S390X: + return CPU_INFO_ARCH_S390; + + case SYS_EMU_TARGET_RISCV32: + case SYS_EMU_TARGET_RISCV64: + return CPU_INFO_ARCH_RISCV; + + default: + return CPU_INFO_ARCH_OTHER; + } +} + +static void cpustate_to_cpuinfo_s390(CpuInfoS390 *info, const CPUState *cpu) +{ +#ifdef TARGET_S390X + S390CPU *s390_cpu = S390_CPU(cpu); + CPUS390XState *env = &s390_cpu->env; + + info->cpu_state = env->cpu_state; +#else + abort(); +#endif +} + /* * fast means: we NEVER interrupt vCPU threads to retrieve * information from KVM. @@ -2196,11 +2249,9 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp) MachineState *ms = MACHINE(qdev_get_machine()); MachineClass *mc = MACHINE_GET_CLASS(ms); CpuInfoFastList *head = NULL, *cur_item = NULL; + SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, + -1, &error_abort); CPUState *cpu; -#if defined(TARGET_S390X) - S390CPU *s390_cpu; - CPUS390XState *env; -#endif CPU_FOREACH(cpu) { CpuInfoFastList *info = g_malloc0(sizeof(*info)); @@ -2218,26 +2269,14 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp) info->value->props = props; } -#if defined(TARGET_I386) - info->value->arch = CPU_INFO_ARCH_X86; -#elif defined(TARGET_PPC) - info->value->arch = CPU_INFO_ARCH_PPC; -#elif defined(TARGET_SPARC) - info->value->arch = CPU_INFO_ARCH_SPARC; -#elif defined(TARGET_MIPS) - info->value->arch = CPU_INFO_ARCH_MIPS; -#elif defined(TARGET_TRICORE) - info->value->arch = CPU_INFO_ARCH_TRICORE; -#elif defined(TARGET_S390X) - s390_cpu = S390_CPU(cpu); - env = &s390_cpu->env; - info->value->arch = CPU_INFO_ARCH_S390; - info->value->u.s390.cpu_state = env->cpu_state; -#elif defined(TARGET_RISCV) - info->value->arch = CPU_INFO_ARCH_RISCV; -#else - info->value->arch = CPU_INFO_ARCH_OTHER; -#endif + info->value->arch = sysemu_target_to_cpuinfo_arch(target); + info->value->target = target; + if (target == SYS_EMU_TARGET_S390X) { + cpustate_to_cpuinfo_s390(&info->value->u.s390x, cpu); + } else { + /* do nothing for @CpuInfoOther */ + } + if (!cur_item) { head = cur_item = info; } else { diff --git a/qapi/misc.json b/qapi/misc.json index 460866cf54..fa4eec7b6b 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -558,25 +558,55 @@ # @props: properties describing to which node/socket/core/thread # virtual CPU belongs to, provided if supported by board # -# @arch: architecture of the cpu, which determines which additional fields -# will be listed +# @arch: base architecture of the cpu +# +# @target: the QEMU system emulation target, which is more specific than +# @arch and determines which additional fields will be listed +# (since 2.13) # # Since: 2.12 # ## -{ 'union': 'CpuInfoFast', - 'base': {'cpu-index': 'int', 'qom-path': 'str', - 'thread-id': 'int', '*props': 'CpuInstanceProperties', - 'arch': 'CpuInfoArch' }, - 'discriminator': 'arch', - 'data': { 'x86': 'CpuInfoOther', - 'sparc': 'CpuInfoOther', - 'ppc': 'CpuInfoOther', - 'mips': 'CpuInfoOther', - 'tricore': 'CpuInfoOther', - 's390': 'CpuInfoS390', - 'riscv': 'CpuInfoOther', - 'other': 'CpuInfoOther' } } +{ 'union' : 'CpuInfoFast', + 'base' : { 'cpu-index' : 'int', + 'qom-path' : 'str', + 'thread-id' : 'int', + '*props' : 'CpuInstanceProperties', + 'arch' : 'CpuInfoArch', + 'target' : 'SysEmuTarget' }, + 'discriminator' : 'target', + 'data' : { 'aarch64' : 'CpuInfoOther', + 'alpha' : 'CpuInfoOther', + 'arm' : 'CpuInfoOther', + 'cris' : 'CpuInfoOther', + 'hppa' : 'CpuInfoOther', + 'i386' : 'CpuInfoOther', + 'lm32' : 'CpuInfoOther', + 'm68k' : 'CpuInfoOther', + 'microblaze' : 'CpuInfoOther', + 'microblazeel' : 'CpuInfoOther', + 'mips' : 'CpuInfoOther', + 'mips64' : 'CpuInfoOther', + 'mips64el' : 'CpuInfoOther', + 'mipsel' : 'CpuInfoOther', + 'moxie' : 'CpuInfoOther', + 'nios2' : 'CpuInfoOther', + 'or1k' : 'CpuInfoOther', + 'ppc' : 'CpuInfoOther', + 'ppc64' : 'CpuInfoOther', + 'ppcemb' : 'CpuInfoOther', + 'riscv32' : 'CpuInfoOther', + 'riscv64' : 'CpuInfoOther', + 's390x' : 'CpuInfoS390', + 'sh4' : 'CpuInfoOther', + 'sh4eb' : 'CpuInfoOther', + 'sparc' : 'CpuInfoOther', + 'sparc64' : 'CpuInfoOther', + 'tricore' : 'CpuInfoOther', + 'unicore32' : 'CpuInfoOther', + 'x86_64' : 'CpuInfoOther', + 'xtensa' : 'CpuInfoOther', + 'xtensaeb' : 'CpuInfoOther' } } ## # @query-cpus-fast: @@ -602,6 +632,7 @@ # }, # "qom-path": "/machine/unattached/device[0]", # "arch":"x86", +# "target":"x86_64", # "cpu-index": 0 # }, # { @@ -613,6 +644,7 @@ # }, # "qom-path": "/machine/unattached/device[2]", # "arch":"x86", +# "target":"x86_64", # "cpu-index": 1 # } # ] |