omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
GitHub aien-dev/omega-mv#306 (code only)
Apply it
git checkout -b patch-79e78ac8cfe45f1d c8463fdd8b834a713500344f34d6fb2e94c233f6 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/79e78ac8cfe45f1d.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
306
0d82bf514619c603402fd27e5847f01ad398dafa
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":306,"url":"https://github.com/aien-dev/omega-mv/pull/306","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:15Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 0952fd93b..b6c8cfe93 100644 --- a/.crumb +++ b/.crumb @@ -87,14 +87,14 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "a6297bff3c4d142fa966c7d8817366e17505f4f0c1a1f97903813606a95d3f36", - "last_commit": "79a805d", + "digest": "216a1cd73e993694a7c2ff9580d2b9ec299ddb0876e29ddcaf23e35844ef73bd", + "last_commit": "bf89cda", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "a7f97a1cd886fa4dfb2f66b766c2948200d0858dc26788d65682ab1c8a4646a5", - "last_commit": "79a805d", + "digest": "4dd032138822b16a873570aa3da09b5eacf47b1cbc91db74a44abf069317cdaf", + "last_commit": "bf89cda", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -105,15 +105,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:b4d9b70b960605d70ed3af66cf2e04c5017da671b305a7307625d54ec1926b8f", - "compiled_at": "2026-10-05T19:17:27Z", + "children_root": "sha256:3d84efc61f05712e5b42769e1e986edefb43081fece5a56b225b528edd8c67c8", + "compiled_at": "2026-10-05T20:10:00Z", "compiler": "crumb-compile/1", - "digest": "sha256:9e6ed59021cbaa737f28fe65878b574710e294277c723cf79291f46d86c1d03e", + "digest": "sha256:ddec05bd6282c2eb67389050974498d6e43c3f7e9dae4f1d35e577ca507ec9a9", "evidence_files": 3304, "evidence_root": "sha256:9594e3e2a05603747e60ab08376dcf98a6857a89e43720f33126d5b68e41f4d1", - "files": 5107, - "generated_at_commit": "ced05c381ab71853360f7b8d65c5175600be4ce0", - "source_tree": "sha256:37c90d732ede220cc9841930bcacc0929e4f67a0016c5de6d925c9b72e722d62" + "files": 5109, + "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", + "source_tree": "sha256:0f967d2f0047b5ebadb0ca0cfc765dd1f7a8f9a6a3b0108d1cdd60d6db94f03d" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/host-suites-2.yml b/.github/workflows/host-suites-2.yml index 6a3372bdc..313adae71 100644 --- a/.github/workflows/host-suites-2.yml +++ b/.github/workflows/host-suites-2.yml @@ -22,7 +22,7 @@ name: Host suites 2 # algebra : test-algebra test-algebra-asan test-realize test-phase-twin # test-ma-digital-bottom 3.5 min # path : test-path 30 s; crumbline : test-crumbline 1 s -# runtime : test-r15-instr test-r15-receipt test-r16-inventory +# runtime : test-r15-instr test-r15-receipt test-r15-preflight test-r15-g15-diag test-r16-inventory # test-r16-negative test-r16-surface test-r16-qualify-selftest test-allen # test-r16-negative-mutants 5 min (Spark: 4.3 min) # argus : test-argus-runtime test-machine-identity-argus @@ -307,6 +307,12 @@ jobs: PHYSICS_DIR: ${{ github.workspace }}/physics-src AIENOS_R7_DIR: ${{ github.workspace }}/aienos-src run: make test-r15-receipt + - name: R15 preflight, energy-instrument preflight and G15 diagnostics + if: ${{ !cancelled() }} + env: + PHYSICS_DIR: ${{ github.workspace }}/physics-src + AIENOS_R7_DIR: ${{ github.workspace }}/aienos-src + run: make test-r15-preflight test-r15-g15-diag - name: R16 G2 loop inventory if: ${{ !cancelled() }} env: diff --git a/Makefile b/Makefile index 51b294b61..f216481d4 100644 --- a/Makefile +++ b/Makefile @@ -857,6 +857,7 @@ 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 + sh tests/seat_marker_uncached_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, diff --git a/src/.crumb b/src/.crumb index b2cb5e0a0..0eb185b4e 100644 --- a/src/.crumb +++ b/src/.crumb @@ -133,8 +133,8 @@ "purpose": "Directory src/polyglot. Purpose not yet described by a human." }, { - "digest": "5a156b88f82413a6284d324d7bf457ec583fe0d4fa07dec1f77d56b3b0652606", - "last_commit": "984aa1e", + "digest": "7927099dac3838db8f33a305a185873d9610c7c496fc3763ec9e5dc9e901bb9d", + "last_commit": "bf89cda", "name": "runtime", "purpose": "Directory src/runtime. Purpose not yet described by a human." }, @@ -169,15 +169,15 @@ "purpose": "Directory src/visor. Purpose not yet described by a human." } ], - "children_root": "sha256:2b11d37dbb5a168332b53d9a69df44685353241048839d3fc79d027c26070e13", - "compiled_at": "2026-10-05T17:01:01Z", + "children_root": "sha256:100d089dae58ac28d48f3c8e0426a60913380b117fd49f9e54ee33620370ff25", + "compiled_at": "2026-10-05T20:10:00Z", "compiler": "crumb-compile/1", - "digest": "sha256:a6297bff3c4d142fa966c7d8817366e17505f4f0c1a1f97903813606a95d3f36", + "digest": "sha256:216a1cd73e993694a7c2ff9580d2b9ec299ddb0876e29ddcaf23e35844ef73bd", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 406, - "generated_at_commit": "714835409175f776b4a5630d892cf9383ba43b44", - "source_tree": "sha256:737cbd6bf1488606ef40aaa86391d377c3624e555e3fa80aa7d52d2bd862774a" + "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", + "source_tree": "sha256:d2d655d8913f1943c3e771446f0d82a900b32e690527cde887157aef0e74de8d" }, "owner_lane": "", "provenance": { diff --git a/src/runtime/.crumb b/src/runtime/.crumb index e2eda9026..afd44ab97 100644 --- a/src/runtime/.crumb +++ b/src/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-05T16:20:56Z", + "compiled_at": "2026-10-05T20:10:00Z", "compiler": "crumb-compile/1", - "digest": "sha256:5a156b88f82413a6284d324d7bf457ec583fe0d4fa07dec1f77d56b3b0652606", + "digest": "sha256:7927099dac3838db8f33a305a185873d9610c7c496fc3763ec9e5dc9e901bb9d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 59, - "generated_at_commit": "3aa6d80ad1c169b5ad605801ad6ef79d3902ecfd", - "source_tree": "sha256:2d2b7c349981d00df339d8b28dda8d9720b5e558646e608fe19aa63406a8cd80" + "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", + "source_tree": "sha256:6eede518faaae5783b6f84140535af1105d811b5975bffdda56934065ac91687" }, "owner_lane": "", "provenance": { diff --git a/src/runtime/rx_resident_gpu.c b/src/runtime/rx_resident_gpu.c index 7cffe4022..9a8272001 100644 --- a/src/runtime/rx_resident_gpu.c +++ b/src/runtime/rx_resident_gpu.c @@ -53,6 +53,8 @@ struct RxGpuSeat { volatile int abort; /* stop waiting for the launch marker */ volatile int marker_ok; volatile int sem_ok; + volatile uint32_t marker_value; /* words the host read when the wait ended (diagnostic) */ + volatile uint32_t sem_value; char err[160]; LaunchJob *job; volatile uint32_t *hb_watch; @@ -723,7 +725,7 @@ static void *launch_main(void *arg) { if (nvrm_alloc(&ctx->rm, 0x4000, &job->code_mem) != 0 || nvrm_alloc(&ctx->rm, 0x1000, &job->cbank_mem) != 0 || nvrm_alloc(&ctx->rm, 0x10000, &job->qmd_mem) != 0 || - nvrm_alloc(&ctx->rm, 0x1000, &job->marker_mem) != 0 || + nvrm_alloc_gpu_uncached(&ctx->rm, 0x1000, &job->marker_mem) != 0 || nvrm_alloc(&ctx->rm, 0x10000, &job->large_pb) != 0) { snprintf(s->err, sizeof s->err, "graphics memory was not allocated"); job->submit_rc = -1; @@ -743,7 +745,11 @@ static void *launch_main(void *arg) { uint64_t qmd0_va = qmd_mem.va; uint64_t qmd1_va = qmd_mem.va + 0x1000; - uint64_t sem_va = qmd_mem.va + 0x2000; + /* The semaphore the host reads after the marker lives on the GPU-uncached marker + * page (nvos.h NVOS32_ATTR2_GPU_CACHEABLE_YES: "For system memory this will not be + * coherent with direct CPU mappings"). On the cached QMD page the host could read a + * stale word once the marker arrived promptly. Offset 0x20 keeps clear of the marker. */ + uint64_t sem_va = marker_mem.va + 0x20; uint64_t scratch_va = qmd_mem.va + 0x4000; /* The chip keeps the top two registers of a thread's allocation for * itself. On GB10 a value placed in R46 of a 48-register launch read back @@ -772,7 +778,7 @@ static void *launch_main(void *arg) { } memcpy(qmd_mem.cpu, qmd0, sizeof(qmd0)); memcpy((uint8_t *)qmd_mem.cpu + 0x1000, qmd1, sizeof(qmd1)); - volatile uint32_t *hsem = (volatile uint32_t *)((uint8_t *)qmd_mem.cpu + 0x2000); + volatile uint32_t *hsem = (volatile uint32_t *)((uint8_t *)marker_mem.cpu + 0x20); volatile uint32_t *hmarker = (volatile uint32_t *)marker_mem.cpu; *hsem = 0; *hmarker = 0; @@ -848,7 +854,9 @@ static void *launch_main(void *arg) { } int wait = wait_marker_or_abort(s, hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 60000); s->marker_ok = wait == 0 && *hmarker == OMEGA_BW_MARKER_COMPLETION_PAYLOAD; - s->sem_ok = *hsem == OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE; + s->marker_value = *hmarker; + s->sem_value = *hsem; + s->sem_ok = s->sem_value == OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE; if (!s->marker_ok && !s->abort) snprintf(s->err, sizeof s->err, "the graphics seat did not finish"); return NULL; @@ -977,6 +985,8 @@ int rx_gpu_seat_relaunch(RxGpuSeat *s) { s->abort = 0; s->marker_ok = 0; s->sem_ok = 0; + s->marker_value = 0; + s->sem_value = 0; s->err[0] = 0; s->job->submit_rc = 0; s->job->args.seat_gen = current_seat_gen(s->world); @@ -1086,7 +1096,9 @@ int rx_gpu_seat_begin(RxWorld *w, RxGpuSeat **out) { return lease_start(s); } -int rx_gpu_seat_finish(RxGpuSeat *seat) { +int rx_gpu_seat_finish(RxGpuSeat *seat) { return rx_gpu_seat_finish_ex(seat, NULL); } + +int rx_gpu_seat_finish_ex(RxGpuSeat *seat, RxGpuSeatLeave *leave) { if (!seat) return -1; /* The shutdown notice was posted before this; stopping the lease only * bounds how long a seat that missed it keeps running. */ @@ -1095,6 +1107,12 @@ int rx_gpu_seat_finish(RxGpuSeat *seat) { pthread_join(seat->thread, NULL); seat->thread_live = 0; } + if (leave) { + leave->marker_ok = seat->marker_ok; + leave->sem_ok = seat->sem_ok; + leave->marker_value = seat->marker_value; + leave->sem_value = seat->sem_value; + } /* A killed seat never reaches its marker; leaving is then only the image * going back to the world and the device closing. */ int ok = seat->killed || (seat->marker_ok && seat->sem_ok); diff --git a/src/runtime/rx_resident_gpu.h b/src/runtime/rx_resident_gpu.h index ba1a52102..430e66274 100644 --- a/src/runtime/rx_resident_gpu.h +++ b/src/runtime/rx_resident_gpu.h @@ -24,6 +24,10 @@ typedef struct RxGpuSeat RxGpuSeat; int rx_gpu_seat_begin(RxWorld *w, RxGpuSeat **out); int rx_gpu_seat_finish(RxGpuSeat *seat); +/* What the host read when the seat left: both words, so a stale or missing read is visible. */ +typedef struct { int marker_ok, sem_ok; uint32_t marker_value, sem_value; } RxGpuSeatLeave; +int rx_gpu_seat_finish_ex(RxGpuSeat *seat, RxGpuSeatLeave *leave); + /* Destroy the seat's channel while it runs, as a fault would. When this * returns the chip no longer writes the image; the image stays mapped and * bound. The caller then declares the seat lost to the world. */ diff --git a/tests/.crumb b/tests/.crumb index b34e8a0ed..ead2cc6ac 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -230,7 +230,7 @@ }, { "digest": "000c487afa8f600842eff25a22a671afb5e29b26845105405de9542a21b70746", - "last_commit": "420a0ff", + "last_commit": "79a805d", "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": "d48420b3eb071836762debb1f1eed6febb4b0b27bf0379175e2a2d4451b70358", - "last_commit": "984aa1e", + "digest": "71ee11a9ea01b73efaf1c3f4fa3495aa98cc7d610b5570ce591f0718bb25a4d4", + "last_commit": "bf89cda", "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:741af2870f086e5e556c26f1007a78ffc1ed055f1f515d8d3712e92b7e209be8", - "compiled_at": "2026-10-05T17:22:20Z", + "children_root": "sha256:5e49c39abb592f9a527e51b78cbb625925b7c4421476815cdcebe6b394a7ecda", + "compiled_at": "2026-10-05T20:10:00Z", "compiler": "crumb-compile/1", - "digest": "sha256:a7f97a1cd886fa4dfb2f66b766c2948200d0858dc26788d65682ab1c8a4646a5", + "digest": "sha256:4dd032138822b16a873570aa3da09b5eacf47b1cbc91db74a44abf069317cdaf", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", - "files": 806, - "generated_at_commit": "420a0ff7d7fe6c6f473c01e9871012609aafd0de", - "source_tree": "sha256:da58c8c1ee12613db888c753ddf8243437b941b2c8d5aa351e2a8a4beae92592" + "files": 808, + "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", + "source_tree": "sha256:fd92b259602b73222ae782b64db0d9940e43300c46d9bec2f0efba4de7f01bfb" }, "owner_lane": "", "provenance": { diff --git a/tests/runtime/.crumb b/tests/runtime/.crumb index cc3061976..3e48c3c44 100644 --- a/tests/runtime/.crumb +++ b/tests/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-05T17:01:01Z", + "compiled_at": "2026-10-05T20:10:00Z", "compiler": "crumb-compile/1", - "digest": "sha256:d48420b3eb071836762debb1f1eed6febb4b0b27bf0379175e2a2d4451b70358", + "digest": "sha256:71ee11a9ea01b73efaf1c3f4fa3495aa98cc7d610b5570ce591f0718bb25a4d4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 57, - "generated_at_commit": "714835409175f776b4a5630d892cf9383ba43b44", - "source_tree": "sha256:c6436bd74923307a6393b12f66beaf3df51e0671b1a1d219cc670cc6fcde9268" + "files": 58, + "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", + "source_tree": "sha256:0e2d0c40beb2bbf8d4a9aca98a69a382d6b0501e33f4dab682c4c7f8861b62f9" }, "owner_lane": "", "provenance": { diff --git a/tests/runtime/r15_seat_diag_test.c b/tests/runtime/r15_seat_diag_test.c index 56719735a..ab12a53d5 100644 --- a/tests/runtime/r15_seat_diag_test.c +++ b/tests/runtime/r15_seat_diag_test.c @@ -1,7 +1,10 @@ /* 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. */ +#define _POSIX_C_SOURCE 200809L #include "r15_seat_diag.h" +#include "r15_stage_clock.h" +#include <string.h> #include <stdio.h> static int fails; @@ -37,6 +40,22 @@ int main(void) { 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); + /* stage clock: stamps become per-stage deltas that sum to the total; an unstamped clock writes nothing */ + { + R15StageClock c; char b[512]; + memset(&c, 0, sizeof c); + CHECK(r15_stage_json(&c, b, sizeof b) == 0); + c.t[0] = 1000; c.name[0] = "begin"; c.n = 1; + CHECK(r15_stage_json(&c, b, sizeof b) == 0); + c.t[1] = 1500; c.name[1] = "producers"; c.t[2] = 102000001500ull; c.name[2] = "seat_finish"; c.n = 3; + int w = r15_stage_json(&c, b, sizeof b); + CHECK(w > 0 && strcmp(b, ",\"teardown\":{\"total_ns\":102000000500,\"stages\":[[\"producers\",500],[\"seat_finish\",102000000000]]}") == 0); + R15StageClock f; memset(&f, 0, sizeof f); + for (int i = 0; i < R15_STAGE_MAX + 5; i++) r15_stage_mark(&f, "x"); + CHECK(f.n == R15_STAGE_MAX); + CHECK(r15_stage_json(&f, b, 40) == 0); /* too small a buffer is refused, never truncated */ + } + printf("failures %d\n", fails); return fails != 0; } diff --git a/tests/runtime/r15_stage_clock.h b/tests/runtime/r15_stage_clock.h new file mode 100644 index 000000000..a0001b8ab --- /dev/null +++ b/tests/runtime/r15_stage_clock.h @@ -0,0 +1,52 @@ +/* r15_stage_clock.h -- named time stamps for the teardown after a trial's + * measured windows (spec/r15-performance-proof.md section 6.10, gate G15). + * + * CAND-1 window 2: trials SEQ-06 and RES4-11 each took 122.7 s against about + * 21.6 s. The record showed the episode ended on time (20.4 s) and the whole + * extra ~102 s sat between the residency record and the result record, which is + * r15_stop() (producers, transport, orchestrator, seat shutdown and finish, + * world destroy). The record could not say which step waited. These stamps are + * taken AFTER the measured windows and the residency sampler are closed, so + * they add nothing to what G15 or any other gate measures. */ +#ifndef R15_STAGE_CLOCK_H +#define R15_STAGE_CLOCK_H +#include <stdint.h> +#include <stdio.h> +#include <time.h> + +#define R15_STAGE_MAX 12 + +typedef struct { + uint64_t t[R15_STAGE_MAX]; + const char *name[R15_STAGE_MAX]; + int n; +} R15StageClock; + +static inline uint64_t r15_stage_now_ns(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; +} + +/* Stamp "the step called name has just finished". The first stamp (n == 0) is + * the start reference. A full clock drops further stamps and never overruns. */ +static inline void r15_stage_mark(R15StageClock *c, const char *name) { + if (c->n >= R15_STAGE_MAX) return; + c->t[c->n] = r15_stage_now_ns(); + c->name[c->n] = name; + c->n++; +} + +/* Writes ,"teardown":{"total_ns":T,"stages":[["name",ns since the previous stamp],...]}. + * Returns the number of bytes written; 0 if nothing was stamped. */ +static inline int r15_stage_json(const R15StageClock *c, char *buf, size_t cap) { + if (c->n < 2 || cap < 64) return 0; + int w = snprintf(buf, cap, ",\"teardown\":{\"total_ns\":%llu,\"stages\":[", + (unsigned long long)(c->t[c->n - 1] - c->t[0])); + for (int i = 1; i < c->n && w > 0 && (size_t)w < cap; i++) + w += snprintf(buf + w, cap - (size_t)w, "%s[\"%s\",%llu]", i > 1 ? "," : "", c->name[i], + (unsigned long long)(c->t[i] - c->t[i - 1])); + if (w > 0 && (size_t)w + 3 < cap) w += snprintf(buf + w, cap - (size_t)w, "]}"); + return (w > 0 && (size_t)w < cap) ? w : 0; +} +#endif diff --git a/tests/runtime/rx_r15_perf.c b/tests/runtime/rx_r15_perf.c index ec0d82511..f17db9547 100644 --- a/tests/runtime/rx_r15_perf.c +++ b/tests/runtime/rx_r15_perf.c @@ -716,6 +716,12 @@ static int run_trial(R15Config cfg) { int complete = rc == 0 && tw.idle_ok && tw.before_ok && tw.after_ok && goal && promo && inforce; r15_rec_begin(&g_out, "result"); rec_i("complete", complete); + { /* where the teardown spent its time (CAND-1 window 2: SEQ-06 and RES4-11 waited ~102 s here); reported only */ + char tb[768]; + if (r15_stage_json(&r->stop_clock, tb, sizeof tb) > 0) fputs(tb, g_out.f); + if (r->leave_valid) + fprintf(g_out.f, ",\"seat_leave\":{\"rc\":%d,\"marker\":%u,\"sem\":%u}", r->leave_rc, r->leave_marker, r->leave_sem); + } r15_rec_end(&g_out); return complete ? 0 : 1; } diff --git a/tests/runtime/rx_r15_rig.c b/tests/runtime/rx_r15_rig.c index 2fe603634..48bb529ce 100644 --- a/tests/runtime/rx_r15_rig.c +++ b/tests/runtime/rx_r15_rig.c @@ -841,31 +841,46 @@ uint64_t r15_lost_triggers(R15Rig *r, char *first, size_t n) { } void r15_stop(R15Rig *r) { + R15StageClock *sc = &r->stop_clock; + memset(sc, 0, sizeof *sc); + r15_stage_mark(sc, "begin"); stop_producer(r); + r15_stage_mark(sc, "producer"); if (r->transport_live) { atomic_store(&r->transport_stop, 1); pthread_join(r->transport, NULL); r->transport_live = 0; } + r15_stage_mark(sc, "transport"); if (r->orch_live) { atomic_store(&r->orch_stop, 1); pthread_join(r->orchestrator, NULL); r->orch_live = 0; } + r15_stage_mark(sc, "orchestrator"); #ifdef R15_SILICON if (r->seat) { (void)rx_resident_shutdown(&r->w); - (void)rx_gpu_seat_finish(r->seat); + r15_stage_mark(sc, "seat_shutdown_post"); + RxGpuSeatLeave lv = {0}; + r->leave_rc = rx_gpu_seat_finish_ex(r->seat, &lv); + r->leave_marker = lv.marker_value; + r->leave_sem = lv.sem_value; + r->leave_valid = 1; + r15_stage_mark(sc, "seat_finish"); } #endif rx_world_destroy(&r->w); + r15_stage_mark(sc, "world_destroy"); rx_aegis_destroy(&r->aegis); rx_omega_destroy(&r->omega); if (r->gen) rx_gen_close(r->gen); if (r->admin) aienos_cap_stop(r->admin, r->view); + r15_stage_mark(sc, "faculties_admin"); if (r->generation_dir[0]) { char cmd[200]; snprintf(cmd, sizeof cmd, "rm -rf '%s'", r->generation_dir); if (system(cmd) != 0) fprintf(stderr, "note: could not remove %s\n", r->generation_dir); } + r15_stage_mark(sc, "generation_dir"); } diff --git a/tests/runtime/rx_r15_rig.h b/tests/runtime/rx_r15_rig.h index 6212a1813..bc3d12d73 100644 --- a/tests/runtime/rx_r15_rig.h +++ b/tests/runtime/rx_r15_rig.h @@ -23,6 +23,7 @@ #include <pthread.h> #include <sched.h> #include <stdatomic.h> +#include "r15_stage_clock.h" typedef enum { R15_RES4, R15_RES1, R15_SEQ } R15Config; @@ -79,6 +80,10 @@ typedef struct { RxCallerKeyring keys_omega, keys_aien, keys_aegis, keys_living, keys_promoter; RxCallerKeyring keys_rig; /* the rig's own R8 ask reaction (seat subject) */ RxCallerKeyring fixtures; /* r15_start_with fixture subjects */ + R15StageClock stop_clock; /* time stamps of each r15_stop step (teardown diagnostics, reported only) */ + int leave_valid; /* r15_stop read the seat's words at finish */ + int leave_rc; /* rx_gpu_seat_finish_ex return, 0 = clean */ + uint32_t leave_marker, leave_sem; /* what the host read (stale or missing reads show here) */ } R15Rig; /* Called on the episode's thread; a nonzero return fails the episode. diff --git a/tests/seat_marker_uncached_test.sh b/tests/seat_marker_uncached_test.sh new file mode 100644 index 000000000..2969ce281 --- /dev/null +++ b/tests/seat_marker_uncached_test.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Source guard: every page the host POLLS or reads for the resident seat's completion must be GPU-uncached. +# NVIDIA nvos.h NVOS32_ATTR2_GPU_CACHEABLE_YES: "For system memory this will not be coherent with direct CPU +# mappings"; spark-hardware-manual s4.1: "Any word the host polls ... must be allocated nvrm_alloc_gpu_uncached". +# Evidence (CAND-1 window 2 and the R15 seat A/B, 2026-10-05): with a GPU-cacheable marker page the seat's leave +# marker reached the host ~1.05 s late in 15 of 16 trials and never within the wait in 3 of 64 (~102 s stalls); +# with a GPU-uncached page it arrived in 13 to 20 ms in 16 of 16, no stall. +# Two guards: (1) the marker page is allocated uncached; (2) the semaphore word the host reads right after the +# marker (gates rx_gpu_seat_finish) lives on that same uncached page, not on the cached QMD page. +# The check reads src/runtime/rx_resident_gpu.c; mutants prove it can say no. +cd "$(dirname "$0")/.." || exit 1 +F=${SEAT_SRC:-src/runtime/rx_resident_gpu.c}; fail=0 +guard() { # file -> 0 when both pages are uncached + grep -Eq 'nvrm_alloc_gpu_uncached\([^;]*&job->marker_mem\)' "$1" || return 1 + grep -Eq '[^_]nvrm_alloc\([^;]*&job->marker_mem\)' "$1" && return 1 + grep -Eq 'sem_va = marker_mem\.va \+ 0x[0-9a-fA-F]+;' "$1" || return 1 + grep -Eq '\(uint8_t \*\)marker_mem\.cpu \+ 0x[0-9a-fA-F]+\)' "$1" || return 1 + grep -Eq 'sem_va = qmd_mem\.va|\(uint8_t \*\)qmd_mem\.cpu \+ 0x2000' "$1" && return 1 + return 0 +} +chk() { # name file expect(0=guard passes,1=guard must refuse) + guard "$2"; got=$? + if [ "$got" = "$3" ]; then echo "[+] $1"; else echo "[-] $1 (guard exit $got, want $3)"; fail=$((fail + 1)); fi +} +W=$(mktemp -d) || exit 1; trap 'rm -rf "$W"' EXIT +chk "seat marker page and semaphore are GPU-uncached" "$F" 0 +sed 's/nvrm_alloc_gpu_uncached(\(&ctx->rm, 0x1000, &job->marker_mem\))/nvrm_alloc(\1)/' "$F" > "$W/m1.c" +cmp -s "$F" "$W/m1.c" && { echo "[-] mutant 1 did not change the source"; fail=$((fail + 1)); } +chk "mutant: cacheable marker page is refused" "$W/m1.c" 1 +sed 's/&job->marker_mem/\&job->marker_mem_x/' "$F" > "$W/m2.c" +chk "mutant: marker allocation not found is refused" "$W/m2.c" 1 +sed 's/sem_va = marker_mem\.va + 0x20;/sem_va = qmd_mem.va + 0x2000;/' "$F" > "$W/m3.c" +cmp -s "$F" "$W/m3.c" && { echo "[-] mutant 3 did not change the source"; fail=$((fail + 1)); } +chk "mutant: semaphore back on the cached QMD page is refused" "$W/m3.c" 1 +sed 's/(uint8_t \*)marker_mem\.cpu + 0x20)/(uint8_t *)qmd_mem.cpu + 0x2000)/' "$F" > "$W/m4.c" +cmp -s "$F" "$W/m4.c" && { echo "[-] mutant 4 did not change the source"; fail=$((fail + 1)); } +chk "mutant: host reads the semaphore from the cached page is refused" "$W/m4.c" 1 +echo "failures $fail"; [ "$fail" = 0 ]