From nobody Thu Apr 20 16:41:37 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q2Nhy1DYQz46HG7; Thu, 20 Apr 2023 16:41:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q2Nhx6d4Bz4Nbv; Thu, 20 Apr 2023 16:41:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682008897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VgrgkM4gWrZ6yC2o5CudXyUqNpniywO/SM+GnCUAX/8=; b=puXxLILcFdTiObErwN8Zzn7+BUwPv2kaEyLjGk/ksAlmoQmniU5hp53eCRUG6H/uc45d9p 0aVgd7yE6j27Lf/OdTAe4D/gMM1B/KtQlHN/TeoNCj0Vsy3h0b8WO61JDmx5vp17TQNbQj PaMlx+3t3e8koIwllVasagtHzK2trqIla6X038htnNSmV0Kbn5bfVZQoL5i2+AiQ/wB6jG fX6n2QxpEUz1gnpnti8ne7ztD/W91H3BjGqW8Xif2BK/cPBrYQ8QMB031QjOk69kQdLb74 n00bLpYzExixdWcZhoZgkC+ZmKk9gDWBupYgWG/+TuFelmVIlabhq0TXHBXpAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682008897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VgrgkM4gWrZ6yC2o5CudXyUqNpniywO/SM+GnCUAX/8=; b=WIVnYfWHFo7dZ2PMsOEWilTkhjBg20nLAMBWE6FmtBZJ3zoGTILgkwuDoZ6rfedVH6Lemw Xo4mxY3nEsTBloJstLhh+9tH0HJ2IyMrJOyKVoKgqN8y+S1h8XbC+DyKKxYZIRmC4iJsHg UGZNPFtMSM7fmCTqHQQnJh9m9hjVHCZ2mxmvbw8jXCcak5PUIvoIyoWlk8Ws3TaY7k1PEV bQDFHl1XFa6hWlZdoIza+mfAfwRQUaXjTnckw+es6bXUk+3vphWmpmb+y8ebH6OcZ2YxyR K8pH05G3HRlVfGc3zXe0lLiSd98FfXBpUu+Nr83TXRrPuFSJ9rN1I1GOsaWQ5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682008897; a=rsa-sha256; cv=none; b=L49qrrqCjhgiPNv12YgvuEYIArvUmNWJ7YlpdypfddioACHNXKE2RKu28OmMz2zwApzued a6UhBWKPoXi+OuQRz5rS9l7Yc+QIPZIL0l12yjeI1rg9pAgHIwN3m1VxNjcCJdEgR7fVba vokVTxxI4fYhZ4MvI8GFVbhDhFsoaMRT1S1a9XUxJIBbxlCrdqWYcckHGmKZftPIHI5oac DDysD5hfLBiYP+WfLmFYh8vG32LT8fmYfH1E/K13Vn721rkx/mxj3llSiAI+o4Qz5k62nB 5iMx8AjAQWrAnOeyu6bJ7uf5Tf8rMbEKdiwVFDV/sEyslnVA6pvtWvCp6k6+LQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q2Nhx5l3yzlDn; Thu, 20 Apr 2023 16:41:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33KGfbWg089376; Thu, 20 Apr 2023 16:41:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33KGfbrH089361; Thu, 20 Apr 2023 16:41:37 GMT (envelope-from git) Date: Thu, 20 Apr 2023 16:41:37 GMT Message-Id: <202304201641.33KGfbrH089361@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Simon J. Gerraty" Subject: git: 0df4d8ad7a1b - main - Add jobs.mk to allow for target-jobs List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0df4d8ad7a1b675ead8dec70f291bfd4f3fd81fa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by sjg: URL: https://cgit.FreeBSD.org/src/commit/?id=0df4d8ad7a1b675ead8dec70f291bfd4f3fd81fa commit 0df4d8ad7a1b675ead8dec70f291bfd4f3fd81fa Author: Simon J. Gerraty AuthorDate: 2023-04-20 16:40:39 +0000 Commit: Simon J. Gerraty CommitDate: 2023-04-20 16:40:39 +0000 Add jobs.mk to allow for target-jobs jobs.mk automates -j$JOB_MAX and capturing build log based on target. Compute a default for JOB_MAX in local.sys.mk Reviewed by: stevek, imp Differential Revision: https://reviews.freebsd.org/D39683 --- Makefile | 10 ++++++ UPDATING | 9 ++++++ share/mk/jobs.mk | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ share/mk/local.sys.mk | 20 ++++++++++++ 4 files changed, 127 insertions(+) diff --git a/Makefile b/Makefile index 8232041e0a35..0b2438a0cfc0 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,16 @@ # For more information, see the build(7) manual page. # +# Include jobs.mk early if we need it. +# It will turn: +# make buildworld-jobs +# into +# make -j${JOB_MAX} buildworld > ../buildworld.log 2>&1 +# +.if make(*-jobs) +.include +.endif + .if defined(UNIVERSE_TARGET) || defined(MAKE_JUST_WORLDS) || defined(WITHOUT_KERNELS) __DO_KERNELS=no .endif diff --git a/UPDATING b/UPDATING index 092115d899ea..70e5a58352af 100644 --- a/UPDATING +++ b/UPDATING @@ -27,6 +27,15 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 14.x IS SLOW: world, or to merely disable the most expensive debugging functionality at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20230420: + Add jobs.mk to save typing. Enables -j${JOB_MAX} and logging + eg. + make buildworld-jobs + runs + make -j${JOB_MAX} buildworld > ../buildworld.log 2>&1 + + where JOB_MAX is derrived from ncpus in local.sys.mk if not set in env. + 20230316: Video related devices for some arm devices have been renamed. If you have a custom kernel config and want to use hdmi output on diff --git a/share/mk/jobs.mk b/share/mk/jobs.mk new file mode 100644 index 000000000000..f465ea06310b --- /dev/null +++ b/share/mk/jobs.mk @@ -0,0 +1,88 @@ +# $Id: jobs.mk,v 1.7 2023/04/18 23:32:28 sjg Exp $ +# +# @(#) Copyright (c) 2012-2023, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# This makefile is used by top-level makefile. +# With the following: +# +# .if make(*-jobs) +# .include +# .endif +# +# +# Then if you do: +# +# mk target-jobs +# +# We will run: +# +# ${MAKE} -j${JOB_MAX} target > ${JOB_LOGDIR}/target.log 2>&1 +# +# JOB_MAX defaults to 8 but should normally be derrived based on the +# number of cpus available. The wrapper script 'mk' makes that easy. +# + +now_utc ?= ${%s:L:gmtime} +.if !defined(start_utc) +start_utc := ${now_utc} +.endif + +.info ${.newline}${TIME_STAMP} Start ${.TARGETS} + +.if make(*-jobs) + +JOB_LOGDIR ?= ${SRCTOP:H} +JOB_LOG = ${JOB_LOGDIR}/${.TARGET:S,-jobs,,:S,/,_,g}.log +JOB_LOG_GENS ?= 4 +# we like to rotate logs +.if empty(NEWLOG_SH) +.ifdef M_whence +NEWLOG_SH := ${newlog.sh:L:${M_whence}} +.else +NEWLOG_SH := ${(type newlog.sh) 2> /dev/null:L:sh:M/*} +.endif +.endif +.if !empty(NEWLOG_SH) && exists(${NEWLOG_SH}) +NEWLOG := sh ${NEWLOG_SH} +JOB_NEWLOG_ARGS ?= -S -n ${JOB_LOG_GENS} +.else +NEWLOG = : +.endif + +.if ${.MAKE.JOBS:U0} > 0 +JOB_MAX= ${.MAKE.JOBS} +.else +# This should be derrived from number of cpu's +JOB_MAX?= 8 +JOB_ARGS+= -j${JOB_MAX} +.endif + +# we need to reset .MAKE.LEVEL to 0 do that +# build orchestration works as expected (DIRDEPS_BUILD) +${.TARGETS:M*-jobs}: + @${NEWLOG} ${JOB_NEWLOG_ARGS} ${JOB_LOG} + @echo Logging to ${JOB_LOG} + @cd ${.CURDIR} && env MAKELEVEL=0 \ + ${.MAKE} ${JOB_ARGS} _TARGETS=${.TARGET:S,-jobs,,} ${.TARGET:S,-jobs,,} >> ${JOB_LOG} 2>&1 + +.endif + +.END: _build_finish +.ERROR: _build_failed + +_build_finish: .NOMETA + @echo "${TIME_STAMP} Finished ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" + +_build_failed: .NOMETA + @echo "${TIME_STAMP} Failed ${.TARGETS} seconds=`expr ${now_utc} - ${start_utc}`" diff --git a/share/mk/local.sys.mk b/share/mk/local.sys.mk index 39605c05e129..1817f6393949 100644 --- a/share/mk/local.sys.mk +++ b/share/mk/local.sys.mk @@ -59,6 +59,26 @@ _PREMK_LIBDIR:= ${LIBDIR} .include "src.sys.mk" .-include +.if make(*-jobs) && empty(JOB_MAX) +# provide a reasonable? default for JOB_MAX based on ncpu +JOB_MAX_FACTOR?= 1.33 +NPROC?= ${(type nproc) 2> /dev/null:L:sh:M/*:[1]} +NPROC:= ${NPROC} +.if !empty(NPROC) +ncpu!= ${NPROC} +.elif ${.MAKE.OS:NDarwin:NFreeBSD} == "" +ncpu!= sysctl -n hw.ncpu +.endif +.if ${ncpu:U0} > 1 +.if ${JOB_MAX_FACTOR} == 1 +JOB_MAX:= ${ncpu} +.else +jm!= echo ${ncpu} \* ${JOB_MAX_FACTOR} | bc +JOB_MAX:= ${jm:R} +.endif +.endif +.endif + .if ${.MAKE.MODE:Mmeta*} != "" # we can afford to use cookies to prevent some targets # re-running needlessly but only when using filemon.