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