Skip to contentSkip to conversation

Fix for top-level parallel make part 1

PATCH Superseded Fabio Porcedda 1 participant 6 messages Sep 25, 2013 Kbuild

v5 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v5 cover Fix for top-level parallel make part 1

Hi all,
this is the first patch set for fixing top-level parallel make in buildroot, the common problem scattered in buildroot's top-level makefile is that in the rules it relies on the order of evaluation of the prerequisites, to be able to use top-level parallel make instead of reling on the left to right ordering of evaluation of the prerequisites we must add an explicit rule to describe the dependencies.

With this patch set the package building seems to work fine with top-level parallel make, example:

make clean toolchain
make BR2_JLEVEL= -j<n> <package name list>

Before to try that you have to remove the ".NOTPARALLEL" line in the top-level Makefile.

The part that remain to fix for top-level parallel make is the toolchain building and targets after building all the packages.

Best regards
Fabio Porcedda

v5:
- added the fourth patch
- fixed some typos
- rewrited the second patch to use only $$($(2)_TARGET_*) in the rules
- add support for top-level parallel make for the glibc package
v4:
- rebased over master
- add Acked-by: Thomas Petazzoni on the third patch
- changed the orderd of the patches
v3:
- add back the patch "package: add toolchain dependency to inner-generic-package" because now is working fine.
- add Acked-by: Arnout Vandecappelle to the third patch.
- reworked the second patch following Arnout suggestions.
v2:
- remove patch "package: add toolchain dependency to inner-generic-package" because was not working fine against recent toolchain changes.

Fabio Porcedda (4):
package: add toolchain dependency to inner-generic-package
pkg-generic: fix rules for top-level parallel make package/Makefile.in: don't force jobs when BR2_JLEVEL is empty
pkg-generic: enable recursive make for $($(PKG)_BUILD_CMDS)

 Makefile                 |  2 +-
 package/Makefile.in      |  2 +-
 package/glibc/glibc.mk   |  3 ++-
 package/pkg-autotools.mk |  3 ++-
 package/pkg-generic.mk   | 46 +++++++++++++++++++++++++++-------------------
 package/uclibc/uclibc.mk |  3 ++-
 6 files changed, 35 insertions(+), 24 deletions(-)
Signature · 1 line
1.8.4
#1 lore raw

PATCH v5 1/4 package: add toolchain dependency to inner-generic-package

This commit makes the dependency from the target toolchain explicit. This way we can buid from command line a package that use innger-generic-package right after the configuration phase, example:

make clean <package-name>

This is a step forward top-level parallel make.

---
 Makefile                 | 2 +-
 package/pkg-autotools.mk | 3 ++-
 package/pkg-generic.mk   | 6 +++++-
 3 files changed, 8 insertions(+), 3 deletions(-)
Makefile +1 -1
index 6b86541..22c5364 100644
@@ -398,7 +398,7 @@ prepare: $(BUILD_DIR)/buildroot-config/auto.conf
 
 toolchain: prepare dirs dependencies $(BASE_TARGETS)
 
-world: toolchain $(TARGETS_ALL)
+world: $(TARGETS_ALL)
 
 .PHONY: all world toolchain dirs clean distclean source outputmakefile \
 	legal-info legal-info-prepare legal-info-clean printvars \
package/pkg-autotools.mk +2 -1
index b0eddde..aafa396 100644
@@ -202,7 +202,8 @@ endef
 # This must be repeated from inner-generic-package, otherwise we get an empty
 # _DEPENDENCIES if _AUTORECONF is YES.  Also filter the result of _AUTORECONF
 # away from the non-host rule
-$(2)_DEPENDENCIES ?= $(filter-out host-automake host-autoconf host-libtool $(1),\
+$(2)_DEPENDENCIES ?= $(filter-out host-automake host-autoconf host-libtool \
+				host-toolchain $(1),\
     $(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
 
 
package/pkg-generic.mk +5 -1
index bfc4dc1..d7efcd3 100644
@@ -307,7 +307,11 @@ endif
 $(2)_REDISTRIBUTE		?= YES
 
 
-$(2)_DEPENDENCIES ?= $(filter-out $(1),$(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
+$(2)_DEPENDENCIES ?= $(filter-out  host-toolchain $(1),\
+	$(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
+ifeq ($$($(2)_TYPE),target)
+$(2)_DEPENDENCIES += toolchain
+endif
 
 $(2)_INSTALL_STAGING		?= NO
 $(2)_INSTALL_IMAGES		?= NO
Signature · 1 line
1.8.4
#2 lore raw

PATCH v5 2/4 pkg-generic: fix rules for top-level parallel make

In reply to Fabio Porcedda

To be able to use top-level parallel make we must not depend in a rule on the order of evaluation of the prerequisites, so instead of relyng on the left to right ordering of evaluation of the prerequisites add an explicit rule to describe the dependencies.

So add explicit dependencies for the following stamp files:
%/.stamp_extracted
%/.stamp_patched
%/.stamp_configured
%/.stamp_built
%/.stamp_host_installed %/.stamp_staging_installed %/.stamp_images_installed %/.stamp_target_installed

Because the %-build target is not anymore part of the dependency chain, add a new variable <pkgname>_BUILD_DEPENDENCIES to be used instead. This new variable is used only by the uclibc package for building the toolchain.

---
 package/glibc/glibc.mk   |  3 ++-
 package/pkg-generic.mk   | 38 +++++++++++++++++++++-----------------
 package/uclibc/uclibc.mk |  3 ++-
 3 files changed, 25 insertions(+), 19 deletions(-)
package/glibc/glibc.mk +2 -1
index 4dd2e63..57f15dc 100644
@@ -30,7 +30,8 @@ endif
 
 # Before (e)glibc is built, we must have the second stage
 # cross-compiler, for some gcc versions
-glibc-build: $(if $(BR2_TOOLCHAIN_NEEDS_THREE_STAGE_BUILD),host-gcc-intermediate)
+GLIBC_BUILD_DEPENDENCIES = \
+	$(if $(BR2_TOOLCHAIN_NEEDS_THREE_STAGE_BUILD),host-gcc-intermediate)
 
 GLIBC_SUBDIR = build
 
package/pkg-generic.mk +21 -17
index d7efcd3..0de1f35 100644
@@ -312,6 +312,7 @@ $(2)_DEPENDENCIES ?= $(filter-out  host-toolchain $(1),\
 ifeq ($$($(2)_TYPE),target)
 $(2)_DEPENDENCIES += toolchain
 endif
+$(2)_BUILD_DEPENDENCIES		?=
 
 $(2)_INSTALL_STAGING		?= NO
 $(2)_INSTALL_IMAGES		?= NO
@@ -363,30 +364,34 @@ $(1)-install:		$(1)-install-staging $(1)-install-target $(1)-install-images
 endif
 
 ifeq ($$($(2)_INSTALL_TARGET),YES)
-$(1)-install-target:	$(1)-build \
-			$$($(2)_TARGET_INSTALL_TARGET)
+$(1)-install-target:	$$($(2)_TARGET_INSTALL_TARGET)
 else
 $(1)-install-target:
 endif
 
 ifeq ($$($(2)_INSTALL_STAGING),YES)
-$(1)-install-staging:	$(1)-build \
-			$$($(2)_TARGET_INSTALL_STAGING)
+$(1)-install-staging:	$$($(2)_TARGET_INSTALL_STAGING)
 else
 $(1)-install-staging:
 endif
 
 ifeq ($$($(2)_INSTALL_IMAGES),YES)
-$(1)-install-images:	$(1)-build \
-			$$($(2)_TARGET_INSTALL_IMAGES)
+$(1)-install-images:	$$($(2)_TARGET_INSTALL_IMAGES)
 else
 $(1)-install-images:
 endif
 
-$(1)-install-host:      $(1)-build $$($(2)_TARGET_INSTALL_HOST)
+$(1)-install-host:      $$($(2)_TARGET_INSTALL_HOST)
 
-$(1)-build:		$(1)-configure \
-			$$($(2)_TARGET_BUILD)
+$$($(2)_TARGET_INSTALL_TARGET) $$($(2)_TARGET_INSTALL_STAGING) \
+$$($(2)_TARGET_INSTALL_IMAGES) $$($(2)_TARGET_INSTALL_HOST): \
+	$$($(2)_TARGET_BUILD)
+
+$(1)-build:		$$($(2)_TARGET_BUILD)
+$$($(2)_TARGET_BUILD):	$$($(2)_TARGET_CONFIGURE) | $$($(2)_BUILD_DEPENDENCIES)
+
+$(1)-configure:			$$($(2)_TARGET_CONFIGURE)
+$$($(2)_TARGET_CONFIGURE):	| $$($(2)_DEPENDENCIES)
 
 ifeq ($$($(2)_OVERRIDE_SRCDIR),)
 # In the normal case (no package override), the sequence of steps is
@@ -395,13 +400,13 @@ ifeq ($$($(2)_OVERRIDE_SRCDIR),)
 #  extract
 #  patch
 #  configure
-$(1)-configure:		$(1)-patch $(1)-depends \
-			$$($(2)_TARGET_CONFIGURE)
+$$($(2)_TARGET_CONFIGURE):	$$($(2)_TARGET_PATCH)
 
-$(1)-patch:		$(1)-extract $$($(2)_TARGET_PATCH)
+$(1)-patch:		$$($(2)_TARGET_PATCH)
+$$($(2)_TARGET_PATCH):	$$($(2)_TARGET_EXTRACT)
 
-$(1)-extract:		$(1)-source \
-			$$($(2)_TARGET_EXTRACT)
+$(1)-extract:			$$($(2)_TARGET_EXTRACT)
+$$($(2)_TARGET_EXTRACT):	$$($(2)_TARGET_SOURCE)
 
 $(1)-depends:		$$($(2)_DEPENDENCIES)
 
@@ -411,10 +416,9 @@ else
 #  source, by rsyncing
 #  depends
 #  configure
-$(1)-configure:		$(1)-depends \
-			$$($(2)_TARGET_CONFIGURE)
+$$($(2)_TARGET_CONFIGURE):	$$($(2)_TARGET_RSYNC)
 
-$(1)-depends:		$(1)-rsync $$($(2)_DEPENDENCIES)
+$(1)-depends:		$$($(2)_DEPENDENCIES)
 
 $(1)-patch:		$(1)-rsync
 $(1)-extract:		$(1)-rsync
package/uclibc/uclibc.mk +2 -1
index 3993d9b..f05b647 100644
@@ -24,7 +24,8 @@ UCLIBC_DEPENDENCIES = host-gcc-initial linux-headers
 
 # Before uClibc is built, we must have the second stage
 # cross-compiler, for some gcc versions, and when NPTL is used.
-uclibc-build: $(if $(BR2_TOOLCHAIN_NEEDS_THREE_STAGE_BUILD),host-gcc-intermediate)
+UCLIBC_BUILD_DEPENDENCIES = \
+	$(if $(BR2_TOOLCHAIN_NEEDS_THREE_STAGE_BUILD),host-gcc-intermediate)
 
 # specifying UCLIBC_CONFIG_FILE on the command-line overrides the .config
 # setting.
Signature · 1 line
1.8.4
#3 lore raw

PATCH v5 3/4 package/Makefile.in: don't force jobs when BR2_JLEVEL is empty

In reply to Fabio Porcedda

When the "BR2_JLEVEL" variable is empty use "make" without the "-j" option, because to be able to use top-level parallel make we must don't force the number of jobs in sub-make.

Example:
make BR2_JLEVEL= -j8

---
 package/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/Makefile.in +1 -1
index 170ad78..d406901 100644
@@ -18,7 +18,7 @@ PARALLEL_JOBS:=$(BR2_JLEVEL)
 endif
 
 MAKE1:=$(HOSTMAKE) -j1
-MAKE:=$(HOSTMAKE) -j$(PARALLEL_JOBS)
+MAKE:=$(HOSTMAKE) $(if $(PARALLEL_JOBS),-j$(PARALLEL_JOBS))
 
 # Compute GNU_TARGET_NAME
 GNU_TARGET_NAME=$(ARCH)-buildroot-$(TARGET_OS)-$(LIBC)$(ABI)
Signature · 1 line
1.8.4
#4 lore raw

PATCH v5 4/4 pkg-generic: enable recursive make for $($(PKG)_BUILD_CMDS)

In reply to Fabio Porcedda

Add '+' prefix to the $($(PKG)_BUILD_CMDS) command to enable jobserver for the sub-make.

Without the '+' prefix GNU make does not detect the sub-make so the jobserver is not avaiable for the sub-make.

From GNU make documentation:
Using the MAKE variable has the same effect as using a ?+? character at the beginning of the recipe line. This special feature is only enabled if the MAKE variable appears directly in the recipe: it does not apply if the MAKE variable is referenced through expansion of another variable. In the latter case you must use the ?+? token to get these special effects.

---
 package/pkg-generic.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/pkg-generic.mk +1 -1
index 0de1f35..499362b 100644
@@ -117,7 +117,7 @@ $(BUILD_DIR)/%/.stamp_configured:
 # Build
 $(BUILD_DIR)/%/.stamp_built::
 	@$(call MESSAGE,"Building")
-	$($(PKG)_BUILD_CMDS)
+	+$($(PKG)_BUILD_CMDS)
 	$(foreach hook,$($(PKG)_POST_BUILD_HOOKS),$(call $(hook))$(sep))
 	$(Q)touch $@
 
Signature · 1 line
1.8.4
#5 lore raw

v5 cover Fix for top-level parallel make part 1

In reply to Fabio Porcedda
Quoted 55 lines · Fabio Porcedda

Hi all,
this is the first patch set for fixing top-level parallel make in buildroot, the common problem scattered in buildroot's top-level makefile is that in the rules it relies on the order of evaluation of the prerequisites, to be able to use top-level parallel make instead of reling on the left to right ordering of evaluation of the prerequisites we must add an explicit rule to describe the dependencies.

With this patch set the package building seems to work fine with top-level parallel make, example:

make clean toolchain
make BR2_JLEVEL= -j<n> <package name list>

Before to try that you have to remove the ".NOTPARALLEL" line in the top-level Makefile.

The part that remain to fix for top-level parallel make is the toolchain building and targets after building all the packages.

Best regards
Fabio Porcedda

v5:
- added the fourth patch
- fixed some typos
- rewrited the second patch to use only $$($(2)_TARGET_*) in the rules
- add support for top-level parallel make for the glibc package
v4:
- rebased over master
- add Acked-by: Thomas Petazzoni on the third patch
- changed the orderd of the patches
v3:
- add back the patch "package: add toolchain dependency to inner-generic-package" because now is working fine.
- add Acked-by: Arnout Vandecappelle to the third patch.
- reworked the second patch following Arnout suggestions.
v2:
- remove patch "package: add toolchain dependency to inner-generic-package" because was not working fine against recent toolchain changes.

Fabio Porcedda (4):
package: add toolchain dependency to inner-generic-package
pkg-generic: fix rules for top-level parallel make package/Makefile.in: don't force jobs when BR2_JLEVEL is empty
pkg-generic: enable recursive make for $($(PKG)_BUILD_CMDS)

 Makefile                 |  2 +-
 package/Makefile.in      |  2 +-
 package/glibc/glibc.mk   |  3 ++-
 package/pkg-autotools.mk |  3 ++-
 package/pkg-generic.mk   | 46 +++++++++++++++++++++++++++-------------------
 package/uclibc/uclibc.mk |  3 ++-
 6 files changed, 35 insertions(+), 24 deletions(-)
Quoted 3 lines

--
1.8.4

Well just after sending the patch set a discovered some build problems, i will try to fix them.

Best regards

Signature · 1 line
Fabio Porcedda