Files
LithosAnanake/experiments/std79-doe/std79-doe.fth
T
Robert Allan JamesandClaude Sonnet 5 9eff122090
Build / build-amd64-iso (push) Waiting to run
Build / build-aarch64-iso (push) Waiting to run
Build / build-riscv64-img (push) Waiting to run
Fix aarch64 Stadium/COOL O(ncells) scan; rerun std79 DoE clean, 81/81 (FABRIC-3.md §XVI)
Root cause of the 90+ minute aarch64 VM-birth stall found in §XV: stadium_admit()'s
eviction-fallback scan iterated the entire stadium_ncells array filtered by owner,
not the calling VM's own resident cells as its own doc comment claimed. Combined
with stadium_grant_quota() always splitting from Hera's shrinking free list and
stadium_word_dispatch() calling stadium_admit() per distinct word a VM's capsule
executes, this compounded into a real O(n) blowup — catastrophic specifically on
aarch64 because its -m 4096 (vs 1024 on amd64/riscv64) inflates the kmalloc heap
kmalloc_init() bisects down to, which inflates stadium_ncells 4x (335,544 vs 83,886
cells, measured from boot logs).

Fixed by threading a real per-VM doubly-linked resident-cell list
(StadiumVMQuota.resident_head + stadium_resident_next[]/stadium_resident_prev[])
so the fallback scan is bounded by that VM's own resident count, not the global
cell array size.

Verified with a full rerun of the 3x9x3 std79 DoE campaign from scratch: one
continuous boot per architecture, all 9 identities simultaneously live throughout
(the 3-boot aarch64/riscv64 batching workaround is no longer needed). 81/81 trials
correct, 0 mismatches, DOE-RUN header sequence md5-identical across all three raw
logs. Identity 04's attach on aarch64, which stalled 90+ minutes before, now
completes in ~34s; full boot-to-DoE-complete in ~290s.

Corrects an earlier misreading (carried into §XV, std79-doe.fth's comments, and
the project memory note) that described the symptom as a runaway "335,000+ cycles"
dispatch counter — those were cell array indices, not an event count.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXieurDfDSsDFdnSyusuWo
2026-09-11 16:37:44 -04:00

181 lines
6.4 KiB
Forth

( std79-doe.4th - 3(arch, fixed per boot) x 9(identity) x 3(rep) )
( randomized full-factorial DoE. Same 24-case content as )
( std79-exerciser.fth, driven via VM-EXEC into each identity's own )
( live VM (all 9 pre-attached before this runs); "zuse" dispatches )
( into "Hera" herself since her power is a session flag on Hera, )
( not a separate registered VM. Fisher-Yates shuffle matches )
( doe.4th's own algorithm/style; seed fixed for cross-architecture )
( reproducibility (same permutation applied on every arch). )
9 CONSTANT N-ID
3 CONSTANT N-REPS
27 CONSTANT N-RUNS
24 CONSTANT N-TESTS
: ID-NAME ( idx -- c-addr u )
CASE
0 OF S" Hera" ENDOF
1 OF S" rajames" ENDOF
2 OF S" 00" ENDOF
3 OF S" 01" ENDOF
4 OF S" 02" ENDOF
5 OF S" 03" ENDOF
6 OF S" 04" ENDOF
7 OF S" 05" ENDOF
8 OF S" 06" ENDOF
ENDCASE ;
: ID-LABEL ( idx -- c-addr u )
CASE
0 OF S" zuse" ENDOF
1 OF S" rajames" ENDOF
2 OF S" 00" ENDOF
3 OF S" 01" ENDOF
4 OF S" 02" ENDOF
5 OF S" 03" ENDOF
6 OF S" 04" ENDOF
7 OF S" 05" ENDOF
8 OF S" 06" ENDOF
ENDCASE ;
( idx 0 (zuse) runs natively on Hera -- never via VM-EXEC targeting )
( "Hera" herself: VM-EXEC's own vm_state_push/pop only saves )
( rsp/exit_colon/ecw_nesting, not input_buffer/input_pos, so a )
( self-targeting call while THIS capsule's own vm_interpret call is )
( still mid-line would risk clobbering the outer parse -- the exact )
( class of bug the idle-tick reentrancy guards (repl.c) exist for, )
( just not covered by VM-EXEC's own narrower state stack. Sidestepped )
( entirely by never dispatching a string back into the caller's own )
( VM; the same 24 cases are just directly-compiled code below. )
: RUN-TEST-NATIVE ( n -- )
CASE
0 OF 7 3 /MOD SWAP . . ENDOF
1 OF -7 3 /MOD SWAP . . ENDOF
2 OF 7 -3 /MOD SWAP . . ENDOF
3 OF -7 -3 /MOD SWAP . . ENDOF
4 OF 2147483647 1 + . ENDOF
5 OF -2147483648 NEGATE . ENDOF
6 OF -2147483648 ABS . ENDOF
7 OF -1 1 RSHIFT . ENDOF
8 OF -8 2 RSHIFT . ENDOF
9 OF 1 31 LSHIFT . ENDOF
10 OF -1 0 < . ENDOF
11 OF -1 0 U< . ENDOF
12 OF 123 456 M* SWAP D. ENDOF
13 OF -123 456 M* SWAP D. ENDOF
14 OF 100000 S>D SWAP 7 M/MOD . . ENDOF
15 OF 7 11 3 */ . ENDOF
16 OF 7 11 3 */MOD SWAP . . ENDOF
17 OF -5 S>D SWAP D. ENDOF
18 OF -5 S>D 3 S>D D+ SWAP D. ENDOF
19 OF -5 S>D DNEGATE SWAP D. ENDOF
20 OF -5 3 MIN . -5 3 MAX . ENDOF
21 OF 5 0 10 WITHIN . ENDOF
22 OF -1 0 AND . -1 0 OR . 5 3 XOR . ENDOF
23 OF -2147483648 2/ . ENDOF
ENDCASE ;
: TEST-CMD ( n -- c-addr u )
CASE
0 OF S" 7 3 /MOD SWAP . ." ENDOF
1 OF S" -7 3 /MOD SWAP . ." ENDOF
2 OF S" 7 -3 /MOD SWAP . ." ENDOF
3 OF S" -7 -3 /MOD SWAP . ." ENDOF
4 OF S" 2147483647 1 + ." ENDOF
5 OF S" -2147483648 NEGATE ." ENDOF
6 OF S" -2147483648 ABS ." ENDOF
7 OF S" -1 1 RSHIFT ." ENDOF
8 OF S" -8 2 RSHIFT ." ENDOF
9 OF S" 1 31 LSHIFT ." ENDOF
10 OF S" -1 0 < ." ENDOF
11 OF S" -1 0 U< ." ENDOF
12 OF S" 123 456 M* SWAP D." ENDOF
13 OF S" -123 456 M* SWAP D." ENDOF
14 OF S" 100000 S>D SWAP 7 M/MOD . ." ENDOF
15 OF S" 7 11 3 */ ." ENDOF
16 OF S" 7 11 3 */MOD SWAP . ." ENDOF
17 OF S" -5 S>D SWAP D." ENDOF
18 OF S" -5 S>D 3 S>D D+ SWAP D." ENDOF
19 OF S" -5 S>D DNEGATE SWAP D." ENDOF
20 OF S" -5 3 MIN . -5 3 MAX ." ENDOF
21 OF S" 5 0 10 WITHIN ." ENDOF
22 OF S" -1 0 AND . -1 0 OR . 5 3 XOR ." ENDOF
23 OF S" -2147483648 2/ ." ENDOF
ENDCASE ;
CREATE RUN-MATRIX N-RUNS CELLS ALLOT
: MATRIX! ( val idx -- ) CELLS RUN-MATRIX + ! ;
: MATRIX@ ( idx -- val ) CELLS RUN-MATRIX + @ ;
VARIABLE SW-I VARIABLE SW-J VARIABLE SW-VI VARIABLE SW-VJ
: SWAP-MTX ( i j -- )
SW-J ! SW-I !
SW-I @ MATRIX@ SW-VI !
SW-J @ MATRIX@ SW-VJ !
SW-VJ @ SW-I @ MATRIX!
SW-VI @ SW-J @ MATRIX! ;
: INIT-MATRIX ( -- ) N-RUNS 0 DO I I MATRIX! LOOP ;
: SHUFFLE-MATRIX ( -- )
N-RUNS 1 - 0 DO
I N-RUNS 1 - RANDOM
I SWAP-MTX
LOOP ;
VARIABLE CURR-ID
VARIABLE CURR-REP
( Boot-batching support, added 2026-09-11 (FABRIC-3.md SXV). Originally a )
( workaround for a real aarch64 Stadium/COOL scaling bug -- root-caused and )
( fixed 2026-09-11/12 (FABRIC-3.md SXVI, src/starkernel/vm/stadium.c): )
( stadium_grant_quota() halves the granting VM's own free list on every )
( birth with no floor, and stadium_admit()'s eviction fallback used to scan )
( the ENTIRE global cell array (stadium_ncells, in the hundreds of )
( thousands on aarch64's larger RAM-scaled Stadium) filtered by owner, )
( instead of walking just the calling VM's own resident cells as its own )
( doc comment already claimed -- fixed by threading a real per-VM resident )
( list. A single boot with all 9 identities simultaneously live now works )
( cleanly on all three architectures (see results-20260911-stadium-fix/), )
( so ACTIVE-LO/ACTIVE-HI is no longer load-bearing -- kept only as general )
( flexibility: every boot shares the SAME seed so INIT-MATRIX/SHUFFLE-MATRIX )
( produce the identical master 27-slot permutation regardless of how many )
( boots this runs across; only the ACTIVE-LO/ACTIVE-HI filter differs if )
( split. The recorded run_id is always I itself (the slot's true position )
( in the master shuffle), never a separately-incremented counter, so row )
( order stays meaningful and comparable across any number of boots. )
VARIABLE ACTIVE-LO
VARIABLE ACTIVE-HI
: ACTIVE? ( idx -- flag )
DUP ACTIVE-LO @ >=
SWAP ACTIVE-HI @ <=
AND ;
: RUN-TEST ( n -- )
CURR-ID @ 0= IF
RUN-TEST-NATIVE
ELSE
TEST-CMD CURR-ID @ ID-NAME VM-EXEC
THEN ;
VARIABLE CURR-RUN-ID
: RUN-TRIAL ( id-idx rep run-id -- )
CURR-RUN-ID !
CURR-REP ! CURR-ID !
." DOE-RUN," CURR-RUN-ID @ . ." ," CURR-ID @ . ." ,"
CURR-ID @ ID-LABEL TYPE ." ," CURR-REP @ . CR
N-TESTS 0 DO I RUN-TEST LOOP ;
: EXEC-STD79-DOE ( seed lo hi -- )
ACTIVE-HI ! ACTIVE-LO !
SEED
INIT-MATRIX SHUFFLE-MATRIX
." DOE-HEADER,run_id,id_idx,id_label,rep" CR
N-RUNS 0 DO
I MATRIX@
DUP N-REPS /
DUP ACTIVE? IF
SWAP N-REPS MOD I RUN-TRIAL
ELSE
DROP DROP
THEN
LOOP
." STD79-DOE: complete" CR ;