Date: 25 Aug 1997 12:18:04 GMT From: nnd@itfs.nsk.su To: current@freebsd.org Subject: Re: Make and SMP - what can be done ? Message-ID: <5trt5s$kh1@news.itfs.nsk.su> References: <199708130432.VAA06415@silvia.HIP.Berkeley.EDU> <5t64ts$7ae@news.itfs.nsk.su>
next in thread | previous in thread | raw e-mail | index | archive | help
This weekend's results of "parallel buildworld" investigations: To make 'buildworld' target making more "parallel" I try to do 'make depend' step with '-j12' flag and fails (;-). 1) First reason to this fault is in 'bsd.dep.mk' where 'depend' target usually looks like: depend: beforedepend .depend afterdepend _SUBDIR which (from the names of 'before/after'depend targets) assumes "sequential" evaluation. The patch (bsd.dep-patch) address this problem and (nearly) solves it. The only unsolved case - if there is 'Makefile' wich sets dependencies for 'beforedepend' target BUT not defines actions for such a rule. It turns out that all such cases in FreeBSD-3.0 src tree can be solved by deleting such a rule for 'beforedepend' from corresponding 'Makefile' and adding all the sources from this rule to the SRCS variable (see the patches for Makefiles later in this message). 2) The second source of troubles was presented by "functions with many results" (;-) - i.e. ${YACC} or ${BISON} commands which produces both <something.c> and <something.h> and have the following sort of rules for them in Makefile(s): foo.c bar.h: baz.y ${YACC} ... baz.y mv y.tab.c foo.c mv y.tab.h bar.h Such a rules obviously presents problems when we try to use "parallel making". All the reallife (i.e. from FreeBSD src tree) examples of such rules can be made "parallel-safe" by adding the rule of the form: .ORDER: foo.c bar.h to the corresponding Makefile. To be correct such an additional rule must followed the requirement - "The first source of this rule must be required for all those targets (all,install, depend ...) for which the second one is necessary". 3) src/gnu/cc/cc_tools/Makefile is too complex (to me) to make it "parallel safe" with respect to 'make -j12 depend' ;-( So I gave up and insert '.SINGLESHELL:' rule in this Makefile which sets the 'compatMake' compatible mode ;-) 4) Some of the 'builworld' steps are too "sequential" - f.e cleaning or rebuilding of the 'obj' tree. There is the shell's 'for' loop through SUBDIRs and small number of the (simple) commands for each of (sub)directory. To feed SMP system with more work I change some of such steps (see the 'par-<something>" part in Makefile.patch). Such a construct must be used very carefully - it can produce too many processes ;-). As a result my last successfull 'make -j12 buildworld' produced 170.9% processor's usage and takes 2:54:00 as opposed to 104.1% and 4:34:23 for 'make buildworld' (without any patches). To achieve this I use following patches: 1) 'make-patch' - propagate '-B' flag to inner 'make's; 2) 'bsd.dep-patch' - to "order" depend's subtargets; 3) 'makefiles-patch' - to make various Makefiles "parallel-safe"; 4) 'Makefile-patch' - patch to src/Makefile to restrict "parallelism" in some cases and to "broaden" it in other steps. make-patch=========================================================== --- src/usr.bin/make-std/main.c Fri Aug 15 17:59:11 1997 +++ src/usr.bin/make/main.c Fri Aug 15 18:07:14 1997 @@ -190,6 +190,7 @@ break; case 'B': compatMake = TRUE; + Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL); break; #ifdef REMOTE case 'L': bsd.dep-patch=========================================================== diff -ruN src/share/mk-std/bsd.dep.mk src/share/mk/bsd.dep.mk --- src/share/mk-std/bsd.dep.mk Fri Jun 20 12:58:49 1997 +++ src/share/mk/bsd.dep.mk Fri Aug 22 16:14:47 1997 @@ -33,8 +33,8 @@ # some of the rules involve .h sources, so remove them from mkdep line .if !target(depend) -depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR .if defined(SRCS) +depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR # .if defined ${SRCS:M*.[sS]} does not work __depend_s= ${SRCS:M*.[sS]} @@ -60,11 +60,15 @@ cd ${.CURDIR}; ${MAKE} _EXTRADEPEND .endif +.ORDER: ${DEPENDFILE} afterdepend .else -${DEPENDFILE}: _SUBDIR +depend: beforedepend afterdepend _SUBDIR .endif .if !target(beforedepend) beforedepend: +.else +.ORDER: beforedepend ${DEPENDFILE} +.ORDER: beforedepend afterdepend .endif .if !target(afterdepend) afterdepend: @@ -83,9 +87,9 @@ .endif .endif -.if defined(SRCS) .if !target(cleandepend) cleandepend: _SUBDIR +.if defined(SRCS) rm -f ${DEPENDFILE} rm -f ${.CURDIR}/GRTAGS ${.CURDIR}/GTAGS .if defined(HTML) makefiles-patch=========================================================== diff -ruN src/gnu/usr.bin/cc/cc_tools-std/Makefile src/gnu/usr.bin/cc/cc_tools/Makefile --- src/gnu/usr.bin/cc/cc_tools-std/Makefile Sat Feb 22 21:44:58 1997 +++ src/gnu/usr.bin/cc/cc_tools/Makefile Fri Aug 22 15:44:50 1997 @@ -26,8 +26,9 @@ .endfor +.ORDER: bi-parser.c bi-parser.h bi-parser.c bi-parser.h: bi-parser.y - ${BISON} ${BISONFLAGS} -d ${.ALLSRC} -o ${.TARGET} + ${BISON} ${BISONFLAGS} -d ${.ALLSRC} -o bi-parser.c SRCS+= bi-parser.c bi-parser.h @@ -82,6 +83,7 @@ #----------------------------------------------------------------------- # C parser +.ORDER: c-parse.c c-parse.h c-parse.c c-parse.h: c-parse.in sed -e "/^ifobjc$$/,/^end ifobjc$$/d" \ -e "/^ifc$$/d" -e "/^end ifc$$/d" \ @@ -94,6 +96,7 @@ #----------------------------------------------------------------------- # objc parser +.ORDER: objc-parse.c objc-parse.h objc-parse.c objc-parse.h: c-parse.in sed -e "/^ifc$$/,/^end ifc$$/d" \ -e "/^ifobjc$$/d" -e "/^end ifobjc$$/d" \ @@ -114,6 +117,12 @@ #----------------------------------------------------------------------- all: ${BINFORMAT} ${SRCS} + +#----------------------------------------------------------------------- +# Make 'depend' in compat mode +.if make(depend) +.SINGLESHELL: +.endif beforedepend: ${BINFORMAT} diff -ruN src/gnu/usr.bin/cc/cc1plus-std/Makefile src/gnu/usr.bin/cc/cc1plus/Makefile --- src/gnu/usr.bin/cc/cc1plus-std/Makefile Thu Jul 10 11:40:35 1997 +++ src/gnu/usr.bin/cc/cc1plus/Makefile Tue Aug 19 14:26:13 1997 @@ -6,7 +6,7 @@ .PATH: ${.CURDIR}/../../../../contrib/gcc/cp PROG = cc1plus -SRCS = parse.c \ +SRCS = parse.c parse.h \ call.c class.c cvt.c decl.c decl2.c edsel.c errfn.c \ error.c except.c expr.c gc.c init.c lex.c method.c pt.c \ ptree.c repo.c search.c sig.c spew.c tree.c typeck.c typeck2.c xref.c @@ -17,6 +17,7 @@ LDADD+= ${LIBCC_INT} CFLAGS+= -I. # I mean it. +.ORDER: parse.c parse.h parse.c parse.h: parse.y ${BISON} -d ${GCCDIR}/cp/parse.y -o parse.c grep '^#define[ ]*YYEMPTY' parse.c >>parse.h diff -ruN src/gnu/usr.bin/cc/cpp-std/Makefile src/gnu/usr.bin/cc/cpp/Makefile --- src/gnu/usr.bin/cc/cpp-std/Makefile Sat Feb 22 21:44:59 1997 +++ src/gnu/usr.bin/cc/cpp/Makefile Sun Aug 17 19:29:04 1997 @@ -9,6 +9,7 @@ MAN1= cccp.1 MLINKS= cccp.1 cpp.1 +.ORDER: cexp.c cexp.h cexp.c cexp.h: cexp.y ${BISON} -d ${GCCDIR}/cexp.y -o cexp.c diff -ruN src/gnu/usr.bin/gdb/gdb-std/Makefile src/gnu/usr.bin/gdb/gdb/Makefile --- src/gnu/usr.bin/gdb/gdb-std/Makefile Fri May 2 18:22:51 1997 +++ src/gnu/usr.bin/gdb/gdb/Makefile Sat Aug 23 15:01:28 1997 @@ -39,7 +39,8 @@ #CFLAGS+= -g CLEANFILES+= c-exp.c f-exp.c m2-exp.c init.c y.tab.h init.c-tmp -beforedepend: c-exp.c f-exp.c m2-exp.c init.c +#beforedepend: c-exp.c f-exp.c m2-exp.c init.c +.ORDER: c-exp.c f-exp.c m2-exp.c .if exists(${.OBJDIR}/../bfd) LDADD+= -L${.OBJDIR}/../bfd -lbfd --- src/usr.sbin/amd/fsinfo-std/Makefile Sat Feb 22 22:03:14 1997 +++ src/usr.sbin/amd/fsinfo/Makefile Tue Aug 19 13:45:04 1997 @@ -3,7 +3,7 @@ PROG= fsinfo MAN8= fsinfo.8 -SRCS= fsinfo.c fsi_gram.c fsi_lex.c \ +SRCS= fsinfo.c fsi_gram.c fsi_gram.h fsi_lex.c \ fsi_util.c fsi_analyze.c fsi_dict.c \ wr_atab.c wr_bparam.c wr_dumpset.c \ wr_exportfs.c wr_fstab.c @@ -16,6 +16,7 @@ CFLAGS+=-DOS_HDR=\"os-bsd44.h\" fsi_lex.o fsinfo.o: fsi_gram.h +.ORDER: fsi_gram.c fsi_gram.h fsi_gram.c fsi_gram.h: ../fsinfo/fsi_gram.y @echo "# expect 2 shift/reduce conflicts" ${YACC} -d ${.CURDIR}/fsi_gram.y --- src/lib/libpcap-std/Makefile Sun Aug 17 17:24:59 1997 +++ src/lib/libpcap/Makefile Tue Aug 19 12:26:32 1997 @@ -32,6 +32,7 @@ ${DESTDIR}/usr/include .endfor +.ORDER: grammar.c tokdefs.h tokdefs.h grammar.c: grammar.y ${YACC} ${YACCFLAGS} -d ${PCAP_DISTDIR}/grammar.y mv y.tab.c grammar.c diff -ruN src/bin/sh-std/Makefile src/bin/sh/Makefile --- src/bin/sh-std/Makefile Wed May 21 10:23:23 1997 +++ src/bin/sh/Makefile Wed Aug 20 14:13:31 1997 @@ -7,7 +7,8 @@ mystring.c options.c output.c parser.c printf.c redir.c show.c \ trap.c var.c GENSRCS= arith.c arith_lex.c builtins.c init.c nodes.c syntax.c -SRCS= ${SHSRCS} ${GENSRCS} +GENHDRS= builtins.h nodes.h syntax.h token.h +SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS} DPADD+= ${LIBL} ${LIBEDIT} ${LIBTERMCAP} LDADD+= -ll -ledit -ltermcap @@ -19,13 +20,13 @@ .PATH: ${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf -CLEANFILES+= builtins.h mkinit mkinit.o mknodes mknodes.o \ +CLEANFILES+= mkinit mkinit.o mknodes mknodes.o \ mksyntax mksyntax.o \ - nodes.h syntax.h token.h y.tab.h -CLEANFILES+= ${GENSRCS} + y.tab.h +CLEANFILES+= ${GENSRCS} ${GENHDRS} -beforedepend: builtins.h nodes.h syntax.h token.h +.ORDER: builtins.c builtins.h builtins.c builtins.h: mkbuiltins builtins.def cd ${.CURDIR}; sh mkbuiltins ${.OBJDIR} @@ -33,9 +34,11 @@ redir.c trap.c var.c ./mkinit ${.ALLSRC:S/^mkinit$//} +.ORDER: nodes.c nodes.h nodes.c nodes.h: mknodes nodetypes nodes.c.pat ./mknodes ${.CURDIR}/nodetypes ${.CURDIR}/nodes.c.pat +.ORDER: syntax.c syntax.h syntax.c syntax.h: mksyntax ./mksyntax --- src/usr.bin/lex-std/Makefile Sat Aug 16 19:28:45 1997 +++ src/usr.bin/lex/Makefile Tue Aug 19 13:48:02 1997 @@ -15,6 +15,7 @@ LINKS+= ${BINDIR}/lex ${BINDIR}/flex++ SRCS= scan.c ccl.c dfa.c ecs.c gen.c main.c misc.c nfa.c parse.c \ + parse.h \ skel.c sym.c tblcmp.c yylex.c LFLAGS+= -is CFLAGS+= -I. -I${.CURDIR} @@ -34,6 +35,7 @@ ${.CURDIR}/FlexLexer.h ${DESTDIR}/usr/include/g++ +.ORDER: parse.c parse.h parse.c parse.h: parse.y $(YACC) -d $(.CURDIR)/parse.y mv -f y.tab.c parse.c @@ -46,7 +48,6 @@ cp -f ${.CURDIR}/initscan.c scan.c ; \ } -beforedepend: parse.h scan.o: parse.h test: check make-patch=========================================================== --- src/Makefile.ORIG Fri Aug 22 17:25:16 1997 +++ src/Makefile Sat Aug 23 15:36:31 1997 @@ -224,9 +224,10 @@ mkdir -p ${WORLDTMP}/usr/bin cd ${.CURDIR}/usr.bin/make && \ ${IBMAKE} -I${.CURDIR}/share/mk \ - ${OBJDIR} clean cleandepend depend && \ + -B ${OBJDIR} clean cleandepend depend && \ + ${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} all && \ ${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} \ - all install clean cleandepend + -B install clean cleandepend @echo @echo "--------------------------------------------------------------" @echo " Making hierarchy" @@ -237,14 +238,14 @@ @echo "--------------------------------------------------------------" @echo " Cleaning up the obj tree" @echo "--------------------------------------------------------------" - cd ${.CURDIR} && ${BMAKE} ${CLEANDIR} + cd ${.CURDIR} && ${BMAKE} par-${CLEANDIR} .endif .if !defined(NOOBJDIR) @echo @echo "--------------------------------------------------------------" @echo " Rebuilding the obj tree" @echo "--------------------------------------------------------------" - cd ${.CURDIR} && ${BMAKE} obj + cd ${.CURDIR} && ${BMAKE} par-obj .endif @echo @echo "--------------------------------------------------------------" @@ -280,7 +281,7 @@ @echo "--------------------------------------------------------------" @echo " Rebuilding dependencies" @echo "--------------------------------------------------------------" - cd ${.CURDIR} && ${XMAKE} depend + cd ${.CURDIR} && ${XMAKE} -j4 par-depend @echo @echo "--------------------------------------------------------------" @echo " Building everything.." @@ -423,11 +424,14 @@ cd ${.CURDIR}/include && make symlinks .endif cd ${.CURDIR}/usr.bin/make && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} cd ${.CURDIR}/usr.bin/xinstall && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} cd ${.CURDIR}/usr.bin/lex && ${MAKE} bootstrap && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} -DNOLIB all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} -DNOLIB all && \ + ${MAKE} ${MK_FLAGS} -DNOLIB -B install ${CLEANDIR} ${OBJDIR} # # include-tools - generally the same as 'bootstrap', except that it's for @@ -438,8 +442,9 @@ # on cleaned away headers in ${WORLDTMP}. # include-tools: - cd ${.CURDIR}/usr.bin/rpcgen && ${MAKE} cleandepend depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + cd ${.CURDIR}/usr.bin/rpcgen && ${MAKE} -B cleandepend depend && \ + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} # # includes - possibly generate and install the include files. @@ -450,7 +455,7 @@ mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${DESTDIR}/usr/include .endif - cd ${.CURDIR}/include && ${MAKE} all installhdrs symlinks + cd ${.CURDIR}/include && ${MAKE} -B all installhdrs symlinks cd ${.CURDIR}/gnu/include && ${MAKE} install cd ${.CURDIR}/gnu/lib/libmp && ${MAKE} beforeinstall cd ${.CURDIR}/gnu/lib/libobjc && ${MAKE} beforeinstall @@ -517,7 +522,8 @@ usr.bin/ranlib \ usr.bin/uudecode cd ${.CURDIR}/$d && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endfor # @@ -526,43 +532,53 @@ libraries: .if exists(lib/csu/i386) cd ${.CURDIR}/lib/csu/i386 && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(lib/libcompat) cd ${.CURDIR}/lib/libcompat && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(lib/libncurses) cd ${.CURDIR}/lib/libncurses && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(lib/libtermcap) cd ${.CURDIR}/lib/libtermcap && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(gnu) cd ${.CURDIR}/gnu/lib && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(secure) && !defined(NOCRYPT) && !defined(NOSECURE) cd ${.CURDIR}/secure/lib && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(lib) cd ${.CURDIR}/lib && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(usr.bin/lex/lib) cd ${.CURDIR}/usr.bin/lex/lib && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(eBones) && !defined(NOCRYPT) && defined(MAKE_EBONES) cd ${.CURDIR}/eBones/lib && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif .if exists(usr.sbin/pcvt/keycap) cd ${.CURDIR}/usr.sbin/pcvt/keycap && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} .endif # @@ -633,7 +649,25 @@ usr.sbin/mtree \ usr.sbin/zic cd ${.CURDIR}/$d && ${MAKE} depend && \ - ${MAKE} ${MK_FLAGS} all install ${CLEANDIR} ${OBJDIR} + ${MAKE} ${MK_FLAGS} all && \ + ${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR} +.endfor + +.for __target in clean cleandir obj depend +.for entry in ${SUBDIR} +${entry}.${__target}__D: .PHONY + if test -d ${.CURDIR}/${entry}.${MACHINE}; then \ + ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE}"; \ + edir=${entry}.${MACHINE}; \ + cd ${.CURDIR}/$${edir}; \ + else \ + ${ECHODIR} "===> ${DIRPRFX}${entry}"; \ + edir=${entry}; \ + cd ${.CURDIR}/$${edir}; \ + fi; \ + ${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/ +.endfor +par-${__target}: ${SUBDIR:S/$/.${__target}__D/} .endfor .include <bsd.subdir.mk>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5trt5s$kh1>