* [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine
@ 2026-11-24 9:06 Li Wang (Hieco)
2026-11-24 9:06 ` [LTP] [PATCH v4 1/3] build: Fix library prerequisites in testcases.mk Li Wang (Hieco)
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Li Wang (Hieco) @ 2026-11-24 9:06 UTC (permalink / raw)
To: ltp
The following results show how this optimization moves compile times
really far from what we have now. With a single threaded build, LTP
would take approximately 12 minutes to compile. With a multi-threaded
build on 16 CPUs, this drops down to ~46 seconds.
time make -j16
Executed in 45.96 secs fish external
usr time 519.11 secs 0.24 millis 519.11 secs
sys time 167.13 secs 1.08 millis 167.13 secs
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v4:
- Mark library targets .PHONY so library source changes are rebuilt
- Also build libkerntest.a when make is run from testcases/
- Remove the old $(LIBLTP) rule from testcases.mk (overriding recipe warning)
- Refactoring the patchset in clean code
- Link to v3: https://lore.kernel.org/all/20261021-build_system_optimize-v3-0-71a3c4c6f937@suse.com/
Changes in v3:
- added libs-all ordering to avoid races
- Link to v2: https://lore.kernel.org/20261020-build_system_optimize-v2-0-b527ac7cf835@suse.com
Changes in v2:
- fix build race condition
- Link to v1: https://lore.kernel.org/20261020-build_system_optimize-v1-1-744f9fa88908@suse.com
Andrea Cervesato (2):
build: Fix library prerequisites in testcases.mk
build: Build shared libraries once when make runs in testcases/
Li Wang (Hieco) (1):
build: Recurse into trunk subdirectories in parallel
Makefile | 2 ++
include/mk/generic_leaf_target.inc | 2 ++
include/mk/generic_lib_deps.inc | 34 ++++++++++++++++++++++++
include/mk/generic_trunk_target.inc | 40 ++++++++++++++++++++++++-----
include/mk/testcases.mk | 15 +++++------
testcases/kernel/Makefile | 6 +++++
testcases/kernel/include/lib.mk | 6 +++--
testcases/network/rpc/Makefile | 5 ++++
8 files changed, 93 insertions(+), 17 deletions(-)
create mode 100644 include/mk/generic_lib_deps.inc
--
2.56.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH v4 1/3] build: Fix library prerequisites in testcases.mk
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 ` 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)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Li Wang (Hieco) @ 2026-11-24 9:06 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Fix LTPLIBS_FILES to match the actual libltp<name>.a archive names and
only mark them .PHONY when MAKELEVEL == 0 so recursive leaf sub-makes
do not redundantly rebuild them in parallel.
Also make directory prerequisites order-only so directory mtime updates
do not trigger unnecessary archive rebuilds.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Li Wang (Hieco) <li.wang@linux.dev>
Reviewed-by: Li Wang (Hieco) <li.wang@linux.dev>
---
include/mk/testcases.mk | 14 ++++++++------
testcases/kernel/include/lib.mk | 4 ++--
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/include/mk/testcases.mk b/include/mk/testcases.mk
index 2609535ce..5960d7485 100644
--- a/include/mk/testcases.mk
+++ b/include/mk/testcases.mk
@@ -12,11 +12,11 @@ LIBLTP_DIR := $(abs_top_builddir)/lib
LIBLTP := $(LIBLTP_DIR)/libltp.a
-$(APICMDS_DIR)/tst_kvercmp: $(APICMDS_DIR)
- $(MAKE) -C "$^" -f "$(abs_top_srcdir)/tools/apicmds/Makefile" all
+$(APICMDS_DIR)/tst_kvercmp: | $(APICMDS_DIR)
+ $(MAKE) -C "$(APICMDS_DIR)" -f "$(abs_top_srcdir)/tools/apicmds/Makefile" all
-$(LIBLTP): $(LIBLTP_DIR)
- $(MAKE) -C "$^" -f "$(abs_top_srcdir)/lib/Makefile" all
+$(LIBLTP): | $(LIBLTP_DIR)
+ $(MAKE) -C "$(LIBLTP_DIR)" -f "$(abs_top_srcdir)/lib/Makefile" all
MAKE_DEPS := $(LIBLTP)
@@ -27,13 +27,15 @@ LDLIBS += -lltp
ifdef LTPLIBS
LTPLIBS_DIRS = $(addprefix $(abs_top_builddir)/libs/, $(LTPLIBS))
-LTPLIBS_FILES = $(addsuffix .a, $(addprefix $(abs_top_builddir)/libs/, $(foreach LIB,$(LTPLIBS),$(LIB)/lib$(LIB))))
+LTPLIBS_FILES = $(addsuffix .a, $(addprefix $(abs_top_builddir)/libs/, $(foreach LIB,$(LTPLIBS),$(LIB)/libltp$(LIB))))
MAKE_DEPS += $(LTPLIBS_FILES)
+ifeq ($(MAKELEVEL),0)
.PHONY: $(LTPLIBS_FILES)
+endif
-$(LTPLIBS_FILES): $(LTPLIBS_DIRS)
+$(LTPLIBS_FILES): | $(LTPLIBS_DIRS)
$(LTPLIBS_FILES): %:
ifdef VERBOSE
diff --git a/testcases/kernel/include/lib.mk b/testcases/kernel/include/lib.mk
index 40a09b77e..c1a0c6d52 100644
--- a/testcases/kernel/include/lib.mk
+++ b/testcases/kernel/include/lib.mk
@@ -29,8 +29,8 @@ LDFLAGS += -L$(LIBKERNTEST_DIR)
$(LIBKERNTEST_DIR):
mkdir -p "$@"
-$(LIBKERNTEST): $(LIBKERNTEST_DIR)
- $(MAKE) -C $^ -f "$(LIBKERNTEST_SRCDIR)/Makefile" all
+$(LIBKERNTEST): | $(LIBKERNTEST_DIR)
+ $(MAKE) -C "$(LIBKERNTEST_DIR)" -f "$(LIBKERNTEST_SRCDIR)/Makefile" all
MAKE_DEPS += $(LIBKERNTEST)
--
2.56.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v4 2/3] build: Build shared libraries once when make runs in testcases/
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 ` Li Wang (Hieco)
2026-11-24 9:06 ` [LTP] [PATCH v4 3/3] build: Recurse into trunk subdirectories in parallel Li Wang (Hieco)
2026-11-24 11:32 ` [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Cyril Hrubis
3 siblings, 0 replies; 5+ messages in thread
From: Li Wang (Hieco) @ 2026-11-24 9:06 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Running make directly under testcases/ (for example
"make -C testcases/kernel/syscalls -j8") can start many sub-makes in
parallel. Each leaf can then reach the $(LIBLTP) rule in
testcases.mk and call "$(MAKE) -C lib" at the same time. This builds
the same library more than once, and parallel builds can race on
libltp.a. libkerntest.a and the libs/ libraries have the same
problem.
Add include/mk/generic_lib_deps.inc and include it from both the
generic leaf and trunk targets. When make is started inside
testcases/ (MAKELEVEL == 0), the file adds libltp.a, the libs/
libraries and, for testcases/ and testcases/kernel/*, libkerntest.a
to MAKE_DEPS. Leaf targets and trunk subdirectories depend on
MAKE_DEPS as order-only prerequisites. As a result, the libraries
are built once, in the top-level make process, before any
subdirectory is entered.
The library targets are .PHONY, so lib/, libs/ and
testcases/kernel/lib/ are always entered and their own Makefiles
decide what to rebuild. A change to the library sources is therefore
picked up. Because the prerequisites are order-only, tests that are
already linked are not relinked.
Remove the old $(LIBLTP) rule and "MAKE_DEPS := $(LIBLTP)" from
include/mk/testcases.mk, which the new file replaces. Builds started
from the top-level directory are not affected.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Li Wang (Hieco) <li.wang@linux.dev>
---
include/mk/generic_leaf_target.inc | 2 ++
include/mk/generic_lib_deps.inc | 34 +++++++++++++++++++++++++++++
include/mk/generic_trunk_target.inc | 8 +++++++
include/mk/testcases.mk | 5 +----
testcases/kernel/include/lib.mk | 2 ++
5 files changed, 47 insertions(+), 4 deletions(-)
create mode 100644 include/mk/generic_lib_deps.inc
diff --git a/include/mk/generic_leaf_target.inc b/include/mk/generic_leaf_target.inc
index 7c685fea7..533381b9f 100644
--- a/include/mk/generic_leaf_target.inc
+++ b/include/mk/generic_leaf_target.inc
@@ -76,6 +76,8 @@
# INSTALL_DIR := $(libdir)
#
+include $(top_srcdir)/include/mk/generic_lib_deps.inc
+
.PHONY: all clean install check
ifneq ($(strip $(MAKE_TARGETS)),)
diff --git a/include/mk/generic_lib_deps.inc b/include/mk/generic_lib_deps.inc
new file mode 100644
index 000000000..666b3f9ef
--- /dev/null
+++ b/include/mk/generic_lib_deps.inc
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2026
+
+ifeq ($(MAKELEVEL),0)
+
+ifneq ($(filter $(abs_top_builddir)/testcases%,$(CURDIR)),)
+
+MAKE_DEPS += $(abs_top_builddir)/lib/libltp.a
+MAKE_DEPS += $(abs_top_builddir)/libs-all
+
+.PHONY: $(abs_top_builddir)/lib/libltp.a
+$(abs_top_builddir)/lib/libltp.a:
+ mkdir -m 00755 -p "$(@D)"
+ $(MAKE) -C "$(@D)" -f "$(abs_top_srcdir)/lib/Makefile" all
+
+.PHONY: $(abs_top_builddir)/libs-all
+$(abs_top_builddir)/libs-all: $(LTPLIBS_FILES) | $(abs_top_builddir)/lib/libltp.a
+ mkdir -m 00755 -p "$(abs_top_builddir)/libs"
+ $(MAKE) -C "$(abs_top_builddir)/libs" -f "$(abs_top_srcdir)/libs/Makefile" all
+
+endif
+
+ifneq ($(filter $(abs_top_builddir)/testcases $(abs_top_builddir)/testcases/kernel%,$(filter-out $(abs_top_builddir)/testcases/kernel/lib,$(CURDIR))),)
+
+MAKE_DEPS += $(abs_top_builddir)/testcases/kernel/lib/libkerntest.a
+
+.PHONY: $(abs_top_builddir)/testcases/kernel/lib/libkerntest.a
+$(abs_top_builddir)/testcases/kernel/lib/libkerntest.a: | $(abs_top_builddir)/lib/libltp.a
+ mkdir -m 00755 -p "$(@D)"
+ $(MAKE) -C "$(@D)" -f "$(abs_top_srcdir)/testcases/kernel/lib/Makefile" all
+
+endif
+
+endif
diff --git a/include/mk/generic_trunk_target.inc b/include/mk/generic_trunk_target.inc
index f9db7896a..4186ee9d9 100644
--- a/include/mk/generic_trunk_target.inc
+++ b/include/mk/generic_trunk_target.inc
@@ -36,6 +36,8 @@ RECURSIVE_TARGETS ?= all install check
$(eval $(get_make_dirs))
+include $(top_srcdir)/include/mk/generic_lib_deps.inc
+
.PHONY: $(RECURSIVE_TARGETS) $(addprefix trunk-,$(RECURSIVE_TARGETS))
$(SUBDIRS): %:
@@ -78,6 +80,12 @@ endif
install: trunk-install
+ifneq ($(strip $(MAKE_DEPS)),)
+ifneq ($(strip $(filter all install,$(RECURSIVE_TARGETS))),)
+$(filter all install,$(RECURSIVE_TARGETS)): | $(MAKE_DEPS)
+endif
+endif
+
# Print out CURDIR to check for a recursion issue.
ifeq ($(strip $(SUBDIRS)),)
$(warning CURDIR is: $(CURDIR))
diff --git a/include/mk/testcases.mk b/include/mk/testcases.mk
index 5960d7485..f9ff93928 100644
--- a/include/mk/testcases.mk
+++ b/include/mk/testcases.mk
@@ -15,10 +15,7 @@ LIBLTP := $(LIBLTP_DIR)/libltp.a
$(APICMDS_DIR)/tst_kvercmp: | $(APICMDS_DIR)
$(MAKE) -C "$(APICMDS_DIR)" -f "$(abs_top_srcdir)/tools/apicmds/Makefile" all
-$(LIBLTP): | $(LIBLTP_DIR)
- $(MAKE) -C "$(LIBLTP_DIR)" -f "$(abs_top_srcdir)/lib/Makefile" all
-
-MAKE_DEPS := $(LIBLTP)
+MAKE_DEPS :=
INSTALL_DIR := testcases/bin
diff --git a/testcases/kernel/include/lib.mk b/testcases/kernel/include/lib.mk
index c1a0c6d52..8f1ec5313 100644
--- a/testcases/kernel/include/lib.mk
+++ b/testcases/kernel/include/lib.mk
@@ -29,8 +29,10 @@ LDFLAGS += -L$(LIBKERNTEST_DIR)
$(LIBKERNTEST_DIR):
mkdir -p "$@"
+ifneq ($(MAKELEVEL),0)
$(LIBKERNTEST): | $(LIBKERNTEST_DIR)
$(MAKE) -C "$(LIBKERNTEST_DIR)" -f "$(LIBKERNTEST_SRCDIR)/Makefile" all
+endif
MAKE_DEPS += $(LIBKERNTEST)
--
2.56.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v4 3/3] build: Recurse into trunk subdirectories in parallel
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)
2026-11-24 11:32 ` [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Cyril Hrubis
3 siblings, 0 replies; 5+ messages in thread
From: Li Wang (Hieco) @ 2026-11-24 9:06 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine
2026-11-24 9:06 [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Li Wang (Hieco)
` (2 preceding siblings ...)
2026-11-24 9:06 ` [LTP] [PATCH v4 3/3] build: Recurse into trunk subdirectories in parallel Li Wang (Hieco)
@ 2026-11-24 11:32 ` Cyril Hrubis
3 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2026-11-24 11:32 UTC (permalink / raw)
To: Li Wang (Hieco); +Cc: ltp
Hi!
Patchset applied, thanks.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-24 11:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [LTP] [PATCH v4 3/3] build: Recurse into trunk subdirectories in parallel Li Wang (Hieco)
2026-11-24 11:32 ` [LTP] [PATCH v4 0/3] Speedup LTP compile time by ~20% on multi-machine Cyril Hrubis
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.