interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / ng / ngbench.om

1505 lines · 27738 bytes Raw Blame History
1note ngbench: the Hive NG A/B timing harness (seed/ng/ngbench.om). Built by seed/out/omc together with
2note the shared SHA-256 unit seed/ng/sha256.om (D1b), this file first (its om2 line sets the profile),
3note then sha256.om, then seed/ng/bench/ngbench-sha.om (hashpb: it names sha256.om's globals, which must
4note be declared before use): `cat seed/ng/ngbench.om seed/ng/sha256.om seed/ng/bench/ngbench-sha.om |
5note seed/out/omc > ngbench`. It builds
6note nothing itself. It runs already-built arm binaries in palindromic ABBA blocks, times each process
7note with monons from before fork to after waitpid, checks every output against its referee hash and
8note checks every arm binary's identity before and after timing. It writes raw rows only; the
9note statistics are done in Wolfram from the rows. Base: bench/omc_efficiency/conductor.om (omega-mv
10note perf/omc-efficiency-baseline d11a7177): child, runone, packet and row code ported from it.
11note
12note ngbench sum FILE ..
13note one line per FILE: 64 lowercase hex digits of its SHA-256, two spaces, FILE (the format of
14note sha256sum). Exit 0, or 1 when a FILE cannot be read (named on stderr).
15note ngbench run BLOCKS WARM DIR ARM .. -- CASE ..
16note DIR/bin/ARM/CASE the arm binary (absent, meaning open fails with ENOENT, and unlisted: the pair
17note is skipped; present but unopenable, unreadable or 16 MiB or more: refused)
18note DIR/manifest.sha256 sha256sum lines "HEX bin/ARM/CASE" for every present binary
19note DIR/want/CASE.sha256 the referee's stdout SHA-256 (64 hex digits)
20note DIR/in/CASE optional stdin of every run of CASE (else /dev/null)
21note DIR/run.out DIR/run.err scratch files: the child's stdout and stderr
22note ARM names state their kind by prefix: omc (the seeded omc layout: AArch64 ELF, entry 0x4000b0,
23note no section table, no "GCC: (" string), gcc (an AArch64 ELF holding "GCC: ("), ng (an AArch64
24note ELF without "GCC: ("). Any other prefix is a usage error.
25note Identity, before any timing: every present binary must match its kind, be listed in the manifest
26note with its own SHA-256; a binary listed but absent is refused. After the last block every binary is
27note hashed again and must be unchanged. A failed identity check is refused by name, no run is timed.
28note Order: block b (0 .. WARM+BLOCKS-1), for every CASE: the present arms p0 .. pk-1 rotated left by
29note b, then the same sequence reversed (A B B A for two arms), so every arm runs twice per block at
30note mirrored positions. Blocks below WARM are warm-up, flagged warm=1.
31note Rows (stdout, one per line, space separated):
32note H ngbench v3 blocks=B warm=W cpus=LIST core=N|unpinned clustermask=M load=LOADAVG
33note A CASE ARM SHA256 BYTES | A CASE ARM absent I CASE SHA256 BYTES (stdin file)
34note L BLOCK LOADAVG at every block start
35note T BLOCK WARM CASE ARM POS WALL_NS STATUS OK INPROC_NS
36note STATUS: exit status, or 1000+signal; OK 1 only when STATUS is 0 and the stdout SHA-256 equals
37note the want; INPROC_NS: the child's stderr when it is exactly one decimal line, else 0
38note v2 contamination rows (seed/ng/bench/PREREG-contamination.md), only when ngbench is pinned to one
39note CPU (Cpus_allowed_list a single number N; the cluster is cpuN/topology/cluster_cpus_list).
40note Before (PH s) and after (PH e) the ABBA sequence of every BLOCK and CASE, every task of
41note /proc/*/task/*/stat is read (field 3 state, field 39 last processor); ngbench's own tasks are
42note excluded. Read between runs, never inside a timed interval.
43note X BLOCK CASE PH PID TID COMM CPU STATE a task last on core N (any state), or runnable (R) or in
44note uninterruptible sleep (D) on another CPU of the cluster; spaces in COMM
45note become _
46note Y BLOCK CASE PH tasks=N cluster=N xrows=N core_foreign_runnable=N errors=N ollm=N gpuline=N
47note the counts of the scan: every task read, those last on the cluster, the X
48note rows, the R tasks on core N, the task stat files that could not be parsed,
49note and (v3, PREREG-slice.md) the processes anywhere on the machine (main task,
50note TID = PID) whose COMM starts with "ollm" (model serve, train, gtrain4) or
51note with "spark-window" (a GB10/quiet window held, waited for or queried)
52note K BLOCK CASE start=N end=N contaminated=0|1 busy=0|1 start/end: core_foreign_runnable of the
53note two scans; contaminated 1 when either is above 0; busy (v3) 1 when either
54note scan counted an ollm or spark-window process
55note R REASON CASE ARM refusals (also on stderr), REASON in kind label unlisted manifest
56note missing nowant status output changed input; label also covers a binary
57note that is present (open does not fail with ENOENT) but cannot be opened or
58note read or holds 16 MiB or more, input the same for a stdin file DIR/in/CASE
59note E LOADAVG after the last block
60note S rows=N ok=N fail=N refused=N
61note Exit: 0 when every row is ok and nothing was refused; 1 otherwise; 2 bad usage. Contamination does
62note not change the exit status; it is classified from the K and X rows.
63om2
64text tbin "/bin/"
65text trbin "bin/"
66text tslash "/"
67text twant "/want/"
68text tdsha ".sha256"
69text tin "/in/"
70text trout "/run.out"
71text trerr "/run.err"
72text tman "/manifest.sha256"
73text tnull "/dev/null"
74text tload "/proc/loadavg"
75text tstat "/proc/self/status"
76text tcpus "Cpus_allowed_list:"
77text tgcc "GCC: ("
78text tdd "--"
79text tsp " "
80text tsp2 " "
81text tnl "\n"
82text tH "H ngbench v3 blocks="
83text twarm " warm="
84text tcpu " cpus="
85text tld " load="
86text tA "A "
87text tabs " absent"
88text tI "I "
89text tL "L "
90text tT "T "
91text tR "R "
92text tE "E "
93text tS "S rows="
94text tok " ok="
95text tfail " fail="
96text tref " refused="
97text tnrd "ngbench: cannot read "
98text tusage "usage: ngbench sum FILE .. | ngbench run BLOCKS WARM DIR ARM .. -- CASE ..\n"
99text trkind "kind"
100text trlab "label"
101text trunl "unlisted"
102text trman "manifest"
103text trmis "missing"
104text trnow "nowant"
105text trsta "status"
106text trout2 "output"
107text trchg "changed"
108text trinp "input"
109text tproc "/proc"
110text ttask "/task"
111text tstat2 "/stat"
112text tsys1 "/sys/devices/system/cpu/cpu"
113text tsys2 "/topology/cluster_cpus_list"
114text tcore " core="
115text tunp "unpinned"
116text tcm " clustermask="
117text tX "X "
118text tY "Y "
119text tK "K "
120text tphs "s"
121text tphe "e"
122text ttsk " tasks="
123text tclu " cluster="
124text txr " xrows="
125text tcfr " core_foreign_runnable="
126text terrs " errors="
127text tkst " start="
128text tken " end="
129text tkc " contaminated="
130text tollm " ollm="
131text tgpl " gpuline="
132text tkbz " busy="
133text tpollm "ollm"
134text tpswin "spark-window"
135note gpb: the path being built; gpk: the exec packet; glb: the output line; gfb: a whole file
136note (binaries, manifest pieces, small text files); gmb: the manifest; gwx: want hex per case;
137note ghx: hex of gdg, the last digest; gpr: present flags [case*16+arm]; gpl/gord: arm order
138global gpb uchar 2048
139global gpbn ulong 1
140global gpk uchar 4096
141global gpkn ulong 1
142global gpkc ulong 1
143global glb uchar 4096
144global glbn ulong 1
145global gfb uchar 16777216
146global gmb uchar 1048576
147global gmbn ulong 1
148global gab uchar 256
149global gdg uchar 32
150global ghx uchar 64
151global gwx uchar 4096
152global gst uchar 4
153global gstat ulong 1
154global gpr ulong 1024
155global gsz ulong 1024
156global gpl ulong 16
157global gord ulong 32
158global gcfg ulong 16
159global gcnt ulong 8
160global gdn uchar 65536
161global gdt uchar 65536
162global gtb uchar 1024
163global gsc ulong 20
164note gsc: 0 timed core (99999 unpinned), 1 cluster mask, 2 own pid, 3 foreign R on the core, 4 tasks
165note read, 5 tasks on the cluster, 6 X rows, 7 parse errors, 8 state byte, 9 cpu, 10/11 comm start/end,
166note 12/13/14 block, case, phase of the scan, 15 ollm processes, 16 spark-window processes, 17/18 their
167note sum in the start / end scan
168note gcfg: 0 blocks, 1 warm, 2 DIR arg index, 3 first arm arg, 4 arm count, 5 first case arg,
169note 6 case count, 7 inproc line valid. gcnt: 0 rows, 1 ok, 2 fail, 3 refused.
170
171note ---- path builder
172fn pbclr to void
173put gpbn 0 0
174end
175fn pbtext t view uchar * to void
176n = get gpbn 0
177if gt add n len t 2048
178trap 9
179end
180for i ulong len t
181put gpb add n i get t i
182end
183put gpbn 0 add n len t
184end
185fn pbarg idx ulong to void
186n = get gpbn 0
187r = argread idx gpb n sub 2048 n
188if lt r 0
189trap 9
190end
191put gpbn 0 add n ulong r
192end
193note DIR/T1 ARM T2 CASE T3, with any piece left out by passing index 0 / an empty text
194fn pbdir to void
195pbclr
196pbarg get gcfg 2
197end
198fn pbbin ai ulong ci ulong to void
199pbdir
200pbtext tbin
201pbarg ai
202pbtext tslash
203pbarg ci
204end
205
206note ---- exec packet: u16 count, then records (u16 length, bytes); pkpush adds gpb as one record
207fn pkreset to void
208put gpk 0 0
209put gpk 1 0
210put gpkn 0 2
211put gpkc 0 0
212end
213fn pkpush to void
214n = get gpkn 0
215m = get gpbn 0
216if gt add add n m 2 4096
217trap 9
218end
219put gpk n uchar and m 255
220put gpk add n 1 uchar shr m 8
221for i ulong m
222put gpk add add n 2 i get gpb i
223end
224put gpkn 0 add add n m 2
225c = add get gpkc 0 1
226put gpkc 0 c
227put gpk 0 uchar and c 255
228put gpk 1 uchar shr c 8
229end
230
231note ---- the output line
232fn lbtext t view uchar * to void
233n = get glbn 0
234if gt add n len t 4096
235trap 9
236end
237for i ulong len t
238put glb add n i get t i
239end
240put glbn 0 add n len t
241end
242fn lbnum v ulong to void
243d = new uchar 24 0
244p = ulong 24
245x = v
246while gt x 9
247p = sub p 1
248put d p uchar add rem x 10 48
249x = div x 10
250end
251p = sub p 1
252put d p uchar add x 48
253n = get glbn 0
254for i ulong sub 24 p
255put glb add n i get d add p i
256end
257put glbn 0 add n sub 24 p
258end
259fn lbarg idx ulong to void
260n = get glbn 0
261r = argread idx glb n sub 4096 n
262if lt r 0
263trap 9
264end
265put glbn 0 add n ulong r
266end
267fn lbhex to void
268n = get glbn 0
269if gt add n 64 4096
270trap 9
271end
272for i ulong 64
273put glb add n i get ghx i
274end
275put glbn 0 add n 64
276end
277note one line of gfb from st0, up to (not including) LF or the end n
278fn lbfb st0 ulong n ulong to void
279i = st0
280going = true
281while going
282if ge i n
283going = false
284else
285c = get gfb i
286if eq c 10
287going = false
288else
289m = get glbn 0
290if lt m 4000
291put glb m c
292put glbn 0 add m 1
293end
294i = add i 1
295end
296end
297end
298end
299fn lbsp to void
300lbtext tsp
301end
302fn lbflush fd int to void
303lbtext tnl
304w = write fd glb 0 get glbn 0
305put glbn 0 0
306end
307
308note ---- files: rdfb reads the file named by gpb into gfb; returns its size, 16777217 when it does not
309note fit, 16777218 when it cannot be opened
310fn rdfb to ulong
311fd = fopen gpb 0 get gpbn 0 0 0
312if lt fd 0
313ret 16777218
314end
315n = ulong 0
316going = true
317while going
318r = read int fd gfb n sub 16777216 n
319if le r 0
320going = false
321else
322n = add n ulong r
323if eq n 16777216
324going = false
325end
326end
327end
328c = fclose int fd
329if eq n 16777216
330ret 16777217
331end
332ret n
333end
334fn hexd v ulong to uchar
335if lt v 10
336ret uchar add v 48
337end
338ret uchar add v 87
339end
340fn tohex to void
341for i ulong 32
342v = ulong get gdg i
343put ghx shl i 1 hexd shr v 4
344put ghx add shl i 1 1 hexd and v 15
345end
346end
347
348note ---- refusals and counts
349fn refuse why view uchar * ci ulong ai ulong to void
350lbtext tR
351lbtext why
352lbsp
353lbarg ci
354lbsp
355if gt ai 0
356lbarg ai
357end
358lbtext tnl
359n = get glbn 0
360w = write 2 glb 0 n
361w = write 1 glb 0 n
362put glbn 0 0
363put gcnt 3 add get gcnt 3 1
364end
365
366note ---- arm kind from its name: 1 omc, 2 gcc, 3 ng, 0 unknown
367fn armkind ai ulong to ulong
368r = argread ai gab 0 len gab
369if lt r 2
370ret 0
371end
372a0 = get gab 0
373a1 = get gab 1
374if and eq a0 110 eq a1 103
375ret 3
376end
377if lt r 3
378ret 0
379end
380a2 = get gab 2
381if and and eq a0 111 eq a1 109 eq a2 99
382ret 1
383end
384if and and eq a0 103 eq a1 99 eq a2 99
385ret 2
386end
387ret 0
388end
389note gfb[0..n) holds "GCC: (" somewhere: 1, else 0
390fn hasgcc n ulong to ulong
391if lt n 6
392ret 0
393end
394for i ulong sub n 5 bound 16777216
395if eq get gfb i 71
396if fbmat i tgcc
397ret 1
398end
399end
400end
401ret 0
402end
403fn u16at o ulong to ulong
404ret or ulong get gfb o shl ulong get gfb add o 1 8
405end
406note the binary in gfb[0..n) matches kind: 1 yes, 0 no
407fn kindok kind ulong n ulong to ulong
408if lt n 64
409ret 0
410end
411if ne get gfb 0 127
412ret 0
413end
414if ne get gfb 1 69
415ret 0
416end
417if ne get gfb 2 76
418ret 0
419end
420if ne get gfb 3 70
421ret 0
422end
423if ne u16at 18 183
424ret 0
425end
426g = hasgcc n
427if eq kind 2
428ret g
429end
430if eq g 1
431ret 0
432end
433if eq kind 3
434ret 1
435end
436note omc: entry 0x4000b0 (bytes 24..31) and no section table (e_shoff, bytes 40..47, zero)
437if ne u16at 24 176
438ret 0
439end
440if ne u16at 26 64
441ret 0
442end
443for i ulong 2
444if ne u16at add 28 shl i 1 0
445ret 0
446end
447end
448for i ulong 8
449if ne get gfb add 40 i 0
450ret 0
451end
452end
453ret 1
454end
455
456note ---- manifest: gmb holds DIR/manifest.sha256. mfind looks for the line whose path is
457note bin/ARM/CASE: 0 not listed, 1 listed with hash ghx, 2 listed with another hash
458fn mfind ai ulong ci ulong to ulong
459p = new uchar 1024 0
460put gpbn 0 0
461pbtext trbin
462pbarg ai
463pbtext tslash
464pbarg ci
465m = get gpbn 0
466for i ulong m
467put p i get gpb i
468end
469n = get gmbn 0
470s = ulong 0
471while lt s n bound 999999999
472e = s
473while and lt e n ne get gmb e 10 bound 999999999
474e = add e 1
475end
476if eq sub e s add 66 m
477if msame s m p
478ret mhash s
479end
480end
481s = add e 1
482end
483ret 0
484end
485fn msame s ulong m ulong p view uchar 1024 to bool
486for i ulong m
487if ne get gmb add add s 66 i get p i
488ret false
489end
490end
491ret true
492end
493fn mhash s ulong to ulong
494for i ulong 64
495if ne get gmb add s i get ghx i
496ret 2
497end
498end
499ret 1
500end
501fn mload to ulong
502pbdir
503pbtext tman
504n = rdfb
505if ge n 1048576
506ret 0
507end
508for i ulong n bound 1048576
509put gmb i get gfb i
510end
511put gmbn 0 n
512ret 1
513end
514
515note ---- identity of every (case, arm); pass 0 before timing, 1 after (hashes must be unchanged)
516fn ident pass ulong to void
517na = get gcfg 4
518for c ulong get gcfg 6
519ci = add get gcfg 5 c
520for a ulong na
521ai = add get gcfg 3 a
522slot = add shl c 4 a
523if eq pass 0
524identone ci ai slot
525else
526if eq get gpr slot 1
527recheck ci ai slot
528end
529end
530end
531end
532end
533fn recheck ci ulong ai ulong slot ulong to void
534pbbin ai ci
535n = hashpb
536k = mfind ai ci
537if or ne n get gsz slot ne k 1
538refuse trchg ci ai
539put gpr slot 0
540end
541end
542fn identone ci ulong ai ulong slot ulong to void
543put gpr slot 0
544pbbin ai ci
545n = hashpb
546if eq n 9223372036854775809
547refuse trlab ci ai
548ret
549end
550if ge n 9223372036854775808
551if ne mfind ai ci 0
552refuse trmis ci ai
553end
554rowcase tA ci ai
555lbtext tabs
556lbflush 1
557ret
558end
559k = mfind ai ci
560if eq k 0
561refuse trunl ci ai
562ret
563end
564if eq k 2
565refuse trman ci ai
566ret
567end
568pbbin ai ci
569nf = rdfb
570if gt nf 16777216
571refuse trlab ci ai
572ret
573end
574if ne kindok armkind ai nf 1
575refuse trlab ci ai
576ret
577end
578put gsz slot n
579put gpr slot 1
580rowcase tA ci ai
581lbsp
582lbhex
583lbsp
584lbnum n
585lbflush 1
586end
587fn rowcase t view uchar * ci ulong ai ulong to void
588lbtext t
589lbarg ci
590lbsp
591lbarg ai
592end
593note want hex and optional stdin of every case
594fn wants to void
595for c ulong get gcfg 6
596ci = add get gcfg 5 c
597pbdir
598pbtext twant
599pbarg ci
600pbtext tdsha
601n = rdfb
602bad = or lt n 64 gt n 16777216
603if not bad
604for i ulong 64
605v = get gfb i
606isd = and ge v 48 le v 57
607isl = and ge v 97 le v 102
608if not or isd isl
609bad = true
610end
611put gwx add shl c 6 i v
612end
613end
614if bad
615refuse trnow ci 0
616end
617pbdir
618pbtext tin
619pbarg ci
620n2 = hashpb
621if eq n2 9223372036854775809
622refuse trinp ci 0
623end
624if lt n2 9223372036854775808
625lbtext tI
626lbarg ci
627lbsp
628lbhex
629lbsp
630lbnum n2
631lbflush 1
632end
633end
634end
635
636note ---- one child: stdin DIR/in/CASE or /dev/null, stdout DIR/run.out, stderr DIR/run.err, exec gpk
637fn child ci ulong to void
638pbdir
639pbtext tin
640pbarg ci
641fi = fopen gpb 0 get gpbn 0 0 0
642if lt fi 0
643fi = fopen tnull 0 len tnull 0 0
644end
645if lt fi 0
646exit 122
647end
648r = dupfd int fi 0 0
649if ne r 0
650exit 123
651end
652pbdir
653pbtext trout
654fo = fopen gpb 0 get gpbn 0 577 420
655if lt fo 0
656exit 120
657end
658r = dupfd int fo 1 0
659if ne r 1
660exit 121
661end
662pbdir
663pbtext trerr
664fe = fopen gpb 0 get gpbn 0 577 420
665if lt fe 0
666exit 126
667end
668r = dupfd int fe 2 0
669if ne r 2
670exit 127
671end
672r = execprog gpk 0 get gpkn 0
673exit 124
674end
675fn runone ci ulong to ulong
676t0 = monons
677pid = fork
678if lt pid 0
679trap 9
680end
681if eq pid 0
682child ci
683exit 125
684end
685r = waitpid int pid gst 0 4 0
686t1 = monons
687if ne r pid
688trap 9
689end
690s0 = ulong get gst 0
691if ne and s0 127 0
692put gstat 0 add 1000 and s0 127
693else
694put gstat 0 ulong get gst 1
695end
696ret ulong sub t1 t0
697end
698note the n bytes of gfb must be 1 .. 19 digits and one LF; gcfg 7 is 1 when they are
699fn rtparse n ulong to ulong
700put gcfg 7 0
701if or lt n 2 gt n 20
702ret 0
703end
704if ne get gfb sub n 1 10
705ret 0
706end
707v = ulong 0
708for i ulong sub n 1
709c = get gfb i
710if or lt c 48 gt c 57
711ret 0
712end
713v = add mul v 10 ulong sub c 48
714end
715put gcfg 7 1
716ret v
717end
718note gcfg 8 wall ns, 9 status, 10 output ok, 11 in-process ns of the last run
719fn dotime b ulong c ulong ai ulong pos ulong to void
720ci = add get gcfg 5 c
721pkreset
722pbbin ai ci
723pkpush
724wall = runone ci
725put gcfg 8 wall
726put gcfg 9 get gstat 0
727ok = outok c
728put gcfg 10 ok
729pbdir
730pbtext trerr
731ne2 = rdfb
732rt = rtparse ne2
733put gcfg 11 rt
734trow b ci ai pos
735tcount ci ai
736end
737fn outok c ulong to ulong
738pbdir
739pbtext trout
740n = hashpb
741if ge n 9223372036854775808
742ret 0
743end
744for i ulong 64
745if ne get ghx i get gwx add shl c 6 i
746ret 0
747end
748end
749ret 1
750end
751fn trow b ulong ci ulong ai ulong pos ulong to void
752lbtext tT
753lbnum b
754lbsp
755if lt b get gcfg 1
756lbnum 1
757else
758lbnum 0
759end
760lbsp
761lbarg ci
762lbsp
763lbarg ai
764lbsp
765lbnum pos
766lbsp
767lbnum get gcfg 8
768lbsp
769lbnum get gcfg 9
770lbsp
771if ne get gcfg 9 0
772lbnum 0
773else
774lbnum get gcfg 10
775end
776lbsp
777lbnum get gcfg 11
778lbflush 1
779end
780fn tcount ci ulong ai ulong to void
781put gcnt 0 add get gcnt 0 1
782if ne get gcfg 9 0
783refuse trsta ci ai
784put gcnt 2 add get gcnt 2 1
785ret
786end
787if eq get gcfg 10 0
788refuse trout2 ci ai
789put gcnt 2 add get gcnt 2 1
790ret
791end
792put gcnt 1 add get gcnt 1 1
793end
794fn block b ulong to void
795lbtext tL
796lbnum b
797lbsp
798lbload
799lbflush 1
800na = get gcfg 4
801for c ulong get gcfg 6
802np = ulong 0
803for a ulong na
804if eq get gpr add shl c 4 a 1
805put gpl np add get gcfg 3 a
806np = add np 1
807end
808end
809if gt np 0
810for i ulong np
811put gord i get gpl rem add i b np
812end
813for i ulong np
814put gord add np i get gord sub sub np 1 i
815end
816sa = scanph b c 0
817put gsc 17 add get gsc 15 get gsc 16
818for p ulong shl np 1
819dotime b c get gord p p
820end
821se = scanph b c 1
822put gsc 18 add get gsc 15 get gsc 16
823krow b c sa se
824end
825end
826end
827
828note ---- v2 contamination scan (PREREG-contamination.md)
829fn pbnum v ulong to void
830d = new uchar 24 0
831p = ulong 24
832x = v
833while gt x 9
834p = sub p 1
835put d p uchar add rem x 10 48
836x = div x 10
837end
838p = sub p 1
839put d p uchar add x 48
840n = get gpbn 0
841if gt add n sub 24 p 2048
842trap 9
843end
844for i ulong sub 24 p
845put gpb add n i get d add p i
846end
847put gpbn 0 add n sub 24 p
848end
849note the timed core from Cpus_allowed_list (one number, else unpinned) and its cluster mask
850fn coreset to void
851put gsc 0 99999
852put gsc 1 0
853put gsc 2 ulong getpid
854pbclr
855pbtext tstat
856n = rdfb
857if gt n 16777216
858ret
859end
860m = len tcpus
861if lt n m
862ret
863end
864for i ulong sub n m bound 16777216
865if fbmat i tcpus
866v = cpuone fbskip add i m n n
867if lt v 64
868put gsc 0 v
869clusset v
870end
871ret
872end
873end
874end
875note the decimal at gfb[j ..] ended by LF; 99999 when anything else is there
876fn cpuone j0 ulong n ulong to ulong
877v = ulong 0
878k = ulong 0
879j = j0
880while lt j n bound 64
881c = get gfb j
882if eq c 10
883if eq k 0
884ret 99999
885end
886ret v
887end
888if or lt c 48 gt c 57
889ret 99999
890end
891v = add mul v 10 ulong sub c 48
892k = add k 1
893j = add j 1
894end
895ret 99999
896end
897fn clusset v ulong to void
898pbclr
899pbtext tsys1
900pbnum v
901pbtext tsys2
902n = rdfb
903if gt n 4096
904put gsc 1 shl ulong 1 v
905ret
906end
907put gsc 1 cpumask n
908end
909note a Linux cpu list (a-b,c,..) in gfb[0 .. n) as a mask of CPUs below 64
910fn cpumask n ulong to ulong
911m = ulong 0
912a = ulong 0
913lo = ulong 99999
914have = false
915for i ulong n
916c = get gfb i
917if and ge c 48 le c 57
918a = add mul a 10 ulong sub c 48
919have = true
920else
921if eq c 45
922lo = a
923a = 0
924else
925if have
926m = or m rng lo a
927end
928lo = 99999
929a = 0
930have = false
931end
932end
933end
934if have
935m = or m rng lo a
936end
937ret m
938end
939fn rng lo0 ulong hi ulong to ulong
940lo = lo0
941if eq lo 99999
942lo = hi
943end
944m = ulong 0
945k = lo
946while and le k hi lt k 64 bound 64
947m = or m shl ulong 1 k
948k = add k 1
949end
950ret m
951end
952note one scan; returns the foreign runnable tasks on the timed core (0 when unpinned: no rows)
953fn scanph b ulong c ulong ph ulong to ulong
954if eq get gsc 0 99999
955ret 0
956end
957put gsc 12 b
958put gsc 13 c
959put gsc 14 ph
960put gsc 3 0
961put gsc 4 0
962put gsc 5 0
963put gsc 6 0
964put gsc 7 0
965put gsc 15 0
966put gsc 16 0
967fd = fopen tproc 0 len tproc 0 0
968if lt fd 0
969put gsc 7 1
970yrow
971ret 0
972end
973going = true
974while going bound 1000000
975n = getdnts int fd gdn 0 65536
976if le n 0
977going = false
978else
979dnwalk ulong n
980end
981end
982r = fclose int fd
983yrow
984ret get gsc 3
985end
986note the getdents64 records of gdn[0 .. n): d_reclen at 16 (u16), d_name at 19, zero-terminated
987fn dnwalk n ulong to void
988o = ulong 0
989while lt o n bound 1000000
990rl = or ulong get gdn add o 16 shl ulong get gdn add o 17 8
991pid = dnum o
992if ne pid 18446744073709551615
993taskdir pid
994end
995if eq rl 0
996o = n
997else
998o = add o rl
999end
1000end
1001end
1002fn dnum o ulong to ulong
1003v = ulong 0
1004k = ulong 0
1005i = add o 19
1006while and lt i 65536 ne get gdn i 0 bound 300
1007c = get gdn i
1008if or lt c 48 gt c 57
1009ret 18446744073709551615
1010end
1011v = add mul v 10 ulong sub c 48
1012i = add i 1
1013k = add k 1
1014end
1015if eq k 0
1016ret 18446744073709551615
1017end
1018ret v
1019end
1020fn tnum o ulong to ulong
1021v = ulong 0
1022k = ulong 0
1023i = add o 19
1024while and lt i 65536 ne get gdt i 0 bound 300
1025c = get gdt i
1026if or lt c 48 gt c 57
1027ret 18446744073709551615
1028end
1029v = add mul v 10 ulong sub c 48
1030i = add i 1
1031k = add k 1
1032end
1033if eq k 0
1034ret 18446744073709551615
1035end
1036ret v
1037end
1038note /proc/PID/task: a process that exited since the /proc listing is skipped (a normal race)
1039fn taskdir pid ulong to void
1040pbclr
1041pbtext tproc
1042pbtext tslash
1043pbnum pid
1044pbtext ttask
1045fd = fopen gpb 0 get gpbn 0 0 0
1046if lt fd 0
1047ret
1048end
1049going = true
1050while going bound 1000000
1051n = getdnts int fd gdt 0 65536
1052if le n 0
1053going = false
1054else
1055tdwalk ulong n pid
1056end
1057end
1058r = fclose int fd
1059end
1060fn tdwalk n ulong pid ulong to void
1061o = ulong 0
1062while lt o n bound 1000000
1063rl = or ulong get gdt add o 16 shl ulong get gdt add o 17 8
1064tid = tnum o
1065if ne tid 18446744073709551615
1066taskone pid tid
1067end
1068if eq rl 0
1069o = n
1070else
1071o = add o rl
1072end
1073end
1074end
1075fn taskone pid ulong tid ulong to void
1076pbclr
1077pbtext tproc
1078pbtext tslash
1079pbnum pid
1080pbtext ttask
1081pbtext tslash
1082pbnum tid
1083pbtext tstat2
1084fd = fopen gpb 0 get gpbn 0 0 0
1085if lt fd 0
1086ret
1087end
1088n = read int fd gtb 0 1024
1089r = fclose int fd
1090if le n 0
1091ret
1092end
1093put gsc 4 add get gsc 4 1
1094if not tparse ulong n
1095put gsc 7 add get gsc 7 1
1096ret
1097end
1098taskdec pid tid
1099end
1100fn taskdec pid ulong tid ulong to void
1101if eq pid tid
1102if cpref tpollm
1103put gsc 15 add get gsc 15 1
1104end
1105if cpref tpswin
1106put gsc 16 add get gsc 16 1
1107end
1108end
1109cpu = get gsc 9
1110incl = false
1111if lt cpu 64
1112incl = eq and shr get gsc 1 cpu 1 1
1113end
1114if incl
1115put gsc 5 add get gsc 5 1
1116end
1117if eq pid get gsc 2
1118ret
1119end
1120st = get gsc 8
1121if eq cpu get gsc 0
1122if eq st 82
1123put gsc 3 add get gsc 3 1
1124end
1125xrow pid tid
1126ret
1127end
1128if and incl or eq st 82 eq st 68
1129xrow pid tid
1130end
1131end
1132note the COMM of the parsed task (gtb[gsc 10 .. gsc 11)) starts with t
1133fn cpref t view uchar * to bool
1134s = get gsc 10
1135e = get gsc 11
1136if lt sub e s len t
1137ret false
1138end
1139for k ulong len t
1140if ne get gtb add s k get t k
1141ret false
1142end
1143end
1144ret true
1145end
1146note gtb[0 .. n): PID (COMM) STATE ... ; COMM is up to the last ')'; field 39 (processor) is the 37th
1147note space-separated field from STATE
1148fn tparse n ulong to bool
1149p1 = n
1150p2 = n
1151for i ulong n
1152c = get gtb i
1153if and eq c 40 eq p1 n
1154p1 = i
1155end
1156if eq c 41
1157p2 = i
1158end
1159end
1160if or ge p1 n ge add p2 3 n
1161ret false
1162end
1163put gsc 10 add p1 1
1164put gsc 11 p2
1165put gsc 8 ulong get gtb add p2 2
1166ret tcpufld add p2 2 n
1167end
1168fn tcpufld j0 ulong n ulong to bool
1169j = j0
1170k = ulong 1
1171while and lt j n lt k 37 bound 2048
1172if eq get gtb j 32
1173k = add k 1
1174end
1175j = add j 1
1176end
1177if lt k 37
1178ret false
1179end
1180v = ulong 0
1181d = ulong 0
1182going = true
1183while and going lt j n bound 32
1184c = get gtb j
1185if and ge c 48 le c 57
1186v = add mul v 10 ulong sub c 48
1187d = add d 1
1188j = add j 1
1189else
1190going = false
1191end
1192end
1193if eq d 0
1194ret false
1195end
1196put gsc 9 v
1197ret true
1198end
1199note BLOCK CASE PH of the current scan (gsc 12, 13, 14)
1200fn lbbcp to void
1201lbnum get gsc 12
1202lbsp
1203lbarg add get gcfg 5 get gsc 13
1204lbsp
1205if eq get gsc 14 0
1206lbtext tphs
1207else
1208lbtext tphe
1209end
1210end
1211fn xrow pid ulong tid ulong to void
1212lbtext tX
1213lbbcp
1214lbsp
1215lbnum pid
1216lbsp
1217lbnum tid
1218lbsp
1219lbcomm
1220lbsp
1221lbnum get gsc 9
1222lbsp
1223m = get glbn 0
1224put glb m uchar get gsc 8
1225put glbn 0 add m 1
1226lbflush 1
1227put gsc 6 add get gsc 6 1
1228end
1229fn lbcomm to void
1230s = get gsc 10
1231e = get gsc 11
1232for i ulong sub e s
1233c = get gtb add s i
1234if or le c 32 ge c 127
1235c = 95
1236end
1237m = get glbn 0
1238if lt m 4000
1239put glb m c
1240put glbn 0 add m 1
1241end
1242end
1243end
1244fn yrow to void
1245lbtext tY
1246lbbcp
1247lbtext ttsk
1248lbnum get gsc 4
1249lbtext tclu
1250lbnum get gsc 5
1251lbtext txr
1252lbnum get gsc 6
1253lbtext tcfr
1254lbnum get gsc 3
1255lbtext terrs
1256lbnum get gsc 7
1257lbtext tollm
1258lbnum get gsc 15
1259lbtext tgpl
1260lbnum get gsc 16
1261lbflush 1
1262end
1263fn krow b ulong c ulong sa ulong se ulong to void
1264if eq get gsc 0 99999
1265ret
1266end
1267lbtext tK
1268lbnum b
1269lbsp
1270lbarg add get gcfg 5 c
1271lbtext tkst
1272lbnum sa
1273lbtext tken
1274lbnum se
1275lbtext tkc
1276if or gt sa 0 gt se 0
1277lbnum 1
1278else
1279lbnum 0
1280end
1281lbtext tkbz
1282if or gt get gsc 17 0 gt get gsc 18 0
1283lbnum 1
1284else
1285lbnum 0
1286end
1287lbflush 1
1288end
1289
1290note ---- /proc readers
1291fn lbload to void
1292pbclr
1293pbtext tload
1294n = rdfb
1295if gt n 16777216
1296ret
1297end
1298lbfb 0 n
1299end
1300fn lbcpus to void
1301pbclr
1302pbtext tstat
1303n = rdfb
1304if gt n 16777216
1305ret
1306end
1307m = len tcpus
1308if lt n m
1309ret
1310end
1311for i ulong sub n m bound 16777216
1312if fbmat i tcpus
1313j = fbskip add i m n
1314lbfb j n
1315ret
1316end
1317end
1318end
1319note gfb[i ..] starts with t (the caller keeps i + len t inside the buffer)
1320fn fbmat i ulong t view uchar * to bool
1321for k ulong len t
1322if ne get gfb add i k get t k
1323ret false
1324end
1325end
1326ret true
1327end
1328fn fbskip j0 ulong n ulong to ulong
1329j = j0
1330while lt j n
1331c = get gfb j
1332if and ne c 9 ne c 32
1333ret j
1334end
1335j = add j 1
1336end
1337ret j
1338end
1339
1340note ---- arguments
1341fn argnum idx ulong to ulong
1342r = argread idx gab 0 len gab
1343if or le r 0 gt r 18
1344exit 2
1345end
1346v = ulong 0
1347for i ulong ulong r
1348c = get gab i
1349if or lt c 48 gt c 57
1350exit 2
1351end
1352v = add mul v 10 ulong sub c 48
1353end
1354ret v
1355end
1356fn usage to void
1357w = write 2 tusage 0 len tusage
1358exit 2
1359end
1360fn isdd idx ulong to bool
1361r = argread idx gab 0 len gab
1362if ne r 2
1363ret false
1364end
1365ret and eq get gab 0 45 eq get gab 1 45
1366end
1367fn setup to void
1368ac = ulong argcnt
1369if lt ac 8
1370usage
1371end
1372put gcfg 0 argnum 2
1373put gcfg 1 argnum 3
1374if eq get gcfg 0 0
1375usage
1376end
1377if gt add get gcfg 0 get gcfg 1 100000
1378usage
1379end
1380put gcfg 2 4
1381put gcfg 3 5
1382k = ulong 5
1383fd = false
1384while and lt k ac not fd
1385if isdd k
1386fd = true
1387else
1388k = add k 1
1389end
1390end
1391if not fd
1392usage
1393end
1394na = sub k 5
1395if or eq na 0 gt na 16
1396usage
1397end
1398nc = sub ac add k 1
1399if or eq nc 0 gt nc 64
1400usage
1401end
1402put gcfg 4 na
1403put gcfg 5 add k 1
1404put gcfg 6 nc
1405for a ulong na
1406if eq armkind add 5 a 0
1407usage
1408end
1409end
1410end
1411fn summary to int
1412lbtext tE
1413lbload
1414lbflush 1
1415lbtext tS
1416lbnum get gcnt 0
1417lbtext tok
1418lbnum get gcnt 1
1419lbtext tfail
1420lbnum get gcnt 2
1421lbtext tref
1422lbnum get gcnt 3
1423lbflush 1
1424if or ne get gcnt 2 0 ne get gcnt 3 0
1425ret 1
1426end
1427if eq get gcnt 1 0
1428ret 1
1429end
1430ret 0
1431end
1432fn dosum to int
1433bad = int 0
1434for i ulong sub ulong argcnt 2
1435ai = add i 2
1436pbclr
1437pbarg ai
1438n = hashpb
1439if ge n 9223372036854775808
1440lbtext tnrd
1441lbarg ai
1442lbtext tnl
1443w = write 2 glb 0 get glbn 0
1444put glbn 0 0
1445bad = 1
1446else
1447lbhex
1448lbtext tsp2
1449lbarg ai
1450lbflush 1
1451end
1452end
1453ret bad
1454end
1455fn dorun to int
1456setup
1457lbtext tH
1458lbnum get gcfg 0
1459lbtext twarm
1460lbnum get gcfg 1
1461lbtext tcpu
1462lbcpus
1463coreset
1464lbtext tcore
1465if eq get gsc 0 99999
1466lbtext tunp
1467else
1468lbnum get gsc 0
1469end
1470lbtext tcm
1471lbnum get gsc 1
1472lbtext tld
1473lbload
1474lbflush 1
1475if eq mload 0
1476refuse trman get gcfg 2 0
1477ret summary
1478end
1479wants
1480ident 0
1481if ne get gcnt 3 0
1482ret summary
1483end
1484for b ulong add get gcfg 0 get gcfg 1
1485block b
1486end
1487ident 1
1488ret summary
1489end
1490fn main to int
1491if lt argcnt 3
1492usage
1493end
1494r = argread 1 gab 0 len gab
1495if eq r 3
1496if and and eq get gab 0 115 eq get gab 1 117 eq get gab 2 109
1497ret dosum
1498end
1499if and and eq get gab 0 114 eq get gab 1 117 eq get gab 2 110
1500ret dorun
1501end
1502end
1503usage
1504ret 2
1505end