aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / tools / ops / quiet-lock-order / quiet-measure.pre-L217
| 1 | #!/bin/sh |
| 2 | # 2026-10-20: commands are pinned to the X925 cores; old copy quiet-measure.bak-20261020. |
| 3 | # quiet-measure CMD... Run a timing measurement with the box as quiet as possible. |
| 4 | # Raises a "wanted" flag so quiet-build stops starting new builds, then takes |
| 5 | # /tmp/aien-quiet.lock exclusive (waits for running builds to drain), after passing the gate |
| 6 | # /tmp/aien-quiet.gate (held by a window waiting at the front of the line; fail open after 25 min; L322). |
| 7 | # Plain flock alone starves measurements: new shared holders keep arriving. |
| 8 | # Inside a measurement window (SPARK_WINDOW set by spark-window run, and that |
| 9 | # window is the open one with a live holder) the lock is already held |
| 10 | # exclusive for us, so CMD runs directly instead of waiting on our own lock. |
| 11 | # L405: a measurement holding the lock past 25 min no longer stops builds; they run beside it and it warns. |
| 12 | # Fast cores for timing (Cortex-X925: 5-9,15-19); builds live on the A725 cores. Builds running at start are logged. |
| 13 | case "${1-}" in |
| 14 | ""|-h|--help|help) |
| 15 | sed -n '2,/^[^#]/{/^#/s/^# \{0,1\}//p}' "$0" |
| 16 | exit 0 ;; |
| 17 | -*) |
| 18 | echo "$(basename "$0"): unknown option '$1' (the first argument must be the command to run; try --help)" >&2 |
| 19 | exit 2 ;; |
| 20 | esac |
| 21 | L=$HOME/.local/state/quiet; mkdir -p "$L" |
| 22 | printf '%s builds_running=%s %s\n' "$(date -u +%FT%TZ)" "$(ls /tmp/aien-build.active.d 2>/dev/null | wc -l)" "$*" >> "$L/measure-overlap.log" |
| 23 | PIN="taskset -c 5-9,15-19" |
| 24 | if [ -n "${SPARK_WINDOW:-}" ]; then |
| 25 | WR=${SPARK_WINDOWS_ROOT:-$HOME/yardsticks/windows} |
| 26 | if [ "$(cat "$WR/OPEN" 2>/dev/null)" = "$SPARK_WINDOW" ] && [ -f "$WR/$SPARK_WINDOW/held" ] && |
| 27 | kill -0 "$(cat "$WR/$SPARK_WINDOW/holder.pid" 2>/dev/null)" 2>/dev/null; then |
| 28 | exec $PIN "$@" |
| 29 | fi |
| 30 | echo "quiet-measure: window $SPARK_WINDOW is not open and held; taking the quiet lock the normal way" >&2 |
| 31 | fi |
| 32 | W=${SPARK_QUIET_WANT:-/tmp/aien-quiet.want.d}; Q=${SPARK_QUIET_LOCK:-/tmp/aien-quiet.lock}; GATE=${SPARK_QUIET_GATE:-/tmp/aien-quiet.gate} |
| 33 | mkdir -p "$W" 2>/dev/null; chmod 1777 "$W" 2>/dev/null |
| 34 | f="$W/$$"; echo "$(date -u +%FT%TZ) $*" > "$f" |
| 35 | trap 'rm -f "$f"' EXIT INT TERM |
| 36 | [ -e "$GATE" ] || { : > "$GATE"; chmod 666 "$GATE"; } 2>/dev/null |
| 37 | flock -s -w "${SPARK_GATE_WAIT:-1500}" "$GATE" true 2>/dev/null # fail open |
| 38 | # L405: correctness jobs stop waiting after their cap (25 min) and run beside us; say so, so the numbers are labelled. |
| 39 | tsf="$W/.$$.held" |
| 40 | flock -x "$Q" sh -c 'date -u +%FT%TZ > "$0"; exec "$@"' "$tsf" $PIN "$@"; rc=$? |
| 41 | ts=$(cat "$tsf" 2>/dev/null); rm -f "$tsf" |
| 42 | n=$( [ -n "$ts" ] && awk -v t="$ts" '$1 >= t' "$L/intrusions.log" 2>/dev/null | wc -l || echo 0) |
| 43 | [ "${n:-0}" -gt 0 ] && echo "quiet-measure: $n correctness job(s) ran beside this measurement after waiting their cap; label its numbers 'shared machine' (L405)" >&2 |
| 44 | exit $rc |