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 / bench / omc_efficiency / conductor.om

860 lines · 14156 bytes Raw Blame History
1note OMC-EFF measurement conductor (bench/omc_efficiency/PROTOCOL.md, corrected by PROTOCOL-2.md). It runs
2note every arm of every case as its own process, in a seeded random arm order per case and round, times
3note each run with monons around fork .. waitpid, reads the program's own in-process runtime (one decimal
4note line on its stderr, OMC-EFF-2), checks every output byte against want/CASE.out, reads perf stat
5note counters, and writes one raw row per run on stdout. It computes no statistics.
6note
7note run mode: conductor run ROUNDS WARM SEED NCTL A ARM1 .. ARMA CASE ..
8note binary bin/ARM/CASE, expected output want/CASE.out; the last NCTL arms are negative
9note controls (their output must NOT match). Rows:
10note T round warm case arm pos wall_ns status ok runtime_ns
11note (ok is 1 only when status is 0, stdout equals want/CASE.out and stderr is exactly one
12note decimal line, whose value is runtime_ns; otherwise runtime_ns is what could be read, or 0)
13note P round warm case arm pos instructions cycles status ok (controls get no P row)
14note build mode: conductor build ROUNDS WARM SEED OMC A ARM1 .. ARMA CASE ..
15note arm omc: OMC < src/CASE.om > build.out; arm cOx: /usr/bin/gcc -B/usr/bin/ -Ox -static
16note -o build.out src/CASE.c. build.out must equal bin/ARM/CASE. Row:
17note B round warm case arm pos wall_ns status same
18note Last row: S rows=N ok=N fail=N ctl_detected=N ctl_missed=N. Exit 0 only when fail and ctl_missed
19note are 0 (and, with NCTL above 0, at least one control was detected); 1 otherwise; 2 for bad usage.
20om2
21text tbin "bin/"
22text tslash "/"
23text twant "want/"
24text tdotout ".out"
25text tsrc "src/"
26text tdotom ".om"
27text tdotc ".c"
28text trunout "run.out"
29text tbuild "build.out"
30text tchild "child.log"
31text ttime "time.out"
32text tperfc "perf.csv"
33text tperf "/usr/bin/perf"
34text tstat "stat"
35text tx "-x"
36text tcomma ","
37text te "-e"
38text tev "instructions:u,cycles:u"
39text tdo "-o"
40text tdd "--"
41text tgcc "/usr/bin/gcc"
42text tbdir "-B/usr/bin/"
43text tdash "-"
44text tstatic "-static"
45text tsp " "
46text tnl "\n"
47text tT "T "
48text tP "P "
49text tB "B "
50text tS "S rows="
51text tok " ok="
52text tfail " fail="
53text tdet " ctl_detected="
54text tmiss " ctl_missed="
55text tH "H omc-eff-1 conductor mode="
56text tseed " seed="
57text trounds " rounds="
58text twarm " warm="
59text tctr " counters="
60text ton "on"
61text toff "off"
62text tparan "/proc/sys/kernel/perf_event_paranoid"
63note pb: the path or argument being assembled; ip: the second path (stdin file or want file)
64global pb uchar 512
65global pbn ulong 1
66global ip uchar 512
67global ipn ulong 1
68global pk uchar 4096
69global pkn ulong 1
70global pkc ulong 1
71global lb uchar 1024
72global lbn ulong 1
73global ob uchar 1048576
74global wb uchar 1048576
75global ab uchar 256
76global st uchar 4
77global gst ulong 1
78global rng ulong 1
79global ord ulong 64
80global cfg ulong 16
81global cnt ulong 8
82note cfg: 0 mode (0 run, 1 build), 1 rounds, 2 warm, 3 nctl, 4 arm count, 5 first arm arg, 6 first case
83note arg, 7 case count, 8 omc arg index, 10 instructions, 11 cycles, 12 runtime line valid.
84note cnt: 0 rows, 1 ok, 2 fail, 3 detected, 4 missed
85
86fn pbclr to void
87put pbn 0 0
88end
89fn pbtext t view uchar * to void
90n = get pbn 0
91if gt add n len t 512
92trap 9
93end
94for i ulong len t
95put pb add n i get t i
96end
97put pbn 0 add n len t
98end
99fn pbarg idx ulong to void
100n = get pbn 0
101r = argread idx pb n sub 512 n
102if lt r 0
103trap 9
104end
105put pbn 0 add n ulong r
106end
107fn ipclr to void
108put ipn 0 0
109end
110fn iptext t view uchar * to void
111n = get ipn 0
112if gt add n len t 512
113trap 9
114end
115for i ulong len t
116put ip add n i get t i
117end
118put ipn 0 add n len t
119end
120fn iparg idx ulong to void
121n = get ipn 0
122r = argread idx ip n sub 512 n
123if lt r 0
124trap 9
125end
126put ipn 0 add n ulong r
127end
128
129note ---- exec packet: u16 count, then records (u16 length, bytes); pkpush adds pb as one record
130fn pkreset to void
131put pk 0 0
132put pk 1 0
133put pkn 0 2
134put pkc 0 0
135end
136fn pkpush to void
137n = get pkn 0
138m = get pbn 0
139if gt add add n m 2 4096
140trap 9
141end
142put pk n uchar and m 255
143put pk add n 1 uchar shr m 8
144for i ulong m
145put pk add add n 2 i get pb i
146end
147put pkn 0 add add n m 2
148c = add get pkc 0 1
149put pkc 0 c
150put pk 0 uchar and c 255
151put pk 1 uchar shr c 8
152end
153fn pkt t view uchar * to void
154pbclr
155pbtext t
156pkpush
157end
158
159note ---- the output line
160fn lbtext t view uchar * to void
161n = get lbn 0
162if gt add n len t 1024
163trap 9
164end
165for i ulong len t
166put lb add n i get t i
167end
168put lbn 0 add n len t
169end
170fn lbnum v ulong to void
171d = new uchar 24 0
172p = ulong 24
173x = v
174while gt x 9
175p = sub p 1
176put d p uchar add rem x 10 48
177x = div x 10
178end
179p = sub p 1
180put d p uchar add x 48
181n = get lbn 0
182for i ulong sub 24 p
183put lb add n i get d add p i
184end
185put lbn 0 add n sub 24 p
186end
187fn lbarg idx ulong to void
188n = get lbn 0
189r = argread idx lb n sub 1024 n
190if lt r 0
191trap 9
192end
193put lbn 0 add n ulong r
194end
195fn lbsp to void
196lbtext tsp
197end
198fn lbflush to void
199lbtext tnl
200w = write 1 lb 0 get lbn 0
201put lbn 0 0
202end
203
204note ---- numbers and the shuffle
205fn argnum idx ulong to ulong
206r = argread idx ab 0 len ab
207if le r 0
208exit 2
209end
210v = ulong 0
211for i ulong ulong r
212c = get ab i
213if or lt c 48 gt c 57
214exit 2
215end
216v = add mul v 10 ulong sub c 48
217end
218ret v
219end
220fn rnext to ulong
221x = get rng 0
222x = xor x shl x 13
223x = xor x shr x 7
224x = xor x shl x 17
225put rng 0 x
226ret x
227end
228fn shuffle na ulong to void
229for i ulong na
230put ord i i
231end
232for s ulong sub na 1
233i = sub sub na 1 s
234j = rem rnext add i 1
235t = get ord i
236put ord i get ord j
237put ord j t
238end
239end
240
241note ---- run one child: fork, redirect, exec pk; the parent times fork .. waitpid
242note how: 0 stdout to run.out, stderr to time.out; 1 stdin from ip, stdout to build.out; 2 stdout to child.log
243fn child how ulong to void
244fd = long -1
245if eq how 0
246fd = fopen trunout 0 len trunout 577 420
247else
248if eq how 1
249fd = fopen tbuild 0 len tbuild 577 420
250else
251fd = fopen tchild 0 len tchild 577 420
252end
253end
254if lt fd 0
255exit 120
256end
257r = dupfd int fd 1 0
258if ne r 1
259exit 121
260end
261if eq how 0
262fe = fopen ttime 0 len ttime 577 420
263if lt fe 0
264exit 126
265end
266r = dupfd int fe 2 0
267if ne r 2
268exit 127
269end
270end
271if eq how 1
272fi = fopen ip 0 get ipn 0 0 0
273if lt fi 0
274exit 122
275end
276r = dupfd int fi 0 0
277if ne r 0
278exit 123
279end
280end
281r = execprog pk 0 get pkn 0
282exit 124
283end
284fn runone how ulong to ulong
285t0 = monons
286pid = fork
287if lt pid 0
288trap 9
289end
290if eq pid 0
291child how
292exit 125
293end
294r = waitpid int pid st 0 4 0
295t1 = monons
296if ne r pid
297trap 9
298end
299s0 = ulong get st 0
300if ne and s0 127 0
301put gst 0 add 1000 and s0 127
302else
303put gst 0 ulong get st 1
304end
305ret ulong sub t1 t0
306end
307
308note ---- files into ob / wb; a file that fills the buffer is reported as 1048577 bytes (never equal)
309fn slurpob how ulong to ulong
310fd = long -1
311if eq how 0
312fd = fopen trunout 0 len trunout 0 0
313else
314if eq how 1
315fd = fopen tbuild 0 len tbuild 0 0
316else
317if eq how 2
318fd = fopen tperfc 0 len tperfc 0 0
319else
320fd = fopen ttime 0 len ttime 0 0
321end
322end
323end
324if lt fd 0
325ret 1048578
326end
327n = ulong 0
328going = true
329while going
330r = read int fd ob n sub 1048576 n
331if le r 0
332going = false
333else
334n = add n ulong r
335if eq n 1048576
336going = false
337end
338end
339end
340c = fclose int fd
341if eq n 1048576
342ret 1048577
343end
344ret n
345end
346fn slurpwb to ulong
347fd = fopen ip 0 get ipn 0 0 0
348if lt fd 0
349ret 1048579
350end
351n = ulong 0
352going = true
353while going
354r = read int fd wb n sub 1048576 n
355if le r 0
356going = false
357else
358n = add n ulong r
359if eq n 1048576
360going = false
361end
362end
363end
364c = fclose int fd
365if eq n 1048576
366ret 1048580
367end
368ret n
369end
370fn same no ulong nw ulong to ulong
371if ne no nw
372ret 0
373end
374for i ulong no
375if ne get ob i get wb i
376ret 0
377end
378end
379ret 1
380end
381
382note ---- perf stat -x , lines: value,unit,event,... ; sum values whose event's first byte after '/'
383note is 'i' (instructions) or 'c' (cycles); lines that do not start with a digit are skipped
384fn pnum st0 ulong n ulong to ulong
385v = ulong 0
386i = st0
387going = true
388while going
389if ge i n
390going = false
391else
392c = get ob i
393if or lt c 48 gt c 57
394going = false
395else
396v = add mul v 10 ulong sub c 48
397i = add i 1
398end
399end
400end
401ret v
402end
403fn pkind st0 ulong n ulong to ulong
404note returns 1 instructions, 2 cycles, 0 other: third field, byte after its first '/'
405i = st0
406commas = ulong 0
407k = ulong 0
408going = true
409while going
410if ge i n
411going = false
412else
413c = get ob i
414if eq c 10
415going = false
416else
417if eq c 44
418commas = add commas 1
419else
420if and eq commas 2 eq c 47
421if eq k 0
422k = add i 1
423end
424end
425end
426i = add i 1
427end
428end
429end
430if or eq k 0 ge k n
431ret 0
432end
433c = get ob k
434if eq c 105
435ret 1
436end
437if eq c 99
438ret 2
439end
440ret 0
441end
442fn perfrd n ulong to void
443put cfg 10 0
444put cfg 11 0
445i = ulong 0
446while lt i n
447c = get ob i
448if and ge c 48 le c 57
449v = pnum i n
450k = pkind i n
451if eq k 1
452put cfg 10 add get cfg 10 v
453end
454if eq k 2
455put cfg 11 add get cfg 11 v
456end
457end
458going = true
459while and going lt i n
460if eq get ob i 10
461going = false
462end
463i = add i 1
464end
465end
466end
467
468note ---- packets for one (arm, case)
469fn binpath ai ulong ci ulong to void
470pbclr
471pbtext tbin
472pbarg ai
473pbtext tslash
474pbarg ci
475end
476fn pkrun ai ulong ci ulong perf ulong to void
477pkreset
478if eq perf 1
479pkt tperf
480pkt tstat
481pkt tx
482pkt tcomma
483pkt te
484pkt tev
485pkt tdo
486pkt tperfc
487pkt tdd
488end
489binpath ai ci
490pkpush
491end
492fn pkomc ci ulong to void
493pkreset
494pbclr
495pbarg get cfg 8
496pkpush
497ipclr
498iptext tsrc
499iparg ci
500iptext tdotom
501end
502fn pkgcc ai ulong ci ulong to void
503pkreset
504pkt tgcc
505pkt tbdir
506r = argread ai ab 0 len ab
507if lt r 2
508exit 2
509end
510pbclr
511pbtext tdash
512n = ulong r
513for i ulong sub n 1
514put pb add 1 i get ab add i 1
515end
516put pbn 0 n
517pkpush
518pkt tstatic
519pkt tdo
520pkt tbuild
521pbclr
522pbtext tsrc
523pbarg ci
524pbtext tdotc
525pkpush
526end
527
528note ---- rows
529fn rowhead tag ulong r ulong ci ulong ai ulong pos ulong to void
530if eq tag 0
531lbtext tT
532else
533if eq tag 1
534lbtext tP
535else
536lbtext tB
537end
538end
539w = get cfg 2
540lbnum r
541lbsp
542if lt r w
543lbnum 1
544else
545lbnum 0
546end
547lbsp
548lbarg ci
549lbsp
550lbarg ai
551lbsp
552lbnum pos
553lbsp
554end
555note ok: the run is valid and its output matches; ex: the run is valid (status 0 and, for timed runs, one
556note runtime line). A control is detected only by a valid run whose output differs; a control that does not
557note run validly is a failed run, never a detection.
558fn tally ok ulong ctl ulong ex ulong to void
559put cnt 0 add get cnt 0 1
560if eq ex 0
561put cnt 2 add get cnt 2 1
562ret
563end
564if eq ctl 1
565if eq ok 1
566put cnt 4 add get cnt 4 1
567else
568put cnt 3 add get cnt 3 1
569end
570else
571if eq ok 1
572put cnt 1 add get cnt 1 1
573else
574put cnt 2 add get cnt 2 1
575end
576end
577end
578
579note ---- rtparse: the n bytes of time.out in ob must be 1 .. 19 digits and one LF; cfg 12 is 1 when
580note they are, and the value is returned (0 and cfg 12 = 0 otherwise)
581fn rtparse n ulong to ulong
582put cfg 12 0
583if or lt n 2 gt n 20
584ret 0
585end
586if ne get ob sub n 1 10
587ret 0
588end
589v = ulong 0
590for i ulong sub n 1
591c = get ob i
592if or lt c 48 gt c 57
593ret 0
594end
595v = add mul v 10 ulong sub c 48
596end
597put cfg 12 1
598ret v
599end
600
601note ---- one timed run and one counted run of arm slot p
602fn dotime r ulong ci ulong p ulong nw ulong to void
603ax = get ord p
604ai = add get cfg 5 ax
605ctl = ulong 0
606if ge ax sub get cfg 4 get cfg 3
607ctl = 1
608end
609pkrun ai ci 0
610wall = runone 0
611sc = get gst 0
612no = slurpob 0
613ok = same no nw
614ex = ulong 1
615if ne sc 0
616ex = 0
617end
618nt = slurpob 3
619rt = rtparse nt
620if eq get cfg 12 0
621ex = 0
622end
623if eq ex 0
624ok = 0
625end
626rowhead 0 r ci ai p
627lbnum wall
628lbsp
629lbnum sc
630lbsp
631lbnum ok
632lbsp
633lbnum rt
634lbflush
635tally ok ctl ex
636end
637fn docount r ulong ci ulong p ulong nw ulong to void
638ax = get ord p
639if lt ax sub get cfg 4 get cfg 3
640ai = add get cfg 5 ax
641pkrun ai ci 1
642wall = runone 0
643sc = get gst 0
644no = slurpob 0
645ok = same no nw
646ex = ulong 1
647if ne sc 0
648ex = 0
649ok = 0
650end
651np = slurpob 2
652if lt np 1048576
653perfrd np
654else
655put cfg 10 0
656put cfg 11 0
657ok = 0
658ex = 0
659end
660rowhead 1 r ci ai p
661lbnum get cfg 10
662lbsp
663lbnum get cfg 11
664lbsp
665lbnum sc
666lbsp
667lbnum ok
668lbflush
669tally ok 0 ex
670end
671end
672fn dobuild r ulong ci ulong p ulong to void
673ax = get ord p
674ai = add get cfg 5 ax
675r2 = argread ai ab 0 len ab
676if le r2 0
677exit 2
678end
679how = ulong 2
680if eq get ab 0 111
681pkomc ci
682how = 1
683else
684pkgcc ai ci
685end
686wall = runone how
687sc = get gst 0
688no = slurpob 1
689ipclr
690iptext tbin
691iparg ai
692iptext tslash
693iparg ci
694nw = slurpwb
695ok = same no nw
696if ne sc 0
697ok = 0
698end
699rowhead 2 r ci ai p
700lbnum wall
701lbsp
702lbnum sc
703lbsp
704lbnum ok
705lbflush
706tally ok 0 1
707end
708
709fn wantload ci ulong to ulong
710ipclr
711iptext twant
712iparg ci
713iptext tdotout
714ret slurpwb
715end
716fn oneround r ulong to void
717na = get cfg 4
718for c ulong get cfg 7
719ci = add get cfg 6 c
720shuffle na
721if eq get cfg 0 0
722nw = wantload ci
723for p ulong na
724dotime r ci p nw
725end
726if eq get cfg 13 1
727for p ulong na
728docount r ci p nw
729end
730end
731else
732for p ulong na
733dobuild r ci p
734end
735end
736end
737end
738
739fn setup to void
740if lt argcnt 8
741exit 2
742end
743r = argread 1 ab 0 len ab
744if lt r 1
745exit 2
746end
747if eq get ab 0 98
748put cfg 0 1
749else
750if ne get ab 0 114
751exit 2
752end
753put cfg 0 0
754end
755put cfg 1 argnum 2
756put cfg 2 argnum 3
757s = argnum 4
758if eq s 0
759exit 2
760end
761put rng 0 s
762if eq get cfg 0 0
763put cfg 3 argnum 5
764else
765put cfg 3 0
766put cfg 8 5
767end
768na = argnum 6
769if or eq na 0 gt na 64
770exit 2
771end
772put cfg 4 na
773put cfg 5 7
774put cfg 6 add 7 na
775ac = ulong argcnt
776if le ac add 7 na
777exit 2
778end
779put cfg 7 sub ac add 7 na
780if ge get cfg 3 na
781exit 2
782end
783put cfg 13 perfok
784end
785note ---- perfok: 1 when /proc/sys/kernel/perf_event_paranoid is at most 2, so an unprivileged perf stat can
786note read user-space instructions and cycles; 0 otherwise (then no P rows are written and H says counters=off)
787fn perfok to ulong
788b = new uchar 32 0
789fd = fopen tparan 0 len tparan 0 0
790if lt fd 0
791ret 0
792end
793n = read int fd b 0 32
794c = fclose int fd
795if lt n 2
796ret 0
797end
798if eq get b 0 45
799ret 1
800end
801v = get b 0
802if and ge v 48 le v 50
803if eq get b 1 10
804ret 1
805end
806end
807ret 0
808end
809fn header to void
810lbtext tH
811if eq get cfg 0 0
812lbarg 1
813else
814lbarg 1
815end
816lbtext tseed
817lbarg 4
818lbtext trounds
819lbnum get cfg 1
820lbtext twarm
821lbnum get cfg 2
822lbtext tctr
823if eq get cfg 13 1
824lbtext ton
825else
826lbtext toff
827end
828lbflush
829end
830fn summary to int
831lbtext tS
832lbnum get cnt 0
833lbtext tok
834lbnum get cnt 1
835lbtext tfail
836lbnum get cnt 2
837lbtext tdet
838lbnum get cnt 3
839lbtext tmiss
840lbnum get cnt 4
841lbflush
842if or ne get cnt 2 0 ne get cnt 4 0
843ret 1
844end
845if and gt get cfg 3 0 eq get cnt 3 0
846ret 1
847end
848if eq get cnt 1 0
849ret 1
850end
851ret 0
852end
853fn main to int
854setup
855header
856for r ulong add get cfg 2 get cfg 1
857oneround r
858end
859ret summary
860end