Skip to content

Commit

Permalink
apps/build: Restore ARLOCK to improve compile speed in incremental case
Browse files Browse the repository at this point in the history
To solve the issue of carrying object files from previous builds,
Matias changed the archiving process to re-archive libapps.a on every compilation,
if libapps.a carries more object files, incremental compilation will waste too
many time in re-archiving, compared with the previous implement, this is a degradation
of the build system.  Referring to mature engineering projects such as cmake, if there
is configuration or source file changed, the best solution should be to reconfigure
the environment.

Revert this PR to ensure the compilation speed during incremental compilation.

|  commit 18137c0
|  Author: Matias N <[email protected]>
|  Date:   Sat Sep 12 00:36:23 2020 -0300
|
|      Fix: ensure archive files do not carry object files from prior builds
|
|      This is the corresponding change to the one on main NuttX repo. In this
|      case this involves splitting the build of libapps.a into: a) building
|      all applications (which is safely parallelizable), b) adding each
|      application's object files to the archive in turns (serial by nature).
|
|      This removes the need for the flock used to protect the parallel build.

Testing:

sim:nsh
-------------------------------
|   Patched    |  Current
-------------------------------
|$ time make   |  $ time make
|real 0m1.270s |  real 0m1.728s
|user 0m0.971s |  user 0m1.276s
|sys  0m0.363s |  sys  0m0.530s
-------------------------------

Private project (20+ 3rd library needs archive to libapps.a)
-------------------------------
|   Patched     |  Current
-------------------------------
|$ time make    |  $ time make
|real 0m21.181s |  real 0m39.721s
|user 0m14.638s |  user 0m24.837s
|sys  0m6.919s  |  sys  0m14.394s
-------------------------------

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao authored and xiaoxiang781216 committed Sep 12, 2023
1 parent bf4d873 commit 52353a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
*.sym
*.su
*~
.built
.context
.depend
.kconfig
/*.lock
/bin
/boot_romfsimg.h
/external
Expand Down
8 changes: 5 additions & 3 deletions Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ VPATH += :.

# Targets follow

all:: $(OBJS)
all:: .built
@:
.PHONY: clean depend distclean
.PRECIOUS: $(BIN)
Expand Down Expand Up @@ -208,11 +208,12 @@ $(ZIGOBJS): %$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE), $(CELFFLAGS)), \
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))

archive:
.built: $(OBJS)
$(call SPLITVARIABLE,ALL_OBJS,$(OBJS),100)
$(foreach BATCH, $(ALL_OBJS_TOTAL), \
$(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $(ALL_OBJS_$(BATCH))) \
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $(ALL_OBJS_$(BATCH))) \
)
$(Q) touch $@

ifeq ($(BUILD_MODULE),y)

Expand Down Expand Up @@ -295,6 +296,7 @@ depend:: .depend
@:

clean::
$(call DELFILE, .built)
$(call CLEAN)

distclean:: clean
Expand Down
1 change: 1 addition & 0 deletions Directory.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include $(APPDIR)/Make.defs

SUBDIRS := $(dir $(wildcard */Makefile))
CONFIGSUBDIRS := $(filter-out $(dir $(wildcard */Kconfig)),$(SUBDIRS))
CLEANSUBDIRS := $(dir $(wildcard *$(DELIM).built))
CLEANSUBDIRS += $(dir $(wildcard */.depend))
CLEANSUBDIRS += $(dir $(wildcard */.kconfig))
CLEANSUBDIRS := $(sort $(CLEANSUBDIRS))
Expand Down
4 changes: 4 additions & 0 deletions Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ define SPLITVARIABLE
$(eval $(PREFIX)_$(idx)=$(wordlist $(FROMINDEX), $(shell expr $(FROMINDEX) + $(BATCH_SIZE) - 1), $(2))) \
)
endef

define ARLOCK
flock $1.lock $(call ARCHIVE, $1, $(2))
endef
17 changes: 3 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
# We first remove libapps.a before letting the other rules add objects to it
# so that we ensure libapps.a does not contain objects from prior build

all:
$(RM) $(BIN)
$(MAKE) $(BIN)
all: $(BIN)

.PHONY: import install dirlinks export .depdirs preconfig depend clean distclean
.PHONY: context clean_context context_all register register_all
Expand Down Expand Up @@ -74,9 +72,6 @@ ifeq ($(CONFIG_BUILD_KERNEL),y)
install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install)

$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) for app in ${CONFIGURED_APPS}; do \
$(MAKE) -C "$${app}" archive ; \
done

.import: $(BIN)
$(Q) install libapps.a $(APPDIR)$(DELIM)import$(DELIM)libs
Expand All @@ -96,21 +91,14 @@ else
ifeq ($(CONFIG_BUILD_LOADABLE),)
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) for %%G in ($(CONFIGURED_APPS)) do ( $(MAKE) -C %%G archive )
else
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) for app in ${CONFIGURED_APPS}; do \
$(MAKE) -C "$${app}" archive ; \
done
$(call LINK_WASM)
endif

else

$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) for app in ${CONFIGURED_APPS}; do \
$(MAKE) -C "$${app}" archive ; \
done
$(Q) $(MAKE) install
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
Expand All @@ -119,7 +107,7 @@ $(SYMTABOBJ): %$(OBJEXT): %.c
$(call COMPILE, $<, $@, -fno-lto -fno-builtin)

$(BIN): $(SYMTABOBJ)
$(call ARCHIVE_ADD, $(call CONVERT_PATH,$(BIN)), $^)
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
$(call LINK_WASM)

endif # !CONFIG_BUILD_LOADABLE
Expand Down Expand Up @@ -208,6 +196,7 @@ clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean)
$(call CLEAN)

distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean)
$(call DELFILE, *.lock)
$(call DELFILE, .depend)
$(call DELFILE, $(SYMTABSRC))
$(call DELFILE, $(SYMTABOBJ))
Expand Down

0 comments on commit 52353a7

Please sign in to comment.