From e81997ce9c067547631309e44ede4780468f9a66 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 30 Oct 2026 11:31:31 +0000 Subject: [PATCH 1/2] Fix measurement-window docs and honour SPARK_GB10_LOCK The documented open used the default GPU lock, which spark-baseline refuses. The quiet-build README claimed builds never wait and run on pinned cores; the script waits up to 25 minutes, then runs at nice 19 with no pinning. The README now lists test-spark-window-starve.sh. spark-baseline and spark-calibrate read SPARK_GB10_LOCK, defaulting to /tmp/aien-gb10.lock. Add tools/ops/SHA256SUMS for every script in that directory. Refs #354 Co-authored-by: Drake Stapleton --- docs/ops/MEASUREMENT_WINDOWS.md | 18 +++++++++++------- tools/ops/README.md | 5 ++++- tools/ops/SHA256SUMS | 9 +++++++++ tools/ops/spark-baseline | 3 ++- tools/ops/spark-calibrate | 7 ++++--- 5 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 tools/ops/SHA256SUMS diff --git a/docs/ops/MEASUREMENT_WINDOWS.md b/docs/ops/MEASUREMENT_WINDOWS.md index 3b1a8ca..b844089 100644 --- a/docs/ops/MEASUREMENT_WINDOWS.md +++ b/docs/ops/MEASUREMENT_WINDOWS.md @@ -44,17 +44,21 @@ the window is marked "shared machine" (L405). ## Exact commands -Open a window (waits its turn; prints the window id when it holds the box): +Open a window that will run the commands below, including `spark-baseline` (waits its turn; prints the +window id when it holds the box). `spark-baseline` refuses a window that holds the GPU lock, so this +open passes `--gb10 none`: ```sh -id=$(spark-window open my-measurement --ledger L109 --lease 20 --wait) +id=$(spark-window open my-measurement --ledger L109 --lease 20 --gb10 none --wait) ``` -By default the window also holds the GPU lock (`--gb10 exclusive`, added by L154), so GPU-only jobs -cannot run inside it. The 27B server takes that lock itself for every reply, so a window that measures -the 27B server, including `spark-baseline`, must be opened with `--gb10 none`; `spark-baseline` refuses -otherwise. `spark-calibrate` works in both: it uses the window's GPU lock when the window holds it and -takes the lock itself when it does not. +By default `open` holds the GPU lock (`--gb10 exclusive`, added by L154), so GPU-only jobs cannot run +inside it. The 27B server takes that lock itself for every reply, so a window that measures the 27B +server, including `spark-baseline`, must be opened with `--gb10 none`; `spark-baseline` refuses +otherwise. A window that does not measure the 27B can leave that default and skip `spark-baseline`. +To hold the GPU lock for other work and still take a 27B baseline, use two windows: the default for +the GPU-holding work, and `--gb10 none` for `spark-baseline`. `spark-calibrate` works in both: it +uses the window's GPU lock when the window holds it and takes the lock itself when it does not. Calibrate and take the baseline inside it: diff --git a/tools/ops/README.md b/tools/ops/README.md index 71bb46a..caa59a7 100644 --- a/tools/ops/README.md +++ b/tools/ops/README.md @@ -9,11 +9,14 @@ 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 ` | | `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 L189 test: a window still opens while shared quiet holders run back to back, and it waits out a busy chip lock before opening. Scratch locks and window root only | | `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` | Builds: since 2026-10-20 (Drake, L118) they never wait; they run on the efficient cores at low priority and are logged for overlap checks. Copy of the installed version | +| `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`. 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 new file mode 100644 index 0000000..b8b9c2e --- /dev/null +++ b/tools/ops/SHA256SUMS @@ -0,0 +1,9 @@ +b8b40d2c1221d6067a49cebd288fcf0b8fb34c616562f58569385d81de62d8dc quiet-build +c838569e1a940e904bc226bcbb192fdf013d0b70913325d3e5af3cdb93ab6b67 quiet-measure +fd4cd473f4e118a7cce5805fc0e2acdb771569aa31c1cad9c3f5ab0c3a173238 spark-baseline +f271b0ae027c35e855d855a528fa61d0f4e6f11dc44c390da2754623d129db46 spark-build-once +cc1f38a67b9e0a87d049351900ff8499405e8f933f446559ada9bad286fe5d35 spark-calibrate +aca797f0d7fa228452712c56a32530865c9c8b7c1d9448fc8ded15b44a39468c spark-receipt +01ac196e3e0fdcf7c2a69706ab0b6ca813af1bf67a4b56599fb65c351169fe14 spark-window +dce3d2986b84d678afd8c314bde3a068c26ec53f10edce8fabd6cda1df3c95a8 test-spark-window-starve.sh +5e744cad81dc823c488f3b330b3c04ead6a62ad806c3ca8b379a334ff82c79d8 test_spark_window_close.sh diff --git a/tools/ops/spark-baseline b/tools/ops/spark-baseline index 36d9c20..26a8c46 100755 --- a/tools/ops/spark-baseline +++ b/tools/ops/spark-baseline @@ -45,7 +45,8 @@ case $models in *"\"$mid\""*) ;; *) echo "spark-baseline: server on :$port does # from the first to the last token the server holds the GPU lock for us, which makes the decode # 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. -G=/tmp/aien-gb10.lock; gino=$(stat -c %i "$G") +# Sample the lock spark-window uses: SPARK_GB10_LOCK, default /tmp/aien-gb10.lock. +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/spark-calibrate b/tools/ops/spark-calibrate index c8f3b52..b44c1fc 100755 --- a/tools/ops/spark-calibrate +++ b/tools/ops/spark-calibrate @@ -2,8 +2,9 @@ # spark-calibrate: the one calibration file of a measurement window. # # Run inside an open window (spark-window run spark-calibrate, or with -# SPARK_WINDOW set). Holding /tmp/aien-gb10.lock (waits for it, printing the -# holders every 60 s), it measures: +# SPARK_WINDOW set). It holds the GPU lock (default /tmp/aien-gb10.lock; +# SPARK_GB10_LOCK overrides it, same as the other scripts), waits for it, and +# prints the holders every 60 s. It measures: # 1. CPU memory bandwidth with the omega#583 memcpy probe (pinned source # omega research/cost-sim-583@3bd56731 tools/dagsim/memcpy_probe.c), the # same call research/583 used: nice -n 10 memcpy_probe 1 K 10, K = 1 and 8. @@ -19,7 +20,7 @@ id=${SPARK_WINDOW:-$(spark-window id)} || { echo "spark-calibrate: no open windo held() { [ "$(cat "$WR/OPEN" 2>/dev/null)" = "$id" ] && [ -f "$WR/$id/held" ] && [ ! -f "$WR/$id/expired" ] && kill -0 "$(cat "$WR/$id/holder.pid" 2>/dev/null)" 2>/dev/null; } d=$WR/$id; mkdir -p "$d/calibration" export SPARK_WINDOW=$id SPARK_WINDOW_DIR=$d -G=/tmp/aien-gb10.lock +G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock} # the probe, built once per source blob + flags REPO=${OMEGA_REPO:-$HOME/workspace/omega}; PIN=3bd56731c5517e2a9c8f195955c71e73dc6f9269; SRC=tools/dagsim/memcpy_probe.c From 77c27b1cc545a55ffe7886d1e3012ff0be489cf1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 30 Oct 2026 11:44:13 +0000 Subject: [PATCH 2/2] Make the starve-test gate case deterministic Case 3's shared holders take SPARK_QUIET_GATE before the quiet lock, the same order as quiet-build, so the L322 drain can finish. The plain flock -s pair is case 5, labeled known-starvable, and runs only when SPARK_STARVE_PLAIN=1. The README row describes that gated proof and the plain-flock limit. The spark-baseline sampler comment names the GPU lock without a hard-coded path. SPARK_GB10_LOCK reads say they are for tests only (see spark-window:63). SHA256SUMS covers the changed scripts. spark-window is untouched. Refs #354 Co-authored-by: Drake Stapleton --- tools/ops/README.md | 2 +- tools/ops/SHA256SUMS | 6 ++-- tools/ops/spark-baseline | 6 ++-- tools/ops/spark-calibrate | 6 ++-- tools/ops/test-spark-window-starve.sh | 47 +++++++++++++++++++-------- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/tools/ops/README.md b/tools/ops/README.md index caa59a7..c322a42 100644 --- a/tools/ops/README.md +++ b/tools/ops/README.md @@ -9,7 +9,7 @@ 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 ` | | `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 L189 test: a window still opens while shared quiet holders run back to back, and it waits out a busy chip lock before opening. Scratch locks and window root only | +| `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` | | `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` | diff --git a/tools/ops/SHA256SUMS b/tools/ops/SHA256SUMS index b8b9c2e..07dc0f0 100644 --- a/tools/ops/SHA256SUMS +++ b/tools/ops/SHA256SUMS @@ -1,9 +1,9 @@ b8b40d2c1221d6067a49cebd288fcf0b8fb34c616562f58569385d81de62d8dc quiet-build c838569e1a940e904bc226bcbb192fdf013d0b70913325d3e5af3cdb93ab6b67 quiet-measure -fd4cd473f4e118a7cce5805fc0e2acdb771569aa31c1cad9c3f5ab0c3a173238 spark-baseline +925e55b6348ba8de23c863cc7476735eda6d1bb43c953b16e1fac04cc565c42a spark-baseline f271b0ae027c35e855d855a528fa61d0f4e6f11dc44c390da2754623d129db46 spark-build-once -cc1f38a67b9e0a87d049351900ff8499405e8f933f446559ada9bad286fe5d35 spark-calibrate +09c45c5a664a3ca1dba3a083cbbcd16d643f114345952868b13c5bafe7e9c40b spark-calibrate aca797f0d7fa228452712c56a32530865c9c8b7c1d9448fc8ded15b44a39468c spark-receipt 01ac196e3e0fdcf7c2a69706ab0b6ca813af1bf67a4b56599fb65c351169fe14 spark-window -dce3d2986b84d678afd8c314bde3a068c26ec53f10edce8fabd6cda1df3c95a8 test-spark-window-starve.sh +b33a7df6e31ae75816a1d1c733750d0d18edb69bf6f4aa4f6bc9f1cd6870085b test-spark-window-starve.sh 5e744cad81dc823c488f3b330b3c04ead6a62ad806c3ca8b379a334ff82c79d8 test_spark_window_close.sh diff --git a/tools/ops/spark-baseline b/tools/ops/spark-baseline index 26a8c46..40ba191 100755 --- a/tools/ops/spark-baseline +++ b/tools/ops/spark-baseline @@ -40,13 +40,13 @@ sexe=$(readlink "/proc/$spid/exe" 2>/dev/null); sargs=$(tr '\0' ' ' < "/proc/$sp models=$(curl -s --max-time 10 "http://127.0.0.1:$port/v1/models") case $models in *"\"$mid\""*) ;; *) echo "spark-baseline: server on :$port does not serve $mid: $models" >&2; exit 1 ;; esac -# The server takes /tmp/aien-gb10.lock itself for each generation (holding it here would deadlock), +# The server takes the GPU lock itself for each generation (holding it here would deadlock), # and GPU-only jobs keep that lock busy. So the reply is streamed and every chunk is timestamped: # from the first to the last token the server holds the GPU lock for us, which makes the decode # 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, default /tmp/aien-gb10.lock. -G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}; gino=$(stat -c %i "$G") +# 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) 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/spark-calibrate b/tools/ops/spark-calibrate index b44c1fc..fe5c257 100755 --- a/tools/ops/spark-calibrate +++ b/tools/ops/spark-calibrate @@ -3,8 +3,8 @@ # # Run inside an open window (spark-window run spark-calibrate, or with # SPARK_WINDOW set). It holds the GPU lock (default /tmp/aien-gb10.lock; -# SPARK_GB10_LOCK overrides it, same as the other scripts), waits for it, and -# prints the holders every 60 s. It measures: +# SPARK_GB10_LOCK overrides it, for tests only (see spark-window:63)), waits +# for it, and prints the holders every 60 s. It measures: # 1. CPU memory bandwidth with the omega#583 memcpy probe (pinned source # omega research/cost-sim-583@3bd56731 tools/dagsim/memcpy_probe.c), the # same call research/583 used: nice -n 10 memcpy_probe 1 K 10, K = 1 and 8. @@ -20,7 +20,7 @@ id=${SPARK_WINDOW:-$(spark-window id)} || { echo "spark-calibrate: no open windo held() { [ "$(cat "$WR/OPEN" 2>/dev/null)" = "$id" ] && [ -f "$WR/$id/held" ] && [ ! -f "$WR/$id/expired" ] && kill -0 "$(cat "$WR/$id/holder.pid" 2>/dev/null)" 2>/dev/null; } d=$WR/$id; mkdir -p "$d/calibration" export SPARK_WINDOW=$id SPARK_WINDOW_DIR=$d -G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock} +G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock} # SPARK_GB10_LOCK is for tests only (see spark-window:63) # the probe, built once per source blob + flags REPO=${OMEGA_REPO:-$HOME/workspace/omega}; PIN=3bd56731c5517e2a9c8f195955c71e73dc6f9269; SRC=tools/dagsim/memcpy_probe.c diff --git a/tools/ops/test-spark-window-starve.sh b/tools/ops/test-spark-window-starve.sh index 8d4cd86..1a913b2 100755 --- a/tools/ops/test-spark-window-starve.sh +++ b/tools/ops/test-spark-window-starve.sh @@ -1,11 +1,18 @@ #!/bin/sh -# test-spark-window-starve.sh [SCRIPT]: L189 regression test for spark-window _hold. -# A window must open even while the quiet lock is held shared by one holder after another -# (builds and tests in turn) and while the chip lock is free. Uses only temp lock files and a -# temp window root; never touches /tmp/aien-quiet.lock or /tmp/aien-gb10.lock. +# test-spark-window-starve.sh [SCRIPT]: regression test for spark-window _hold. +# 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 (shared quiet holders back to back, short gaps): opens within LIMIT seconds. -# Exit 0 = all pass. Pass an older script path to see it fail (red). +# 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 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. +# 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} T=$(mktemp -d /tmp/spark-window-starve.XXXXXX) @@ -14,6 +21,7 @@ export SPARK_WINDOWS_ROOT=$T/win SPARK_QUIET_LOCK=$T/quiet.lock SPARK_GB10_LOCK= # these temp locks have no other users, so the real machine load says nothing about them. export SPARK_QUIET_GATE=$T/quiet.gate SPARK_QUIET_WANT=$T/want.d SPARK_BOARD=$T/BOARD.md SPARK_IDLE_LOAD=100000 : > "$SPARK_QUIET_LOCK"; : > "$SPARK_GB10_LOCK" +: > "$SPARK_QUIET_GATE" pids="" cleanup() { for p in $pids; do kill "$p" 2>/dev/null; done; for h in "$T"/win/*/holder.pid; do [ -f "$h" ] && kill -- -"$(cat "$h")" 2>/dev/null; done; sleep 0.5; rm -rf "$T"; } trap cleanup EXIT @@ -29,9 +37,15 @@ close_it() { "$S" close "$(cat "$SPARK_WINDOWS_ROOT/OPEN" 2>/dev/null)" > /dev/n if opens_within plain 10; then echo "PASS case 1: no contention opens"; close_it; else echo "FAIL case 1: no contention did not open"; fail=1; close_it; fi -# Shared quiet holders back to back, like builds and tests in turn. A waiting exclusive lock can only -# be won in a gap; the old _hold let it go again at once and almost never won it a second time. -stream() { # SECONDS GAP: one shared holder after another, forever +# Shared holders, one after another. SECONDS is how long each hold lasts; GAP is the pause after it. +# gated: quiet-build order. Pass $SPARK_QUIET_GATE shared, then hold the quiet lock shared. +# spark-window holds that gate exclusive while it drains (L322), so the next iteration waits +# outside and does not take the quiet lock. The holders already inside finish, then the window wins. +# plain: flock -s on the quiet lock only, no gate. Two of these can starve an exclusive waiter. +stream_gated() { # SECONDS GAP + ( while :; do flock -s "$SPARK_QUIET_GATE" true; flock -s "$SPARK_QUIET_LOCK" sleep "$1"; sleep "$2"; done ) & pids="$pids $!" +} +stream_plain() { # SECONDS GAP ( while :; do flock -s "$SPARK_QUIET_LOCK" sleep "$1"; sleep "$2"; done ) & pids="$pids $!" } stop_streams() { for p in $pids; do kill "$p" 2>/dev/null; done; pids=""; sleep 1.2; } @@ -40,12 +54,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 1.0 0 +stream_plain 1.0 0 case_run "case 2 one holder, no pause between holders" -stream 0.9 0; stream 0.6 0 -case_run "case 3 two holders, no pause between holders" +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 1.0 0 +stream_plain 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 @@ -54,4 +68,11 @@ 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. +if [ "${SPARK_STARVE_PLAIN:-}" = 1 ]; then + 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 5 known-starvable: two plain flock -s holders, no gate (set SPARK_STARVE_PLAIN=1 to run)" +fi exit $fail