From 3566bf6ce07ee5fd1890a43d779c154da357839d Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 3 Oct 2026 05:57:50 -0500 Subject: [PATCH 1/4] CHIPWAIT-2: canonical m16 wait primitive + tagged two-program doorbell Add m16/m16_gpu_wait.{h,c}: same contract as omega 6fa4d97 (fixed and wrap-safe sequence wait, monotonic clock, hard deadline never extended, stall deadline reset only on progress, barrier before every read and after PASS, same report fields and result codes) plus a failure-class helper. Host test with order-checked barrier scenario and three compile-flag mutants of the real code (make host-tests-m16). m16_concurrent now waits through it, allocates markers GPU-uncached (nvrm_alloc_gpu_uncached), follows each marker with an L2_FLUSH_DIRTY mem-op and a second marker, and prints class=submission_fail|no_progress| late_progress|wrong_marker|output_parity with the full wait report. m16_native_wait_marker(_ge) is unchanged (follow-up). Host only; no chip run. Co-Authored-By: Claude Sonnet 5.5 --- Makefile | 36 ++++ m16/m16_concurrent.c | 163 ++++++++++++++--- m16/m16_gpu_wait.c | 162 ++++++++++++++++ m16/m16_gpu_wait.h | 115 ++++++++++++ tests/run_m16_requalification.sh | 2 +- tests/test_m16_gpu_wait.c | 304 +++++++++++++++++++++++++++++++ 6 files changed, 755 insertions(+), 27 deletions(-) create mode 100644 Makefile create mode 100644 m16/m16_gpu_wait.c create mode 100644 m16/m16_gpu_wait.h create mode 100644 tests/test_m16_gpu_wait.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d39ae9e --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +# Host-only test targets for the m16 wait primitive. No GPU, no chip. +CC ?= gcc +CFLAGS ?= -O2 -Wall -Wextra -Werror +BUILD := build/m16_gpu_wait + +.PHONY: test-m16-gpu-wait mutants-m16-gpu-wait host-tests-m16 + +host-tests-m16: test-m16-gpu-wait mutants-m16-gpu-wait + +$(BUILD)/test_real: tests/test_m16_gpu_wait.c m16/m16_gpu_wait.c m16/m16_gpu_wait.h + @mkdir -p $(BUILD) + $(CC) $(CFLAGS) -I m16 tests/test_m16_gpu_wait.c m16/m16_gpu_wait.c -o $@ + +test-m16-gpu-wait: $(BUILD)/test_real + $(BUILD)/test_real + +# Three one-line compile-flag mutants of the REAL primitive. Each must make the +# host test fail, and fail in the scenario named for it. A surviving mutant +# fails this target. +# STALL_NEVER_RESETS killed by progress_resets_idle +# PROGRESS_EXTENDS_HARD killed by hard_deadline_with_progress +# NO_BARRIER killed by barrier_before_read +MUTANTS := STALL_NEVER_RESETS:progress_resets_idle \ + PROGRESS_EXTENDS_HARD:hard_deadline_with_progress \ + NO_BARRIER:barrier_before_read + +mutants-m16-gpu-wait: + @mkdir -p $(BUILD) + @set -e; for m in $(MUTANTS); do \ + flag=$${m%%:*}; scen=$${m##*:}; \ + $(CC) $(CFLAGS) -DM16_GPU_WAIT_MUT_$$flag -I m16 tests/test_m16_gpu_wait.c m16/m16_gpu_wait.c -o $(BUILD)/mut_$$flag; \ + if $(BUILD)/mut_$$flag > $(BUILD)/mut_$$flag.log 2>&1; then echo "MUTANT $$flag SURVIVED (test passed)"; exit 1; fi; \ + if ! grep -Eq "^real +$$scen +FAIL" $(BUILD)/mut_$$flag.log; then echo "MUTANT $$flag died but not in $$scen"; cat $(BUILD)/mut_$$flag.log; exit 1; fi; \ + echo "MUTANT $$flag killed by $$scen"; \ + done + @echo "M16_GPU_WAIT_MUTANTS PASS (3/3 killed)" diff --git a/m16/m16_concurrent.c b/m16/m16_concurrent.c index b9d342e..123b67a 100644 --- a/m16/m16_concurrent.c +++ b/m16/m16_concurrent.c @@ -4,22 +4,118 @@ * Sequence: * 1. Initialize two independent M16NativeContext instances (ctxA, ctxB). * 2. Allocate separate channels, GPFIFO rings, USERD, and tokens. - * 3. Allocate independent coherent markers: markerA, markerB. + * 3. Allocate independent GPU-uncached marker pages (nvrm_alloc_gpu_uncached, + * nvrm/nvrm.c:473): markerA, markerB. Each page also holds marker2 at +0x10. * 4. Submit independent work: - * Channel A -> 0x16000001 - * Channel B -> 0x16000002 + * Channel A -> 0x16000001, L2 flush, then 0x46464646 at +0x10 + * Channel B -> 0x16000002, L2 flush, then 0x46464646 at +0x10 * 5. Verify independent causality: * Both withheld -> markerA=0, markerB=0 * Ring A -> markerA=0x16000001, markerB=0 * Ring B -> markerB=0x16000002 * 6. Prove non-collision and dynamic resource independence. + * + * Waits use the canonical primitive m16/m16_gpu_wait.c: monotonic clock, hard + * 2000 ms deadline that is never extended, 1000 ms stall deadline that restarts + * only on progress, barrier before every read, PASS needs marker AND marker2. + * Every failure prints one line tagged + * class= + * followed by the full wait report. + * + * Exit codes (unchanged unless marked NEW): + * 1 init failure or enqueue failure (class submission_fail) + * 2 premature execution on withheld doorbells (wrong_marker) + * 3 markerA wait failed (no_progress / late_progress / wrong_marker) + * 4 cross-talk: B executed on A's doorbell (wrong_marker) + * 5 markerB wait failed (no_progress / late_progress / wrong_marker) + * 6 root handle collision + * 7 NEW: marker reached its value but the re-read after PASS disagrees (output_parity) + * + * The doorbell is a plain store (nvrm_ring, nvrm/nvrm.c:742, returns void), so a + * doorbell write that fails cannot be detected; one that never reaches the chip + * shows up as no_progress. */ #include "m16_native.h" +#include "m16_gpu_wait.h" #include #include #include #include +#define PAYLOAD_A 0x16000001u +#define PAYLOAD_B 0x16000002u +#define MARKER2_PAYLOAD 0x46464646u +#define MARKER2_OFF 0x10u +#define WAIT_TOTAL_MS 2000u /* hard deadline: same 2 s window as the old wait */ +#define WAIT_STALL_MS 1000u + +static void fence(void) { __asm__ volatile("dsb sy" ::: "memory"); } + +/* Marker stream: bind class, WFI release of payload at marker_va, L2_FLUSH_DIRTY + * mem-op (NVC96F_MEM_OP_A..D = 0x28..0x34, D bits 31:27 = 0x10), then a second WFI + * release of 0x46464646 at marker_va + 0x10. Same block as omega's + * src/omega_numeric_gb10.c (the C3 hardening block, "L2_FLUSH_DIRTY" comment + * above the second 0x005c packet); nvrm_mthd is nvrm/nvrm.h:112. */ +static int build_release_flushed(uint32_t *w, uint64_t marker_va, uint32_t payload, uint32_t cls) { + int n = m16_native_build_release(w, marker_va, payload, cls); + if (n < 0) return -1; + w[n++] = nvrm_mthd(0, 0x0028, 4); + w[n++] = 0; + w[n++] = 0; + w[n++] = 0; + w[n++] = (0x10u << 27); + uint64_t m2 = marker_va + MARKER2_OFF; + w[n++] = nvrm_mthd(0, 0x005c, 5); + w[n++] = (uint32_t)m2; + w[n++] = (uint32_t)(m2 >> 32); + w[n++] = MARKER2_PAYLOAD; + w[n++] = 0; + w[n++] = 0x1 | (1u << 20); + return n; +} + +static void print_report(const char *cls, const char *stage, int code, const m16_gpu_wait_report_t *r) { + fprintf(stderr, + "FAIL class=%s stage=%s exit=%d kind=%s result=%s expected=0x%08x last_marker=0x%08x " + "last_marker2=0x%08x elapsed_ms=%llu last_progress_ms=%llu " + "progress_count=%llu polls=%llu\n", + cls, stage, code, m16_gpu_wait_kind_name(r->wait_kind), m16_gpu_wait_result_name(r->result), + r->expected, r->last_observed, r->last_marker2, (unsigned long long)(r->elapsed_ns / 1000000ull), + (unsigned long long)((r->last_progress_ns - r->start_ns) / 1000000ull), + (unsigned long long)r->progress_count, (unsigned long long)r->polls); +} + +static void print_simple(const char *cls, const char *stage, int code, const char *what) { + fprintf(stderr, "FAIL class=%s stage=%s exit=%d %s\n", cls, stage, code, what); +} + +/* Wait marker==want and marker2==MARKER2_PAYLOAD; on failure print the tagged + * line and return the class's exit code, on PASS re-read both (parity). */ +static int wait_marker(volatile uint32_t *marker, uint32_t want, const char *stage, int fail_exit) { + volatile uint32_t *marker2 = (volatile uint32_t *)((volatile uint8_t *)marker + MARKER2_OFF); + m16_gpu_wait_cfg_t cfg; + m16_gpu_wait_report_t rpt; + memset(&cfg, 0, sizeof cfg); + cfg.total_timeout_ms = WAIT_TOTAL_MS; + cfg.progress_timeout_ms = WAIT_STALL_MS; + cfg.marker2 = marker2; + cfg.marker2_want = MARKER2_PAYLOAD; + if (!m16_gpu_wait_fixed(marker, want, &rpt, &cfg)) { + print_report(m16_gpu_wait_failure_class(&rpt, MARKER2_PAYLOAD), stage, fail_exit, &rpt); + return fail_exit; + } + fence(); + uint32_t m = *marker, m2 = *marker2; + if (m != want || m2 != MARKER2_PAYLOAD) { + char what[160]; + snprintf(what, sizeof what, "reread_marker=0x%08x want=0x%08x reread_marker2=0x%08x want2=0x%08x", + m, want, m2, MARKER2_PAYLOAD); + print_simple("output_parity", stage, 7, what); + return 7; + } + return 0; +} + int main(void) { printf("=== M16 CONCURRENT MULTI-CHANNEL QUALIFICATION ===\n"); @@ -42,42 +138,53 @@ int main(void) { printf("[OBSERVED] Context B: token=0x%08x gpfifo=0x%08x fifo_va=0x%lx\n", ctxB.rm.token, ctxB.rm.gpfifo, (unsigned long)ctxB.rm.fifo.va); - /* Allocate markers */ - void *cpuA = NULL, *cpuB = NULL; - uint64_t vaA = 0, vaB = 0; - if (m16_native_alloc_memory(&ctxA, 0x1000, &cpuA, &vaA) != 0 || - m16_native_alloc_memory(&ctxB, 0x1000, &cpuB, &vaB) != 0) { + /* Allocate markers: GPU-uncached, so a GPU store reaches memory instead of + * sitting in GPU L2 (was nvrm_alloc via m16_native_alloc_memory: cacheable). */ + NvrmMem memA, memB; + if (nvrm_alloc_gpu_uncached(&ctxA.rm, 0x1000, &memA) != 0 || + nvrm_alloc_gpu_uncached(&ctxB.rm, 0x1000, &memB) != 0) { fprintf(stderr, "FATAL: Failed to allocate marker memories\n"); m16_native_close(&ctxA); m16_native_close(&ctxB); return 1; } - volatile uint32_t *markerA = (volatile uint32_t *)cpuA; - volatile uint32_t *markerB = (volatile uint32_t *)cpuB; + uint64_t vaA = memA.va, vaB = memB.va; + volatile uint32_t *markerA = (volatile uint32_t *)memA.cpu; + volatile uint32_t *markerB = (volatile uint32_t *)memB.cpu; + volatile uint32_t *marker2A = (volatile uint32_t *)((volatile uint8_t *)memA.cpu + MARKER2_OFF); + volatile uint32_t *marker2B = (volatile uint32_t *)((volatile uint8_t *)memB.cpu + MARKER2_OFF); *markerA = 0; *markerB = 0; + *marker2A = 0; + *marker2B = 0; + fence(); - printf("[OBSERVED] Marker A: VA=0x%lx CPU=%p (initial=0)\n", (unsigned long)vaA, cpuA); - printf("[OBSERVED] Marker B: VA=0x%lx CPU=%p (initial=0)\n", (unsigned long)vaB, cpuB); + printf("[OBSERVED] Marker A: VA=0x%lx CPU=%p (initial=0, GPU-uncached)\n", (unsigned long)vaA, memA.cpu); + printf("[OBSERVED] Marker B: VA=0x%lx CPU=%p (initial=0, GPU-uncached)\n", (unsigned long)vaB, memB.cpu); /* Build methods */ uint32_t mthdA[32], mthdB[32]; - int nA = m16_native_build_release(mthdA, vaA, 0x16000001, ctxA.rm.compute_class); - int nB = m16_native_build_release(mthdB, vaB, 0x16000002, ctxB.rm.compute_class); + int nA = build_release_flushed(mthdA, vaA, PAYLOAD_A, ctxA.rm.compute_class); + int nB = build_release_flushed(mthdB, vaB, PAYLOAD_B, ctxB.rm.compute_class); /* Enqueue to both without ringing */ printf("\n--- ENQUEUING WORK WITHOUT DOORBELLS ---\n"); - if (m16_native_enqueue_methods(&ctxA, mthdA, (size_t)nA) != 0 || + if (nA < 0 || nB < 0 || + m16_native_enqueue_methods(&ctxA, mthdA, (size_t)nA) != 0 || m16_native_enqueue_methods(&ctxB, mthdB, (size_t)nB) != 0) { - fprintf(stderr, "FATAL: Failed to enqueue methods\n"); + print_simple("submission_fail", "enqueue", 1, "enqueue of method stream failed"); m16_native_close(&ctxA); m16_native_close(&ctxB); return 1; } usleep(50000); + fence(); printf("[OBSERVED] Withheld doorbells: markerA=0x%08x markerB=0x%08x\n", *markerA, *markerB); - if (*markerA != 0 || *markerB != 0) { - fprintf(stderr, "FATAL: Premature execution on withheld doorbells!\n"); + if (*markerA != 0 || *markerB != 0 || *marker2A != 0 || *marker2B != 0) { + char what[160]; + snprintf(what, sizeof what, "premature markerA=0x%08x markerB=0x%08x marker2A=0x%08x marker2B=0x%08x", + *markerA, *markerB, *marker2A, *marker2B); + print_simple("wrong_marker", "withheld", 2, what); m16_native_close(&ctxA); m16_native_close(&ctxB); return 2; @@ -86,16 +193,20 @@ int main(void) { /* Ring Doorbell A only */ printf("\n--- RINGING DOORBELL A ONLY ---\n"); m16_native_ring_doorbell(&ctxA); - if (m16_native_wait_marker(markerA, 0x16000001, 2000) != 0) { - fprintf(stderr, "FATAL: Timeout waiting for markerA!\n"); + int rc = wait_marker(markerA, PAYLOAD_A, "A", 3); + if (rc != 0) { m16_native_close(&ctxA); m16_native_close(&ctxB); - return 3; + return rc; } printf("[OBSERVED] After Doorbell A: markerA=0x%08x markerB=0x%08x (expected A=0x16000001, B=0x00000000)\n", *markerA, *markerB); - if (*markerB != 0) { - fprintf(stderr, "FATAL: Cross-talk detected! Channel B executed when only Doorbell A was rung!\n"); + fence(); + if (*markerB != 0 || *marker2B != 0) { + char what[120]; + snprintf(what, sizeof what, "cross-talk markerB=0x%08x marker2B=0x%08x with only doorbell A rung", + *markerB, *marker2B); + print_simple("wrong_marker", "crosstalk", 4, what); m16_native_close(&ctxA); m16_native_close(&ctxB); return 4; @@ -104,11 +215,11 @@ int main(void) { /* Ring Doorbell B */ printf("\n--- RINGING DOORBELL B ---\n"); m16_native_ring_doorbell(&ctxB); - if (m16_native_wait_marker(markerB, 0x16000002, 2000) != 0) { - fprintf(stderr, "FATAL: Timeout waiting for markerB!\n"); + rc = wait_marker(markerB, PAYLOAD_B, "B", 5); + if (rc != 0) { m16_native_close(&ctxA); m16_native_close(&ctxB); - return 5; + return rc; } printf("[OBSERVED] After Doorbell B: markerA=0x%08x markerB=0x%08x (expected A=0x16000001, B=0x16000002)\n", *markerA, *markerB); diff --git a/m16/m16_gpu_wait.c b/m16/m16_gpu_wait.c new file mode 100644 index 0000000..b2929d7 --- /dev/null +++ b/m16/m16_gpu_wait.c @@ -0,0 +1,162 @@ +#include "m16_gpu_wait.h" + +#include +#include + +static uint64_t real_now_ns(void *ctx) { + (void)ctx; + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; +} + +static void real_barrier(void *ctx) { + (void)ctx; +#if defined(__aarch64__) + __asm__ volatile("dsb sy" ::: "memory"); +#else + __atomic_thread_fence(__ATOMIC_SEQ_CST); +#endif +} + +/* Compile-flag mutants of the real code, used only by `make mutants-m16-gpu-wait`. + * Each one must be killed by tests/test_m16_gpu_wait.c. Never defined in a real build. */ +#ifdef M16_GPU_WAIT_MUT_NO_BARRIER +#define WAIT_BARRIER(fn, ctx) ((void)(fn), (void)(ctx)) +#else +#define WAIT_BARRIER(fn, ctx) (fn)(ctx) +#endif + +static void real_relax(void *ctx) { + (void)ctx; +#if defined(__aarch64__) + __asm__ volatile("yield"); +#else + __asm__ volatile("" ::: "memory"); +#endif +} + +const char *m16_gpu_wait_result_name(m16_gpu_wait_result_t r) { + switch (r) { + case M16_GPU_WAIT_PASS: return "PASS"; + case M16_GPU_WAIT_TIMEOUT: return "TIMEOUT"; + case M16_GPU_WAIT_STALLED: return "STALLED"; + case M16_GPU_WAIT_INVALID_STATE: return "INVALID_STATE"; + case M16_GPU_WAIT_ABORTED: return "ABORTED"; + default: return "UNKNOWN"; + } +} + +const char *m16_gpu_wait_kind_name(m16_gpu_wait_kind_t k) { + return k == M16_GPU_WAIT_FIXED ? "fixed" : k == M16_GPU_WAIT_SEQUENCE ? "sequence" : "unknown"; +} + +static bool wait_core(m16_gpu_wait_kind_t kind, volatile uint32_t *word, uint32_t expected, + m16_gpu_wait_report_t *rpt, const m16_gpu_wait_cfg_t *cfg) { + m16_gpu_wait_report_t local; + m16_gpu_wait_cfg_t zero; + if (!rpt) rpt = &local; + memset(rpt, 0, sizeof(*rpt)); + rpt->wait_kind = kind; + rpt->expected = expected; + if (!cfg) { + memset(&zero, 0, sizeof(zero)); + cfg = &zero; + } + + uint64_t (*now_ns)(void *) = cfg->now_ns ? cfg->now_ns : real_now_ns; + void (*barrier)(void *) = cfg->barrier ? cfg->barrier : real_barrier; + void (*relax)(void *) = cfg->relax ? cfg->relax : real_relax; + uint64_t total_ns = 1000000ull * (cfg->total_timeout_ms ? cfg->total_timeout_ms : M16_GPU_WAIT_DEFAULT_TOTAL_MS); + uint64_t stall_ns = 1000000ull * (cfg->progress_timeout_ms ? cfg->progress_timeout_ms : M16_GPU_WAIT_DEFAULT_PROGRESS_MS); + + uint64_t start = now_ns(cfg->hook_ctx); + uint64_t hard_deadline = start + total_ns; + uint64_t stall_deadline = start + stall_ns; + rpt->start_ns = start; + rpt->last_progress_ns = start; + uint64_t now = start; + bool first = true; + + /* A null word is a caller bug; report it as an invalid state, not a hang. */ + if (!word) { + rpt->result = M16_GPU_WAIT_INVALID_STATE; + return false; + } + + while (now < hard_deadline) { + uint32_t m, m2 = 0, snap[2] = {0, 0}; + if (cfg->abort && cfg->abort(cfg->hook_ctx)) { + rpt->result = M16_GPU_WAIT_ABORTED; + rpt->elapsed_ns = now - start; + return false; + } + WAIT_BARRIER(barrier, cfg->hook_ctx); + m = *word; + if (cfg->marker2) m2 = *cfg->marker2; + if (cfg->snapshot) cfg->snapshot(cfg->snapshot_ctx, snap); + rpt->polls++; + now = now_ns(cfg->hook_ctx); + + bool changed = m != rpt->last_observed || m2 != rpt->last_marker2 || + snap[0] != rpt->snap[0] || snap[1] != rpt->snap[1]; + rpt->last_observed = m; + rpt->last_marker2 = m2; + rpt->snap[0] = snap[0]; + rpt->snap[1] = snap[1]; + rpt->elapsed_ns = now - start; + + if (changed && !first) { + rpt->progress_count++; + rpt->last_progress_ns = now; +#ifndef M16_GPU_WAIT_MUT_STALL_NEVER_RESETS + stall_deadline = now + stall_ns; +#endif +#ifdef M16_GPU_WAIT_MUT_PROGRESS_EXTENDS_HARD + hard_deadline = now + total_ns; +#endif + } + bool ok = kind == M16_GPU_WAIT_FIXED ? (m == expected) : ((int32_t)(m - expected) >= 0); + if (ok && (!cfg->marker2 || m2 == cfg->marker2_want)) { + WAIT_BARRIER(barrier, cfg->hook_ctx); /* acquire: later CPU loads are ordered after the marker load */ + rpt->result = M16_GPU_WAIT_PASS; + return true; + } + if (cfg->valid && !cfg->valid(cfg->hook_ctx, m)) { + rpt->result = M16_GPU_WAIT_INVALID_STATE; + return false; + } + first = false; + if (now >= stall_deadline) { + rpt->result = M16_GPU_WAIT_STALLED; + return false; + } + relax(cfg->hook_ctx); + now = now_ns(cfg->hook_ctx); + } + rpt->elapsed_ns = now - start; + rpt->result = M16_GPU_WAIT_TIMEOUT; + return false; +} + +bool m16_gpu_wait_fixed(volatile uint32_t *word, uint32_t expected, + m16_gpu_wait_report_t *rpt, const m16_gpu_wait_cfg_t *cfg) { + return wait_core(M16_GPU_WAIT_FIXED, word, expected, rpt, cfg); +} + +bool m16_gpu_wait_sequence(volatile uint32_t *word, uint32_t target, + m16_gpu_wait_report_t *rpt, const m16_gpu_wait_cfg_t *cfg) { + return wait_core(M16_GPU_WAIT_SEQUENCE, word, target, rpt, cfg); +} + +const char *m16_gpu_wait_failure_class(const m16_gpu_wait_report_t *r, uint32_t m2_want) { + if (r->result == M16_GPU_WAIT_INVALID_STATE) return "wrong_marker"; + if (r->result == M16_GPU_WAIT_STALLED) { + if (r->last_observed != 0 && r->last_observed != r->expected) return "wrong_marker"; + if (r->last_marker2 != 0 && r->last_marker2 != m2_want) return "wrong_marker"; + } + if (r->progress_count > 0 || r->last_observed == r->expected || + (m2_want != 0 && r->last_marker2 == m2_want)) + return "late_progress"; + return "no_progress"; +} diff --git a/m16/m16_gpu_wait.h b/m16/m16_gpu_wait.h new file mode 100644 index 0000000..7769fff --- /dev/null +++ b/m16/m16_gpu_wait.h @@ -0,0 +1,115 @@ +#ifndef M16_GPU_WAIT_H +#define M16_GPU_WAIT_H + +/* Shared completion wait for words the GPU writes to host-visible memory. + * + * Pure C, no NVRM dependency, so the host unit test can drive it with fake + * memory and a fake clock. + * + * Two wait kinds, never one ambiguous wait: + * m16_gpu_wait_fixed the word must equal `expected` exactly. A value + * that overshoots is NOT success. + * m16_gpu_wait_sequence the word is a free-running u32 counter (for + * example dispatch ids). Success when it has reached + * or passed `target` in serial-number order, i.e. + * (int32_t)(observed - target) >= 0, so it is + * correct across the 0xffffffff -> 0 wrap. Valid + * while the counter is less than 2^31 ahead. + * + * Two bounds, both on CLOCK_MONOTONIC in nanoseconds: + * total_timeout_ms hard deadline from the start; never extended. A device + * that advances occasionally still hits it (TIMEOUT). + * progress_timeout_ms stall deadline; restarts only when a watched word + * (word, marker2, snapshot words) changes (STALLED). + * + * Memory visibility: a barrier (dsb sy on AArch64, a full fence elsewhere) runs + * before every read of the watched words and once more, after the success + * observation, before returning PASS. After PASS, the CPU loads issued by the + * caller are ordered after the marker load. That is ordering only. It does not + * make a cached CPU mapping coherent with GPU writes and it does not flush the + * GPU L2: the marker page must still be GPU-uncached and the producing work must + * flush (WFI marker, L2_FLUSH_DIRTY mem-op, second WFI marker; see + * m16/m16_concurrent.c). The timer does not fix visibility. + * + * Same contract as omega's src/omega_gpu_wait.h (omega 6fa4d97, PR omega#232). + * Physics cannot include omega code, so this is the canonical copy; omega's + * becomes a thin wrapper in a later cut. m16_native_wait_marker(_ge) is not + * converted yet (follow-up). + * + * If cfg->marker2 is set, PASS also requires *marker2 == marker2_want (read + * output only after both). */ + +#include +#include + +typedef enum { + M16_GPU_WAIT_FIXED = 1, + M16_GPU_WAIT_SEQUENCE = 2 +} m16_gpu_wait_kind_t; + +typedef enum { + M16_GPU_WAIT_PASS = 0, + M16_GPU_WAIT_TIMEOUT = 1, /* hard total deadline */ + M16_GPU_WAIT_STALLED = 2, /* no progress for progress_timeout_ms */ + M16_GPU_WAIT_INVALID_STATE = 3, /* cfg->valid rejected an observed value */ + M16_GPU_WAIT_ABORTED = 4 /* cfg->abort asked to stop */ +} m16_gpu_wait_result_t; + +typedef struct { + m16_gpu_wait_kind_t wait_kind; + m16_gpu_wait_result_t result; + uint32_t expected; /* fixed value or sequence target */ + uint32_t last_observed; /* last value read from the watched word */ + uint32_t last_marker2; /* last value read from marker2 (0 when unused) */ + uint32_t snap[2]; /* last values from the snapshot callback */ + uint64_t start_ns; + uint64_t elapsed_ns; + uint64_t last_progress_ns; /* time of the last observed change (start if none) */ + uint64_t progress_count; /* observed changes after the first read */ + uint64_t polls; +} m16_gpu_wait_report_t; + +typedef struct { + uint32_t total_timeout_ms; /* 0 means the default, 600000 */ + uint32_t progress_timeout_ms; /* 0 means the default, 5000 */ + volatile uint32_t *marker2; + uint32_t marker2_want; + /* Optional: fill two extra words that count as progress when they change + * (for example GP_PUT and a semaphore). Called once per poll. */ + void (*snapshot)(void *ctx, uint32_t out[2]); + void *snapshot_ctx; + /* Optional: return false to declare the observed word out of order. */ + bool (*valid)(void *ctx, uint32_t observed); + /* Optional: return true to stop the wait (ABORTED). */ + bool (*abort)(void *ctx); + /* Test hooks. NULL means the real ones (CLOCK_MONOTONIC, dsb, yield). + * hook_ctx is passed to now_ns, barrier, relax, valid and abort. */ + uint64_t (*now_ns)(void *ctx); + void (*barrier)(void *ctx); + void (*relax)(void *ctx); + void *hook_ctx; +} m16_gpu_wait_cfg_t; + +#define M16_GPU_WAIT_DEFAULT_TOTAL_MS 600000u +#define M16_GPU_WAIT_DEFAULT_PROGRESS_MS 5000u + +/* Both return true on PASS. rpt and cfg may be NULL (cfg NULL means defaults). */ +bool m16_gpu_wait_fixed(volatile uint32_t *word, uint32_t expected, + m16_gpu_wait_report_t *rpt, const m16_gpu_wait_cfg_t *cfg); +bool m16_gpu_wait_sequence(volatile uint32_t *word, uint32_t target, + m16_gpu_wait_report_t *rpt, const m16_gpu_wait_cfg_t *cfg); + +/* Failure class of a failed wait, for tagged test output (additive, not in omega's copy): + * "wrong_marker" INVALID_STATE, or the wait STALLED on a nonzero value other + * than the expected one (word or marker2) + * "late_progress" something moved (progress_count > 0, or the word already held + * its value but marker2 never arrived) yet the wait did not finish + * (hard TIMEOUT while still moving, or stalled after moving) + * "no_progress" word and marker2 never left 0 + * Call only on a report whose result is not PASS. marker2_want is 0 when unused. */ +const char *m16_gpu_wait_failure_class(const m16_gpu_wait_report_t *r, uint32_t marker2_want); + +const char *m16_gpu_wait_result_name(m16_gpu_wait_result_t r); +const char *m16_gpu_wait_kind_name(m16_gpu_wait_kind_t k); + +#endif diff --git a/tests/run_m16_requalification.sh b/tests/run_m16_requalification.sh index d7ada4d..a1e13be 100755 --- a/tests/run_m16_requalification.sh +++ b/tests/run_m16_requalification.sh @@ -56,7 +56,7 @@ echo -e "\n[*] Step 1: Compiling M16 binaries..." -I./third_party/nvidia-open-580.173.02/kernel-open/common/inc \ -I./third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \ -I./third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include \ - nvrm/nvrm.c m16/m16_native.c m16/m16_concurrent.c -o m16/m16_concurrent + nvrm/nvrm.c m16/m16_native.c m16/m16_gpu_wait.c m16/m16_concurrent.c -o m16/m16_concurrent } > "$EVIDENCE_DIR/build.log" 2>&1 if [ -x m16/m16_requalify ] && [ -x m16/m16_concurrent ]; then diff --git a/tests/test_m16_gpu_wait.c b/tests/test_m16_gpu_wait.c new file mode 100644 index 0000000..f4f1ba8 --- /dev/null +++ b/tests/test_m16_gpu_wait.c @@ -0,0 +1,304 @@ +/* Host test for src/m16_gpu_wait.c: fake memory, fake clock, no GPU. + * Every scenario runs against the real primitive (must behave) and against + * mutants (a naive wall-clock loop, a fixed wait that accepts overshoot, a + * sequence wait with an unsigned compare). Each mutant must be killed by the + * scenarios named for it, otherwise this test fails. */ +#include "m16_gpu_wait.h" + +#include +#include + +typedef struct { + uint64_t t_ns; + uint64_t step_ns; /* clock advance per relax */ + uint64_t relaxes; + uint64_t barriers; + uint64_t at[32]; + volatile uint32_t *target[32]; + uint32_t value[32]; + int nsched; + uint32_t invalid_value; /* valid() rejects this value when nonzero */ + int abort_at; /* abort() true once relaxes >= abort_at when nonzero */ + uint64_t bar_at; /* the bar_at-th barrier call lands bar_value in bar_target (a GPU write that becomes visible at the fence) */ + volatile uint32_t *bar_target; + uint32_t bar_value; +} Fake; + +static uint64_t fk_now(void *c) { return ((Fake *)c)->t_ns; } +static void fk_barrier(void *c) { + Fake *f = c; + f->barriers++; + if (f->bar_at && f->barriers == f->bar_at) *f->bar_target = f->bar_value; +} +static void fk_relax(void *c) { + Fake *f = c; + f->relaxes++; + f->t_ns += f->step_ns; + for (int i = 0; i < f->nsched; i++) + if (f->at[i] == f->relaxes) *f->target[i] = f->value[i]; +} +static bool fk_valid(void *c, uint32_t v) { return !((Fake *)c)->invalid_value || v != ((Fake *)c)->invalid_value; } +static bool fk_abort(void *c) { Fake *f = c; return f->abort_at && f->relaxes >= (uint64_t)f->abort_at; } + +typedef bool (*WaitFn)(volatile uint32_t *, uint32_t, m16_gpu_wait_report_t *, const m16_gpu_wait_cfg_t *); + +/* Mutants. mode 0: naive wall clock (single deadline, unsigned <, no progress + * tracking, no marker2, no barrier, no report). mode 1: exact for sequence too + * is not needed; mode "fixed_ge": signed >= for a fixed wait. mode "seq_unsigned": + * unsigned >= for a sequence wait. The last two keep everything else correct. */ +static bool naive_wait(volatile uint32_t *word, uint32_t want, m16_gpu_wait_report_t *rpt, + const m16_gpu_wait_cfg_t *cfg) { + uint64_t start = cfg->now_ns(cfg->hook_ctx); + uint64_t lim = 1000000ull * cfg->progress_timeout_ms; + if (rpt) memset(rpt, 0, sizeof(*rpt)); + while (*word < want) { + if (cfg->now_ns(cfg->hook_ctx) - start >= lim) return false; + cfg->relax(cfg->hook_ctx); + } + return true; +} +static bool mut_loop(int cmp, volatile uint32_t *w, uint32_t want, m16_gpu_wait_report_t *rpt, + const m16_gpu_wait_cfg_t *cfg, m16_gpu_wait_kind_t kind) { + /* Correct kind-aware wait with one comparison replaced; delegate the rest + * to the real primitive by wrapping the watched value would be circular, so + * implement the minimal real loop here. */ + uint64_t start = cfg->now_ns(cfg->hook_ctx), last = start; + uint64_t stall = 1000000ull * cfg->progress_timeout_ms; + uint32_t prev = *w; + if (rpt) { memset(rpt, 0, sizeof(*rpt)); rpt->wait_kind = kind; rpt->expected = want; } + for (;;) { + cfg->barrier(cfg->hook_ctx); + uint32_t m = *w, m2 = cfg->marker2 ? *cfg->marker2 : 0; + bool ok = cmp == 0 ? m == want : cmp == 1 ? (int32_t)(m - want) >= 0 : m >= want; + if (rpt) { rpt->last_observed = m; rpt->last_marker2 = m2; } + if (ok && (!cfg->marker2 || m2 == cfg->marker2_want)) { + cfg->barrier(cfg->hook_ctx); + if (rpt) rpt->result = M16_GPU_WAIT_PASS; + return true; + } + uint64_t now = cfg->now_ns(cfg->hook_ctx); + if (m != prev) { prev = m; last = now; if (rpt) rpt->progress_count++; } + if (now - last >= stall) { if (rpt) rpt->result = M16_GPU_WAIT_STALLED; return false; } + cfg->relax(cfg->hook_ctx); + } +} +static bool mut_fixed_ge(volatile uint32_t *w, uint32_t v, m16_gpu_wait_report_t *r, const m16_gpu_wait_cfg_t *c) { + return mut_loop(1, w, v, r, c, M16_GPU_WAIT_FIXED); +} +static bool mut_seq_unsigned(volatile uint32_t *w, uint32_t v, m16_gpu_wait_report_t *r, const m16_gpu_wait_cfg_t *c) { + return mut_loop(2, w, v, r, c, M16_GPU_WAIT_SEQUENCE); +} + +static int g_fail, g_checks, g_quiet; +#define CHECK(c, ...) do { g_checks++; if (!(c)) { g_fail++; if (!g_quiet) { printf(" FAIL: " __VA_ARGS__); printf("\n"); } } } while (0) + +static void setup(Fake *f, m16_gpu_wait_cfg_t *cfg) { + memset(f, 0, sizeof(*f)); + f->step_ns = 1000000ull; /* 1 ms per poll */ + memset(cfg, 0, sizeof(*cfg)); + cfg->progress_timeout_ms = 100; + cfg->total_timeout_ms = 100000; + cfg->now_ns = fk_now; + cfg->barrier = fk_barrier; + cfg->relax = fk_relax; + cfg->valid = fk_valid; + cfg->abort = fk_abort; + cfg->hook_ctx = f; +} +static void sched(Fake *f, uint64_t at, volatile uint32_t *t, uint32_t v) { + f->at[f->nsched] = at; f->target[f->nsched] = t; f->value[f->nsched] = v; f->nsched++; +} + +enum { S_NEVER, S_LATE, S_MARKER2, S_SEQ_WRAP, S_PROGRESS_RESETS, S_BARRIER, S_HARD_DEADLINE, + S_FIXED_OVERSHOOT, S_INVALID, S_ABORT, S_CLASSES, S_COUNT }; +static const char *names[S_COUNT] = {"never_written", "written_late", "marker2_gate", "seq_wrap32", + "progress_resets_idle", "barrier_before_read", "hard_deadline_with_progress", + "fixed_overshoot", "invalid_state", "abort", "failure_classes"}; + +/* Returns failed checks. fx and sq are the fixed and sequence implementations. */ +static int scenario(const char *name, WaitFn fx, WaitFn sq, int which) { + volatile uint32_t w = 0, w2 = 0; + Fake f; + m16_gpu_wait_cfg_t cfg; + m16_gpu_wait_report_t r; + int before = g_fail; + bool ok; + setup(&f, &cfg); + + switch (which) { + case S_NEVER: + ok = sq(&w, 5, &r, &cfg); + CHECK(!ok, "%s: never-written marker must not pass", name); + CHECK(r.result == M16_GPU_WAIT_STALLED, "%s: result STALLED (got %d)", name, r.result); + CHECK(r.last_observed == 0 && r.expected == 5 && r.wait_kind == M16_GPU_WAIT_SEQUENCE, + "%s: report carries kind/expected/last-seen 0", name); + CHECK(r.elapsed_ns >= 100000000ull && r.progress_count == 0, "%s: elapsed %llu progress %llu", name, + (unsigned long long)r.elapsed_ns, (unsigned long long)r.progress_count); + break; + case S_LATE: + sched(&f, 60, &w, 7); + ok = fx(&w, 7, &r, &cfg); + CHECK(ok && r.result == M16_GPU_WAIT_PASS && r.last_observed == 7, "%s: late fixed marker seen", name); + CHECK(r.progress_count == 1 && r.last_progress_ns > r.start_ns, "%s: progress recorded", name); + break; + case S_MARKER2: + cfg.marker2 = &w2; + cfg.marker2_want = 0x46464646u; + sched(&f, 10, &w, 3); + ok = fx(&w, 3, &r, &cfg); + CHECK(!ok, "%s: marker without marker2 must not pass", name); + CHECK(r.last_observed == 3 && r.last_marker2 == 0, "%s: report shows marker 3, marker2 0", name); + w = 0; w2 = 0; setup(&f, &cfg); + cfg.marker2 = &w2; + cfg.marker2_want = 0x46464646u; + sched(&f, 10, &w, 3); + sched(&f, 20, &w2, 0x46464646u); + ok = fx(&w, 3, &r, &cfg); + CHECK(ok && r.last_marker2 == 0x46464646u, "%s: both markers pass", name); + break; + case S_SEQ_WRAP: { + static const uint32_t tg[4] = {0xfffffffeu, 0xffffffffu, 0u, 1u}; + for (int i = 0; i < 4; i++) { + w = tg[i] - 1u; /* one step behind, wrapping through 0 */ + setup(&f, &cfg); + sched(&f, 10, &w, tg[i]); + ok = sq(&w, tg[i], &r, &cfg); + CHECK(ok, "%s: reaches target %08x from %08x", name, tg[i], tg[i] - 1u); + } + w = 3; setup(&f, &cfg); + ok = sq(&w, 0xffffffffu, &r, &cfg); + CHECK(ok, "%s: 3 is past 0xffffffff", name); + w = 0; setup(&f, &cfg); + ok = sq(&w, 0xfffffffeu, &r, &cfg); + CHECK(ok, "%s: 0 is past 0xfffffffe", name); + w = 0xfffffff0u; setup(&f, &cfg); + ok = sq(&w, 0xffffffffu, &r, &cfg); + CHECK(!ok, "%s: 0xfffffff0 is before 0xffffffff", name); + w = 0xfffffffeu; setup(&f, &cfg); + ok = sq(&w, 1, &r, &cfg); + CHECK(!ok, "%s: 0xfffffffe is before 1", name); + break; + } + case S_PROGRESS_RESETS: + for (int i = 0; i < 4; i++) sched(&f, 60u * (i + 1), &w, (uint32_t)(i + 1)); + ok = sq(&w, 4, &r, &cfg); /* 240 ms total, 60 ms gaps, 100 ms stall bound */ + CHECK(ok, "%s: steady progress must not stall", name); + CHECK(r.progress_count == 4, "%s: progress_count %llu", name, (unsigned long long)r.progress_count); + break; + case S_BARRIER: + /* Order check: the value lands when the 3rd barrier runs. A barrier before + * every read means the read right after it sees the value: polls == 3. + * A barrier after the read (or none) cannot pass in 3 polls. The extra + * barrier after PASS (acquire) makes barriers == polls + 1. */ + f.bar_at = 3; f.bar_target = &w; f.bar_value = 1; + ok = sq(&w, 1, &r, &cfg); + CHECK(ok && r.polls == 3 && f.barriers == 4, "%s: barrier-before-read order: polls %llu barriers %llu (want 3, 4)", name, + (unsigned long long)r.polls, (unsigned long long)f.barriers); + break; + case S_HARD_DEADLINE: + cfg.total_timeout_ms = 200; + for (int i = 0; i < 30; i++) sched(&f, (uint64_t)(20 * (i + 1)), &w, (uint32_t)(i + 1)); + ok = sq(&w, 99, &r, &cfg); /* moves every 20 ms, never arrives */ + CHECK(!ok && r.result == M16_GPU_WAIT_TIMEOUT, "%s: hard deadline TIMEOUT (got %d)", name, r.result); + CHECK(r.progress_count > 3, "%s: progress was occurring (%llu)", name, (unsigned long long)r.progress_count); + break; + case S_FIXED_OVERSHOOT: + sched(&f, 10, &w, 5); /* jumps past the fixed value 3 */ + ok = fx(&w, 3, &r, &cfg); + CHECK(!ok, "%s: fixed wait must not accept overshoot 5 for 3", name); + CHECK(r.result == M16_GPU_WAIT_STALLED && r.last_observed == 5, "%s: stalled, saw 5", name); + w = 0; setup(&f, &cfg); + sched(&f, 10, &w, 5); + ok = sq(&w, 3, &r, &cfg); + CHECK(ok, "%s: sequence wait accepts 5 for target 3", name); + break; + case S_INVALID: + f.invalid_value = 9; + sched(&f, 10, &w, 9); + ok = sq(&w, 20, &r, &cfg); + CHECK(!ok && r.result == M16_GPU_WAIT_INVALID_STATE && r.last_observed == 9, + "%s: invalid value reported (got %d)", name, r.result); + break; + case S_ABORT: + f.abort_at = 7; + ok = sq(&w, 20, &r, &cfg); + CHECK(!ok && r.result == M16_GPU_WAIT_ABORTED, "%s: abort reported (got %d)", name, r.result); + break; + case S_CLASSES: { + const char *cl; + ok = fx(&w, 5, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0); + CHECK(!ok && !strcmp(cl, "no_progress"), "%s: never moved -> no_progress (got %s)", name, cl); + setup(&f, &cfg); w = 0; + cfg.total_timeout_ms = 200; + for (int i = 0; i < 30; i++) sched(&f, (uint64_t)(20 * (i + 1)), &w, (uint32_t)(i + 1)); + ok = fx(&w, 99, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0); + CHECK(!ok && !strcmp(cl, "late_progress"), "%s: moved, missed hard deadline -> late_progress (got %s)", name, cl); + setup(&f, &cfg); w = 0; + sched(&f, 10, &w, 5); + ok = fx(&w, 3, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0); + CHECK(!ok && !strcmp(cl, "wrong_marker"), "%s: unexpected value -> wrong_marker (got %s)", name, cl); + setup(&f, &cfg); w = 0; w2 = 0; + cfg.marker2 = &w2; cfg.marker2_want = 0x46464646u; + sched(&f, 10, &w, 3); + ok = fx(&w, 3, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0x46464646u); + CHECK(!ok && !strcmp(cl, "late_progress"), "%s: marker ok, marker2 missing -> late_progress (got %s)", name, cl); + setup(&f, &cfg); w = 0; w2 = 0; + cfg.marker2 = &w2; cfg.marker2_want = 0x46464646u; + sched(&f, 10, &w, 3); + sched(&f, 12, &w2, 0x11u); + ok = fx(&w, 3, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0x46464646u); + CHECK(!ok && !strcmp(cl, "wrong_marker"), "%s: marker2 wrong value -> wrong_marker (got %s)", name, cl); + break; + } + } + return g_fail - before; +} + +typedef struct { + const char *label; + WaitFn fx, sq; + unsigned must_kill; /* bitmask of scenarios that must kill this mutant */ +} Mutant; + +int main(void) { + for (int s = 0; s < S_COUNT; s++) { + int bad = scenario(names[s], m16_gpu_wait_fixed, m16_gpu_wait_sequence, s); + printf("real %-28s %s\n", names[s], bad ? "FAIL" : "ok"); + } + int real_fail = g_fail; + + const Mutant muts[] = { + {"naive_wall_clock", naive_wait, naive_wait, (1u << S_COUNT) - 1u}, + {"fixed_accepts_overshoot", mut_fixed_ge, m16_gpu_wait_sequence, 1u << S_FIXED_OVERSHOOT}, + {"seq_unsigned_compare", m16_gpu_wait_fixed, mut_seq_unsigned, 1u << S_SEQ_WRAP}, + }; + int saved = g_fail, kill_total = 0, kill_need = 0; + g_quiet = 1; + for (unsigned m = 0; m < sizeof(muts) / sizeof(muts[0]); m++) { + unsigned killed = 0; + for (int s = 0; s < S_COUNT; s++) { + if (scenario(names[s], muts[m].fx, muts[m].sq, s) > 0) killed |= 1u << s; + } + g_fail = saved; + g_quiet = 0; + for (int s = 0; s < S_COUNT; s++) { + if (!(muts[m].must_kill & (1u << s))) continue; + kill_need++; + g_checks++; + if (killed & (1u << s)) kill_total++; + else { g_fail++; printf(" FAIL: mutant %s survived scenario %s\n", muts[m].label, names[s]); } + } + printf("mutant %-26s killed mask %03x (required %03x)\n", muts[m].label, killed, muts[m].must_kill); + saved = g_fail; + g_quiet = 1; + } + g_quiet = 0; + printf("m16_gpu_wait: checks=%d real_failures=%d required_kills=%d/%d\n", g_checks, real_fail, kill_total, kill_need); + printf("%s\n", g_fail ? "M16_GPU_WAIT_HOST FAIL" : "M16_GPU_WAIT_HOST PASS"); + return g_fail ? 1 : 0; +} From 158359c6ecff82f05e40d027cb10402b954df599 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 3 Oct 2026 06:00:45 -0500 Subject: [PATCH 2/4] CHIPWAIT-2: stall bound equals hard bound; class independent of result; final page parity Co-Authored-By: Claude Sonnet 5.5 --- m16/m16_concurrent.c | 24 ++++++++++++++++++++---- m16/m16_gpu_wait.c | 7 +++---- m16/m16_gpu_wait.h | 6 ++++-- tests/test_m16_gpu_wait.c | 17 +++++++++++++++-- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/m16/m16_concurrent.c b/m16/m16_concurrent.c index 123b67a..53f36af 100644 --- a/m16/m16_concurrent.c +++ b/m16/m16_concurrent.c @@ -16,8 +16,8 @@ * 6. Prove non-collision and dynamic resource independence. * * Waits use the canonical primitive m16/m16_gpu_wait.c: monotonic clock, hard - * 2000 ms deadline that is never extended, 1000 ms stall deadline that restarts - * only on progress, barrier before every read, PASS needs marker AND marker2. + * 2000 ms deadline that is never extended, 2000 ms stall deadline (equal, so the + * old 2 s pass window is unchanged) that restarts only on progress, barrier before every read, PASS needs marker AND marker2. * Every failure prints one line tagged * class= * followed by the full wait report. @@ -29,7 +29,11 @@ * 4 cross-talk: B executed on A's doorbell (wrong_marker) * 5 markerB wait failed (no_progress / late_progress / wrong_marker) * 6 root handle collision - * 7 NEW: marker reached its value but the re-read after PASS disagrees (output_parity) + * 7 NEW: output_parity. Either a marker re-read right after its PASS disagrees + * with the value just accepted (nearly a tautology, it only catches a torn + * or unstable word), or, new tightening, the final check that both pages still + * hold their payload and 0x46464646 after B completed fails. + * This test has no output buffer; the markers are the output. * * The doorbell is a plain store (nvrm_ring, nvrm/nvrm.c:742, returns void), so a * doorbell write that fails cannot be detected; one that never reaches the chip @@ -47,7 +51,7 @@ #define MARKER2_PAYLOAD 0x46464646u #define MARKER2_OFF 0x10u #define WAIT_TOTAL_MS 2000u /* hard deadline: same 2 s window as the old wait */ -#define WAIT_STALL_MS 1000u +#define WAIT_STALL_MS 2000u /* >= hard bound so the pass window is not narrower than the old wait */ static void fence(void) { __asm__ volatile("dsb sy" ::: "memory"); } @@ -223,6 +227,18 @@ int main(void) { } printf("[OBSERVED] After Doorbell B: markerA=0x%08x markerB=0x%08x (expected A=0x16000001, B=0x16000002)\n", *markerA, *markerB); + /* output_parity, final: B's work must not have disturbed A's page. The old log + * printed this as "expected" but never enforced it (NEW tightening). */ + fence(); + if (*markerA != PAYLOAD_A || *marker2A != MARKER2_PAYLOAD || *markerB != PAYLOAD_B || *marker2B != MARKER2_PAYLOAD) { + char what[200]; + snprintf(what, sizeof what, "final markerA=0x%08x marker2A=0x%08x markerB=0x%08x marker2B=0x%08x", + *markerA, *marker2A, *markerB, *marker2B); + print_simple("output_parity", "final", 7, what); + m16_native_close(&ctxA); + m16_native_close(&ctxB); + return 7; + } /* Verify distinct resource handles */ printf("\n--- VERIFYING RESOURCE INDEPENDENCE ---\n"); diff --git a/m16/m16_gpu_wait.c b/m16/m16_gpu_wait.c index b2929d7..a927d65 100644 --- a/m16/m16_gpu_wait.c +++ b/m16/m16_gpu_wait.c @@ -151,10 +151,9 @@ bool m16_gpu_wait_sequence(volatile uint32_t *word, uint32_t target, const char *m16_gpu_wait_failure_class(const m16_gpu_wait_report_t *r, uint32_t m2_want) { if (r->result == M16_GPU_WAIT_INVALID_STATE) return "wrong_marker"; - if (r->result == M16_GPU_WAIT_STALLED) { - if (r->last_observed != 0 && r->last_observed != r->expected) return "wrong_marker"; - if (r->last_marker2 != 0 && r->last_marker2 != m2_want) return "wrong_marker"; - } + if (r->wait_kind == M16_GPU_WAIT_FIXED && r->last_observed != 0 && r->last_observed != r->expected) + return "wrong_marker"; + if (r->last_marker2 != 0 && r->last_marker2 != m2_want) return "wrong_marker"; if (r->progress_count > 0 || r->last_observed == r->expected || (m2_want != 0 && r->last_marker2 == m2_want)) return "late_progress"; diff --git a/m16/m16_gpu_wait.h b/m16/m16_gpu_wait.h index 7769fff..fa216fc 100644 --- a/m16/m16_gpu_wait.h +++ b/m16/m16_gpu_wait.h @@ -100,8 +100,10 @@ bool m16_gpu_wait_sequence(volatile uint32_t *word, uint32_t target, m16_gpu_wait_report_t *rpt, const m16_gpu_wait_cfg_t *cfg); /* Failure class of a failed wait, for tagged test output (additive, not in omega's copy): - * "wrong_marker" INVALID_STATE, or the wait STALLED on a nonzero value other - * than the expected one (word or marker2) + * "wrong_marker" INVALID_STATE; or, for a FIXED wait, the word holds a nonzero + * value other than the expected one; or marker2 holds a nonzero + * value other than marker2_want. (A SEQUENCE word below its + * target is progress, never wrong.) Independent of TIMEOUT vs STALLED. * "late_progress" something moved (progress_count > 0, or the word already held * its value but marker2 never arrived) yet the wait did not finish * (hard TIMEOUT while still moving, or stalled after moving) diff --git a/tests/test_m16_gpu_wait.c b/tests/test_m16_gpu_wait.c index f4f1ba8..7477277 100644 --- a/tests/test_m16_gpu_wait.c +++ b/tests/test_m16_gpu_wait.c @@ -232,9 +232,9 @@ static int scenario(const char *name, WaitFn fx, WaitFn sq, int which) { setup(&f, &cfg); w = 0; cfg.total_timeout_ms = 200; for (int i = 0; i < 30; i++) sched(&f, (uint64_t)(20 * (i + 1)), &w, (uint32_t)(i + 1)); - ok = fx(&w, 99, &r, &cfg); + ok = sq(&w, 99, &r, &cfg); /* counter climbing toward 99 */ cl = m16_gpu_wait_failure_class(&r, 0); - CHECK(!ok && !strcmp(cl, "late_progress"), "%s: moved, missed hard deadline -> late_progress (got %s)", name, cl); + CHECK(!ok && r.result == M16_GPU_WAIT_TIMEOUT && !strcmp(cl, "late_progress"), "%s: counter moved, missed hard deadline -> late_progress (got %s)", name, cl); setup(&f, &cfg); w = 0; sched(&f, 10, &w, 5); ok = fx(&w, 3, &r, &cfg); @@ -253,6 +253,19 @@ static int scenario(const char *name, WaitFn fx, WaitFn sq, int which) { ok = fx(&w, 3, &r, &cfg); cl = m16_gpu_wait_failure_class(&r, 0x46464646u); CHECK(!ok && !strcmp(cl, "wrong_marker"), "%s: marker2 wrong value -> wrong_marker (got %s)", name, cl); + setup(&f, &cfg); w = 0; w2 = 0; + cfg.total_timeout_ms = 200; cfg.progress_timeout_ms = 200; /* stall bound == hard bound, as in m16_concurrent */ + cfg.marker2 = &w2; cfg.marker2_want = 0x46464646u; + sched(&f, 150, &w, 3); + ok = fx(&w, 3, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0x46464646u); + CHECK(!ok && r.result == M16_GPU_WAIT_TIMEOUT && !strcmp(cl, "late_progress"), "%s: marker lands at 150 ms of 200, marker2 never -> TIMEOUT late_progress (got %s)", name, cl); + setup(&f, &cfg); w = 0; + cfg.total_timeout_ms = 200; cfg.progress_timeout_ms = 200; + sched(&f, 150, &w, 5); + ok = fx(&w, 3, &r, &cfg); + cl = m16_gpu_wait_failure_class(&r, 0); + CHECK(!ok && r.result == M16_GPU_WAIT_TIMEOUT && !strcmp(cl, "wrong_marker"), "%s: wrong value then hard TIMEOUT still wrong_marker (got %s)", name, cl); break; } } From 8da7eeff8c7ebf90e0100a2b109ebec37250bdcb Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 3 Oct 2026 06:03:39 -0500 Subject: [PATCH 3/4] CHIPWAIT-2: add m16_gpu_wait.{h,c} to the M16 evidence manifest Co-Authored-By: Claude Opus 5.5 --- tests/run_m16_requalification.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run_m16_requalification.sh b/tests/run_m16_requalification.sh index a1e13be..74a3d9f 100755 --- a/tests/run_m16_requalification.sh +++ b/tests/run_m16_requalification.sh @@ -357,6 +357,8 @@ sha256sum \ "$REPO_ROOT/m16/m16_native.c" \ "$REPO_ROOT/m16/m16_requalify.c" \ "$REPO_ROOT/m16/m16_concurrent.c" \ + "$REPO_ROOT/m16/m16_gpu_wait.h" \ + "$REPO_ROOT/m16/m16_gpu_wait.c" \ "$REPO_ROOT/nvrm/nvrm.h" \ "$REPO_ROOT/nvrm/nvrm.c" \ "$REPO_ROOT/tests/run_m16_requalification.sh" \ From a2268fcc5293ea7f1462f8638ae74b8f17041a4a Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 13:23:05 -0500 Subject: [PATCH 4/4] CHIPWAIT-2: recompile crumbs after merging main (crumb verify CI) Main gained compiled crumbs (#45) and FORM0 (#46) after this branch was cut. This merge brings them in and recompiles the two stale crumbs (root, tests/). No file under m16/ or nvrm/ changed relative to dbefa01, the head the GB10 chip qualification of 2026-10-04T02:23Z was run on. Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- .crumb | 16 ++++++++-------- tests/.crumb | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.crumb b/.crumb index 0273939..0e22f00 100644 --- a/.crumb +++ b/.crumb @@ -67,8 +67,8 @@ "purpose": "Directory m3. Purpose not yet described by a human." }, { - "digest": "75efed90799746e089a7c60bf007dbbf0102d53299d4b1b21fe32f70c065aa93", - "last_commit": "dcc7c21", + "digest": "12c4b5d90b57c51b8d44aab4366ba7792be6e495ff28153ca0e7c5abdd5b567d", + "last_commit": "8da7eef", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -85,15 +85,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:0670a6ccf8f2b6ce4293750fa1bf3129761bf741c60e86660105708a4ab621de", - "compiled_at": "2026-10-04T18:14:55Z", + "children_root": "sha256:d274fc9707332eea17973f05e53075630ed1ce2ec3c190d591d445282f19997f", + "compiled_at": "2026-10-04T19:20:59Z", "compiler": "crumb-compile/1", - "digest": "sha256:524e7dcac93cb2c4ce6c66bde07edbcb199fa2b0b8cbbe28ca3e9a9d89b46150", + "digest": "sha256:62fb5028997768dbe2bd4d2e6b5bd8f80d164600a78a6cc10c0124ed517af86d", "evidence_files": 81, "evidence_root": "sha256:0a0459a4517679721bb2817540dd06995500a1c1ede079bc4665d9da5c39183d", - "files": 257, - "generated_at_commit": "dcc7c21e62716c7b890571a84d4b64e37511ab31", - "source_tree": "sha256:9049c436645816e1873ae5e094c7d73edbc45256b95ff9c13438e50f77a6fe2b" + "files": 261, + "generated_at_commit": "8da7eeff8c7ebf90e0100a2b109ebec37250bdcb", + "source_tree": "sha256:fa01d14e34f4d679d90f4ac659222de820321a94a4b8e4dbd2a738178d9d9ecd" }, "owner_lane": "", "provenance": { diff --git a/tests/.crumb b/tests/.crumb index 2e2061a..89ad0e1 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -20,14 +20,14 @@ } ], "children_root": "sha256:be29e4df8a1e9e426d7723fccf6e09f23eb6fb07a6b21490cd019c75d6fed6cd", - "compiled_at": "2026-10-04T16:07:57Z", + "compiled_at": "2026-10-04T18:23:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:75efed90799746e089a7c60bf007dbbf0102d53299d4b1b21fe32f70c065aa93", + "digest": "sha256:12c4b5d90b57c51b8d44aab4366ba7792be6e495ff28153ca0e7c5abdd5b567d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 15, - "generated_at_commit": "7aba0b9597b9163a3890a266abb87c293cb396db", - "source_tree": "sha256:cc4a7d117c8eba611f9cbf8f2c034f5ae7223d2e7835a08d57dfde648efca84a" + "files": 16, + "generated_at_commit": "e7cfcb555840e67f10be136901b4d83de4a7e983", + "source_tree": "sha256:46d1505ad45f50a5cb2fc54679983b8ea44c2861d72f4134ba6dbe4f731dd87a" }, "owner_lane": "", "provenance": {