From e089371c3ad0f04dce948d3d5478c44a3906b45d Mon Sep 17 00:00:00 2001 From: dim Date: Wed, 9 Apr 2014 18:16:58 +0000 Subject: [PATCH] MFC r263778: Add a SUBDIR_PARALLEL option to bsd.subdir.mk, to allow make to process all the SUBDIR entries in parallel, instead of serially. Apply this option to a selected number of Makefiles, which can greatly speed up the build on multi-core machines, when using make -j. This can be extended to more Makefiles later on, whenever they are verified to work correctly with parallel building. I tested this on a 24-core machine, with make -j48 buildworld (N = 6): before stddev after stddev ======= ====== ======= ====== real time 1741.1 16.5 959.8 2.7 user time 12468.7 16.4 14393.0 16.8 sys time 1825.0 54.8 2110.6 22.8 (user+sys)/real 8.2 17.1 E.g. the build was approximately 45% faster in real time. On machines with less cores, or with lower -j settings, the speedup will not be as impressive. But at least you can now almost max out a machine with buildworld! Submitted by: jilles MFC r263833: Enable parallel building for gnu/usr.bin and usr.bin/clang too. git-svn-id: svn://svn.freebsd.org/base/stable/9@264303 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- bin/Makefile | 2 ++ gnu/usr.bin/Makefile | 2 ++ lib/Makefile | 4 ++++ lib/clang/Makefile | 2 ++ sbin/Makefile | 2 ++ share/mk/bsd.subdir.mk | 19 +++++++++++++++++++ usr.bin/Makefile | 2 ++ usr.bin/clang/Makefile | 2 ++ usr.sbin/Makefile | 2 ++ 9 files changed, 37 insertions(+) diff --git a/bin/Makefile b/bin/Makefile index e5052cad5..31ec81b89 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -55,4 +55,6 @@ SUBDIR+= csh SUBDIR:= ${SUBDIR:O} +SUBDIR_PARALLEL= + .include diff --git a/gnu/usr.bin/Makefile b/gnu/usr.bin/Makefile index b222c4795..306ded1dc 100644 --- a/gnu/usr.bin/Makefile +++ b/gnu/usr.bin/Makefile @@ -53,4 +53,6 @@ _cc= cc _gdb= gdb .endif +SUBDIR_PARALLEL= + .include diff --git a/lib/Makefile b/lib/Makefile index 411089775..734bc0dc7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -240,4 +240,8 @@ _libusbhid= libusbhid _libusb= libusb .endif +.if !make(install) +SUBDIR_PARALLEL= +.endif + .include diff --git a/lib/clang/Makefile b/lib/clang/Makefile index 2ad96f818..a4c8a40f7 100644 --- a/lib/clang/Makefile +++ b/lib/clang/Makefile @@ -101,4 +101,6 @@ SUBDIR+=libllvmdebuginfo \ SUBDIR+= include +SUBDIR_PARALLEL= + .include diff --git a/sbin/Makefile b/sbin/Makefile index f9ba4cae6..006bb237b 100644 --- a/sbin/Makefile +++ b/sbin/Makefile @@ -113,4 +113,6 @@ SUBDIR+= routed SUBDIR:= ${SUBDIR:O} +SUBDIR_PARALLEL= + .include diff --git a/share/mk/bsd.subdir.mk b/share/mk/bsd.subdir.mk index a66ab9bf9..85e60a885 100644 --- a/share/mk/bsd.subdir.mk +++ b/share/mk/bsd.subdir.mk @@ -68,7 +68,26 @@ ${SUBDIR}: .PHONY .for __target in all all-man checkdpadd clean cleandepend cleandir \ cleanilinks depend distribute lint maninstall manlint obj objlink \ realinstall regress tags ${SUBDIR_TARGETS} +.ifdef SUBDIR_PARALLEL +.for __dir in ${SUBDIR} +${__target}: ${__target}_subdir_${__dir} +${__target}_subdir_${__dir}: .MAKE + @${_+_}set -e; \ + if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \ + ${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \ + edir=${__dir}.${MACHINE_ARCH}; \ + cd ${.CURDIR}/$${edir}; \ + else \ + ${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \ + edir=${__dir}; \ + cd ${.CURDIR}/$${edir}; \ + fi; \ + ${MAKE} ${__target:realinstall=install} \ + DIRPRFX=${DIRPRFX}$$edir/ +.endfor +.else ${__target}: _SUBDIR +.endif .endfor .for __target in files includes diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 44375af5d..159f03ac4 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -351,4 +351,6 @@ SUBDIR+= wtmpcvt SUBDIR:= ${SUBDIR:O} +SUBDIR_PARALLEL= + .include diff --git a/usr.bin/clang/Makefile b/usr.bin/clang/Makefile index 0eb46cce6..2db967a5f 100644 --- a/usr.bin/clang/Makefile +++ b/usr.bin/clang/Makefile @@ -23,4 +23,6 @@ SUBDIR+=bugpoint \ opt .endif +SUBDIR_PARALLEL= + .include diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile index 3b8be8f7e..dc5b85875 100644 --- a/usr.sbin/Makefile +++ b/usr.sbin/Makefile @@ -335,4 +335,6 @@ SUBDIR+= wpa SUBDIR:= ${SUBDIR:O} +SUBDIR_PARALLEL= + .include -- 2.45.0