aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
GitHub aien-dev/aien-architecture-mv#373 (code only)
Apply it
git checkout -b patch-d6744a83a860b68b 12e8c7de510f85c61ae8809a9b15467c51233783 curl -fsSL https://interplane.io/drakestapleton/aien-architecture-mv/patches/d6744a83a860b68b.patch | git am
Provenance
github-import 1
aien-dev/aien-architecture-mv
373
6920472a655df903ccebdf9de396d5ac4c130ce7
{"kind":"github-import","owner":"aien-dev","repo":"aien-architecture-mv","number":373,"url":"https://github.com/aien-dev/aien-architecture-mv/pull/373","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:04Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/tools/ops/README.md b/tools/ops/README.md index c322a42..6f15db7 100644 --- a/tools/ops/README.md +++ b/tools/ops/README.md @@ -9,14 +9,16 @@ How and when to use them: [docs/ops/MEASUREMENT_WINDOWS.md](../../docs/ops/MEASU | `spark-build-once` | Build cache keyed by the source tree, command and env knobs; concurrent callers build once | | `spark-window` | One measurement window at a time; holds the quiet lock exclusive; box state at open and close. A bare `close` only closes a window you opened (same shell tree, or `SPARK_WINDOW` set); otherwise refused with exit 3, use `close <ID>` | | `test_spark_window_close.sh` | Offline test for the close rule above (scratch locks and folder, never the live windows) | -| `test-spark-window-starve.sh` | Offline test, scratch locks and window root only. The gated case proves a window opens while two shared holders take `$SPARK_QUIET_GATE` and then the quiet lock, the quiet-build order, so the gate in spark-window (L322) keeps new holders out and the drain finishes. Plain `flock -s` skips that gate and can starve an exclusive waiter, because Linux flock gives the waiter no priority. That plain-flock case is labeled known-starvable and is skipped unless `SPARK_STARVE_PLAIN=1` | +| `test-spark-window-starve.sh` | Offline test, scratch locks and window root only. Case 1: no contention. Cases 2 and 3: one and two shared holders take `$SPARK_QUIET_GATE` and then the quiet lock, the quiet-build order, so the gate at `spark-window:330-336` keeps new holders out and the drain finishes. Case 4 (chip busy): with the chip lock held for 6 s, the window waits for the chip and opens only after it is free. Plain `flock -s` skips that gate: one plain holder leaves only a timing-dependent gap, and two can starve an exclusive waiter, because Linux flock gives the waiter no priority. Those plain-flock cases (2p, 5) are skipped unless `SPARK_STARVE_PLAIN=1` | | `spark-calibrate` | Per-window calibration: memcpy bandwidth (omega#583 probe) and 30 s idle power at the wall | | `spark-baseline` | Per-window 27B baseline: fixed 64-token streamed reply on 127.0.0.1:18091, decode tok/s and J/token | | `spark-receipt` | Energy receipt for any command; now stamps `window_id` and `calibration` | | `quiet-measure` | Exclusive quiet lock for a measurement; runs directly inside its own open window | | `quiet-build` | CPU-heavy jobs. Waits for a live measurement flag (at most 1 min), then the quiet gate, then a shared quiet lock. The whole wait is capped at 25 min (`SPARK_BUILD_MAX_WAIT`, default 1500 s). If the lock is acquired in time, the command runs as given. Past the cap it runs at nice 19, with no lock and no core pinning, and the open window is marked shared machine (L405). Waits are logged | -`SHA256SUMS` in this directory is the sha256 of each script. From `tools/ops`: `sha256sum -c SHA256SUMS`. +`SHA256SUMS` in this directory is the sha256 of each script. It lists bare file names, so check it from +`tools/ops`: from the repository root, `(cd tools/ops && sha256sum -c SHA256SUMS)`. To check the copies +installed on the Spark, run `(cd ~/.local/bin && sha256sum -c --ignore-missing <repo>/tools/ops/SHA256SUMS)`. Shown on the Spark (2026-10-19/20): two callers on one source built once in a scratch repo (the second reused the stored result), two windows opened at the same moment (one refused), lease expiry, the diff --git a/tools/ops/SHA256SUMS b/tools/ops/SHA256SUMS index 07dc0f0..672087f 100644 --- a/tools/ops/SHA256SUMS +++ b/tools/ops/SHA256SUMS @@ -1,9 +1,9 @@ b8b40d2c1221d6067a49cebd288fcf0b8fb34c616562f58569385d81de62d8dc quiet-build c838569e1a940e904bc226bcbb192fdf013d0b70913325d3e5af3cdb93ab6b67 quiet-measure -925e55b6348ba8de23c863cc7476735eda6d1bb43c953b16e1fac04cc565c42a spark-baseline +7eeab517e9d9ceffd69d5feafd9cd9bc29a33f88186ad8ec6af239adaaa54730 spark-baseline f271b0ae027c35e855d855a528fa61d0f4e6f11dc44c390da2754623d129db46 spark-build-once 09c45c5a664a3ca1dba3a083cbbcd16d643f114345952868b13c5bafe7e9c40b spark-calibrate aca797f0d7fa228452712c56a32530865c9c8b7c1d9448fc8ded15b44a39468c spark-receipt 01ac196e3e0fdcf7c2a69706ab0b6ca813af1bf67a4b56599fb65c351169fe14 spark-window -b33a7df6e31ae75816a1d1c733750d0d18edb69bf6f4aa4f6bc9f1cd6870085b test-spark-window-starve.sh +0596f315f62b8517e488b7e7c40b972068ad9ce794c221a3b6a7df0ec8fe7841 test-spark-window-starve.sh 5e744cad81dc823c488f3b330b3c04ead6a62ad806c3ca8b379a334ff82c79d8 test_spark_window_close.sh diff --git a/tools/ops/spark-baseline b/tools/ops/spark-baseline index 40ba191..cf5562e 100755 --- a/tools/ops/spark-baseline +++ b/tools/ops/spark-baseline @@ -46,7 +46,7 @@ case $models in *"\"$mid\""*) ;; *) echo "spark-baseline: server on :$port does # rate and its energy clean whatever the queue did before. The lock table is sampled throughout; # any other process seen holding the GPU lock during the decode marks the baseline not ok. # Sample the lock spark-window uses. SPARK_GB10_LOCK is for tests only (see spark-window:63). -G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}; gino=$(stat -c %i "$G") # SPARK_GB10_LOCK is for tests only (see spark-window:63) +G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}; gino=$(stat -c %i "$G") held || { echo "spark-baseline: window $id is not held; nothing measured" >&2; exit 1; } ( while :; do grep -E ":$gino " /proc/locks | sed "s/^/$(date +%s.%N) /"; sleep 0.5; done ) > "$b/gb10-during.txt" 2>/dev/null & smp=$! diff --git a/tools/ops/test-spark-window-starve.sh b/tools/ops/test-spark-window-starve.sh index 1a913b2..1f92b7d 100755 --- a/tools/ops/test-spark-window-starve.sh +++ b/tools/ops/test-spark-window-starve.sh @@ -3,15 +3,16 @@ # Uses only temp lock files and a temp window root; never touches /tmp/aien-quiet.lock # or /tmp/aien-gb10.lock. # case 1 (no contention): opens fast. -# case 2 (one shared holder, plain flock -s, no pause): opens within LIMIT seconds. -# One holder still leaves a gap, which is the L189 path. +# case 2 (one shared holder through $SPARK_QUIET_GATE, no pause): opens within LIMIT. +# Deterministic for the same reason as case 3: the gate keeps the holder's next turn out. # case 3 (two shared holders through $SPARK_QUIET_GATE, no pause): opens within LIMIT. -# Same order as quiet-build, so the gate at spark-window L322 keeps new holders out -# and the drain finishes. This is the case the default run treats as deterministic. -# case 4 (chip busy): waits for the chip, then opens. -# case 5 (two plain flock -s holders, no gate): known-starvable. Linux flock gives an -# exclusive waiter no priority, so two holders with no gap can starve the window. -# Skipped unless SPARK_STARVE_PLAIN=1. +# Same order as quiet-build, so the gate at spark-window:330-336 keeps new holders out +# and the drain finishes. +# case 4 (chip busy, one gated shared holder): waits for the chip, then opens. +# case 2p (one plain flock -s holder, no gate) and case 5 (two plain flock -s holders, +# no gate) run only with SPARK_STARVE_PLAIN=1. Linux flock gives an exclusive waiter no +# priority: one plain holder leaves only a process-start gap (the L189 path), so whether +# the window wins it depends on timing; two holders with no gap can starve the window. # Exit 0 = every case that ran passed (a skip is not a failure). Pass an older script path to see it fail (red). set -u S=${1:-$(dirname "$0")/spark-window}; LIMIT=${LIMIT:-60} @@ -54,12 +55,12 @@ case_run() { # LABEL: open under the running streams else echo "FAIL $1: no window in $LIMIT s under shared quiet holders back to back"; fail=1; fi close_it; stop_streams } -stream_plain 1.0 0 -case_run "case 2 one holder, no pause between holders" +stream_gated 1.0 0 +case_run "case 2 one holder through the quiet gate, no pause" stream_gated 0.9 0; stream_gated 0.6 0 case_run "case 3 two holders through the quiet gate, no pause" # chip busy too: the window must wait for the chip, then open once it is free (no deadlock, no early open) -stream_plain 1.0 0 +stream_gated 1.0 0 ( flock -x "$SPARK_GB10_LOCK" sleep 6 ) & pids="$pids $!"; sleep 0.5; t0=$(date +%s) # the open time comes from the window's own held file, not from when this loop noticed it (the poll is slow on a loaded box) if opens_within "case 4 chip busy 6 s" "$LIMIT"; then @@ -68,11 +69,14 @@ if opens_within "case 4 chip busy 6 s" "$LIMIT"; then else echo "FAIL case 4 chip busy 6 s: opened while the chip was held ($dt s)"; fail=1; fi else echo "FAIL case 4 chip busy 6 s: no window in $LIMIT s"; fail=1; fi close_it; stop_streams -# Two plain flock -s holders, no gate. Known-starvable: opt in with SPARK_STARVE_PLAIN=1. +# Plain flock -s holders, no gate: timing-dependent (one) or known-starvable (two). Opt in with SPARK_STARVE_PLAIN=1. if [ "${SPARK_STARVE_PLAIN:-}" = 1 ]; then + stream_plain 1.0 0 + case_run "case 2p timing-dependent: one plain flock -s holder, no gate" stream_plain 0.9 0; stream_plain 0.6 0 case_run "case 5 known-starvable: two plain flock -s holders, no gate" else + echo "SKIP case 2p timing-dependent: one plain flock -s holder, no gate (set SPARK_STARVE_PLAIN=1 to run)" echo "SKIP case 5 known-starvable: two plain flock -s holders, no gate (set SPARK_STARVE_PLAIN=1 to run)" fi exit $fail