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_r11_aien.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_r11_aien.c` 1220 lines · 58844 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 * R11: AIEN as a continuous cognitive faculty (ADR 0016 §44). 19 * 20 * Part A drives AIEN alone. The test plays the rest of the world: it 21 * publishes demand intervals, selection records, placements and goals from 22 * outside, and reads what AIEN publishes back. Every branch of the 23 * cognition is exercised here: no record, a steady record, one outlier, a 24 * change of core class, drift, a goal met and unmet, memory that refuses a 25 * second experiment, and authority. 26 * 27 * Part B is the living run on the DGX Spark with the real Omega faculty. 28 * The whole process starts on the Cortex-A725 cores, where Omega's own 29 * search keeps the semantic reference. The process is then moved to the 30 * Cortex-X925 cores. Nothing asks anyone to re-optimize. AIEN's prediction 31 * fails, AIEN explains the failure by the change of core class, publishes a 32 * plan, and Omega takes it up by itself. A control world without AIEN makes 33 * the same move and stays on the old record. 34 * 35 * Authority is the native Aienux capability authority. 36 */ 37 #include "runtime/aienos_cap.h" 38 #include "runtime/rx_aien.h" 39 #include "runtime/rx_omega.h" 40 #include "runtime/rx_world.h" 41 #include "omega_evidence.h" 42 #include "sha256.h" 43 #include "omega_path_check.h" 44 45 #include 46 #include 47 #include 48 #include 49 #include 50 #include 51 #include 52 #include 53 #include 54 #include 55 56 enum { SUBJ_EXTERNAL = 100, ISSUER = 3 }; 57 58 #define REG_M 64u 59 #define REG_N 256u 60 #define CLASS_X925 0xd85u 61 #define CLASS_A725 0xd87u 62 #define P1 0x111u 63 #define P2 0x222u 64 65 static int g_checks; 66 static int g_fail; 67 68 #define CHECK(cond, ...) do { \ 69 g_checks++; \ 70 if (!(cond)) { \ 71 g_fail++; \ 72 fprintf(stderr, " FAIL %s:%d ", __FILE__, __LINE__); \ 73 fprintf(stderr, __VA_ARGS__); \ 74 fputc('\n', stderr); \ 75 } \ 76 } while (0) 77 78 static uint64_t now_ns(void) { 79 struct timespec ts; 80 clock_gettime(CLOCK_MONOTONIC, &ts); 81 return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; 82 } 83 84 static void sleep_us(int us) { 85 struct timespec ts = { 0, (long)us * 1000L }; 86 nanosleep(&ts, NULL); 87 } 88 89 /* ---- shared environment ---- */ 90 91 typedef struct { 92 AienosCapAdmin *admin; 93 AienosCapView *view; 94 RxWorld w; 95 RxAienFaculty a; 96 RxAienCaps acaps; 97 int with_aien; 98 /* Part A: stand-ins for Omega's demand and selection. */ 99 RxObjRef demand, selection; 100 RxCapRef ext_demand, ext_selection; 101 uint64_t calls, spent, windows; 102 /* Part B: the real Omega faculty. */ 103 int with_omega; 104 RxOmegaFaculty f; 105 RxOmegaCaps ocaps; 106 RxCapRef ext_request; 107 uint64_t seq, served, wrong; 108 /* Not correctness failures: the request never got a result. Under load 109 * a publish can be refused (the crumb log is full) or the answer can miss 110 * the 5 s deadline. Counted apart so they are not reported as wrong. */ 111 uint64_t timed_out, refused; 112 RxCapRef ext_placement, ext_goal; 113 } Env; 114 115 static RxCapRef mint(Env *e, uint32_t subject, uint64_t resource, uint32_t rights) { 116 AienosCapRef office; 117 aienos_cap_office(e->admin, &office); 118 AienosCapMint m = { ISSUER, subject, resource, rights, 0, { UINT32_MAX, 0 }, office }; 119 AienosCapRef r = { UINT32_MAX, 0 }; 120 if (aienos_cap_mint(e->admin, &m, &r) != 0) r = (AienosCapRef){ UINT32_MAX, 0 }; 121 return (RxCapRef){ r.cap_id, r.generation }; 122 } 123 124 static int revoke_cap(Env *e, RxCapRef cap) { 125 AienosCapRef office; 126 aienos_cap_office(e->admin, &office); 127 return aienos_cap_revoke(e->admin, office, (AienosCapRef){ cap.cap_id, cap.generation }); 128 } 129 130 static uint64_t fld(Env *e, RxObjRef r, uint32_t i) { 131 RxObject o; 132 if (rx_world_read(&e->w, r, &o) != RX_OK) return UINT64_MAX; 133 return o.field[i]; 134 } 135 136 static int settle(Env *e) { return rx_world_wait_quiescent(&e->w, 20000); } 137 138 static int publish(Env *e, RxCapRef cap, RxObjRef o, const uint32_t *fields, 139 const uint64_t *vals, uint32_t n) { 140 RxMutation m[RX_MAX_FIELDS]; 141 for (uint32_t i = 0; i < n; i++) m[i] = (RxMutation){ o, fields[i], vals[i] }; 142 int64_t id = rx_world_publish_external(&e->w, cap, m, n); 143 return id > 0 ? 0 : -1; 144 } 145 146 static void place(Env *e, uint64_t cls) { 147 uint64_t s = fld(e, e->a.o.placement, 0) + 1; 148 uint32_t f[2] = { 0, 1 }; 149 uint64_t v[2] = { s, cls }; 150 CHECK(publish(e, e->ext_placement, e->a.o.placement, f, v, 2) == 0, "placement refused"); 151 } 152 153 static void set_goal(Env *e, uint64_t regime, uint64_t target_ns) { 154 uint64_t s = fld(e, e->a.o.goal, 0) + 1; 155 uint32_t f[3] = { 0, 1, 2 }; 156 uint64_t v[3] = { s, regime, target_ns }; 157 CHECK(publish(e, e->ext_goal, e->a.o.goal, f, v, 3) == 0, "goal refused"); 158 } 159 160 static int mint_aien(Env *e) { 161 const uint32_t RW = RX_RIGHT_READ | RX_RIGHT_WRITE; 162 for (uint32_t i = 0; i < RX_AIEN_RES_COUNT; i++) 163 e->acaps.own[i] = mint(e, RX_AIEN_SUBJ, RX_AIEN_RES_BASE + i, 164 i == RX_AIEN_RES_PLACEMENT || i == RX_AIEN_RES_GOAL ? RX_RIGHT_READ : RW); 165 /* AIEN observes demand and selection. It cannot write them. */ 166 e->acaps.demand = mint(e, RX_AIEN_SUBJ, e->w.objects[e->a.in.demand.id].resource, RX_RIGHT_READ); 167 e->acaps.selection = mint(e, RX_AIEN_SUBJ, e->w.objects[e->a.in.selection.id].resource, 168 RX_RIGHT_READ); 169 e->ext_placement = mint(e, SUBJ_EXTERNAL, RX_AIEN_RES_BASE + RX_AIEN_RES_PLACEMENT, RX_RIGHT_WRITE); 170 e->ext_goal = mint(e, SUBJ_EXTERNAL, RX_AIEN_RES_BASE + RX_AIEN_RES_GOAL, RX_RIGHT_WRITE); 171 return rx_aien_register(&e->a, &e->acaps); 172 } 173 174 static int world_start(Env *e) { 175 if (aienos_cap_start(&e->admin, &e->view) != 0) return -1; 176 if (rx_world_init_native(&e->w, e->view, 4, 1u << 20) != RX_OK) { 177 aienos_cap_stop(e->admin, e->view); 178 return -1; 179 } 180 e->w.external_subject = SUBJ_EXTERNAL; 181 return 0; 182 } 183 184 static void env_stop(Env *e) { 185 rx_world_wait_quiescent(&e->w, 20000); 186 rx_world_destroy(&e->w); 187 if (e->with_omega) rx_omega_destroy(&e->f); 188 aienos_cap_stop(e->admin, e->view); 189 } 190 191 /* ---- Part A: AIEN against a scripted world ---- */ 192 193 #define RES_DEMAND 0x7711000ull 194 #define RES_SELECTION 0x7711001ull 195 196 static int envA_start(Env *e) { 197 memset(e, 0, sizeof(*e)); 198 if (world_start(e) != 0) return -1; 199 uint64_t z[RX_MAX_FIELDS] = { 0 }; 200 if (rx_world_create(&e->w, RX_OT_DEMAND, RX_PERSIST_RESIDENT, RES_DEMAND, z, &e->demand) != RX_OK || 201 rx_world_create(&e->w, RX_OT_SELECTION, RX_PERSIST_RESIDENT, RES_SELECTION, z, 202 &e->selection) != RX_OK) 203 return -1; 204 e->ext_demand = mint(e, SUBJ_EXTERNAL, RES_DEMAND, RX_RIGHT_WRITE); 205 e->ext_selection = mint(e, SUBJ_EXTERNAL, RES_SELECTION, RX_RIGHT_WRITE); 206 RxAienConfig cfg; 207 rx_aien_default_config(&cfg); 208 RxAienInputs in = { e->demand, e->selection }; 209 if (rx_aien_create_objects(&e->a, &e->w, &cfg, &in) != RX_OK) return -1; 210 e->with_aien = 1; 211 return mint_aien(e) == RX_OK ? 0 : -1; 212 } 213 214 /* Omega recorded a realization for the regime. */ 215 static void record(Env *e, uint64_t epoch, uint64_t real) { 216 uint32_t f[3] = { 0, 1, 6 }; 217 uint64_t v[3] = { epoch, real, rx_aien_regime(REG_M, REG_N) }; 218 CHECK(publish(e, e->ext_selection, e->selection, f, v, 3) == 0, "selection refused"); 219 CHECK(settle(e) == RX_OK, "world did not settle"); 220 } 221 222 /* One demand window of 16 production calls at `ns` each, served by `real`. */ 223 static void window(Env *e, uint64_t ns, uint64_t real) { 224 e->calls += 16; 225 e->spent += 16 * ns; 226 e->windows++; 227 uint32_t f[6] = { 0, 1, 2, 4, 5, 6 }; 228 uint64_t v[6] = { e->calls, e->spent, e->windows, REG_M, REG_N, real }; 229 CHECK(publish(e, e->ext_demand, e->demand, f, v, 6) == 0, "demand refused"); 230 CHECK(settle(e) == RX_OK, "world did not settle"); 231 } 232 233 static void windows(Env *e, uint32_t n, uint64_t ns, uint64_t real) { 234 for (uint32_t i = 0; i < n; i++) window(e, ns, real); 235 } 236 237 static uint64_t commits_of(Env *e, uint32_t rid) { return e->w.reactions[rid].commits; } 238 239 /* Does the causal past of `from` contain a crumb with this id? */ 240 static int caused_by(Env *e, uint64_t from, uint64_t ancestor) { 241 uint64_t n = e->w.n_crumbs; 242 uint8_t *seen = calloc(n + 1, 1); 243 uint64_t *stack = malloc((n + 1) * sizeof(uint64_t)); 244 uint64_t sp = 0; 245 int found = 0; 246 stack[sp++] = from; 247 while (sp && !found) { 248 uint64_t id = stack[--sp]; 249 if (id == 0 || id > n || seen[id]) continue; 250 seen[id] = 1; 251 if (id == ancestor) found = 1; 252 const RxCrumb *c = rx_world_crumb(&e->w, id); 253 if (!c) continue; 254 for (uint32_t i = 0; i < c->n_parents && sp < n; i++) stack[sp++] = c->parents[i]; 255 if (c->wake_cause && sp < n) stack[sp++] = c->wake_cause; 256 } 257 free(seen); 258 free(stack); 259 return found; 260 } 261 262 /* Every AIEN activation was woken by a world change, never by a caller. */ 263 static void check_only_reactive(Env *e) { 264 uint64_t aien = 0, uncaused = 0; 265 for (uint64_t id = 1; id <= e->w.n_crumbs; id++) { 266 const RxCrumb *c = rx_world_crumb(&e->w, id); 267 if (!c || c->reaction == UINT32_MAX || c->faculty != RX_FACULTY_AIEN) continue; 268 aien++; 269 if (c->wake_cause == 0) uncaused++; 270 } 271 CHECK(aien > 0 && uncaused == 0, "AIEN crumbs %llu, without a waking cause %llu", 272 (unsigned long long)aien, (unsigned long long)uncaused); 273 } 274 275 static void t_no_record(void) { 276 printf("[*] no record yet: AIEN watches and publishes nothing\n"); 277 Env e; 278 CHECK(envA_start(&e) == 0, "setup"); 279 place(&e, P1); 280 windows(&e, 10, 5000, 0); 281 CHECK(fld(&e, e.a.o.belief, 0) == 0, "belief formed without a record"); 282 CHECK(fld(&e, e.a.o.prediction, 0) == 0 && fld(&e, e.a.o.plan, 0) == 0, "acted without a record"); 283 CHECK(e.w.reactions[e.a.r_observe].activations == 10, "observe woke %llu times for 10 windows", 284 (unsigned long long)e.w.reactions[e.a.r_observe].activations); 285 CHECK(e.w.reactions[e.a.r_predict].activations == 0, "predict woke with nothing to predict"); 286 env_stop(&e); 287 } 288 289 /* Warm-up, baseline, then enough hits to confirm. */ 290 static void confirm_at(Env *e, uint64_t ns, uint64_t real) { 291 windows(e, 1 + e->a.cfg.baseline_intervals + e->a.cfg.confirm_intervals, ns, real); 292 } 293 294 static void t_steady_and_outlier(void) { 295 printf("[*] a steady record is predicted and confirmed; one outlier is not a failure\n"); 296 Env e; 297 CHECK(envA_start(&e) == 0, "setup"); 298 place(&e, P1); 299 window(&e, 5000, 0); /* production runs before any record exists */ 300 record(&e, 1, 0xAA); 301 windows(&e, 1 + e.a.cfg.baseline_intervals - 1, 5000, 0xAA); 302 CHECK(fld(&e, e.a.o.prediction, 0) == 0, "predicted before the baseline was complete"); 303 window(&e, 5000, 0xAA); 304 CHECK(fld(&e, e.a.o.prediction, 0) == 1 && fld(&e, e.a.o.prediction, 6) == RX_AIEN_PRED_HOLDING, 305 "prediction after baseline: seq %llu state %llu", 306 (unsigned long long)fld(&e, e.a.o.prediction, 0), (unsigned long long)fld(&e, e.a.o.prediction, 6)); 307 CHECK(fld(&e, e.a.o.prediction, 5) == 5000 && fld(&e, e.a.o.prediction, 4) == P1 && 308 fld(&e, e.a.o.prediction, 2) == rx_aien_regime(REG_M, REG_N), "prediction contents"); 309 windows(&e, e.a.cfg.confirm_intervals, 5100, 0xAA); 310 CHECK(fld(&e, e.a.o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "not confirmed after %u hits", 311 e.a.cfg.confirm_intervals); 312 313 /* One interval far off, then back to normal. */ 314 window(&e, 9000, 0xAA); 315 CHECK(fld(&e, e.a.o.belief, 7) == 1, "outlier not counted as a miss"); 316 CHECK(fld(&e, e.a.o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "one outlier failed the prediction"); 317 CHECK(fld(&e, e.a.o.prediction, 3) == 0, "hit streak survived a miss"); 318 windows(&e, 3, 5000, 0xAA); 319 CHECK(fld(&e, e.a.o.belief, 7) == 0 && fld(&e, e.a.o.prediction, 3) == 3, "recovery after outlier"); 320 CHECK(fld(&e, e.a.o.hypothesis, 0) == 0 && fld(&e, e.a.o.plan, 0) == 0, 321 "AIEN acted on a confirmed prediction"); 322 323 /* Intervals served before production switched to the record are not evidence. */ 324 uint64_t seen = fld(&e, e.a.o.belief, 5); 325 record(&e, 2, 0xBB); 326 windows(&e, 3, 99999, 0xAA); 327 CHECK(fld(&e, e.a.o.belief, 0) == 2 && fld(&e, e.a.o.belief, 5) == 0, 328 "intervals on the old realization counted for the new record (seen %llu, was %llu)", 329 (unsigned long long)fld(&e, e.a.o.belief, 5), (unsigned long long)seen); 330 check_only_reactive(&e); 331 env_stop(&e); 332 } 333 334 static void t_core_class(void) { 335 printf("[*] a failed prediction after a core-class change becomes a hypothesis and a plan\n"); 336 Env e; 337 CHECK(envA_start(&e) == 0, "setup"); 338 RxAienFaculty *a = &e.a; 339 uint64_t R = rx_aien_regime(REG_M, REG_N); 340 place(&e, P1); 341 window(&e, 5000, 0); /* production runs before any record exists */ 342 record(&e, 1, 0xAA); 343 confirm_at(&e, 5000, 0xAA); 344 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "setup prediction"); 345 346 /* The environment moves the work. AIEN notes nothing yet: moving is not evidence. */ 347 place(&e, P2); 348 CHECK(settle(&e) == RX_OK, "settle"); 349 uint64_t place_crumb = rx_world_explain(&e.w, a->o.placement, 1); 350 CHECK(fld(&e, a->o.hypothesis, 0) == 0, "a placement alone produced a hypothesis"); 351 window(&e, 2000, 0xAA); 352 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "one miss failed the prediction"); 353 window(&e, 2100, 0xAA); 354 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED && fld(&e, a->o.prediction, 7) == 2100, 355 "prediction state %llu observed %llu", (unsigned long long)fld(&e, a->o.prediction, 6), 356 (unsigned long long)fld(&e, a->o.prediction, 7)); 357 CHECK(fld(&e, a->o.hypothesis, 0) == 1 && fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_CORE_CLASS, 358 "hypothesis kind %llu", (unsigned long long)fld(&e, a->o.hypothesis, 1)); 359 CHECK(fld(&e, a->o.hypothesis, 3) == P1 && fld(&e, a->o.hypothesis, 4) == P2 && 360 fld(&e, a->o.hypothesis, 5) == 5000 && fld(&e, a->o.hypothesis, 6) == 2100, 361 "hypothesis contents"); 362 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, "hypothesis state %llu", 363 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 364 CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 1) == RX_AIEN_ACT_RESEARCH && 365 fld(&e, a->o.plan, 2) == R && fld(&e, a->o.plan, 3) == P2 && fld(&e, a->o.plan, 4) == 1 && 366 fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, "plan contents"); 367 CHECK(fld(&e, a->o.memory, 0) == 1 && fld(&e, a->o.memory, 1) == rx_aien_key(P2, R), "memory"); 368 369 /* The plan's causal past holds both the evidence and the observation that explains it. */ 370 uint64_t plan_crumb = rx_world_explain(&e.w, a->o.plan, 0); 371 uint64_t demand_crumb = rx_world_explain(&e.w, e.demand, 1); 372 CHECK(caused_by(&e, plan_crumb, place_crumb), "plan does not trace to the placement"); 373 CHECK(caused_by(&e, plan_crumb, demand_crumb), "plan does not trace to the failing evidence"); 374 375 /* More failing windows do not repeat the plan. */ 376 windows(&e, 4, 2000, 0xAA); 377 CHECK(fld(&e, a->o.plan, 0) == 1 && commits_of(&e, a->r_plan) >= 1, "plan repeated"); 378 379 /* Some faculty answers with a new record measured where the work runs now. */ 380 record(&e, 2, 0xBB); 381 confirm_at(&e, 2000, 0xBB); 382 CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && 383 fld(&e, a->o.prediction, 4) == P2, "prediction under the new condition"); 384 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_SUPPORTED, "hypothesis state %llu", 385 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 386 387 /* Back to P1: that condition was never explored by AIEN, so one plan for it. */ 388 place(&e, P1); 389 windows(&e, 2, 5000, 0xBB); 390 CHECK(fld(&e, a->o.hypothesis, 0) == 2 && fld(&e, a->o.hypothesis, 4) == P1 && 391 fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, "second hypothesis"); 392 CHECK(fld(&e, a->o.plan, 0) == 2 && fld(&e, a->o.plan, 3) == P1, "second plan"); 393 record(&e, 3, 0xAA); 394 confirm_at(&e, 5000, 0xAA); 395 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_SUPPORTED, "second hypothesis not supported"); 396 397 /* P2 again: explored already. AIEN says so and plans nothing. */ 398 place(&e, P2); 399 windows(&e, 2, 2000, 0xAA); 400 CHECK(fld(&e, a->o.hypothesis, 0) == 3 && fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_EXHAUSTED, 401 "third hypothesis seq %llu state %llu", (unsigned long long)fld(&e, a->o.hypothesis, 0), 402 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 403 CHECK(fld(&e, a->o.plan, 0) == 2, "planned an explored condition"); 404 check_only_reactive(&e); 405 env_stop(&e); 406 } 407 408 static void t_drift(void) { 409 printf("[*] a failure with nothing else changed is drift: relearned first, researched only " 410 "if the cost moved; a second failure refutes it\n"); 411 Env e; 412 CHECK(envA_start(&e) == 0, "setup"); 413 RxAienFaculty *a = &e.a; 414 place(&e, P1); 415 window(&e, 5000, 0); /* production runs before any record exists */ 416 record(&e, 1, 0xAA); 417 confirm_at(&e, 5000, 0xAA); 418 windows(&e, 2, 9000, 0xAA); 419 CHECK(fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_DRIFT && fld(&e, a->o.hypothesis, 3) == P1 && 420 fld(&e, a->o.hypothesis, 4) == P1, "drift hypothesis"); 421 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_OPEN && fld(&e, a->o.plan, 0) == 0, 422 "drift researched before the record was relearned"); 423 /* The same record, learned again where it runs: the cost really moved. */ 424 windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 9000, 0xAA); 425 CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && 426 fld(&e, a->o.prediction, 5) == 9000, "relearned prediction"); 427 CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_DRIFT && 428 fld(&e, a->o.plan, 4) == fld(&e, a->o.hypothesis, 0), "drift plan"); 429 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, "hypothesis state %llu", 430 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 431 record(&e, 2, 0xBB); 432 windows(&e, 1 + a->cfg.baseline_intervals, 9000, 0xBB); 433 windows(&e, 2, 15000, 0xBB); 434 CHECK(fld(&e, a->o.prediction, 0) == 3 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED, 435 "second prediction"); 436 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_UNSUPPORTED, "hypothesis state %llu", 437 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 438 CHECK(fld(&e, a->o.plan, 0) == 1, "planned again"); 439 env_stop(&e); 440 } 441 442 /* Seen in R13 under whole-machine load (omega #527): a burst failed the 443 * prediction with nothing changed, then the cost came back. The drift plan 444 * went out at once and its research could not run before the goal, so the 445 * failed prediction was never relearned and the incumbent cost never 446 * confirmed. Drift is now tested by relearning first: a cost back where it 447 * was refutes it, with no research. A real change later is still noticed. */ 448 static void t_drift_burst_refuted(void) { 449 printf("[*] a burst that passes is refuted by relearning: no research, a later move is noticed\n"); 450 Env e; 451 CHECK(envA_start(&e) == 0, "setup"); 452 RxAienFaculty *a = &e.a; 453 place(&e, P1); 454 window(&e, 5000, 0); /* production runs before any record exists */ 455 record(&e, 1, 0xAA); 456 confirm_at(&e, 5000, 0xAA); 457 windows(&e, 2, 9000, 0xAA); /* the burst */ 458 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED && 459 fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_DRIFT, "the burst was not noticed"); 460 windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 5100, 0xAA); 461 CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && 462 fld(&e, a->o.prediction, 5) == 5100, "not relearned: seq %llu state %llu cost %llu", 463 (unsigned long long)fld(&e, a->o.prediction, 0), (unsigned long long)fld(&e, a->o.prediction, 6), 464 (unsigned long long)fld(&e, a->o.prediction, 5)); 465 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_UNSUPPORTED, "hypothesis state %llu", 466 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 467 CHECK(fld(&e, a->o.plan, 0) == 0 && fld(&e, a->o.memory, 0) == 0, "researched a burst"); 468 place(&e, P2); 469 windows(&e, 2, 2000, 0xAA); 470 CHECK(fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_CORE_CLASS && 471 fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING && 472 fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, 473 "the move was not planned"); 474 check_only_reactive(&e); 475 env_stop(&e); 476 } 477 478 /* R13 under load: baseline intervals 16361, 26203, 8370, 7708 ns averaged to 479 * 14660 ns, a cost no interval paid. A baseline interval that disagrees with 480 * the ones before it by more than the tolerance starts the baseline again. */ 481 /* Seen in R14 under whole-machine load (OMEGA-R14-HOST, 2026-10-20): a burst 482 * failed the incumbent's prediction on the A725 cores (drift, open, to be 483 * relearned), then the body moved to the X925 cores before the relearn. The 484 * relearned prediction was about the new class, so the drift question was 485 * moot; left open it waited forever for a same-class prediction, and the body 486 * never researched the class it ran on, even with a goal it already met. */ 487 static void t_drift_moved(void) { 488 printf("[*] a drift hypothesis whose relearn lands on another core class becomes a core-class " 489 "hypothesis and a plan for that class\n"); 490 Env e; 491 CHECK(envA_start(&e) == 0, "setup"); 492 RxAienFaculty *a = &e.a; 493 uint64_t R = rx_aien_regime(REG_M, REG_N); 494 place(&e, P1); 495 window(&e, 5000, 0); /* production runs before any record exists */ 496 record(&e, 1, 0xAA); 497 confirm_at(&e, 5000, 0xAA); 498 windows(&e, 2, 9000, 0xAA); /* a burst: drift, open, relearn pending */ 499 CHECK(fld(&e, a->o.hypothesis, 0) == 1 && fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_DRIFT && 500 fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_OPEN, "drift hypothesis"); 501 /* The body moves before the record is relearned. */ 502 place(&e, P2); 503 CHECK(settle(&e) == RX_OK, "settle"); 504 windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 4000, 0xAA); 505 CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 4) == P2 && 506 fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && fld(&e, a->o.prediction, 5) == 4000, 507 "relearned on the new class: prediction %llu class %llx state %llu cost %llu", 508 (unsigned long long)fld(&e, a->o.prediction, 0), (unsigned long long)fld(&e, a->o.prediction, 4), 509 (unsigned long long)fld(&e, a->o.prediction, 6), (unsigned long long)fld(&e, a->o.prediction, 5)); 510 CHECK(fld(&e, a->o.hypothesis, 0) == 2 && fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_CORE_CLASS && 511 fld(&e, a->o.hypothesis, 2) == 2 && fld(&e, a->o.hypothesis, 3) == P1 && 512 fld(&e, a->o.hypothesis, 4) == P2, 513 "core-class hypothesis: seq %llu kind %llu prediction %llu then %llx now %llx", 514 (unsigned long long)fld(&e, a->o.hypothesis, 0), (unsigned long long)fld(&e, a->o.hypothesis, 1), 515 (unsigned long long)fld(&e, a->o.hypothesis, 2), (unsigned long long)fld(&e, a->o.hypothesis, 3), 516 (unsigned long long)fld(&e, a->o.hypothesis, 4)); 517 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, "hypothesis state %llu", 518 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 519 CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 1) == RX_AIEN_ACT_RESEARCH && 520 fld(&e, a->o.plan, 2) == R && fld(&e, a->o.plan, 3) == P2 && fld(&e, a->o.plan, 4) == 2 && 521 fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, 522 "plan for the class the body runs on: seq %llu class %llx why %llu", 523 (unsigned long long)fld(&e, a->o.plan, 0), (unsigned long long)fld(&e, a->o.plan, 3), 524 (unsigned long long)fld(&e, a->o.plan, 5)); 525 CHECK(fld(&e, a->o.memory, 0) == 1 && fld(&e, a->o.memory, 1) == rx_aien_key(P2, R), "memory"); 526 env_stop(&e); 527 } 528 529 static void t_baseline_must_agree(void) { 530 printf("[*] a burst inside the baseline restarts it; the prediction is what production pays\n"); 531 Env e; 532 CHECK(envA_start(&e) == 0, "setup"); 533 RxAienFaculty *a = &e.a; 534 place(&e, P1); 535 window(&e, 5000, 0); /* production runs before any record exists */ 536 record(&e, 1, 0xAA); 537 window(&e, 5000, 0xAA); /* warm-up */ 538 window(&e, 5000, 0xAA); 539 window(&e, 12000, 0xAA); /* the burst */ 540 windows(&e, a->cfg.baseline_intervals - 1, 5000, 0xAA); 541 CHECK(fld(&e, a->o.prediction, 0) == 0, "predicted from a baseline that disagrees with itself"); 542 window(&e, 5000, 0xAA); 543 CHECK(fld(&e, a->o.prediction, 0) == 1 && fld(&e, a->o.prediction, 5) == 5000, 544 "prediction %llu expects %llu ns", (unsigned long long)fld(&e, a->o.prediction, 0), 545 (unsigned long long)fld(&e, a->o.prediction, 5)); 546 windows(&e, a->cfg.confirm_intervals, 5000, 0xAA); 547 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "not confirmed"); 548 /* A steady, slower cost is learned at what it is. */ 549 record(&e, 2, 0xBB); 550 confirm_at(&e, 9000, 0xBB); 551 CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 5) == 9000 && 552 fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "a steady slower cost was not learned"); 553 env_stop(&e); 554 } 555 556 /* Seen on GB10 in R15 (2026-09-28): production jitter on A725 failed the 557 * prediction twice with nothing changed; the drift research found nothing and 558 * the failure was settled. The prediction then stayed FAILED, so the later 559 * move to X925 was never noticed and no plan followed. A settled failure must 560 * give way to a fresh prediction learned from fresh intervals. */ 561 static void t_settled_failure_relearns(void) { 562 printf("[*] a settled failure is relearned, so a later core move is still noticed\n"); 563 Env e; 564 CHECK(envA_start(&e) == 0, "setup"); 565 RxAienFaculty *a = &e.a; 566 uint64_t R = rx_aien_regime(REG_M, REG_N); 567 place(&e, P1); 568 window(&e, 5000, 0); /* production runs before any record exists */ 569 record(&e, 1, 0xAA); 570 confirm_at(&e, 5000, 0xAA); 571 windows(&e, 2, 9000, 0xAA); /* jitter: drift hypothesis */ 572 windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 9000, 0xAA); 573 /* relearned: the cost stays moved, so a drift plan */ 574 CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_DRIFT, "drift plan"); 575 record(&e, 2, 0xAA); /* the research kept the same realization */ 576 windows(&e, 1 + a->cfg.baseline_intervals, 9000, 0xAA); 577 windows(&e, 2, 15000, 0xAA); /* fails again: the drift hypothesis is refuted */ 578 CHECK(settle(&e) == RX_OK, "settle"); 579 uint64_t failed_seq = fld(&e, a->o.prediction, 0); 580 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED, "second failure"); 581 CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_UNSUPPORTED || 582 fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_EXHAUSTED, "failure not settled: hypothesis state %llu", 583 (unsigned long long)fld(&e, a->o.hypothesis, 7)); 584 585 /* Nothing is left to try here: AIEN relearns the record where it runs. */ 586 windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 15000, 0xAA); 587 CHECK(fld(&e, a->o.prediction, 0) == failed_seq + 1 && 588 fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && 589 fld(&e, a->o.prediction, 5) == 15000 && fld(&e, a->o.prediction, 4) == P1, 590 "no fresh prediction after a settled failure: seq %llu (failed %llu) state %llu cost %llu", 591 (unsigned long long)fld(&e, a->o.prediction, 0), (unsigned long long)failed_seq, 592 (unsigned long long)fld(&e, a->o.prediction, 6), (unsigned long long)fld(&e, a->o.prediction, 5)); 593 CHECK(fld(&e, a->o.plan, 0) == 1, "relearning planned"); 594 595 /* The real change: the work moves. It is noticed, explained, planned. */ 596 uint64_t hyps = fld(&e, a->o.hypothesis, 0); 597 place(&e, P2); 598 windows(&e, 2, 4000, 0xAA); 599 CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED, "the move was not noticed"); 600 CHECK(fld(&e, a->o.hypothesis, 0) == hyps + 1 && 601 fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_CORE_CLASS && 602 fld(&e, a->o.hypothesis, 3) == P1 && fld(&e, a->o.hypothesis, 4) == P2 && 603 fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, 604 "core-class hypothesis: seq %llu kind %llu state %llu", (unsigned long long)fld(&e, a->o.hypothesis, 0), 605 (unsigned long long)fld(&e, a->o.hypothesis, 1), (unsigned long long)fld(&e, a->o.hypothesis, 7)); 606 CHECK(fld(&e, a->o.plan, 0) == 2 && fld(&e, a->o.plan, 2) == R && fld(&e, a->o.plan, 3) == P2 && 607 fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, "no plan for the move"); 608 check_only_reactive(&e); 609 env_stop(&e); 610 } 611 612 static void t_goal(void) { 613 printf("[*] a human goal: unknown, met, unmet -> one plan, then unmet and explored\n"); 614 Env e; 615 CHECK(envA_start(&e) == 0, "setup"); 616 RxAienFaculty *a = &e.a; 617 uint64_t R = rx_aien_regime(REG_M, REG_N); 618 place(&e, P1); 619 set_goal(&e, R, 6000); 620 CHECK(settle(&e) == RX_OK, "settle"); 621 CHECK(fld(&e, a->o.assessment, 4) == RX_AIEN_GOAL_UNKNOWN, "goal without evidence: %llu", 622 (unsigned long long)fld(&e, a->o.assessment, 4)); 623 window(&e, 5000, 0); /* production runs before any record exists */ 624 record(&e, 1, 0xAA); 625 confirm_at(&e, 5000, 0xAA); 626 CHECK(fld(&e, a->o.assessment, 4) == RX_AIEN_GOAL_MET && fld(&e, a->o.assessment, 3) == 5000, 627 "goal met: status %llu", (unsigned long long)fld(&e, a->o.assessment, 4)); 628 CHECK(fld(&e, a->o.plan, 0) == 0, "planned for a met goal"); 629 630 set_goal(&e, R, 3000); 631 CHECK(settle(&e) == RX_OK, "settle"); 632 CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_GOAL && 633 fld(&e, a->o.plan, 6) == 2 && fld(&e, a->o.plan, 3) == P1, "goal plan"); 634 record(&e, 2, 0xBB); 635 confirm_at(&e, 4000, 0xBB); 636 CHECK(fld(&e, a->o.assessment, 4) == RX_AIEN_GOAL_UNMET_EXPLORED && fld(&e, a->o.assessment, 3) == 4000, 637 "after the experiment: status %llu", (unsigned long long)fld(&e, a->o.assessment, 4)); 638 set_goal(&e, R, 2500); 639 CHECK(settle(&e) == RX_OK, "settle"); 640 CHECK(fld(&e, a->o.plan, 0) == 1, "planned an explored condition for a new goal"); 641 set_goal(&e, R, 4500); 642 CHECK(settle(&e) == RX_OK, "settle"); 643 CHECK(fld(&e, a->o.assessment, 4) == RX_AIEN_GOAL_MET, "relaxed goal not met"); 644 env_stop(&e); 645 } 646 647 static int fn_forge_selection(RxCtx *c) { 648 Env *e = c->user; 649 c->out[c->n_out++] = (RxMutation){ e->selection, 1, 0xDEAD }; 650 return 0; 651 } 652 653 static void t_authority(void) { 654 printf("[*] AIEN cannot write what it observes; revoked, AIEN stops and the world does not\n"); 655 Env e; 656 CHECK(envA_start(&e) == 0, "setup"); 657 /* An AIEN reaction that tries to publish into Omega's record with AIEN's read-only reference. */ 658 RxReactionDesc d; 659 memset(&d, 0, sizeof d); 660 d.name = "aien.forge"; 661 d.faculty = RX_FACULTY_AIEN; 662 d.subject = RX_AIEN_SUBJ; 663 d.priority = RX_PRIO_LEARNING; 664 d.fn = fn_forge_selection; 665 d.user = &e; 666 d.n_triggers = 1; 667 d.triggers[0] = (RxDep){ e.demand, RX_FIELD(2) }; 668 d.n_writes = 1; 669 d.writes[0] = (RxDep){ e.selection, RX_ALL_FIELDS }; 670 d.n_caps = 2; 671 d.caps[0] = (RxCapNeed){ e.acaps.demand, RES_DEMAND, RX_RIGHT_READ }; 672 d.caps[1] = (RxCapNeed){ e.acaps.selection, RES_SELECTION, RX_RIGHT_READ | RX_RIGHT_WRITE }; 673 uint32_t rid = UINT32_MAX; 674 CHECK(rx_world_add_reaction(&e.w, &d, &rid) == RX_OK, "register"); 675 place(&e, P1); 676 window(&e, 5000, 0); /* production runs before any record exists */ 677 record(&e, 1, 0xAA); 678 windows(&e, 3, 5000, 0xAA); 679 CHECK(fld(&e, e.selection, 1) == 0xAA, "AIEN wrote Omega's selection"); 680 CHECK(e.w.reactions[rid].commits == 0, "forging reaction committed"); 681 CHECK(e.w.stats.blocked_authority > 0, "no authority block recorded"); 682 683 /* Revoke AIEN's belief reference. Observation stops; demand keeps flowing. */ 684 uint64_t seen = fld(&e, e.a.o.belief, 5); 685 CHECK(revoke_cap(&e, e.acaps.own[RX_AIEN_RES_BELIEF]) == 0, "revoke"); 686 uint64_t before = e.windows; 687 windows(&e, 4, 5000, 0xAA); 688 CHECK(e.windows == before + 4 && fld(&e, e.demand, 2) == e.windows, "world stopped with AIEN"); 689 CHECK(fld(&e, e.a.o.belief, 5) == seen, "belief advanced without authority"); 690 CHECK(e.w.reactions[e.a.r_observe].state == RX_BLOCKED_AUTHORITY || 691 e.w.reactions[e.a.r_observe].state == RX_DORMANT, "observe state %s", 692 rx_state_name(e.w.reactions[e.a.r_observe].state)); 693 env_stop(&e); 694 } 695 696 /* ---- Part B: the living run on the DGX Spark ---- */ 697 698 static cpu_set_t g_x925, g_a725; 699 static int g_nx, g_na; 700 static char g_x_cpus[128], g_a_cpus[128]; 701 702 static void find_core_classes(void) { 703 CPU_ZERO(&g_x925); 704 CPU_ZERO(&g_a725); 705 long n = sysconf(_SC_NPROCESSORS_CONF); 706 size_t ux = 0, ua = 0; 707 for (long c = 0; c < n && c < CPU_SETSIZE; c++) { 708 char path[128]; 709 snprintf(path, sizeof path, "/sys/devices/system/cpu/cpu%ld/regs/identification/midr_el1", c); 710 FILE *fp = fopen(path, "r"); 711 if (!fp) continue; 712 unsigned long long midr = 0; 713 int ok = fscanf(fp, "%llx", &midr) == 1; 714 fclose(fp); 715 unsigned part = (unsigned)((midr >> 4) & 0xfffu); 716 if (!ok) continue; 717 if (part == CLASS_X925 && ux < sizeof g_x_cpus - 8) { 718 CPU_SET((int)c, &g_x925); 719 g_nx++; 720 ux += (size_t)snprintf(g_x_cpus + ux, sizeof g_x_cpus - ux, "%s%ld", ux ? "," : "", c); 721 } else if (part == CLASS_A725 && ua < sizeof g_a_cpus - 8) { 722 CPU_SET((int)c, &g_a725); 723 g_na++; 724 ua += (size_t)snprintf(g_a_cpus + ua, sizeof g_a_cpus - ua, "%s%ld", ua ? "," : "", c); 725 } 726 } 727 } 728 729 /* Move every thread of this process, the world's workers included. */ 730 static int move_all_threads(const cpu_set_t *set) { 731 DIR *d = opendir("/proc/self/task"); 732 if (!d) return -1; 733 struct dirent *de; 734 int moved = 0, bad = 0; 735 while ((de = readdir(d)) != NULL) { 736 if (de->d_name[0] == '.') continue; 737 pid_t tid = (pid_t)atoi(de->d_name); 738 if (sched_setaffinity(tid, sizeof *set, set) == 0) moved++; 739 else bad++; 740 } 741 closedir(d); 742 return bad ? -1 : moved; 743 } 744 745 static int envB_start(Env *e, int with_aien) { 746 memset(e, 0, sizeof(*e)); 747 if (world_start(e) != 0) return -1; 748 RxOmegaConfig oc; 749 rx_omega_default_config(&oc); 750 oc.hot_calls = 64; 751 oc.hot_ns = 200000; 752 /* A realization must be clearly better to replace the reference. */ 753 oc.margin_pct = 10; 754 if (rx_omega_create_objects(&e->f, &e->w, &oc) != RX_OK) return -1; 755 e->with_omega = 1; 756 const uint32_t RW = RX_RIGHT_READ | RX_RIGHT_WRITE; 757 for (uint32_t i = 0; i < RX_OMEGA_RES_COUNT; i++) { 758 e->ocaps.serve[i] = (RxCapRef){ UINT32_MAX, 0 }; 759 e->ocaps.omega[i] = (RxCapRef){ UINT32_MAX, 0 }; 760 } 761 uint64_t B = RX_OMEGA_RES_BASE; 762 e->ocaps.serve[RX_OMEGA_RES_REQUEST] = mint(e, RX_OMEGA_SUBJ_SERVE, B + RX_OMEGA_RES_REQUEST, RX_RIGHT_READ); 763 e->ocaps.serve[RX_OMEGA_RES_SELECTION] = mint(e, RX_OMEGA_SUBJ_SERVE, B + RX_OMEGA_RES_SELECTION, RX_RIGHT_READ); 764 e->ocaps.serve[RX_OMEGA_RES_DEMAND] = mint(e, RX_OMEGA_SUBJ_SERVE, B + RX_OMEGA_RES_DEMAND, RW); 765 e->ocaps.serve[RX_OMEGA_RES_RESULT] = mint(e, RX_OMEGA_SUBJ_SERVE, B + RX_OMEGA_RES_RESULT, RW); 766 e->ocaps.omega[RX_OMEGA_RES_DEMAND] = mint(e, RX_OMEGA_SUBJ_OMEGA, B + RX_OMEGA_RES_DEMAND, RX_RIGHT_READ); 767 e->ocaps.omega[RX_OMEGA_RES_SEARCH] = mint(e, RX_OMEGA_SUBJ_OMEGA, B + RX_OMEGA_RES_SEARCH, RW); 768 e->ocaps.omega[RX_OMEGA_RES_SELECTION] = mint(e, RX_OMEGA_SUBJ_OMEGA, B + RX_OMEGA_RES_SELECTION, RW); 769 for (uint32_t k = 0; k < e->f.cfg.n_slots; k++) { 770 uint32_t c = RX_OMEGA_RES_CANDIDATE0 + k, v = RX_OMEGA_RES_VERDICT0 + k, 771 m = RX_OMEGA_RES_MEASURE0 + k; 772 e->ocaps.omega[c] = mint(e, RX_OMEGA_SUBJ_OMEGA, B + c, RW); 773 e->ocaps.omega[v] = mint(e, RX_OMEGA_SUBJ_OMEGA, B + v, RW); 774 e->ocaps.omega[m] = mint(e, RX_OMEGA_SUBJ_OMEGA, B + m, RW); 775 } 776 e->ext_request = mint(e, SUBJ_EXTERNAL, B + RX_OMEGA_RES_REQUEST, RX_RIGHT_WRITE); 777 if (rx_omega_register(&e->f, &e->ocaps) != RX_OK) return -1; 778 779 RxAienConfig ac; 780 rx_aien_default_config(&ac); 781 RxAienInputs in = { e->f.o.demand, e->f.o.selection }; 782 if (rx_aien_create_objects(&e->a, &e->w, &ac, &in) != RX_OK) return -1; 783 e->ext_placement = mint(e, SUBJ_EXTERNAL, RX_AIEN_RES_BASE + RX_AIEN_RES_PLACEMENT, RX_RIGHT_WRITE); 784 e->ext_goal = mint(e, SUBJ_EXTERNAL, RX_AIEN_RES_BASE + RX_AIEN_RES_GOAL, RX_RIGHT_WRITE); 785 if (!with_aien) return 0; 786 e->with_aien = 1; 787 if (mint_aien(e) != RX_OK) return -1; 788 /* Omega may read AIEN's plan. It gets no other right on AIEN's objects. */ 789 RxCapRef plan_read = mint(e, RX_OMEGA_SUBJ_OMEGA, RX_AIEN_RES_BASE + RX_AIEN_RES_PLAN, RX_RIGHT_READ); 790 return rx_omega_register_reconsider(&e->f, e->a.o.plan, plan_read, 791 e->ocaps.omega[RX_OMEGA_RES_SEARCH], 792 e->ocaps.omega[RX_OMEGA_RES_SELECTION]) == RX_OK ? 0 : -1; 793 } 794 795 796 /* The quiet flag belongs to this run when quietlock started it under that 797 * hold: the flag line carries hold= and QUIETLOCK_HOLD= is set in this 798 * process (tools/quietlock). Any other flag is someone else's measurement. */ 799 static int quiet_flag_is_mine(const char *flag) { 800 const char *mine = getenv("QUIETLOCK_HOLD"); 801 if (!mine || !mine[0]) return 0; 802 FILE *f = fopen(flag, "r"); 803 if (!f) return 0; 804 char line[1024] = { 0 }, tok[300]; 805 int ok = fgets(line, sizeof line, f) != NULL; 806 fclose(f); 807 if (!ok) return 0; 808 snprintf(tok, sizeof tok, "hold=%s", mine); 809 size_t tn = strlen(tok); 810 for (char *p = strstr(line, tok); p; p = strstr(p + 1, tok)) 811 if ((p == line || p[-1] == ' ') && (p[tn] == ' ' || p[tn] == '\n' || p[tn] == '\0')) return 1; 812 return 0; 813 } 814 815 /* Whose measurement holds the quiet flag? Decided before and apart from the 816 * host load, so a loaded machine can never hide this answer: main prints it 817 * and tests/runtime/r11_own_hold_test.sh reads it. */ 818 enum { QUIET_FLAG_NONE, QUIET_FLAG_OWN, QUIET_FLAG_OTHER, QUIET_FLAG_REFUSED }; 819 static int quiet_flag_state(void) { 820 const char *h = getenv("HOME"); 821 char home[400] = "", flag[512], real_flag[PATH_MAX], real_home[PATH_MAX]; 822 if (!h || !h[0]) return QUIET_FLAG_NONE; 823 /* Only a checked HOME (src/omega_path_check.h) names the flag; a refused one 824 * cannot rule a measurement out, so other_load treats it as load. */ 825 if (omega_path_copy(home, sizeof home, h) != 0) return QUIET_FLAG_REFUSED; 826 snprintf(flag, sizeof flag, "%s/workspace/.spark-quiet", home); 827 /* The flag must resolve to a file inside $HOME (symlinks and ".." are 828 * resolved first). A flag that is missing or lies outside home is no flag. */ 829 if (!realpath(flag, real_flag) || !realpath(home, real_home)) return QUIET_FLAG_NONE; 830 size_t hn = strlen(real_home); 831 if (strncmp(real_flag, real_home, hn) != 0 || real_flag[hn] != '/') return QUIET_FLAG_NONE; 832 return quiet_flag_is_mine(real_flag) ? QUIET_FLAG_OWN : QUIET_FLAG_OTHER; 833 } 834 835 /* The 1-minute load average above which the living run is not started. 836 * R11_LOAD_LIMIT raises it (tests/runtime/r11_own_hold_test.sh does, to see 837 * the quiet-flag decision on a busy judge); it can never lower it, so the 838 * override cannot make a run pass that the default would refuse. */ 839 #define R11_LOAD_LIMIT_DEFAULT 2.0 840 static double load_limit(void) { 841 const char *v = getenv("R11_LOAD_LIMIT"); 842 if (v && v[0]) { 843 char *end = NULL; 844 double d = strtod(v, &end); 845 if (end != v && *end == '\0' && d > R11_LOAD_LIMIT_DEFAULT) return d; 846 } 847 return R11_LOAD_LIMIT_DEFAULT; 848 } 849 850 /* A timed phase measures this host. When an R15 timed measurement is 851 * running (its quiet flag exists or an R15 program is alive) or the machine 852 * is already loaded, the numbers would describe the other work, so the 853 * living run is not started. Same test as rx_plan_reuse.c. */ 854 static int other_load(int flag_state, char *why, size_t n) { 855 if (flag_state == QUIET_FLAG_REFUSED) { 856 snprintf(why, n, "HOME refused by src/omega_path_check.h"); 857 return 1; 858 } 859 if (flag_state == QUIET_FLAG_OTHER) { 860 snprintf(why, n, "an R15 timed measurement holds ~/workspace/.spark-quiet"); 861 return 1; 862 } 863 DIR *d = opendir("/proc"); 864 if (d) { 865 struct dirent *de; 866 int busy = 0; 867 while (!busy && (de = readdir(d)) != NULL) { 868 if (de->d_name[0] < '0' || de->d_name[0] > '9') continue; 869 char p[300], comm[64] = { 0 }; 870 snprintf(p, sizeof p, "/proc/%s/comm", de->d_name); 871 FILE *f = fopen(p, "r"); 872 if (!f) continue; 873 if (fgets(comm, sizeof comm, f)) 874 busy = strncmp(comm, "rx_r15", 6) == 0 || strncmp(comm, "r15_", 4) == 0; 875 fclose(f); 876 } 877 closedir(d); 878 if (busy) { 879 snprintf(why, n, "an R15 program is running"); 880 return 1; 881 } 882 } 883 double load = 0; 884 FILE *f = fopen("/proc/loadavg", "r"); 885 if (f) { 886 if (fscanf(f, "%lf", &load) != 1) load = 0; 887 fclose(f); 888 } 889 if (load > load_limit()) { 890 snprintf(why, n, "1-minute load average %.2f is above %.0f", load, load_limit()); 891 return 1; 892 } 893 return 0; 894 } 895 896 static uint64_t expected_digest(uint64_t seed, uint32_t M, uint32_t N) { 897 uint64_t *A = malloc((size_t)M * N * sizeof(uint64_t)); 898 uint64_t *x = malloc((size_t)N * sizeof(uint64_t)); 899 uint64_t *y = malloc((size_t)M * sizeof(uint64_t)); 900 rx_omega_fill(seed, A, x, M, N); 901 omega_matvec_reference(A, x, y, M, N); 902 uint64_t d = rx_omega_digest(y, M); 903 free(A); free(x); free(y); 904 return d; 905 } 906 907 /* One outside request; waits for its result the way a client would. */ 908 static uint64_t request(Env *e) { 909 uint64_t seq = ++e->seq; 910 uint64_t seed = seq * 0x2545F4914F6CDD1Dull; 911 RxMutation m[4] = { 912 { e->f.o.request, 0, seq }, { e->f.o.request, 1, REG_M }, 913 { e->f.o.request, 2, REG_N }, { e->f.o.request, 3, seed } }; 914 if (rx_world_publish_external(&e->w, e->ext_request, m, 4) <= 0) { e->refused++; return UINT64_MAX; } 915 uint64_t t0 = now_ns(); 916 while (fld(e, e->f.o.result, 0) != seq) { 917 if (now_ns() - t0 > 5000000000ull) { e->timed_out++; return UINT64_MAX; } 918 sleep_us(20); 919 } 920 RxObject r; 921 rx_world_read(&e->w, e->f.o.result, &r); 922 e->served++; 923 if (r.field[1] != expected_digest(seed, REG_M, REG_N)) e->wrong++; 924 return r.field[3]; 925 } 926 927 typedef int (*Until)(Env *e); 928 929 static uint64_t serve_until(Env *e, Until done, uint64_t limit) { 930 uint64_t n = 0; 931 while (!done(e) && n < limit) { request(e); n++; } 932 return n; 933 } 934 935 /* Mean production ns over n requests. */ 936 static uint64_t serve_mean(Env *e, uint32_t n) { 937 uint64_t s = 0, k = 0; 938 for (uint32_t i = 0; i < n; i++) { 939 uint64_t ns = request(e); 940 if (ns != UINT64_MAX) { s += ns; k++; } 941 } 942 return k ? s / k : 0; 943 } 944 945 static int u_selected1(Env *e) { return fld(e, e->f.o.selection, 0) >= 1; } 946 static int u_confirmed(Env *e) { 947 return fld(e, e->a.o.prediction, 6) == RX_AIEN_PRED_CONFIRMED; 948 } 949 static int u_supported(Env *e) { 950 return fld(e, e->a.o.hypothesis, 7) == RX_AIEN_HYP_SUPPORTED; 951 } 952 953 /* Receipt data. */ 954 static int g_b_run; 955 static const char *g_b_skip = ""; 956 static char g_b_skip_buf[160]; 957 static uint64_t g_sel1_real, g_a725_ns, g_x925_old_ns, g_x925_new_ns, g_sel2_real; 958 static uint64_t g_ctrl_a725_ns, g_ctrl_x925_ns, g_ctrl_search, g_after_move, g_during; 959 static uint64_t g_hyp_kind, g_hyp_state, g_plan_seq, g_search_epoch, g_pred_seq; 960 static uint64_t g_improve_x100; 961 static int g_improved; 962 963 static uint32_t named(Env *e, const char *nm) { 964 for (uint32_t i = 0; i < e->w.n_reactions; i++) 965 if (!strcmp(e->w.reactions[i].desc.name, nm)) return i; 966 return UINT32_MAX; 967 } 968 969 static uint64_t first_commit_after(Env *e, uint32_t rid, uint64_t after) { 970 for (uint64_t id = after + 1; id <= e->w.n_crumbs; id++) { 971 const RxCrumb *c = rx_world_crumb(&e->w, id); 972 if (c && c->kind == RX_CRUMB_COMMIT && c->reaction == rid) return id; 973 } 974 return 0; 975 } 976 977 static void t_living(void) { 978 printf("[*] living run: moved from Cortex-A725 to Cortex-X925, AIEN notices and Omega re-realizes\n"); 979 Env e; 980 CHECK(envB_start(&e, 1) == 0, "setup"); 981 RxAienFaculty *a = &e.a; 982 RxOmegaFaculty *f = &e.f; 983 CHECK(move_all_threads(&g_a725) > 0, "move to A725"); 984 place(&e, CLASS_A725); 985 986 serve_until(&e, u_selected1, 200000); 987 CHECK(fld(&e, f->o.selection, 0) == 1, "Omega's own first search never finished"); 988 g_sel1_real = fld(&e, f->o.selection, 1); 989 serve_until(&e, u_confirmed, 20000); 990 CHECK(u_confirmed(&e), "AIEN never confirmed a prediction on A725"); 991 CHECK(fld(&e, a->o.prediction, 4) == CLASS_A725, "prediction class"); 992 g_a725_ns = fld(&e, a->o.prediction, 5); 993 CHECK(fld(&e, a->o.plan, 0) == 0 && fld(&e, f->o.search, 0) == 1, "acted before anything changed"); 994 995 /* The environment moves the work. Nothing else is published. */ 996 CHECK(move_all_threads(&g_x925) > 0, "move to X925"); 997 place(&e, CLASS_X925); 998 uint64_t c_move = e.w.n_crumbs; 999 uint64_t served_at_move = e.served; 1000 g_after_move = serve_until(&e, u_supported, 200000); 1001 CHECK(u_supported(&e), "hypothesis never supported (state %llu, plan %llu, search %llu)", 1002 (unsigned long long)fld(&e, a->o.hypothesis, 7), (unsigned long long)fld(&e, a->o.plan, 0), 1003 (unsigned long long)fld(&e, f->o.search, 0)); 1004 g_hyp_kind = fld(&e, a->o.hypothesis, 1); 1005 g_hyp_state = fld(&e, a->o.hypothesis, 7); 1006 g_plan_seq = fld(&e, a->o.plan, 0); 1007 g_search_epoch = fld(&e, f->o.search, 0); 1008 g_pred_seq = fld(&e, a->o.prediction, 0); 1009 CHECK(g_hyp_kind == RX_AIEN_HYP_CORE_CLASS, "hypothesis kind %llu", (unsigned long long)g_hyp_kind); 1010 CHECK(fld(&e, a->o.hypothesis, 3) == CLASS_A725 && fld(&e, a->o.hypothesis, 4) == CLASS_X925, 1011 "hypothesis classes"); 1012 CHECK(g_plan_seq == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, "one plan, for the class"); 1013 CHECK(g_search_epoch == 2 && fld(&e, f->o.search, 6) == 1, "Omega took the plan up: search %llu", 1014 (unsigned long long)g_search_epoch); 1015 CHECK(fld(&e, f->o.selection, 0) == 2, "no new selection"); 1016 g_x925_old_ns = fld(&e, a->o.hypothesis, 6); 1017 g_x925_new_ns = fld(&e, a->o.prediction, 5); 1018 g_sel2_real = fld(&e, f->o.selection, 1); 1019 CHECK(fld(&e, a->o.prediction, 4) == CLASS_X925, "new prediction class"); 1020 1021 /* The causal chain: selection 2 <- measure <- ... <- search 2 <- omega.reconsider 1022 * <- plan <- hypothesis <- failed prediction <- demand + placement. */ 1023 uint32_t r_recon = named(&e, "omega.reconsider"); 1024 uint64_t c_plan = first_commit_after(&e, a->r_plan, c_move); 1025 uint64_t c_recon = first_commit_after(&e, r_recon, c_move); 1026 uint64_t c_sel2 = rx_world_explain(&e.w, f->o.selection, 0); 1027 uint64_t c_place = rx_world_explain(&e.w, a->o.placement, 1); 1028 CHECK(c_plan && c_recon && c_plan < c_recon && c_recon < c_sel2, "order plan %llu reconsider %llu sel %llu", 1029 (unsigned long long)c_plan, (unsigned long long)c_recon, (unsigned long long)c_sel2); 1030 CHECK(caused_by(&e, c_sel2, c_recon), "selection does not trace to omega.reconsider"); 1031 CHECK(caused_by(&e, c_recon, c_plan), "reconsider does not trace to AIEN's plan"); 1032 CHECK(caused_by(&e, c_plan, c_place), "plan does not trace to the placement"); 1033 g_during = 0; 1034 for (uint64_t id = c_plan + 1; id < c_sel2; id++) { 1035 const RxCrumb *c = rx_world_crumb(&e.w, id); 1036 if (c && c->kind == RX_CRUMB_COMMIT && c->reaction == f->r_serve) g_during++; 1037 } 1038 CHECK(g_during > 0, "production stopped while AIEN and Omega worked"); 1039 CHECK(e.w.reactions[f->r_watch].commits == 1, "omega.watch searched again on its own"); 1040 printf(" requests: served %llu, wrong %llu, timed out %llu, refused %llu, crumb overflow %llu\n", 1041 (unsigned long long)e.served, (unsigned long long)e.wrong, 1042 (unsigned long long)e.timed_out, (unsigned long long)e.refused, 1043 (unsigned long long)e.w.stats.crumb_overflow); 1044 CHECK(e.wrong == 0, "%llu wrong results", (unsigned long long)e.wrong); 1045 CHECK(e.timed_out == 0 && e.refused == 0 && e.w.stats.crumb_overflow == 0, 1046 "harness/load: %llu timed out, %llu refused, %llu crumb overflow (not wrong results; " 1047 "rerun on a quiet machine)", 1048 (unsigned long long)e.timed_out, (unsigned long long)e.refused, 1049 (unsigned long long)e.w.stats.crumb_overflow); 1050 CHECK(e.served > served_at_move, "served"); 1051 check_only_reactive(&e); 1052 1053 /* The improvement is AIEN's doing only if Omega now runs something faster here. */ 1054 g_improve_x100 = g_x925_new_ns ? g_x925_old_ns * 100u / g_x925_new_ns : 0; 1055 g_improved = g_sel1_real == 0 && g_sel2_real != 0 && g_improve_x100 >= 120; 1056 printf(" A725 record %llx at %llu ns; X925 under it %llu ns; X925 new record %llx at %llu ns (%.2fx)\n", 1057 (unsigned long long)g_sel1_real, (unsigned long long)g_a725_ns, 1058 (unsigned long long)g_x925_old_ns, (unsigned long long)g_sel2_real, 1059 (unsigned long long)g_x925_new_ns, g_improve_x100 / 100.0); 1060 CHECK(g_sel1_real == 0, "Omega kept a realization on A725 at a 10%% margin; the move cannot " 1061 "show an improvement (record %llx)", (unsigned long long)g_sel1_real); 1062 CHECK(g_improved, "no improvement on X925: %llu -> %llu ns", 1063 (unsigned long long)g_x925_old_ns, (unsigned long long)g_x925_new_ns); 1064 env_stop(&e); 1065 1066 /* Control: the same world and move, without AIEN. */ 1067 printf("[*] control: the same move without AIEN leaves the body on the old record\n"); 1068 Env c; 1069 CHECK(envB_start(&c, 0) == 0, "control setup"); 1070 CHECK(move_all_threads(&g_a725) > 0, "control move to A725"); 1071 serve_until(&c, u_selected1, 200000); 1072 g_ctrl_a725_ns = serve_mean(&c, 128); 1073 CHECK(move_all_threads(&g_x925) > 0, "control move to X925"); 1074 for (uint64_t i = 0; i < g_after_move; i++) request(&c); 1075 g_ctrl_x925_ns = serve_mean(&c, 128); 1076 CHECK(settle(&c) == RX_OK, "control settle"); 1077 g_ctrl_search = fld(&c, c.f.o.search, 0); 1078 CHECK(g_ctrl_search == 1 && fld(&c, c.f.o.selection, 0) == 1, 1079 "control re-searched without AIEN (search %llu)", (unsigned long long)g_ctrl_search); 1080 CHECK(fld(&c, c.f.o.selection, 1) == g_sel1_real, "control changed its record"); 1081 CHECK(c.wrong == 0, "control: %llu wrong results", (unsigned long long)c.wrong); 1082 CHECK(c.timed_out == 0 && c.refused == 0 && c.w.stats.crumb_overflow == 0, 1083 "control harness/load: %llu timed out, %llu refused, %llu crumb overflow (not wrong " 1084 "results; rerun on a quiet machine)", 1085 (unsigned long long)c.timed_out, (unsigned long long)c.refused, 1086 (unsigned long long)c.w.stats.crumb_overflow); 1087 printf(" control: A725 %llu ns, X925 after %llu more requests %llu ns\n", 1088 (unsigned long long)g_ctrl_a725_ns, (unsigned long long)g_after_move, 1089 (unsigned long long)g_ctrl_x925_ns); 1090 env_stop(&c); 1091 g_b_run = 1; 1092 } 1093 1094 /* ---- receipt ---- */ 1095 1096 static void binary_digest(char out[65]) { 1097 strcpy(out, "unavailable"); 1098 FILE *fp = fopen("/proc/self/exe", "rb"); 1099 if (!fp) return; 1100 sha256_ctx c; 1101 sha256_init(&c); 1102 uint8_t buf[65536]; 1103 size_t n; 1104 while ((n = fread(buf, 1, sizeof buf, fp)) > 0) sha256_update(&c, buf, n); 1105 fclose(fp); 1106 uint8_t d[32]; 1107 sha256_final(&c, d); 1108 for (int i = 0; i < 32; i++) sprintf(out + i * 2, "%02x", d[i]); 1109 } 1110 1111 static void write_receipt(void) { 1112 char path[512]; 1113 if (omega_evidence_path("R11/rx_aien_faculty_receipt.json", path, sizeof path) != 0) return; 1114 FILE *fp = omega_evidence_create(path); 1115 if (!fp) return; 1116 char commit[41]; 1117 memset(commit, 0, sizeof commit); 1118 if (!omega_evidence_run_commit(commit)) memcpy(commit, "unknown", 8); 1119 const char *candidate = getenv("OMEGA_CANDIDATE_COMMIT"); 1120 int bound = candidate && candidate[0] && strcmp(candidate, commit) == 0 && 1121 !omega_evidence_tree_dirty(); 1122 const char *aienos = getenv("AIENOS_COMMIT"); 1123 char digest[65]; 1124 binary_digest(digest); 1125 struct utsname u; 1126 memset(&u, 0, sizeof u); 1127 uname(&u); 1128 const char *gate = g_fail ? "FAIL" : g_b_run ? "PASS" : "HOST_PASS_LIVING_RUN_NOT_EXERCISED"; 1129 fprintf(fp, 1130 "{\n" 1131 " \"schema\": \"AIEN_RX_R11_AIEN_FACULTY_V1\",\n" 1132 " \"run_id\": \"%s\",\n" 1133 " \"candidate_commit\": %s%s%s,\n" 1134 " \"candidate_bound\": %s,\n" 1135 " \"run_commit\": \"%s\",\n" 1136 " \"tree_dirty\": %s,\n" 1137 " \"aienos_commit\": %s%s%s,\n" 1138 " \"checks\": %d,\n" 1139 " \"failures\": %d,\n" 1140 " \"test_binary_sha256\": \"%s\",\n" 1141 " \"host\": {\"sysname\": \"%s\", \"release\": \"%s\", \"machine\": \"%s\"},\n" 1142 " \"cpus\": {\"cortex_x925\": \"%s\", \"cortex_a725\": \"%s\"},\n" 1143 " \"hardware_scope\": \"host processor only; no graphics processor is used\",\n" 1144 " \"cognition_model\": \"explicit statistical belief model (interval means, tolerance " 1145 "bands, streaks); not a neural model\",\n" 1146 " \"living_run\": {\n" 1147 " \"exercised\": %s,\n" 1148 " \"skip_reason\": \"%s\",\n" 1149 " \"operation\": \"omega_matvec (M12), regime %ux%u\",\n" 1150 " \"a725_record_realization_word0\": \"0x%llx\",\n" 1151 " \"a725_predicted_ns_per_call\": %llu,\n" 1152 " \"x925_observed_ns_under_old_record\": %llu,\n" 1153 " \"x925_record_realization_word0\": \"0x%llx\",\n" 1154 " \"x925_predicted_ns_under_new_record\": %llu,\n" 1155 " \"improvement_x100\": %llu,\n" 1156 " \"requests_after_move_until_supported\": %llu,\n" 1157 " \"production_commits_between_plan_and_new_selection\": %llu,\n" 1158 " \"hypothesis_kind\": %llu, \"hypothesis_state\": %llu,\n" 1159 " \"plans\": %llu, \"search_epochs\": %llu, \"predictions\": %llu,\n" 1160 " \"control_without_aien\": {\"a725_ns\": %llu, \"x925_ns\": %llu, \"search_epochs\": %llu}\n" 1161 " },\n" 1162 " \"gates\": {\n" 1163 " \"R11_CONTINUOUS_COGNITION\": \"%s\",\n" 1164 " \"aien_caused_improvement\": %s,\n" 1165 " \"not_claimed\": [\"R8\", \"R13\", \"neural cognition\", \"durable beliefs (R9)\", " 1166 "\"new memory as a trigger\"]\n" 1167 " }\n" 1168 "}\n", 1169 omega_evidence_run_id(), candidate ? "\"" : "", candidate ? candidate : "null", 1170 candidate ? "\"" : "", bound ? "true" : "false", commit, 1171 omega_evidence_tree_dirty() ? "true" : "false", aienos ? "\"" : "", 1172 aienos ? aienos : "null", aienos ? "\"" : "", g_checks, g_fail, digest, u.sysname, 1173 u.release, u.machine, g_x_cpus, g_a_cpus, g_b_run ? "true" : "false", g_b_skip, REG_M, 1174 REG_N, (unsigned long long)g_sel1_real, (unsigned long long)g_a725_ns, 1175 (unsigned long long)g_x925_old_ns, (unsigned long long)g_sel2_real, 1176 (unsigned long long)g_x925_new_ns, (unsigned long long)g_improve_x100, 1177 (unsigned long long)g_after_move, (unsigned long long)g_during, 1178 (unsigned long long)g_hyp_kind, (unsigned long long)g_hyp_state, 1179 (unsigned long long)g_plan_seq, (unsigned long long)g_search_epoch, 1180 (unsigned long long)g_pred_seq, (unsigned long long)g_ctrl_a725_ns, 1181 (unsigned long long)g_ctrl_x925_ns, (unsigned long long)g_ctrl_search, gate, 1182 g_improved ? "true" : "false"); 1183 fclose(fp); 1184 printf("receipt: %s\n", path); 1185 } 1186 1187 int main(void) { 1188 signal(SIGPIPE, SIG_IGN); 1189 t_no_record(); 1190 t_steady_and_outlier(); 1191 t_core_class(); 1192 t_drift(); 1193 t_drift_burst_refuted(); 1194 t_drift_moved(); 1195 t_baseline_must_agree(); 1196 t_settled_failure_relearns(); 1197 t_goal(); 1198 t_authority(); 1199 #if defined(__aarch64__) 1200 find_core_classes(); 1201 char why[128]; 1202 int flag_state = quiet_flag_state(); 1203 printf("quiet flag: %s\n", flag_state == QUIET_FLAG_NONE ? "none" 1204 : flag_state == QUIET_FLAG_OWN ? "this run's own hold" 1205 : flag_state == QUIET_FLAG_REFUSED ? "HOME refused" 1206 : "another measurement's hold"); 1207 if (g_nx > 0 && g_na > 0 && other_load(flag_state, why, sizeof why)) { 1208 snprintf(g_b_skip_buf, sizeof g_b_skip_buf, "SKIPPED-LOADED: %s", why); 1209 g_b_skip = g_b_skip_buf; 1210 printf("[-] SKIPPED-LOADED: living run not started: %s\n", why); 1211 } else if (g_nx > 0 && g_na > 0) t_living(); 1212 else g_b_skip = "this host does not have both Cortex-X925 and Cortex-A725 cores"; 1213 #else 1214 g_b_skip = "Omega's realizations are AArch64"; 1215 #endif 1216 if (!g_b_run) printf("[-] living run not exercised: %s\n", g_b_skip); 1217 printf("checks %d failures %d\n", g_checks, g_fail); 1218 write_receipt(); 1219 return g_fail ? 1 : 0; 1220 }