From owner-svn-src-head@freebsd.org Fri Nov 6 04:45:32 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E8B93A2622E; Fri, 6 Nov 2015 04:45:31 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B973812B1; Fri, 6 Nov 2015 04:45:31 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA64jU7O063315; Fri, 6 Nov 2015 04:45:30 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA64jUjj063307; Fri, 6 Nov 2015 04:45:30 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201511060445.tA64jUjj063307@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Fri, 6 Nov 2015 04:45:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290433 - in head: share/mk sys/conf tools/build/options X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Nov 2015 04:45:32 -0000 Author: bdrewery Date: Fri Nov 6 04:45:29 2015 New Revision: 290433 URL: https://svnweb.freebsd.org/changeset/base/290433 Log: Add a FAST_DEPEND option, off by default, which speeds up the build significantly. This speeds up buildworld by 16% on my system and buildkernel by 35%. Rather than calling mkdep(1), which is just a wrapper around 'cc -E', use the modern -MD -MT -MF flags to gather and generate dependencies during compilation. This flag was introduced in GCC "a long time ago", in GCC 3.0, and is also supported by Clang. (It appears that ICC also supports this but I do not have access to test it). This avoids running the preprocessor *twice* for every build, in both 'make depend' and 'make all'. This is especially noticeable when using ccache since it does not cache preprocessor results from mkdep(1) / 'cc -E', but still speeds up compilation with the -MD flags. For 'make depend' a tree-walk is still done to ensure that all DPSRCS are generated when expected, and that beforedepend/afterdepend and _EXTRADEPEND are all still respected. In time this may change but for now I've been conservative. The time for a tree-walk with -j combined with SUBDIR_PARALLEL is not significant. For example, it takes about 9 seconds with -j15 to walk all of src/ for 'make depend' now on my system. A .depend file is still generated with the various rules that apply to the final target, or custom rules. Otherwise there are now per-built-object-file .depend files, such as .depend.filename.o. These are included directly by make rather than populating .depend with a loop and .depend lines, which only added overhead to the now almost-NOP 'make depend' phase. Before this I experimented with having mkdep(1) called in parallel per-file. While this improved the kernel and lib/libc 'make depend' phase, it resulted in slower build times overall. The -M flags are removed from CFLAGS when linking since they have no effect. Enabling this by default, for src or out-of-src, can be done once more testing has been done, such as a ports exp-run, and with more compilers. The system I used for testing was: WITNESS Build options: -j20 WITH_LLDB=yes WITH_DEBUG_FILES=yes WITH_FAST_DEPEND=yes DISK: ZFS 3-way mirror with very slow disks using SSD l2arc/log. The arc was fully populated with src tree files. RAM: 76GiB CPU: Intel(R) Xeon(R) CPU L5520 @2.27GHz 2 package(s) x 4 core(s) x 2 SMT threads = hw.ncpu=16 buildworld: x buildworld-before + buildworld-fastdep +-------------------------------------------------------------------------------+ |+ | |+ | |+ xx x| | |_MA___|| |A | +-------------------------------------------------------------------------------+ N Min Max Median Avg Stddev x 3 3744.13 3794.31 3752.25 3763.5633 26.935139 + 3 3153.34 3155.16 3154.2 3154.2333 0.91045776 Difference at 95.0% confidence -609.33 +/- 43.1943 -16.1902% +/- 1.1477% (Student's t, pooled s = 19.0569) buildkernel: x buildkernel-before + buildkernel-fastdep +-------------------------------------------------------------------------------+ |+ x | |++ xx| | A|| |A| | +-------------------------------------------------------------------------------+ N Min Max Median Avg Stddev x 3 571.57 573.94 571.79 572.43333 1.3094401 + 3 369.12 370.57 369.3 369.66333 0.79033748 Difference at 95.0% confidence -202.77 +/- 2.45131 -35.4225% +/- 0.428227% (Student's t, pooled s = 1.0815) Sponsored by: EMC / Isilon Storage Division MFC after: 3 weeks Relnotes: yes Added: head/tools/build/options/WITH_FAST_DEPEND (contents, props changed) Modified: head/share/mk/bsd.dep.mk head/share/mk/bsd.lib.mk head/share/mk/bsd.opts.mk head/share/mk/bsd.prog.mk head/sys/conf/kern.opts.mk head/sys/conf/kern.post.mk Modified: head/share/mk/bsd.dep.mk ============================================================================== --- head/share/mk/bsd.dep.mk Fri Nov 6 03:09:26 2015 (r290432) +++ head/share/mk/bsd.dep.mk Fri Nov 6 04:45:29 2015 (r290433) @@ -54,6 +54,18 @@ MKDEPCMD?= CC='${CC} ${DEPFLAGS}' mkdep MKDEPCMD?= mkdep .endif DEPENDFILE?= .depend +DEPENDFILES= ${DEPENDFILE} +.if ${MK_FAST_DEPEND} == "yes" +DEPENDFILES+= ${DEPENDFILE}.* +DEPEND_CFLAGS+= -MD -MP -MF${DEPENDFILE}.${.TARGET} +DEPEND_CFLAGS+= -MT${.TARGET} +CFLAGS+= ${DEPEND_CFLAGS} +DEPENDOBJS+= ${OBJS} ${POBJS} ${SOBJS} +.for __obj in ${DEPENDOBJS:O:u} +.sinclude "${DEPENDFILE}.${__obj}" +DEPENDFILES_OBJS+= ${DEPENDFILE}.${__obj} +.endfor +.endif # ${MK_FAST_DEPEND} == "yes" # Keep `tags' here, before SRCS are mangled below for `depend'. .if !target(tags) && defined(SRCS) && !defined(NO_TAGS) @@ -161,7 +173,7 @@ afterdepend: beforedepend depend: beforedepend ${DEPENDFILE} afterdepend # Tell bmake not to look for generated files via .PATH -.NOPATH: ${DEPENDFILE} +.NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS} # Different types of sources are compiled with slightly different flags. # Split up the sources, and filter out headers and non-applicable flags. @@ -172,6 +184,7 @@ MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} DPSRCS+= ${SRCS} ${DEPENDFILE}: ${DPSRCS} +.if ${MK_FAST_DEPEND} == "no" rm -f ${DEPENDFILE} .if !empty(DPSRCS:M*.[cS]) ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ @@ -182,7 +195,11 @@ ${DEPENDFILE}: ${DPSRCS} ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ ${MKDEP_CXXFLAGS} \ ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} +.else .endif +.else + : > ${.TARGET} +.endif # ${MK_FAST_DEPEND} == "no" .if target(_EXTRADEPEND) _EXTRADEPEND: .USE ${DEPENDFILE}: _EXTRADEPEND @@ -207,12 +224,12 @@ afterdepend: cleandepend: .if defined(SRCS) .if ${CTAGS:T} == "gtags" - rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS + rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS .if defined(HTML) rm -rf HTML .endif .else - rm -f ${DEPENDFILE} tags + rm -f ${DEPENDFILES} tags .endif .endif .endif Modified: head/share/mk/bsd.lib.mk ============================================================================== --- head/share/mk/bsd.lib.mk Fri Nov 6 03:09:26 2015 (r290432) +++ head/share/mk/bsd.lib.mk Fri Nov 6 04:45:29 2015 (r290433) @@ -305,10 +305,12 @@ all: _manpages .endif _EXTRADEPEND: +.if ${MK_FAST_DEPEND} == "no" @TMP=_depend$$$$; \ sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ > $$TMP; \ mv $$TMP ${DEPENDFILE} +.endif .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) .if defined(DPADD) && !empty(DPADD) echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE} Modified: head/share/mk/bsd.opts.mk ============================================================================== --- head/share/mk/bsd.opts.mk Fri Nov 6 03:09:26 2015 (r290432) +++ head/share/mk/bsd.opts.mk Fri Nov 6 04:45:29 2015 (r290433) @@ -66,6 +66,7 @@ __DEFAULT_YES_OPTIONS = \ WARNS __DEFAULT_NO_OPTIONS = \ + FAST_DEPEND \ CTF \ DEBUG_FILES \ INSTALL_AS_USER \ Modified: head/share/mk/bsd.prog.mk ============================================================================== --- head/share/mk/bsd.prog.mk Fri Nov 6 03:09:26 2015 (r290432) +++ head/share/mk/bsd.prog.mk Fri Nov 6 04:45:29 2015 (r290433) @@ -82,9 +82,9 @@ ${PROG_FULL}: beforelinking .endif ${PROG_FULL}: ${OBJS} .if defined(PROG_CXX) - ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} + ${CXX} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} .else - ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} + ${CC} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} .endif .if ${MK_CTF} != "no" ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} @@ -112,9 +112,9 @@ ${PROG_FULL}: beforelinking .endif ${PROG_FULL}: ${OBJS} .if defined(PROG_CXX) - ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} + ${CXX} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} .else - ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} + ${CC} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} .endif .if ${MK_CTF} != "no" ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} Modified: head/sys/conf/kern.opts.mk ============================================================================== --- head/sys/conf/kern.opts.mk Fri Nov 6 03:09:26 2015 (r290432) +++ head/sys/conf/kern.opts.mk Fri Nov 6 04:45:29 2015 (r290433) @@ -45,6 +45,7 @@ __DEFAULT_YES_OPTIONS = \ __DEFAULT_NO_OPTIONS = \ EISA \ + FAST_DEPEND \ NAND \ OFED Modified: head/sys/conf/kern.post.mk ============================================================================== --- head/sys/conf/kern.post.mk Fri Nov 6 03:09:26 2015 (r290432) +++ head/sys/conf/kern.post.mk Fri Nov 6 04:45:29 2015 (r290433) @@ -198,18 +198,37 @@ kernel-depend: .depend SRCS= assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \ ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \ ${MFILES:T:S/.m$/.h/} +DEPENDFILES= .depend +.if ${MK_FAST_DEPEND} == "yes" +DEPENDFILES+= .depend.* +DEPEND_CFLAGS+= -MD -MP -MF.depend.${.TARGET} +DEPEND_CFLAGS+= -MT${.TARGET} +CFLAGS+= ${DEPEND_CFLAGS} +DEPENDOBJS+= ${SYSTEM_OBJS} +.for __obj in ${DEPENDOBJS:O:u} +.sinclude ".depend.${__obj}" +DEPENDFILES_OBJS+= .depend.${__obj} +.endfor +.endif # ${MK_FAST_DEPEND} == "yes" + +.NOPATH: .depend ${DEPENDFILES_OBJS} + .depend: .PRECIOUS ${SRCS} - rm -f .newdep +.if ${MK_FAST_DEPEND} == "no" + rm -f ${.TARGET}.tmp ${MAKE} -V CFILES_NOCDDL -V SYSTEM_CFILES -V GEN_CFILES | \ - MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS} + CC="${CC}" xargs mkdep -a -f ${.TARGET}.tmp ${CFLAGS} ${MAKE} -V CFILES_CDDL | \ - MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${ZFS_CFLAGS} ${FBT_CFLAGS} ${DTRACE_CFLAGS} + CC="${CC}" xargs mkdep -a -f ${.TARGET}.tmp ${ZFS_CFLAGS} \ + ${FBT_CFLAGS} ${DTRACE_CFLAGS} ${MAKE} -V SFILES_NOCDDL | \ - MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS} + CC="${CC}" xargs mkdep -a -f ${.TARGET}.tmp ${ASM_CFLAGS} ${MAKE} -V SFILES_CDDL | \ - MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ZFS_ASM_CFLAGS} - rm -f .depend - mv .newdep .depend + CC="${CC}" xargs mkdep -a -f ${.TARGET}.tmp ${ZFS_ASM_CFLAGS} + mv ${.TARGET}.tmp ${.TARGET} +.else + : > ${.TARGET} +.endif _ILINKS= machine .if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" @@ -237,8 +256,8 @@ ${_ILINKS}: ln -s $$path ${.TARGET} # .depend needs include links so we remove them only together. -kernel-cleandepend: - rm -f .depend ${_ILINKS} +kernel-cleandepend: .PHONY + rm -f ${DEPENDFILES} ${_ILINKS} kernel-tags: @[ -f .depend ] || { echo "you must make depend first"; exit 1; } Added: head/tools/build/options/WITH_FAST_DEPEND ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/build/options/WITH_FAST_DEPEND Fri Nov 6 04:45:29 2015 (r290433) @@ -0,0 +1,7 @@ +.\" $FreeBSD$ +Set to generate +.Sy .depend +files in the build during compilation instead of the +historial +.Xr mkdep 1 +call during the "make depend" phase.