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/sched-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 / sched-test.om` 542 lines ยท 11666 bytes Raw Blame History 1 note Concatenate after transport.om, pool.om, super.om and sched.om. CPU-only 2 note acceptance of DRA-287 with real forked workers: irrelevant changes, 3 note coalesced hints, no lost wake-up, no barrier behind a slow worker, full 4 note admission and review queues, dead workers, stop under load, idle CPU and 5 note wake latency. No GPU, model or network. 6 text sok "PASS node sched\n" 7 text sidle "idle ticks workers=" 8 text screat " creator=" 9 text swake " wake rounds=" 10 text smean " mean_us=" 11 text smax " max_us=" 12 text snl "\n" 13 text sproc "/proc/" 14 text sstat "/stat" 15 global stc long 1 16 global stm long 1 17 18 fn st_ok ok bool code int to void 19 if not ok 20 exit code 21 end 22 end 23 24 fn st_num v ulong to void 25 d = new uchar 20 0 26 x = v 27 k = ulong 20 28 for i ulong 20 29 k = sub k 1 30 put d k uchar add rem x 10 48 31 x = div x 10 32 if eq x 0 33 break 34 end 35 end 36 r = write 1 d k sub 20 k 37 end 38 39 note Write "/proc//stat" into p; returns its length. 40 fn st_path pid ulong p edit uchar 64 to ulong 41 d = new uchar 20 0 42 for i ulong 6 43 put p i get sproc i 44 end 45 x = pid 46 k = ulong 20 47 for i ulong 20 48 k = sub k 1 49 put d k uchar add rem x 10 48 50 x = div x 10 51 if eq x 0 52 break 53 end 54 end 55 n = ulong 6 56 for i ulong sub 20 k bound 20 57 put p n get d add k i 58 n = add n 1 59 end 60 for i ulong 5 61 put p n get sstat i 62 n = add n 1 63 end 64 ret n 65 end 66 67 note Sum of fields 14 and 15 (utime, stime) of a /proc stat line of got bytes. 68 fn st_parse b view uchar 1024 got ulong to ulong 69 rp = ulong 0 70 for i ulong got bound 1023 71 if eq get b i 41 72 rp = i 73 end 74 end 75 field = ulong 2 76 t = ulong 0 77 v = ulong 0 78 for i ulong sub got rp bound 1023 79 c = get b add rp i 80 if eq c 32 81 if or eq field 14 eq field 15 82 t = add t v 83 end 84 field = add field 1 85 v = 0 86 else 87 if and ge c 48 le c 57 88 v = add mul v 10 sub ulong c 48 89 end 90 end 91 end 92 ret t 93 end 94 95 note utime + stime of process pid in clock ticks, from /proc/pid/stat. 96 fn st_ticks pid ulong to ulong 97 p = new uchar 64 0 98 b = new uchar 1024 0 99 n = st_path pid p 100 fd = fopen p 0 n 524288 0 101 if lt fd 0 102 exit 150 103 end 104 got = read int fd b 0 1023 105 r = fclose int fd 106 if le got 0 107 exit 151 108 end 109 ret st_parse b ulong got 110 end 111 112 note Worker: run the job of assignment q cooperatively for the number of 113 note milliseconds in the low four decimal digits of its id, then report 114 note outcome id+1 and 64 bytes of the id's low byte. 0 done, 2 stopped, 115 note 3 creator gone, 4 wait error, 5 report refused. 116 fn st_run c long w ulong q ulong to int 117 buf = new uchar 4096 0 118 id = sc_cell w 8 119 dl = add ulong monons mul rem id 10000 `1000000` 120 for t ulong `1000000` 121 now = ulong monons 122 if ge now dl 123 break 124 end 125 r = sched_wwait c w long sub dl now 126 if eq r 2 127 ret 2 128 end 129 if eq r 3 130 ret 3 131 end 132 if lt r 0 133 ret 4 134 end 135 end 136 for j ulong 64 137 put buf j uchar and id 255 138 end 139 if ne sched_wdone w q add id 1 buf 64 0 140 ret 5 141 end 142 ret 0 143 end 144 145 note Worker loop: run an assigned job, else scan the subscribed versions, 146 note record how many it has seen, and wait without a deadline. A worker with 147 note its lazy flag set sleeps 300 ms before each wait, so hints pile up. 148 fn st_worker w ulong to int 149 c = get stc 0 150 m = get stm 0 151 seen = ulong 0 152 for it ulong `1000000000` 153 q = sched_wjob w 154 if gt q 0 155 r = st_run c w q 156 if eq r 2 157 ret 0 158 end 159 if ne r 0 160 ret add 60 r 161 end 162 continue 163 end 164 k = sched_wscan c w 165 if eq k neg long 1 166 ret 0 167 end 168 if lt k 0 169 ret 59 170 end 171 seen = add seen ulong k 172 r = mapset m add 64 mul w 8 8 seen 173 if ne mapget m add 600 mul w 8 8 0 174 r = sleepns `300000000` 175 end 176 r = sched_wwait c w neg long 1 177 if eq r 2 178 ret 0 179 end 180 if eq r 3 181 ret 41 182 end 183 if lt r 0 184 ret 43 185 end 186 end 187 ret 45 188 end 189 190 fn st_spawn c long w ulong to bool 191 p = sup_spawn c w 192 if eq p 0 193 exit st_worker w 194 end 195 ret gt p 0 196 end 197 198 note Fresh pool of 4 arenas for w workers with limits a and rl, plus the test 199 note page. Exits with code on any refusal. 200 fn st_setup w ulong a ulong rl ulong code int to long 201 c = pool_new 4 w 202 st_ok gt c 0 code 203 put stc 0 c 204 m = mapnew neg int 1 0 4096 3 33 205 st_ok gt m 0 code 206 put stm 0 m 207 st_ok eq sup_init c 0 code 208 st_ok eq sched_new c a rl 0 code 209 ret c 210 end 211 212 fn st_down c long code int to void 213 st_ok ge sched_stop c `2000000000` 0 code 214 sup_closeall 215 st_ok eq sched_free 0 code 216 st_ok eq pool_free c 0 code 217 st_ok eq mapdrop get stm 0 0 code 218 end 219 220 note Step the creator until at least n jobs are in state st, up to ms. 221 fn st_until c long st ulong n ulong ms ulong to bool 222 dl = add ulong monons mul ms `1000000` 223 for t ulong `1000000` 224 if ge sched_count st st n 225 ret true 226 end 227 if ge ulong monons dl 228 ret false 229 end 230 r = sched_step c `10000000` 231 end 232 ret false 233 end 234 235 note Wait up to ms for worker w's seen count to reach n. 236 fn st_seen w ulong n ulong ms ulong to bool 237 dl = add ulong monons mul ms `1000000` 238 for t ulong `1000000` 239 if ge mapget get stm 0 add 64 mul w 8 8 n 240 ret true 241 end 242 if ge ulong monons dl 243 ret false 244 end 245 r = sleepns `1000000` 246 end 247 ret false 248 end 249 250 note Phase A: interests w0 topic 1, w1 topic 2, w2 topic 1 and lazy. Topic 4 251 note publications wake nobody. One topic 1 publication wakes w2; the next 29 252 note land while it sleeps and reach it in exactly one more wake. w0 sees all 253 note 30, w1 is never woken. 254 fn st_hints to void 255 buf = new uchar 4096 0 256 c = st_setup 3 8 8 10 257 m = get stm 0 258 st_ok eq sched_want 0 1 0 11 259 st_ok eq sched_want 1 2 0 12 260 st_ok eq sched_want 2 1 0 13 261 r = mapset m 616 8 1 262 for w ulong 3 263 st_ok st_spawn c w 14 264 end 265 r = sleepns `100000000` 266 for i ulong 20 267 st_ok gt sched_publish c 4 buf 16 0 15 268 end 269 r = sleepns `500000000` 270 for w ulong 3 271 st_ok eq sc_cell w 80 0 16 272 st_ok eq mapget m add 64 mul w 8 8 0 17 273 end 274 st_ok gt sched_publish c 1 buf 16 0 18 275 st_ok st_seen 2 1 3000 19 276 for i ulong 29 277 st_ok gt sched_publish c 1 buf 16 0 29 278 end 279 st_ok st_seen 0 30 3000 44 280 st_ok st_seen 2 30 3000 20 281 r = sleepns `400000000` 282 st_ok eq mapget m 64 8 30 21 283 st_ok eq mapget m 80 8 30 22 284 st_ok eq mapget m 72 8 0 23 285 st_ok eq sc_cell 1 80 0 24 286 st_ok eq sc_cell 2 80 2 25 287 st_ok ge sc_cell 0 80 1 26 288 st_ok le sc_cell 0 80 30 27 289 st_down c 28 290 end 291 292 fn st_admit id ulong deps ulong fl ulong code int to ulong 293 j = sched_admit id deps fl 294 st_ok ge j 0 code 295 ret ulong j 296 end 297 298 note Phase B: one slow job and six fast ones on three workers. The fast jobs 299 note finish and are reviewed while the slow one still runs (no barrier). 300 fn st_nobar to void 301 buf = new uchar 4096 0 302 c = st_setup 3 8 8 30 303 for w ulong 3 304 st_ok st_spawn c w 31 305 end 306 s = st_admit 11500 0 0 32 307 for i ulong 6 308 j = st_admit add mul add i 2 10000 20 0 0 33 309 end 310 st_ok st_until c 4 6 5000 34 311 st_ok eq get sjst s 3 35 312 for j ulong 64 313 if and eq get sjst j 4 ne j s 314 st_ok eq sched_review j long add get sjid j 1 36 315 end 316 end 317 st_ok eq sched_count 1 4 1 37 318 st_ok st_until c 4 1 5000 38 319 w = get sjw s 320 st_ok eq sched_review s 11501 39 321 st_ok eq sched_result w buf 4096 40 322 st_ok eq get buf 63 236 41 323 st_ok eq sched_count 1 6 0 42 324 st_down c 43 325 end 326 327 note Phase C: admission refuses past 8 and review holds at 2. Workers keep 328 note finished results instead of taking more work; reviewing drains it all. 329 fn st_full to void 330 c = st_setup 3 8 2 45 331 for w ulong 3 332 st_ok st_spawn c w 46 333 end 334 for i ulong 8 335 j = st_admit add mul add i 1 10000 20 0 0 47 336 end 337 st_ok eq sched_admit 99020 0 0 neg long 2 48 338 st_ok st_until c 4 2 5000 49 339 r = sleepns `300000000` 340 for t ulong 20 341 r = sched_step c `10000000` 342 end 343 st_ok eq sched_count 4 4 2 50 344 st_ok eq sched_count 3 3 3 51 345 st_ok eq sched_count 2 2 3 52 346 for w ulong 3 347 st_ok eq sc_cell w 64 get scseq w 53 348 end 349 note Jobs in review no longer count as admitted: 3 held results + 3 ready. 350 st_ok eq sched_count 1 3 6 54 351 n = ulong 0 352 for t ulong 400 353 for j ulong 64 354 if eq get sjst j 4 355 st_ok eq sched_review j long add get sjid j 1 55 356 n = add n 1 357 end 358 end 359 if eq n 8 360 break 361 end 362 r = sched_step c `10000000` 363 end 364 st_ok eq n 8 56 365 st_ok ge sched_admit 99020 0 0 0 57 366 st_down c 58 367 end 368 369 note Phase D: a job that waits on topic 8 starts only after a topic 8 370 note publication; topic 16 does not start it. 371 fn st_deps to void 372 buf = new uchar 4096 0 373 c = st_setup 2 8 8 65 374 for w ulong 2 375 st_ok st_spawn c w 66 376 end 377 j = st_admit 10020 8 0 67 378 st_ok eq get sjst j 1 68 379 st_ok gt sched_publish c 16 buf 16 0 69 380 st_ok not st_until c 4 1 300 70 381 st_ok eq get sjst j 1 71 382 st_ok gt sched_publish c 8 buf 16 0 72 383 st_ok st_until c 4 1 3000 73 384 st_ok eq sched_review j 10021 74 385 st_down c 75 386 end 387 388 note Phase E: kill two workers mid-job. The rerunnable job runs again on the 389 note third worker; the other becomes UNKNOWN and is never run again. 390 note Respawned workers find their old assignment retired. 391 fn st_dead to void 392 c = st_setup 3 8 8 76 393 for w ulong 3 394 st_ok st_spawn c w 77 395 end 396 x = st_admit 11500 0 0 78 397 y = st_admit 21500 0 1 79 398 st_ok st_until c 3 2 2000 80 399 wx = get sjw x 400 wy = get sjw y 401 st_ok eq killpid int get swpid wx 9 0 81 402 st_ok eq killpid int get swpid wy 9 0 82 403 st_ok st_until c 6 1 3000 83 404 st_ok eq get sjatt x 1 84 405 st_ok st_until c 4 1 5000 85 406 st_ok eq get sjatt y 2 86 407 st_ok eq sched_review y 21501 87 408 st_ok eq get sjst x 6 88 409 st_ok eq sched_review x neg long 3 89 410 st_ok st_spawn c wx 90 411 st_ok st_spawn c wy 91 412 st_ok eq sc_cell wx 64 get scseq wx 92 413 st_ok eq sc_cell wy 64 get scseq wy 93 414 for t ulong 30 415 r = sched_step c `10000000` 416 end 417 st_ok eq get sjst x 6 94 418 st_ok eq sched_settle x 0 95 419 st_ok eq sched_count 1 6 0 96 420 st_down c 97 421 end 422 423 note Phase F: stop with eight long jobs admitted and three running. Every 424 note worker leaves cooperatively well inside the deadline; the three running 425 note jobs become UNKNOWN; the five never started stay ready. 426 fn st_stop to void 427 c = st_setup 3 8 8 115 428 for w ulong 3 429 st_ok st_spawn c w 116 430 end 431 for i ulong 8 432 j = st_admit add mul add i 1 10000 5000 0 0 117 433 end 434 st_ok st_until c 3 3 2000 118 435 t0 = ulong monons 436 st_ok eq sched_stop c `2000000000` 0 119 437 st_ok lt sub ulong monons t0 `1000000000` 120 438 st_ok eq sup_live c 0 121 439 st_ok eq sched_count 6 6 3 122 440 st_ok eq sched_count 2 2 5 123 441 for w ulong 3 442 st_ok eq get swst w 0 124 443 end 444 sup_closeall 445 st_ok eq sched_free 0 125 446 st_ok eq pool_free c 0 126 447 st_ok eq mapdrop get stm 0 0 127 448 end 449 450 note CPU ticks used by both workers (word 1000) and the creator (1008) of the 451 note test page while the creator waits 2 s with nothing to do. 452 fn st_idlecpu c long to void 453 m = get stm 0 454 p0 = ulong get swpid 0 455 p1 = ulong get swpid 1 456 me = ulong getpid 457 a0 = add st_ticks p0 st_ticks p1 458 a1 = st_ticks me 459 r = sched_step c `2000000000` 460 b0 = add st_ticks p0 st_ticks p1 461 b1 = st_ticks me 462 r = mapset m 1000 8 sub b0 a0 463 r = mapset m 1008 8 sub b1 a1 464 end 465 466 note 200 rounds of one topic 1 publication, each seen by both workers before 467 note the next. Returns the sum of the per-round wake latencies in ns. 468 fn st_rounds c long to ulong 469 buf = new uchar 4096 0 470 sum = ulong 0 471 for i ulong 200 472 st_ok gt sched_publish c 1 buf 16 0 134 473 for w ulong 2 474 st_ok st_seen w add i 1 2000 135 475 sum = add sum sc_cell w 88 476 end 477 end 478 ret sum 479 end 480 481 note Phase G: two idle workers block while the creator idles 2 s; then 200 482 note publication rounds wake each worker exactly once per round (no lost and 483 note no extra wake-ups). 484 fn st_idle to void 485 c = st_setup 2 8 8 130 486 m = get stm 0 487 st_ok eq sched_want 0 1 0 131 488 st_ok eq sched_want 1 1 0 132 489 for w ulong 2 490 st_ok st_spawn c w 133 491 end 492 r = sleepns `200000000` 493 st_idlecpu c 494 st_ok le mapget m 1000 8 2 138 495 st_ok le mapget m 1008 8 2 139 496 sum = st_rounds c 497 st_ok eq sc_cell 0 80 200 136 498 st_ok eq sc_cell 1 80 200 137 499 r = write 1 sidle 0 len sidle 500 st_num mapget m 1000 8 501 r = write 1 screat 0 len screat 502 st_num mapget m 1008 8 503 r = write 1 swake 0 len swake 504 st_num 200 505 r = write 1 smean 0 len smean 506 st_num div sum 400000 507 r = write 1 smax 0 len smax 508 mx = sc_cell 0 96 509 if gt sc_cell 1 96 mx 510 mx = sc_cell 1 96 511 end 512 st_num div mx 1000 513 r = write 1 snl 0 1 514 st_down c 140 515 end 516 517 fn st_isarg to bool 518 a = new uchar 16 0 519 if ne argcnt 2 520 ret false 521 end 522 ret eq argread 1 a 0 16 4 523 end 524 525 note With one 4-byte argument ("idle"), run only phase G. 526 fn main to int 527 if st_isarg 528 st_idle 529 ret 0 530 end 531 st_hints 532 st_nobar 533 st_full 534 st_deps 535 st_dead 536 st_stop 537 st_idle 538 if ne write 1 sok 0 len sok long len sok 539 ret 100 540 end 541 ret 0 542 end