Patchwork [RFC,10/11] s390/qemu: cpu model QMP query-cpu-model

login
register
mail settings
Submitter Michael Mueller
Date Oct. 2, 2013, 11:33 a.m.
Message ID <1380713622-22325-11-git-send-email-mimu@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/279703/
State New
Headers show

Comments

Michael Mueller - Oct. 2, 2013, 11:33 a.m.
This patch implements a new QMP request named "cpu-model". It returns
the cpu model of cpu 0. eg:

request: '{"execute" : "query-cpu-model" }
answer:  '{"return" : "2817-ga1" }

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

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 +++++
 target-s390x/cpu.c         | 21 +++++++++++++++++++++
 5 files changed, 56 insertions(+)
Eric Blake - Oct. 2, 2013, 12:06 p.m.
On 10/02/2013 05:33 AM, Michael Mueller wrote:
> This patch implements a new QMP request named "cpu-model". It returns
> the cpu model of cpu 0. eg:
> 
> request: '{"execute" : "query-cpu-model" }
> answer:  '{"return" : "2817-ga1" }
> 
> Alias names are resolved to their respactive machine type and GA names
> already during cpu instantiation. Thus, also a cpu name like "host",
> which is iplemented as alias, will return its normalized cpu model name.
> 
> Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
> ---

> +++ b/qapi-schema.json
> @@ -3129,6 +3129,29 @@
>  ##
>  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
>  
> +##
> +# @CpuModelInfo:
> +#
> +# Virtual CPU model definition.
> +#
> +# @name: the name of the CPU model definition
> +#
> +# Since: 1.x.0

s/x/7/ - you are targetting 1.7.0 after all.

> +##
> +{ 'type': 'CpuModelInfo',
> +  'data': { 'name': 'str' } }
> +
> +##
> +# @query-cpu-model:
> +#
> +# Return to current virtual CPU model
> +#
> +# Returns: CpuModelInfo
> +#
> +# Since: 1.2.0

s/2/7/
Michael Mueller - Oct. 2, 2013, 2:30 p.m.
On Wed, 02 Oct 2013 06:06:32 -0600
Eric Blake <eblake@redhat.com> wrote:

> On 10/02/2013 05:33 AM, Michael Mueller wrote:
> > This patch implements a new QMP request named "cpu-model". It returns
> > the cpu model of cpu 0. eg:
> > 
> > request: '{"execute" : "query-cpu-model" }
> > answer:  '{"return" : "2817-ga1" }
> > 
> > Alias names are resolved to their respactive machine type and GA names
> > already during cpu instantiation. Thus, also a cpu name like "host",
> > which is iplemented as alias, will return its normalized cpu model name.
> > 
> > Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
> > ---
> 
> > +++ b/qapi-schema.json
> > @@ -3129,6 +3129,29 @@
> >  ##
> >  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
> >  
> > +##
> > +# @CpuModelInfo:
> > +#
> > +# Virtual CPU model definition.
> > +#
> > +# @name: the name of the CPU model definition
> > +#
> > +# Since: 1.x.0
> 
> s/x/7/ - you are targetting 1.7.0 after all.
welcome
> 
> > +##
> > +{ 'type': 'CpuModelInfo',
> > +  'data': { 'name': 'str' } }
> > +
> > +##
> > +# @query-cpu-model:
> > +#
> > +# Return to current virtual CPU model
> > +#
> > +# Returns: CpuModelInfo
> > +#
> > +# Since: 1.2.0
> 
> s/2/7/
yep
>

Patch

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index be71bca..a8d623b 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -36,5 +36,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 145eca8..9e86186 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3129,6 +3129,29 @@ 
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
 
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model definition.
+#
+# @name: the name of the CPU model definition
+#
+# Since: 1.x.0
+##
+{ 'type': 'CpuModelInfo',
+  'data': { 'name': 'str' } }
+
+##
+# @query-cpu-model:
+#
+# Return to current virtual CPU model
+#
+# Returns: CpuModelInfo
+#
+# Since: 1.2.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 b17c46e..fef83a4 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3036,6 +3036,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 4c149b3..d9b1921 100644
--- a/qmp.c
+++ b/qmp.c
@@ -486,6 +486,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/target-s390x/cpu.c b/target-s390x/cpu.c
index b790905..605c124 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -129,6 +129,27 @@  CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
         return entry;
     }
 }
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+    CpuModelInfo *cpu_model;
+    S390CPU *cpu;
+
+    cpu = s390_cpu_addr2state(0);
+    if (!cpu) {
+        return NULL;
+    }
+    cpu_model = g_malloc0(sizeof(*cpu_model));
+    if (!cpu_model) {
+        return NULL;
+    }
+    cpu_model->name = g_strdup(cpu->env.cpu_model_str);
+    if (!cpu_model->name) {
+        g_free(cpu_model);
+        return NULL;
+    }
+    return cpu_model;
+}
 #endif
 
 static void s390_cpu_set_pc(CPUState *cs, vaddr value)