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 / node / schedpol-test.om
| 1 | note Concatenate after transport.om, pool.om, super.om and sched.om. CPU-only |
| 2 | note acceptance of the resource-aware selection policy (P-DRA-14) with real |
| 3 | note forked workers: impossible requests, the capacity invariant under churn, |
| 4 | note ready order, the head-of-line scenarios of the reference pump |
| 5 | note (aien-sovereign-core-mv spark-harness scheduler/core.rs Core::pump), |
| 6 | note starvation under repeated small arrivals, admission tickets, lease |
| 7 | note expiry and cancellation of a reserved job. |
| 8 | note After every creator step the test checks that no kind is used beyond its |
| 9 | note capacity and that the use equals the needs of the jobs holding them. |
| 10 | note Argument "fifo" runs policy 0, "noreserve" policy 1 with the bypass |
| 11 | note budget out of reach: the negative controls. No GPU, model or network. |
| 12 | text pok "PASS node schedpol\n" |
| 13 | text pst "schedpol events=" |
| 14 | text pex " examined=" |
| 15 | text pas " assigned=" |
| 16 | text phol " hol_stops=" |
| 17 | text pbyp " bypasses=" |
| 18 | text pres " reservations=" |
| 19 | text pnl "\n" |
| 20 | text ptr "schedpol goal trace " |
| 21 | text psp " " |
| 22 | text pw1 "schedpol hol witness head=" |
| 23 | text pw2 " fits_behind=" |
| 24 | text pw3 " free_cpu=" |
| 25 | text pw4 " idle_worker=" |
| 26 | global ptc long 1 |
| 27 | note Mode: 0 default policy, 1 fifo, 2 noreserve, 3 goal (policy 2). |
| 28 | global ptm ulong 1 |
| 29 | note Step-bound snapshot (pt_snap): event count, candidate reads, |
| 30 | note maintenance reads, assigned, cursor, window scans. |
| 31 | global ptb ulong 6 |
| 32 | note Phase G trace: ids in review order. |
| 33 | global ptt ulong 16 |
| 34 | global ptn ulong 1 |
| 35 | note Value-read bound baseline: stats 38, 32, 33 at the last check. |
| 36 | global ptv ulong 3 |
| 37 | |
| 38 | fn pt_ok ok bool code int to void |
| 39 | if not ok |
| 40 | exit code |
| 41 | end |
| 42 | end |
| 43 | |
| 44 | fn pt_num v ulong to void |
| 45 | d = new uchar 20 0 |
| 46 | x = v |
| 47 | k = ulong 20 |
| 48 | for i ulong 20 |
| 49 | k = sub k 1 |
| 50 | put d k uchar add rem x 10 48 |
| 51 | x = div x 10 |
| 52 | if eq x 0 |
| 53 | break |
| 54 | end |
| 55 | end |
| 56 | r = write 1 d k sub 20 k |
| 57 | end |
| 58 | |
| 59 | note Packed request: cpu slots, memory MiB, inference slots, kind 3. |
| 60 | fn pt_req cpu ulong mem ulong inf ulong x ulong to ulong |
| 61 | ret or or cpu shl mem 16 or shl inf 32 shl x 48 |
| 62 | end |
| 63 | |
| 64 | note Worker: run assignment q for the milliseconds in the low four decimal |
| 65 | note digits of its job id, then report outcome id+1 and 8 bytes. 0 done, |
| 66 | note 2 stopped, 3 creator gone, 4 wait error, 5 report refused. |
| 67 | fn pt_run c long w ulong q ulong to int |
| 68 | buf = new uchar 4096 0 |
| 69 | id = sc_cell w 8 |
| 70 | dl = add ulong monons mul rem id 10000 1000000 |
| 71 | for t ulong 1000000 |
| 72 | now = ulong monons |
| 73 | if ge now dl |
| 74 | break |
| 75 | end |
| 76 | r = sched_wwait c w long sub dl now |
| 77 | if eq r 2 |
| 78 | ret 2 |
| 79 | end |
| 80 | if eq r 3 |
| 81 | ret 3 |
| 82 | end |
| 83 | if lt r 0 |
| 84 | ret 4 |
| 85 | end |
| 86 | end |
| 87 | if ne sched_wdone w q add id 1 buf 8 0 |
| 88 | ret 5 |
| 89 | end |
| 90 | ret 0 |
| 91 | end |
| 92 | |
| 93 | fn pt_worker w ulong to int |
| 94 | c = get ptc 0 |
| 95 | for it ulong 1000000000 |
| 96 | q = sched_wjob w |
| 97 | if gt q 0 |
| 98 | r = pt_run c w q |
| 99 | if eq r 2 |
| 100 | ret 0 |
| 101 | end |
| 102 | if ne r 0 |
| 103 | ret add 60 r |
| 104 | end |
| 105 | continue |
| 106 | end |
| 107 | r = sched_wwait c w neg long 1 |
| 108 | if eq r 2 |
| 109 | ret 0 |
| 110 | end |
| 111 | if eq r 3 |
| 112 | ret 41 |
| 113 | end |
| 114 | if lt r 0 |
| 115 | ret 43 |
| 116 | end |
| 117 | end |
| 118 | ret 45 |
| 119 | end |
| 120 | |
| 121 | fn pt_spawn c long w ulong to bool |
| 122 | p = sup_spawn c w |
| 123 | if eq p 0 |
| 124 | exit pt_worker w |
| 125 | end |
| 126 | ret gt p 0 |
| 127 | end |
| 128 | |
| 129 | note Fresh pool for w workers (spawned), admission limit a, review limit rl, |
| 130 | note capacities caps. Exits with code on any refusal. |
| 131 | fn pt_setup w ulong a ulong rl ulong caps ulong code int to long |
| 132 | c = pool_new 4 w |
| 133 | pt_ok gt c 0 code |
| 134 | put ptc 0 c |
| 135 | pt_ok eq sup_init c 0 code |
| 136 | pt_ok eq sched_new c a rl 0 code |
| 137 | pt_ok eq sched_cap caps 0 code |
| 138 | put ptv 0 sched_stat 38 |
| 139 | put ptv 1 sched_stat 32 |
| 140 | put ptv 2 sched_stat 33 |
| 141 | if eq get ptm 0 1 |
| 142 | pt_ok eq sched_policy 0 64 64 4 1000 0 code |
| 143 | end |
| 144 | if eq get ptm 0 2 |
| 145 | pt_ok eq sched_policy 1 64 64 65535 1000 0 code |
| 146 | end |
| 147 | if eq get ptm 0 3 |
| 148 | pt_ok eq sched_policy 2 64 64 4 1000 0 code |
| 149 | end |
| 150 | for i ulong w bound 64 |
| 151 | pt_ok pt_spawn c i code |
| 152 | end |
| 153 | ret c |
| 154 | end |
| 155 | |
| 156 | fn pt_down c long code int to void |
| 157 | pt_ok ge sched_stop c 2000000000 0 code |
| 158 | sup_closeall |
| 159 | pt_ok eq sched_free 0 code |
| 160 | pt_ok eq pool_free c 0 code |
| 161 | end |
| 162 | |
| 163 | note The capacity invariant: of each kind the use is at most the capacity |
| 164 | note and equals the sum of the needs of the jobs that hold resources; only |
| 165 | note a running job holds them, and every running job whose worker has not |
| 166 | note reported done holds them. |
| 167 | fn pt_inv code int to void |
| 168 | for j ulong 64 |
| 169 | if eq get sjst j 3 |
| 170 | w = get sjw j |
| 171 | if ne sc_cell w 64 get scseq w |
| 172 | pt_ok eq get sjheld j 1 code |
| 173 | end |
| 174 | end |
| 175 | end |
| 176 | for k ulong 4 |
| 177 | s = ulong 0 |
| 178 | for j ulong 64 |
| 179 | if eq get sjheld j 1 |
| 180 | pt_ok eq get sjst j 3 code |
| 181 | s = add s sp_need get sjneed j k |
| 182 | end |
| 183 | end |
| 184 | pt_ok eq get suse k s code |
| 185 | pt_ok le get suse k get scap k code |
| 186 | end |
| 187 | end |
| 188 | |
| 189 | note One creator step of up to 10 ms, then the invariant and the scan |
| 190 | note bounds since the last step. An event makes at most one pick more than |
| 191 | note it assigns, so candidate reads are at most (assigned + events) x |
| 192 | note (window + 1), the reserved probe included, plus one proposal probe per |
| 193 | note pick under policy 2, or x 64 under FIFO (policy 0), 9; maintenance reads |
| 194 | note at most 64 per event, 14; the cursor moved by exactly the window per |
| 195 | note window scan, mod 64, 15 (the traversal witness: window scans cover |
| 196 | note consecutive windows, so ceil(64/win) of them examine every slot); value |
| 197 | note reads at most 64 per rescoring plus 128 per job scored, 8. |
| 198 | fn pt_step c long code int to void |
| 199 | pt_snap |
| 200 | r = sched_step c 10000000 |
| 201 | pt_ok ge r 0 code |
| 202 | pt_inv code |
| 203 | pt_check |
| 204 | end |
| 205 | |
| 206 | note Snapshot the counters the step bounds compare against (ptb). |
| 207 | fn pt_snap to void |
| 208 | put ptb 0 sched_stat 2 |
| 209 | put ptb 1 sched_stat 3 |
| 210 | put ptb 2 sched_stat 13 |
| 211 | put ptb 3 sched_stat 4 |
| 212 | put ptb 4 sched_stat 28 |
| 213 | put ptb 5 sched_stat 14 |
| 214 | end |
| 215 | |
| 216 | note The bounds since pt_snap (exits 9, 14, 15, 8). |
| 217 | fn pt_check to void |
| 218 | w = add sched_stat 25 1 |
| 219 | if eq sched_stat 24 0 |
| 220 | w = ulong 64 |
| 221 | end |
| 222 | if eq sched_stat 24 2 |
| 223 | w = add w 1 |
| 224 | end |
| 225 | ev = sub sched_stat 2 get ptb 0 |
| 226 | lim = mul add sub sched_stat 4 get ptb 3 ev w |
| 227 | pt_ok le sub sched_stat 3 get ptb 1 lim 9 |
| 228 | pt_ok le sub sched_stat 13 get ptb 2 mul ev 64 14 |
| 229 | pt_cursor get ptb 4 get ptb 5 |
| 230 | pt_vbound |
| 231 | end |
| 232 | |
| 233 | note Resume dispatch (it dispatches at once) inside the step bounds. |
| 234 | fn pt_resume c long to void |
| 235 | pt_snap |
| 236 | k = sched_pause c false |
| 237 | pt_check |
| 238 | end |
| 239 | |
| 240 | note The cursor moved by the window once per window scan since (u0, s0). |
| 241 | fn pt_cursor u0 ulong s0 ulong to void |
| 242 | d = mul sched_stat 25 sub sched_stat 14 s0 |
| 243 | pt_ok eq sched_stat 28 rem add u0 d 64 15 |
| 244 | end |
| 245 | |
| 246 | note The value-read bound since the last call (phase checks, exit 8). |
| 247 | fn pt_vbound to void |
| 248 | v = sched_stat 38 |
| 249 | lim = add mul sub sched_stat 32 get ptv 1 64 mul sub sched_stat 33 get ptv 2 128 |
| 250 | pt_ok le sub v get ptv 0 lim 8 |
| 251 | put ptv 0 v |
| 252 | put ptv 1 sched_stat 32 |
| 253 | put ptv 2 sched_stat 33 |
| 254 | end |
| 255 | |
| 256 | note Step until job j is in a state in lo..hi, up to ms. True when reached. |
| 257 | fn pt_until c long j ulong lo ulong hi ulong ms ulong code int to bool |
| 258 | dl = add ulong monons mul ms 1000000 |
| 259 | for t ulong 1000000 |
| 260 | s = get sjst j |
| 261 | if and ge s lo le s hi |
| 262 | ret true |
| 263 | end |
| 264 | if ge ulong monons dl |
| 265 | ret false |
| 266 | end |
| 267 | pt_step c code |
| 268 | end |
| 269 | ret false |
| 270 | end |
| 271 | |
| 272 | note Review every job in review whose outcome is its id + 1. |
| 273 | fn pt_review code int to ulong |
| 274 | n = ulong 0 |
| 275 | for j ulong 64 |
| 276 | if eq get sjst j 4 |
| 277 | pt_ok eq sched_review j long add get sjid j 1 code |
| 278 | n = add n 1 |
| 279 | end |
| 280 | end |
| 281 | ret n |
| 282 | end |
| 283 | |
| 284 | note Step and review until n jobs were reviewed, up to ms. |
| 285 | fn pt_drain c long n ulong ms ulong code int to void |
| 286 | dl = add ulong monons mul ms 1000000 |
| 287 | k = ulong 0 |
| 288 | for t ulong 1000000 |
| 289 | k = add k pt_review code |
| 290 | if ge k n |
| 291 | ret |
| 292 | end |
| 293 | pt_ok lt ulong monons dl code |
| 294 | pt_step c code |
| 295 | end |
| 296 | exit code |
| 297 | end |
| 298 | |
| 299 | fn pt_admit id ulong deps ulong req ulong code int to ulong |
| 300 | j = sched_admitr id deps 0 req |
| 301 | pt_ok ge j 0 code |
| 302 | ret ulong j |
| 303 | end |
| 304 | |
| 305 | note Phase C: a request beyond the capacity of any kind is refused (-8) and |
| 306 | note counted; lowering a capacity below an admitted job's need, or below |
| 307 | note the use of two running jobs that each fit it alone, is refused and |
| 308 | note changes nothing. |
| 309 | fn pt_impossible to void |
| 310 | c = pt_setup 2 8 8 pt_req 4 1024 1 8 30 |
| 311 | pt_ok eq sched_admitr 1 0 0 pt_req 5 0 0 0 neg long 8 31 |
| 312 | pt_ok eq sched_admitr 2 0 0 pt_req 1 1025 0 0 neg long 8 32 |
| 313 | pt_ok eq sched_admitr 3 0 0 pt_req 0 0 2 0 neg long 8 33 |
| 314 | pt_ok eq sched_stat 7 3 34 |
| 315 | a = pt_admit 4 0 pt_req 3 0 0 0 35 |
| 316 | pt_ok eq sched_cap pt_req 2 1024 1 8 neg long 8 36 |
| 317 | pt_ok eq sched_stat 16 4 37 |
| 318 | pt_ok eq sched_cancel a 1 38 |
| 319 | pt_ok eq sched_cap pt_req 2 1024 1 8 0 39 |
| 320 | pt_ok eq sched_stat 16 2 40 |
| 321 | pt_ok eq sched_cap pt_req 4 1024 1 8 0 130 |
| 322 | p = pt_admit 130400 0 pt_req 2 0 0 0 130 |
| 323 | q = pt_admit 140400 0 pt_req 2 0 0 0 130 |
| 324 | pt_ok pt_until c p 3 3 2000 130 130 |
| 325 | pt_ok pt_until c q 3 3 2000 130 130 |
| 326 | pt_ok eq sched_cap pt_req 3 1024 1 8 neg long 8 131 |
| 327 | pt_ok eq sched_stat 16 4 132 |
| 328 | pt_drain c 2 3000 133 |
| 329 | pt_ok eq sched_cap pt_req 3 1024 1 8 0 134 |
| 330 | pt_down c 41 |
| 331 | end |
| 332 | |
| 333 | note Phase D: 12 jobs with mixed CPU, memory and inference needs on three |
| 334 | note workers, capacities 4 CPU, 1024 MiB, 1 inference slot. Every job runs |
| 335 | note once and returns its outcome; the invariant holds at every step and |
| 336 | note every resource is free at the end. |
| 337 | fn pt_churn to void |
| 338 | c = pt_setup 3 16 8 pt_req 4 1024 1 0 42 |
| 339 | for i ulong 12 |
| 340 | cpu = add rem i 3 1 |
| 341 | mem = mul add rem i 6 1 100 |
| 342 | inf = rem i 2 |
| 343 | id = add mul add i 1 10000 add 30 mul rem i 4 15 |
| 344 | j = pt_admit id 0 pt_req cpu mem inf 0 43 |
| 345 | end |
| 346 | pt_drain c 12 10000 44 |
| 347 | for k ulong 4 |
| 348 | pt_ok eq get suse k 0 45 |
| 349 | end |
| 350 | pt_ok eq sched_count 1 6 0 46 |
| 351 | pt_ok eq sched_stat 4 12 47 |
| 352 | pt_down c 48 |
| 353 | end |
| 354 | |
| 355 | note Some running job whose worker has reported done (its result waits |
| 356 | note for review room). |
| 357 | fn pt_held to bool |
| 358 | for j ulong 64 |
| 359 | if eq get sjst j 3 |
| 360 | w = get sjw j |
| 361 | if eq sc_cell w 64 get scseq w |
| 362 | ret true |
| 363 | end |
| 364 | end |
| 365 | end |
| 366 | ret false |
| 367 | end |
| 368 | |
| 369 | note Phase V: release while review is full. Review limit 1, two workers, |
| 370 | note 2 CPU: j1 and j2 (1 CPU, 50 ms) both finish; one enters review, the |
| 371 | note other's result waits for room, yet both CPUs are free at once and j3 |
| 372 | note (2 CPU) runs before anything is reviewed. |
| 373 | fn pt_release to void |
| 374 | c = pt_setup 2 8 1 pt_req 2 1024 1 8 120 |
| 375 | j1 = pt_admit 150050 0 pt_req 1 0 0 0 120 |
| 376 | j2 = pt_admit 160050 0 pt_req 1 0 0 0 120 |
| 377 | dl = add ulong monons 2000000000 |
| 378 | for t ulong 1000000 |
| 379 | if eq sched_count 4 4 1 |
| 380 | if pt_held |
| 381 | break |
| 382 | end |
| 383 | end |
| 384 | pt_ok lt ulong monons dl 121 |
| 385 | pt_step c 121 |
| 386 | end |
| 387 | note The done report may land after the last collect: one more step |
| 388 | note collects it (review stays full, so nothing else changes). |
| 389 | pt_step c 121 |
| 390 | pt_ok eq get suse 0 0 122 |
| 391 | j3 = pt_admit 170050 0 pt_req 2 0 0 0 123 |
| 392 | pt_ok pt_until c j3 3 4 2000 123 124 |
| 393 | pt_drain c 3 3000 125 |
| 394 | pt_down c 126 |
| 395 | end |
| 396 | |
| 397 | note Phase F: ready order. With one worker, x is admitted first waiting on |
| 398 | note topic 8 and y second ready at once; then topic 8 is published. FIFO |
| 399 | note (policy 0) serves the job that became ready first, y; fair fitting |
| 400 | note serves the job admitted first, x (waiting age counts from admission). |
| 401 | fn pt_order to void |
| 402 | buf = new uchar 4096 0 |
| 403 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 50 |
| 404 | x = pt_admit 60050 8 0 51 |
| 405 | y = pt_admit 70050 0 0 52 |
| 406 | pt_snap |
| 407 | pt_ok gt sched_publish c 8 buf 16 0 53 |
| 408 | pt_check |
| 409 | if eq sched_stat 24 0 |
| 410 | pt_ok eq get sjst y 3 54 |
| 411 | pt_ok eq get sjst x 2 55 |
| 412 | else |
| 413 | pt_ok eq get sjst x 3 54 |
| 414 | pt_ok eq get sjst y 2 55 |
| 415 | end |
| 416 | pt_drain c 2 3000 56 |
| 417 | pt_down c 57 |
| 418 | end |
| 419 | |
| 420 | note Witness of a head-of-line block, read with no step in between: a runs |
| 421 | note unfinished holding its need, the head h is ready and does not fit, x |
| 422 | note is ready and fits, a live worker is idle, and dispatch stopped at the |
| 423 | note head at least once since h0 (codes code..code+4 when not). |
| 424 | fn pt_witness c long a ulong h ulong x ulong h0 ulong code int to void |
| 425 | w = get sjw a |
| 426 | pt_ok eq get sjst a 3 code |
| 427 | pt_ok ne sc_cell w 64 get scseq w code |
| 428 | pt_ok eq get sjheld a 1 code |
| 429 | pt_ok eq get sjst h 2 add code 1 |
| 430 | pt_ok not sp_fits get sjneed h 0 add code 1 |
| 431 | pt_ok eq get sjst x 2 add code 2 |
| 432 | pt_ok sp_fits get sjneed x 0 add code 2 |
| 433 | i = sp_idle mapget c 48 8 |
| 434 | pt_ok lt i 64 add code 3 |
| 435 | pt_ok gt sched_stat 8 h0 add code 4 |
| 436 | r = write 1 pw1 0 len pw1 |
| 437 | pt_num get sjid h |
| 438 | r = write 1 pw2 0 len pw2 |
| 439 | pt_num get sjid x |
| 440 | r = write 1 pw3 0 len pw3 |
| 441 | pt_num sp_free 0 |
| 442 | r = write 1 pw4 0 len pw4 |
| 443 | pt_num i |
| 444 | r = write 1 phol 0 len phol |
| 445 | pt_num sub sched_stat 8 h0 |
| 446 | r = write 1 pnl 0 1 |
| 447 | end |
| 448 | |
| 449 | note Phase A: the blocked head. a (3 CPU, 800 ms) runs; then b (2 CPU, |
| 450 | note cannot fit) and c (1 CPU, fits) arrive with no dependency. The target: |
| 451 | note c runs while a still runs and b waits (0). When c has not run within |
| 452 | note 400 ms, the witness is checked and printed and the phase returns 11: |
| 453 | note c stayed idle behind b although a CPU and a worker were free. |
| 454 | fn pt_blocked to int |
| 455 | c = pt_setup 3 8 8 pt_req 4 1024 1 8 10 |
| 456 | a = pt_admit 10800 0 pt_req 3 0 0 0 10 |
| 457 | pt_ok pt_until c a 3 3 2000 10 10 |
| 458 | b = pt_admit 20050 0 pt_req 2 0 0 0 10 |
| 459 | x = pt_admit 30050 0 pt_req 1 0 0 0 10 |
| 460 | h0 = sched_stat 8 |
| 461 | v = int 0 |
| 462 | if pt_until c x 3 4 400 10 |
| 463 | pt_ok eq get sjst a 3 12 |
| 464 | pt_ok eq get sjst b 2 13 |
| 465 | else |
| 466 | pt_witness c a b x h0 12 |
| 467 | v = int 11 |
| 468 | end |
| 469 | pt_drain c 3 5000 17 |
| 470 | pt_down c 18 |
| 471 | ret v |
| 472 | end |
| 473 | |
| 474 | note Phase B: a second head-of-line case, after the pump's queue-of-two |
| 475 | note scenario (the bounded queue itself is not modelled: every admitted |
| 476 | note job is in the table). a (3 CPU, 800 ms) runs, b and d (2 CPU) cannot |
| 477 | note fit, e (1 CPU) fits. Target: e runs while a still runs (0); else the |
| 478 | note witness and 21. |
| 479 | fn pt_exclude to int |
| 480 | c = pt_setup 3 8 8 pt_req 4 1024 1 8 20 |
| 481 | a = pt_admit 10800 0 pt_req 3 0 0 0 20 |
| 482 | pt_ok pt_until c a 3 3 2000 20 20 |
| 483 | b = pt_admit 20050 0 pt_req 2 0 0 0 20 |
| 484 | d = pt_admit 40050 0 pt_req 2 0 0 0 20 |
| 485 | e = pt_admit 50050 0 pt_req 1 0 0 0 20 |
| 486 | h0 = sched_stat 8 |
| 487 | v = int 0 |
| 488 | if pt_until c e 3 4 400 20 |
| 489 | pt_ok eq get sjst a 3 22 |
| 490 | else |
| 491 | pt_witness c a b e h0 22 |
| 492 | v = int 21 |
| 493 | end |
| 494 | pt_drain c 4 5000 27 |
| 495 | pt_down c 28 |
| 496 | ret v |
| 497 | end |
| 498 | |
| 499 | note Phase S: starvation under repeated small arrivals. Three workers, 4 |
| 500 | note CPU. Small jobs (1 CPU) start staggered (100, 200, 300 ms), and each |
| 501 | note that finishes is replaced by one of 300 ms, so the small jobs never |
| 502 | note all end together; big (4 CPU, 50 ms) needs every CPU free. The target: |
| 503 | note big runs within 4 s. 61 means it never did: the small jobs kept the |
| 504 | note CPU partly busy (the "noreserve" control). |
| 505 | fn pt_starve to void |
| 506 | c = pt_setup 3 16 8 pt_req 4 1024 1 8 60 |
| 507 | for i ulong 3 |
| 508 | j = pt_admit mul add i 1 100100 0 pt_req 1 0 0 0 60 |
| 509 | end |
| 510 | s = ulong 4 |
| 511 | g = pt_admit 90050 0 pt_req 4 0 0 0 60 |
| 512 | dl = add ulong monons 4000000000 |
| 513 | ok = false |
| 514 | for t ulong 1000000 |
| 515 | if ge get sjst g 3 |
| 516 | ok = true |
| 517 | break |
| 518 | end |
| 519 | if ge ulong monons dl |
| 520 | break |
| 521 | end |
| 522 | if lt sched_count 1 3 4 |
| 523 | j = pt_admit add mul s 100000 300 0 pt_req 1 0 0 0 60 |
| 524 | s = add s 1 |
| 525 | end |
| 526 | pt_step c 60 |
| 527 | n = pt_review 60 |
| 528 | end |
| 529 | pt_ok ok 61 |
| 530 | pt_ok ge sched_stat 6 1 62 |
| 531 | pt_ok ge sched_stat 9 1 63 |
| 532 | pt_drain c sched_count 1 4 5000 64 |
| 533 | pt_stats |
| 534 | pt_ok eq get suse 0 0 65 |
| 535 | pt_down c 66 |
| 536 | end |
| 537 | |
| 538 | note Phase Q: admission tickets. Limit 2: p1 (400 ms) and p2 (900 ms) fill |
| 539 | note it; X then Y are refused and hold tickets in that order. When p1 is |
| 540 | note reviewed there is room for one: Y asking first is refused (75), X is |
| 541 | note admitted (76); Y enters once more room returns (78). A ticket not |
| 542 | note asked about for the lifetime (20 events) lapses, so a new caller is |
| 543 | note admitted although the old holder never came back (80). The wait for |
| 544 | note the lapse reviews whatever finishes, 140900 included when it outlasts |
| 545 | note that job's 900 ms, so the last drain waits for the jobs still |
| 546 | note outstanding, not a fixed two: a fixed two timed out (80) whenever the |
| 547 | note loop had already reviewed 140900. |
| 548 | fn pt_tickets to void |
| 549 | c = pt_setup 2 2 8 pt_req 4 1024 1 8 70 |
| 550 | pt_ok eq sched_policy sched_stat 24 64 64 sched_stat 27 1000 0 70 |
| 551 | p1 = pt_admit 100400 0 0 70 |
| 552 | p2 = pt_admit 110900 0 0 70 |
| 553 | pt_ok eq sched_admitr 120050 0 0 0 neg long 2 71 |
| 554 | pt_ok eq sched_admitr 130050 0 0 0 neg long 2 72 |
| 555 | pt_ok eq sched_stat 30 2 73 |
| 556 | pt_drain c 1 3000 74 |
| 557 | pt_ok eq sched_admitr 130050 0 0 0 neg long 2 75 |
| 558 | pt_ok ge sched_admitr 120050 0 0 0 0 76 |
| 559 | pt_drain c 2 3000 77 |
| 560 | pt_ok ge sched_admitr 130050 0 0 0 0 78 |
| 561 | pt_ok eq sched_policy sched_stat 24 64 64 sched_stat 27 20 0 79 |
| 562 | f = pt_admit 140900 0 0 79 |
| 563 | pt_ok eq sched_admitr 150050 0 0 0 neg long 2 79 |
| 564 | e0 = sched_stat 2 |
| 565 | dl = add ulong monons 3000000000 |
| 566 | for t ulong 1000000 |
| 567 | if le sched_count 1 3 1 |
| 568 | if gt sched_stat 2 add e0 21 |
| 569 | break |
| 570 | end |
| 571 | end |
| 572 | pt_ok lt ulong monons dl 79 |
| 573 | pt_step c 79 |
| 574 | n = pt_review 79 |
| 575 | end |
| 576 | pt_ok ge sched_admitr 160050 0 0 0 0 80 |
| 577 | pt_ok ge sched_stat 11 1 80 |
| 578 | pt_drain c sched_count 1 4 3000 80 |
| 579 | pt_down c 80 |
| 580 | end |
| 581 | |
| 582 | note Step until sched_overdue reports a job, up to 2 s: its slot, or 64. |
| 583 | fn pt_waitod c long code int to ulong |
| 584 | t0 = ulong monons |
| 585 | for t ulong 1000000 |
| 586 | o = sched_overdue |
| 587 | if lt o 64 |
| 588 | ret o |
| 589 | end |
| 590 | if gt sub ulong monons t0 2000000000 |
| 591 | ret 64 |
| 592 | end |
| 593 | pt_step c code |
| 594 | end |
| 595 | ret 64 |
| 596 | end |
| 597 | |
| 598 | note Phase L: lease expiry. h (2 of 2 CPU, 3 s, not safe to rerun) has a |
| 599 | note 200 ms lease: its deadline is at least 200 ms after h was admitted, and |
| 600 | note sched_overdue reports it once, at or after that deadline (83); the |
| 601 | note creator kills its worker; h becomes UNKNOWN and its CPU is free. |
| 602 | note h2 (2 CPU, 400 ms, safe to rerun, 100 ms lease) is killed the same |
| 603 | note way: it is ready or running again with its admission age kept, and |
| 604 | note completes. Then a new 2-CPU job runs. |
| 605 | fn pt_lease to void |
| 606 | c = pt_setup 3 8 8 pt_req 2 1024 1 8 81 |
| 607 | t0 = ulong monons |
| 608 | h = pt_admit 173000 0 pt_req 2 0 0 0 81 |
| 609 | pt_ok eq sched_lease h 200000000 0 81 |
| 610 | pt_ok pt_until c h 3 3 2000 81 81 |
| 611 | due = get sjdue h |
| 612 | pt_ok ge due add t0 200000000 83 |
| 613 | o = pt_waitod c 82 |
| 614 | pt_ok eq o h 82 |
| 615 | pt_ok ge ulong monons due 83 |
| 616 | pt_ok eq sched_overdue 64 84 |
| 617 | r = killpid int get swpid get sjw h 9 |
| 618 | pt_ok pt_until c h 6 6 2000 85 85 |
| 619 | pt_ok eq get suse 0 0 86 |
| 620 | pt_ok eq sched_settle h 0 87 |
| 621 | x = sched_admitr 180400 0 1 pt_req 2 0 0 0 |
| 622 | pt_ok ge x 0 140 |
| 623 | h2 = ulong x |
| 624 | pt_ok eq sched_lease h2 100000000 0 140 |
| 625 | pt_ok pt_until c h2 3 3 2000 140 140 |
| 626 | ar = get sjarr h2 |
| 627 | pt_ok eq pt_waitod c 141 h2 141 |
| 628 | w = get sjw h2 |
| 629 | r = killpid int get swpid w 9 |
| 630 | dl = add ulong monons 2000000000 |
| 631 | for t ulong 1000000 |
| 632 | if eq get swpid w 0 |
| 633 | break |
| 634 | end |
| 635 | pt_ok lt ulong monons dl 142 |
| 636 | pt_step c 142 |
| 637 | end |
| 638 | pt_ok eq get sjarr h2 ar 143 |
| 639 | s = get sjst h2 |
| 640 | pt_ok and ge s 2 le s 3 144 |
| 641 | pt_drain c 1 3000 145 |
| 642 | z = pt_admit 190050 0 pt_req 2 0 0 0 88 |
| 643 | pt_drain c 1 3000 88 |
| 644 | pt_down c 89 |
| 645 | end |
| 646 | |
| 647 | note Phase R: cancellation of a reserved job. Bypass budget 1: a (1 of 2 |
| 648 | note CPU) runs, b (2 CPU) waits, x (1 CPU) runs past it, so b is reserved. |
| 649 | note Cancelling b frees it with no effect and clears the reservation. |
| 650 | fn pt_rcancel to void |
| 651 | c = pt_setup 2 8 8 pt_req 2 1024 1 8 90 |
| 652 | pt_ok eq sched_policy sched_stat 24 64 64 1 1000 0 90 |
| 653 | a = pt_admit 190600 0 pt_req 1 0 0 0 90 |
| 654 | pt_ok pt_until c a 3 3 2000 90 90 |
| 655 | b = pt_admit 200050 0 pt_req 2 0 0 0 90 |
| 656 | x = pt_admit 210050 0 pt_req 1 0 0 0 90 |
| 657 | pt_ok pt_until c x 3 4 400 90 91 |
| 658 | pt_ok eq sched_stat 29 add b 1 92 |
| 659 | pt_ok eq sched_cancel b 1 93 |
| 660 | pt_ok eq sched_stat 29 0 94 |
| 661 | pt_drain c 2 3000 95 |
| 662 | pt_ok eq get suse 0 0 96 |
| 663 | pt_down c 97 |
| 664 | end |
| 665 | |
| 666 | note Phase W: bounded candidate work. Window 4 slots, dispatch budget 2, |
| 667 | note two workers, so an event may pick twice: 12 ready jobs fill slots |
| 668 | note 0..11, beyond any one window. Each pick reads at most 5 slots (the |
| 669 | note reserved probe and the window, exit 9), every window scan moves the |
| 670 | note cursor on by 4 (15), and all 12 run. 101 means some never did. |
| 671 | fn pt_window to void |
| 672 | c = pt_setup 2 16 16 pt_req 4 1024 1 8 101 |
| 673 | pt_ok eq sched_policy sched_stat 24 4 2 sched_stat 27 1000 0 101 |
| 674 | for i ulong 12 |
| 675 | j = pt_admit add mul add i 1 10000 30 0 0 101 |
| 676 | end |
| 677 | pt_drain c 12 5000 101 |
| 678 | pt_ok eq sched_stat 4 12 102 |
| 679 | pt_down c 103 |
| 680 | end |
| 681 | |
| 682 | note Phase T: ticket order with several openings. Limit 3 held by p1, p2 |
| 683 | note (400 ms) and p3, which waits on a topic nobody publishes; X, Y, Z are |
| 684 | note refused in that order and hold tickets (104). p1 and p2 are reviewed, |
| 685 | note so there are exactly two openings: Y asking first is refused (105), and |
| 686 | note so is a new caller W, who takes a ticket behind Z (106); X enters |
| 687 | note (107), then Y (108). p3 is cancelled and X and Y are reviewed, so there |
| 688 | note are three openings: W asking first is refused, then Z and W enter (109). |
| 689 | fn pt_torder to void |
| 690 | c = pt_setup 3 3 8 pt_req 4 1024 1 8 104 |
| 691 | p = pt_admit 400400 0 0 104 |
| 692 | p = pt_admit 410400 0 0 104 |
| 693 | p3 = pt_admit 420050 4096 0 104 |
| 694 | pt_ok eq sched_admitr 430050 0 0 0 neg long 2 104 |
| 695 | pt_ok eq sched_admitr 440050 0 0 0 neg long 2 104 |
| 696 | pt_ok eq sched_admitr 450050 0 0 0 neg long 2 104 |
| 697 | pt_ok eq sched_stat 30 3 104 |
| 698 | pt_drain c 2 3000 104 |
| 699 | pt_ok eq sched_admitr 440050 0 0 0 neg long 2 105 |
| 700 | pt_ok eq sched_admitr 460050 0 0 0 neg long 2 106 |
| 701 | pt_ok eq sched_stat 30 4 106 |
| 702 | pt_ok ge sched_admitr 430050 0 0 0 0 107 |
| 703 | pt_ok ge sched_admitr 440050 0 0 0 0 108 |
| 704 | pt_ok eq sched_cancel p3 1 108 |
| 705 | pt_drain c 2 3000 108 |
| 706 | pt_ok eq sched_admitr 460050 0 0 0 neg long 2 109 |
| 707 | pt_ok ge sched_admitr 450050 0 0 0 0 109 |
| 708 | pt_ok ge sched_admitr 460050 0 0 0 0 109 |
| 709 | pt_drain c 2 3000 109 |
| 710 | pt_down c 109 |
| 711 | end |
| 712 | |
| 713 | note Phase X: the table, not the admission limit, is full. Admission limit |
| 714 | note and review limit 64; 64 jobs finish and wait in review, so none is |
| 715 | note admitted, waiting, ready or running. A new caller is refused and takes |
| 716 | note a ticket (190, 191), as is a second (192). One review frees one slot: |
| 717 | note the second holder is refused, the first enters (193, 194). |
| 718 | fn pt_slots to void |
| 719 | c = pt_setup 3 64 64 pt_req 4 1024 1 8 190 |
| 720 | for i ulong 64 |
| 721 | j = pt_admit add 500001 mul i 10000 0 0 190 |
| 722 | end |
| 723 | dl = add ulong monons 5000000000 |
| 724 | for t ulong 1000000 |
| 725 | if eq sched_count 4 4 64 |
| 726 | break |
| 727 | end |
| 728 | pt_ok lt ulong monons dl 190 |
| 729 | pt_step c 190 |
| 730 | end |
| 731 | pt_ok not sched_room 600050 191 |
| 732 | pt_ok eq sched_stat 30 1 191 |
| 733 | pt_ok eq sched_admitr 600050 0 0 0 neg long 2 192 |
| 734 | pt_ok eq sched_admitr 610050 0 0 0 neg long 2 192 |
| 735 | pt_ok eq sched_stat 30 2 192 |
| 736 | pt_ok eq sched_review 0 long add get sjid 0 1 193 |
| 737 | pt_ok eq sched_admitr 610050 0 0 0 neg long 2 193 |
| 738 | pt_ok ge sched_admitr 600050 0 0 0 0 194 |
| 739 | n = pt_review 194 |
| 740 | pt_ok ge sched_admitr 610050 0 0 0 0 194 |
| 741 | pt_drain c 2 3000 194 |
| 742 | pt_down c 194 |
| 743 | end |
| 744 | |
| 745 | note Phase Z: reserved progress needs review progress. Review limit 1, two |
| 746 | note workers, 2 CPU, bypass budget 1. p finishes and waits in review, |
| 747 | note unreviewed. a (1 CPU) and x (1 CPU) run past b (2 CPU), so b is |
| 748 | note reserved (196). a and x finish; their workers keep the results, since |
| 749 | note review is full, so b is ready at every step for 600 ms (197) and all |
| 750 | note CPU is free at the end of that interval (198). Reviewing p lets a into |
| 751 | note review, frees its worker, and b runs (199). |
| 752 | fn pt_live to void |
| 753 | c = pt_setup 2 8 1 pt_req 2 1024 1 8 195 |
| 754 | pt_ok eq sched_policy sched_stat 24 64 64 1 1000 0 195 |
| 755 | p = pt_admit 470050 0 pt_req 1 0 0 0 195 |
| 756 | pt_ok pt_until c p 4 4 2000 195 195 |
| 757 | k = sched_pause c true |
| 758 | a = pt_admit 480050 0 pt_req 1 0 0 0 195 |
| 759 | b = pt_admit 490050 0 pt_req 2 0 0 0 195 |
| 760 | x = pt_admit 510050 0 pt_req 1 0 0 0 195 |
| 761 | pt_resume c |
| 762 | pt_ok eq sched_stat 29 add b 1 196 |
| 763 | dl = add ulong monons 600000000 |
| 764 | for t ulong 1000000 |
| 765 | if ge ulong monons dl |
| 766 | break |
| 767 | end |
| 768 | pt_step c 197 |
| 769 | pt_ok eq get sjst b 2 197 |
| 770 | end |
| 771 | pt_ok eq get suse 0 0 198 |
| 772 | pt_ok eq sched_review p long add get sjid p 1 199 |
| 773 | pt_ok pt_until c b 3 4 2000 199 199 |
| 774 | pt_drain c 3 3000 199 |
| 775 | pt_down c 199 |
| 776 | end |
| 777 | |
| 778 | note Phase M: lease bounds (2^50 ns, about 13 days). Waiting job w refuses |
| 779 | note 2^50 + 1 and 2^64 - 1 (-7) with its lease unchanged (200, 201) and |
| 780 | note accepts 2^50 (202). Job r, leased 2^50 before it is assigned, runs with |
| 781 | note a deadline ahead of the clock and nothing overdue (203); running, it |
| 782 | note refuses both too large values with lease and deadline unchanged (204, |
| 783 | note 205) and accepts a renewal of 2^49 measured from now: the new deadline |
| 784 | note lies between clock + 2^49 read just before and just after the call |
| 785 | note (206), and nothing is overdue; it then completes (207). |
| 786 | fn pt_lbound to void |
| 787 | c = pt_setup 1 8 8 pt_req 2 1024 1 8 200 |
| 788 | mx = ulong 1125899906842624 |
| 789 | w = pt_admit 220050 1 0 200 |
| 790 | pt_ok eq sched_lease w add mx 1 neg long 7 200 |
| 791 | pt_ok eq get sjlse w 0 200 |
| 792 | pt_ok eq sched_lease w sub ulong 0 1 neg long 7 201 |
| 793 | pt_ok eq get sjlse w 0 201 |
| 794 | pt_ok eq sched_lease w mx 0 202 |
| 795 | pt_ok eq get sjlse w mx 202 |
| 796 | r = pt_admit 230600 0 pt_req 1 0 0 0 203 |
| 797 | pt_ok eq sched_lease r mx 0 203 |
| 798 | pt_ok pt_until c r 3 3 2000 203 203 |
| 799 | d = get sjdue r |
| 800 | pt_ok gt d ulong monons 203 |
| 801 | pt_ok eq sched_overdue 64 203 |
| 802 | pt_ok eq sched_lease r sub ulong 0 1 neg long 7 204 |
| 803 | pt_ok and eq get sjdue r d eq get sjlse r mx 204 |
| 804 | pt_ok eq sched_lease r add mx 1 neg long 7 205 |
| 805 | pt_ok and eq get sjdue r d eq get sjlse r mx 205 |
| 806 | w = ulong monons |
| 807 | pt_ok eq sched_lease r div mx 2 0 206 |
| 808 | t2 = ulong monons |
| 809 | pt_ok ge get sjdue r add w div mx 2 206 |
| 810 | pt_ok le get sjdue r add t2 div mx 2 206 |
| 811 | pt_ok eq sched_overdue 64 206 |
| 812 | pt_drain c 1 3000 207 |
| 813 | pt_down c 207 |
| 814 | end |
| 815 | |
| 816 | note Phase N: every ask renews a ticket, a successful one too. Admission |
| 817 | note limit 1, ticket lifetime 2. o waits on a topic nobody publishes and |
| 818 | note fills the limit; X is refused at event e and holds a ticket. o is |
| 819 | note cancelled; at event e + 1 X asks and is told yes, which renews its |
| 820 | note ticket (210). At e + 3 the ticket still holds (asked at e + 1, lifetime |
| 821 | note 2), so newcomer Y is refused (211); at e + 4 it lapses, exactly one |
| 822 | note lapse is counted and Y, now first, is admitted (212). |
| 823 | fn pt_renew to void |
| 824 | c = pt_setup 1 1 8 pt_req 2 1024 1 8 210 |
| 825 | pt_ok eq sched_policy sched_stat 24 64 64 sched_stat 27 2 0 210 |
| 826 | o = pt_admit 240050 1 0 210 |
| 827 | pt_ok eq sched_admitr 250050 0 0 0 neg long 2 210 |
| 828 | pt_ok eq sched_cancel o 1 210 |
| 829 | k = sched_dispatch c |
| 830 | pt_ok sched_room 250050 210 |
| 831 | k = sched_dispatch c |
| 832 | k = sched_dispatch c |
| 833 | pt_ok eq sched_admitr 260050 0 0 0 neg long 2 211 |
| 834 | l0 = sched_stat 11 |
| 835 | k = sched_dispatch c |
| 836 | pt_ok ge sched_admitr 260050 0 0 0 0 212 |
| 837 | pt_ok eq sched_stat 11 add l0 1 212 |
| 838 | pt_drain c 1 3000 212 |
| 839 | pt_down c 212 |
| 840 | end |
| 841 | |
| 842 | note Phase U: the dispatch budget binds. Four idle workers, dispatch budget |
| 843 | note 2, six ready 1-CPU jobs and 4 CPU: one dispatch assigns exactly 2 |
| 844 | note (220); all six then complete (221). |
| 845 | fn pt_budget to void |
| 846 | c = pt_setup 4 16 16 pt_req 4 1024 1 8 220 |
| 847 | pt_ok eq sched_policy sched_stat 24 64 2 sched_stat 27 1000 0 220 |
| 848 | for i ulong 6 |
| 849 | j = pt_admit add 270100 mul i 10000 0 pt_req 1 0 0 0 220 |
| 850 | end |
| 851 | a0 = sched_stat 4 |
| 852 | k = sched_dispatch c |
| 853 | pt_ok and eq k 2 eq sub sched_stat 4 a0 2 220 |
| 854 | pt_drain c 6 5000 221 |
| 855 | pt_down c 221 |
| 856 | end |
| 857 | |
| 858 | fn pt_mode to void |
| 859 | a = new uchar 16 0 |
| 860 | if ne argcnt 2 |
| 861 | ret |
| 862 | end |
| 863 | n = argread 1 a 0 16 |
| 864 | if eq n 4 |
| 865 | if eq get a 0 102 |
| 866 | put ptm 0 1 |
| 867 | end |
| 868 | if eq get a 0 103 |
| 869 | put ptm 0 3 |
| 870 | end |
| 871 | end |
| 872 | if eq n 9 |
| 873 | put ptm 0 2 |
| 874 | end |
| 875 | end |
| 876 | |
| 877 | note Step, then review every job in review in slot order, appending its id |
| 878 | note to the trace and publishing the topics it declared (as the workflow |
| 879 | note does after accepting a result). |
| 880 | fn pt_gstep c long buf edit uchar 4096 code int to void |
| 881 | pt_step c code |
| 882 | for j ulong 64 |
| 883 | if eq get sjst j 4 |
| 884 | p = get sjpro j |
| 885 | n = get ptn 0 |
| 886 | if lt n 16 |
| 887 | put ptt n get sjid j |
| 888 | end |
| 889 | put ptn 0 add n 1 |
| 890 | pt_ok eq sched_review j long add get sjid j 1 code |
| 891 | if ne p 0 |
| 892 | pt_snap |
| 893 | pt_ok gt sched_publish c p buf 16 0 code |
| 894 | pt_check |
| 895 | end |
| 896 | end |
| 897 | end |
| 898 | end |
| 899 | |
| 900 | fn pt_gadmit id ulong deps ulong pro ulong code int to ulong |
| 901 | j = pt_admit id deps pt_req 1 0 0 0 code |
| 902 | if ne pro 0 |
| 903 | pt_ok eq sched_goal j pro 50 10 0 code |
| 904 | end |
| 905 | ret j |
| 906 | end |
| 907 | |
| 908 | note One run of the goal workload, one worker, policy 2, bypass budget 4, |
| 909 | note admitted while paused: x (no value), z (unblocks d: value 1), a |
| 910 | note (unblocks b, which unblocks c: value 2), f (unblocks g1..g3: value 3). |
| 911 | note A decision is made when the worker frees, before the finished job's |
| 912 | note topics are published. Order: f a z b x d c g1 g2 g3. f and a first |
| 913 | note (useful work); x, bypassed in 4 events, is reserved and runs 5th. |
| 914 | fn pt_grun code int to void |
| 915 | buf = new uchar 4096 0 |
| 916 | c = pt_setup 1 16 16 pt_req 1 1024 1 8 code |
| 917 | pt_ok eq sched_policy 2 64 64 4 1000 0 code |
| 918 | k = sched_pause c true |
| 919 | put ptn 0 0 |
| 920 | j = pt_gadmit 220050 0 0 code |
| 921 | j = pt_gadmit 230050 0 128 code |
| 922 | j = pt_gadmit 240050 128 0 code |
| 923 | j = pt_gadmit 250050 0 32 code |
| 924 | j = pt_gadmit 260050 32 64 code |
| 925 | j = pt_gadmit 270050 64 0 code |
| 926 | j = pt_gadmit 280050 0 256 code |
| 927 | for i ulong 3 |
| 928 | j = pt_gadmit add 290050 mul i 10000 256 0 code |
| 929 | end |
| 930 | pt_resume c |
| 931 | dl = add ulong monons 5000000000 |
| 932 | for t ulong 1000000 |
| 933 | if ge get ptn 0 10 |
| 934 | break |
| 935 | end |
| 936 | pt_ok lt ulong monons dl code |
| 937 | pt_gstep c buf code |
| 938 | end |
| 939 | pt_down c code |
| 940 | end |
| 941 | |
| 942 | note Phase G: goal-aware ranking. The goal workload runs twice; both traces |
| 943 | note must equal the expected order (151 first run, 152 second): repeated |
| 944 | note identical inputs, identical decisions. |
| 945 | fn pt_goal to void |
| 946 | ex = new ulong 10 0 |
| 947 | put ex 0 280050 |
| 948 | put ex 1 250050 |
| 949 | put ex 2 230050 |
| 950 | put ex 3 260050 |
| 951 | put ex 4 220050 |
| 952 | put ex 5 240050 |
| 953 | put ex 6 270050 |
| 954 | put ex 7 290050 |
| 955 | put ex 8 300050 |
| 956 | put ex 9 310050 |
| 957 | for r ulong 2 |
| 958 | code = int add 151 r |
| 959 | pt_grun 150 |
| 960 | pt_ok eq get ptn 0 10 code |
| 961 | for i ulong 10 |
| 962 | if ne get ptt i get ex i |
| 963 | pt_trace |
| 964 | exit code |
| 965 | end |
| 966 | end |
| 967 | end |
| 968 | end |
| 969 | |
| 970 | fn pt_trace to void |
| 971 | r = write 1 ptr 0 len ptr |
| 972 | for i ulong get ptn 0 bound 16 |
| 973 | pt_num get ptt i |
| 974 | r = write 1 psp 0 1 |
| 975 | end |
| 976 | r = write 1 pnl 0 1 |
| 977 | end |
| 978 | |
| 979 | note Phase H: rescoring. Policy 2, paused: one ready job r and two jobs |
| 980 | note waiting on topic 512, then r declares topic 512: four graph changes, |
| 981 | note no rescoring (160). The first pick rescores once for all four (161). |
| 982 | note r completing and being reviewed with nothing published changes no |
| 983 | note value: no rescoring (162). Publishing 512 readies both waiting jobs: |
| 984 | note two changes, one more rescoring at the next pick (163). The work of |
| 985 | note every rescoring is bounded (checked at each step, exit 8). Cancelling |
| 986 | note a waiting job is one more change (165). |
| 987 | fn pt_rescores to void |
| 988 | buf = new uchar 4096 0 |
| 989 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 160 |
| 990 | pt_ok eq sched_policy 2 64 64 4 1000 0 160 |
| 991 | k = sched_pause c true |
| 992 | r = pt_admit 320050 0 pt_req 1 0 0 0 160 |
| 993 | w1 = pt_admit 330050 512 pt_req 1 0 0 0 160 |
| 994 | w2 = pt_admit 340050 512 pt_req 1 0 0 0 160 |
| 995 | pt_ok eq sched_goal r 512 50 10 0 160 |
| 996 | pt_ok eq sched_stat 34 4 160 |
| 997 | pt_ok eq sched_stat 32 0 160 |
| 998 | pt_resume c |
| 999 | pt_ok eq sched_stat 32 1 161 |
| 1000 | pt_ok eq get sjval r 2 161 |
| 1001 | pt_drain c 1 2000 162 |
| 1002 | pt_ok eq sched_stat 32 1 162 |
| 1003 | pt_ok eq sched_stat 34 4 162 |
| 1004 | pt_snap |
| 1005 | pt_ok gt sched_publish c 512 buf 16 0 163 |
| 1006 | pt_check |
| 1007 | pt_ok eq sched_stat 34 6 163 |
| 1008 | pt_ok eq sched_stat 32 2 163 |
| 1009 | pt_drain c 2 2000 164 |
| 1010 | pt_ok eq sched_stat 32 2 165 |
| 1011 | w3 = pt_admit 345050 4096 pt_req 1 0 0 0 165 |
| 1012 | b0 = sched_stat 34 |
| 1013 | pt_ok eq sched_cancel w3 1 165 |
| 1014 | pt_ok eq sched_stat 34 add b0 1 165 |
| 1015 | pt_down c 166 |
| 1016 | end |
| 1017 | |
| 1018 | note Phase K: the policy-2 key on two free slots, a and b. Larger unblock |
| 1019 | note value first, even when b is older and cheaper (180); equal values: |
| 1020 | note smaller estimate first, even when b is older (181); equal values and |
| 1021 | note estimates: older admission first (182); outside policy 2 only the |
| 1022 | note admission age counts (183). |
| 1023 | fn pt_key to void |
| 1024 | a = ulong 60 |
| 1025 | b = ulong 61 |
| 1026 | put sjval a 2 |
| 1027 | put sjval b 1 |
| 1028 | put sjest a 90 |
| 1029 | put sjest b 10 |
| 1030 | put sjarr a 9 |
| 1031 | put sjarr b 8 |
| 1032 | pt_ok sp_better true a b 180 |
| 1033 | pt_ok not sp_better true b a 180 |
| 1034 | put sjval b 2 |
| 1035 | put sjest a 10 |
| 1036 | put sjest b 90 |
| 1037 | pt_ok sp_better true a b 181 |
| 1038 | pt_ok not sp_better true b a 181 |
| 1039 | put sjest b 10 |
| 1040 | pt_ok sp_better true b a 182 |
| 1041 | pt_ok not sp_better true a b 182 |
| 1042 | put sjval a 5 |
| 1043 | put sjest b 1 |
| 1044 | pt_ok sp_better false b a 183 |
| 1045 | pt_ok not sp_better false a b 183 |
| 1046 | for i ulong 2 |
| 1047 | put sjval add a i 0 |
| 1048 | put sjest add a i 0 |
| 1049 | put sjarr add a i 0 |
| 1050 | end |
| 1051 | end |
| 1052 | |
| 1053 | note Phase P: proposals. Policy 2, paused. p1 (value 0) and p2 (value 1) |
| 1054 | note are ready. A proposal naming an older graph version is refused (170) |
| 1055 | note and counted (171); one naming an id with no ready job is refused |
| 1056 | note (172); p1 at the current version is accepted (173) and used over the |
| 1057 | note higher ranked p2 (174). A proposal made stale by a later change is |
| 1058 | note rejected when next used and counted: p3 runs by rank, after p2 (175, |
| 1059 | note 176). Outside policy 2: -7 (177). |
| 1060 | fn pt_proposals to void |
| 1061 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 170 |
| 1062 | pt_ok eq sched_incarnate 1 0 170 |
| 1063 | pt_ok eq sched_policy 2 64 64 4 1000 0 170 |
| 1064 | k = sched_pause c true |
| 1065 | p1 = pt_admit 350050 0 pt_req 1 0 0 0 170 |
| 1066 | p2 = pt_admit 360050 0 pt_req 1 0 0 0 170 |
| 1067 | q = pt_admit 370050 1024 pt_req 1 0 0 0 170 |
| 1068 | pt_ok eq sched_goal p2 1024 50 10 0 170 |
| 1069 | v = sched_version |
| 1070 | p3 = pt_admit 380050 0 pt_req 1 0 0 0 170 |
| 1071 | pt_ok eq sched_propose 350050 v neg long 9 170 |
| 1072 | pt_ok eq sched_stat 36 1 171 |
| 1073 | v = sched_version |
| 1074 | pt_ok eq sched_propose 999999 v neg long 3 172 |
| 1075 | pt_ok eq sched_propose 350050 v 0 173 |
| 1076 | pt_resume c |
| 1077 | pt_ok eq get sjst p1 3 174 |
| 1078 | pt_ok eq sched_stat 39 1 174 |
| 1079 | k = sched_pause c true |
| 1080 | v = sched_version |
| 1081 | pt_ok eq sched_propose 380050 v 0 175 |
| 1082 | p4 = pt_admit 390050 2048 pt_req 1 0 0 0 175 |
| 1083 | pt_ok eq sched_goal p3 0 10 1 0 175 |
| 1084 | pt_resume c |
| 1085 | pt_ok pt_until c p2 3 4 2000 175 175 |
| 1086 | pt_ok eq get sjst p3 2 176 |
| 1087 | pt_ok eq sched_stat 39 1 176 |
| 1088 | pt_ok eq sched_stat 36 2 176 |
| 1089 | pt_ok eq sched_cancel p4 1 176 |
| 1090 | pt_ok eq sched_cancel q 1 176 |
| 1091 | pt_drain c 3 3000 176 |
| 1092 | pt_ok eq sched_policy 1 64 64 4 1000 0 177 |
| 1093 | pt_ok eq sched_propose 350050 sched_version neg long 7 177 |
| 1094 | pt_down c 178 |
| 1095 | end |
| 1096 | |
| 1097 | note Phase I: a proposal from an earlier scheduler. Scheduler 1 |
| 1098 | note (incarnation 1) admits a into slot 0 and hands out the version; |
| 1099 | note scheduler 2 (incarnation 2) admits b into slot 0 with as many bumps. |
| 1100 | note There the old version is stale (184); a's id names no job even at the |
| 1101 | note current version, b's is accepted, and incarnation 0 is refused (185). |
| 1102 | fn pt_incarn to void |
| 1103 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 184 |
| 1104 | pt_ok eq sched_incarnate 1 0 184 |
| 1105 | pt_ok eq sched_policy 2 64 64 4 1000 0 184 |
| 1106 | k = sched_pause c true |
| 1107 | a = pt_admit 670050 0 pt_req 1 0 0 0 184 |
| 1108 | pt_ok eq a 0 184 |
| 1109 | v1 = sched_version |
| 1110 | pt_ok eq sched_cancel a 1 184 |
| 1111 | pt_down c 184 |
| 1112 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 184 |
| 1113 | pt_ok eq sched_incarnate 2 0 184 |
| 1114 | pt_ok eq sched_policy 2 64 64 4 1000 0 184 |
| 1115 | k = sched_pause c true |
| 1116 | b = pt_admit 680050 0 pt_req 1 0 0 0 184 |
| 1117 | pt_ok eq b 0 184 |
| 1118 | pt_ok eq sched_propose 670050 v1 neg long 9 184 |
| 1119 | pt_ok eq sched_propose 670050 sched_version neg long 3 185 |
| 1120 | pt_ok eq sched_propose 680050 sched_version 0 185 |
| 1121 | pt_ok eq sched_incarnate 0 neg long 7 185 |
| 1122 | pt_ok eq sched_cancel b 1 185 |
| 1123 | pt_down c 185 |
| 1124 | end |
| 1125 | |
| 1126 | note Phase R2: a proposal beside a reservation. Policy 2, bypass budget 1, |
| 1127 | note two workers, 5 CPU. h (2 CPU, 5 s) runs; then B and B2 (4 CPU each) |
| 1128 | note and s1 (1 CPU, 1.5 s) are admitted: s1 runs, B and B2 are bypassed and |
| 1129 | note B, the older, is reserved. x (2 CPU) is refused beside it and counted |
| 1130 | note (186). Cancelling B clears the reservation and x is accepted (187). |
| 1131 | note An event with no idle worker reserves B2 and leaves the proposal |
| 1132 | note pending (188). Once s1 is done, the next pick finds x no longer fits |
| 1133 | note beside B2: the proposal is dropped and counted stale, and x does not |
| 1134 | note run (189). Once h is done B2 fits; y (1 CPU) is accepted beside it, |
| 1135 | note and at the next event B2 runs first, then y is used; x (2 CPU, 0 |
| 1136 | note left) stays ready and, bypassed by y, is now the reservation (179). |
| 1137 | fn pt_propres to void |
| 1138 | c = pt_setup 2 8 8 pt_req 5 1024 2 8 186 |
| 1139 | pt_ok eq sched_incarnate 1 0 186 |
| 1140 | pt_ok eq sched_policy 2 64 64 1 1000 0 186 |
| 1141 | k = sched_pause c true |
| 1142 | h = pt_admit 625000 0 pt_req 2 0 0 0 186 |
| 1143 | pt_resume c |
| 1144 | k = sched_pause c true |
| 1145 | pt_ok eq get sjst h 3 186 |
| 1146 | b = pt_admit 630050 0 pt_req 4 0 0 0 186 |
| 1147 | b2 = pt_admit 640050 0 pt_req 4 0 0 0 186 |
| 1148 | s1 = pt_admit 651500 0 pt_req 1 0 0 0 186 |
| 1149 | pt_resume c |
| 1150 | k = sched_pause c true |
| 1151 | pt_ok eq get sjst s1 3 186 |
| 1152 | pt_ok eq sched_stat 29 add b 1 186 |
| 1153 | x = pt_admit 660050 0 pt_req 2 0 0 0 186 |
| 1154 | r0 = sched_stat 37 |
| 1155 | pt_ok eq sched_propose 660050 sched_version neg long 8 186 |
| 1156 | pt_ok eq sched_stat 37 add r0 1 186 |
| 1157 | pt_ok eq sched_cancel b 1 187 |
| 1158 | pt_ok eq sched_stat 29 0 187 |
| 1159 | pt_ok eq sched_propose 660050 sched_version 0 187 |
| 1160 | pt_resume c |
| 1161 | k = sched_pause c true |
| 1162 | pt_ok eq sched_stat 29 add b2 1 188 |
| 1163 | pt_ok gt get scgv 2 0 188 |
| 1164 | pt_ok pt_until c s1 4 4 3000 188 188 |
| 1165 | s0 = sched_stat 36 |
| 1166 | pt_resume c |
| 1167 | k = sched_pause c true |
| 1168 | pt_ok eq sched_stat 36 add s0 1 189 |
| 1169 | pt_ok eq get sjst x 2 189 |
| 1170 | pt_ok eq get scgv 2 0 189 |
| 1171 | y = pt_admit 690050 0 pt_req 1 0 0 0 179 |
| 1172 | pt_ok pt_until c h 4 4 6000 179 179 |
| 1173 | pt_ok eq sched_propose 690050 sched_version 0 179 |
| 1174 | s0 = sched_stat 39 |
| 1175 | pt_resume c |
| 1176 | k = sched_pause c true |
| 1177 | pt_ok eq get sjst b2 3 179 |
| 1178 | pt_ok eq get sjst y 3 179 |
| 1179 | pt_ok eq sched_stat 39 add s0 1 179 |
| 1180 | pt_ok eq sched_stat 29 add x 1 179 |
| 1181 | pt_ok eq get sjst x 2 179 |
| 1182 | pt_ok eq sched_cancel x 1 179 |
| 1183 | pt_drain c 4 8000 179 |
| 1184 | pt_down c 189 |
| 1185 | end |
| 1186 | |
| 1187 | fn pt_stats to void |
| 1188 | r = write 1 pst 0 len pst |
| 1189 | pt_num sched_stat 2 |
| 1190 | r = write 1 pex 0 len pex |
| 1191 | pt_num sched_stat 3 |
| 1192 | r = write 1 pas 0 len pas |
| 1193 | pt_num sched_stat 4 |
| 1194 | r = write 1 phol 0 len phol |
| 1195 | pt_num sched_stat 8 |
| 1196 | r = write 1 pbyp 0 len pbyp |
| 1197 | pt_num sched_stat 5 |
| 1198 | r = write 1 pres 0 len pres |
| 1199 | pt_num sched_stat 6 |
| 1200 | r = write 1 pnl 0 1 |
| 1201 | end |
| 1202 | |
| 1203 | note Phase X: proposal guards. Without an incarnation a proposal is refused |
| 1204 | note (120); a second incarnation is refused (121); after the first one a |
| 1205 | note proposal is accepted and used (122). The version is then set to the |
| 1206 | note last revision of incarnation 5 (2^40 - 1 bumps): a proposal made there |
| 1207 | note is accepted, and the next bump exhausts the version instead of |
| 1208 | note carrying it into incarnation 6's range (123); proposals are refused |
| 1209 | note (124), the pending one is dropped at use (125) and every pick rescores |
| 1210 | note (126). In a new scheduler, two ready jobs share an id: a proposal |
| 1211 | note naming it is refused (127). |
| 1212 | fn pt_incx to void |
| 1213 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 120 |
| 1214 | pt_ok eq sched_policy 2 64 64 4 1000 0 120 |
| 1215 | k = sched_pause c true |
| 1216 | a = pt_admit 710050 0 pt_req 1 0 0 0 120 |
| 1217 | pt_ok eq sched_propose 710050 sched_version neg long 6 120 |
| 1218 | pt_ok eq sched_stat 41 0 120 |
| 1219 | pt_ok eq sched_incarnate 5 0 121 |
| 1220 | pt_ok eq sched_incarnate 6 neg long 7 121 |
| 1221 | pt_ok eq sched_propose 710050 sched_version 0 122 |
| 1222 | pt_ok eq sp_proposal 0 a 122 |
| 1223 | put scgv 0 add shl ulong 5 40 1099511627775 |
| 1224 | v = sched_version |
| 1225 | pt_ok eq sched_propose 710050 v 0 123 |
| 1226 | pt_ok eq sched_goal a 0 10 1 0 123 |
| 1227 | pt_ok eq sched_version v 123 |
| 1228 | pt_ok eq shr sched_version 40 5 123 |
| 1229 | pt_ok eq sched_stat 41 2 123 |
| 1230 | pt_ok eq sched_propose 710050 v neg long 6 124 |
| 1231 | pt_ok eq sp_proposal 0 64 125 |
| 1232 | r0 = sched_stat 32 |
| 1233 | sp_rescore |
| 1234 | sp_rescore |
| 1235 | pt_ok eq sched_stat 32 add r0 2 126 |
| 1236 | pt_ok eq sched_cancel a 1 126 |
| 1237 | pt_down c 126 |
| 1238 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 127 |
| 1239 | pt_ok eq sched_incarnate 7 0 127 |
| 1240 | pt_ok eq sched_policy 2 64 64 4 1000 0 127 |
| 1241 | k = sched_pause c true |
| 1242 | b1 = pt_admit 720050 0 pt_req 1 0 0 0 127 |
| 1243 | b2 = pt_admit 720050 0 pt_req 1 0 0 0 127 |
| 1244 | pt_ok ne b1 b2 127 |
| 1245 | pt_ok eq sched_propose 720050 sched_version neg long 3 127 |
| 1246 | pt_ok eq sched_cancel b1 1 127 |
| 1247 | pt_ok eq sched_cancel b2 1 127 |
| 1248 | pt_down c 127 |
| 1249 | end |
| 1250 | |
| 1251 | note Phase L: a late first incarnation must not mark stale values current. |
| 1252 | note Paused, one worker, policy 2: an older unrelated job u, a younger |
| 1253 | note producer p declaring topic 64 and a job d waiting on it are admitted |
| 1254 | note and declared, then the scheduler incarnates. At resume the one pick |
| 1255 | note rescores and takes p (value 1); with the values left unscored they all |
| 1256 | note read 0 and u (older, no estimate) would run instead (128). |
| 1257 | fn pt_incl to void |
| 1258 | c = pt_setup 1 8 8 pt_req 4 1024 1 8 128 |
| 1259 | pt_ok eq sched_policy 2 64 64 4 1000 0 128 |
| 1260 | k = sched_pause c true |
| 1261 | u = pt_admit 730300 0 pt_req 1 0 0 0 128 |
| 1262 | p = pt_admit 740300 0 pt_req 1 0 0 0 128 |
| 1263 | d = pt_admit 750300 64 pt_req 1 0 0 0 128 |
| 1264 | pt_ok eq sched_goal p 64 300 0 0 128 |
| 1265 | pt_ok eq sched_incarnate 8 0 128 |
| 1266 | pt_resume c |
| 1267 | pt_ok eq get sjst p 3 128 |
| 1268 | pt_ok eq get sjst u 2 128 |
| 1269 | pt_ok eq sched_cancel u 1 128 |
| 1270 | pt_ok eq sched_cancel d 1 128 |
| 1271 | pt_drain c 1 3000 128 |
| 1272 | pt_down c 128 |
| 1273 | end |
| 1274 | |
| 1275 | note The regression phases A and B return their verdict, so both run and |
| 1276 | note print their witness; the first failing one is the exit status. |
| 1277 | fn main to int |
| 1278 | pt_mode |
| 1279 | pt_impossible |
| 1280 | pt_churn |
| 1281 | pt_release |
| 1282 | pt_order |
| 1283 | ra = pt_blocked |
| 1284 | rb = pt_exclude |
| 1285 | if ne ra 0 |
| 1286 | ret ra |
| 1287 | end |
| 1288 | if ne rb 0 |
| 1289 | ret rb |
| 1290 | end |
| 1291 | pt_starve |
| 1292 | pt_tickets |
| 1293 | pt_lease |
| 1294 | pt_rcancel |
| 1295 | pt_window |
| 1296 | pt_torder |
| 1297 | pt_slots |
| 1298 | pt_live |
| 1299 | pt_goal |
| 1300 | pt_rescores |
| 1301 | pt_proposals |
| 1302 | pt_incarn |
| 1303 | pt_propres |
| 1304 | pt_incx |
| 1305 | pt_incl |
| 1306 | pt_key |
| 1307 | pt_lbound |
| 1308 | pt_renew |
| 1309 | pt_budget |
| 1310 | if ne write 1 pok 0 len pok long len pok |
| 1311 | ret 100 |
| 1312 | end |
| 1313 | ret 0 |
| 1314 | end |