All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Li Wang (Hieco)" <li.wang@linux.dev>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 3/3] build: Recurse into trunk subdirectories in parallel
Date: Tue, 24 Nov 2026 17:06:33 +0800	[thread overview]
Message-ID: <20261124090633.840656-4-li.wang@linux.dev> (raw)
In-Reply-To: <20261124090633.840656-1-li.wang@linux.dev>

Currently, generic_trunk_target traverses $(SUBDIRS) using a serial shell
'for' loop. This serializes directory traversal and prevents 'make -jN'
from building sibling directories in parallel.

Replace the shell loop with target-based recursion:

1. Map each subdirectory to phony targets <dir>-all, <dir>-install and
   <dir>-check, implemented as static pattern rules using $* as the
   directory name.
2. Make 'all', 'install' and 'check' depend on these targets so GNU Make
   can dispatch sibling directories concurrently across available job
   slots.
3. Keep $(MAKE) literal in the recipes so that sub-makes keep access to
   the jobserver and 'make -n' still recurses.
4. Keep $(MAKE_DEPS) as order-only prerequisite. Together with the
   previous patch, libltp.a and libs/ are built exactly once at the
   top-level make invocation before any subdirectory is entered, so
   parallel leaves never race on the library build.
5. Add explicit ordering where a subdirectory produces a library used by
   its siblings (tools before testcases, kernel/lib before the other
   kernel subdirectories, rpc-tirpc before basic_tests), guarded against
   the directories being filtered out.

This cuts full build time by over 20% on multi-core systems.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Li Wang (Hieco) <li.wang@linux.dev>
---
 Makefile                            |  2 ++
 include/mk/generic_trunk_target.inc | 32 ++++++++++++++++++++++-------
 testcases/kernel/Makefile           |  6 ++++++
 testcases/network/rpc/Makefile      |  5 +++++
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 2efbe8c6c..0abb5c6b4 100644
--- a/Makefile
+++ b/Makefile
@@ -63,6 +63,8 @@ CHECK_TARGETS		:= $(addsuffix -check,testcases lib)
 all: $(addsuffix -all,$(COMMON_TARGETS)) Version
 
 $(MAKE_TARGETS): lib-all libs-all
+# tools contains apicmds/tst_kvercmp required by some testcases
+testcases-all: tools-all
 
 .PHONY: include-all include-install
 include-install: $(top_builddir)/include/config.h include/mk/config.mk include-all
diff --git a/include/mk/generic_trunk_target.inc b/include/mk/generic_trunk_target.inc
index 4186ee9d9..4c86fe1ec 100644
--- a/include/mk/generic_trunk_target.inc
+++ b/include/mk/generic_trunk_target.inc
@@ -91,16 +91,34 @@ ifeq ($(strip $(SUBDIRS)),)
 	$(warning CURDIR is: $(CURDIR))
 	$(error SUBDIRS empty -- did you want generic_leaf_target instead?)
 else
-$(RECURSIVE_TARGETS): %: | $(SUBDIRS)
 ifdef VERBOSE
-	@set -e; for dir in $(SUBDIRS); do \
-	    $(MAKE) -C $$dir -f "$(abs_srcdir)/$$dir/Makefile" $@; \
-	done
+TRUNK_Q		:=
+SUBMAKE_OPTS	:=
 else
-	@set -e; for dir in $(SUBDIRS); do \
-	    $(MAKE) --no-print-directory -C $$dir -f "$(abs_srcdir)/$$dir/Makefile" $@; \
-	done
+TRUNK_Q		:= @
+SUBMAKE_OPTS	:= --no-print-directory
 endif
+
+# Recurse into subdirectories via per-directory phony targets
+# (<dir>-all, <dir>-install, <dir>-check) so that GNU Make can build
+# sibling directories in parallel under -jN. $(MAKE) must appear
+# literally in the recipes so that sub-makes join the jobserver.
+all:     $(addsuffix -all,$(SUBDIRS))
+install: $(addsuffix -install,$(SUBDIRS))
+check:   $(addsuffix -check,$(SUBDIRS))
+
+.PHONY: $(addsuffix -all,$(SUBDIRS)) \
+	$(addsuffix -install,$(SUBDIRS)) \
+	$(addsuffix -check,$(SUBDIRS))
+
+$(addsuffix -all,$(SUBDIRS)): %-all: trunk-all | $(SUBDIRS) $(MAKE_DEPS)
+	$(TRUNK_Q)$(MAKE) $(SUBMAKE_OPTS) -C "$*" -f "$(abs_srcdir)/$*/Makefile" all
+
+$(addsuffix -install,$(SUBDIRS)): %-install: trunk-install | $(SUBDIRS) $(MAKE_DEPS)
+	$(TRUNK_Q)$(MAKE) $(SUBMAKE_OPTS) -C "$*" -f "$(abs_srcdir)/$*/Makefile" install
+
+$(addsuffix -check,$(SUBDIRS)): %-check: trunk-check | $(SUBDIRS) $(MAKE_DEPS)
+	$(TRUNK_Q)$(MAKE) $(SUBMAKE_OPTS) -C "$*" -f "$(abs_srcdir)/$*/Makefile" check
 endif
 
 check: trunk-check
diff --git a/testcases/kernel/Makefile b/testcases/kernel/Makefile
index 29e26742d..90615fbb4 100644
--- a/testcases/kernel/Makefile
+++ b/testcases/kernel/Makefile
@@ -54,3 +54,9 @@ FILTER_OUT_DIRS		+= containers controllers device-drivers fs io ipc mem \
 endif
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
+
+# libkerntest.a in lib/ must be built before its consumers
+ifneq ($(filter lib,$(SUBDIRS)),)
+KERNTEST_USERS	:= $(filter-out lib,$(SUBDIRS))
+$(addsuffix -all,$(KERNTEST_USERS)) $(addsuffix -install,$(KERNTEST_USERS)): lib-all
+endif
diff --git a/testcases/network/rpc/Makefile b/testcases/network/rpc/Makefile
index 6ecb1a665..d5ed5814c 100644
--- a/testcases/network/rpc/Makefile
+++ b/testcases/network/rpc/Makefile
@@ -9,3 +9,8 @@ include $(top_srcdir)/include/mk/env_pre.mk
 INSTALL_TARGETS		:= *.sh
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
+
+# librpc-tirpc.a in rpc-tirpc/ must be built before basic_tests
+ifneq ($(filter rpc-tirpc,$(SUBDIRS)),)
+basic_tests-all basic_tests-install: rpc-tirpc-all
+endif
-- 
2.56.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-11-24  9:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:06 [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Li Wang (Hieco)
2026-11-24  9:06 ` [LTP] [PATCH v4 1/3] build: Fix library prerequisites in testcases.mk Li Wang (Hieco)
2026-11-24  9:06 ` [LTP] [PATCH v4 2/3] build: Build shared libraries once when make runs in testcases/ Li Wang (Hieco)
2026-11-24  9:06 ` Li Wang (Hieco) [this message]
2026-11-24 11:32 ` [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124090633.840656-4-li.wang@linux.dev \
    --to=li.wang@linux.dev \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.