Patchwork [5/7] qapi: add query-cpudefs command

login
register
mail settings
Submitter Anthony Liguori
Date July 27, 2012, 1:37 p.m.
Message ID <1343396239-19272-6-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/173674/
State New
Headers show

Comments

Anthony Liguori - July 27, 2012, 1:37 p.m.
This command attempts to map to the behavior of -cpu ?.  Unfortunately, the
output of this command differs wildly across targets.

To accomodate this, we use a weak symbol to implement a default version of the
command that fails with a QERR_NOT_SUPPORTED error code.  Targets can then
override and implement this command if it makes sense for them.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 qapi-schema.json |   23 +++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |    6 ++++++
 3 files changed, 35 insertions(+), 0 deletions(-)
Peter Maydell - July 27, 2012, 2 p.m.
On 27 July 2012 14:37, Anthony Liguori <aliguori@us.ibm.com> wrote:
> This command attempts to map to the behavior of -cpu ?.  Unfortunately, the
> output of this command differs wildly across targets.

I've never really understood why so much of the cpu selection
logic is deferred to target-*...

> To accomodate this, we use a weak symbol to implement a default version of the
> command that fails with a QERR_NOT_SUPPORTED error code.  Targets can then
> override and implement this command if it makes sense for them.

This is a bit of a weak reason (boom boom!) for requiring a platform
specific thing like weak symbols, though, and it's not how we handle
similar existing cases (eg see the configure/makefile logic for
memory_mapping.c vs memory_mapping-stub.c).

If having separate configure/make stuff for each of these things
sounds a bit heavyweight, we could just have a target-stubs.c which
#includes cpu.h and has a lot of
#ifndef TARGET_QUERY_CPUDEFS
[stub version]
#endif
#ifndef TARGET_GET_MEMORY_MAPPING
[stub version]
#endif

etc.

-- PMM
Anthony Liguori - July 27, 2012, 3:01 p.m.
Peter Maydell <peter.maydell@linaro.org> writes:

> On 27 July 2012 14:37, Anthony Liguori <aliguori@us.ibm.com> wrote:
>> This command attempts to map to the behavior of -cpu ?.  Unfortunately, the
>> output of this command differs wildly across targets.
>
> I've never really understood why so much of the cpu selection
> logic is deferred to target-*...

It will be fixed as part of the QOM conversion.

>> To accomodate this, we use a weak symbol to implement a default version of the
>> command that fails with a QERR_NOT_SUPPORTED error code.  Targets can then
>> override and implement this command if it makes sense for them.
>
> This is a bit of a weak reason (boom boom!) for requiring a platform
> specific thing like weak symbols, though, and it's not how we handle
> similar existing cases (eg see the configure/makefile logic for
> memory_mapping.c vs memory_mapping-stub.c).

I don't think we have a consistent approach today FWIW.  I think using
weak symbols is sufficiently compelling that it will become consistent.

>
> If having separate configure/make stuff for each of these things
> sounds a bit heavyweight, we could just have a target-stubs.c which
> #includes cpu.h and has a lot of
> #ifndef TARGET_QUERY_CPUDEFS
> [stub version]
> #endif
> #ifndef TARGET_GET_MEMORY_MAPPING
> [stub version]
> #endif

This is pretty hideous.

FWIW, weak symbols are supported on OS X as of 10.2.

Regards,

Anthony Liguori

>
> etc.
>
> -- PMM
Luiz Capitulino - July 27, 2012, 4:19 p.m.
On Fri, 27 Jul 2012 08:37:17 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> This command attempts to map to the behavior of -cpu ?.  Unfortunately, the
> output of this command differs wildly across targets.
> 
> To accomodate this, we use a weak symbol to implement a default version of the
> command that fails with a QERR_NOT_SUPPORTED error code.  Targets can then
> override and implement this command if it makes sense for them.
> 
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  qapi-schema.json |   23 +++++++++++++++++++++++
>  qmp-commands.hx  |    6 ++++++
>  qmp.c            |    6 ++++++
>  3 files changed, 35 insertions(+), 0 deletions(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 5b47026..768fb44 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2228,3 +2228,26 @@
>  # Since: 1.2.0
>  ##
>  { 'command': 'query-machines', 'returns': ['MachineInfo'] }
> +
> +##
> +# @CpuDefInfo:
> +#
> +# Virtual CPU definition.
> +#
> +# @name: the name of the CPU definition
> +#
> +# Since: 1.2.0
> +##
> +{ 'type': 'CpuDefInfo',
> +  'data': { 'name': 'str' } }
> +
> +##
> +# @query-cpudefs:

I'd call this query-cpu-defs or even query-cpu-difinitions. The latter makes
it self-documenting.

> +#
> +# Return a list of supported virtual CPU definitions
> +#
> +# Returns: a list of CpuDefInfo
> +#
> +# Since: 1.2.0
> +##
> +{ 'command': 'query-cpudefs', 'returns': ['CpuDefInfo'] }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index a6f82fc..73dfeab 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -2228,3 +2228,9 @@ EQMP
>          .mhandler.cmd_new = qmp_marshal_input_query_machines,
>      },
>  
> +    {
> +        .name       = "query-cpudefs",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_cpudefs,
> +    },
> +
> diff --git a/qmp.c b/qmp.c
> index 254a32f..51b4f75 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -467,3 +467,9 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
>  
>      return prop_list;
>  }
> +
> +CpuDefInfoList GCC_WEAK *qmp_query_cpudefs(Error **errp)
> +{
> +    error_set(errp, QERR_NOT_SUPPORTED);
> +    return NULL;
> +}
Eric Blake - July 27, 2012, 6:37 p.m.
On 07/27/2012 07:37 AM, Anthony Liguori wrote:
> This command attempts to map to the behavior of -cpu ?.  Unfortunately, the
> output of this command differs wildly across targets.
> 
> To accomodate this, we use a weak symbol to implement a default version of the

s/accomodate/accommodate/

> command that fails with a QERR_NOT_SUPPORTED error code.  Targets can then
> override and implement this command if it makes sense for them.
> 
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

> +##
> +# @CpuDefInfo:
> +#
> +# Virtual CPU definition.
> +#
> +# @name: the name of the CPU definition
> +#
> +# Since: 1.2.0

We are inconsistent in this file whether to use '1.2.0' or just '1.2';
probably worth a followup patch to clean whichever version is deemed
inappropriate.

> +##
> +{ 'type': 'CpuDefInfo',
> +  'data': { 'name': 'str' } }
> +
> +##
> +# @query-cpudefs:

I though QMP favored English words, as in 'query-cpu-definitions'

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index 5b47026..768fb44 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2228,3 +2228,26 @@ 
 # Since: 1.2.0
 ##
 { 'command': 'query-machines', 'returns': ['MachineInfo'] }
+
+##
+# @CpuDefInfo:
+#
+# Virtual CPU definition.
+#
+# @name: the name of the CPU definition
+#
+# Since: 1.2.0
+##
+{ 'type': 'CpuDefInfo',
+  'data': { 'name': 'str' } }
+
+##
+# @query-cpudefs:
+#
+# Return a list of supported virtual CPU definitions
+#
+# Returns: a list of CpuDefInfo
+#
+# Since: 1.2.0
+##
+{ 'command': 'query-cpudefs', 'returns': ['CpuDefInfo'] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a6f82fc..73dfeab 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2228,3 +2228,9 @@  EQMP
         .mhandler.cmd_new = qmp_marshal_input_query_machines,
     },
 
+    {
+        .name       = "query-cpudefs",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_cpudefs,
+    },
+
diff --git a/qmp.c b/qmp.c
index 254a32f..51b4f75 100644
--- a/qmp.c
+++ b/qmp.c
@@ -467,3 +467,9 @@  DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
 
     return prop_list;
 }
+
+CpuDefInfoList GCC_WEAK *qmp_query_cpudefs(Error **errp)
+{
+    error_set(errp, QERR_NOT_SUPPORTED);
+    return NULL;
+}