From 30d2b57a7cfc4c91475bd114f52286205a20f0b3 Mon Sep 17 00:00:00 2001 From: sakaki Date: Tue, 17 Jan 2017 18:09:52 +0000 Subject: [PATCH] Add ability to set niceness for make. Default niceness adjustment set to +19, to avoid buildkernel clogging up the system. --- buildkernel | 38 +++++++++++++++++++++++++++----------- buildkernel.8 | 14 ++++++++++++-- buildkernel.conf.5 | 4 ++-- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/buildkernel b/buildkernel index a20cde0..801604f 100755 --- a/buildkernel +++ b/buildkernel @@ -3,7 +3,7 @@ # Build kernel, modules and initial ramdisk in correct sequence, ensuring kernel # config is conformed, then sign if possible and copy to EFI boot partition. # -# Copyright (c) 2014-2016 sakaki +# Copyright (c) 2014-2017 sakaki # # License (GPL v3.0) # ------------------ @@ -31,7 +31,7 @@ shopt -s nullglob # ********************** variables ********************* PROGNAME="$(basename "${0}")" CONFFILE="/etc/${PROGNAME}.conf" -VERSION="1.0.17" +VERSION="1.0.18" ETCPROFILE="/etc/profile" DEFAULTEFIBOOTFILE="bootx64.efi" EFIBOOTFILE="${DEFAULTEFIBOOTFILE}" @@ -118,6 +118,7 @@ VERBOSITYFLAG="" ASKFLAG="" ALERTFLAG="" PORTAGEINFO="" +MAKE="" # following array variables set by find_all_gpg_keyfile_partitions function declare -a GPGUUIDS GPGPARTNAMES GPGDEVNAMES GPGPARTNUMS # following array variables set by find_all_luks_partitions function @@ -161,6 +162,8 @@ declare -i ARG_STAGEONLY=0 ARG_UNMOUNTATEND=0 ARG_VERBOSE=0 ARG_VERSION=0 declare -i ARG_POSTCLEAR=0 ARG_MENUCONFIG=0 ARG_SNAPSHOTBACKUP=0 declare -i ARG_EASYSETUP=0 ARG_IS_NEW_KERNEL_AVAILABLE=0 declare -i ARG_REBUILD_EXTERNAL_MODULES=0 ARG_ALERT=0 +# non-boolean arguments +declare -i ADJUSTMENT=19 # ***************** various functions ****************** cleanup_and_exit_with_code() { @@ -1652,7 +1655,7 @@ clean_kernel_tree_if_desired() { fi if ((DOCLEAN==1)); then show "Cleaning up..." - make clean # not mrproper - so our .config file will be left alone + ${MAKE} clean # not mrproper - so our .config file will be left alone fi } kernel_build_pass_1() { @@ -1661,13 +1664,13 @@ kernel_build_pass_1() { rm ${VERBOSITYFLAG} -f "${UNCOMPRESSEDINITRAMFS}" touch "${UNCOMPRESSEDINITRAMFS}" show "Building ${NEWVERSION} (pass 1 - dummy initramfs)..." - make modules_prepare - make -j ${NUMCPUSPLUSONE} - make install + ${MAKE} modules_prepare + ${MAKE} -j ${NUMCPUSPLUSONE} + ${MAKE} install show "Installing modules..." - make modules_install + ${MAKE} modules_install show "Installing firmware..." - make firmware_install + ${MAKE} firmware_install } rebuild_external_modules_if_necessary() { if ((ARG_REBUILD_EXTERNAL_MODULES==1)); then @@ -1747,9 +1750,9 @@ repack_initramfs() { } kernel_build_pass_2() { show "Building ${NEWVERSION} (pass 2, to include real initramfs)..." - make -j ${NUMCPUSPLUSONE} + ${MAKE} -j ${NUMCPUSPLUSONE} show "Installing boot files to ${BOOTDIR}; for reference only..." - make install + ${MAKE} install # no need to re-install modules or firmware - only the initramfs has changed } sign_kernel_if_possible() { @@ -1954,6 +1957,9 @@ Options: (at /boot), or 1 otherwise -m, --menuconfig show kernel configuration GUI, even if non-interactive -p, --postclear clear genkernel temporary files and caches after run + -r, --adjustment=N add integer N to the make niceness -20<=N<=19 + (the default is 19; this runs make at the lowest + priority to avoid slowing the system too much) -s, --stage-only prepare kernel in /boot as usual, but do not copy to system partition -u, --unmount-at-end umount the EFI system partition on successful exit @@ -1993,6 +1999,9 @@ internal_consistency_option_checks() { if ((ARG_MENUCONFIG==1 && ARG_COPYFROMSTAGING==1)); then display_usage_message_and_bail_out "--menuconfig if meaningless with --copy-from-staging" fi + if ((ADJUSTMENT<-20 || ADJUSTMENT>19)); then + display_usage_message_and_bail_out "must have -20 <= make niceness adjustment <= 19" + fi } snapshot_kernel_on_efi_partition() { local TIMESTAMP_PREFIX=$(date +"%Y-%m-%d-%H-%M-%S-") @@ -2019,7 +2028,7 @@ process_command_line_options() { declare -i RC set +e # error trapping off, as we want to handle errors - TEMP="$(getopt -o aAbcefhimpsuvxV --long ask,alert,snapshot-backup,clean,easy-setup,copy-from-staging,help,is-new-kernel-available,menuconfig,postclear,stage-only,verbose,unmount-at-end,rebuild-external-modules,version -n "${PROGNAME}" -- "${@}")" + TEMP="$(getopt -o aAbcefhimpr:suvxV --long ask,alert,snapshot-backup,clean,easy-setup,copy-from-staging,help,is-new-kernel-available,menuconfig,postclear,adjustment:,stage-only,verbose,unmount-at-end,rebuild-external-modules,version -n "${PROGNAME}" -- "${@}")" RC="${?}" set -e if ((RC!=0)); then @@ -2040,6 +2049,11 @@ process_command_line_options() { -i|--is-new-kernel-available) ARG_IS_NEW_KERNEL_AVAILABLE=1 ; shift ;; -m|--menuconfig) ARG_MENUCONFIG=1 ; shift ;; -p|--postclear) ARG_POSTCLEAR=1 ; shift ;; + -r|--adjustment) + case "${2}" in + "") shift 2 ;; + *) ADJUSTMENT="${2}" ; shift 2 ;; + esac ;; -s|--stage-only) ARG_STAGEONLY=1 ; shift ;; -u|--unmount-at-end) ARG_UNMOUNTATEND=1 ; shift ;; -v|--verbose) ARG_VERBOSE=1 ; shift ;; @@ -2049,6 +2063,8 @@ process_command_line_options() { *) die "Internal error!" ;; esac done + # setup make with specified niceness + MAKE="nice -n ${ADJUSTMENT} make" # set verbosity if ((ARG_VERBOSE==1)); then VERBOSITY+=1 diff --git a/buildkernel.8 b/buildkernel.8 index 21f8313..be047ab 100644 --- a/buildkernel.8 +++ b/buildkernel.8 @@ -1,4 +1,4 @@ -.TH BUILDKERNEL 8 "Version 1.0.17: May 2016" +.TH BUILDKERNEL 8 "Version 1.0.18: January 2017" .SH NAME buildkernel \- build secure boot kernel, save to EFI system partition .SH SYNOPSIS @@ -146,6 +146,15 @@ b) in interactive move, ask you whether or not you wish to \fBmake menuconfig\fR .BR \-p ", " \-\-postclear Clears all \fBgenkernel\fR(8) temporary files and caches after run. .TP +.BR \-r ", " \-\-adjustment\=N +Specifies the \fBnice\fR(1) adjustment value N (-20<=N<=19) under which +to run \fBmake\fR(1) operations. + +If this option is unspecified, the default niceness adjustment value is 19, +which causes invoked makes to run at the lowest possible +priority; this is useful to prevent \fBbuildkernel\fR clogging up your +system. Be careful about using negative values! +.TP .BR \-s ", " \-\-stage\-only When this option is specified, \fBbuildkernel\fR will create the kernel in the \fI/boot\fR staging directory as usual, but will not copy the result across @@ -231,7 +240,7 @@ A post-reboot run of \fBgenup\fR(8) will achieve this. .SH COPYRIGHT .nf -Copyright \(co 2014-2016 sakaki +Copyright \(co 2014-2017 sakaki License GPLv3+ (GNU GPL version 3 or later) @@ -244,6 +253,7 @@ sakaki \(em send bug reports or comments to .BR emerge (1), .BR gpg (1), .BR make (1), +.BR nice (1), .BR systemd (1), .BR cryptsetup (8), .BR genkernel (8), diff --git a/buildkernel.conf.5 b/buildkernel.conf.5 index d372319..a57f7b7 100644 --- a/buildkernel.conf.5 +++ b/buildkernel.conf.5 @@ -1,4 +1,4 @@ -.TH BUILDKERNEL 5 "Version 1.0.17: May 2016" +.TH BUILDKERNEL 5 "Version 1.0.18: January 2017" .SH NAME buildkernel.conf \- a configuration file for \fBbuildkernel\fR(8) .SH SYNOPSIS @@ -173,7 +173,7 @@ function exit. .RE .SH COPYRIGHT .nf -Copyright \(co 2014-2016 sakaki +Copyright \(co 2014-2017 sakaki License GPLv3+ (GNU GPL version 3 or later)