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