From ec150c7e09071bcf51bfaa8071fe23efb6df69f7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:31 +0200 Subject: include: Make headers more self-contained MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Back in 2016, we discussed[1] rules for headers, and these were generally liked: 1. Have a carefully curated header that's included everywhere first. We got that already thanks to Peter: osdep.h. 2. Headers should normally include everything they need beyond osdep.h. If exceptions are needed for some reason, they must be documented in the header. If all that's needed from a header is typedefs, put those into qemu/typedefs.h instead of including the header. 3. Cyclic inclusion is forbidden. This patch gets include/ closer to obeying 2. It's actually extracted from my "[RFC] Baby steps towards saner headers" series[2], which demonstrates a possible path towards checking 2 automatically. It passes the RFC test there. [1] Message-ID: <87h9g8j57d.fsf@blackfin.pond.sub.org> https://lists.nongnu.org/archive/html/qemu-devel/2016-03/msg03345.html [2] Message-Id: <20190711122827.18970-1-armbru@redhat.com> https://lists.nongnu.org/archive/html/qemu-devel/2019-07/msg02715.html Signed-off-by: Markus Armbruster Reviewed-by: Alistair Francis Message-Id: <20190812052359.30071-2-armbru@redhat.com> Tested-by: Philippe Mathieu-Daudé --- include/migration/cpu.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/migration') diff --git a/include/migration/cpu.h b/include/migration/cpu.h index a40bd3549f..da1618d620 100644 --- a/include/migration/cpu.h +++ b/include/migration/cpu.h @@ -1,7 +1,10 @@ /* Declarations for use for CPU state serialization. */ + #ifndef MIGRATION_CPU_H #define MIGRATION_CPU_H +#include "exec/cpu-defs.h" + #if TARGET_LONG_BITS == 64 #define qemu_put_betl qemu_put_be64 #define qemu_get_betl qemu_get_be64 -- cgit v1.2.3 From 2ae16a6aa4ce688e2ee25dec3ad2f023bece0b14 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:32 +0200 Subject: Include generated QAPI headers less MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some of the generated qapi-types-MODULE.h are included all over the place. Changing a QAPI type can trigger massive recompiling. Top scorers recompile more than 1000 out of some 6600 objects (not counting tests and objects that don't depend on qemu/osdep.h): 6300 qapi/qapi-builtin-types.h 5700 qapi/qapi-types-run-state.h 3900 qapi/qapi-types-common.h 3300 qapi/qapi-types-sockets.h 3000 qapi/qapi-types-misc.h 3000 qapi/qapi-types-crypto.h 3000 qapi/qapi-types-job.h 3000 qapi/qapi-types-block-core.h 2800 qapi/qapi-types-block.h 1300 qapi/qapi-types-net.h Clean up headers to include generated QAPI headers only where needed. Impact is negligible except for hw/qdev-properties.h. This header includes qapi/qapi-types-block.h and qapi/qapi-types-misc.h. They are used only in expansions of property definition macros such as DEFINE_PROP_BLOCKDEV_ON_ERROR() and DEFINE_PROP_OFF_AUTO(). Moving their inclusion from hw/qdev-properties.h to the users of these macros avoids pointless recompiles. This is how other property definition macros, such as DEFINE_PROP_NETDEV(), already work. Improves things for some of the top scorers: 3600 qapi/qapi-types-common.h 2800 qapi/qapi-types-sockets.h 900 qapi/qapi-types-misc.h 2200 qapi/qapi-types-crypto.h 2100 qapi/qapi-types-job.h 2100 qapi/qapi-types-block-core.h 270 qapi/qapi-types-block.h Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Message-Id: <20190812052359.30071-3-armbru@redhat.com> --- include/migration/global_state.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/migration') diff --git a/include/migration/global_state.h b/include/migration/global_state.h index fd22dd3034..d307de8350 100644 --- a/include/migration/global_state.h +++ b/include/migration/global_state.h @@ -13,7 +13,6 @@ #ifndef QEMU_MIGRATION_GLOBAL_STATE_H #define QEMU_MIGRATION_GLOBAL_STATE_H -#include "qapi/qapi-types-run-state.h" #include "sysemu/sysemu.h" void register_global_state(void); -- cgit v1.2.3 From ca77ee28e03fb5052be01b9237b0a7cef5d90d4a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:39 +0200 Subject: Include migration/qemu-file-types.h a lot less MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In my "build everything" tree, changing migration/qemu-file-types.h triggers a recompile of some 2600 out of 6600 objects (not counting tests and objects that don't depend on qemu/osdep.h). The culprit is again hw/hw.h, which supposedly includes it for convenience. Include migration/qemu-file-types.h only where it's needed. Touching it now recompiles less than 200 objects. Signed-off-by: Markus Armbruster Message-Id: <20190812052359.30071-10-armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- include/migration/cpu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/migration') diff --git a/include/migration/cpu.h b/include/migration/cpu.h index da1618d620..2a22470d0d 100644 --- a/include/migration/cpu.h +++ b/include/migration/cpu.h @@ -4,6 +4,7 @@ #define MIGRATION_CPU_H #include "exec/cpu-defs.h" +#include "migration/qemu-file-types.h" #if TARGET_LONG_BITS == 64 #define qemu_put_betl qemu_put_be64 -- cgit v1.2.3 From 6a0acfff997c294ad935b9f0b713a62bec68f50b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:43 +0200 Subject: Clean up inclusion of exec/cpu-common.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit migration/qemu-file.h neglects to include it even though it needs ram_addr_t. Fix that. Drop a few superfluous inclusions elsewhere. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Message-Id: <20190812052359.30071-14-armbru@redhat.com> --- include/migration/misc.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/migration') diff --git a/include/migration/misc.h b/include/migration/misc.h index 5cdbabd094..b9d8e787af 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -14,7 +14,6 @@ #ifndef MIGRATION_MISC_H #define MIGRATION_MISC_H -#include "exec/cpu-common.h" #include "qemu/notify.h" #include "qapi/qapi-types-net.h" -- cgit v1.2.3 From 8a9358cc6e6a6ba3685e1b6e8bbf6fa194a38379 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:44 +0200 Subject: migration: Move the VMStateDescription typedef to typedefs.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We declare incomplete struct VMStateDescription in a couple of places so we don't have to include migration/vmstate.h for the typedef. That's fine with me. However, the next commit will drop migration/vmstate.h from a massive number of compiles. Move the typedef to qemu/typedefs.h now, so I don't have to insert struct in front of VMStateDescription all over the place then. Signed-off-by: Markus Armbruster Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Message-Id: <20190812052359.30071-15-armbru@redhat.com> --- include/migration/vmstate.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/migration') diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index c2bfa7a7f0..1fbfd099dd 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -28,7 +28,6 @@ #define QEMU_VMSTATE_H typedef struct VMStateInfo VMStateInfo; -typedef struct VMStateDescription VMStateDescription; typedef struct VMStateField VMStateField; /* VMStateInfo allows customized migration of objects that don't fit in -- cgit v1.2.3 From d6454270575da1f16a8923c7cb240e46ef243f72 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:45 +0200 Subject: Include migration/vmstate.h less MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In my "build everything" tree, changing migration/vmstate.h triggers a recompile of some 2700 out of 6600 objects (not counting tests and objects that don't depend on qemu/osdep.h). hw/hw.h supposedly includes it for convenience. Several other headers include it just to get VMStateDescription. The previous commit made that unnecessary. Include migration/vmstate.h only where it's still needed. Touching it now recompiles only some 1600 objects. Signed-off-by: Markus Armbruster Reviewed-by: Alistair Francis Message-Id: <20190812052359.30071-16-armbru@redhat.com> Tested-by: Philippe Mathieu-Daudé --- include/migration/cpu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/migration') diff --git a/include/migration/cpu.h b/include/migration/cpu.h index 2a22470d0d..65abe3c8cc 100644 --- a/include/migration/cpu.h +++ b/include/migration/cpu.h @@ -5,6 +5,7 @@ #include "exec/cpu-defs.h" #include "migration/qemu-file-types.h" +#include "migration/vmstate.h" #if TARGET_LONG_BITS == 64 #define qemu_put_betl qemu_put_be64 -- cgit v1.2.3 From d5938f29fea29581725426f203a74da746ca03e7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 12 Aug 2019 07:23:56 +0200 Subject: Clean up inclusion of sysemu/sysemu.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In my "build everything" tree, changing sysemu/sysemu.h triggers a recompile of some 5400 out of 6600 objects (not counting tests and objects that don't depend on qemu/osdep.h). Almost a third of its inclusions are actually superfluous. Delete them. Downgrade two more to qapi/qapi-types-run-state.h, and move one from char/serial.h to char/serial.c. hw/semihosting/config.c, monitor/monitor.c, qdev-monitor.c, and stubs/semihost.c define variables declared in sysemu/sysemu.h without including it. The compiler is cool with that, but include it anyway. This doesn't reduce actual use much, as it's still included into widely included headers. The next commit will tackle that. Signed-off-by: Markus Armbruster Reviewed-by: Alistair Francis Message-Id: <20190812052359.30071-27-armbru@redhat.com> Reviewed-by: Alex Bennée --- include/migration/global_state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/migration') diff --git a/include/migration/global_state.h b/include/migration/global_state.h index d307de8350..945eb35d5b 100644 --- a/include/migration/global_state.h +++ b/include/migration/global_state.h @@ -13,7 +13,7 @@ #ifndef QEMU_MIGRATION_GLOBAL_STATE_H #define QEMU_MIGRATION_GLOBAL_STATE_H -#include "sysemu/sysemu.h" +#include "qapi/qapi-types-run-state.h" void register_global_state(void); int global_state_store(void); -- cgit v1.2.3