[Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86

Marc-André Lureau posted 54 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86
Posted by Marc-André Lureau 8 years, 5 months ago
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qapi-schema.json                       |  4 +++-
 include/sysemu/arch_init.h             |  3 ---
 monitor.c                              |  3 ---
 qmp.c                                  |  7 -------
 stubs/arch-query-cpu-model-expansion.c | 12 ------------
 target/i386/cpu.c                      |  2 +-
 target/s390x/cpu_models.c              |  3 ++-
 stubs/Makefile.objs                    |  1 -
 8 files changed, 6 insertions(+), 29 deletions(-)
 delete mode 100644 stubs/arch-query-cpu-model-expansion.c

diff --git a/qapi-schema.json b/qapi-schema.json
index 6c1adb35b5..127a2c71c6 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4535,7 +4535,9 @@
 { 'command': 'query-cpu-model-expansion',
   'data': { 'type': 'CpuModelExpansionType',
             'model': 'CpuModelInfo' },
-  'returns': 'CpuModelExpansionInfo' }
+  'returns': 'CpuModelExpansionInfo',
+  'if': ['defined(NEED_CPU_H)',
+         'defined(TARGET_S390X) || defined(TARGET_I386)']}
 
 ##
 # @CpuModelCompareResult:
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index e9f1ea0cca..fb3d20a1b8 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -32,8 +32,5 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
-CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
-                                                      CpuModelInfo *mode,
-                                                      Error **errp);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 6ddc3c7ff7..ca67a584d2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -971,9 +971,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
  */
 static void qmp_unregister_commands_hack(void)
 {
-#if !defined(TARGET_S390X) && !defined(TARGET_I386)
-    qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion");
-#endif
 #if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \
     && !defined(TARGET_S390X)
     qmp_unregister_command(&qmp_commands, "query-cpu-definitions");
diff --git a/qmp.c b/qmp.c
index 7b6861846f..afa266ec1e 100644
--- a/qmp.c
+++ b/qmp.c
@@ -546,13 +546,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     return arch_query_cpu_definitions(errp);
 }
 
-CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
-                                                     CpuModelInfo *model,
-                                                     Error **errp)
-{
-    return arch_query_cpu_model_expansion(type, 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/arch-query-cpu-model-expansion.c b/stubs/arch-query-cpu-model-expansion.c
deleted file mode 100644
index ae7cf554d1..0000000000
--- a/stubs/arch-query-cpu-model-expansion.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "qemu/osdep.h"
-#include "qemu-common.h"
-#include "sysemu/arch_init.h"
-#include "qapi/qmp/qerror.h"
-
-CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
-                                                      CpuModelInfo *mode,
-                                                      Error **errp)
-{
-    error_setg(errp, QERR_UNSUPPORTED);
-    return NULL;
-}
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ddc45abd70..d683e70a13 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2574,7 +2574,7 @@ out:
 }
 
 CpuModelExpansionInfo *
-arch_query_cpu_model_expansion(CpuModelExpansionType type,
+qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                       CpuModelInfo *model,
                                                       Error **errp)
 {
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index cdff9cdd3b..863dce064f 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -22,6 +22,7 @@
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
+#include "qmp-commands.h"
 
 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
     {                                                                    \
@@ -520,7 +521,7 @@ static void cpu_info_from_model(CpuModelInfo *info, const S390CPUModel *model,
     }
 }
 
-CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
+CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                       CpuModelInfo *model,
                                                       Error **errp)
 {
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 1421824eb3..eb17628ede 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,5 +1,4 @@
 stub-obj-y += arch-query-cpu-def.o
-stub-obj-y += arch-query-cpu-model-expansion.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
-- 
2.14.1.146.gd35faa819


Re: [Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86
Posted by Eduardo Habkost 8 years, 5 months ago
On Tue, Aug 22, 2017 at 03:22:54PM +0200, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  qapi-schema.json                       |  4 +++-
>  include/sysemu/arch_init.h             |  3 ---
>  monitor.c                              |  3 ---
>  qmp.c                                  |  7 -------
>  stubs/arch-query-cpu-model-expansion.c | 12 ------------
>  target/i386/cpu.c                      |  2 +-
>  target/s390x/cpu_models.c              |  3 ++-
>  stubs/Makefile.objs                    |  1 -
>  8 files changed, 6 insertions(+), 29 deletions(-)
>  delete mode 100644 stubs/arch-query-cpu-model-expansion.c
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 6c1adb35b5..127a2c71c6 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -4535,7 +4535,9 @@
>  { 'command': 'query-cpu-model-expansion',
>    'data': { 'type': 'CpuModelExpansionType',
>              'model': 'CpuModelInfo' },
> -  'returns': 'CpuModelExpansionInfo' }
> +  'returns': 'CpuModelExpansionInfo',
> +  'if': ['defined(NEED_CPU_H)',
> +         'defined(TARGET_S390X) || defined(TARGET_I386)']}

Maybe this is already documented somewhere in the series (I'm
still going through the other patches), but: why exactly is
'defined(NEED_CPU_H)' in the list, too?

I always assumed that all the QAPI and QMP dispatching code would
be compiled only once, and never be compiled with -DNEED_CPU_H
defined.

-- 
Eduardo

Re: [Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86
Posted by Marc-André Lureau 8 years, 5 months ago
Hi

----- Original Message -----
> On Tue, Aug 22, 2017 at 03:22:54PM +0200, Marc-André Lureau wrote:
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  qapi-schema.json                       |  4 +++-
> >  include/sysemu/arch_init.h             |  3 ---
> >  monitor.c                              |  3 ---
> >  qmp.c                                  |  7 -------
> >  stubs/arch-query-cpu-model-expansion.c | 12 ------------
> >  target/i386/cpu.c                      |  2 +-
> >  target/s390x/cpu_models.c              |  3 ++-
> >  stubs/Makefile.objs                    |  1 -
> >  8 files changed, 6 insertions(+), 29 deletions(-)
> >  delete mode 100644 stubs/arch-query-cpu-model-expansion.c
> > 
> > diff --git a/qapi-schema.json b/qapi-schema.json
> > index 6c1adb35b5..127a2c71c6 100644
> > --- a/qapi-schema.json
> > +++ b/qapi-schema.json
> > @@ -4535,7 +4535,9 @@
> >  { 'command': 'query-cpu-model-expansion',
> >    'data': { 'type': 'CpuModelExpansionType',
> >              'model': 'CpuModelInfo' },
> > -  'returns': 'CpuModelExpansionInfo' }
> > +  'returns': 'CpuModelExpansionInfo',
> > +  'if': ['defined(NEED_CPU_H)',
> > +         'defined(TARGET_S390X) || defined(TARGET_I386)']}
> 
> Maybe this is already documented somewhere in the series (I'm
> still going through the other patches), but: why exactly is
> 'defined(NEED_CPU_H)' in the list, too?

The point of this series is to make qapi schema configurable.

Some types/commands/events are target-specifc. In order to #ifdef on poisoined symbols, we make most of QAPI generated code built per-target in patch 49/54. But the common code still need to compile some units, that's why #ifdef NEED_CPU_U. The clean solution is probably to split the generated schema to common & per-target, that's not covered in the series.

> 
> I always assumed that all the QAPI and QMP dispatching code would
> be compiled only once, and never be compiled with -DNEED_CPU_H
> defined.

No longer after 49/54.

Re: [Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86
Posted by Eduardo Habkost 8 years, 5 months ago
On Wed, Aug 23, 2017 at 06:21:16AM -0400, Marc-André Lureau wrote:
> Hi
> 
> ----- Original Message -----
> > On Tue, Aug 22, 2017 at 03:22:54PM +0200, Marc-André Lureau wrote:
> > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > ---
> > >  qapi-schema.json                       |  4 +++-
> > >  include/sysemu/arch_init.h             |  3 ---
> > >  monitor.c                              |  3 ---
> > >  qmp.c                                  |  7 -------
> > >  stubs/arch-query-cpu-model-expansion.c | 12 ------------
> > >  target/i386/cpu.c                      |  2 +-
> > >  target/s390x/cpu_models.c              |  3 ++-
> > >  stubs/Makefile.objs                    |  1 -
> > >  8 files changed, 6 insertions(+), 29 deletions(-)
> > >  delete mode 100644 stubs/arch-query-cpu-model-expansion.c
> > > 
> > > diff --git a/qapi-schema.json b/qapi-schema.json
> > > index 6c1adb35b5..127a2c71c6 100644
> > > --- a/qapi-schema.json
> > > +++ b/qapi-schema.json
> > > @@ -4535,7 +4535,9 @@
> > >  { 'command': 'query-cpu-model-expansion',
> > >    'data': { 'type': 'CpuModelExpansionType',
> > >              'model': 'CpuModelInfo' },
> > > -  'returns': 'CpuModelExpansionInfo' }
> > > +  'returns': 'CpuModelExpansionInfo',
> > > +  'if': ['defined(NEED_CPU_H)',
> > > +         'defined(TARGET_S390X) || defined(TARGET_I386)']}
> > 
> > Maybe this is already documented somewhere in the series (I'm
> > still going through the other patches), but: why exactly is
> > 'defined(NEED_CPU_H)' in the list, too?
> 
> The point of this series is to make qapi schema configurable.
> 
> Some types/commands/events are target-specifc. In order to
> #ifdef on poisoined symbols, we make most of QAPI generated
> code built per-target in patch 49/54. But the common code still
> need to compile some units, that's why #ifdef NEED_CPU_U. The
> clean solution is probably to split the generated schema to
> common & per-target, that's not covered in the series.

I see.  I'm worried about one thing: what if the QMP dispatch
code is incorrectly moved back to common code later?  It will
silently skip all the arch-dependent commands without any
warnings.

e.g.: I just applied the following change on top of your series,
and all arch-dependent commands are silently skipped:

  diff --git a/Makefile.objs b/Makefile.objs
  index 2664720..24a4ea0 100644
  --- a/Makefile.objs
  +++ b/Makefile.objs
  @@ -2,7 +2,7 @@
   # Common libraries for tools and emulators
   stub-obj-y = stubs/ crypto/
   util-obj-y = util/ qobject/ qapi/
  -util-obj-y += qapi-types.o qapi-visit.o
  +util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
   
   chardev-obj-y = chardev/
   
  @@ -72,6 +72,13 @@ common-obj-y += chardev/
   common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
   
   common-obj-$(CONFIG_FDT) += device_tree.o
  +
  +######################################################################
  +# qapi
  +
  +common-obj-y += qmp-marshal.o
  +common-obj-y += qmp-introspect.o
  +common-obj-y += qmp.o hmp.o
   endif
   
   #######################################################################
  diff --git a/Makefile.target b/Makefile.target
  index c5f8ded..7f42c45 100644
  --- a/Makefile.target
  +++ b/Makefile.target
  @@ -157,10 +157,6 @@ endif
   
   GENERATED_FILES += hmp-commands.h hmp-commands-info.h
   
  -obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
  -obj-y += qmp-marshal.o qmp-introspect.o
  -obj-y += qmp.o hmp.o
  -
   endif # CONFIG_SOFTMMU
   
   # Workaround for http://gcc.gnu.org/PR55489, see configure.


We wouldn't need to check NEED_CPU_H at all if the condition on
QMP commands affect only the actual QMP dispatch code, and not
the generated types or declarations.  e.g.:


diff --git a/qapi-schema.json b/qapi-schema.json
index 194859f..67b46ad 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3578,7 +3578,7 @@
 ##
 { 'command': 'dump-skeys',
   'data': { 'filename': 'str' },
-  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
+  'if': ['defined(TARGET_S390X)']}
 
 ##
 # @netdev_add:
@@ -4434,8 +4434,7 @@
 # Since: 1.2.0
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'],
-  'if': ['defined(NEED_CPU_H)',
-         'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X)'] }
+  'if': ['defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X)'] }
 
 ##
 # @CpuModelInfo:
@@ -4538,8 +4537,7 @@
   'data': { 'type': 'CpuModelExpansionType',
             'model': 'CpuModelInfo' },
   'returns': 'CpuModelExpansionInfo',
-  'if': ['defined(NEED_CPU_H)',
-         'defined(TARGET_S390X) || defined(TARGET_I386)']}
+  'if': ['defined(TARGET_S390X) || defined(TARGET_I386)']}
 
 ##
 # @CpuModelCompareResult:
@@ -4627,7 +4625,7 @@
 { 'command': 'query-cpu-model-comparison',
   'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' },
   'returns': 'CpuModelCompareInfo',
-  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
+  'if': ['defined(TARGET_S390X)']}
 
 
 ##
@@ -4681,7 +4679,7 @@
   'data': { 'modela': 'CpuModelInfo',
             'modelb': 'CpuModelInfo' },
   'returns': 'CpuModelBaselineInfo',
-  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
+  'if': ['defined(TARGET_S390X)']}
 
 ##
 # @AddfdInfo:
@@ -6303,7 +6301,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_I386)'] }
+  'if': ['defined(TARGET_I386)'] }
 
 # Rocker ethernet network switch
 { 'include': 'qapi/rocker.json' }
@@ -6466,7 +6464,7 @@
 #
 ##
 { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'],
-  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_ARM)']}
+  'if': ['defined(TARGET_ARM)']}
 
 ##
 # @CpuInstanceProperties:
diff --git a/scripts/qapi.py b/scripts/qapi.py
index bcd8d37..769a730 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1720,8 +1720,7 @@ class QAPISchema(object):
         ifcond = expr.get('if')
         if isinstance(data, OrderedDict):
             data = self._make_implicit_object_type(
-                name, info, doc, 'arg', self._make_members(data, info),
-                ifcond)
+                name, info, doc, 'arg', self._make_members(data, info))
         if isinstance(rets, list):
             assert len(rets) == 1
             rets = self._make_array_type(rets[0], info)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index db45415..2baa73f 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -228,7 +228,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
         self.defn = None
         self._regy = None
         self._visited_ret_types = None
-        self.if_members = ['decl', 'defn', '_regy']
+        self.if_members = ['defn', '_regy']
 
     def visit_begin(self, schema):
         self.decl = ''


-- 
Eduardo

Re: [Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86
Posted by Marc-André Lureau 8 years, 5 months ago
Hi

----- Original Message -----
> On Wed, Aug 23, 2017 at 06:21:16AM -0400, Marc-André Lureau wrote:
> > Hi
> > 
> > ----- Original Message -----
> > > On Tue, Aug 22, 2017 at 03:22:54PM +0200, Marc-André Lureau wrote:
> > > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > > ---
> > > >  qapi-schema.json                       |  4 +++-
> > > >  include/sysemu/arch_init.h             |  3 ---
> > > >  monitor.c                              |  3 ---
> > > >  qmp.c                                  |  7 -------
> > > >  stubs/arch-query-cpu-model-expansion.c | 12 ------------
> > > >  target/i386/cpu.c                      |  2 +-
> > > >  target/s390x/cpu_models.c              |  3 ++-
> > > >  stubs/Makefile.objs                    |  1 -
> > > >  8 files changed, 6 insertions(+), 29 deletions(-)
> > > >  delete mode 100644 stubs/arch-query-cpu-model-expansion.c
> > > > 
> > > > diff --git a/qapi-schema.json b/qapi-schema.json
> > > > index 6c1adb35b5..127a2c71c6 100644
> > > > --- a/qapi-schema.json
> > > > +++ b/qapi-schema.json
> > > > @@ -4535,7 +4535,9 @@
> > > >  { 'command': 'query-cpu-model-expansion',
> > > >    'data': { 'type': 'CpuModelExpansionType',
> > > >              'model': 'CpuModelInfo' },
> > > > -  'returns': 'CpuModelExpansionInfo' }
> > > > +  'returns': 'CpuModelExpansionInfo',
> > > > +  'if': ['defined(NEED_CPU_H)',
> > > > +         'defined(TARGET_S390X) || defined(TARGET_I386)']}
> > > 
> > > Maybe this is already documented somewhere in the series (I'm
> > > still going through the other patches), but: why exactly is
> > > 'defined(NEED_CPU_H)' in the list, too?
> > 
> > The point of this series is to make qapi schema configurable.
> > 
> > Some types/commands/events are target-specifc. In order to
> > #ifdef on poisoined symbols, we make most of QAPI generated
> > code built per-target in patch 49/54. But the common code still
> > need to compile some units, that's why #ifdef NEED_CPU_U. The
> > clean solution is probably to split the generated schema to
> > common & per-target, that's not covered in the series.
> 
> I see.  I'm worried about one thing: what if the QMP dispatch
> code is incorrectly moved back to common code later?  It will
> silently skip all the arch-dependent commands without any
> warnings.
> 
> e.g.: I just applied the following change on top of your series,
> and all arch-dependent commands are silently skipped:
> 

And it doesn't fail a full/all-arch make check? It probably should.

>   diff --git a/Makefile.objs b/Makefile.objs
>   index 2664720..24a4ea0 100644
>   --- a/Makefile.objs
>   +++ b/Makefile.objs
>   @@ -2,7 +2,7 @@
>    # Common libraries for tools and emulators
>    stub-obj-y = stubs/ crypto/
>    util-obj-y = util/ qobject/ qapi/
>   -util-obj-y += qapi-types.o qapi-visit.o
>   +util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
>    
>    chardev-obj-y = chardev/
>    
>   @@ -72,6 +72,13 @@ common-obj-y += chardev/
>    common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
>    
>    common-obj-$(CONFIG_FDT) += device_tree.o
>   +
>   +######################################################################
>   +# qapi
>   +
>   +common-obj-y += qmp-marshal.o
>   +common-obj-y += qmp-introspect.o
>   +common-obj-y += qmp.o hmp.o
>    endif
>    
>    #######################################################################
>   diff --git a/Makefile.target b/Makefile.target
>   index c5f8ded..7f42c45 100644
>   --- a/Makefile.target
>   +++ b/Makefile.target
>   @@ -157,10 +157,6 @@ endif
>    
>    GENERATED_FILES += hmp-commands.h hmp-commands-info.h
>    
>   -obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
>   -obj-y += qmp-marshal.o qmp-introspect.o
>   -obj-y += qmp.o hmp.o
>   -
>    endif # CONFIG_SOFTMMU
>    
>    # Workaround for http://gcc.gnu.org/PR55489, see configure.
> 
> 
> We wouldn't need to check NEED_CPU_H at all if the condition on
> QMP commands affect only the actual QMP dispatch code, and not
> the generated types or declarations.  e.g.:
> 

Possible, but is it desirable? I would prefer if all the generated code would be configured, so we can more easily compile out dead code when disabling a feature. 

> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 194859f..67b46ad 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3578,7 +3578,7 @@
>  ##
>  { 'command': 'dump-skeys',
>    'data': { 'filename': 'str' },
> -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
> +  'if': ['defined(TARGET_S390X)']}
>  
>  ##
>  # @netdev_add:
> @@ -4434,8 +4434,7 @@
>  # Since: 1.2.0
>  ##
>  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'],
> -  'if': ['defined(NEED_CPU_H)',
> -         'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386)
> || defined(TARGET_S390X)'] }
> +  'if': ['defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386)
> || defined(TARGET_S390X)'] }
>  
>  ##
>  # @CpuModelInfo:
> @@ -4538,8 +4537,7 @@
>    'data': { 'type': 'CpuModelExpansionType',
>              'model': 'CpuModelInfo' },
>    'returns': 'CpuModelExpansionInfo',
> -  'if': ['defined(NEED_CPU_H)',
> -         'defined(TARGET_S390X) || defined(TARGET_I386)']}
> +  'if': ['defined(TARGET_S390X) || defined(TARGET_I386)']}
>  
>  ##
>  # @CpuModelCompareResult:
> @@ -4627,7 +4625,7 @@
>  { 'command': 'query-cpu-model-comparison',
>    'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' },
>    'returns': 'CpuModelCompareInfo',
> -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
> +  'if': ['defined(TARGET_S390X)']}
>  
>  
>  ##
> @@ -4681,7 +4679,7 @@
>    'data': { 'modela': 'CpuModelInfo',
>              'modelb': 'CpuModelInfo' },
>    'returns': 'CpuModelBaselineInfo',
> -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
> +  'if': ['defined(TARGET_S390X)']}
>  
>  ##
>  # @AddfdInfo:
> @@ -6303,7 +6301,7 @@
>  #
>  ##
>  { 'command': 'rtc-reset-reinjection',
> -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_I386)'] }
> +  'if': ['defined(TARGET_I386)'] }
>  
>  # Rocker ethernet network switch
>  { 'include': 'qapi/rocker.json' }
> @@ -6466,7 +6464,7 @@
>  #
>  ##
>  { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'],
> -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_ARM)']}
> +  'if': ['defined(TARGET_ARM)']}
>  
>  ##
>  # @CpuInstanceProperties:
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index bcd8d37..769a730 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -1720,8 +1720,7 @@ class QAPISchema(object):
>          ifcond = expr.get('if')
>          if isinstance(data, OrderedDict):
>              data = self._make_implicit_object_type(
> -                name, info, doc, 'arg', self._make_members(data, info),
> -                ifcond)
> +                name, info, doc, 'arg', self._make_members(data, info))
>          if isinstance(rets, list):
>              assert len(rets) == 1
>              rets = self._make_array_type(rets[0], info)
> diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
> index db45415..2baa73f 100644
> --- a/scripts/qapi-commands.py
> +++ b/scripts/qapi-commands.py
> @@ -228,7 +228,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
>          self.defn = None
>          self._regy = None
>          self._visited_ret_types = None
> -        self.if_members = ['decl', 'defn', '_regy']
> +        self.if_members = ['defn', '_regy']
>  
>      def visit_begin(self, schema):
>          self.decl = ''
> 
> 
> --
> Eduardo
> 

Re: [Qemu-devel] [PATCH v2 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86
Posted by Eduardo Habkost 8 years, 5 months ago
On Wed, Aug 23, 2017 at 09:58:59AM -0400, Marc-André Lureau wrote:
> Hi
> 
> ----- Original Message -----
> > On Wed, Aug 23, 2017 at 06:21:16AM -0400, Marc-André Lureau wrote:
> > > Hi
> > > 
> > > ----- Original Message -----
> > > > On Tue, Aug 22, 2017 at 03:22:54PM +0200, Marc-André Lureau wrote:
> > > > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > > > > ---
> > > > >  qapi-schema.json                       |  4 +++-
> > > > >  include/sysemu/arch_init.h             |  3 ---
> > > > >  monitor.c                              |  3 ---
> > > > >  qmp.c                                  |  7 -------
> > > > >  stubs/arch-query-cpu-model-expansion.c | 12 ------------
> > > > >  target/i386/cpu.c                      |  2 +-
> > > > >  target/s390x/cpu_models.c              |  3 ++-
> > > > >  stubs/Makefile.objs                    |  1 -
> > > > >  8 files changed, 6 insertions(+), 29 deletions(-)
> > > > >  delete mode 100644 stubs/arch-query-cpu-model-expansion.c
> > > > > 
> > > > > diff --git a/qapi-schema.json b/qapi-schema.json
> > > > > index 6c1adb35b5..127a2c71c6 100644
> > > > > --- a/qapi-schema.json
> > > > > +++ b/qapi-schema.json
> > > > > @@ -4535,7 +4535,9 @@
> > > > >  { 'command': 'query-cpu-model-expansion',
> > > > >    'data': { 'type': 'CpuModelExpansionType',
> > > > >              'model': 'CpuModelInfo' },
> > > > > -  'returns': 'CpuModelExpansionInfo' }
> > > > > +  'returns': 'CpuModelExpansionInfo',
> > > > > +  'if': ['defined(NEED_CPU_H)',
> > > > > +         'defined(TARGET_S390X) || defined(TARGET_I386)']}
> > > > 
> > > > Maybe this is already documented somewhere in the series (I'm
> > > > still going through the other patches), but: why exactly is
> > > > 'defined(NEED_CPU_H)' in the list, too?
> > > 
> > > The point of this series is to make qapi schema configurable.
> > > 
> > > Some types/commands/events are target-specifc. In order to
> > > #ifdef on poisoined symbols, we make most of QAPI generated
> > > code built per-target in patch 49/54. But the common code still
> > > need to compile some units, that's why #ifdef NEED_CPU_U. The
> > > clean solution is probably to split the generated schema to
> > > common & per-target, that's not covered in the series.
> > 
> > I see.  I'm worried about one thing: what if the QMP dispatch
> > code is incorrectly moved back to common code later?  It will
> > silently skip all the arch-dependent commands without any
> > warnings.
> > 
> > e.g.: I just applied the following change on top of your series,
> > and all arch-dependent commands are silently skipped:
> > 
> 
> And it doesn't fail a full/all-arch make check? It probably should.

I don't know, I will test it.

> 
> >   diff --git a/Makefile.objs b/Makefile.objs
> >   index 2664720..24a4ea0 100644
> >   --- a/Makefile.objs
> >   +++ b/Makefile.objs
> >   @@ -2,7 +2,7 @@
> >    # Common libraries for tools and emulators
> >    stub-obj-y = stubs/ crypto/
> >    util-obj-y = util/ qobject/ qapi/
> >   -util-obj-y += qapi-types.o qapi-visit.o
> >   +util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
> >    
> >    chardev-obj-y = chardev/
> >    
> >   @@ -72,6 +72,13 @@ common-obj-y += chardev/
> >    common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
> >    
> >    common-obj-$(CONFIG_FDT) += device_tree.o
> >   +
> >   +######################################################################
> >   +# qapi
> >   +
> >   +common-obj-y += qmp-marshal.o
> >   +common-obj-y += qmp-introspect.o
> >   +common-obj-y += qmp.o hmp.o
> >    endif
> >    
> >    #######################################################################
> >   diff --git a/Makefile.target b/Makefile.target
> >   index c5f8ded..7f42c45 100644
> >   --- a/Makefile.target
> >   +++ b/Makefile.target
> >   @@ -157,10 +157,6 @@ endif
> >    
> >    GENERATED_FILES += hmp-commands.h hmp-commands-info.h
> >    
> >   -obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o
> >   -obj-y += qmp-marshal.o qmp-introspect.o
> >   -obj-y += qmp.o hmp.o
> >   -
> >    endif # CONFIG_SOFTMMU
> >    
> >    # Workaround for http://gcc.gnu.org/PR55489, see configure.
> > 
> > 
> > We wouldn't need to check NEED_CPU_H at all if the condition on
> > QMP commands affect only the actual QMP dispatch code, and not
> > the generated types or declarations.  e.g.:
> > 
> 
> Possible, but is it desirable? I would prefer if all the
> generated code would be configured, so we can more easily
> compile out dead code when disabling a feature. 

That's a valid question.

A check for defined(NEED_CPU_H) inside a .c file still feels
wrong to me.  But if "make check" will detect a mistake like the
one above and QAPI maintainers don't mind, I won't mind either.


> > 
> > diff --git a/qapi-schema.json b/qapi-schema.json
> > index 194859f..67b46ad 100644
> > --- a/qapi-schema.json
> > +++ b/qapi-schema.json
> > @@ -3578,7 +3578,7 @@
> >  ##
> >  { 'command': 'dump-skeys',
> >    'data': { 'filename': 'str' },
> > -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
> > +  'if': ['defined(TARGET_S390X)']}
> >  
> >  ##
> >  # @netdev_add:
> > @@ -4434,8 +4434,7 @@
> >  # Since: 1.2.0
> >  ##
> >  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'],
> > -  'if': ['defined(NEED_CPU_H)',
> > -         'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386)
> > || defined(TARGET_S390X)'] }
> > +  'if': ['defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386)
> > || defined(TARGET_S390X)'] }
> >  
> >  ##
> >  # @CpuModelInfo:
> > @@ -4538,8 +4537,7 @@
> >    'data': { 'type': 'CpuModelExpansionType',
> >              'model': 'CpuModelInfo' },
> >    'returns': 'CpuModelExpansionInfo',
> > -  'if': ['defined(NEED_CPU_H)',
> > -         'defined(TARGET_S390X) || defined(TARGET_I386)']}
> > +  'if': ['defined(TARGET_S390X) || defined(TARGET_I386)']}
> >  
> >  ##
> >  # @CpuModelCompareResult:
> > @@ -4627,7 +4625,7 @@
> >  { 'command': 'query-cpu-model-comparison',
> >    'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' },
> >    'returns': 'CpuModelCompareInfo',
> > -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
> > +  'if': ['defined(TARGET_S390X)']}
> >  
> >  
> >  ##
> > @@ -4681,7 +4679,7 @@
> >    'data': { 'modela': 'CpuModelInfo',
> >              'modelb': 'CpuModelInfo' },
> >    'returns': 'CpuModelBaselineInfo',
> > -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']}
> > +  'if': ['defined(TARGET_S390X)']}
> >  
> >  ##
> >  # @AddfdInfo:
> > @@ -6303,7 +6301,7 @@
> >  #
> >  ##
> >  { 'command': 'rtc-reset-reinjection',
> > -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_I386)'] }
> > +  'if': ['defined(TARGET_I386)'] }
> >  
> >  # Rocker ethernet network switch
> >  { 'include': 'qapi/rocker.json' }
> > @@ -6466,7 +6464,7 @@
> >  #
> >  ##
> >  { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'],
> > -  'if': ['defined(NEED_CPU_H)', 'defined(TARGET_ARM)']}
> > +  'if': ['defined(TARGET_ARM)']}
> >  
> >  ##
> >  # @CpuInstanceProperties:
> > diff --git a/scripts/qapi.py b/scripts/qapi.py
> > index bcd8d37..769a730 100644
> > --- a/scripts/qapi.py
> > +++ b/scripts/qapi.py
> > @@ -1720,8 +1720,7 @@ class QAPISchema(object):
> >          ifcond = expr.get('if')
> >          if isinstance(data, OrderedDict):
> >              data = self._make_implicit_object_type(
> > -                name, info, doc, 'arg', self._make_members(data, info),
> > -                ifcond)
> > +                name, info, doc, 'arg', self._make_members(data, info))
> >          if isinstance(rets, list):
> >              assert len(rets) == 1
> >              rets = self._make_array_type(rets[0], info)
> > diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
> > index db45415..2baa73f 100644
> > --- a/scripts/qapi-commands.py
> > +++ b/scripts/qapi-commands.py
> > @@ -228,7 +228,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
> >          self.defn = None
> >          self._regy = None
> >          self._visited_ret_types = None
> > -        self.if_members = ['decl', 'defn', '_regy']
> > +        self.if_members = ['defn', '_regy']
> >  
> >      def visit_begin(self, schema):
> >          self.decl = ''
> > 
> > 
> > --
> > Eduardo
> > 

-- 
Eduardo