diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2017-11-13 05:29:37 -0500 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2017-11-15 19:07:35 -0500 |
commit | 8a78756eb545a6fb8007fa154a626ca2bc208027 (patch) | |
tree | a5f6f791cf742128df2d9af0cfba1393cae0b0c4 | |
parent | 591f66899784ae0afa13ff9a3eb5ce0a4358e48b (diff) |
kbuild: create object directories simpler and faster
For the out-of-tree build, scripts/Makefile.build creates output
directories, but this operation is not efficient.
scripts/Makefile.lib calculates obj-dirs as follows:
obj-dirs := $(dir $(multi-objs) $(obj-y))
Please notice $(sort ...) is not used here. Usually the result is
as many "./" as objects here.
For a lot of duplicated paths, the following command is invoked.
_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
Then, the costly shell command is run over and over again.
I see many points for optimization:
[1] Use $(sort ...) to cut down duplicated paths before passing them
to system call
[2] Use single $(shell ...) instead of repeating it with $(foreach ...)
This will reduce forking.
[3] We can calculate obj-dirs more simply. Most of objects are already
accumulated in $(targets). So, $(dir $(targets)) is fine and more
comprehensive.
I also removed ugly code in arch/x86/entry/vdso/Makefile. This is now
really unnecessary.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
-rw-r--r-- | arch/x86/entry/vdso/Makefile | 4 | ||||
-rw-r--r-- | scripts/Makefile.build | 15 | ||||
-rw-r--r-- | scripts/Makefile.host | 12 | ||||
-rw-r--r-- | scripts/Makefile.lib | 5 |
4 files changed, 6 insertions, 30 deletions
diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index d5409660f5de..f8e3d85256ad 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile | |||
@@ -129,10 +129,6 @@ $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE | |||
129 | CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) | 129 | CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) |
130 | VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1 | 130 | VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1 |
131 | 131 | ||
132 | # This makes sure the $(obj) subdirectory exists even though vdso32/ | ||
133 | # is not a kbuild sub-make subdirectory. | ||
134 | override obj-dirs = $(dir $(obj)) $(obj)/vdso32/ | ||
135 | |||
136 | targets += vdso32/vdso32.lds | 132 | targets += vdso32/vdso32.lds |
137 | targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o | 133 | targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o |
138 | targets += vdso32/vclock_gettime.o | 134 | targets += vdso32/vclock_gettime.o |
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6f603770b08e..496ecd825c71 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build | |||
@@ -64,15 +64,6 @@ ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(h | |||
64 | include scripts/Makefile.host | 64 | include scripts/Makefile.host |
65 | endif | 65 | endif |
66 | 66 | ||
67 | ifneq ($(KBUILD_SRC),) | ||
68 | # Create output directory if not already present | ||
69 | _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) | ||
70 | |||
71 | # Create directories for object files if directory does not exist | ||
72 | # Needed when obj-y := dir/file.o syntax is used | ||
73 | _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) | ||
74 | endif | ||
75 | |||
76 | ifndef obj | 67 | ifndef obj |
77 | $(warning kbuild: Makefile.build is included improperly) | 68 | $(warning kbuild: Makefile.build is included improperly) |
78 | endif | 69 | endif |
@@ -589,6 +580,12 @@ ifneq ($(cmd_files),) | |||
589 | include $(cmd_files) | 580 | include $(cmd_files) |
590 | endif | 581 | endif |
591 | 582 | ||
583 | ifneq ($(KBUILD_SRC),) | ||
584 | # Create directories for object files if they do not exist | ||
585 | obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets)))) | ||
586 | $(shell mkdir -p $(obj-dirs)) | ||
587 | endif | ||
588 | |||
592 | # Declare the contents of the .PHONY variable as phony. We keep that | 589 | # Declare the contents of the .PHONY variable as phony. We keep that |
593 | # information in a variable se we can use it in if_changed and friends. | 590 | # information in a variable se we can use it in if_changed and friends. |
594 | 591 | ||
diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 9cfd5c84d76f..a5e03838eca8 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host | |||
@@ -48,15 +48,6 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) | |||
48 | host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) | 48 | host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) |
49 | host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs)))) | 49 | host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs)))) |
50 | 50 | ||
51 | # output directory for programs/.o files | ||
52 | # hostprogs-y := tools/build may have been specified. | ||
53 | # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation | ||
54 | host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs)) | ||
55 | |||
56 | host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) | ||
57 | |||
58 | |||
59 | __hostprogs := $(addprefix $(obj)/,$(__hostprogs)) | ||
60 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) | 51 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) |
61 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) | 52 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) |
62 | host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) | 53 | host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) |
@@ -66,9 +57,6 @@ host-cshlib := $(addprefix $(obj)/,$(host-cshlib)) | |||
66 | host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib)) | 57 | host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib)) |
67 | host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs)) | 58 | host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs)) |
68 | host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) | 59 | host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) |
69 | host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) | ||
70 | |||
71 | obj-dirs += $(host-objdirs) | ||
72 | 60 | ||
73 | ##### | 61 | ##### |
74 | # Handle options to gcc. Support building with separate output directory | 62 | # Handle options to gcc. Support building with separate output directory |
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 4d88ad70fd96..5fbc46daa0f8 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
@@ -50,15 +50,11 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) | |||
50 | # objects depend on those (obviously) | 50 | # objects depend on those (obviously) |
51 | multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) | 51 | multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) |
52 | multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) | 52 | multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) |
53 | multi-objs := $(multi-objs-y) $(multi-objs-m) | ||
54 | 53 | ||
55 | # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to | 54 | # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to |
56 | # tell kbuild to descend | 55 | # tell kbuild to descend |
57 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) | 56 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) |
58 | 57 | ||
59 | # $(obj-dirs) is a list of directories that contain object files | ||
60 | obj-dirs := $(dir $(multi-objs) $(obj-y)) | ||
61 | |||
62 | # Replace multi-part objects by their individual parts, look at local dir only | 58 | # Replace multi-part objects by their individual parts, look at local dir only |
63 | real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) | 59 | real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) |
64 | real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) | 60 | real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) |
@@ -81,7 +77,6 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) | |||
81 | multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) | 77 | multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) |
82 | multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) | 78 | multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) |
83 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) | 79 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) |
84 | obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) | ||
85 | 80 | ||
86 | # These flags are needed for modversions and compiling, so we define them here | 81 | # These flags are needed for modversions and compiling, so we define them here |
87 | # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will | 82 | # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will |