From c66275654703a5926e49927b8e9a9c4ebb48e3b8 Mon Sep 17 00:00:00 2001 From: Burntgogi <224273819+Burntgogi@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:06:58 +0900 Subject: [PATCH 1/3] ref: the window's start marker lands at its line, not at the stream's end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The marker's sample ran in an awk whose stdin is buffered (mawk 1.3.4, gawk and the Mac's awk alike): the match's sample waited for the buffer's fill or the stream's end, and faults inside the measured window landed under its start — the warm and warm-fail checks of the DS41 stub suite have carried it. The mark is now one line at a time through the shell, with the sampler itself (majflt_sample) the part the stub suites replace, and the self-test pins the marker against a pipe that stays open. --- tools/ref/cold-blocks.sh | 65 +++++++++++++++++++++++++++----- tools/ref/depth-ds41-stub.sh | 2 +- tools/ref/depth-glm5next-stub.sh | 2 +- tools/ref/depth-qwen3moe-stub.sh | 2 +- 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/tools/ref/cold-blocks.sh b/tools/ref/cold-blocks.sh index 34b871d33..46af44452 100644 --- a/tools/ref/cold-blocks.sh +++ b/tools/ref/cold-blocks.sh @@ -141,14 +141,34 @@ majflt_require() { echo "$1: /proc/vmstat gives no pgmajfault: every row's majflt column and cold tag would read 0" >&2 exit 2 } -# majflt_mark : its stdin to stdout line by line, and /proc/vmstat's pgmajfault into -# at the first line matching (at none when is empty): the line an engine prints as its -# measured window starts. +# majflt_sample : /proc/vmstat's pgmajfault into . The depth runners' stub suites +# override this one with their own counter file; majflt_mark keeps the reading and the line loop. +majflt_sample() { + local l + while read -r l; do + case $l in pgmajfault\ *) printf '%s\n' "${l#pgmajfault }" > "$1"; return 0 ;; esac + done < /proc/vmstat + printf '%s\n' '' > "$1" +} +# majflt_mark : its stdin to stdout line by line, and /proc/vmstat's pgmajfault into +# at the first line matching (at none when is empty): the line an engine prints as +# its measured window starts. The read is one line at a time through the shell: awk buffers its +# stdin (mawk 1.3.4, gawk and the Mac's awk alike), so a sample the match took waited for the +# buffer's fill or the stream's end, and the faults a lazy sample leaves out of the window are the +# ones the window's start line means to measure away. majflt_mark() { - awk -v f="$1" -v re="$2" '!s && re != "" && $0 ~ re { - while ((getline l < "/proc/vmstat") > 0) if (l ~ /^pgmajfault /) { sub(/^pgmajfault /, "", l); print l > f; close(f) } - close("/proc/vmstat"); s = 1 - } { print; fflush() }' + local f=$1 re=$2 line s='' + while IFS= read -r line; do + if [ -z "$s" ] && [ -n "$re" ] && [[ $line =~ $re ]]; then + majflt_sample "$f" + s=1 + fi + printf '%s\n' "$line" + done + if [ -n "$line" ]; then + if [ -z "$s" ] && [ -n "$re" ] && [[ $line =~ $re ]]; then majflt_sample "$f"; fi + printf '%s\n' "$line" + fi } # cold_check : MAJ_BOUND, faults × COLD_US as a percent of the window, and COLD_TAG # (` [cold]` at COLD_PCT or more). @@ -409,9 +429,10 @@ res_sums_table() { }' | sort } -# `bash tools/ref/cold-blocks.sh --self-test`: the cold bound, the flag rewrite, the order's refusal and -# the block planner on fixed arms (just check-recipes runs it on the Mac; the runners' use of it is -# depth-ds41-stub.sh's and depth-qwen3moe-stub.sh's, on the box). +# `bash tools/ref/cold-blocks.sh --self-test`: the cold bound, the flag rewrite, the order's refusal, +# the block planner on fixed arms, and the window's start marker landing at its line on a pipe that +# stays open (Linux; the Mac has no /proc/vmstat for the sample to read) — just check-recipes runs it +# on the Mac; the runners' use of it is depth-ds41-stub.sh's and depth-qwen3moe-stub.sh's, on the box. if [ "${BASH_SOURCE[0]}" = "$0" ] && [ "${1:-}" = --self-test ]; then fails=0 check() { @@ -427,6 +448,30 @@ if [ "${BASH_SOURCE[0]}" = "$0" ] && [ "${1:-}" = --self-test ]; then check cold-zero "$MAJ_BOUND|$COLD_TAG" "0.0|" cold_check 0 0 check cold-nowindow "$COLD_TAG" " [cold]" + # The start marker's sample is taken at its line, not at the stream's end: the stdin the marker + # reads stays open across the measured window (the runner hands the marker the whole run's + # output), and awk buffers that input, so a marker the match itself sampled waited for a + # buffer's fill and the window's faults landed under its start. One line at a time through the + # shell lands it while the pipe is still open; the sleep below is the check's wait, not a fix. + if [ -e /proc/vmstat ]; then + d=$(mktemp -d) + mkfifo "$d/pipe" + majflt_mark "$d/mark" 'window-start' < "$d/pipe" > "$d/out" & + mp=$! + exec 9> "$d/pipe" + printf 'ahead\nwindow-start\n' >&9 + sleep 0.4 + v=$(cat "$d/mark" 2> /dev/null) + case $v in '' | *[!0-9]*) at='no' ;; *) at='yes' ;; esac + check marker-at-line "$at" 'yes' + printf 'trailing\n' >&9 + exec 9>&- + wait "$mp" && r=0 || r=$? + check marker-rc "$r" '0' + check marker-pass "$(paste -sd'|' - < "$d/out")" 'ahead|window-start|trailing' + majflt_mark "$d/mark-none" '' <<< $'window-start\ntrailing' > /dev/null + check marker-empty-re "$([ -e "$d/mark-none" ] && echo yes || echo no)" 'no' + fi check ncmoe-long "$(with_ncmoe '-ngl 99 --n-cpu-moe 33 -fa on' 2)" "-ngl 99 -fa on --n-cpu-moe 2" check ncmoe-short "$(with_ncmoe '-ngl 99 -fa on -lzm off -ncmoe 26' 30)" "-ngl 99 -fa on -lzm off --n-cpu-moe 30" check ncmoe-none "$(with_ncmoe '-ngl 99' 4)" "-ngl 99 --n-cpu-moe 4" diff --git a/tools/ref/depth-ds41-stub.sh b/tools/ref/depth-ds41-stub.sh index 7f705a120..c1c0c1972 100755 --- a/tools/ref/depth-ds41-stub.sh +++ b/tools/ref/depth-ds41-stub.sh @@ -221,7 +221,7 @@ echo 'LEASE_CARDS_RECORD=1' >> "$T/tools/ref/lease.sh" # shellcheck disable=SC2016 # the copies expand them when they run { echo 'majflt_now() { cat "$STUB_MAJFLT"; }' - echo 'majflt_mark() { awk -v f="$1" -v re="$2" -v src="$STUB_MAJFLT" '"'"'!s && re != "" && $0 ~ re { getline l < src; close(src); print l > f; close(f); s = 1 } { print; fflush() }'"'"'; }' + echo 'majflt_sample() { local v='"'"''"'"'; if [ -r "$STUB_MAJFLT" ]; then read -r v < "$STUB_MAJFLT" || v='"'"''"'"'; fi; printf '"'"'%s\n'"'"' "$v" > "$1"; }' } >> "$T/tools/ref/cold-blocks.sh" echo 'lg_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/load-groups.sh" [ ! -f "$T/tools/ref/lcpp-warm.sh" ] || echo 'lcpp_srv_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/lcpp-warm.sh" diff --git a/tools/ref/depth-glm5next-stub.sh b/tools/ref/depth-glm5next-stub.sh index 9689c3c97..38658cddd 100755 --- a/tools/ref/depth-glm5next-stub.sh +++ b/tools/ref/depth-glm5next-stub.sh @@ -248,7 +248,7 @@ echo 'lease_take() { echo "[stub] no lease: the stub test'"'"'s copy of lease.sh # shellcheck disable=SC2016 # the copies expand them when they run { echo 'majflt_now() { cat "$STUB_MAJFLT"; }' - echo 'majflt_mark() { awk -v f="$1" -v re="$2" -v src="$STUB_MAJFLT" '"'"'!s && re != "" && $0 ~ re { getline l < src; close(src); print l > f; close(f); s = 1 } { print; fflush() }'"'"'; }' + echo 'majflt_sample() { local v='"'"''"'"'; if [ -r "$STUB_MAJFLT" ]; then read -r v < "$STUB_MAJFLT" || v='"'"''"'"'; fi; printf '"'"'%s\n'"'"' "$v" > "$1"; }' } >> "$T/tools/ref/cold-blocks.sh" echo 'lcpp_srv_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/lcpp-warm.sh" touch "$T/Cargo.toml" diff --git a/tools/ref/depth-qwen3moe-stub.sh b/tools/ref/depth-qwen3moe-stub.sh index ef432fbb9..5e7dc9390 100755 --- a/tools/ref/depth-qwen3moe-stub.sh +++ b/tools/ref/depth-qwen3moe-stub.sh @@ -254,7 +254,7 @@ echo 'if [ -n "${STUB_ONE_CARD_LEASE:-}" ]; then unset LEASE_CARDS_RECORD; else # shellcheck disable=SC2016 # the copies expand them when they run { echo 'majflt_now() { cat "$STUB_MAJFLT"; }' - echo 'majflt_mark() { awk -v f="$1" -v re="$2" -v src="$STUB_MAJFLT" '"'"'!s && re != "" && $0 ~ re { getline l < src; close(src); print l > f; close(f); s = 1 } { print; fflush() }'"'"'; }' + echo 'majflt_sample() { local v='"'"''"'"'; if [ -r "$STUB_MAJFLT" ]; then read -r v < "$STUB_MAJFLT" || v='"'"''"'"'; fi; printf '"'"'%s\n'"'"' "$v" > "$1"; }' } >> "$T/tools/ref/cold-blocks.sh" echo 'lg_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/load-groups.sh" [ ! -f "$T/tools/ref/lcpp-warm.sh" ] || echo 'lcpp_srv_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/lcpp-warm.sh" From ac1ac032e1cdc824daf77a473ffb265826ca2ed4 Mon Sep 17 00:00:00 2001 From: Burntgogi <224273819+Burntgogi@users.noreply.github.com> Date: Sat, 17 Oct 2026 08:05:56 +0900 Subject: [PATCH 2/3] ref: the marker forwards the stream's failures and keeps the counter's owner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A failed forwarding write was dropped and the marker's own sampler was a second reader of the counter the owners already read. The forward now returns a printf failure, the sample is the counter's owner (majflt_now, whose stub overrides stand), and the self-test asserts that input before the window's line marks nothing — the marker check the matched line's predicate needs. --- tools/ref/cold-blocks.sh | 33 +++++++++++++++----------------- tools/ref/depth-ds41-stub.sh | 1 - tools/ref/depth-glm5next-stub.sh | 1 - tools/ref/depth-qwen3moe-stub.sh | 1 - 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/tools/ref/cold-blocks.sh b/tools/ref/cold-blocks.sh index 46af44452..ad5e896ad 100644 --- a/tools/ref/cold-blocks.sh +++ b/tools/ref/cold-blocks.sh @@ -141,34 +141,28 @@ majflt_require() { echo "$1: /proc/vmstat gives no pgmajfault: every row's majflt column and cold tag would read 0" >&2 exit 2 } -# majflt_sample : /proc/vmstat's pgmajfault into . The depth runners' stub suites -# override this one with their own counter file; majflt_mark keeps the reading and the line loop. -majflt_sample() { - local l - while read -r l; do - case $l in pgmajfault\ *) printf '%s\n' "${l#pgmajfault }" > "$1"; return 0 ;; esac - done < /proc/vmstat - printf '%s\n' '' > "$1" +# majflt_require : exit 2 before the lease when /proc/vmstat has no pgmajfault. +majflt_require() { + [ -n "$(majflt_now 2> /dev/null)" ] && return 0 + echo "$1: /proc/vmstat gives no pgmajfault: every row's majflt column and cold tag would read 0" >&2 + exit 2 } # majflt_mark : its stdin to stdout line by line, and /proc/vmstat's pgmajfault into # at the first line matching (at none when is empty): the line an engine prints as # its measured window starts. The read is one line at a time through the shell: awk buffers its -# stdin (mawk 1.3.4, gawk and the Mac's awk alike), so a sample the match took waited for the +# stdin (mawk 1.3.4, gawk and the Mac's awk alike), so the sample a match took waited for the # buffer's fill or the stream's end, and the faults a lazy sample leaves out of the window are the -# ones the window's start line means to measure away. +# ones the window's start line means to measure away. The sampler is `majflt_now`, the counter's +# owner; a failed forward is the run's failure, not the marker's. majflt_mark() { local f=$1 re=$2 line s='' - while IFS= read -r line; do + while IFS= read -r line || [ -n "$line" ]; do if [ -z "$s" ] && [ -n "$re" ] && [[ $line =~ $re ]]; then - majflt_sample "$f" + majflt_now > "$f" || return s=1 fi - printf '%s\n' "$line" + printf '%s\n' "$line" || return done - if [ -n "$line" ]; then - if [ -z "$s" ] && [ -n "$re" ] && [[ $line =~ $re ]]; then majflt_sample "$f"; fi - printf '%s\n' "$line" - fi } # cold_check : MAJ_BOUND, faults × COLD_US as a percent of the window, and COLD_TAG # (` [cold]` at COLD_PCT or more). @@ -459,7 +453,10 @@ if [ "${BASH_SOURCE[0]}" = "$0" ] && [ "${1:-}" = --self-test ]; then majflt_mark "$d/mark" 'window-start' < "$d/pipe" > "$d/out" & mp=$! exec 9> "$d/pipe" - printf 'ahead\nwindow-start\n' >&9 + printf 'ahead\n' >&9 + for ((i = 0; i < 40; i++)); do [ -s "$d/out" ] && break; sleep 0.01; done + check marker-before-match "$(cat "$d/out")|$([ -e "$d/mark" ] && echo yes || echo no)" 'ahead|no' + printf 'window-start\n' >&9 sleep 0.4 v=$(cat "$d/mark" 2> /dev/null) case $v in '' | *[!0-9]*) at='no' ;; *) at='yes' ;; esac diff --git a/tools/ref/depth-ds41-stub.sh b/tools/ref/depth-ds41-stub.sh index c1c0c1972..787119dba 100755 --- a/tools/ref/depth-ds41-stub.sh +++ b/tools/ref/depth-ds41-stub.sh @@ -221,7 +221,6 @@ echo 'LEASE_CARDS_RECORD=1' >> "$T/tools/ref/lease.sh" # shellcheck disable=SC2016 # the copies expand them when they run { echo 'majflt_now() { cat "$STUB_MAJFLT"; }' - echo 'majflt_sample() { local v='"'"''"'"'; if [ -r "$STUB_MAJFLT" ]; then read -r v < "$STUB_MAJFLT" || v='"'"''"'"'; fi; printf '"'"'%s\n'"'"' "$v" > "$1"; }' } >> "$T/tools/ref/cold-blocks.sh" echo 'lg_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/load-groups.sh" [ ! -f "$T/tools/ref/lcpp-warm.sh" ] || echo 'lcpp_srv_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/lcpp-warm.sh" diff --git a/tools/ref/depth-glm5next-stub.sh b/tools/ref/depth-glm5next-stub.sh index 38658cddd..dee671eb1 100755 --- a/tools/ref/depth-glm5next-stub.sh +++ b/tools/ref/depth-glm5next-stub.sh @@ -248,7 +248,6 @@ echo 'lease_take() { echo "[stub] no lease: the stub test'"'"'s copy of lease.sh # shellcheck disable=SC2016 # the copies expand them when they run { echo 'majflt_now() { cat "$STUB_MAJFLT"; }' - echo 'majflt_sample() { local v='"'"''"'"'; if [ -r "$STUB_MAJFLT" ]; then read -r v < "$STUB_MAJFLT" || v='"'"''"'"'; fi; printf '"'"'%s\n'"'"' "$v" > "$1"; }' } >> "$T/tools/ref/cold-blocks.sh" echo 'lcpp_srv_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/lcpp-warm.sh" touch "$T/Cargo.toml" diff --git a/tools/ref/depth-qwen3moe-stub.sh b/tools/ref/depth-qwen3moe-stub.sh index 5e7dc9390..4c3cfc710 100755 --- a/tools/ref/depth-qwen3moe-stub.sh +++ b/tools/ref/depth-qwen3moe-stub.sh @@ -254,7 +254,6 @@ echo 'if [ -n "${STUB_ONE_CARD_LEASE:-}" ]; then unset LEASE_CARDS_RECORD; else # shellcheck disable=SC2016 # the copies expand them when they run { echo 'majflt_now() { cat "$STUB_MAJFLT"; }' - echo 'majflt_sample() { local v='"'"''"'"'; if [ -r "$STUB_MAJFLT" ]; then read -r v < "$STUB_MAJFLT" || v='"'"''"'"'; fi; printf '"'"'%s\n'"'"' "$v" > "$1"; }' } >> "$T/tools/ref/cold-blocks.sh" echo 'lg_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/load-groups.sh" [ ! -f "$T/tools/ref/lcpp-warm.sh" ] || echo 'lcpp_srv_majflt() { cat "$STUB_MAJFLT"; }' >> "$T/tools/ref/lcpp-warm.sh" From 25d8a832ae55e4da35baf5e288dc2aba30564aa0 Mon Sep 17 00:00:00 2001 From: Burntgogi <224273819+Burntgogi@users.noreply.github.com> Date: Sat, 17 Oct 2026 08:21:53 +0900 Subject: [PATCH 3/3] ref: keep one fault-counter preflight and test live forwarding failure --- docs/performance.md | 4 ++++ tools/ref/cold-blocks.sh | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/performance.md b/docs/performance.md index 18fe7b2d1..68b2f536f 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -105,6 +105,10 @@ language is not one of the reasons: the kernels are Rust (274 of them, through - **Bit gates.** Graph replay equals eager execution; the skewed pass equals two single steps; a rollback and a V4.1 batched prompt leave the same state as one step per token. - **Each gate is shown to fail** on its defect before the fix lands. Bands are not relaxed to pass. +- **Fault-window integrity.** The depth runners' preflight and first-match marker share `majflt_now` + as their counter reader. The marker samples the matching line while its input is still open; + sampling or output failures fail the run. `bash tools/ref/cold-blocks.sh --self-test` and the + DS41, Qwen3MoE and GLM depth-runner stub suites exercise this without a model or GPU. ## Recorded sessions diff --git a/tools/ref/cold-blocks.sh b/tools/ref/cold-blocks.sh index ad5e896ad..0ab1544d4 100644 --- a/tools/ref/cold-blocks.sh +++ b/tools/ref/cold-blocks.sh @@ -141,12 +141,6 @@ majflt_require() { echo "$1: /proc/vmstat gives no pgmajfault: every row's majflt column and cold tag would read 0" >&2 exit 2 } -# majflt_require : exit 2 before the lease when /proc/vmstat has no pgmajfault. -majflt_require() { - [ -n "$(majflt_now 2> /dev/null)" ] && return 0 - echo "$1: /proc/vmstat gives no pgmajfault: every row's majflt column and cold tag would read 0" >&2 - exit 2 -} # majflt_mark : its stdin to stdout line by line, and /proc/vmstat's pgmajfault into # at the first line matching (at none when is empty): the line an engine prints as # its measured window starts. The read is one line at a time through the shell: awk buffers its @@ -447,9 +441,9 @@ if [ "${BASH_SOURCE[0]}" = "$0" ] && [ "${1:-}" = --self-test ]; then # output), and awk buffers that input, so a marker the match itself sampled waited for a # buffer's fill and the window's faults landed under its start. One line at a time through the # shell lands it while the pipe is still open; the sleep below is the check's wait, not a fix. + d=$(mktemp -d) + mkfifo "$d/pipe" if [ -e /proc/vmstat ]; then - d=$(mktemp -d) - mkfifo "$d/pipe" majflt_mark "$d/mark" 'window-start' < "$d/pipe" > "$d/out" & mp=$! exec 9> "$d/pipe" @@ -469,6 +463,20 @@ if [ "${BASH_SOURCE[0]}" = "$0" ] && [ "${1:-}" = --self-test ]; then majflt_mark "$d/mark-none" '' <<< $'window-start\ntrailing' > /dev/null check marker-empty-re "$([ -e "$d/mark-none" ] && echo yes || echo no)" 'no' fi + # A failed forward must finish without waiting for upstream EOF. + ( + majflt_mark /dev/null '' < "$d/pipe" 1< /dev/null 2> /dev/null && r=0 || r=$? + printf '%s\n' "$r" > "$d/forward.rc" + ) & + mp=$! + exec 9> "$d/pipe" + printf 'forwarded\n' >&9 + for ((i = 0; i < 40; i++)); do [ -s "$d/forward.rc" ] && break; sleep 0.01; done + r=$(cat "$d/forward.rc" 2> /dev/null) + check marker-forward-failure "$([ -n "$r" ] && [ "$r" -ne 0 ] && echo failed || echo waiting-or-success)" failed + exec 9>&- + wait "$mp" + rm -rf "$d" check ncmoe-long "$(with_ncmoe '-ngl 99 --n-cpu-moe 33 -fa on' 2)" "-ngl 99 -fa on --n-cpu-moe 2" check ncmoe-short "$(with_ncmoe '-ngl 99 -fa on -lzm off -ncmoe 26' 30)" "-ngl 99 -fa on -lzm off --n-cpu-moe 30" check ncmoe-none "$(with_ncmoe '-ngl 99' 4)" "-ngl 99 --n-cpu-moe 4"