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
omega-mv / seed / ng / physics / phys_solver.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/ng/physics/phys_solver.om |
| 3 | note Sovereign Intelligence 2.0 Stage 3 (Pillar 3: Physics-Typed Computing) |
| 4 | note Real-Time Physics Dispatch Solver + ΩIR v2 Contract Reader + Error-Composition Tracker |
| 5 | note + Direct fabHotSwap (seed/ng/target/fabric.om) Wiring. |
| 6 | note |
| 7 | note Exact 1:1 fixed-point mirror of seed/helix/proofs/PhysicsDispatch.lean. |
| 8 | note Queries apps/omega-wattd/watt_cbf.om UNCHANGED (strictly DRY_RUN_READONLY, hw_writes=0). |
| 9 | note |
| 10 | note LOCKED strict priority hierarchy: |
| 11 | note 1. Hardware WattCBF thermal/power safety ceiling is INVIOLABLE |
| 12 | note (P_gpu <= 80,000 mW, P_total <= min(P_budget, 140,000 mW), CBF h >= 0, fail_closed == 0, |
| 13 | note plus @power contract cap when > 0). |
| 14 | note 2. Declared @err bound is NEVER silently broken (proven_err_bound <= @err). |
| 15 | note 3. Minimize latency / honor @deadline inside (1) & (2): |
| 16 | note - If no safe realization meets @deadline: |
| 17 | note * @hard_deadline == 1 -> fail closed with PHYS_ERR_HARD_DEADLINE (never dispatches!) |
| 18 | note * @hard_deadline == 0 -> select fastest safe realization inside (1) & (2) AND emit |
| 19 | note explicit structured ALARM_DEADLINE_SLIP (never silent!). |
| 20 | |
| 21 | note Dispatch & refusal status codes |
| 22 | const PHYS_OK ulong 0 |
| 23 | const PHYS_OK_DEADLINE_SLIP ulong 1 |
| 24 | const PHYS_ERR_BAD_SLOT ulong 10 |
| 25 | const PHYS_ERR_BAD_CONTRACT ulong 11 |
| 26 | const PHYS_ERR_BAD_BASELINE ulong 12 |
| 27 | const PHYS_ERR_WATTCBF_FAIL_CLOSED ulong 13 |
| 28 | const PHYS_ERR_NO_REALIZATION ulong 14 |
| 29 | const PHYS_ERR_WATTCBF_UNSAFE ulong 15 |
| 30 | const PHYS_ERR_ERR_BOUND ulong 16 |
| 31 | const PHYS_ERR_HARD_DEADLINE ulong 17 |
| 32 | const PHYS_ERR_FAB_SWAP ulong 18 |
| 33 | const PHYS_ERR_HW_WRITE_GUARD ulong 19 |
| 34 | const PHYS_ERR_CHAIN_ERR_OVERFLOW ulong 20 |
| 35 | const PHYS_ERR_CHAIN_BAD_STAGE ulong 21 |
| 36 | |
| 37 | note Structured alarm codes (0 = none) |
| 38 | const PHYS_ALARM_NONE ulong 0 |
| 39 | const PHYS_ALARM_DEADLINE_SLIP ulong 1 |
| 40 | |
| 41 | note Actuator mode (strictly READ-ONLY / DRY-RUN) |
| 42 | const PHYS_ACTUATOR_DRY_RUN_READONLY ulong 0 |
| 43 | |
| 44 | note ΩIR v2 precision tiers (exact mirror of seed/ng/IR.md §16.1) |
| 45 | const PHYS_TIER_UNSPEC ulong 0 |
| 46 | const PHYS_TIER_EXACT ulong 1 |
| 47 | const PHYS_TIER_TOL ulong 2 |
| 48 | |
| 49 | note Contract staging array ps_ctr[0..6]: |
| 50 | note [0]=purity_flag [1]=precision_tier [2]=hard_deadline [3]=err_bound |
| 51 | note [4]=deadline_us [5]=power_mw [6]=reserved_byte |
| 52 | global ps_ctr long 8 |
| 53 | |
| 54 | note Baseline non-kernel rail loads ps_base[0..2]: |
| 55 | note [0]=base_cpu_mw [1]=base_unc_mw [2]=fan_req_pct |
| 56 | global ps_base long 4 |
| 57 | |
| 58 | note Dispatch telemetry array ps_tel[0..19]: |
| 59 | const PS_TEL_STATUS ulong 0 |
| 60 | const PS_TEL_BANK_IDX ulong 1 |
| 61 | const PS_TEL_TID ulong 2 |
| 62 | const PS_TEL_PREC ulong 3 |
| 63 | const PS_TEL_POWER_MW ulong 4 |
| 64 | const PS_TEL_LAT_US ulong 5 |
| 65 | const PS_TEL_JOULES_UJ ulong 6 |
| 66 | const PS_TEL_ERR_BOUND ulong 7 |
| 67 | const PS_TEL_DL_MARGIN_US ulong 8 |
| 68 | const PS_TEL_ALARM_CODE ulong 9 |
| 69 | const PS_TEL_ALARM_COUNT ulong 10 |
| 70 | const PS_TEL_TURING_YIELD ulong 11 |
| 71 | const PS_TEL_FAN_PCT ulong 12 |
| 72 | const PS_TEL_BARRIER_H ulong 13 |
| 73 | const PS_TEL_P_SAFE_GPU ulong 14 |
| 74 | const PS_TEL_P_SAFE_CPU ulong 15 |
| 75 | const PS_TEL_HW_WRITES ulong 16 |
| 76 | const PS_TEL_ACTUATOR_MODE ulong 17 |
| 77 | const PS_TEL_REJ_WATTCBF ulong 18 |
| 78 | const PS_TEL_REJ_ERR ulong 19 |
| 79 | global ps_tel long 20 |
| 80 | |
| 81 | note Cumulative structured alarm log (up to 64 deadline-slip events; never silent) |
| 82 | const PS_ALARM_CAP ulong 64 |
| 83 | global ps_alm_count ulong 1 |
| 84 | global ps_alm_code ulong 64 |
| 85 | global ps_alm_sem ulong 64 |
| 86 | global ps_alm_dl long 64 |
| 87 | global ps_alm_lat long 64 |
| 88 | global ps_alm_slip long 64 |
| 89 | global ps_alm_prec ulong 64 |
| 90 | global ps_alm_tid ulong 64 |
| 91 | |
| 92 | note Cumulative dispatch statistics: [0]=dispatches [1]=refusals [2]=swaps [3]=hard_dl_refusals |
| 93 | global ps_stats ulong 8 |
| 94 | |
| 95 | note Sequential call-chain error-composition tracker (up to 64 stages) |
| 96 | const PS_CHAIN_CAP ulong 64 |
| 97 | global ps_ch_active ulong 1 |
| 98 | global ps_ch_refused ulong 1 |
| 99 | global ps_ch_outer_err long 1 |
| 100 | global ps_ch_outer_tier long 1 |
| 101 | global ps_ch_total_err long 1 |
| 102 | global ps_ch_len ulong 1 |
| 103 | global ps_ch_sem ulong 64 |
| 104 | global ps_ch_err long 64 |
| 105 | |
| 106 | fn ps_init to void |
| 107 | for i ulong 8 |
| 108 | put ps_ctr i 0 |
| 109 | put ps_stats i 0 |
| 110 | end |
| 111 | put ps_base 0 10000 |
| 112 | put ps_base 1 5000 |
| 113 | put ps_base 2 40 |
| 114 | for j ulong 20 |
| 115 | put ps_tel j 0 |
| 116 | end |
| 117 | put ps_tel PS_TEL_BANK_IDX long PB_NONE |
| 118 | put ps_tel PS_TEL_HW_WRITES 0 |
| 119 | put ps_tel PS_TEL_ACTUATOR_MODE long PHYS_ACTUATOR_DRY_RUN_READONLY |
| 120 | put ps_alm_count 0 0 |
| 121 | put ps_ch_active 0 0 |
| 122 | put ps_ch_refused 0 0 |
| 123 | put ps_ch_outer_err 0 0 |
| 124 | put ps_ch_outer_tier 0 0 |
| 125 | put ps_ch_total_err 0 0 |
| 126 | put ps_ch_len 0 0 |
| 127 | note Ensure watt_sense hw_writes counter starts at 0 (strictly read-only) |
| 128 | put g_wmeta 12 0 |
| 129 | end |
| 130 | |
| 131 | fn ps_set_baseline base_cpu_mw long base_unc_mw long fan_req long to void |
| 132 | put ps_base 0 base_cpu_mw |
| 133 | put ps_base 1 base_unc_mw |
| 134 | put ps_base 2 fan_req |
| 135 | end |
| 136 | |
| 137 | fn ps_set_contract purity long tier long hard_dl long err_b long dl_us long pwr_mw long to void |
| 138 | put ps_ctr 0 purity |
| 139 | put ps_ctr 1 tier |
| 140 | put ps_ctr 2 hard_dl |
| 141 | put ps_ctr 3 err_b |
| 142 | put ps_ctr 4 dl_us |
| 143 | put ps_ctr 5 pwr_mw |
| 144 | put ps_ctr 6 0 |
| 145 | end |
| 146 | |
| 147 | note Decode little-endian u64 from byte slice at offset off (checked bounds) |
| 148 | fn ps_le_u64 buf view uchar * off ulong to ulong |
| 149 | if gt add off 8 len buf |
| 150 | ret 0 |
| 151 | end |
| 152 | v = ulong 0 |
| 153 | for k ulong 8 |
| 154 | b = ulong get buf add off k |
| 155 | v = or v shl b mul k 8 |
| 156 | end |
| 157 | ret v |
| 158 | end |
| 159 | |
| 160 | note Canonical ΩIR v2 contract validation (exact mirror of seed/ng/IR.md §16.1 & PhysicsDispatch.lean) |
| 161 | fn ps_contract_valid to bool |
| 162 | if ne get ps_ctr 6 0 |
| 163 | ret false |
| 164 | end |
| 165 | pur = get ps_ctr 0 |
| 166 | if or lt pur 0 gt pur 1 |
| 167 | ret false |
| 168 | end |
| 169 | tier = get ps_ctr 1 |
| 170 | if or lt tier 0 gt tier 2 |
| 171 | ret false |
| 172 | end |
| 173 | hdl = get ps_ctr 2 |
| 174 | if or lt hdl 0 gt hdl 1 |
| 175 | ret false |
| 176 | end |
| 177 | eb = get ps_ctr 3 |
| 178 | if lt eb 0 |
| 179 | ret false |
| 180 | end |
| 181 | dl = get ps_ctr 4 |
| 182 | if lt dl 0 |
| 183 | ret false |
| 184 | end |
| 185 | if lt get ps_ctr 5 0 |
| 186 | ret false |
| 187 | end |
| 188 | if ne tier long PHYS_TIER_TOL |
| 189 | if ne eb 0 |
| 190 | ret false |
| 191 | end |
| 192 | end |
| 193 | if eq hdl 1 |
| 194 | if le dl 0 |
| 195 | ret false |
| 196 | end |
| 197 | end |
| 198 | ret true |
| 199 | end |
| 200 | |
| 201 | note Parse a live 28-byte ΩIR v2 wire contract record (IR.md §16.1) into ps_ctr and validate |
| 202 | note Wire layout: [0]=purity u8, [1]=precision_tier u8, [2]=hard_deadline u8, [3]=reserved u8, |
| 203 | note [4..11]=err_bound u64 LE, [12..19]=deadline_us u64 LE, [20..27]=power_mw u64 LE |
| 204 | fn ps_parse_oir_v2_contract rec view uchar * to ulong |
| 205 | if lt len rec 28 |
| 206 | ret PHYS_ERR_BAD_CONTRACT |
| 207 | end |
| 208 | put ps_ctr 0 long get rec 0 |
| 209 | put ps_ctr 1 long get rec 1 |
| 210 | put ps_ctr 2 long get rec 2 |
| 211 | put ps_ctr 6 long get rec 3 |
| 212 | v = ps_le_u64 rec 4 |
| 213 | if gt v 9000000000000000000 |
| 214 | ret PHYS_ERR_BAD_CONTRACT |
| 215 | end |
| 216 | put ps_ctr 3 long v |
| 217 | v = ps_le_u64 rec 12 |
| 218 | if gt v 9000000000000000000 |
| 219 | ret PHYS_ERR_BAD_CONTRACT |
| 220 | end |
| 221 | put ps_ctr 4 long v |
| 222 | v = ps_le_u64 rec 20 |
| 223 | if gt v 9000000000000000000 |
| 224 | ret PHYS_ERR_BAD_CONTRACT |
| 225 | end |
| 226 | put ps_ctr 5 long v |
| 227 | if not ps_contract_valid |
| 228 | ret PHYS_ERR_BAD_CONTRACT |
| 229 | end |
| 230 | ret PHYS_OK |
| 231 | end |
| 232 | |
| 233 | note Build WattProp for bank realization idx using baseline CPU/Uncore loads |
| 234 | fn ps_make_prop idx ulong prop edit WattProp to void |
| 235 | tid = get pb_tid idx |
| 236 | pw = get pb_power_mw idx |
| 237 | bcpu = get ps_base 0 |
| 238 | bunc = get ps_base 1 |
| 239 | fan = get ps_base 2 |
| 240 | if pb_is_gpu_target tid |
| 241 | put prop p_gpu pw |
| 242 | put prop p_cpu bcpu |
| 243 | put prop p_unc bunc |
| 244 | put prop fan_pct fan |
| 245 | else |
| 246 | put prop p_gpu 0 |
| 247 | put prop p_cpu add bcpu pw |
| 248 | put prop p_unc bunc |
| 249 | put prop fan_pct fan |
| 250 | end |
| 251 | end |
| 252 | |
| 253 | note Query watt_cbf.om instantaneous safe power headroom (P_safe_gpu, P_safe_cpu_extra) |
| 254 | fn ps_query_envelope st view WattThermal pol view WattPolicy to void |
| 255 | bcpu = get ps_base 0 |
| 256 | bunc = get ps_base 1 |
| 257 | fan = get ps_base 2 |
| 258 | pg_probe = new WattProp WATT_P_GPU_HARD_MAX bcpu bunc fan |
| 259 | cg = new WattCmd 0 0 0 0 0 0 |
| 260 | wc_cbf_filter st pol pg_probe cg |
| 261 | if eq get cg fail_closed 1 |
| 262 | put ps_tel PS_TEL_P_SAFE_GPU 0 |
| 263 | put ps_tel PS_TEL_P_SAFE_CPU 0 |
| 264 | ret |
| 265 | end |
| 266 | put ps_tel PS_TEL_P_SAFE_GPU get cg p_gpu |
| 267 | pc_probe = new WattProp 0 WATT_P_TOTAL_HARD_MAX bunc fan |
| 268 | cc = new WattCmd 0 0 0 0 0 0 |
| 269 | wc_cbf_filter st pol pc_probe cc |
| 270 | cpu_tot = get cc p_cpu |
| 271 | cpu_extra = sub cpu_tot bcpu |
| 272 | if lt cpu_extra 0 |
| 273 | cpu_extra = long 0 |
| 274 | end |
| 275 | put ps_tel PS_TEL_P_SAFE_CPU cpu_extra |
| 276 | end |
| 277 | |
| 278 | note Priority 1 (INVIOLABLE): verify proof_mask == 7, WattCBF un-clamped admission, and @power cap |
| 279 | fn ps_check_wattcbf idx ulong st view WattThermal pol view WattPolicy to bool |
| 280 | if ne get pb_proof idx PB_PROOF_REQUIRED |
| 281 | ret false |
| 282 | end |
| 283 | pw = get pb_power_mw idx |
| 284 | if lt pw 0 |
| 285 | ret false |
| 286 | end |
| 287 | if gt pw WATT_P_TOTAL_HARD_MAX |
| 288 | ret false |
| 289 | end |
| 290 | if le get pb_lat_us idx 0 |
| 291 | ret false |
| 292 | end |
| 293 | if lt get pb_joules_uj idx 0 |
| 294 | ret false |
| 295 | end |
| 296 | if lt get pb_err_bound idx 0 |
| 297 | ret false |
| 298 | end |
| 299 | cpw = get ps_ctr 5 |
| 300 | if gt cpw 0 |
| 301 | if gt pw cpw |
| 302 | ret false |
| 303 | end |
| 304 | end |
| 305 | pr = new WattProp 0 0 0 0 |
| 306 | cmd = new WattCmd 0 0 0 0 0 0 |
| 307 | ps_make_prop idx pr |
| 308 | wc_cbf_filter st pol pr cmd |
| 309 | if ne get cmd fail_closed 0 |
| 310 | ret false |
| 311 | end |
| 312 | if ne get cmd p_gpu get pr p_gpu |
| 313 | ret false |
| 314 | end |
| 315 | if ne get cmd p_cpu get pr p_cpu |
| 316 | ret false |
| 317 | end |
| 318 | if ne get cmd p_unc get pr p_unc |
| 319 | ret false |
| 320 | end |
| 321 | ret true |
| 322 | end |
| 323 | |
| 324 | note Priority 2 (INVIOLABLE): declared @err bound is NEVER silently broken |
| 325 | fn ps_check_err idx ulong to bool |
| 326 | ret le get pb_err_bound idx get ps_ctr 3 |
| 327 | end |
| 328 | |
| 329 | note Exact deterministic preference order inside (1) & (2): |
| 330 | note minimize est_latency_us, tie-break by lower err_bound, lower est_joules_uj, lower est_power_mw |
| 331 | fn ps_better a ulong b ulong to bool |
| 332 | la = get pb_lat_us a |
| 333 | lb = get pb_lat_us b |
| 334 | if lt la lb |
| 335 | ret true |
| 336 | end |
| 337 | if gt la lb |
| 338 | ret false |
| 339 | end |
| 340 | ea = get pb_err_bound a |
| 341 | eb = get pb_err_bound b |
| 342 | if lt ea eb |
| 343 | ret true |
| 344 | end |
| 345 | if gt ea eb |
| 346 | ret false |
| 347 | end |
| 348 | ua = get pb_joules_uj a |
| 349 | ub = get pb_joules_uj b |
| 350 | if lt ua ub |
| 351 | ret true |
| 352 | end |
| 353 | if gt ua ub |
| 354 | ret false |
| 355 | end |
| 356 | ret lt get pb_power_mw a get pb_power_mw b |
| 357 | end |
| 358 | |
| 359 | note Compute exact TuringYield_J (bits/Joule) via watt_cbf.om's overflow-free wc_turing_yield_bpj |
| 360 | fn ps_turing_yield_uj work_bits long joules_uj long to long |
| 361 | if or le work_bits 0 le joules_uj 0 |
| 362 | ret 0 |
| 363 | end |
| 364 | if le work_bits 9000000000000000 |
| 365 | ret wc_turing_yield_bpj mul work_bits 1000 joules_uj |
| 366 | end |
| 367 | mj = wc_ceil_div joules_uj 1000 |
| 368 | ret wc_turing_yield_bpj work_bits mj |
| 369 | end |
| 370 | |
| 371 | note Emit structured ALARM_DEADLINE_SLIP event for bank entry idx (never silent!) |
| 372 | fn ps_emit_alarm idx ulong dl long to void |
| 373 | cnt = get ps_alm_count 0 |
| 374 | lat = get pb_lat_us idx |
| 375 | if lt cnt PS_ALARM_CAP |
| 376 | put ps_alm_code cnt PHYS_ALARM_DEADLINE_SLIP |
| 377 | put ps_alm_sem cnt get pb_sem idx |
| 378 | put ps_alm_dl cnt dl |
| 379 | put ps_alm_lat cnt lat |
| 380 | put ps_alm_slip cnt sub lat dl |
| 381 | put ps_alm_prec cnt get pb_prec idx |
| 382 | put ps_alm_tid cnt get pb_tid idx |
| 383 | end |
| 384 | ncnt = add cnt 1 |
| 385 | put ps_alm_count 0 ncnt |
| 386 | put ps_tel PS_TEL_ALARM_CODE long PHYS_ALARM_DEADLINE_SLIP |
| 387 | put ps_tel PS_TEL_ALARM_COUNT long ncnt |
| 388 | end |
| 389 | |
| 390 | note Record structured refusal telemetry (fabWtbl untouched!) |
| 391 | fn ps_record_refusal code ulong to ulong |
| 392 | put ps_tel PS_TEL_STATUS long code |
| 393 | put ps_tel PS_TEL_BANK_IDX long PB_NONE |
| 394 | put ps_tel PS_TEL_TID 0 |
| 395 | put ps_tel PS_TEL_PREC 0 |
| 396 | put ps_tel PS_TEL_POWER_MW 0 |
| 397 | put ps_tel PS_TEL_LAT_US 0 |
| 398 | put ps_tel PS_TEL_JOULES_UJ 0 |
| 399 | put ps_tel PS_TEL_ERR_BOUND 0 |
| 400 | put ps_tel PS_TEL_DL_MARGIN_US 0 |
| 401 | put ps_tel PS_TEL_ALARM_CODE long PHYS_ALARM_NONE |
| 402 | put ps_tel PS_TEL_ALARM_COUNT long get ps_alm_count 0 |
| 403 | put ps_tel PS_TEL_TURING_YIELD 0 |
| 404 | put ps_tel PS_TEL_HW_WRITES get g_wmeta 12 |
| 405 | put ps_tel PS_TEL_ACTUATOR_MODE long PHYS_ACTUATOR_DRY_RUN_READONLY |
| 406 | put ps_stats 1 add get ps_stats 1 1 |
| 407 | if eq code PHYS_ERR_HARD_DEADLINE |
| 408 | put ps_stats 3 add get ps_stats 3 1 |
| 409 | end |
| 410 | ret code |
| 411 | end |
| 412 | |
| 413 | note Record WattCBF fan and barrier-h telemetry for admitted bank entry idx |
| 414 | fn ps_record_cbf_tel idx ulong st view WattThermal pol view WattPolicy to void |
| 415 | pr = new WattProp 0 0 0 0 |
| 416 | cmd = new WattCmd 0 0 0 0 0 0 |
| 417 | ps_make_prop idx pr |
| 418 | wc_cbf_filter st pol pr cmd |
| 419 | dt = wc_next_die_delta st get cmd p_gpu get cmd p_cpu get cmd p_unc |
| 420 | bh = wc_barrier_h get pol t_ceil get st t_die get pol tau dt |
| 421 | put ps_tel PS_TEL_FAN_PCT get cmd fan_pct |
| 422 | put ps_tel PS_TEL_BARRIER_H bh |
| 423 | end |
| 424 | |
| 425 | note Record telemetry for an admitted, hot-swapped realization |
| 426 | fn ps_record_win idx ulong st view WattThermal pol view WattPolicy slipped bool to ulong |
| 427 | ps_record_cbf_tel idx st pol |
| 428 | dl = get ps_ctr 4 |
| 429 | lat = get pb_lat_us idx |
| 430 | margin = long 0 |
| 431 | if gt dl 0 |
| 432 | margin = sub dl lat |
| 433 | end |
| 434 | put ps_tel PS_TEL_DL_MARGIN_US margin |
| 435 | put ps_tel PS_TEL_LAT_US lat |
| 436 | put ps_tel PS_TEL_BANK_IDX long idx |
| 437 | put ps_tel PS_TEL_TID long get pb_tid idx |
| 438 | put ps_tel PS_TEL_PREC long get pb_prec idx |
| 439 | put ps_tel PS_TEL_POWER_MW get pb_power_mw idx |
| 440 | put ps_tel PS_TEL_JOULES_UJ get pb_joules_uj idx |
| 441 | put ps_tel PS_TEL_ERR_BOUND get pb_err_bound idx |
| 442 | put ps_tel PS_TEL_TURING_YIELD ps_turing_yield_uj get pb_work_bits idx get pb_joules_uj idx |
| 443 | put ps_tel PS_TEL_HW_WRITES get g_wmeta 12 |
| 444 | put ps_tel PS_TEL_ACTUATOR_MODE long PHYS_ACTUATOR_DRY_RUN_READONLY |
| 445 | put ps_stats 0 add get ps_stats 0 1 |
| 446 | put ps_stats 2 add get ps_stats 2 1 |
| 447 | if slipped |
| 448 | ps_emit_alarm idx dl |
| 449 | put ps_tel PS_TEL_STATUS long PHYS_OK_DEADLINE_SLIP |
| 450 | ret PHYS_OK_DEADLINE_SLIP |
| 451 | end |
| 452 | put ps_tel PS_TEL_ALARM_CODE long PHYS_ALARM_NONE |
| 453 | put ps_tel PS_TEL_ALARM_COUNT long get ps_alm_count 0 |
| 454 | put ps_tel PS_TEL_STATUS long PHYS_OK |
| 455 | ret PHYS_OK |
| 456 | end |
| 457 | |
| 458 | note Scan bank for minimum-latency safe candidate inside Priorities (1) & (2). |
| 459 | note Sets ps_tel[PS_TEL_REJ_WATTCBF] and ps_tel[PS_TEL_REJ_ERR]; returns bank idx or PB_NONE. |
| 460 | note Uses ps_stats[4] temporarily for found count. |
| 461 | fn ps_select_best sem_id ulong st view WattThermal pol view WattPolicy to ulong |
| 462 | best = PB_NONE |
| 463 | found = ulong 0 |
| 464 | rej_wc = long 0 |
| 465 | rej_err = long 0 |
| 466 | for i ulong PB_CAP |
| 467 | if eq get pb_used i 1 |
| 468 | if eq get pb_sem i sem_id |
| 469 | found = add found 1 |
| 470 | if not ps_check_wattcbf i st pol |
| 471 | rej_wc = add rej_wc 1 |
| 472 | else |
| 473 | if not ps_check_err i |
| 474 | rej_err = add rej_err 1 |
| 475 | else |
| 476 | if eq best PB_NONE |
| 477 | best = i |
| 478 | else |
| 479 | if ps_better i best |
| 480 | best = i |
| 481 | end |
| 482 | end |
| 483 | end |
| 484 | end |
| 485 | end |
| 486 | end |
| 487 | end |
| 488 | put ps_stats 4 found |
| 489 | put ps_tel PS_TEL_REJ_WATTCBF rej_wc |
| 490 | put ps_tel PS_TEL_REJ_ERR rej_err |
| 491 | ret best |
| 492 | end |
| 493 | |
| 494 | note Primary Real-Time Physics Dispatch Solver: |
| 495 | note Queries watt_cbf.om + ΩIR v2 contract, enforces WattCBF > @err > @deadline, |
| 496 | note wires winner into fabHotSwap (seed/ng/target/fabric.om), records telemetry. |
| 497 | fn ps_dispatch sem_id ulong wtbl_slot ulong st view WattThermal pol view WattPolicy to ulong |
| 498 | if ne get g_wmeta 12 0 |
| 499 | ret ps_record_refusal PHYS_ERR_HW_WRITE_GUARD |
| 500 | end |
| 501 | if ge wtbl_slot FAB_SLOTS |
| 502 | ret ps_record_refusal PHYS_ERR_BAD_SLOT |
| 503 | end |
| 504 | if not ps_contract_valid |
| 505 | ret ps_record_refusal PHYS_ERR_BAD_CONTRACT |
| 506 | end |
| 507 | if lt get ps_base 0 0 |
| 508 | ret ps_record_refusal PHYS_ERR_BAD_BASELINE |
| 509 | end |
| 510 | if lt get ps_base 1 0 |
| 511 | ret ps_record_refusal PHYS_ERR_BAD_BASELINE |
| 512 | end |
| 513 | ps_query_envelope st pol |
| 514 | if wc_must_fail_closed st pol |
| 515 | put ps_tel PS_TEL_FAN_PCT WATT_FAN_MAX |
| 516 | put ps_tel PS_TEL_BARRIER_H 0 |
| 517 | ret ps_record_refusal PHYS_ERR_WATTCBF_FAIL_CLOSED |
| 518 | end |
| 519 | best = ps_select_best sem_id st pol |
| 520 | if eq best PB_NONE |
| 521 | if eq get ps_stats 4 0 |
| 522 | ret ps_record_refusal PHYS_ERR_NO_REALIZATION |
| 523 | end |
| 524 | if gt get ps_tel PS_TEL_REJ_ERR 0 |
| 525 | ret ps_record_refusal PHYS_ERR_ERR_BOUND |
| 526 | end |
| 527 | ret ps_record_refusal PHYS_ERR_WATTCBF_UNSAFE |
| 528 | end |
| 529 | dl = get ps_ctr 4 |
| 530 | slipped = false |
| 531 | if gt dl 0 |
| 532 | if gt get pb_lat_us best dl |
| 533 | slipped = true |
| 534 | end |
| 535 | end |
| 536 | if slipped |
| 537 | if eq get ps_ctr 2 1 |
| 538 | ret ps_record_refusal PHYS_ERR_HARD_DEADLINE |
| 539 | end |
| 540 | end |
| 541 | tid = get pb_tid best |
| 542 | mode = pb_mode_for_realization tid get pb_prec best |
| 543 | if not fabHotSwap wtbl_slot sem_id get pb_code_ptr best tid mode get pb_proof best |
| 544 | ret ps_record_refusal PHYS_ERR_FAB_SWAP |
| 545 | end |
| 546 | ret ps_record_win best st pol slipped |
| 547 | end |
| 548 | |
| 549 | note ---- Sequential Call-Chain Error-Composition Tracker ---- |
| 550 | |
| 551 | note Begin a sequential call chain bounded by outer_err (and outer precision tier) |
| 552 | fn ps_chain_begin outer_err long outer_tier long to ulong |
| 553 | put ps_ch_active 0 0 |
| 554 | put ps_ch_refused 0 0 |
| 555 | put ps_ch_total_err 0 0 |
| 556 | put ps_ch_len 0 0 |
| 557 | if or lt outer_err 0 or lt outer_tier 0 gt outer_tier 2 |
| 558 | ret PHYS_ERR_BAD_CONTRACT |
| 559 | end |
| 560 | if ne outer_tier long PHYS_TIER_TOL |
| 561 | if ne outer_err 0 |
| 562 | ret PHYS_ERR_BAD_CONTRACT |
| 563 | end |
| 564 | end |
| 565 | put ps_ch_outer_err 0 outer_err |
| 566 | put ps_ch_outer_tier 0 outer_tier |
| 567 | put ps_ch_active 0 1 |
| 568 | ret PHYS_OK |
| 569 | end |
| 570 | |
| 571 | note Compose one additive stage error bound into the active call chain (overflow-safe) |
| 572 | fn ps_chain_add_stage sem_id ulong stage_err long to ulong |
| 573 | if eq get ps_ch_active 0 0 |
| 574 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 575 | end |
| 576 | if eq get ps_ch_refused 0 1 |
| 577 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 578 | end |
| 579 | if lt stage_err 0 |
| 580 | put ps_ch_refused 0 1 |
| 581 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 582 | end |
| 583 | n = get ps_ch_len 0 |
| 584 | if ge n PS_CHAIN_CAP |
| 585 | put ps_ch_refused 0 1 |
| 586 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 587 | end |
| 588 | tot = get ps_ch_total_err 0 |
| 589 | outer = get ps_ch_outer_err 0 |
| 590 | rem_bud = sub outer tot |
| 591 | if gt stage_err rem_bud |
| 592 | put ps_ch_refused 0 1 |
| 593 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 594 | end |
| 595 | put ps_ch_sem n sem_id |
| 596 | put ps_ch_err n stage_err |
| 597 | put ps_ch_total_err 0 add tot stage_err |
| 598 | put ps_ch_len 0 add n 1 |
| 599 | ret PHYS_OK |
| 600 | end |
| 601 | |
| 602 | note Compose one interval/Lipschitz stage: outward-rounded ceil(total_err * amp_num / amp_den) + stage_err |
| 603 | fn ps_chain_add_stage_amp sem_id ulong stage_err long amp_num long amp_den long to ulong |
| 604 | if eq get ps_ch_active 0 0 |
| 605 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 606 | end |
| 607 | if eq get ps_ch_refused 0 1 |
| 608 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 609 | end |
| 610 | if or lt stage_err 0 or le amp_den 0 lt amp_num amp_den |
| 611 | put ps_ch_refused 0 1 |
| 612 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 613 | end |
| 614 | n = get ps_ch_len 0 |
| 615 | if ge n PS_CHAIN_CAP |
| 616 | put ps_ch_refused 0 1 |
| 617 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 618 | end |
| 619 | tot = get ps_ch_total_err 0 |
| 620 | outer = get ps_ch_outer_err 0 |
| 621 | if gt tot 1000000000 |
| 622 | put ps_ch_refused 0 1 |
| 623 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 624 | end |
| 625 | if gt amp_num 1000000000 |
| 626 | put ps_ch_refused 0 1 |
| 627 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 628 | end |
| 629 | scaled = wc_ceil_div mul tot amp_num amp_den |
| 630 | if gt scaled outer |
| 631 | put ps_ch_refused 0 1 |
| 632 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 633 | end |
| 634 | rem_bud = sub outer scaled |
| 635 | if gt stage_err rem_bud |
| 636 | put ps_ch_refused 0 1 |
| 637 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 638 | end |
| 639 | put ps_ch_sem n sem_id |
| 640 | put ps_ch_err n stage_err |
| 641 | put ps_ch_total_err 0 add scaled stage_err |
| 642 | put ps_ch_len 0 add n 1 |
| 643 | ret PHYS_OK |
| 644 | end |
| 645 | |
| 646 | note Commit the active call chain; refuses if any stage overflowed outer @err |
| 647 | fn ps_chain_commit to ulong |
| 648 | if eq get ps_ch_active 0 0 |
| 649 | ret PHYS_ERR_CHAIN_BAD_STAGE |
| 650 | end |
| 651 | if ne get ps_ch_refused 0 0 |
| 652 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 653 | end |
| 654 | if gt get ps_ch_total_err 0 get ps_ch_outer_err 0 |
| 655 | put ps_ch_refused 0 1 |
| 656 | ret PHYS_ERR_CHAIN_ERR_OVERFLOW |
| 657 | end |
| 658 | put ps_ch_active 0 0 |
| 659 | ret PHYS_OK |
| 660 | end |