qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Mueller <mimu@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org, kvm@vger.kernel.org,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Michael Mueller <mimu@linux.vnet.ibm.com>,
	Gleb Natapov <gleb@kernel.org>, Alexander Graf <agraf@suse.de>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	"Jason J. Herne" <jjherne@linux.vnet.ibm.com>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Andreas Faerber <afaerber@suse.de>,
	Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [RFC PATCH v2 11/15] cpu-model/s390: Add QMP command query-cpu-model
Date: Tue, 17 Feb 2015 15:24:09 +0100	[thread overview]
Message-ID: <1424183053-4310-12-git-send-email-mimu@linux.vnet.ibm.com> (raw)
In-Reply-To: <1424183053-4310-1-git-send-email-mimu@linux.vnet.ibm.com>

This patch implements a new QMP request named 'query-cpu-model'.
It returns the cpu model of cpu 0 and its backing accelerator.

request:
  {"execute" : "query-cpu-model" }

answer:
  {"return" : {"name": "2827-ga2", "accelerator": "kvm" }}

Alias names are resolved to their respective machine type and GA names
already during cpu instantiation. Thus, also a cpu model like 'host'
which is implemented as alias will return its normalized cpu model name.

Furthermore the patch implements the following functions:

- s390_cpu_typename(), returns the currently selected cpu type name or NULL
- s390_cpu_models_used(), returns true if S390 cpu models are in use

Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
---
 include/sysemu/arch_init.h |  1 +
 qapi-schema.json           | 23 +++++++++++++++++++++++
 qmp-commands.hx            |  6 ++++++
 qmp.c                      |  5 +++++
 stubs/Makefile.objs        |  1 +
 stubs/arch-query-cpu-mod.c |  9 +++++++++
 target-s390x/cpu-models.c  | 25 +++++++++++++++++++++++++
 target-s390x/cpu-models.h  |  2 ++
 target-s390x/cpu.c         | 32 ++++++++++++++++++++++++++++++++
 9 files changed, 104 insertions(+)
 create mode 100644 stubs/arch-query-cpu-mod.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 54b36c1..86344a2 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -37,5 +37,6 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuModelInfo *arch_query_cpu_model(Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 4d237c8..9431fc2 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2507,6 +2507,29 @@
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
 
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model definition.
+#
+# @name: the name of the CPU model definition
+#
+# Since: 2.3.0
+##
+{ 'type': 'CpuModelInfo',
+  'data': { 'name': 'str', '*accelerator': 'AccelId' } }
+
+##
+# @query-cpu-model:
+#
+# Return to current virtual CPU model
+#
+# Returns: CpuModelInfo
+#
+# Since: 2.3.0
+##
+{ 'command': 'query-cpu-model', 'returns': 'CpuModelInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a85d847..98bfedd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3392,6 +3392,12 @@ EQMP
     },
 
     {
+        .name       = "query-cpu-model",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_cpu_model,
+    },
+
+    {
         .name       = "query-target",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_input_query_target,
diff --git a/qmp.c b/qmp.c
index 6b2c4be..d32abbc 100644
--- a/qmp.c
+++ b/qmp.c
@@ -568,6 +568,11 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     return arch_query_cpu_definitions(errp);
 }
 
+CpuModelInfo *qmp_query_cpu_model(Error **errp)
+{
+    return arch_query_cpu_model(errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
                     bool has_skipauth, bool skipauth, bool has_tls, bool tls,
                     Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index fd7a489..45daa92 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,4 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
+stub-obj-y += arch-query-cpu-mod.o
 stub-obj-y += bdrv-commit-all.o
 stub-obj-y += chr-baum-init.o
 stub-obj-y += chr-msmouse.o
diff --git a/stubs/arch-query-cpu-mod.c b/stubs/arch-query-cpu-mod.c
new file mode 100644
index 0000000..90ebd08
--- /dev/null
+++ b/stubs/arch-query-cpu-mod.c
@@ -0,0 +1,9 @@
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+    error_set(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 9f40998..4d03adc 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -110,6 +110,7 @@ typedef struct ParmAddrAddrAccel {
 } ParmAddrAddrAccel;
 
 static GSList *s390_cpu_aliases;
+static const char *selected_cpu_typename;
 
 /* compare order of two cpu classes for ascending sort */
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
@@ -631,3 +632,27 @@ bool s390_probe_mode(void)
     return false;
 }
 
+/**
+ * s390_cpu_typename - get name of selected cpu class type
+ *
+ * Returns: address to name of selected cpu class type
+ *          NULL if no cpu class type has been selected yet
+ */
+const char *s390_cpu_typename(void)
+{
+    return selected_cpu_typename;
+}
+
+/**
+ * s390_cpu_models_used - indicates that cpus with model properties
+ *                        are in use
+ *
+ * Returns: true  if a cpu model type name has been selected
+ *          false if either no cpu class type was selected yet or the
+ *                selected type is TYPE_S390_CPU
+ */
+bool s390_cpu_models_used(void)
+{
+    return s390_cpu_typename() && strcmp(s390_cpu_typename(), TYPE_S390_CPU);
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index be94667..23ac2c4 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -110,6 +110,8 @@ void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 bool s390_test_facility(S390CPUClass *cc, unsigned long nr);
 bool s390_probe_mode(void);
+const char *s390_cpu_typename(void);
+bool s390_cpu_models_used(void);
 
 /*
  * bits 0-7   : CMOS generation
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index d27832b..d98578b 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -37,6 +37,11 @@
 #define CR0_RESET       0xE0UL
 #define CR14_RESET      0xC2000000UL;
 
+static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
+{
+    return g_strdup_printf("%04x-ga%u", cc->proc->type, cc->mach->ga);
+}
+
 /* generate CPU information for cpu -? */
 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 {
@@ -74,6 +79,33 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
 
     return entry;
 }
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+    CpuModelInfo *info;
+    S390CPUClass *cc;
+
+    if (!s390_cpu_models_used()) {
+        return NULL;
+    }
+    info = g_try_new0(CpuModelInfo, 1);
+    if (!info) {
+        return NULL;
+    }
+    cc = S390_CPU_CLASS(object_class_by_name(s390_cpu_typename()));
+    info->name = strdup_s390_cpu_name(cc);
+    if (!info->name) {
+        g_free(info);
+        return NULL;
+    }
+    info->accelerator = ACCEL_ID_MAX;
+    if (kvm_enabled()) {
+        info->accelerator = ACCEL_ID_KVM;
+    }
+    info->has_accelerator = (info->accelerator != ACCEL_ID_MAX);
+
+    return info;
+}
 #endif
 
 static void s390_cpu_set_pc(CPUState *cs, vaddr value)
-- 
1.8.3.1

  parent reply	other threads:[~2015-02-17 14:25 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-17 14:23 [Qemu-devel] [RFC PATCH v2 00/15] QEMU: s390: cpu model implementation Michael Mueller
2015-02-17 14:23 ` [Qemu-devel] [RFC PATCH v2 01/15] cpu-model: Introduce probe mode for machine none Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 02/15] cpu-model: Introduce option --probe to switch into probe mode Michael Mueller
2015-02-17 19:16   ` Eric Blake
2015-02-18  9:08     ` Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 03/15] cpu-model: Introduce stub routine cpu_desc_avail Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models Michael Mueller
2015-02-20 13:54   ` Alexander Graf
2015-02-20 15:00     ` Michael Mueller
2015-02-20 15:22       ` Alexander Graf
2015-02-20 15:49         ` Michael Mueller
2015-02-20 16:57           ` Alexander Graf
2015-02-20 17:37             ` Michael Mueller
2015-02-20 17:50               ` Alexander Graf
2015-02-20 19:43                 ` Michael Mueller
2015-02-20 19:55                   ` Alexander Graf
2015-02-23 12:56         ` Christian Borntraeger
2015-02-23 13:27           ` Christian Borntraeger
2015-02-20 13:55   ` Alexander Graf
2015-02-20 15:02     ` Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 05/15] cpu-model/s390: Introduce S390 CPU facilities Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 06/15] cpu-model/s390: Define cpu model specific facility lists Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 07/15] cpu-model/s390: Add cpu model alias definition routines Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 08/15] cpu-model/s390: Update linux-headers/asm-s390/kvm.h Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 09/15] cpu-model/s390: Add KVM VM attribute interface routines Michael Mueller
2015-02-20 13:59   ` Alexander Graf
2015-02-20 15:18     ` Michael Mueller
2015-02-20 16:59       ` Alexander Graf
2015-02-20 18:42         ` Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines Michael Mueller
2015-02-20 16:02   ` Richard Henderson
2015-02-20 16:12     ` Michael Mueller
2015-02-20 16:27       ` Michael Mueller
2015-02-20 16:34       ` Andreas Färber
2015-02-20 16:55         ` Michael Mueller
2015-02-20 18:11   ` Richard Henderson
2015-02-20 18:59     ` Michael Mueller
2015-02-20 19:21       ` Alexander Graf
2015-02-20 19:35         ` Michael Mueller
2015-02-17 14:24 ` Michael Mueller [this message]
2015-02-17 18:03   ` [Qemu-devel] [RFC PATCH v2 11/15] cpu-model/s390: Add QMP command query-cpu-model Eric Blake
2015-02-18  8:39     ` Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 12/15] cpu-model/s390: Extend QMP command query-cpu-definitions Michael Mueller
2015-02-17 18:09   ` Eric Blake
2015-02-18  9:29     ` Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines Michael Mueller
2015-02-20 14:03   ` Alexander Graf
2015-02-20 15:32     ` Michael Mueller
2015-02-20 15:41       ` Andreas Färber
2015-02-20 16:04         ` Michael Mueller
2015-02-20 16:28           ` Andreas Färber
2015-02-20 16:53             ` Michael Mueller
2015-02-20 16:05         ` Michael Mueller
2015-02-20 17:00       ` Alexander Graf
2015-02-20 19:29         ` Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 14/15] cpu-model/s390: Add cpu model selection routine Michael Mueller
2015-02-17 14:24 ` [Qemu-devel] [RFC PATCH v2 15/15] cpu-model/s390: Enable S390 cpu model Michael Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424183053-4310-12-git-send-email-mimu@linux.vnet.ibm.com \
    --to=mimu@linux.vnet.ibm.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=gleb@kernel.org \
    --cc=jjherne@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).