kbuild: reduce single-build dependencies
v2 cover kbuild: reduce single-build dependencies
Building a single .o file depends on the prepare target which contains a lot of dependencies. Some of those preparation dependencies are not needed for a single .o build.
This is a small annoyance because a modification of the compilation flags causes several prepare dependencies to rebuild. Consequently, single-build incurs an artificial penalty.
Move the generic preparation checks and scripts/mod out of the single-build preparation path. The first patch is a preparation change to make rq-offsets-file an explicit prepare dependency. The second addresses missing-syscalls check and atomic-checks. The third and last patch addresses scripts/mod.
Move the generic preparation checks and scripts/mod out of the preparation path for single .o builds. The first patch is a preparation change to make rq-offsets-file an explicit prepare dependency. The second addresses missing-syscalls check and atomic-checks. The third and last patch addresses scripts/mod.
== Illustration ==
These are the build steps triggered when just changing the compilation flags (here: adding W=1).
Before this series...
$ time make W=1 init/main.o
CC scripts/mod/empty.o
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/modpost.o
CC scripts/mod/devicetable-offsets.s
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/sumversion.o
HOSTCC scripts/mod/symsearch.o
HOSTLD scripts/mod/modpost
CC kernel/bounds.s
CC arch/x86/kernel/asm-offsets.s
CC kernel/sched/rq-offsets.s
CALL scripts/checksyscalls.sh
DESCEND objtool
CC init/main.o real 0m5,808s
user 0m3,216s
sys 0m3,196s
... and after:
$ time make W=1 init/main.o
CC kernel/bounds.s
CC arch/x86/kernel/asm-offsets.s
CC kernel/sched/rq-offsets.s
DESCEND objtool
CC init/main.o real 0m4,064s
user 0m1,901s
sys 0m2,728s
(done on an x86_64 cpu).
---
Changes in v2:
- Make modpost_prepare depend on prepare so scripts/mod is built after preparation completes. This addresses the sashiko report:
https://lore.kernel.org/all/[email protected]/
Link to v1: https://patch.msgid.link/20261111-reduce-single-build-dependencies-v1-0-7196ca986a85@kernel.org
---
Vincent Mailhol (3):
kbuild: make rq-offsets-file an explicit preparation dependency
kbuild: move preparation checks out of single-build
kbuild: move scripts/mod target out of single-build
Kbuild | 7 +++++-- Makefile | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261111-reduce-single-build-dependencies-966646f25a0c
Best regards,
Signature · 1 line
Vincent Mailhol <[email protected]>
PATCH v2 1/3 kbuild: make rq-offsets-file an explicit preparation dependency
The generated rq-offsets.h header is included by linux/sched.h and must exist before compiling ordinary objects. Currently that header is prepared indirectly through the missing-syscalls target.
Make prepare depend directly on rq-offsets-file. Because rq-offsets-file depends on offsets-file, that other dependency can be removed.
Keep the rq-offsets-file dependency in missing-syscalls so that the check can still run independently.
--- Kbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Kbuild +1 -1
@@ -87,7 +87,7 @@ $(atomic-checks): $(obj)/.checked-%: include/linux/atomic/% FORCE # A phony target that depends on all the preparation targets PHONY += prepare -prepare: $(offsets-file) missing-syscalls $(atomic-checks) +prepare: $(rq-offsets-file) missing-syscalls $(atomic-checks) @: # Ordinary directory descending
Signature · 1 line
2.56.1
PATCH v2 2/3 kbuild: move preparation checks out of single-build
In reply to Vincent MailholThe missing-syscalls check and the atomic-checks are currently set as preparation dependencies. However, these are not needed to compile, for example, a single object.
Add a new prepare_checks target to group those checks and call it conditionally only if we are not doing a single-build so that the prepare target does not trigger that dependency anymore.
--- Kbuild | 7 +++++-- Makefile | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-)
Kbuild +5 -2
@@ -86,8 +86,11 @@ $(atomic-checks): $(obj)/.checked-%: include/linux/atomic/% FORCE # A phony target that depends on all the preparation targets -PHONY += prepare -prepare: $(rq-offsets-file) missing-syscalls $(atomic-checks) +PHONY += prepare prepare_checks +prepare: $(rq-offsets-file) + @: + +prepare_checks: missing-syscalls $(atomic-checks) @: # Ordinary directory descending
Makefile +1 -1
@@ -1413,8 +1413,8 @@ archprepare: outputmakefile archheaders archscripts scripts include/config/kerne include/generated/rustc_cfg remove-stale-files prepare0: archprepare + $(Q)$(MAKE) $(build)=. prepare $(if $(single-build),,prepare_checks) $(Q)$(MAKE) $(build)=scripts/mod - $(Q)$(MAKE) $(build)=. prepare # All the preparing.. prepare: prepare0
Signature · 1 line
2.56.1
PATCH v2 3/3 kbuild: move scripts/mod target out of single-build
In reply to Vincent MailholThe scripts/mod target is currently built by prepare0, even when compiling a single object that does not need modpost.
Introduce modpost_prepare between prepare and modules_prepare, and make in-tree modpost depend on it. Move the scripts/mod build from prepare0 to this new target. This keeps scripts/mod out of single-object builds that do not need modpost.
--- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Makefile +6 -3
@@ -1405,7 +1405,7 @@ scripts: scripts_basic scripts_dtc # archprepare is used in arch Makefiles and when processed asm symlink, # version.h and scripts_basic is processed / created. -PHONY += prepare archprepare +PHONY += prepare archprepare modpost_prepare archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ asm-generic $(version_h) include/generated/utsrelease.h \
@@ -1414,6 +1414,8 @@ archprepare: outputmakefile archheaders archscripts scripts include/config/kerne prepare0: archprepare $(Q)$(MAKE) $(build)=. prepare $(if $(single-build),,prepare_checks) + +modpost_prepare: prepare $(Q)$(MAKE) $(build)=scripts/mod # All the preparing..
@@ -1765,7 +1767,7 @@ endif modules: modules_prepare # Target to prepare building external modules -modules_prepare: prepare +modules_prepare: modpost_prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds endif # CONFIG_MODULES
@@ -2189,7 +2191,8 @@ KBUILD_MODULES := endif # CONFIG_MODULES PHONY += modpost -modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \ +modpost: $(if $(KBUILD_EXTMOD),,modpost_prepare) \ + $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \ $(if $(KBUILD_MODULES), modules_check) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
Signature · 1 line
2.56.1
Nicolas Schier
maintainerQuoted 11 lines · Vincent Mailhol
kbuild: reduce single-build dependencies
Building a single .o file depends on the prepare target which contains a lot of dependencies. Some of those preparation dependencies are not needed for a single .o build.
This is a small annoyance because a modification of the compilation flags causes several prepare dependencies to rebuild. Consequently, single-build incurs an artificial penalty.
[...]
Applied to kbuild/linux.git (kbuild-next-unstable), thanks!
[1/3] kbuild: make rq-offsets-file an explicit preparation dependency
https://git.kernel.org/kbuild/c/7e9b69c5 [2/3] kbuild: move preparation checks out of single-build https://git.kernel.org/kbuild/c/b9d3d3d8 [3/3] kbuild: move scripts/mod target out of single-build https://git.kernel.org/kbuild/c/1b9279a5
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped, reverted or modified (e.g. trailers).
Patches applied to the kbuild-next-unstable branch are accepted pending wider testing in linux-next and any post-commit review; they will generally be moved to the kbuild-next branch in about a week if no issues are found.
Best regards,
Signature · 1 line
Nicolas