Skip to content

Commit

Permalink
Merge pull request #1407 from citrus-it/buildctl
Browse files Browse the repository at this point in the history
buildctl would never find enough expensive slots at end of run
  • Loading branch information
oetiker authored Feb 15, 2024
2 parents cd4604e + 8036aa0 commit e92fa6b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
49 changes: 30 additions & 19 deletions build/buildctl
Original file line number Diff line number Diff line change
Expand Up @@ -465,30 +465,28 @@ clear_slots() {

nextslot=
wait_for_slot() {
# Check for any idle slots
for i in `seq 0 $threads`; do
[ -z "${slots[$i]}" ] && nextslot=$i && return
done

typeset slot=
typeset -i stat=0
typeset slot=
typeset pid=

# Wait for a slot to terminate
while :; do
wait -fn -p pid ${slots[*]}
stat=$?
(( stat == 169 )) && continue # SIGINFO
(( stat == 141 )) && continue # SIGPIPE
(( stat == 144 )) && nextslot= && return # SIGUSR1
if (( stat == 127 )); then # No jobs left
clear_slots $stat
nextslot=0
return
fi
case $stat in
169) continue ;; # SIGINFO
141) continue ;; # SIGPIPE
144) nextslot=; return ;; # SIGUSR1
127) # No jobs left
clear_slots $stat
nextslot=0
return ;;
esac

[ -n "$pid" ] || continue
slot=${slotpid[$pid]}
[ -n "$slot" ] && break
logmsg -n "Unknown pid $pid terminated $s"
logmsg -n "Unknown pid $pid terminated $stat"
done

if reap_slot $slot $stat; then
Expand All @@ -500,6 +498,21 @@ wait_for_slot() {
fi
}

find_slot() {
# Check for any idle slots
for i in `seq 0 $threads`; do
[ -z "${slots[$i]}" ] && nextslot=$i && return
done

wait_for_slot
}

wait_for_expensive_slot() {
while (( `count_expensive` > ETHROTTLE )); do
wait_for_slot
done
}

wait_for_jobs() {
local msg="$1"

Expand Down Expand Up @@ -676,9 +689,7 @@ parallel_build() {
# number of expensive jobs has dropped low enough.
if [ $newloc -le 0 -o ${#queue[@]} -le ${#expensive[@]} ]; then
logmsg -n "-- $tgt, waiting for number of jobs to drop"
while [ `count_expensive` -gt $ETHROTTLE ]; do
wait_for_slot
done
wait_for_expensive_slot
else
logmsg -n "-- $tgt, relocating to $newloc/${#queue[@]}"
_queue=("${queue[@]:0:newloc}")
Expand All @@ -694,7 +705,7 @@ parallel_build() {

if [ -z "$nextslot" ]; then
logmsg "-- Waiting for spare job slot for $tgt"
wait_for_slot
find_slot
[ -n "$nextslot" ] || break
fi

Expand Down
19 changes: 16 additions & 3 deletions lib/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1321,11 +1321,24 @@ patch_source() {
# $1 - resource to get
#
get_resource() {
local RESOURCE=$1
case ${MIRROR:0:1} in
/) logcmd $CP $MIRROR/$RESOURCE . ;;
typeset RESOURCE="$1"

if [ -n "$MIRRORCACHE" -a -f "$MIRRORCACHE/$RESOURCE" ]; then
logcmd $CP $MIRRORCACHE/$RESOURCE . && return
fi

case $MIRROR in
/*) logcmd $CP $MIRROR/$RESOURCE . ;;
*) $WGET -a $LOGFILE $MIRROR/$RESOURCE ;;
esac
typeset -i stat=$?

if ((stat == 0)) && [ -n "$MIRRORCACHE" ]; then
logcmd $MKDIR -p $MIRRORCACHE/${RESOURCE%/*}
logcmd $CP ${RESOURCE##*/} $MIRRORCACHE/${RESOURCE%/*}
fi

return $stat
}

set_checksum() {
Expand Down
4 changes: 4 additions & 0 deletions lib/site.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# The web server or local directory from which source files are fetched.
#MIRROR=https://mirrors.omnios.org

# A directory used to cache files downloaded from the $MIRROR for use in
# subsequent builds.
#MIRRORCACHE=/tmp/mirror.cache

# Package publisher
#PKGPUBLISHER=extra.omnios

Expand Down

0 comments on commit e92fa6b

Please sign in to comment.