diff --git a/.crumb b/.crumb index 69d561623..e616ac80e 100644 --- a/.crumb +++ b/.crumb @@ -64,7 +64,7 @@ }, { "digest": "ee805b014db4923cbbb2a86b940e5737e76d15c636148c3576276204e8b076f1", - "last_commit": "5b826f5", + "last_commit": "e798fb7", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -93,27 +93,27 @@ "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "c344fe651eaf853a43d4767d6ea5d29151bb4e610b67829d956b29a47d966f01", - "last_commit": "ab07608", + "digest": "dbd66339e5bcd81e328f8b4e9db44a92482418ef6636af75e7e2b92fdba6b065", + "last_commit": "82d9dc0", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "546da8393e444a620edd23486a7a66b483539dd10a4c273e4bd41deacb2d218d", - "last_commit": "468354a", + "digest": "43dd39270ced0e0209a37d3b7d37376581f4d54f1e436662472c232c08f1c633", + "last_commit": "82d9dc0", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:cbc160ad83bcab2c0ff053fa2c59c79be642222c1a7733583c3cf2e70be993a9", - "compiled_at": "2026-10-05T15:28:49Z", + "children_root": "sha256:09a8a1f3924313e80183e86671ac02314178c510dc5f82d97827a059eedaa6aa", + "compiled_at": "2026-10-05T16:04:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:9ab08bdb200b75198478eef41117768be3eebef31ad0da59b0a4489497165aae", + "digest": "sha256:4887527bf7a304fdc8f034915d2debff41ea2decf23321b5ba229874ea1f0a71", "evidence_files": 2749, "evidence_root": "sha256:c6e60c5b2803cfddf6a1fed130c92066d285ddb68aeea0bc65d58668cf139dfc", - "files": 4541, - "generated_at_commit": "50d535b45ee24fa8bec28ac3248be7209b6a07b0", - "source_tree": "sha256:3eb9e9d67192f0e40ce2dfb740c017a703d678161d8733b6b3a4159854d14ec8" + "files": 4544, + "generated_at_commit": "82d9dc09c6c3a673409daf32fb69c70be8bf9850", + "source_tree": "sha256:3899c1f44ec8cd12191449b893d3558af34b84bb59e5f42b607da747b93ba3c4" }, "owner_lane": "", "provenance": { diff --git a/Makefile b/Makefile index 9a9df8643..40ab1921a 100644 --- a/Makefile +++ b/Makefile @@ -832,6 +832,14 @@ test-r15-preflight: sh tests/r15_preflight_test.sh sh tests/r15_energy_preflight_test.sh +# G15 diagnostics: sampler lateness / not-live-run record, its reducer report, +# and the readable-kernel-log Xid scan. Host-only, no chip. +.PHONY: test-r15-g15-diag +test-r15-g15-diag: $(R15_REDUCE) | $(OUT_DIR) + $(CC) -std=c11 -Wall -Wextra -Werror -fsanitize=address,undefined -Itests/runtime -o $(OUT_DIR)/r15_seat_diag_test tests/runtime/r15_seat_diag_test.c + $(OUT_DIR)/r15_seat_diag_test + R15_REDUCE=$(R15_REDUCE) sh tests/r15_g15_diag_test.sh + # R16-G2 code-search gate (spec/r16-orchestrator-retirement.md). Host-only C tool, # seconds, no network. Scans the five repos (paths from R16_REPO_OMEGA, # R16_REPO_SOVEREIGN_CORE, R16_REPO_AEGIS_RUNTIME, R16_REPO_AIENOS, diff --git a/tests/.crumb b/tests/.crumb index ffebfa593..07bb5a47a 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -230,7 +230,7 @@ }, { "digest": "bcbd86e0fc80826cf66b7c2bbd71b6eab93c539313dbd042f30f3bb1fd3c5659", - "last_commit": "5b826f5", + "last_commit": "e798fb7", "name": "r16_negative", "purpose": "Directory tests/r16_negative. Purpose not yet described by a human." }, @@ -253,8 +253,8 @@ "purpose": "Directory tests/relations. Purpose not yet described by a human." }, { - "digest": "91f6e8213fbfaa51048b9573ff4e7102d83019a5317d6ae6637cfcd952e53fa1", - "last_commit": "ad8ca9a", + "digest": "471d1ac8ecb149b58ee57d6f9b8e17ac59f21935f83fd6d6281fdc2a057b0678", + "last_commit": "b18913b", "name": "runtime", "purpose": "Directory tests/runtime. Purpose not yet described by a human." }, @@ -283,15 +283,15 @@ "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], - "children_root": "sha256:ca83c873b245d9a367fabf72c1d7ab183ace4a7ada1139333778b6ec1d928781", - "compiled_at": "2026-10-05T15:28:49Z", + "children_root": "sha256:5931b109ad80c3fe8f2a1d88ca77be3b288a5b3c61334e07eb278b329d36504c", + "compiled_at": "2026-10-05T16:04:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:c344fe651eaf853a43d4767d6ea5d29151bb4e610b67829d956b29a47d966f01", + "digest": "sha256:dbd66339e5bcd81e328f8b4e9db44a92482418ef6636af75e7e2b92fdba6b065", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", - "files": 799, - "generated_at_commit": "50d535b45ee24fa8bec28ac3248be7209b6a07b0", - "source_tree": "sha256:da421f93937838ed46d86d46893c0bf4863dbe2b02563bdf805cf0027347847a" + "files": 802, + "generated_at_commit": "82d9dc09c6c3a673409daf32fb69c70be8bf9850", + "source_tree": "sha256:364ce6353e516cfd18524c10a498e8846b1a580c5639c441e2fa13c9aaeb0e0e" }, "owner_lane": "", "provenance": { diff --git a/tests/r15_g15_diag_test.sh b/tests/r15_g15_diag_test.sh new file mode 100644 index 000000000..abf7d7f1b --- /dev/null +++ b/tests/r15_g15_diag_test.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# G15 diagnostic in the reducer (tools/r15_reduce.c, m10_gpu_residency.worst_process_diagnostic). +# Uses the real CAND-1 window-2 trial-SEQ-06 raw file (16348 of 19253 samples live), +# plus copies whose residency record is extended with sampler diag fields. +# Checks: the verdict is untouched (G15 FAIL, value 0.849114424) in every case; old +# evidence says UNMEASURED and infers nothing; a long not-live run is reported as +# seat_stopped_long_run; scattered losses with a late sampler are reported as such. +# Needs build/r15_reduce (make build/r15_reduce). +cd "$(dirname "$0")/.." || exit 1 +RED=${R15_REDUCE:-build/r15_reduce}; SRC=evidence/CAND1-WINDOW2-20261005T1259Z/R15-silicon/raw/trial-SEQ-06.jsonl +[ -x "$RED" ] && [ -f "$SRC" ] || { echo "need $RED and $SRC"; exit 2; } +W=$(mktemp -d) || exit 1; trap 'rm -rf "$W"' EXIT; fail=0 +run() { # name diag-json-or-empty expected-class-text expected-extra-text + mkdir "$W/$1" + if [ -n "$2" ]; then sed "s|\"claims_max\":1}}|\"claims_max\":1,\"diag\":$2}}|" "$SRC" > "$W/$1/trial-SEQ-06.jsonl" + else cp "$SRC" "$W/$1/trial-SEQ-06.jsonl"; fi + ( cd "$W/$1" && sha256sum trial-SEQ-06.jsonl > SHA256SUMS ) + "$RED" "$W/$1" "$W/$1/s.json" >/dev/null 2>&1 + s=$(tr -d '\n' < "$W/$1/s.json") + if printf '%s' "$s" | grep -Fq "$3" && printf '%s' "$s" | grep -Fq "$4" \ + && printf '%s' "$s" | grep -Fq '"id":"G15","criterion":"GPU residency","threshold":">= 99% of samples live","value":0.849114424,"outcome":"FAIL"'; then + echo "[+] $1" + else echo "[-] $1: $(printf '%s' "$s" | grep -o '"worst_process_diagnostic":{[^}]*}')"; fail=$((fail + 1)); fi +} +run old_evidence "" '"class":"UNMEASURED"' '"lost_samples":2905' +run seat_stopped '{"late_2ms":0,"late_10ms":0,"max_gap_ns":1100000,"dead_runs":1,"dead_longest":2905,"dead_at_end":2905,"t_first":1000,"t_last":20000000000,"first_dead_t":17000001000,"last_live_t":16999000000,"stale_max_ns":3000000000}' \ + '"class":"seat_stopped_long_run"' '"sampler_late_observed":false' +run scattered_late_sampler '{"late_2ms":400,"late_10ms":60,"max_gap_ns":80000000,"dead_runs":2905,"dead_longest":1,"dead_at_end":0,"t_first":1000,"t_last":20000000000,"first_dead_t":5000000,"last_live_t":19999000000,"stale_max_ns":2000000}' \ + '"class":"scattered_not_live"' '"sampler_late_observed":true' +# xid-scan: a GPU fault must be reported, none must read as none, and an unreadable +# log must never read as none (window 2's dmesg-based count did exactly that). +T=tools/r15_machine_state.sh +xcheck() { # name expected-exit expected-text + out=$(R15_KLOG_FILE="$W/$1" "$T" xid-scan 0 1 2>&1); rc=$? + if [ "$rc" = "$2" ] && printf '%s\n' "$out" | grep -Fq -- "$3"; then echo "[+] xid-scan $1" + else echo "[-] xid-scan $1: exit $rc: $out"; fail=$((fail + 1)); fi +} +printf '%s\n' '2026-10-05T08:08:16-05:00 spark kernel: NVRM: Xid (PCI:000f:01:00): 109, pid=2050644, name=rx_r15_perf_sil, channel 0x0000000a, errorString CTX SWITCH TIMEOUT, Info 0x3c002' \ + '2026-10-05T08:08:17-05:00 spark kernel: audit: unrelated' > "$W/with_xid" +: > "$W/none" +xcheck with_xid 0 "xid lines: 1" +xcheck none 0 "xid lines: 0" +xcheck missing_file 4 "XID_LOG_UNREADABLE" +# No journal access: journalctl prints "-- No entries --" and exits 0. The empty +# boot-log probe must turn that into UNREADABLE, while a readable boot log with an +# empty window still reads as none. +printf '%s\n' '-- No entries --' > "$W/no_entries" +printf '%s\n' 'Linux version 7.0.0' > "$W/probe_ok" +: > "$W/probe_empty" +pcheck() { # name probe expected-exit expected-text + out=$(R15_KLOG_FILE="$W/$1" R15_KLOG_PROBE_FILE="$W/$2" "$T" xid-scan 0 1 2>&1); rc=$? + if [ "$rc" = "$3" ] && printf '%s\n' "$out" | grep -Fq -- "$4"; then echo "[+] xid-scan $1 probe=$2" + else echo "[-] xid-scan $1 probe=$2: exit $rc: $out"; fail=$((fail + 1)); fi +} +pcheck no_entries probe_empty 4 "XID_LOG_UNREADABLE" +pcheck no_entries probe_missing 4 "XID_LOG_UNREADABLE" +pcheck no_entries probe_ok 0 "xid lines: 0" +pcheck with_xid probe_ok 0 "xid lines: 1" +echo "failures $fail"; [ "$fail" = 0 ] diff --git a/tests/runtime/.crumb b/tests/runtime/.crumb index 392dbd5d5..97f120cca 100644 --- a/tests/runtime/.crumb +++ b/tests/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-05T13:02:11Z", + "compiled_at": "2026-10-05T15:00:18Z", "compiler": "crumb-compile/1", - "digest": "sha256:91f6e8213fbfaa51048b9573ff4e7102d83019a5317d6ae6637cfcd952e53fa1", + "digest": "sha256:471d1ac8ecb149b58ee57d6f9b8e17ac59f21935f83fd6d6281fdc2a057b0678", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 53, - "generated_at_commit": "e55855ddfc098407fddb702d20966aacb9a87463", - "source_tree": "sha256:25cdc22a3ebe02ccece6417212825e19250e8a943dc99e7f65bb45bc218f8ce4" + "files": 55, + "generated_at_commit": "a386d65ed193a02dccac444de3fd3224c96162b4", + "source_tree": "sha256:cceeea5f8ce01092b50ea98d6a52b12762de66d2b649c5635a6cdaafcbdc1894" }, "owner_lane": "", "provenance": { diff --git a/tests/runtime/r15_seat_diag.h b/tests/runtime/r15_seat_diag.h new file mode 100644 index 000000000..5d0a8c0bc --- /dev/null +++ b/tests/runtime/r15_seat_diag.h @@ -0,0 +1,57 @@ +/* r15_seat_diag.h -- per-sample diagnostics for the 1 ms GPU-seat residency + * sampler (spec/r15-performance-proof.md section 6.10, gate G15). + * + * G15 counts a sample "live" when the seat's heartbeat word moved since the + * previous 1 ms sample. A not-live sample can mean the seat really stopped + * (residency loss), or that the sampler ran late or not at all, or that the + * heartbeat read was stale. The counts alone cannot tell these apart, which is + * why CAND-1 window 2 (trial SEQ-06, 16348 of 19253 live) could only be + * explained from outside the evidence. These fields travel with the existing + * "sampler"/"total" objects (additive keys; seat_live and intervals, and so + * G15, are computed exactly as before). + * + * Wake-up lateness is the time between consecutive counted samples (nominal + * 1 ms plus the read); a starved sampler shows large gaps AND fewer samples, + * a stopped seat shows a long run of not-live samples with normal gaps. + */ +#ifndef R15_SEAT_DIAG_H +#define R15_SEAT_DIAG_H +#include + +typedef struct { + uint64_t last_t, last_change_t; /* monotonic ns of previous sample / last heartbeat move */ + uint64_t late_2ms, late_10ms, max_gap_ns; + uint64_t dead_runs, dead_longest, dead_cur; /* runs of consecutive not-live samples */ + uint64_t first_dead_t, last_live_t; /* monotonic ns; 0 = never */ + uint64_t stale_max_ns; /* longest time the heartbeat had not moved, seen at a sample */ + uint64_t t_first; /* time of the first counted sample */ + uint32_t hb_last; + int have; +} SeatDiag; + +static inline void seat_diag_sample(SeatDiag *d, uint64_t t_ns, int live, uint32_t hb) { + if (!d->have) { d->have = 1; d->t_first = t_ns; d->last_change_t = t_ns; } + else { + uint64_t gap = t_ns - d->last_t; + if (gap > d->max_gap_ns) d->max_gap_ns = gap; + if (gap > 2000000u) d->late_2ms++; + if (gap > 10000000u) d->late_10ms++; + } + d->last_t = t_ns; + d->hb_last = hb; + if (live) { + d->last_change_t = t_ns; + d->last_live_t = t_ns; + d->dead_cur = 0; + } else { + if (d->dead_cur == 0) { + d->dead_runs++; + if (!d->first_dead_t) d->first_dead_t = t_ns; + } + d->dead_cur++; + if (d->dead_cur > d->dead_longest) d->dead_longest = d->dead_cur; + uint64_t age = t_ns - d->last_change_t; + if (age > d->stale_max_ns) d->stale_max_ns = age; + } +} +#endif diff --git a/tests/runtime/r15_seat_diag_test.c b/tests/runtime/r15_seat_diag_test.c new file mode 100644 index 000000000..56719735a --- /dev/null +++ b/tests/runtime/r15_seat_diag_test.c @@ -0,0 +1,42 @@ +/* Host-only test of the G15 sampler diagnostics (r15_seat_diag.h). Feeds + * synthetic sample streams and checks the diagnostics tell a stopped seat + * from a late sampler from a healthy run. No chip, no threads. */ +#include "r15_seat_diag.h" +#include + +static int fails; +#define CHECK(c) do { if (!(c)) { printf("[-] line %d: %s\n", __LINE__, #c); fails++; } } while (0) + +int main(void) { + SeatDiag d; + uint64_t t; + + /* healthy: 1000 samples 1.05 ms apart, heartbeat moves every time */ + d = (SeatDiag){0}; t = 1000000000ull; + for (int i = 0; i < 1000; i++, t += 1050000u) seat_diag_sample(&d, t, i > 0, (uint32_t)i); + CHECK(d.dead_runs == 1 && d.dead_longest == 1); /* only the first sample has no predecessor to compare */ + CHECK(d.late_2ms == 0 && d.late_10ms == 0 && d.max_gap_ns == 1050000u); + + /* seat stops: 600 live then 400 not live, sampler on time (the SEQ-06 shape) */ + d = (SeatDiag){0}; t = 1000000000ull; + for (int i = 0; i < 1000; i++, t += 1050000u) seat_diag_sample(&d, t, i >= 1 && i < 600, 7u); + CHECK(d.dead_runs == 2 && d.dead_longest == 400 && d.dead_cur == 400); + CHECK(d.late_10ms == 0 && d.max_gap_ns == 1050000u); + CHECK(d.first_dead_t == 1000000000ull); /* the opening sample */ + CHECK(d.last_live_t == 1000000000ull + 599u * 1050000ull); + CHECK(d.stale_max_ns == 399u * 1050000ull + 1050000ull); + + /* starved sampler, seat fine: every sample live but 50 ms apart */ + d = (SeatDiag){0}; t = 1000000000ull; + for (int i = 0; i < 100; i++, t += 50000000ull) seat_diag_sample(&d, t, i > 0, (uint32_t)i); + CHECK(d.late_10ms == 99 && d.late_2ms == 99 && d.max_gap_ns == 50000000ull); + CHECK(d.dead_longest == 1); + + /* scattered: a not-live sample every 10th, never two in a row */ + d = (SeatDiag){0}; t = 1000000000ull; + for (int i = 0; i < 1000; i++, t += 1050000u) seat_diag_sample(&d, t, i > 0 && i % 10 != 0, 1u); + CHECK(d.dead_runs == 100 && d.dead_longest == 1 && d.late_10ms == 0); + + printf("failures %d\n", fails); + return fails != 0; +} diff --git a/tests/runtime/rx_r15_perf.c b/tests/runtime/rx_r15_perf.c index 70cbe875f..ec0d82511 100644 --- a/tests/runtime/rx_r15_perf.c +++ b/tests/runtime/rx_r15_perf.c @@ -20,6 +20,7 @@ */ #include "rx_r15_rig.h" #include "r15_measure.h" +#include "r15_seat_diag.h" #include "runtime/rx_generation.h" #include @@ -128,7 +129,10 @@ static void thermal_wait(void) { /* One accumulator per open window (windows may overlap), plus whole-process * residency totals that are never reset. */ -typedef struct { uint64_t samples, live, slot_sum, slot_max, inflight_sum, inflight_max, claims_max; } SampSnap; +typedef struct { + uint64_t samples, live, slot_sum, slot_max, inflight_sum, inflight_max, claims_max; + SeatDiag d; /* sampler lateness and not-live runs (r15_seat_diag.h); does not feed G15 */ +} SampSnap; #define SAMP_ACC 4 typedef struct { @@ -164,6 +168,7 @@ static void *sampler_main(void *arg) { int counted = s->have_last; s->last = hb; s->have_last = 1; + uint64_t t_now = r15_now_ns(); if (!counted) continue; pthread_mutex_lock(&s->mu); for (int i = 0; i <= SAMP_ACC; i++) { @@ -171,6 +176,7 @@ static void *sampler_main(void *arg) { if (i < SAMP_ACC && !s->active[i]) continue; a->samples++; a->live += (uint64_t)live; + seat_diag_sample(&a->d, t_now, live, (uint32_t)hb); a->slot_sum += slots; if (slots > a->slot_max) a->slot_max = slots; a->inflight_sum += infl; @@ -205,9 +211,15 @@ static SampSnap samp_close(int k) { static void rec_samp(const char *key, const SampSnap *x) { fprintf(g_out.f, ",\"%s\":{\"silicon\":%d,\"intervals\":%" PRIu64 ",\"seat_live\":%" PRIu64 ",\"slot_sum\":%" PRIu64 ",\"slot_max\":%" PRIu64 ",\"inflight_sum\":%" PRIu64 - ",\"inflight_max\":%" PRIu64 ",\"claims_max\":%" PRIu64 "}", + ",\"inflight_max\":%" PRIu64 ",\"claims_max\":%" PRIu64 + ",\"diag\":{\"late_2ms\":%" PRIu64 ",\"late_10ms\":%" PRIu64 ",\"max_gap_ns\":%" PRIu64 + ",\"dead_runs\":%" PRIu64 ",\"dead_longest\":%" PRIu64 ",\"dead_at_end\":%" PRIu64 + ",\"t_first\":%" PRIu64 ",\"t_last\":%" PRIu64 ",\"first_dead_t\":%" PRIu64 + ",\"last_live_t\":%" PRIu64 ",\"stale_max_ns\":%" PRIu64 "}}", key, g_samp.silicon, x->samples, x->live, x->slot_sum, x->slot_max, x->inflight_sum, - x->inflight_max, x->claims_max); + x->inflight_max, x->claims_max, x->d.late_2ms, x->d.late_10ms, x->d.max_gap_ns, x->d.dead_runs, + x->d.dead_longest, x->d.dead_cur, x->d.t_first, x->d.last_t, x->d.first_dead_t, x->d.last_live_t, + x->d.stale_max_ns); } static void rec_residency(void) { diff --git a/tools/.crumb b/tools/.crumb index 15504fa2f..b7921a221 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -56,14 +56,14 @@ } ], "children_root": "sha256:3f9857a8b0946837f5556bcea0b4deaddd3a5aa3a60a31aa08ac917ac69d19f9", - "compiled_at": "2026-10-05T15:28:49Z", + "compiled_at": "2026-10-05T16:04:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:546da8393e444a620edd23486a7a66b483539dd10a4c273e4bd41deacb2d218d", + "digest": "sha256:43dd39270ced0e0209a37d3b7d37376581f4d54f1e436662472c232c08f1c633", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 133, - "generated_at_commit": "50d535b45ee24fa8bec28ac3248be7209b6a07b0", - "source_tree": "sha256:bb5621de70ca077dc05c32d77923be3d1d42ee37cb200e3dbcfadf634752dc12" + "generated_at_commit": "82d9dc09c6c3a673409daf32fb69c70be8bf9850", + "source_tree": "sha256:404eefcebb1075edffd1235fc2d5dd79fdb89773605c22a3aa08dab826e2ceb9" }, "owner_lane": "", "provenance": { diff --git a/tools/r15_machine_state.sh b/tools/r15_machine_state.sh index 8e14c4042..dcd3912cd 100755 --- a/tools/r15_machine_state.sh +++ b/tools/r15_machine_state.sh @@ -10,7 +10,8 @@ # reader gives valid samples, 5 if not # tools/r15_machine_state.sh start begin 1 s sampling # tools/r15_machine_state.sh mark -# tools/r15_machine_state.sh stop end sampling, write summary +# tools/r15_machine_state.sh stop end sampling, write summary (+ kernel-xid.txt) +# tools/r15_machine_state.sh xid-scan Xid lines from the kernel log # # The operating system's reported frequency does not show the sustained X925 # clock cut seen on 2026-09-28 (scaling_cur_freq stayed at 3.9 GHz while the @@ -118,6 +119,37 @@ energy_preflight() { return 0 } if [ "${1:-}" = energy-preflight ]; then energy_preflight; exit $?; fi + +# xid-scan : NVRM Xid lines from the kernel log in +# that span. Window 2 of CAND-1 had a GPU fault (Xid 109, CTX SWITCH TIMEOUT, +# 08:08:16 CDT) that the runner's xid-count.txt reported as 0, because it used +# `dmesg`, which this account may not read; the failed read was hidden and +# counted as "none". journalctl -k is readable here. A failed read is reported +# as XID_LOG_UNREADABLE (exit 4), never as zero. Observability only. +# journalctl answers "-- No entries --" with exit 0 to an account without journal +# access, so a readable-looking empty window is not proof of no Xid: the kernel +# log of this boot must itself read non-empty first (it never is, on a real boot). +# R15_KLOG_FILE= reads a saved log instead of journalctl (tests). +# R15_KLOG_PROBE_FILE= stands in for that boot-log probe (tests). +xid_scan() { + local out rc + if [ -z "${R15_KLOG_FILE:-}" ] || [ -n "${R15_KLOG_PROBE_FILE+x}" ]; then + local probe + if [ -n "${R15_KLOG_PROBE_FILE+x}" ]; then probe=$(cat "$R15_KLOG_PROBE_FILE" 2>/dev/null) + else probe=$(journalctl -k -b --no-pager -q -n 1 -o cat 2>/dev/null); fi + if [ -z "$probe" ]; then + echo "XID_LOG_UNREADABLE: the kernel log of this boot reads empty (no journal access?)"; return 4 + fi + fi + if [ -n "${R15_KLOG_FILE:-}" ]; then out=$(cat "$R15_KLOG_FILE" 2>&1); rc=$? + else out=$(journalctl -k --no-pager -o short-iso --since "@$1" --until "@$2" 2>&1); rc=$?; fi + if [ $rc -ne 0 ]; then echo "XID_LOG_UNREADABLE: $(printf '%s' "$out" | head -1)"; return 4; fi + printf '%s\n' "$out" | grep -i 'NVRM: Xid' + echo "xid lines: $(printf '%s\n' "$out" | grep -ci 'NVRM: Xid')" + return 0 +} +if [ "${1:-}" = xid-scan ]; then xid_scan "${2:?since epoch}" "${3:?until epoch}"; exit $?; fi + CMD=${1:?preflight, start, mark or stop} OUT=${2:?out dir} mkdir -p "$OUT" @@ -149,6 +181,7 @@ preflight) ;; start) date -u +%FT%TZ > "$OUT/machine-state-start.txt" + date +%s > "$OUT/.start.epoch" for c in /sys/devices/system/cpu/cpu[0-9]*; do echo "${c##*/} $(cat "$c/cpufreq/scaling_governor" 2>/dev/null) max=$(cat "$c/cpufreq/cpuinfo_max_freq" 2>/dev/null)" done >> "$OUT/machine-state-start.txt" @@ -197,6 +230,16 @@ stop) sudo -n pkill -f "perf stat -a -A -e cycles -I 1000 -x, -o $OUT/machine-perf.csv" 2>/dev/null rm -f "$OUT/$p" done + # Kernel GPU faults (Xid) during the run, from the readable kernel log. + # The scan's own verdict is kept: an unreadable log or a missing start time is + # written into kernel-xid.txt and warned about, never left as an empty file. + if [ -f "$OUT/.start.epoch" ]; then + xid_scan "$(cat "$OUT/.start.epoch")" "$(date +%s)" > "$OUT/kernel-xid.txt" 2>&1; xrc=$? + else + echo "XID_SCAN_NOT_RUN: $OUT/.start.epoch is missing" > "$OUT/kernel-xid.txt"; xrc=5 + fi + echo "xid-scan exit $xrc" >> "$OUT/kernel-xid.txt" + [ $xrc = 0 ] || echo "r15_machine_state: warning: kernel Xid scan did not complete (exit $xrc), see $OUT/kernel-xid.txt" >&2 # Summary (informative; the raw files are authoritative): per-second # cycles of each X925 core (cpus 5-9, 15-19) as GHz. A fully busy second # reads as the effective clock; a partly idle second reads lower, so the diff --git a/tools/r15_reduce.c b/tools/r15_reduce.c index 344d2821b..eaf9abb10 100644 --- a/tools/r15_reduce.c +++ b/tools/r15_reduce.c @@ -586,6 +586,40 @@ static Cmp paired(const char *num, const char *den, TrialVal f, int need_same) { return c; } +/* G15 diagnostic (observability only; G15 itself is min seat_live/intervals and + * is not touched). For the process with the lowest live fraction, say what the + * sampler's own record can tell: whether the lost samples are one long run of + * not-live samples (the seat stopped advancing its heartbeat) or scattered, + * and whether the sampler itself ran late. Data recorded before the sampler + * carried diag fields reports UNMEASURED; nothing is inferred. */ +static void o_residency_diagnostic(const J *tot, const char *name) { + if (!tot) return; + uint64_t lost = ju(tot, "intervals") - ju(tot, "seat_live"); + const J *d = jget(tot, "diag"); + o_open("worst_process_diagnostic", '{'); + o_str("process", name); + o_u("lost_samples", lost); + if (!lost) { + o_str("class", "no_loss"); + } else if (!d) { + o_str("class", "UNMEASURED"); + o_str("why", "raw evidence has no sampler diag fields; starvation, residency loss and stale reads are not distinguishable"); + } else { + uint64_t longest = ju(d, "dead_longest"); + o_str("class", longest >= 100 ? "seat_stopped_long_run" : "scattered_not_live"); + o_u("dead_runs", ju(d, "dead_runs")); + o_u("dead_longest", longest); + o_u("dead_at_end", ju(d, "dead_at_end")); + o_u("late_2ms", ju(d, "late_2ms")); + o_u("late_10ms", ju(d, "late_10ms")); + o_bool("sampler_late_observed", ju(d, "late_10ms") > 0); + o_u("max_gap_ns", ju(d, "max_gap_ns")); + o_u("stale_max_ns", ju(d, "stale_max_ns")); + if (ju(d, "first_dead_t") && ju(d, "t_first")) o_u("first_dead_after_ns", ju(d, "first_dead_t") - ju(d, "t_first")); + } + o_close('}'); +} + static void o_cmp(const char *k, const Cmp *c) { o_open(k, '{'); o_num("median_ratio", c->med); @@ -1051,23 +1085,32 @@ int main(int argc, char **argv) { /* m10 residency */ double res_min = NAN; size_t res_n = 0; + J *res_worst = NULL; /* the process behind res_min; used only for the diagnostic below */ + char res_worst_name[300] = ""; for (int i = 0; i < g_nt; i++) { J *tot = jget(g_trials[i].residency, "total"); if (!g_trials[i].silicon || !(jd(tot, "intervals") > 0)) continue; double r = jd(tot, "seat_live") / jd(tot, "intervals"); - if (isnan(res_min) || r < res_min) res_min = r; + if (isnan(res_min) || r < res_min) { + res_min = r; res_worst = tot; + snprintf(res_worst_name, sizeof res_worst_name, "%.250s", g_trials[i].file); + } res_n++; } for (int i = 0; i < g_nl2; i++) { J *tot = jget(g_l2[i].residency, "total"); if (!g_l2[i].silicon || !(jd(tot, "intervals") > 0)) continue; double r = jd(tot, "seat_live") / jd(tot, "intervals"); - if (isnan(res_min) || r < res_min) res_min = r; + if (isnan(res_min) || r < res_min) { + res_min = r; res_worst = tot; + snprintf(res_worst_name, sizeof res_worst_name, "l2-%.20s-%d", g_l2[i].config, i); + } res_n++; } o_open("m10_gpu_residency", '{'); o_num("min_fraction_live", res_min); o_u("silicon_processes", res_n); + o_residency_diagnostic(res_worst, res_worst_name); o_close('}'); have[10] = res_n > 0; /* m11 resource utilization */