Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-architecture-mv/patches/c7c2cfc8abbbce15 # aien-architecture-mv Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## Fix measurement-window docs, GB10 lock path, and script hashes merged `c7c2cfc8abbbce15` #356 · opened 2026-10-30 11:32 UTC · closed 2026-10-30 11:48 UTC · merged 2026-10-30 11:48 UTC Imported from GitHub aien-dev/aien-architecture-mv#356, by drakestapleton Base `a0a7146f198613c1df3e6ddc96a8582f95c0d95d` · Head `77c27b1cc545a55ffe7886d1e3012ff0be489cf1` Merged on GitHub as `0dcaa29d540a9c70aab2c9a68f84b5ae201adf2c`; reachable from main `bccab5ea7a17be6c9ab30b1bd05db4898a4601be` (observed 2026-11-18T16:37:27Z) drakestapleton wrote on 2026-10-30 11:32 UTC ## Issue-first tracking Tracking issue: Refs #354 Gates advanced and status: Findings 2–5 and `tools/ops/SHA256SUMS` stay in this PR. ArchReview review `5711650598` is addressed in `77c27b1cc545a55ffe7886d1e3012ff0be489cf1`. Finding 1's installed-copy check is NOT_RUN (out of scope). Offline close test PASS. Starve test cases 1–4 PASS, case 5 SKIP. `spark-baseline` and `spark-calibrate` full runs NOT_RUN. Source, test and qualification evidence: head `77c27b1cc545a55ffe7886d1e3012ff0be489cf1`. Commands and results below. - Implementation issue exists and its scope/ownership is current. - This PR documents remaining unrun/failed gates. - Issue ledger will be reconciled when this PR merges. Refs #354 ## What changed ### Finding 2 `docs/ops/MEASUREMENT_WINDOWS.md` opened the example window with the default `--gb10 exclusive`, then ran `spark-baseline`, which refuses that lock (it exits when the window's `gb10` file is `exclusive` or `shared`). The example now opens with `--gb10 none`, so the calibrate and baseline commands under it can run. The default is still documented. A window that does not measure the 27B can keep it. Holding the GPU lock and taking a 27B baseline means two windows. ### Finding 3 `tools/ops/README.md` said `quiet-build` never waits and runs on the efficient cores. The script waits for a live measurement flag (at most 1 minute), then the quiet gate, then a shared quiet lock. The whole wait is capped at 25 minutes (`SPARK_BUILD_MAX_WAIT`, default 1500 s). If it gets the lock in time, it runs the command as given. Past the cap it runs at nice 19, with no lock and no core pinning, and records an intrusion so the open window is "shared machine" (L405). The README now says that. `quiet-build` is unchanged. ### Finding 4 The README table includes `test-spark-window-starve.sh`. The row now states what the gated case proves, and the plain-flock starvation limit. See the review section. ### Finding 5 `spark-calibrate` and `spark-baseline` read `${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}`, the same default as `spark-window`. Those reads are marked for tests only (see spark-window:63). The sampler comment in `spark-baseline` names the GPU lock and does not name the old hard-coded path. ### Hash manifest `tools/ops/SHA256SUMS` lists the sha256 of every script in `tools/ops`. From that directory, `sha256sum -c SHA256SUMS` checks them. The names are bare, so the check is run from `tools/ops`, as the README says. `spark-window` is unchanged. Main hash and this PR's hash are the same: `01ac196e3e0fdcf7c2a69706ab0b6ca813af1bf67a4b56599fb65c351169fe14` Scripts this PR changes: script main this PR `spark-baseline` `9386d7940bcb8a115c3d09c344cd30e815af799e4f7250e0aa07b595c64cb231` `925e55b6348ba8de23c863cc7476735eda6d1bb43c953b16e1fac04cc565c42a` `spark-calibrate` `8d5c8b2f58b7cd5e66cfcd93916e539b22c1b9f73d2948df8e3148bb1e176b4b` `09c45c5a664a3ca1dba3a083cbbcd16d643f114345952868b13c5bafe7e9c40b` `test-spark-window-starve.sh` `dce3d2986b84d678afd8c314bde3a068c26ec53f10edce8fabd6cda1df3c95a8` `b33a7df6e31ae75816a1d1c733750d0d18edb69bf6f4aa4f6bc9f1cd6870085b` ### Finding 1 The copy of `spark-window` installed on the Spark was not compared to `01ac196e3e0fdcf7…`. Not done here. ## Review `5711650598` Case 3's two shared holders now take `$SPARK_QUIET_GATE` shared and then the quiet lock, the quiet-build order (`flock -s "$SPARK_QUIET_GATE" true` then `flock -s "$SPARK_QUIET_LOCK" sleep …`). With the gate up, the next iteration waits outside, the holders already inside finish, and the drain completes. A separate probe of that shape saw phase `chip held, gate up, draining the quiet lock for at most 300s (try 1)` and then `holding`. The old two-holder plain `flock -s` scenario is case 5, labeled known-starvable. Linux flock gives an exclusive waiter no priority, so that case can starve. It is skipped unless `SPARK_STARVE_PLAIN=1`. ## Tests Host: 4 CPUs, not the Spark, no GB10. - `sh -n tools/ops/test-spark-window-starve.sh`: OK - `sh -n tools/ops/spark-baseline`: OK - `sh -n tools/ops/spark-calibrate`: OK - `cd tools/ops && sha256sum -c SHA256SUMS`: all 9 OK, including `spark-window` `01ac196e3e0fdcf7c2a69706ab0b6ca813af1bf67a4b56599fb65c351169fe14` - `sha256sum -c tools/ops/SHA256SUMS` from the repo root: FAILED open or read on all 9 names. The manifest lists bare names, so this command only sees the files when the cwd is `tools/ops`. - `tools/ops/test_spark_window_close.sh`: pass 23, fail 0, exit 0. PASS. The script was not modified. - `tools/ops/test-spark-window-starve.sh` (default, `SPARK_STARVE_PLAIN` unset), exit 0: - PASS case 1: no contention opens - PASS case 2 one holder, no pause between holders (tries 1) - PASS case 3 two holders through the quiet gate, no pause (tries 1) - PASS case 4 chip busy 6 s: opened only after the chip was free (window opened 5 s after the start) - SKIP case 5 known-starvable: two plain flock -s holders, no gate - Case 5 with `SPARK_STARVE_PLAIN=1`: not run. The default run skips it. - `spark-baseline` end to end: NOT RUN (needs the 27B server on 127.0.0.1:18091, an open window, and yardstick sensors) - `spark-calibrate` end to end: NOT RUN (needs an open window, the omega memcpy probe at `3bd56731`, `spark-receipt`, and wall-power sensors) - Installed `~/.local/bin/spark-window` on the Spark: NOT RUN ## Architecture change No subsystem responsibility change. Docs, the starve test, and two lock-path reads. No ADR. No security-boundary, secret, or effect-broker change. Failure behavior of `spark-baseline` and `spark-calibrate` is the same when `SPARK_GB10_LOCK` is unset. No diagrams. - Planned work is not described as implemented. - Machine naming remains hardware-neutral. - Tool/Skill/World/Cortex/J-Space responsibilities remain distinct. - External irreversible effects still require AEGIS + Effect Broker. - Secrets do not enter model-visible or provenance state. — Grokbot
Open in Web Open in Cursor
drakestapleton reviewed (COMMENTED) on 2026-10-30 11:36 UTC Triage: needs-changes (small). Review at `e81997c`, read-only. Verified - Findings 2 to 5 from #291 are fixed and match the scripts: - MEASUREMENT_WINDOWS now opens with `--gb10 none`, consistent with spark-baseline:28-29. - The quiet-build row matches quiet-build:21-58 (60 s flag wait, gate, shared lock, `SPARK_BUILD_MAX_WAIT` 1500 s, nice 19 plus intrusion log). - test-spark-window-starve.sh is now listed. - spark-calibrate:23 and spark-baseline:49 use `${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}`. - SHA256SUMS: all 9 entries match the bytes at the head, and nothing in tools/ops is missing. spark-window is `01ac196e…fe14`, the repo copy, unchanged from main. The file uses bare names, so it must be run from `tools/ops`, as the README says. Requested - README.md:12 says the window "still opens while shared quiet holders run back to back", but case 3 failed on a 4-CPU VM at both 60 s and 180 s. Case 3's holders use plain `flock -s`, which skips `$SPARK_QUIET_GATE`, and Linux flock gives no priority to an exclusive waiter. The window only gets in during the rare moment when both holders are between iterations, so this is a timing race, not a threshold problem: `SPARK_IDLE_LOAD=100000` (test line 15) turns off the load limit, two holders stay under `IDLE_N=3`, and nothing reads the CPU count. The 4/4 result under taskset on the Spark is likely the timing being kinder there; I haven't confirmed that. Suggestion: make case 3 go through the gate first, as quiet-build does (`flock -s "$SPARK_QUIET_GATE" true; flock -s "$SPARK_QUIET_LOCK" sleep …`). That makes it deterministic and actually exercises L322. Keep the plain-flock version as a separate case marked known-starvable, or let an env var skip it, and reword the README row to match. - Nits: - The spark-baseline:43 comment still names the hard-coded lock path. - spark-window:63 says `SPARK_GB10_LOCK` is for tests only and the 27B server uses the fixed path. Please say so next to the new lines, so nobody sets it in production and has spark-baseline watch the wrong lock. Not blocking, still open - Finding 1: the installed spark-window was not compared with `01ac196e…`. - Not run: spark-baseline and spark-calibrate end to end, and the Spark install. The diff is low-risk with the variable unset. - At review time Analyze (c-cpp) was still running and the mergeable state was unknown. — Grokbot drakestapleton reviewed (COMMENTED) on 2026-10-30 11:47 UTC Triage: ready-to-merge. Re-review at `77c27b1` (read-only), following my earlier review `5711650598`. Verified - Case 3 now takes `$SPARK_QUIET_GATE` and then the quiet lock, quiet-build's order (quiet-build:41, :45). With spark-window's exclusive gate at :336, the window now gets in reliably. - Case 5 runs only with `SPARK_STARVE_PLAIN=1`. Otherwise it prints SKIP and doesn't affect the exit code (:72-78). - The README row now matches what the test proves. - spark-calibrate and spark-baseline: since `e81997c` the changes are comments only. Compared with main, the lock path is `${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}` with the default unchanged, so it's safe with the variable unset. spark-window is unchanged (`01ac196e`). - SHA256SUMS: all 9 entries match the head bytes and nothing in tools/ops is missing. README:19 ("From `tools/ops`") covers the bare-name format. - Checks are green and the merge state is clean. The VM results (cases 1-4 PASS, case 5 skipped, close test 23/23, `sha256sum -c` 9/9) are as reported, not re-run here. Nits, optional - "the gate in spark-window (L322)" reads like a line number; the gate is actually taken at spark-window:330-336. - The README row no longer mentions the chip-busy case (case 4). - The tests-only note appears twice, at spark-baseline:48 and :49. - Consider adding `(cd tools/ops && sha256sum -c SHA256SUMS)` to the README for runs from the repo root. - Case 2 is still the timing-based plain-flock run with one holder. It passed on both hosts but isn't guaranteed the way case 3 now is. Still open, not blocking - Finding 1: the installed spark-window hasn't been compared with `01ac196e`. - spark-baseline and spark-calibrate haven't been run end to end on the Spark. — Grokbot ### Apply it ``` git checkout -b patch-c7c2cfc8abbbce15 a0a7146f198613c1df3e6ddc96a8582f95c0d95d curl -fsSL https://interplane.io/drakestapleton/aien-architecture-mv/patches/c7c2cfc8abbbce15.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aien-architecture-mv 356 77c27b1cc545a55ffe7886d1e3012ff0be489cf1 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-architecture-mv","number":356,"url":"https://github.com/aien-dev/aien-architecture-mv/pull/356","export_sha256":"e0ab76730762f7bd707f3b0c07e133f83d4287854fada828261004f8d4bcaa1a","imported_utc":"2026-11-18T16:37:27Z"} ``` ### Changes ``` 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..c322a42 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 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` | | `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..07dc0f0 --- /dev/null +++ b/tools/ops/SHA256SUMS @@ -0,0 +1,9 @@ +b8b40d2c1221d6067a49cebd288fcf0b8fb34c616562f58569385d81de62d8dc quiet-build +c838569e1a940e904bc226bcbb192fdf013d0b70913325d3e5af3cdb93ab6b67 quiet-measure +925e55b6348ba8de23c863cc7476735eda6d1bb43c953b16e1fac04cc565c42a spark-baseline +f271b0ae027c35e855d855a528fa61d0f4e6f11dc44c390da2754623d129db46 spark-build-once +09c45c5a664a3ca1dba3a083cbbcd16d643f114345952868b13c5bafe7e9c40b spark-calibrate +aca797f0d7fa228452712c56a32530865c9c8b7c1d9448fc8ded15b44a39468c spark-receipt +01ac196e3e0fdcf7c2a69706ab0b6ca813af1bf67a4b56599fb65c351169fe14 spark-window +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 36d9c20..40ba191 100755 --- a/tools/ops/spark-baseline +++ b/tools/ops/spark-baseline @@ -40,12 +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. -G=/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 c8f3b52..fe5c257 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, 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. @@ -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} # 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 ```