[dpdk-dev,v2] mk: parallelize make config

Message ID 20170130102115.20975-1-ferruh.yigit@intel.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Ferruh Yigit Jan. 30, 2017, 10:21 a.m. UTC
  make config dependency resolving was always running serial,
parallelize it for better performance.

$ time make T=x86_64-native-linuxapp-gcc config
real    0m12.633s

$ time make -j8 T=x86_64-native-linuxapp-gcc config
real    0m1.826s

When config creation done under a single make target, using a for loop,
make has no control on the action, and it needs to run as implemented in
the rule. But if for loop converted into multiple targets, make can
detect independent targets and run them parallel based on -j parameter.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 devtools/test-build.sh          |  2 +-
 mk/internal/rte.depdirs-post.mk | 11 ++++++-----
 mk/rte.sdkdepdirs.mk            | 21 ++++++++++-----------
 mk/rte.subdir.mk                | 17 +++++++----------
 4 files changed, 24 insertions(+), 27 deletions(-)
  

Comments

Thomas Monjalon Jan. 30, 2017, 6:13 p.m. UTC | #1
2017-01-30 10:21, Ferruh Yigit:
> make config dependency resolving was always running serial,
> parallelize it for better performance.
> 
> $ time make T=x86_64-native-linuxapp-gcc config
> real    0m12.633s
> 
> $ time make -j8 T=x86_64-native-linuxapp-gcc config
> real    0m1.826s
> 
> When config creation done under a single make target, using a for loop,
> make has no control on the action, and it needs to run as implemented in
> the rule. But if for loop converted into multiple targets, make can
> detect independent targets and run them parallel based on -j parameter.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Looks a good improvement, thanks Ferruh.

Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>

Applied
  

Patch

diff --git a/devtools/test-build.sh b/devtools/test-build.sh
index 680d79b..0f131fc 100755
--- a/devtools/test-build.sh
+++ b/devtools/test-build.sh
@@ -146,7 +146,7 @@  config () # <directory> <target> <options>
 	fi
 	if [ ! -e $1/.config ] || $reconfig ; then
 		echo "================== Configure $1"
-		make T=$2 O=$1 config
+		make -j$J T=$2 O=$1 config
 
 		echo 'Customize configuration'
 		# Built-in options (lowercase)
diff --git a/mk/internal/rte.depdirs-post.mk b/mk/internal/rte.depdirs-post.mk
index 102a369..eb73ad3 100644
--- a/mk/internal/rte.depdirs-post.mk
+++ b/mk/internal/rte.depdirs-post.mk
@@ -29,11 +29,12 @@ 
 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-.PHONY: depdirs
-depdirs:
-	@for d in $(DEPDIRS-y); do \
-		$(RTE_SDK)/buildtools/depdirs-rule.sh $(S) $$d ; \
-	done
+.PHONY: depdirs $(DEPDIRS-y)
+depdirs: $(DEPDIRS-y)
+	@echo ""
+
+$(DEPDIRS-y):
+	@$(RTE_SDK)/buildtools/depdirs-rule.sh $(S) $@
 
 .PHONY: depgraph
 depgraph:
diff --git a/mk/rte.sdkdepdirs.mk b/mk/rte.sdkdepdirs.mk
index bebaf2a..38fd863 100644
--- a/mk/rte.sdkdepdirs.mk
+++ b/mk/rte.sdkdepdirs.mk
@@ -36,19 +36,18 @@  ifeq (,$(wildcard $(RTE_OUTPUT)/Makefile))
   $(error "need a make config first")
 endif
 
-# use a "for" in a shell to process dependencies: we don't want this
-# task to be run in parallel.
+DEPDIR_FILES = $(addsuffix /.depdirs, $(addprefix $(BUILDDIR)/,$(ROOTDIRS-y)))
+
 .PHONY: depdirs
 depdirs: $(RTE_OUTPUT)/.depdirs
-$(RTE_OUTPUT)/.depdirs: $(RTE_OUTPUT)/.config
-	@rm -f $(RTE_OUTPUT)/.depdirs ; \
-	for d in $(ROOTDIRS-y); do \
-		if [ -f $(RTE_SRCDIR)/$$d/Makefile ]; then \
-			[ -d $(BUILDDIR)/$$d ] || mkdir -p $(BUILDDIR)/$$d ; \
-			$(MAKE) S=$$d -f $(RTE_SRCDIR)/$$d/Makefile depdirs \
-				>> $(RTE_OUTPUT)/.depdirs ; \
-		fi ; \
-	done
+$(RTE_OUTPUT)/.depdirs: $(DEPDIR_FILES)
+	@rm -f $@
+	@sort -u -o $@ $(DEPDIR_FILES)
+
+$(DEPDIR_FILES): $(RTE_OUTPUT)/.config
+	@dir=$(notdir $(@D)); \
+	[ -d $(BUILDDIR)/$$dir ] || mkdir -p $(BUILDDIR)/$$dir; \
+	$(MAKE) S=$$dir -f $(RTE_SRCDIR)/$$dir/Makefile depdirs > $@
 
 .PHONY: depgraph
 depgraph:
diff --git a/mk/rte.subdir.mk b/mk/rte.subdir.mk
index 256e64e..5341f1f 100644
--- a/mk/rte.subdir.mk
+++ b/mk/rte.subdir.mk
@@ -76,7 +76,7 @@  clean: _postclean
 # include .depdirs and define rules to order priorities between build
 # of directories.
 #
-include $(RTE_OUTPUT)/.depdirs
+-include $(RTE_OUTPUT)/.depdirs
 
 define depdirs_rule
 $(1): $(sort $(patsubst $(S)/%,%,$(LOCAL_DEPDIRS-$(S)/$(1))))
@@ -84,16 +84,13 @@  endef
 
 $(foreach d,$(DIRS-y),$(eval $(call depdirs_rule,$(d))))
 
+DEPDIRS = $(wildcard $(addprefix $(S)/,$(DIRS-y)))
 
-# use a "for" in a shell to process dependencies: we don't want this
-# task to be run in parallel.
-.PHONY: depdirs
-depdirs:
-	@for d in $(DIRS-y); do \
-		if [ -f $(SRCDIR)/$$d/Makefile ]; then \
-			$(MAKE) S=$S/$$d -f $(SRCDIR)/$$d/Makefile depdirs ; \
-		fi ; \
-	done
+.PHONY: depdirs $(DEPDIRS)
+depdirs: $(DEPDIRS)
+
+$(DEPDIRS):
+	@$(MAKE) S=$@ -f $(RTE_SRCDIR)/$@/Makefile depdirs
 
 .PHONY: depgraph
 depgraph: