Blame SOURCES/kvm-qapi-discriminate-CpuInfoFast-on-SysEmuTarget-not-Cp.patch

7711c0
From 17a1d383393e879c43e2aa8f2b264cb001cbca78 Mon Sep 17 00:00:00 2001
7711c0
From: Laszlo Ersek <lersek@redhat.com>
7711c0
Date: Tue, 13 Nov 2018 18:16:37 +0100
7711c0
Subject: [PATCH 18/22] qapi: discriminate CpuInfoFast on SysEmuTarget, not
7711c0
 CpuInfoArch
7711c0
MIME-Version: 1.0
7711c0
Content-Type: text/plain; charset=UTF-8
7711c0
Content-Transfer-Encoding: 8bit
7711c0
7711c0
RH-Author: Laszlo Ersek <lersek@redhat.com>
7711c0
Message-id: <20181113181639.4999-5-lersek@redhat.com>
7711c0
Patchwork-id: 83005
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 4/6] qapi: discriminate CpuInfoFast on SysEmuTarget, not CpuInfoArch
7711c0
Bugzilla: 1607406
7711c0
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
7711c0
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
7711c0
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
7711c0
7711c0
Add a new field @target (of type @SysEmuTarget) to the output of the
7711c0
@query-cpus-fast command, which provides more information about the
7711c0
emulation target than the field @arch (of type @CpuInfoArch). Make @target
7711c0
the new discriminator for the @CpuInfoFast return structure. Keep @arch
7711c0
for compatibility.
7711c0
7711c0
Cc: "Daniel P. Berrange" <berrange@redhat.com>
7711c0
Cc: Eric Blake <eblake@redhat.com>
7711c0
Cc: Markus Armbruster <armbru@redhat.com>
7711c0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
7711c0
Reviewed-by: Eric Blake <eblake@redhat.com>
7711c0
Message-Id: <20180427192852.15013-5-lersek@redhat.com>
7711c0
Reviewed-by: Markus Armbruster <armbru@redhat.com>
7711c0
Signed-off-by: Markus Armbruster <armbru@redhat.com>
7711c0
(cherry picked from commit daa9d2bc6d73618bc230787ddfa821a6a6560fc2)
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 cpus.c         | 87 ++++++++++++++++++++++++++++++++++++++++++----------------
7711c0
 qapi/misc.json | 62 +++++++++++++++++++++++++++++++----------
7711c0
 2 files changed, 110 insertions(+), 39 deletions(-)
7711c0
7711c0
diff --git a/cpus.c b/cpus.c
7711c0
index 4f83f16..be3a4eb 100644
7711c0
--- a/cpus.c
7711c0
+++ b/cpus.c
7711c0
@@ -2187,6 +2187,59 @@ CpuInfoList *qmp_query_cpus(Error **errp)
7711c0
     return head;
7711c0
 }
7711c0
 
7711c0
+static CpuInfoArch sysemu_target_to_cpuinfo_arch(SysEmuTarget target)
7711c0
+{
7711c0
+    /*
7711c0
+     * The @SysEmuTarget -> @CpuInfoArch mapping below is based on the
7711c0
+     * TARGET_ARCH -> TARGET_BASE_ARCH mapping in the "configure" script.
7711c0
+     */
7711c0
+    switch (target) {
7711c0
+    case SYS_EMU_TARGET_I386:
7711c0
+    case SYS_EMU_TARGET_X86_64:
7711c0
+        return CPU_INFO_ARCH_X86;
7711c0
+
7711c0
+    case SYS_EMU_TARGET_PPC:
7711c0
+    case SYS_EMU_TARGET_PPCEMB:
7711c0
+    case SYS_EMU_TARGET_PPC64:
7711c0
+        return CPU_INFO_ARCH_PPC;
7711c0
+
7711c0
+    case SYS_EMU_TARGET_SPARC:
7711c0
+    case SYS_EMU_TARGET_SPARC64:
7711c0
+        return CPU_INFO_ARCH_SPARC;
7711c0
+
7711c0
+    case SYS_EMU_TARGET_MIPS:
7711c0
+    case SYS_EMU_TARGET_MIPSEL:
7711c0
+    case SYS_EMU_TARGET_MIPS64:
7711c0
+    case SYS_EMU_TARGET_MIPS64EL:
7711c0
+        return CPU_INFO_ARCH_MIPS;
7711c0
+
7711c0
+    case SYS_EMU_TARGET_TRICORE:
7711c0
+        return CPU_INFO_ARCH_TRICORE;
7711c0
+
7711c0
+    case SYS_EMU_TARGET_S390X:
7711c0
+        return CPU_INFO_ARCH_S390;
7711c0
+
7711c0
+    case SYS_EMU_TARGET_RISCV32:
7711c0
+    case SYS_EMU_TARGET_RISCV64:
7711c0
+        return CPU_INFO_ARCH_RISCV;
7711c0
+
7711c0
+    default:
7711c0
+        return CPU_INFO_ARCH_OTHER;
7711c0
+    }
7711c0
+}
7711c0
+
7711c0
+static void cpustate_to_cpuinfo_s390(CpuInfoS390 *info, const CPUState *cpu)
7711c0
+{
7711c0
+#ifdef TARGET_S390X
7711c0
+    S390CPU *s390_cpu = S390_CPU(cpu);
7711c0
+    CPUS390XState *env = &s390_cpu->env;
7711c0
+
7711c0
+    info->cpu_state = env->cpu_state;
7711c0
+#else
7711c0
+    abort();
7711c0
+#endif
7711c0
+}
7711c0
+
7711c0
 /*
7711c0
  * fast means: we NEVER interrupt vCPU threads to retrieve
7711c0
  * information from KVM.
7711c0
@@ -2196,11 +2249,9 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
7711c0
     MachineState *ms = MACHINE(qdev_get_machine());
7711c0
     MachineClass *mc = MACHINE_GET_CLASS(ms);
7711c0
     CpuInfoFastList *head = NULL, *cur_item = NULL;
7711c0
+    SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME,
7711c0
+                                          -1, &error_abort);
7711c0
     CPUState *cpu;
7711c0
-#if defined(TARGET_S390X)
7711c0
-    S390CPU *s390_cpu;
7711c0
-    CPUS390XState *env;
7711c0
-#endif
7711c0
 
7711c0
     CPU_FOREACH(cpu) {
7711c0
         CpuInfoFastList *info = g_malloc0(sizeof(*info));
7711c0
@@ -2218,26 +2269,14 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
7711c0
             info->value->props = props;
7711c0
         }
7711c0
 
7711c0
-#if defined(TARGET_I386)
7711c0
-        info->value->arch = CPU_INFO_ARCH_X86;
7711c0
-#elif defined(TARGET_PPC)
7711c0
-        info->value->arch = CPU_INFO_ARCH_PPC;
7711c0
-#elif defined(TARGET_SPARC)
7711c0
-        info->value->arch = CPU_INFO_ARCH_SPARC;
7711c0
-#elif defined(TARGET_MIPS)
7711c0
-        info->value->arch = CPU_INFO_ARCH_MIPS;
7711c0
-#elif defined(TARGET_TRICORE)
7711c0
-        info->value->arch = CPU_INFO_ARCH_TRICORE;
7711c0
-#elif defined(TARGET_S390X)
7711c0
-        s390_cpu = S390_CPU(cpu);
7711c0
-        env = &s390_cpu->env;
7711c0
-        info->value->arch = CPU_INFO_ARCH_S390;
7711c0
-        info->value->u.s390.cpu_state = env->cpu_state;
7711c0
-#elif defined(TARGET_RISCV)
7711c0
-        info->value->arch = CPU_INFO_ARCH_RISCV;
7711c0
-#else
7711c0
-        info->value->arch = CPU_INFO_ARCH_OTHER;
7711c0
-#endif
7711c0
+        info->value->arch = sysemu_target_to_cpuinfo_arch(target);
7711c0
+        info->value->target = target;
7711c0
+        if (target == SYS_EMU_TARGET_S390X) {
7711c0
+            cpustate_to_cpuinfo_s390(&info->value->u.s390x, cpu);
7711c0
+        } else {
7711c0
+            /* do nothing for @CpuInfoOther */
7711c0
+        }
7711c0
+
7711c0
         if (!cur_item) {
7711c0
             head = cur_item = info;
7711c0
         } else {
7711c0
diff --git a/qapi/misc.json b/qapi/misc.json
7711c0
index 7cf4fbc..d7fd8bd 100644
7711c0
--- a/qapi/misc.json
7711c0
+++ b/qapi/misc.json
7711c0
@@ -558,25 +558,55 @@
7711c0
 # @props: properties describing to which node/socket/core/thread
7711c0
 #         virtual CPU belongs to, provided if supported by board
7711c0
 #
7711c0
-# @arch: architecture of the cpu, which determines which additional fields
7711c0
-#        will be listed
7711c0
+# @arch: base architecture of the cpu
7711c0
+#
7711c0
+# @target: the QEMU system emulation target, which is more specific than
7711c0
+#          @arch and determines which additional fields will be listed
7711c0
+#          (since 2.13)
7711c0
 #
7711c0
 # Since: 2.12
7711c0
 #
7711c0
 ##
7711c0
-{ 'union': 'CpuInfoFast',
7711c0
-  'base': {'cpu-index': 'int', 'qom-path': 'str',
7711c0
-           'thread-id': 'int', '*props': 'CpuInstanceProperties',
7711c0
-           'arch': 'CpuInfoArch' },
7711c0
-  'discriminator': 'arch',
7711c0
-  'data': { 'x86': 'CpuInfoOther',
7711c0
-            'sparc': 'CpuInfoOther',
7711c0
-            'ppc': 'CpuInfoOther',
7711c0
-            'mips': 'CpuInfoOther',
7711c0
-            'tricore': 'CpuInfoOther',
7711c0
-            's390': 'CpuInfoS390',
7711c0
-            'riscv': 'CpuInfoOther',
7711c0
-            'other': 'CpuInfoOther' } }
7711c0
+{ 'union'         : 'CpuInfoFast',
7711c0
+  'base'          : { 'cpu-index'    : 'int',
7711c0
+                      'qom-path'     : 'str',
7711c0
+                      'thread-id'    : 'int',
7711c0
+                      '*props'       : 'CpuInstanceProperties',
7711c0
+                      'arch'         : 'CpuInfoArch',
7711c0
+                      'target'       : 'SysEmuTarget' },
7711c0
+  'discriminator' : 'target',
7711c0
+  'data'          : { 'aarch64'      : 'CpuInfoOther',
7711c0
+                      'alpha'        : 'CpuInfoOther',
7711c0
+                      'arm'          : 'CpuInfoOther',
7711c0
+                      'cris'         : 'CpuInfoOther',
7711c0
+                      'hppa'         : 'CpuInfoOther',
7711c0
+                      'i386'         : 'CpuInfoOther',
7711c0
+                      'lm32'         : 'CpuInfoOther',
7711c0
+                      'm68k'         : 'CpuInfoOther',
7711c0
+                      'microblaze'   : 'CpuInfoOther',
7711c0
+                      'microblazeel' : 'CpuInfoOther',
7711c0
+                      'mips'         : 'CpuInfoOther',
7711c0
+                      'mips64'       : 'CpuInfoOther',
7711c0
+                      'mips64el'     : 'CpuInfoOther',
7711c0
+                      'mipsel'       : 'CpuInfoOther',
7711c0
+                      'moxie'        : 'CpuInfoOther',
7711c0
+                      'nios2'        : 'CpuInfoOther',
7711c0
+                      'or1k'         : 'CpuInfoOther',
7711c0
+                      'ppc'          : 'CpuInfoOther',
7711c0
+                      'ppc64'        : 'CpuInfoOther',
7711c0
+                      'ppcemb'       : 'CpuInfoOther',
7711c0
+                      'riscv32'      : 'CpuInfoOther',
7711c0
+                      'riscv64'      : 'CpuInfoOther',
7711c0
+                      's390x'        : 'CpuInfoS390',
7711c0
+                      'sh4'          : 'CpuInfoOther',
7711c0
+                      'sh4eb'        : 'CpuInfoOther',
7711c0
+                      'sparc'        : 'CpuInfoOther',
7711c0
+                      'sparc64'      : 'CpuInfoOther',
7711c0
+                      'tricore'      : 'CpuInfoOther',
7711c0
+                      'unicore32'    : 'CpuInfoOther',
7711c0
+                      'x86_64'       : 'CpuInfoOther',
7711c0
+                      'xtensa'       : 'CpuInfoOther',
7711c0
+                      'xtensaeb'     : 'CpuInfoOther' } }
7711c0
 
7711c0
 ##
7711c0
 # @query-cpus-fast:
7711c0
@@ -602,6 +632,7 @@
7711c0
 #             },
7711c0
 #             "qom-path": "/machine/unattached/device[0]",
7711c0
 #             "arch":"x86",
7711c0
+#             "target":"x86_64",
7711c0
 #             "cpu-index": 0
7711c0
 #         },
7711c0
 #         {
7711c0
@@ -613,6 +644,7 @@
7711c0
 #             },
7711c0
 #             "qom-path": "/machine/unattached/device[2]",
7711c0
 #             "arch":"x86",
7711c0
+#             "target":"x86_64",
7711c0
 #             "cpu-index": 1
7711c0
 #         }
7711c0
 #     ]
7711c0
-- 
7711c0
1.8.3.1
7711c0