Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/runtime/rx_r12_silicon.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / runtime / rx_r12_silicon.c` 1051 lines ยท 46182 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * R12 on the physical chip: one resident graphics seat inside the same world. 19 * 20 * processor changes A -> seat reaction ready -> admission -> native 21 * authority -> resident seat claims -> seat reads A under the same 22 * {id, generation} -> qualified 32-bit add on the chip -> seat writes B 23 * -> B is published under the same rules as processor work -> the 24 * processor reaction waiting on B wakes and writes C. 25 * 26 * The seat is never called as a function. Authority is the native Aienux 27 * authority (C), not the Linux stand-in. silicon_observed stays false unless 28 * this run saw the chip publish into the shared image. 29 */ 30 #include "runtime/aienos_cap.h" 31 #include "runtime/rx_world.h" 32 #include "runtime/rx_resident_gpu.h" 33 #include "omega_blackwell_codegen.h" 34 #include "omega_evidence.h" 35 #include "sha256.h" 36 37 #include 38 #include 39 #include 40 #include 41 #include 42 #include 43 #include 44 #include 45 #include 46 47 #define RES_A 0x10u 48 #define RES_B 0x20u 49 #define RES_C 0x30u 50 #define SENTINEL 0x11111111ull 51 52 enum { SUBJ_SEAT = 3, SUBJ_DEPEND = 4, SUBJ_EXTERNAL = 100, ISSUER = 3 }; 53 54 static int g_checks; 55 static int g_fail; 56 static int g_silicon; 57 58 #define CHECK(cond, ...) do { \ 59 g_checks++; \ 60 if (!(cond)) { \ 61 g_fail++; \ 62 fprintf(stderr, " FAIL %s:%d ", __FILE__, __LINE__); \ 63 fprintf(stderr, __VA_ARGS__); \ 64 fputc('\n', stderr); \ 65 } \ 66 } while (0) 67 68 /* Scenario outcomes for the receipt. */ 69 typedef struct { 70 const char *name; 71 int checks_before; 72 int fails_before; 73 int ran; 74 int passed; 75 } Scenario; 76 77 static Scenario g_sc[16]; 78 static int g_nsc; 79 static int g_cur = -1; 80 81 static void begin(const char *name) { 82 printf("[*] %s\n", name); 83 g_cur = g_nsc++; 84 g_sc[g_cur] = (Scenario){ name, g_checks, g_fail, 1, 0 }; 85 } 86 87 static void end(void) { 88 if (g_cur < 0) return; 89 g_sc[g_cur].passed = g_fail == g_sc[g_cur].fails_before; 90 printf(" %s (%d checks)\n", g_sc[g_cur].passed ? "PASS" : "FAIL", 91 g_checks - g_sc[g_cur].checks_before); 92 g_cur = -1; 93 } 94 95 static void sleep_ms(int ms) { 96 struct timespec ts = { ms / 1000, (long)(ms % 1000) * 1000000L }; 97 nanosleep(&ts, NULL); 98 } 99 100 static void barrier(void) { 101 atomic_thread_fence(memory_order_seq_cst); 102 __asm__ volatile("dsb sy" ::: "memory"); 103 } 104 105 static uint64_t load_u64(const uint8_t *p) { 106 uint64_t v = 0; 107 for (int i = 0; i < 8; i++) v |= (uint64_t)p[i] << (8 * i); 108 return v; 109 } 110 111 static void store_u64(uint8_t *p, uint64_t v) { 112 for (int i = 0; i < 8; i++) p[i] = (uint8_t)(v >> (8 * i)); 113 } 114 115 static uint64_t field_of(RxWorld *w, RxObjRef r, uint32_t f) { 116 RxObject o; 117 if (rx_world_read(w, r, &o) != RX_OK) return UINT64_MAX; 118 return o.field[f]; 119 } 120 121 static OmegaSharedWorldRing *ring_at(RxWorld *w, uint64_t off) { 122 return (OmegaSharedWorldRing *)(w->coherent + off); 123 } 124 125 static uint64_t g2c_tail(RxWorld *w) { 126 barrier(); 127 return ring_at(w, rx_world_off_g2c())->tail; 128 } 129 130 static uint64_t c2g_head(RxWorld *w) { 131 barrier(); 132 return ring_at(w, rx_world_off_c2g())->head; 133 } 134 135 static const uint8_t *window(RxWorld *w, RxObjRef r) { 136 return w->coherent + w->objects[r.id].region_offset; 137 } 138 139 static int g_poison; 140 141 static int fn_poison(RxCtx *c) { 142 (void)c; 143 g_poison++; 144 return -1; 145 } 146 147 typedef struct { 148 RxObjRef b; 149 RxObjRef c; 150 } Chain; 151 152 /* C = B + 1, on the processor. It only runs because B changed. */ 153 static int fn_depend(RxCtx *c) { 154 Chain *ch = c->user; 155 const RxSnapshotDep *s = NULL; 156 for (uint32_t i = 0; i < c->n_in; i++) 157 if (c->in[i].obj.id == ch->b.id) s = &c->in[i]; 158 if (!s) return -1; 159 c->out[c->n_out++] = (RxMutation){ ch->c, 0, s->field[0] + 1 }; 160 return 0; 161 } 162 163 static AienosCapAdmin *g_admin; 164 165 static RxCapRef mint(uint32_t subject, uint64_t resource, uint32_t rights) { 166 AienosCapRef office; 167 aienos_cap_office(g_admin, &office); 168 AienosCapMint m = { ISSUER, subject, resource, rights, 0, 169 { UINT32_MAX, 0 }, office }; 170 AienosCapRef r = { UINT32_MAX, 0 }; 171 if (aienos_cap_mint(g_admin, &m, &r) != 0) r = (AienosCapRef){ UINT32_MAX, 0 }; 172 return (RxCapRef){ r.cap_id, r.generation }; 173 } 174 175 static int revoke_cap(RxCapRef cap) { 176 AienosCapRef office; 177 aienos_cap_office(g_admin, &office); 178 return aienos_cap_revoke(g_admin, office, (AienosCapRef){ cap.cap_id, cap.generation }); 179 } 180 181 static void offer(RxWorld *w) { 182 RxResourceBudget b; 183 memset(&b, 0, sizeof(b)); 184 b.slots = 8; 185 b.memory_bytes = UINT64_MAX; 186 b.energy_budget = UINT64_MAX; 187 b.offered_locality = UINT32_MAX; 188 b.offered_accel = RX_ACCEL_BLACKWELL; 189 b.compute_mask = UINT32_MAX; 190 rx_world_set_resources(w, &b); 191 } 192 193 static void desc_init(RxReactionDesc *d, const char *name, uint32_t subject, RxFn fn, void *user) { 194 memset(d, 0, sizeof(*d)); 195 d->name = name; 196 d->faculty = RX_FACULTY_AEGIS; 197 d->subject = subject; 198 d->priority = RX_PRIO_FOREGROUND; 199 d->fn = fn; 200 d->user = user; 201 } 202 203 static int add_seat(RxWorld *w, RxObjRef a, RxObjRef b, RxCapRef in_cap, RxCapRef out_cap, 204 uint32_t *id) { 205 RxReactionDesc d; 206 desc_init(&d, "resident.seat.add", SUBJ_SEAT, fn_poison, NULL); 207 d.need.accelerator_features = RX_ACCEL_BLACKWELL; 208 d.n_triggers = 1; 209 d.triggers[0] = (RxDep){ a, RX_FIELD(0) | RX_FIELD(1) }; 210 d.n_writes = 1; 211 d.writes[0] = (RxDep){ b, RX_FIELD(0) }; 212 d.n_caps = 2; 213 d.caps[0] = (RxCapNeed){ in_cap, RES_A, RX_RIGHT_READ }; 214 d.caps[1] = (RxCapNeed){ out_cap, RES_B, RX_RIGHT_WRITE }; 215 return rx_world_add_reaction(w, &d, id); 216 } 217 218 /* Wait until this seat reaction has posted its claim. */ 219 static int wait_claimed(RxWorld *w, uint32_t id) { 220 for (int i = 0; i < 3000; i++) { 221 RxState s = w->reactions[id].state; 222 if (s == RX_RUNNING && w->reactions[id].resident_seat) return 0; 223 if (s == RX_BLOCKED_RESOURCE || s == RX_BLOCKED_AUTHORITY || s == RX_FAILED || 224 s == RX_REJECTED) 225 return 1; 226 sleep_ms(1); 227 } 228 return -1; 229 } 230 231 /* Wait until the chip has put one more notice on its result ring. */ 232 static int wait_chip(RxWorld *w, uint64_t before) { 233 for (int i = 0; i < 3000; i++) { 234 if (g2c_tail(w) > before) return 0; 235 sleep_ms(1); 236 } 237 return -1; 238 } 239 240 static int poll_accept(RxWorld *w) { 241 int acc = RX_ERR_NOT_FOUND; 242 for (int i = 0; i < 3000; i++) { 243 acc = rx_resident_accept(w); 244 if (acc != RX_ERR_NOT_FOUND) return acc; 245 sleep_ms(1); 246 } 247 return acc; 248 } 249 250 static int64_t stimulate(RxWorld *w, RxCapRef ext, RxObjRef a, uint64_t x, uint64_t y) { 251 RxMutation m[2] = { { a, 0, x }, { a, 1, y } }; 252 return rx_world_publish_external(w, ext, m, 2); 253 } 254 255 static uint64_t last_commit_of(RxWorld *w, uint32_t reaction) { 256 uint64_t found = 0; 257 for (uint64_t id = 1; id <= w->n_crumbs; id++) { 258 const RxCrumb *k = rx_world_crumb(w, id); 259 if (k && k->kind == RX_CRUMB_COMMIT && k->reaction == reaction) found = id; 260 } 261 return found; 262 } 263 264 static uint64_t last_crumb_of(RxWorld *w, uint32_t reaction, RxCrumbKind kind) { 265 uint64_t found = 0; 266 for (uint64_t id = 1; id <= w->n_crumbs; id++) { 267 const RxCrumb *k = rx_world_crumb(w, id); 268 if (k && k->kind == kind && k->reaction == reaction) found = id; 269 } 270 return found; 271 } 272 273 /* ---- seat loss and channel reset ----------------------------------------- */ 274 275 static volatile uint32_t *hb_word(RxWorld *w, uint32_t off) { 276 return (volatile uint32_t *)(w->coherent + rx_world_off_heartbeat() + off); 277 } 278 279 /* The chip's pass counter stops moving once its channel is gone. */ 280 static int chip_still(RxWorld *w, int ms) { 281 barrier(); 282 uint32_t a = *hb_word(w, RX_SEAT_HB_LIVE); 283 sleep_ms(ms); 284 barrier(); 285 return *hb_word(w, RX_SEAT_HB_LIVE) == a; 286 } 287 288 static uint64_t crumbs_of(RxWorld *w, uint32_t reaction, RxCrumbKind kind, int reason, 289 uint64_t *last) { 290 uint64_t n = 0; 291 for (uint64_t id = 1; id <= w->n_crumbs; id++) { 292 const RxCrumb *k = rx_world_crumb(w, id); 293 if (!k || k->reaction != reaction || k->kind != kind) continue; 294 if (reason && k->reason != reason) continue; 295 n++; 296 if (last) *last = id; 297 } 298 return n; 299 } 300 301 static int seats_holding(RxWorld *w) { 302 int n = 0; 303 for (uint32_t i = 0; i < w->n_reactions; i++) 304 if (w->reactions[i].resident_seat) n++; 305 return n; 306 } 307 308 /* A fresh A -> seat -> B -> processor -> C chain for the loss scenarios. */ 309 typedef struct { 310 RxObjRef a, b, c; 311 RxCapRef in, out, ext; 312 uint32_t seat, dep; 313 Chain ch; 314 } Rig; 315 316 static Rig g_rig; 317 318 static int rig_up(RxWorld *w, Rig *g, uint64_t res) { 319 uint64_t zero[RX_MAX_FIELDS] = { 0 }; 320 if (rx_world_create(w, 1, RX_PERSIST_RESIDENT, res, zero, &g->a) != RX_OK || 321 rx_world_create(w, 1, RX_PERSIST_RESIDENT, res + 1, zero, &g->b) != RX_OK || 322 rx_world_create(w, 1, RX_PERSIST_RESIDENT, res + 2, zero, &g->c) != RX_OK || 323 rx_world_attach_physical(w, g->a) != RX_OK || rx_world_attach_physical(w, g->b) != RX_OK) 324 return -1; 325 g->in = mint(SUBJ_SEAT, res, RX_RIGHT_READ); 326 g->out = mint(SUBJ_SEAT, res + 1, RX_RIGHT_READ | RX_RIGHT_WRITE); 327 g->ext = mint(SUBJ_EXTERNAL, res, RX_RIGHT_WRITE); 328 RxCapRef dr = mint(SUBJ_DEPEND, res + 1, RX_RIGHT_READ); 329 RxCapRef dw = mint(SUBJ_DEPEND, res + 2, RX_RIGHT_WRITE); 330 if (rx_world_bind_capability(w, g->a, g->in) != RX_OK || 331 rx_world_bind_capability(w, g->b, g->out) != RX_OK) 332 return -1; 333 RxReactionDesc d; 334 desc_init(&d, "resident.seat.add", SUBJ_SEAT, fn_poison, NULL); 335 d.need.accelerator_features = RX_ACCEL_BLACKWELL; 336 d.n_triggers = 1; 337 d.triggers[0] = (RxDep){ g->a, RX_FIELD(0) | RX_FIELD(1) }; 338 d.n_writes = 1; 339 d.writes[0] = (RxDep){ g->b, RX_FIELD(0) }; 340 d.n_caps = 2; 341 d.caps[0] = (RxCapNeed){ g->in, res, RX_RIGHT_READ }; 342 d.caps[1] = (RxCapNeed){ g->out, res + 1, RX_RIGHT_WRITE }; 343 if (rx_world_add_reaction(w, &d, &g->seat) != RX_OK) return -1; 344 g->ch = (Chain){ g->b, g->c }; 345 desc_init(&d, "cpu.dependent", SUBJ_DEPEND, fn_depend, &g->ch); 346 d.n_triggers = 1; 347 d.triggers[0] = (RxDep){ g->b, RX_FIELD(0) }; 348 d.n_reads = 1; 349 d.reads[0] = (RxDep){ g->b, RX_FIELD(0) }; 350 d.n_writes = 1; 351 d.writes[0] = (RxDep){ g->c, RX_FIELD(0) }; 352 d.n_caps = 2; 353 d.caps[0] = (RxCapNeed){ dr, res + 1, RX_RIGHT_READ }; 354 d.caps[1] = (RxCapNeed){ dw, res + 2, RX_RIGHT_WRITE }; 355 return rx_world_add_reaction(w, &d, &g->dep) == RX_OK ? 0 : -1; 356 } 357 358 /* Every claim ever posted has ended exactly once and nothing is held. */ 359 static void check_settled(RxWorld *w, const char *when) { 360 CHECK(w->stats.resident_claims == w->stats.resident_closed, 361 "%s: claims %llu ended %llu", when, (unsigned long long)w->stats.resident_claims, 362 (unsigned long long)w->stats.resident_closed); 363 CHECK(seats_holding(w) == 0, "%s: a claim is still held", when); 364 CHECK(w->used_slots == 0 && w->used_memory == 0 && w->used_energy == 0, 365 "%s: a resource charge was not released (%u slots)", when, w->used_slots); 366 } 367 368 /* Takes every result as it lands. A result computed from an A that has 369 * since moved is refused as torn; the rearmed activation runs again. */ 370 typedef struct { 371 RxWorld *w; 372 atomic_int stop; 373 uint64_t ok, stale, input_moved, other; 374 int other_rc; 375 } Acceptor; 376 377 static void *acceptor_main(void *arg) { 378 Acceptor *a = arg; 379 while (!atomic_load(&a->stop)) { 380 int rc = rx_resident_accept(a->w); 381 if (rc == RX_OK) a->ok++; 382 else if (rc == RX_ERR_STALE_GEN) a->stale++; 383 else if (rc == RX_ERR_TORN) a->input_moved++; 384 else if (rc == RX_ERR_NOT_FOUND) { 385 struct timespec ts = { 0, 100000L }; 386 nanosleep(&ts, NULL); 387 } else { 388 a->other++; 389 a->other_rc = rc; 390 } 391 } 392 return NULL; 393 } 394 395 /* Keeps changing A for the whole scenario, including while a channel is 396 * being torn down, so resets land on work in flight. */ 397 typedef struct { 398 RxWorld *w; 399 RxCapRef ext; 400 RxObjRef a; 401 atomic_int stop; 402 atomic_ullong want; 403 uint64_t sent; 404 } Loader; 405 406 static void *loader_main(void *arg) { 407 Loader *l = arg; 408 for (uint64_t n = 0; !atomic_load(&l->stop); n++) { 409 uint64_t x = 1000u + n, y = n % 7u; 410 RxMutation m[2] = { { l->a, 0, x }, { l->a, 1, y } }; 411 if (rx_world_publish_external(l->w, l->ext, m, 2) > 0) { 412 atomic_store(&l->want, (uint64_t)(uint32_t)(x + y)); 413 l->sent++; 414 } 415 /* Paced so the causal record holds the whole scenario. */ 416 struct timespec ts = { 0, 4000000L }; 417 nanosleep(&ts, NULL); 418 } 419 return NULL; 420 } 421 422 static uint64_t g_resets, g_resets_in_flight, g_claims_lost, g_kill_lost, g_kill_ms_max; 423 424 static uint32_t xs32(uint32_t *s) { 425 uint32_t x = *s; 426 x ^= x << 13; 427 x ^= x >> 17; 428 x ^= x << 5; 429 return *s = x; 430 } 431 432 static void binary_digest(char out[65]) { 433 strcpy(out, "unavailable"); 434 FILE *f = fopen("/proc/self/exe", "rb"); 435 if (!f) return; 436 sha256_ctx c; 437 sha256_init(&c); 438 uint8_t buf[65536]; 439 size_t n; 440 while ((n = fread(buf, 1, sizeof buf, f)) > 0) sha256_update(&c, buf, n); 441 fclose(f); 442 uint8_t d[32]; 443 sha256_final(&c, d); 444 for (int i = 0; i < 32; i++) sprintf(out + i * 2, "%02x", d[i]); 445 } 446 447 static void write_receipt(void) { 448 char path[512]; 449 if (omega_evidence_path("R12/rx_resident_silicon_receipt.json", path, sizeof path) != 0) return; 450 FILE *f = fopen(path, "w"); 451 if (!f) return; 452 char commit[41]; 453 memset(commit, 0, sizeof commit); 454 if (!omega_evidence_run_commit(commit)) memcpy(commit, "unknown", 8); 455 const char *candidate = getenv("OMEGA_CANDIDATE_COMMIT"); 456 const char *aienos = getenv("AIENOS_COMMIT"); 457 const char *physics = getenv("PHYSICS_COMMIT"); 458 int bound = candidate && candidate[0] && strcmp(candidate, commit) == 0 && 459 !omega_evidence_tree_dirty(); 460 int claimed = g_silicon && g_fail == 0 && bound; 461 char digest[65]; 462 binary_digest(digest); 463 struct utsname u; 464 memset(&u, 0, sizeof u); 465 uname(&u); 466 fprintf(f, 467 "{\n" 468 " \"schema\": \"AIEN_RX_R12_RESIDENT_SILICON_V3\",\n" 469 " \"run_id\": \"%s\",\n" 470 " \"candidate_commit\": %s%s%s,\n" 471 " \"candidate_bound\": %s,\n" 472 " \"run_commit\": \"%s\",\n" 473 " \"tree_dirty\": %s,\n" 474 " \"aienos_commit\": \"%s\",\n" 475 " \"physics_commit\": \"%s\",\n" 476 " \"authority\": \"native AIENOS capability authority (C); Linux stand-in not started\",\n" 477 " \"seat_body\": \"qualified 32-bit integer add (IADD3), A.field0 + A.field1 -> B.field0\",\n" 478 " \"checks\": %d,\n" 479 " \"failures\": %d,\n" 480 " \"silicon_observed\": %s,\n" 481 " \"claimed\": %s,\n" 482 " \"test_binary_sha256\": \"%s\",\n" 483 " \"host\": {\"sysname\": \"%s\", \"release\": \"%s\", \"machine\": \"%s\"},\n" 484 " \"hardware_scope\": \"one persistent graphics seat on the machine's own chip, same image as the processor\",\n" 485 " \"scenarios\": [\n", 486 omega_evidence_run_id(), candidate ? "\"" : "", candidate ? candidate : "null", 487 candidate ? "\"" : "", bound ? "true" : "false", commit, 488 omega_evidence_tree_dirty() ? "true" : "false", aienos ? aienos : "unknown", 489 physics ? physics : "unknown", g_checks, g_fail, g_silicon ? "true" : "false", 490 claimed ? "true" : "false", digest, u.sysname, u.release, u.machine); 491 for (int i = 0; i < g_nsc; i++) 492 fprintf(f, " {\"name\": \"%s\", \"result\": \"%s\"}%s\n", g_sc[i].name, 493 g_sc[i].passed ? "PASS" : "FAIL", i + 1 < g_nsc ? "," : ""); 494 fprintf(f, 495 " ],\n" 496 " \"seat_loss\": {\"killed_holding_claims_lost\": %llu, \"channel_resets\": %llu, " 497 "\"resets_with_work_in_flight\": %llu, \"claims_lost_and_retried\": %llu, " 498 "\"longest_channel_teardown_ms\": %llu, " 499 "\"kill_method\": \"host destroys the running channel group; not a chip-raised fault\"},\n" 500 " \"not_exercised\": [\"recovery from a chip-raised fault (MMU fault, Xid) rather than a " 501 "host-initiated channel teardown\", \"seat lost before its first heartbeat\"],\n" 502 " \"gates\": {\n", 503 (unsigned long long)g_kill_lost, (unsigned long long)g_resets, 504 (unsigned long long)g_resets_in_flight, (unsigned long long)g_claims_lost, 505 (unsigned long long)g_kill_ms_max); 506 fprintf(f, 507 " \"R12_RESIDENT_SEAT\": \"%s\",\n" 508 " \"not_claimed\": [\"R8\", \"R10\", \"R11\", \"R13\"%s]\n" 509 " }\n" 510 "}\n", 511 claimed ? "PASS" : (g_silicon ? "SILICON_PASS_UNBOUND" : "NOT_CLAIMED"), 512 claimed ? "" : ", \"R12\""); 513 fclose(f); 514 printf("receipt: %s\n", path); 515 } 516 517 int main(void) { 518 signal(SIGPIPE, SIG_IGN); 519 setvbuf(stdout, NULL, _IONBF, 0); 520 printf("[*] R12 resident seat on this machine's graphics chip\n"); 521 int fixtures = omega_blackwell_verify_codegen_fixtures(); 522 CHECK(fixtures == 0, "instruction checks %d", fixtures); 523 524 AienosCapView *view = NULL; 525 RxWorld w; 526 memset(&w, 0, sizeof w); 527 int auth_up = 0, world_up = 0, observed = 0; 528 RxGpuSeat *seat = NULL; 529 CHECK(aienos_cap_start(&g_admin, &view) == 0, "the native authority did not start"); 530 if (g_fail) goto done; 531 auth_up = 1; 532 CHECK(rx_world_init_native(&w, view, 2, 1u << 16) == RX_OK, "world did not start"); 533 if (g_fail) goto done; 534 world_up = 1; 535 w.external_subject = SUBJ_EXTERNAL; 536 537 uint64_t zero[RX_MAX_FIELDS] = { 0 }; 538 RxObjRef A = { UINT32_MAX, 0 }, B = { UINT32_MAX, 0 }, C = { UINT32_MAX, 0 }; 539 CHECK(rx_world_create(&w, 1, RX_PERSIST_RESIDENT, RES_A, zero, &A) == RX_OK, "object A"); 540 CHECK(rx_world_create(&w, 1, RX_PERSIST_RESIDENT, RES_B, zero, &B) == RX_OK, "object B"); 541 CHECK(rx_world_create(&w, 1, RX_PERSIST_RESIDENT, RES_C, zero, &C) == RX_OK, "object C"); 542 CHECK(rx_world_attach_physical(&w, A) == RX_OK, "A has no window"); 543 CHECK(rx_world_attach_physical(&w, B) == RX_OK, "B has no window"); 544 Chain ch = { B, C }; 545 546 RxCapRef seat_in = mint(SUBJ_SEAT, RES_A, RX_RIGHT_READ); 547 RxCapRef seat_out = mint(SUBJ_SEAT, RES_B, RX_RIGHT_READ | RX_RIGHT_WRITE); 548 RxCapRef ext = mint(SUBJ_EXTERNAL, RES_A, RX_RIGHT_WRITE); 549 RxCapRef dep_r = mint(SUBJ_DEPEND, RES_B, RX_RIGHT_READ); 550 RxCapRef dep_w = mint(SUBJ_DEPEND, RES_C, RX_RIGHT_WRITE); 551 CHECK(seat_in.cap_id != UINT32_MAX && seat_out.cap_id != UINT32_MAX && 552 ext.cap_id != UINT32_MAX && dep_r.cap_id != UINT32_MAX && 553 dep_w.cap_id != UINT32_MAX, 554 "the native authority did not mint"); 555 CHECK(rx_world_bind_capability(&w, A, seat_in) == RX_OK, "A capability not bound"); 556 CHECK(rx_world_bind_capability(&w, B, seat_out) == RX_OK, "B capability not bound"); 557 CHECK(rx_world_enable_resident(&w) == RX_OK, "resident seat not enabled"); 558 offer(&w); 559 560 RxCapRef forged = { 200, 7 }; 561 RxMutation bad = { A, 0, 5 }; 562 CHECK(rx_world_publish_external(&w, forged, &bad, 1) == RX_ERR_AUTHORITY, 563 "a forged capability published"); 564 565 uint32_t seat_id = 0, dep_id = 0; 566 CHECK(add_seat(&w, A, B, seat_in, seat_out, &seat_id) == RX_OK, "seat not registered"); 567 RxReactionDesc d; 568 desc_init(&d, "cpu.dependent", SUBJ_DEPEND, fn_depend, &ch); 569 d.n_triggers = 1; 570 d.triggers[0] = (RxDep){ B, RX_FIELD(0) }; 571 d.n_reads = 1; 572 d.reads[0] = (RxDep){ B, RX_FIELD(0) }; 573 d.n_writes = 1; 574 d.writes[0] = (RxDep){ C, RX_FIELD(0) }; 575 d.n_caps = 2; 576 d.caps[0] = (RxCapNeed){ dep_r, RES_B, RX_RIGHT_READ }; 577 d.caps[1] = (RxCapNeed){ dep_w, RES_C, RX_RIGHT_WRITE }; 578 CHECK(rx_world_add_reaction(&w, &d, &dep_id) == RX_OK, "dependent not registered"); 579 if (g_fail) goto done; 580 581 int began = rx_gpu_seat_begin(&w, &seat); 582 CHECK(began == 0 && seat != NULL, "the graphics seat did not show a heartbeat"); 583 if (began != 0 || !seat) goto done; 584 585 /* 1. The chain. */ 586 begin("chain A -> chip add -> B -> processor -> C"); 587 { 588 int64_t cause = stimulate(&w, ext, A, 40, 2); 589 CHECK(cause > 0, "stimulus was not published"); 590 uint64_t before = g2c_tail(&w); 591 CHECK(wait_claimed(&w, seat_id) == 0, "the admitted seat did not post a claim"); 592 CHECK(wait_chip(&w, before) == 0, "the chip did not answer"); 593 barrier(); 594 uint32_t pick = *hb_word(&w, RX_SEAT_HB_T_PICK); 595 uint32_t done_ns = *hb_word(&w, RX_SEAT_HB_T_DONE); 596 uint32_t chip_ns = done_ns - pick; /* low 32-bit timer wraps naturally */ 597 CHECK(pick != 0 && chip_ns > 0 && chip_ns < 1000000000u, 598 "chip timing stamps are invalid (pickup %u, duration %u ns)", 599 pick, chip_ns); 600 CHECK(g_poison == 0, "the seat was called as a function"); 601 CHECK(load_u64(window(&w, B)) == 42, "the chip did not write the sum into B's window"); 602 CHECK(field_of(&w, B, 0) == 0, "B changed before publication"); 603 int acc = poll_accept(&w); 604 CHECK(acc == RX_OK, "the chip publication was not accepted (%d)", acc); 605 observed = acc == RX_OK; 606 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "the processor dependent did not finish"); 607 CHECK(field_of(&w, A, 0) == 40 && field_of(&w, A, 1) == 2, "A changed"); 608 CHECK(field_of(&w, B, 0) == 42, "B is not A.field0 + A.field1"); 609 CHECK(field_of(&w, C, 0) == 43, "C did not observe B"); 610 CHECK(w.objects[B.id].coherency == RX_COHERENCY_SEAT, "B not marked from the seat"); 611 CHECK(w.objects[A.id].generation == A.generation && 612 w.objects[B.id].generation == B.generation, 613 "an identity moved"); 614 uint64_t sk_id = last_commit_of(&w, seat_id), dk_id = last_commit_of(&w, dep_id); 615 CHECK(sk_id && dk_id, "the causal record is missing a commit"); 616 if (sk_id && dk_id) { 617 const RxCrumb *sk = rx_world_crumb(&w, sk_id); 618 const RxCrumb *dk = rx_world_crumb(&w, dk_id); 619 CHECK(sk->worker == RX_SEAT_BLACKWELL, "the seat commit is not marked as the chip"); 620 CHECK(sk->wake_cause == (uint64_t)cause, "the seat cause is not the stimulus"); 621 CHECK(dk->wake_cause == sk_id, "C was not woken by the chip's publication"); 622 CHECK(rx_world_explain(&w, B, 0) == sk_id, "B has no chip writer"); 623 CHECK(rx_world_explain(&w, C, 0) == dk_id, "C has no dependent writer"); 624 } 625 uint64_t checked = 0; 626 CHECK(rx_world_verify_crumbs(&w, &checked) == 0, "the causal chain did not verify"); 627 } 628 end(); 629 630 /* 2. The same completion delivered twice. */ 631 begin("duplicate completion is not published twice"); 632 { 633 OmegaSharedWorldRing *g = ring_at(&w, rx_world_off_g2c()); 634 barrier(); 635 uint64_t t = g->tail; 636 memcpy(&g->slots[t & g->mask], &g->slots[(t - 1) & g->mask], sizeof(OmegaSharedWorldDesc)); 637 barrier(); 638 g->tail = t + 1; 639 barrier(); 640 uint64_t commits = w.reactions[seat_id].commits; 641 uint64_t head_before = g->head; 642 int acc = rx_resident_accept(&w); 643 CHECK(acc != RX_OK, "a repeated completion was accepted"); 644 barrier(); 645 CHECK(g->head == head_before + 1, "the repeated completion was not consumed"); 646 CHECK(w.reactions[seat_id].commits == commits, "a repeated completion committed"); 647 CHECK(field_of(&w, B, 0) == 42 && field_of(&w, C, 0) == 43, "a repeat changed B or C"); 648 } 649 end(); 650 651 /* 3. A torn result notice. */ 652 begin("torn result notice is refused and B is restored"); 653 { 654 uint64_t before = g2c_tail(&w); 655 CHECK(stimulate(&w, ext, A, 1000, 1) > 0, "stimulus"); 656 CHECK(wait_claimed(&w, seat_id) == 0, "no claim"); 657 CHECK(wait_chip(&w, before) == 0, "the chip did not answer"); 658 OmegaSharedWorldRing *g = ring_at(&w, rx_world_off_g2c()); 659 g->slots[before & g->mask].payload[12] ^= 0x40; 660 barrier(); 661 int acc = poll_accept(&w); 662 CHECK(acc == RX_ERR_TORN, "a torn notice was not refused (%d)", acc); 663 CHECK(field_of(&w, B, 0) == 42, "a torn notice changed B"); 664 CHECK(load_u64(window(&w, B)) == 42, "B's window was not restored"); 665 CHECK(last_crumb_of(&w, seat_id, RX_CRUMB_REJECTED) != 0, "no rejection in the record"); 666 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "world did not settle"); 667 CHECK(field_of(&w, C, 0) == 43, "C moved without a publication"); 668 } 669 end(); 670 671 /* 4. The seat leaves and a new one starts; identity stays with the world. */ 672 begin("seat restart keeps identity and history"); 673 { 674 uint64_t n_crumbs = w.n_crumbs; 675 CHECK(rx_resident_shutdown(&w) == RX_OK, "shutdown was not posted"); 676 int finished = rx_gpu_seat_finish(seat); 677 seat = NULL; 678 CHECK(finished == 0, "the seat did not leave cleanly"); 679 CHECK(field_of(&w, A, 0) == 1000 && field_of(&w, B, 0) == 42 && field_of(&w, C, 0) == 43, 680 "objects changed when the seat left"); 681 CHECK(w.objects[A.id].generation == A.generation && 682 w.objects[B.id].generation == B.generation && 683 w.objects[C.id].generation == C.generation, 684 "an identity moved when the seat left"); 685 CHECK(w.n_crumbs >= n_crumbs, "history shrank"); 686 began = rx_gpu_seat_begin(&w, &seat); 687 CHECK(began == 0 && seat, "the second seat did not start"); 688 if (began != 0 || !seat) goto done; 689 uint64_t before = g2c_tail(&w); 690 int64_t cause = stimulate(&w, ext, A, 7, 8); 691 CHECK(cause > 0, "stimulus"); 692 CHECK(wait_claimed(&w, seat_id) == 0, "no claim"); 693 CHECK(wait_chip(&w, before) == 0, "the second seat did not answer"); 694 CHECK(poll_accept(&w) == RX_OK, "the second seat's publication was refused"); 695 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "world did not settle"); 696 CHECK(field_of(&w, B, 0) == 15 && field_of(&w, C, 0) == 16, 697 "the chain did not run again after restart"); 698 uint64_t checked = 0; 699 CHECK(rx_world_verify_crumbs(&w, &checked) == 0, "history did not verify across restart"); 700 } 701 end(); 702 703 /* 5. B's physical window goes away while the chip holds the claim. */ 704 begin("detached window refuses the publication"); 705 { 706 uint64_t before = g2c_tail(&w); 707 CHECK(stimulate(&w, ext, A, 20, 22) > 0, "stimulus"); 708 CHECK(wait_claimed(&w, seat_id) == 0, "no claim"); 709 CHECK(wait_chip(&w, before) == 0, "the chip did not answer"); 710 CHECK(rx_world_detach_physical(&w, B) == RX_OK, "B could not be detached"); 711 int acc = poll_accept(&w); 712 CHECK(acc != RX_OK, "a publication into a detached window was accepted"); 713 CHECK(field_of(&w, B, 0) == 15, "B changed through a detached window"); 714 CHECK(rx_world_attach_physical(&w, B) == RX_OK, "B could not be attached again"); 715 CHECK(rx_world_bind_capability(&w, B, seat_out) == RX_OK, "B capability not rebound"); 716 CHECK(load_u64(window(&w, B)) == 15, "the new window does not show canonical B"); 717 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "world did not settle"); 718 CHECK(field_of(&w, C, 0) == 16, "C moved without a publication"); 719 } 720 end(); 721 722 /* 6. Authority is taken back after the claim, before publication. */ 723 begin("capability revoked after the claim is refused at publication"); 724 { 725 uint64_t before = g2c_tail(&w); 726 CHECK(stimulate(&w, ext, A, 100, 5) > 0, "stimulus"); 727 CHECK(wait_claimed(&w, seat_id) == 0, "no claim"); 728 CHECK(wait_chip(&w, before) == 0, "the chip did not answer"); 729 CHECK(load_u64(window(&w, B)) == 105, "the chip did not compute"); 730 CHECK(revoke_cap(seat_out) == 0, "the native authority did not revoke"); 731 int acc = poll_accept(&w); 732 CHECK(acc == RX_ERR_AUTHORITY, "a revoked capability published (%d)", acc); 733 CHECK(field_of(&w, B, 0) == 15, "B changed without authority"); 734 CHECK(load_u64(window(&w, B)) == 15, "B's window was not restored"); 735 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "world did not settle"); 736 CHECK(field_of(&w, C, 0) == 16, "C moved without a publication"); 737 /* A fresh grant, a fresh seat registration. The revoked one stays blocked. */ 738 seat_out = mint(SUBJ_SEAT, RES_B, RX_RIGHT_READ | RX_RIGHT_WRITE); 739 CHECK(rx_world_bind_capability(&w, B, seat_out) == RX_OK, "fresh capability not bound"); 740 CHECK(add_seat(&w, A, B, seat_in, seat_out, &seat_id) == RX_OK, "fresh seat not registered"); 741 } 742 end(); 743 744 /* 7. A's generation moves while the chip holds the claim. */ 745 begin("generation moved in flight invalidates the chip's work"); 746 { 747 uint64_t before = g2c_tail(&w); 748 CHECK(stimulate(&w, ext, A, 3, 4) > 0, "stimulus"); 749 CHECK(wait_claimed(&w, seat_id) == 0, "no claim"); 750 CHECK(wait_chip(&w, before) == 0, "the chip did not answer"); 751 uint32_t old_gen = A.generation; 752 CHECK(rx_world_retire(&w, A) == RX_OK, "A was not retired"); 753 CHECK(w.objects[A.id].generation != old_gen, "A's generation did not move"); 754 int acc = poll_accept(&w); 755 CHECK(acc == RX_ERR_STALE_GEN, "work on an old generation published (%d)", acc); 756 CHECK(field_of(&w, B, 0) == 15, "old-generation work changed B"); 757 CHECK(last_crumb_of(&w, seat_id, RX_CRUMB_INVALIDATED) != 0, "no invalidation in the record"); 758 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "world did not settle"); 759 } 760 end(); 761 762 /* 8. A claim naming the old generation, sent straight to the chip. */ 763 begin("stale generation claim is refused on the chip"); 764 { 765 uint8_t *bw = w.coherent + w.objects[B.id].region_offset; 766 store_u64(bw, SENTINEL); 767 barrier(); 768 uint64_t head_before = c2g_head(&w); 769 uint64_t before = g2c_tail(&w); 770 OmegaSharedWorldDesc stale; 771 memset(&stale, 0, sizeof stale); 772 stale.msg_type = RX_RING_CLAIM; 773 stale.object_id = A.id; 774 stale.object_generation = A.generation; /* the retired one */ 775 stale.object_length = 64; 776 stale.payload_len = RX_CAP_PAYLOAD; 777 /* The current seat generation: only the object generation is stale. */ 778 stale.producer_generation = w.seat_generation; 779 for (int i = 0; i < 4; i++) { 780 stale.payload[24 + i] = (uint8_t)(B.id >> (8 * i)); 781 stale.payload[28 + i] = (uint8_t)(w.objects[B.id].generation >> (8 * i)); 782 } 783 rx_world_seal_descriptor(&stale); 784 CHECK(rx_world_inject_descriptor(&w, &stale) == RX_OK, "the old claim was not posted"); 785 int moved = 0; 786 for (int i = 0; i < 3000 && !moved; i++) { 787 if (c2g_head(&w) > head_before) moved = 1; 788 else sleep_ms(1); 789 } 790 CHECK(moved, "the chip did not consume the old claim"); 791 CHECK(wait_chip(&w, before) == 0, "the chip did not answer the old claim"); 792 OmegaSharedWorldRing *g = ring_at(&w, rx_world_off_g2c()); 793 uint16_t msg = g->slots[before & g->mask].msg_type; 794 CHECK(msg == RX_RING_FAULT, "the chip did not answer with a fault (%u)", msg); 795 CHECK(load_u64(bw) == SENTINEL, "an old generation changed B's window"); 796 barrier(); 797 g->head = g->tail; /* drain the fault notice; there is no reaction for it */ 798 barrier(); 799 } 800 end(); 801 802 /* 9. The seat is killed while it holds a claim. */ 803 begin("seat killed holding a claim: recorded, restored, released once, retried"); 804 { 805 Rig *g = &g_rig; 806 CHECK(rig_up(&w, g, 0x40) == 0, "the second chain was not built"); 807 if (g_fail) goto done; 808 uint32_t gen0 = w.seat_generation; 809 uint32_t ga = g->a.generation, gb = g->b.generation, gc = g->c.generation; 810 *hb_word(&w, RX_SEAT_HB_HOLD) = 1; 811 barrier(); 812 uint64_t before = g2c_tail(&w); 813 int64_t cause = stimulate(&w, g->ext, g->a, 30, 12); 814 CHECK(cause > 0, "stimulus"); 815 CHECK(wait_claimed(&w, g->seat) == 0, "no claim"); 816 uint64_t seq = w.reactions[g->seat].resident_seq; 817 int held = 0; 818 for (int i = 0; i < 3000 && !held; i++) { 819 barrier(); 820 if (*hb_word(&w, RX_SEAT_HB_HELD) == (uint32_t)(seq + 1)) held = 1; 821 else sleep_ms(1); 822 } 823 CHECK(held, "the chip did not reach the hold with this claim"); 824 CHECK(load_u64(window(&w, g->b)) == 42, "the chip did not write B's window before the hold"); 825 CHECK(g2c_tail(&w) == before, "the chip posted a result while holding"); 826 CHECK(!chip_still(&w, 20), "the holding seat is not alive"); 827 OmegaSharedWorldRing *c2g = ring_at(&w, rx_world_off_c2g()); 828 OmegaSharedWorldDesc old = c2g->slots[seq & c2g->mask]; 829 uint64_t fails0 = w.stats.transitions[RX_RUNNING][RX_FAILED]; 830 831 CHECK(rx_gpu_seat_kill(seat) == 0, "the channel was not destroyed"); 832 CHECK(chip_still(&w, 50), "the chip still runs after its channel was destroyed"); 833 int lost = rx_resident_seat_lost(&w, 1); 834 g_kill_lost = lost > 0 ? (uint64_t)lost : 0; 835 CHECK(lost == 1, "the held claim was not declared lost (%d)", lost); 836 CHECK(w.seat_generation == gen0 + 1, "the seat generation did not move"); 837 CHECK(w.stats.transitions[RX_RUNNING][RX_FAILED] == fails0 + 1, "a claim failed twice"); 838 CHECK(load_u64(window(&w, g->b)) == 0, "B's window still holds the dead seat's sum"); 839 CHECK(field_of(&w, g->b, 0) == 0 && field_of(&w, g->c, 0) == 0, "B or C moved"); 840 uint64_t fail_id = 0; 841 CHECK(crumbs_of(&w, g->seat, RX_CRUMB_FAILED, RX_ERR_SEAT_LOST, &fail_id) == 1, 842 "no single seat-lost crumb"); 843 if (fail_id) { 844 const RxCrumb *k = rx_world_crumb(&w, fail_id); 845 CHECK(k->wake_cause == (uint64_t)cause && k->worker == RX_SEAT_BLACKWELL, 846 "the loss does not name the stimulus and the chip"); 847 } 848 int finished = rx_gpu_seat_finish(seat); 849 seat = NULL; 850 CHECK(finished == 0, "the killed seat did not return the image"); 851 852 began = rx_gpu_seat_begin(&w, &seat); 853 CHECK(began == 0 && seat, "a new seat did not start after the loss"); 854 if (began != 0 || !seat) goto done; 855 CHECK(wait_claimed(&w, g->seat) == 0, "the lost work was not retried"); 856 CHECK(w.reactions[g->seat].resident_parent == fail_id, "the retry is not caused by the loss"); 857 int acc = poll_accept(&w); 858 CHECK(acc == RX_OK, "the retried result was refused (%d)", acc); 859 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "world did not settle"); 860 CHECK(field_of(&w, g->b, 0) == 42 && field_of(&w, g->c, 0) == 43, 861 "the retried work did not reach B and C"); 862 uint64_t commit_id = 0; 863 CHECK(crumbs_of(&w, g->seat, RX_CRUMB_COMMIT, 0, &commit_id) == 1 && 864 w.reactions[g->seat].commits == 1, 865 "the work was not published exactly once"); 866 if (commit_id) 867 CHECK(rx_world_crumb(&w, commit_id)->wake_cause == fail_id, 868 "the publication is not caused by the loss"); 869 CHECK(rx_world_validate_cap(&w, g->in, SUBJ_SEAT, 0x40, RX_RIGHT_READ, NULL) == RX_CAP_OK && 870 rx_world_validate_cap(&w, g->out, SUBJ_SEAT, 0x41, RX_RIGHT_WRITE, NULL) == 871 RX_CAP_OK, 872 "the authority lost a grant across the loss"); 873 CHECK(w.objects[g->a.id].generation == ga && w.objects[g->b.id].generation == gb && 874 w.objects[g->c.id].generation == gc, 875 "an object generation moved"); 876 877 /* The dead seat's claim, posted again: the new seat refuses it. */ 878 uint64_t before2 = g2c_tail(&w); 879 CHECK(rx_world_inject_descriptor(&w, &old) == RX_OK, "the old claim was not posted"); 880 CHECK(wait_chip(&w, before2) == 0, "the new seat did not answer the old claim"); 881 OmegaSharedWorldRing *g2 = ring_at(&w, rx_world_off_g2c()); 882 CHECK(g2->slots[before2 & g2->mask].msg_type == RX_RING_FAULT, 883 "the new seat took the old claim"); 884 CHECK(load_u64(window(&w, g->b)) == 42, "the old claim changed B's window"); 885 CHECK(poll_accept(&w) == RX_ERR_STALE_GEN, "the old seat's generation was accepted"); 886 CHECK(w.reactions[g->seat].commits == 1 && field_of(&w, g->c, 0) == 43, 887 "the old claim published"); 888 check_settled(&w, "after the kill"); 889 uint64_t checked = 0; 890 CHECK(rx_world_verify_crumbs(&w, &checked) == 0, "history did not verify across the kill"); 891 } 892 end(); 893 894 /* 10. The channel is destroyed and rebuilt again and again while claims 895 * flow. The image stays in place; the seat is launched again on it. */ 896 begin("channel reset under load"); 897 { 898 Rig *g = &g_rig; 899 uint32_t gen0 = w.seat_generation; 900 uint32_t ga = g->a.generation, gb = g->b.generation, gc = g->c.generation; 901 uint64_t commits0 = w.reactions[g->seat].commits; 902 Acceptor ac; 903 memset(&ac, 0, sizeof ac); 904 ac.w = &w; 905 Loader ld; 906 memset(&ld, 0, sizeof ld); 907 ld.w = &w; 908 ld.ext = g->ext; 909 ld.a = g->a; 910 pthread_t at, lt; 911 CHECK(pthread_create(&at, NULL, acceptor_main, &ac) == 0, "acceptor did not start"); 912 CHECK(pthread_create(<, NULL, loader_main, &ld) == 0, "load did not start"); 913 uint32_t rng = 0x5eed1234u; 914 const int rounds = 8; 915 uint64_t held_rounds = 0, held_in_flight = 0; 916 for (int i = 0; i < rounds && !g_fail; i++) { 917 struct timespec d = { 0, (long)(20 + xs32(&rng) % 180u) * 1000000L }; 918 nanosleep(&d, NULL); 919 /* Even rounds: the chip holds whatever claim it takes next, so 920 * the reset lands on it. Odd rounds: nothing is arranged. */ 921 int held = (i % 2) == 0; 922 if (held) { 923 *hb_word(&w, RX_SEAT_HB_HOLD) = 1; 924 barrier(); 925 held_rounds++; 926 sleep_ms(20); 927 } 928 struct timespec k0, k1; 929 clock_gettime(CLOCK_MONOTONIC, &k0); 930 CHECK(rx_gpu_seat_kill(seat) == 0, "round %d: the channel was not destroyed", i); 931 clock_gettime(CLOCK_MONOTONIC, &k1); 932 uint64_t ms = (uint64_t)(k1.tv_sec - k0.tv_sec) * 1000u + 933 (uint64_t)((k1.tv_nsec - k0.tv_nsec) / 1000000L); 934 if (ms > g_kill_ms_max) g_kill_ms_max = ms; 935 CHECK(chip_still(&w, 5), "round %d: the chip still runs after the reset", i); 936 int lost = rx_resident_seat_lost(&w, 1); 937 CHECK(lost >= 0, "round %d: recovery failed", i); 938 g_resets++; 939 if (lost > 0) { 940 g_resets_in_flight++; 941 g_claims_lost += (uint64_t)lost; 942 if (held) held_in_flight++; 943 } 944 CHECK(rx_gpu_seat_relaunch(seat) == 0, "round %d: the seat did not come back", i); 945 } 946 atomic_store(&ld.stop, 1); 947 pthread_join(lt, NULL); 948 CHECK(rx_world_wait_quiescent(&w, 5000) == RX_OK, "world did not settle after the load"); 949 atomic_store(&ac.stop, 1); 950 pthread_join(at, NULL); 951 uint64_t want = atomic_load(&ld.want); 952 printf(" resets %llu (held %llu), with work in flight %llu, claims lost and retried %llu,\n" 953 " changes %llu, published %llu, refused as input moved %llu, stale refused %llu,\n" 954 " longest channel teardown %llu ms\n", 955 (unsigned long long)g_resets, (unsigned long long)held_rounds, 956 (unsigned long long)g_resets_in_flight, (unsigned long long)g_claims_lost, 957 (unsigned long long)ld.sent, (unsigned long long)ac.ok, 958 (unsigned long long)ac.input_moved, (unsigned long long)ac.stale, 959 (unsigned long long)g_kill_ms_max); 960 CHECK(g_resets == (uint64_t)rounds, "not every round reset the channel"); 961 CHECK(held_in_flight == held_rounds, "a held round found no claim in flight"); 962 CHECK(ac.other == 0, "the acceptor saw %llu unexpected refusals (last %d)", 963 (unsigned long long)ac.other, ac.other_rc); 964 CHECK(field_of(&w, g->b, 0) == want && field_of(&w, g->c, 0) == want + 1, 965 "after the load B=%llu C=%llu want %llu", (unsigned long long)field_of(&w, g->b, 0), 966 (unsigned long long)field_of(&w, g->c, 0), (unsigned long long)want); 967 check_settled(&w, "after the resets"); 968 CHECK(w.seat_generation == gen0 + (uint32_t)rounds, 969 "the seat generation did not follow the resets"); 970 CHECK(w.objects[g->a.id].generation == ga && w.objects[g->b.id].generation == gb && 971 w.objects[g->c.id].generation == gc, 972 "an object generation moved under resets"); 973 /* Each loss is published at most once. */ 974 for (uint64_t id = 1; id <= w.n_crumbs; id++) { 975 const RxCrumb *k = rx_world_crumb(&w, id); 976 if (!k || k->reaction != g->seat || k->kind != RX_CRUMB_FAILED || 977 k->reason != RX_ERR_SEAT_LOST) 978 continue; 979 uint64_t n = 0; 980 for (uint64_t j = id + 1; j <= w.n_crumbs; j++) { 981 const RxCrumb *c = rx_world_crumb(&w, j); 982 if (c && c->reaction == g->seat && c->kind == RX_CRUMB_COMMIT && c->wake_cause == id) 983 n++; 984 } 985 CHECK(n <= 1, "a lost claim was published %llu times", (unsigned long long)n); 986 } 987 CHECK(w.reactions[g->seat].commits - commits0 == ac.ok, 988 "commits and accepted results differ"); 989 CHECK(w.stats.crumb_overflow == 0, "the causal record overflowed"); 990 CHECK(rx_world_explain(&w, g->c, 0) == last_commit_of(&w, g->dep), "C's writer"); 991 uint64_t checked = 0; 992 CHECK(rx_world_verify_crumbs(&w, &checked) == 0, "history did not verify under resets"); 993 } 994 end(); 995 996 /* Regression (R14). The seat reads the world's projected table, which has 997 * RX_MAX_OBJECTS entries. It refused every claim on an object id of 64 or 998 * more (the frozen ABI's OMEGA_SW_MAX_OBJECTS), while the processor 999 * stand-in accepted them; R14's GPU lanes found it. */ 1000 begin("objects past id 64 are claimed on the chip"); 1001 { 1002 static Rig hi; 1003 uint64_t zero[RX_MAX_FIELDS] = { 0 }; 1004 RxObjRef filler; 1005 uint32_t made = 0; 1006 while (w.n_reactions && made < RX_MAX_OBJECTS && 1007 rx_world_create(&w, 1, RX_PERSIST_RESIDENT, 0x70, zero, &filler) == RX_OK && 1008 filler.id < 200) 1009 made++; 1010 CHECK(rig_up(&w, &hi, 0x80) == 0, "the high chain was not built"); 1011 CHECK(hi.a.id >= 64 && hi.b.id >= 64, "the high chain has ids %u and %u", hi.a.id, hi.b.id); 1012 if (g_fail) goto done; 1013 int64_t cause = stimulate(&w, hi.ext, hi.a, 1000, 24); 1014 CHECK(cause > 0, "stimulus"); 1015 uint64_t before = g2c_tail(&w); 1016 CHECK(wait_claimed(&w, hi.seat) == 0, "no claim on the high chain"); 1017 CHECK(wait_chip(&w, before) == 0, "the chip did not answer"); 1018 OmegaSharedWorldRing *g = ring_at(&w, rx_world_off_g2c()); 1019 CHECK(g->slots[before & g->mask].msg_type == RX_RING_PUBLISH, 1020 "the chip refused a claim on object %u (answer 0x%x)", hi.a.id, 1021 g->slots[before & g->mask].msg_type); 1022 int acc = poll_accept(&w); 1023 CHECK(acc == RX_OK, "the high publication was refused (%d)", acc); 1024 CHECK(rx_world_wait_quiescent(&w, 3000) == RX_OK, "settle"); 1025 CHECK(field_of(&w, hi.b, 0) == 1024 && field_of(&w, hi.c, 0) == 1025, 1026 "B=%llu C=%llu", (unsigned long long)field_of(&w, hi.b, 0), 1027 (unsigned long long)field_of(&w, hi.c, 0)); 1028 check_settled(&w, "after the high chain"); 1029 } 1030 end(); 1031 1032 begin("seat leaves on request"); 1033 { 1034 CHECK(rx_resident_shutdown(&w) == RX_OK, "shutdown was not posted"); 1035 int finished = rx_gpu_seat_finish(seat); 1036 seat = NULL; 1037 CHECK(finished == 0, "the seat did not leave cleanly"); 1038 CHECK(g_poison == 0, "the seat was called as a function"); 1039 CHECK(w.stats.illegal_transitions == 0, "a reaction took an illegal step"); 1040 } 1041 end(); 1042 if (g_fail == 0 && observed) g_silicon = 1; 1043 1044 done: 1045 if (seat) rx_gpu_seat_finish(seat); 1046 if (world_up) rx_world_destroy(&w); 1047 if (auth_up) aienos_cap_stop(g_admin, view); 1048 printf("checks %d failures %d silicon %d\n", g_checks, g_fail, g_silicon); 1049 write_receipt(); 1050 return g_fail ? 1 : 0; 1051 }