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/seed/node/bench-test.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 / seed / node / bench-test.om` 595 lines ยท 12000 bytes Raw Blame History 1 note Omega Node scheduling comparison (DRA-399). Concatenate after 2 note transport.om, pool.om, super.om and sched.om. Runs pinned workloads 3 note under arm 0 (FIFO), 1 (fair fitting), 2 (goal-aware, declared estimates 4 note within a factor of 2 of the duration) and 3 (goal-aware given the true 5 note durations: ORACLE, an upper bound, not a policy result) with real 6 note forked workers that sleep for the milliseconds in the low four decimal 7 note digits of their job id, on the host's wall clock. Usage: bench-gate 8 note (five repetitions of every scenario and arm). Prints one line per run: 9 note bench S P R mk_us idle_us dsp_ns dsp_n ev cand maint vread rework res cont ok hwm_kb : waits_us... 10 note S scenario 1..6 (blocked head, long chain, fan-out, sustained arrivals, 11 note queue pressure, worker failure), P arm (0..3), R repetition; mk makespan 12 note (first admission to last review); idle the integral of min(idle live 13 note workers, ready jobs that fit the free capacity) over time, in 14 note worker-microseconds; dsp time inside sched_dispatch from the creator 15 note loop and its calls; ev, cand, maint, vread the scheduler's counters 16 note (events, candidate reads, maintenance reads, value reads); rework the 17 note jobs that went back to ready after starting; res the reservations made 18 note (sched_stat 6); cont the new reservations seen while another ready job 19 note was also at the bypass budget (where check 71 can tell oldest from any); 20 note ok the jobs reviewed with 21 note the expected outcome; hwm_kb the creator's VmHWM; waits from ready to 22 note started, per job, in microseconds (sampled after every creator step 23 note and every publication). Every policy sees the same jobs, requests, 24 note durations, declarations, workers and capacities. Checked in every run: 25 note the capacity invariant (exit 70), a new reservation goes to the oldest 26 note ready job at the bypass budget (71), every job is reviewed once with 27 note its expected outcome before the deadline (72), setup (73..79). 28 text bnok "PASS node bench\n" 29 text bnhd "bench " 30 text bnsp " " 31 text bnco " :" 32 text bnnl "\n" 33 text bnst "/proc/self/status" 34 text bnhw "VmHWM:" 35 global bnc long 1 36 note Run metrics: 0 t0, 1 last review, 2 idle sum ns, 3 last sample, 4 37 note dispatch ns, 5 dispatch calls, 6 reviewed, 7 verified, 8 reworks, 9 38 note jobs in the scenario, 10 next queue entry, 11 killed, 12 reservation 39 note last seen + 1, 13 idle-eligible workers at the last sample, 14 policy, 40 note 15 bypass budget, 16 contested reservations. 41 global bnm ulong 20 42 note Per slot: ready since (ns, 0 not ready), started flag. 43 global bnr ulong 64 44 global bns ulong 64 45 note Waits of this run (us) and their count. 46 global bnwt ulong 256 47 global bnwn ulong 1 48 note Scenario queue: id, deps, request, flags, arrival ms, topics published. 49 global bnqi ulong 64 50 global bnqd ulong 64 51 global bnqr ulong 64 52 global bnqf ulong 64 53 global bnqt ulong 64 54 global bnqp ulong 64 55 global bnqn ulong 1 56 note 1: arm 3, policy 2 given the true durations as estimates (ORACLE). 57 global bne ulong 1 58 59 fn bn_ok ok bool code int to void 60 if not ok 61 exit code 62 end 63 end 64 65 fn bn_num v ulong to void 66 d = new uchar 20 0 67 x = v 68 k = ulong 20 69 for i ulong 20 70 k = sub k 1 71 put d k uchar add rem x 10 48 72 x = div x 10 73 if eq x 0 74 break 75 end 76 end 77 r = write 1 d k sub 20 k 78 end 79 80 fn bn_sp v ulong to void 81 r = write 1 bnsp 0 1 82 bn_num v 83 end 84 85 fn bn_req cpu ulong to ulong 86 ret cpu 87 end 88 89 fn bn_run c long w ulong q ulong to int 90 buf = new uchar 4096 0 91 id = sc_cell w 8 92 dl = add ulong monons mul rem id 10000 `1000000` 93 for t ulong `1000000` 94 now = ulong monons 95 if ge now dl 96 break 97 end 98 r = sched_wwait c w long sub dl now 99 if eq r 2 100 ret 2 101 end 102 if eq r 3 103 ret 3 104 end 105 if lt r 0 106 ret 4 107 end 108 end 109 if ne sched_wdone w q add id 1 buf 8 0 110 ret 5 111 end 112 ret 0 113 end 114 115 fn bn_worker w ulong to int 116 c = get bnc 0 117 for it ulong `1000000000` 118 q = sched_wjob w 119 if gt q 0 120 r = bn_run c w q 121 if eq r 2 122 ret 0 123 end 124 if ne r 0 125 ret add 60 r 126 end 127 continue 128 end 129 r = sched_wwait c w neg long 1 130 if eq r 2 131 ret 0 132 end 133 if eq r 3 134 ret 41 135 end 136 if lt r 0 137 ret 43 138 end 139 end 140 ret 45 141 end 142 143 note Queue entry: job id (duration in its low four digits), deps, CPU, 144 note flags, arrival ms after the start, topics its completion publishes. 145 fn bn_q id ulong deps ulong cpu ulong fl ulong at ulong pro ulong to void 146 n = get bnqn 0 147 put bnqi n id 148 put bnqd n deps 149 put bnqr n cpu 150 put bnqf n fl 151 put bnqt n at 152 put bnqp n pro 153 put bnqn 0 add n 1 154 end 155 156 note Declared work estimate of job id in ms. Policy 2 is not told the 157 note duration: the estimate is the duration times 1/2, 1, 3/2 or 2, chosen 158 note by a multiplicative hash of the id (fixed, so every run and repetition 159 note declares the same values). Arm 3 (ORACLE) declares the true duration. 160 fn bn_est id ulong to ulong 161 d = rem id 10000 162 if ne get bne 0 0 163 ret d 164 end 165 k = rem div mul id `2654435761` 65536 4 166 ret div mul d add k 1 2 167 end 168 169 note Scenario s into the queue; returns (workers, admission limit). 170 fn bn_load s ulong to ulong 171 put bnqn 0 0 172 if eq s 1 173 bn_q 10600 0 2 0 0 0 174 bn_q 20300 0 4 0 0 0 175 for i ulong 6 176 bn_q add 30200 mul i 10000 0 1 0 0 0 177 end 178 ret 64 179 end 180 if eq s 2 181 for i ulong 8 182 bn_q add 100300 mul i 10000 0 1 0 0 0 183 end 184 bn_q 200150 0 1 0 0 2 185 for i ulong 5 186 bn_q add 210150 mul i 10000 shl ulong 2 i 1 0 0 shl ulong 4 i 187 end 188 ret 64 189 end 190 if eq s 3 191 for i ulong 6 192 bn_q add 300300 mul i 10000 0 1 0 0 0 193 end 194 bn_q 400100 0 1 0 0 1024 195 for i ulong 6 196 bn_q add 410200 mul i 10000 1024 1 0 0 0 197 end 198 ret 64 199 end 200 if eq s 4 201 bn_s4 202 ret 64 203 end 204 if eq s 5 205 bn_s5 206 ret 8 207 end 208 bn_s6 209 ret 64 210 end 211 212 note Sustained arrivals: 24 jobs of 100..400 ms needing 1..3 CPU, four 213 note every 150 ms. 214 fn bn_s4 to void 215 for i ulong 24 216 d = add 100 mul rem mul i 7 4 100 217 id = add add 500000 mul i 10000 d 218 at = mul div i 4 150 219 bn_q id 0 add 1 rem i 3 0 at 0 220 end 221 end 222 223 note Queue pressure: 30 jobs of 100..300 ms needing 1..2 CPU offered at 224 note once against an admission limit of 8. 225 fn bn_s5 to void 226 for i ulong 30 227 d = add 100 mul rem mul i 5 3 100 228 id = add add 600000 mul i 10000 d 229 bn_q id 0 add 1 rem i 2 0 0 0 230 end 231 end 232 233 note Worker failure: 12 rerunnable jobs of 150..450 ms needing 1..3 CPU; 234 note worker 0 is killed 250 ms in while busy. 235 fn bn_s6 to void 236 for i ulong 12 237 d = add 150 mul rem mul i 7 4 100 238 id = add add 700000 mul i 10000 d 239 bn_q id 0 add 1 rem i 3 1 0 0 240 end 241 end 242 243 note Admit the queue entries that have arrived, in order; a refusal for 244 note room (-2, a ticket) stops until the next call. 245 fn bn_admit now ulong to void 246 for k ulong 64 247 i = get bnm 10 248 if ge i get bnqn 0 249 ret 250 end 251 if lt sub now get bnm 0 mul get bnqt i `1000000` 252 ret 253 end 254 j = sched_admitr get bnqi i get bnqd i get bnqf i bn_req get bnqr i 255 if eq j neg long 2 256 ret 257 end 258 bn_ok ge j 0 74 259 e = bn_est get bnqi i 260 r = sched_goal ulong j get bnqp i e e 261 put bnm 10 add i 1 262 end 263 end 264 265 note Topics job id publishes on completion. 266 fn bn_pro id ulong to ulong 267 for i ulong get bnqn 0 bound 64 268 if eq get bnqi i id 269 ret get bnqp i 270 end 271 end 272 ret 0 273 end 274 275 fn bn_inv to void 276 for k ulong 4 277 s = ulong 0 278 for j ulong 64 279 if eq get sjheld j 1 280 s = add s sp_need get sjneed j k 281 end 282 end 283 bn_ok eq get suse k s 70 284 bn_ok le get suse k get scap k 70 285 end 286 end 287 288 note A reservation that appeared since the last sample goes to the oldest 289 note ready job at the bypass budget: no older ready job is at the budget. 290 note Another ready job at the budget makes it contested (bnm 16). 291 fn bn_fair to void 292 r = sched_stat 29 293 if or eq r 0 eq r get bnm 12 294 put bnm 12 r 295 ret 296 end 297 put bnm 12 r 298 a = get sjarr sub r 1 299 n = ulong 0 300 for j ulong 64 301 if and eq get sjst j 2 ne j sub r 1 302 if ge get sjbyp j get bnm 15 303 n = add n 1 304 end 305 if lt get sjarr j a 306 bn_ok lt get sjbyp j get bnm 15 71 307 end 308 end 309 end 310 if gt n 0 311 put bnm 16 add get bnm 16 1 312 end 313 end 314 315 note Sample after a creator step or publication: waits, reworks, the idle 316 note eligible integral, the invariants. 317 fn bn_sample to void 318 now = ulong monons 319 put bnm 2 add get bnm 2 mul get bnm 13 sub now get bnm 3 320 put bnm 3 now 321 nf = ulong 0 322 for j ulong 64 323 s = get sjst j 324 if eq s 2 325 if ne get bns j 0 326 put bns j 0 327 put bnm 8 add get bnm 8 1 328 end 329 if eq get bnr j 0 330 put bnr j now 331 end 332 if sp_fits get sjneed j 0 333 nf = add nf 1 334 end 335 end 336 if and ge s 3 ne get bnr j 0 337 bn_wait sub now get bnr j 338 put bnr j 0 339 put bns j 1 340 end 341 end 342 put bnm 13 bn_min nf bn_idle 343 bn_inv 344 if ge get bnm 14 1 345 bn_fair 346 end 347 end 348 349 fn bn_wait ns ulong to void 350 n = get bnwn 0 351 if lt n 256 352 put bnwt n div ns 1000 353 put bnwn 0 add n 1 354 end 355 end 356 357 fn bn_min a ulong b ulong to ulong 358 if lt a b 359 ret a 360 end 361 ret b 362 end 363 364 fn bn_idle to ulong 365 c = get bnc 0 366 n = mapget c 48 8 367 k = ulong 0 368 for w ulong n bound 64 369 if and gt get swpid w 0 eq get scbusy w 0 370 k = add k 1 371 end 372 end 373 ret k 374 end 375 376 note sched_step with the dispatch timed. 377 fn bn_step c long to void 378 d = sup_poll c `1000000` 379 bn_ok ge d 0 75 380 n = mapget c 48 8 381 for w ulong n bound 64 382 if gt get swpid w 0 383 r = sup_take get swack w 384 else 385 r = sched_lost c w 386 end 387 end 388 k = sched_collect c 389 t = ulong monons 390 k = sched_dispatch c 391 put bnm 4 add get bnm 4 sub ulong monons t 392 put bnm 5 add get bnm 5 1 393 end 394 395 note Review finished jobs (outcome id + 1 is verified work); publish what 396 note each declared. 397 fn bn_review c long to void 398 buf = new uchar 4096 0 399 for j ulong 64 400 if eq get sjst j 4 401 id = get sjid j 402 o = sched_review j 403 if eq o long add id 1 404 put bnm 7 add get bnm 7 1 405 end 406 put bnm 6 add get bnm 6 1 407 put bnm 1 ulong monons 408 put bns j 0 409 put bnr j 0 410 p = bn_pro id 411 if ne p 0 412 v = sched_publish c p buf 8 413 bn_ok gt v 0 76 414 bn_sample 415 end 416 end 417 end 418 end 419 420 fn bn_hwm to ulong 421 b = new uchar 4096 0 422 fd = fopen bnst 0 len bnst 0 0 423 if lt fd 0 424 ret 0 425 end 426 r = pread int fd b 0 4096 long 0 427 x = fclose int fd 428 if le r 0 429 ret 0 430 end 431 n = ulong r 432 h = len bnhw 433 for i ulong 4000 434 if gt add i h n 435 ret 0 436 end 437 m = true 438 for k ulong h bound 8 439 if ne get b add i k get bnhw k 440 m = false 441 end 442 end 443 if m 444 ret bn_digits b add i h n 445 end 446 end 447 ret 0 448 end 449 450 fn bn_digits b view uchar 4096 i ulong n ulong to ulong 451 v = ulong 0 452 for k ulong 32 453 p = add i k 454 if ge p n 455 ret v 456 end 457 ch = get b p 458 if and ge ch 48 le ch 57 459 v = add mul v 10 sub ulong ch 48 460 else 461 if gt v 0 462 ret v 463 end 464 end 465 end 466 ret v 467 end 468 469 fn bn_reset pol ulong by ulong to void 470 for i ulong 20 471 put bnm i 0 472 end 473 for j ulong 64 474 put bnr j 0 475 put bns j 0 476 end 477 put bnwn 0 0 478 put bnm 14 pol 479 put bnm 15 by 480 end 481 482 note One run of scenario s under arm a (policy 0, 1, 2; arm 3 is policy 2 483 note with ORACLE estimates); prints its line. 484 fn bn_one s ulong a ulong rep ulong to void 485 pol = a 486 put bne 0 0 487 if eq a 3 488 pol = 2 489 put bne 0 1 490 end 491 lim = bn_load s 492 c = pool_new 4 2 493 bn_ok gt c 0 73 494 put bnc 0 c 495 bn_ok eq sup_init c 0 73 496 bn_ok eq sched_new c lim 64 0 73 497 bn_ok eq sched_cap bn_req 4 0 73 498 bn_ok eq sched_policy pol 64 64 4 1000 0 73 499 bn_reset a 4 500 put bnm 9 get bnqn 0 501 for w ulong 2 502 p = sup_spawn c w 503 if eq p 0 504 exit bn_worker w 505 end 506 bn_ok gt p 0 73 507 end 508 k = sched_pause c true 509 put bnm 0 ulong monons 510 put bnm 3 get bnm 0 511 bn_admit get bnm 0 512 bn_sample 513 k = sched_pause c false 514 bn_loop c s 515 bn_ok eq get bnm 6 get bnm 9 72 516 bn_ok eq get bnm 7 get bnm 9 72 517 bn_print s a rep 518 bn_ok ge sched_stop c `2000000000` 0 77 519 sup_closeall 520 bn_ok eq sched_free 0 77 521 bn_ok eq pool_free c 0 77 522 end 523 524 fn bn_loop c long s ulong to void 525 dl = add ulong monons `20000000000` 526 for t ulong `100000000` 527 bn_sample 528 if ge get bnm 6 get bnm 9 529 ret 530 end 531 bn_ok lt ulong monons dl 72 532 if and eq s 6 eq get bnm 11 0 533 if ge sub ulong monons get bnm 0 `250000000` 534 bn_kill c 535 end 536 end 537 bn_admit ulong monons 538 bn_step c 539 bn_sample 540 bn_review c 541 end 542 end 543 544 note Scenario 6: SIGKILL the busy worker 0 once. 545 fn bn_kill c long to void 546 if eq get scbusy 0 0 547 ret 548 end 549 r = killpid int get swpid 0 9 550 put bnm 11 1 551 end 552 553 fn bn_print s ulong pol ulong rep ulong to void 554 r = write 1 bnhd 0 len bnhd 555 bn_num s 556 bn_sp pol 557 bn_sp rep 558 bn_sp div sub get bnm 1 get bnm 0 1000 559 bn_sp div get bnm 2 1000 560 bn_sp get bnm 4 561 bn_sp get bnm 5 562 bn_sp sched_stat 2 563 bn_sp sched_stat 3 564 bn_sp sched_stat 13 565 bn_sp sched_stat 38 566 bn_sp get bnm 8 567 bn_sp sched_stat 6 568 bn_sp get bnm 16 569 bn_sp get bnm 7 570 bn_sp bn_hwm 571 r = write 1 bnco 0 len bnco 572 for i ulong get bnwn 0 bound 256 573 bn_sp get bnwt i 574 end 575 r = write 1 bnnl 0 1 576 end 577 578 fn bn_reps to ulong 579 ret 5 580 end 581 582 fn main to int 583 n = bn_reps 584 for rep ulong n bound 100 585 for s ulong 6 586 for pol ulong 4 587 bn_one add s 1 pol rep 588 end 589 end 590 end 591 if ne write 1 bnok 0 len bnok long len bnok 592 ret 100 593 end 594 ret 0 595 end