Skip to content

Commit

Permalink
Add ability to set niceness for make.
Browse files Browse the repository at this point in the history
Default niceness adjustment set to +19, to avoid buildkernel clogging
up the system.
  • Loading branch information
sakaki- committed Jan 17, 2017
1 parent 3a32319 commit 30d2b57
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
38 changes: 27 additions & 11 deletions buildkernel
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
# Copyright (c) 2014-2017 sakaki <[email protected]>
#
# License (GPL v3.0)
# ------------------
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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-")
Expand All @@ -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
Expand All @@ -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 ;;
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions buildkernel.8
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
<http://gnu.org/licenses/gpl.html>

Expand All @@ -244,6 +253,7 @@ sakaki \(em send bug reports or comments to <[email protected]>
.BR emerge (1),
.BR gpg (1),
.BR make (1),
.BR nice (1),
.BR systemd (1),
.BR cryptsetup (8),
.BR genkernel (8),
Expand Down
4 changes: 2 additions & 2 deletions buildkernel.conf.5
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
<http://gnu.org/licenses/gpl.html>

Expand Down

0 comments on commit 30d2b57

Please sign in to comment.