|
36 | 36 |
|
37 | 37 | SHIM=$(mktemp -d) |
38 | 38 | LOG="$SHIM/podman.log" |
39 | | -trap 'rm -rf "$SHIM"' EXIT 0 |
| 39 | +RUN=$(mktemp -d) |
| 40 | +trap 'rm -rf "$SHIM" "$RUN"' EXIT 0 |
40 | 41 |
|
41 | 42 | # The four tools the contract allows. git is real: bin/sdlc genuinely asks git |
42 | 43 | # where the repo root and the hooks are, and that is allowed. |
@@ -164,14 +165,64 @@ else |
164 | 165 | bad "a host step's word was evaluated as shell" |
165 | 166 | fi |
166 | 167 |
|
| 168 | +printf '\n== the CPU budget\n\n' |
| 169 | + |
| 170 | +# Halving the machine protects the person at the keyboard. Two cases have no |
| 171 | +# such person, and halving them throws away half a machine -- which is what |
| 172 | +# made lanes a REGRESSION on a 4-vCPU GitHub runner: budget 2, two lanes at 1 |
| 173 | +# each, and trentina's `sdlc ci` went from 15m27s to 24m38s. |
| 174 | +BUDGET="$RUN/budget.sh" |
| 175 | +# shellcheck disable=SC2016 |
| 176 | +# Deliberate throughout this block: the sed patterns match literal `$_best` |
| 177 | +# in bin/sdlc, and the echoed line must reach the generated script as source |
| 178 | +# rather than be expanded here. |
| 179 | +{ |
| 180 | + echo 'set -eu' |
| 181 | + echo 'die() { echo "$*" >&2; exit 2; }' |
| 182 | + sed -n '/^_cpus_in_list()/,/^}$/p' bin/sdlc |
| 183 | + sed -n '/^_cgroup_cpu_ceiling()/,/^ printf .%s. "$_best"$/p' bin/sdlc |
| 184 | + echo '}' |
| 185 | + sed -n '/^budget()/,/^}$/p' bin/sdlc |
| 186 | + echo 'printf "%s" "$(budget)"' |
| 187 | +} > "$BUDGET" |
| 188 | + |
| 189 | +machine=$(nproc --all 2>/dev/null || nproc) |
| 190 | +half=$((machine / 2)) |
| 191 | +[ "$half" -lt 1 ] && half=1 |
| 192 | + |
| 193 | +got=$(env -u CI sh "$BUDGET") |
| 194 | +if [ "$got" = "$half" ]; then |
| 195 | + ok "a developer machine still gets half of it ($got of $machine)" |
| 196 | +else |
| 197 | + bad "an unconstrained machine budgeted $got, want $half of $machine" |
| 198 | +fi |
| 199 | + |
| 200 | +got=$(CI=true sh "$BUDGET") |
| 201 | +if [ "$got" = "$machine" ]; then |
| 202 | + ok "CI gets the whole machine, having no desktop to protect ($got)" |
| 203 | +else |
| 204 | + bad "CI budgeted $got, want all $machine" |
| 205 | +fi |
| 206 | + |
| 207 | +# A cpuset is the case the first version of this missed: `nproc` is already |
| 208 | +# narrowed by it, so comparing the allowance against nproc found nothing. |
| 209 | +if command -v taskset >/dev/null 2>&1 && [ "$machine" -ge 2 ]; then |
| 210 | + got=$(env -u CI taskset -c 0-1 sh "$BUDGET") |
| 211 | + if [ "$got" = 2 ]; then |
| 212 | + ok "a cpuset is someone else's decision, so it is taken whole ($got)" |
| 213 | + else |
| 214 | + bad "a 2-CPU cpuset budgeted $got, want 2" |
| 215 | + fi |
| 216 | +else |
| 217 | + printf 'skip taskset unavailable or too few CPUs\n' |
| 218 | +fi |
| 219 | + |
167 | 220 | printf '\n== the lanes\n\n' |
168 | 221 |
|
169 | 222 | # Steps of one lane run in sequence; lanes run at the same time. What has to |
170 | 223 | # hold is not the speed -- it is that the answer and the log do not depend on |
171 | 224 | # which lane happened to finish first. |
172 | 225 |
|
173 | | -RUN=$(mktemp -d) |
174 | | -trap 'rm -rf "$SHIM" "$RUN"' EXIT 0 |
175 | 226 |
|
176 | 227 | lanes() { # target [stall-seconds] -> exit status, output in $RUN/out |
177 | 228 | rm -f "$SHIM/must-not-run" |
|
0 commit comments