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 / sched-gate.om
| 1 | note Omega Node transport, concatenate with a program-mode consumer. |
| 2 | note Trusted forked processes only. This is transport, not write authority. |
| 3 | note One publisher PID, 64 immutable records per epoch; reuse only via node_reset. |
| 4 | note Layout: 4096 byte header then 64 slots of 4160 bytes. |
| 5 | note Header u64: magic, ABI, published count, stop, publisher PID, epoch. |
| 6 | note Slot u64: version, length, topic mask; payload begins at offset 64. |
| 7 | const NCAP ulong 64 |
| 8 | const NBYTES ulong 270336 |
| 9 | const NMAGIC ulong 1313817669 |
| 10 | |
| 11 | fn node_new to long |
| 12 | h = mapnew neg int 1 0 NBYTES 3 33 |
| 13 | if le h 0 |
| 14 | ret h |
| 15 | end |
| 16 | r = mapset h 8 8 1 |
| 17 | r = mapset h 32 8 ulong getpid |
| 18 | r = mapset h 0 8 NMAGIC |
| 19 | ret h |
| 20 | end |
| 21 | |
| 22 | fn node_valid h long to bool |
| 23 | ret and eq mapget h 0 8 NMAGIC eq mapget h 8 8 1 |
| 24 | end |
| 25 | |
| 26 | fn node_offset v ulong to ulong |
| 27 | ret add 4096 mul sub v 1 4160 |
| 28 | end |
| 29 | |
| 30 | note Return version, or -1 stopped, -2 full, -3 length, -4 topic, |
| 31 | note -5 invalid header, -6 wrong publisher. Refusals do not publish. |
| 32 | fn node_publish h long topics ulong src view uchar 4096 n ulong to long |
| 33 | if not node_valid h |
| 34 | ret neg long 5 |
| 35 | end |
| 36 | if ne mapget h 32 8 ulong getpid |
| 37 | ret neg long 6 |
| 38 | end |
| 39 | if ne mapget h 24 8 0 |
| 40 | ret neg long 1 |
| 41 | end |
| 42 | if gt n 4096 |
| 43 | ret neg long 3 |
| 44 | end |
| 45 | if eq topics 0 |
| 46 | ret neg long 4 |
| 47 | end |
| 48 | v = mapget h 16 8 |
| 49 | if gt v NCAP |
| 50 | ret neg long 5 |
| 51 | end |
| 52 | if eq v NCAP |
| 53 | ret neg long 2 |
| 54 | end |
| 55 | v = add v 1 |
| 56 | off = node_offset v |
| 57 | r = mapwrite h add off 64 src 0 n |
| 58 | r = mapset h add off 8 8 n |
| 59 | r = mapset h add off 16 8 topics |
| 60 | note mapset has barriers before and after its aligned store. |
| 61 | r = mapset h off 8 v |
| 62 | r = mapset h 16 8 v |
| 63 | ret long v |
| 64 | end |
| 65 | |
| 66 | note Header and record checks precede copying. No partial publication is read. |
| 67 | note Returns payload length, -5 invalid header/record, -7 unavailable version. |
| 68 | fn node_read h long v ulong dst edit uchar 4096 to long |
| 69 | if not node_valid h |
| 70 | ret neg long 5 |
| 71 | end |
| 72 | if or eq v 0 gt v NCAP |
| 73 | ret neg long 7 |
| 74 | end |
| 75 | latest = mapget h 16 8 |
| 76 | if gt latest NCAP |
| 77 | ret neg long 5 |
| 78 | end |
| 79 | if gt v latest |
| 80 | ret neg long 7 |
| 81 | end |
| 82 | off = node_offset v |
| 83 | if ne mapget h off 8 v |
| 84 | ret neg long 5 |
| 85 | end |
| 86 | n = mapget h add off 8 8 |
| 87 | if gt n 4096 |
| 88 | ret neg long 5 |
| 89 | end |
| 90 | ret mapread h add off 64 dst 0 n |
| 91 | end |
| 92 | |
| 93 | note Return the next matching version after cursor, zero if caught up, |
| 94 | note or negative refusal. Caller advances its cursor through returned versions. |
| 95 | fn node_next h long cursor ulong topics ulong to long |
| 96 | if not node_valid h |
| 97 | ret neg long 5 |
| 98 | end |
| 99 | if or gt cursor NCAP eq topics 0 |
| 100 | ret neg long 7 |
| 101 | end |
| 102 | latest = mapget h 16 8 |
| 103 | if or gt latest NCAP gt cursor latest |
| 104 | ret neg long 5 |
| 105 | end |
| 106 | v = cursor |
| 107 | note At most NCAP published slots can be examined. |
| 108 | while lt v latest bound 64 |
| 109 | v = add v 1 |
| 110 | off = node_offset v |
| 111 | if ne mapget h off 8 v |
| 112 | ret neg long 5 |
| 113 | end |
| 114 | if ne and mapget h add off 16 8 topics 0 |
| 115 | ret long v |
| 116 | end |
| 117 | end |
| 118 | ret 0 |
| 119 | end |
| 120 | |
| 121 | fn node_stop h long to long |
| 122 | if not node_valid h |
| 123 | ret neg long 5 |
| 124 | end |
| 125 | if ne mapget h 32 8 ulong getpid |
| 126 | ret neg long 6 |
| 127 | end |
| 128 | ret mapset h 24 8 1 |
| 129 | end |
| 130 | |
| 131 | note Creator only. Retire every record so a pool can reuse the arena for a new |
| 132 | note epoch. The caller must first prove no reader holds the old epoch (pool.om). |
| 133 | note The count drops to zero before any record version is cleared. |
| 134 | fn node_reset h long epoch ulong to long |
| 135 | if not node_valid h |
| 136 | ret neg long 5 |
| 137 | end |
| 138 | if ne mapget h 32 8 ulong getpid |
| 139 | ret neg long 6 |
| 140 | end |
| 141 | if eq epoch 0 |
| 142 | ret neg long 7 |
| 143 | end |
| 144 | r = mapset h 16 8 0 |
| 145 | for i ulong NCAP |
| 146 | r = mapset h node_offset add i 1 8 0 |
| 147 | end |
| 148 | r = mapset h 24 8 0 |
| 149 | r = mapset h 40 8 epoch |
| 150 | ret 0 |
| 151 | end |
| 152 | |
| 153 | fn node_epoch h long to ulong |
| 154 | ret mapget h 40 8 |
| 155 | end |
| 156 | |
| 157 | note The latest published version of the arena's current epoch (0 when empty). |
| 158 | fn node_count h long to ulong |
| 159 | ret mapget h 16 8 |
| 160 | end |
| 161 | |
| 162 | note One nonblocking eventfd per consumer. Saturation means already readable. |
| 163 | note Interrupted operations retry at most 64 times, then return EINTR. |
| 164 | fn node_notify fd int to long |
| 165 | buf = new uchar 8 0 |
| 166 | put buf 0 1 |
| 167 | for i ulong 64 |
| 168 | r = write fd buf 0 8 |
| 169 | if eq r 8 |
| 170 | ret 0 |
| 171 | end |
| 172 | if eq r neg long 11 |
| 173 | ret 0 |
| 174 | end |
| 175 | if ne r neg long 4 |
| 176 | if lt r 0 |
| 177 | ret r |
| 178 | end |
| 179 | ret neg long 5 |
| 180 | end |
| 181 | end |
| 182 | ret neg long 4 |
| 183 | end |
| 184 | |
| 185 | fn node_drain fd int to long |
| 186 | buf = new uchar 8 0 |
| 187 | for i ulong 64 |
| 188 | r = read fd buf 0 8 |
| 189 | if or eq r 8 eq r neg long 11 |
| 190 | ret 0 |
| 191 | end |
| 192 | if ne r neg long 4 |
| 193 | if lt r 0 |
| 194 | ret r |
| 195 | end |
| 196 | ret neg long 5 |
| 197 | end |
| 198 | end |
| 199 | ret neg long 4 |
| 200 | end |
| 201 | |
| 202 | fn node_pollfd p edit uchar 16 off ulong fd int to void |
| 203 | for i ulong 4 |
| 204 | put p add off i uchar and shr uint fd uint mul i 8 255 |
| 205 | end |
| 206 | put p add off 4 1 |
| 207 | end |
| 208 | |
| 209 | note Returns 2 stop, 1 wake, 0 timeout or negative errno. |
| 210 | note Control takes priority when both descriptors are ready. |
| 211 | note EINTR returns to caller so it can recompute its monotonic deadline. |
| 212 | fn node_wait h long wake int stop int interval long to long |
| 213 | p = new uchar 16 0 |
| 214 | if not node_valid h |
| 215 | ret neg long 5 |
| 216 | end |
| 217 | if or lt wake 0 lt stop 0 |
| 218 | ret neg long 9 |
| 219 | end |
| 220 | if eq wake stop |
| 221 | ret neg long 22 |
| 222 | end |
| 223 | if ne mapget h 24 8 0 |
| 224 | ret 2 |
| 225 | end |
| 226 | node_pollfd p 0 wake |
| 227 | node_pollfd p 8 stop |
| 228 | r = pollfds p 0 16 interval |
| 229 | if lt r 0 |
| 230 | ret r |
| 231 | end |
| 232 | if ne mapget h 24 8 0 |
| 233 | ret 2 |
| 234 | end |
| 235 | if ne and get p 14 56 0 |
| 236 | ret neg long 5 |
| 237 | end |
| 238 | if ne and get p 14 1 0 |
| 239 | r = node_drain stop |
| 240 | if lt r 0 |
| 241 | ret r |
| 242 | end |
| 243 | ret 2 |
| 244 | end |
| 245 | if ne and get p 6 56 0 |
| 246 | ret neg long 5 |
| 247 | end |
| 248 | if ne and get p 6 1 0 |
| 249 | r = node_drain wake |
| 250 | if lt r 0 |
| 251 | ret r |
| 252 | end |
| 253 | ret 1 |
| 254 | end |
| 255 | ret 0 |
| 256 | end |
| 257 | note Omega Node epoch pool. Concatenate after transport.om, before super.om. |
| 258 | note K arenas (1..8) and one control page are mapped before any worker fork, |
| 259 | note so every forked worker inherits the same shared mappings. |
| 260 | note Single writer: the creator writes the current epoch, the arena table and |
| 261 | note every arena record. Worker w alone writes hold word w while it lives; |
| 262 | note the creator clears hold w only after it has reaped worker w. |
| 263 | note Control u64: 0 magic, 8 ABI, 16 current epoch, 24 stop, 32 creator PID, |
| 264 | note 40 arena count K, 48 worker slots W, 64+8k arena handle k, |
| 265 | note 128+8k epoch of arena k (0 free), 256+8w hold of worker w (0 none), |
| 266 | note 768+8w worker PID, 1280+8w worker state (0 empty, 1 live, 2 reaped). |
| 267 | const PMAGIC ulong 1347374924 |
| 268 | const PCAP ulong 8 |
| 269 | const PWCAP ulong 64 |
| 270 | const PBYTES ulong 4096 |
| 271 | |
| 272 | fn pool_valid c long to bool |
| 273 | ret and eq mapget c 0 8 PMAGIC eq mapget c 8 8 1 |
| 274 | end |
| 275 | |
| 276 | fn pool_mine c long to bool |
| 277 | ret eq mapget c 32 8 ulong getpid |
| 278 | end |
| 279 | |
| 280 | fn pool_arena c long k ulong to long |
| 281 | ret long mapget c add 64 mul k 8 8 |
| 282 | end |
| 283 | |
| 284 | note Drop the first n arenas and the control page of a pool being refused. |
| 285 | fn pool_unwind c long n ulong to long |
| 286 | for i ulong n bound 8 |
| 287 | r = mapdrop pool_arena c i |
| 288 | end |
| 289 | ret mapdrop c |
| 290 | end |
| 291 | |
| 292 | note Return the control handle, or -7 bad size, or a negative mapping errno. |
| 293 | note Arena 0 starts as epoch 1. Call before forking any worker. |
| 294 | fn pool_new k ulong w ulong to long |
| 295 | if or eq k 0 gt k PCAP |
| 296 | ret neg long 7 |
| 297 | end |
| 298 | if or eq w 0 gt w PWCAP |
| 299 | ret neg long 7 |
| 300 | end |
| 301 | c = mapnew neg int 1 0 PBYTES 3 33 |
| 302 | if le c 0 |
| 303 | ret c |
| 304 | end |
| 305 | r = mapset c 32 8 ulong getpid |
| 306 | r = mapset c 40 8 k |
| 307 | r = mapset c 48 8 w |
| 308 | for i ulong k bound 8 |
| 309 | h = node_new |
| 310 | if le h 0 |
| 311 | r = pool_unwind c i |
| 312 | ret h |
| 313 | end |
| 314 | r = mapset c add 64 mul i 8 8 ulong h |
| 315 | end |
| 316 | r = node_reset pool_arena c 0 1 |
| 317 | r = mapset c 128 8 1 |
| 318 | r = mapset c 16 8 1 |
| 319 | r = mapset c 8 8 1 |
| 320 | r = mapset c 0 8 PMAGIC |
| 321 | ret c |
| 322 | end |
| 323 | |
| 324 | note Arena index holding epoch e, or -5 when no arena holds it. |
| 325 | fn pool_slot c long e ulong to long |
| 326 | k = mapget c 40 8 |
| 327 | if gt k PCAP |
| 328 | ret neg long 5 |
| 329 | end |
| 330 | for i ulong k bound 8 |
| 331 | if eq mapget c add 128 mul i 8 8 e |
| 332 | ret long i |
| 333 | end |
| 334 | end |
| 335 | ret neg long 5 |
| 336 | end |
| 337 | |
| 338 | note Creator: the arena of the current epoch, or a negative refusal. |
| 339 | fn pool_current c long to long |
| 340 | if not pool_valid c |
| 341 | ret neg long 5 |
| 342 | end |
| 343 | k = pool_slot c mapget c 16 8 |
| 344 | if lt k 0 |
| 345 | ret k |
| 346 | end |
| 347 | ret pool_arena c ulong k |
| 348 | end |
| 349 | |
| 350 | fn pool_epoch c long to ulong |
| 351 | ret mapget c 16 8 |
| 352 | end |
| 353 | |
| 354 | note Worker step: store hold e for worker w, then read the epoch again. mapset |
| 355 | note and mapget fence both sides, so a creator that moved the epoch before it |
| 356 | note scanned holds either sees this hold or this read sees the move. Returns |
| 357 | note the arena of e, -8 when the epoch moved, or -5 when no arena holds e. |
| 358 | note Every refusal clears the hold. |
| 359 | fn pool_hold c long w ulong e ulong to long |
| 360 | if ge w mapget c 48 8 |
| 361 | ret neg long 7 |
| 362 | end |
| 363 | hw = add 256 mul w 8 |
| 364 | r = mapset c hw 8 e |
| 365 | if ne mapget c 16 8 e |
| 366 | r = mapset c hw 8 0 |
| 367 | ret neg long 8 |
| 368 | end |
| 369 | k = pool_slot c e |
| 370 | if lt k 0 |
| 371 | r = mapset c hw 8 0 |
| 372 | ret k |
| 373 | end |
| 374 | h = pool_arena c ulong k |
| 375 | if ne node_epoch h e |
| 376 | r = mapset c hw 8 0 |
| 377 | ret neg long 5 |
| 378 | end |
| 379 | ret h |
| 380 | end |
| 381 | |
| 382 | note Worker w holds the current epoch and returns its arena. Returns -1 |
| 383 | note stopped, -5 invalid, -7 bad worker, -8 the epoch kept moving. |
| 384 | fn pool_acquire c long w ulong to long |
| 385 | if not pool_valid c |
| 386 | ret neg long 5 |
| 387 | end |
| 388 | if ge w mapget c 48 8 |
| 389 | ret neg long 7 |
| 390 | end |
| 391 | for t ulong 16 |
| 392 | if ne mapget c 24 8 0 |
| 393 | r = mapset c add 256 mul w 8 8 0 |
| 394 | ret neg long 1 |
| 395 | end |
| 396 | h = pool_hold c w mapget c 16 8 |
| 397 | if ne h neg long 8 |
| 398 | ret h |
| 399 | end |
| 400 | end |
| 401 | ret neg long 8 |
| 402 | end |
| 403 | |
| 404 | note Worker w gives up its hold. Its old arena must not be read afterwards. |
| 405 | fn pool_release c long w ulong to long |
| 406 | if ge w mapget c 48 8 |
| 407 | ret neg long 7 |
| 408 | end |
| 409 | ret mapset c add 256 mul w 8 8 0 |
| 410 | end |
| 411 | |
| 412 | fn pool_held c long e ulong to bool |
| 413 | n = mapget c 48 8 |
| 414 | for w ulong n bound 64 |
| 415 | if eq mapget c add 256 mul w 8 8 e |
| 416 | ret true |
| 417 | end |
| 418 | end |
| 419 | ret false |
| 420 | end |
| 421 | |
| 422 | note Creator step: retire arena i and open epoch n in it, then publish n. |
| 423 | fn pool_reuse c long i ulong n ulong to long |
| 424 | off = add 128 mul i 8 |
| 425 | r = mapset c off 8 0 |
| 426 | r = node_reset pool_arena c i n |
| 427 | if lt r 0 |
| 428 | ret r |
| 429 | end |
| 430 | r = mapset c off 8 n |
| 431 | r = mapset c 16 8 n |
| 432 | ret long n |
| 433 | end |
| 434 | |
| 435 | note Creator step: an arena that is free or whose older epoch no worker holds, |
| 436 | note or -9. Call only after the current epoch has moved past that arena. |
| 437 | fn pool_pick c long to long |
| 438 | e = mapget c 16 8 |
| 439 | k = mapget c 40 8 |
| 440 | for i ulong k bound 8 |
| 441 | ek = mapget c add 128 mul i 8 8 |
| 442 | if ne ek e |
| 443 | if or eq ek 0 not pool_held c ek |
| 444 | ret long i |
| 445 | end |
| 446 | end |
| 447 | end |
| 448 | ret neg long 9 |
| 449 | end |
| 450 | |
| 451 | note Creator: open the next epoch in a free or unheld arena and make it current. |
| 452 | note Returns the new epoch, -1 stopped, -5 invalid, -6 not creator, or -9 when |
| 453 | note every other arena is still held: the pool fails closed, nothing changes. |
| 454 | fn pool_roll c long to long |
| 455 | if not pool_valid c |
| 456 | ret neg long 5 |
| 457 | end |
| 458 | if not pool_mine c |
| 459 | ret neg long 6 |
| 460 | end |
| 461 | if ne mapget c 24 8 0 |
| 462 | ret neg long 1 |
| 463 | end |
| 464 | k = pool_pick c |
| 465 | if lt k 0 |
| 466 | ret k |
| 467 | end |
| 468 | ret pool_reuse c ulong k add mapget c 16 8 1 |
| 469 | end |
| 470 | |
| 471 | note Creator: publish to the current epoch; when it is full, roll once and retry. |
| 472 | note Returns the version, or the refusal of the publish or of the roll. |
| 473 | fn pool_publish c long topics ulong src view uchar 4096 n ulong to long |
| 474 | h = pool_current c |
| 475 | if lt h 0 |
| 476 | ret h |
| 477 | end |
| 478 | v = node_publish h topics src n |
| 479 | if ne v neg long 2 |
| 480 | ret v |
| 481 | end |
| 482 | r = pool_roll c |
| 483 | if lt r 0 |
| 484 | ret r |
| 485 | end |
| 486 | h = pool_current c |
| 487 | if lt h 0 |
| 488 | ret h |
| 489 | end |
| 490 | ret node_publish h topics src n |
| 491 | end |
| 492 | |
| 493 | fn pool_stop c long to long |
| 494 | if not pool_valid c |
| 495 | ret neg long 5 |
| 496 | end |
| 497 | if not pool_mine c |
| 498 | ret neg long 6 |
| 499 | end |
| 500 | ret mapset c 24 8 1 |
| 501 | end |
| 502 | |
| 503 | fn pool_stopped c long to bool |
| 504 | ret ne mapget c 24 8 0 |
| 505 | end |
| 506 | |
| 507 | note Creator: record worker w's PID and state for observers. |
| 508 | fn pool_setw c long w ulong pid ulong st ulong to long |
| 509 | if not pool_mine c |
| 510 | ret neg long 6 |
| 511 | end |
| 512 | if ge w mapget c 48 8 |
| 513 | ret neg long 7 |
| 514 | end |
| 515 | r = mapset c add 768 mul w 8 8 pid |
| 516 | ret mapset c add 1280 mul w 8 8 st |
| 517 | end |
| 518 | |
| 519 | note Creator: clear hold w. Only after worker w has been reaped. |
| 520 | fn pool_clear c long w ulong to long |
| 521 | if not pool_mine c |
| 522 | ret neg long 6 |
| 523 | end |
| 524 | if ge w mapget c 48 8 |
| 525 | ret neg long 7 |
| 526 | end |
| 527 | ret mapset c add 256 mul w 8 8 0 |
| 528 | end |
| 529 | |
| 530 | note Drop every mapping of the pool in this process. Other processes keep |
| 531 | note their own inherited mappings until they drop them or exit. |
| 532 | fn pool_free c long to long |
| 533 | ret pool_unwind c mapget c 40 8 |
| 534 | end |
| 535 | note Omega Node worker supervision. Concatenate after transport.om and pool.om. |
| 536 | note The creator forks trusted workers from its own binary: sup_spawn returns 0 |
| 537 | note in the child, which runs its worker function and exits with its result. |
| 538 | note Death is seen without polling PIDs. Worker w alone holds the write end of |
| 539 | note its close-on-exec life pipe, so its exit hangs up the creator's read end. |
| 540 | note Every worker holds the read end of the creator's life pipe, whose only |
| 541 | note writer is the creator, so creator death hangs up every worker. |
| 542 | note Per worker: wake, stop and ack eventfds, kept across respawns. |
| 543 | note Workers must not exec: exec closes the life pipe and reads as death. |
| 544 | global swpid long 64 |
| 545 | global swwake int 64 |
| 546 | global swstop int 64 |
| 547 | global swack int 64 |
| 548 | global swlife int 64 |
| 549 | global swst ulong 64 |
| 550 | global swpw ulong 64 |
| 551 | global swpar int 2 |
| 552 | global swme ulong 1 |
| 553 | global swws uchar 4 |
| 554 | global swpf uchar 8 |
| 555 | global swpoll uchar 1024 |
| 556 | |
| 557 | fn sup_fd off ulong to int |
| 558 | v = ulong get swpf off |
| 559 | v = or v shl ulong get swpf add off 1 8 |
| 560 | v = or v shl ulong get swpf add off 2 16 |
| 561 | v = or v shl ulong get swpf add off 3 24 |
| 562 | ret int v |
| 563 | end |
| 564 | |
| 565 | note Poll record j at swpoll offset off; a negative fd is stored as itself |
| 566 | note (bit pattern) so the kernel ignores that record. |
| 567 | fn sup_gpfd off ulong fd int to void |
| 568 | u = bitcast uint fd |
| 569 | for i ulong 4 |
| 570 | put swpoll add off i uchar and shr u uint mul i 8 255 |
| 571 | end |
| 572 | put swpoll add off 4 1 |
| 573 | put swpoll add off 5 0 |
| 574 | put swpoll add off 6 0 |
| 575 | put swpoll add off 7 0 |
| 576 | end |
| 577 | |
| 578 | fn sup_lpfd p edit uchar 24 off ulong fd int to void |
| 579 | for i ulong 4 |
| 580 | put p add off i uchar and shr uint fd uint mul i 8 255 |
| 581 | end |
| 582 | put p add off 4 1 |
| 583 | end |
| 584 | |
| 585 | note Read and reset an eventfd counter: the number of hints since the last |
| 586 | note take, 0 when none is pending, or a negative errno. |
| 587 | fn sup_take fd int to long |
| 588 | buf = new uchar 8 0 |
| 589 | for i ulong 64 |
| 590 | r = read fd buf 0 8 |
| 591 | if eq r 8 |
| 592 | v = ulong 0 |
| 593 | for j ulong 8 |
| 594 | v = or v shl ulong get buf j mul j 8 |
| 595 | end |
| 596 | ret long and v 9223372036854775807 |
| 597 | end |
| 598 | if eq r neg long 11 |
| 599 | ret 0 |
| 600 | end |
| 601 | if ne r neg long 4 |
| 602 | if lt r 0 |
| 603 | ret r |
| 604 | end |
| 605 | ret neg long 5 |
| 606 | end |
| 607 | end |
| 608 | ret neg long 4 |
| 609 | end |
| 610 | |
| 611 | fn sup_closeall to void |
| 612 | for i ulong 64 |
| 613 | if ge get swwake i 0 |
| 614 | r = fclose get swwake i |
| 615 | end |
| 616 | if ge get swstop i 0 |
| 617 | r = fclose get swstop i |
| 618 | end |
| 619 | if ge get swack i 0 |
| 620 | r = fclose get swack i |
| 621 | end |
| 622 | if ge get swlife i 0 |
| 623 | r = fclose get swlife i |
| 624 | end |
| 625 | put swwake i neg int 1 |
| 626 | put swstop i neg int 1 |
| 627 | put swack i neg int 1 |
| 628 | put swlife i neg int 1 |
| 629 | end |
| 630 | for i ulong 2 |
| 631 | if ge get swpar i 0 |
| 632 | r = fclose get swpar i |
| 633 | end |
| 634 | put swpar i neg int 1 |
| 635 | end |
| 636 | end |
| 637 | |
| 638 | note Creator: create the creator life pipe and three eventfds per worker slot. |
| 639 | note Call once after pool_new and before sup_spawn. 0 or a negative errno; |
| 640 | note a failure closes everything this call opened. |
| 641 | fn sup_init c long to long |
| 642 | if not pool_mine c |
| 643 | ret neg long 6 |
| 644 | end |
| 645 | for i ulong 64 |
| 646 | put swpid i 0 |
| 647 | put swst i 0 |
| 648 | put swwake i neg int 1 |
| 649 | put swstop i neg int 1 |
| 650 | put swack i neg int 1 |
| 651 | put swlife i neg int 1 |
| 652 | end |
| 653 | put swme 0 0 |
| 654 | put swpar 0 neg int 1 |
| 655 | put swpar 1 neg int 1 |
| 656 | r = pipefds swpf 0 8 524288 |
| 657 | if lt r 0 |
| 658 | ret r |
| 659 | end |
| 660 | put swpar 0 sup_fd 0 |
| 661 | put swpar 1 sup_fd 4 |
| 662 | n = mapget c 48 8 |
| 663 | for i ulong n bound 64 |
| 664 | a = eventfd uint 0 |
| 665 | if lt a 0 |
| 666 | sup_closeall |
| 667 | ret a |
| 668 | end |
| 669 | put swwake i int a |
| 670 | a = eventfd uint 0 |
| 671 | if lt a 0 |
| 672 | sup_closeall |
| 673 | ret a |
| 674 | end |
| 675 | put swstop i int a |
| 676 | a = eventfd uint 0 |
| 677 | if lt a 0 |
| 678 | sup_closeall |
| 679 | ret a |
| 680 | end |
| 681 | put swack i int a |
| 682 | end |
| 683 | ret 0 |
| 684 | end |
| 685 | |
| 686 | note Creator: fork worker w. Returns 0 in the child, the child PID in the |
| 687 | note creator, -7 bad slot, -16 slot still live, or a negative errno. The |
| 688 | note child keeps only its own life write end; the creator keeps the read end. |
| 689 | fn sup_spawn c long w ulong to long |
| 690 | if not pool_mine c |
| 691 | ret neg long 6 |
| 692 | end |
| 693 | if ge w mapget c 48 8 |
| 694 | ret neg long 7 |
| 695 | end |
| 696 | if ne get swpid w 0 |
| 697 | ret neg long 16 |
| 698 | end |
| 699 | r = pipefds swpf 0 8 524288 |
| 700 | if lt r 0 |
| 701 | ret r |
| 702 | end |
| 703 | rd = sup_fd 0 |
| 704 | wr = sup_fd 4 |
| 705 | pid = fork |
| 706 | if eq pid 0 |
| 707 | r = fclose get swpar 1 |
| 708 | put swpar 1 neg int 1 |
| 709 | r = fclose rd |
| 710 | put swlife w wr |
| 711 | put swme 0 add w 1 |
| 712 | ret 0 |
| 713 | end |
| 714 | r = fclose wr |
| 715 | if lt pid 0 |
| 716 | r = fclose rd |
| 717 | ret pid |
| 718 | end |
| 719 | put swpid w pid |
| 720 | put swlife w rd |
| 721 | r = pool_setw c w ulong pid 1 |
| 722 | ret pid |
| 723 | end |
| 724 | |
| 725 | note Worker: 3 creator gone, 2 stop, 1 wake hint, 0 timeout, negative errno. |
| 726 | note Creator loss outranks stop, which outranks work. A set stop flag makes |
| 727 | note the poll nonblocking. Hints are drained; rescan shared state after 1. |
| 728 | fn sup_wwait c long w ulong interval long to long |
| 729 | p = new uchar 24 0 |
| 730 | if ge w 64 |
| 731 | ret neg long 7 |
| 732 | end |
| 733 | iv = interval |
| 734 | if pool_stopped c |
| 735 | iv = 0 |
| 736 | end |
| 737 | sup_lpfd p 0 get swwake w |
| 738 | sup_lpfd p 8 get swstop w |
| 739 | sup_lpfd p 16 get swpar 0 |
| 740 | r = pollfds p 0 24 iv |
| 741 | if lt r 0 |
| 742 | ret r |
| 743 | end |
| 744 | if ne get p 22 0 |
| 745 | ret 3 |
| 746 | end |
| 747 | if pool_stopped c |
| 748 | ret 2 |
| 749 | end |
| 750 | if ne and get p 14 56 0 |
| 751 | ret neg long 5 |
| 752 | end |
| 753 | if ne and get p 14 1 0 |
| 754 | r = node_drain get swstop w |
| 755 | ret 2 |
| 756 | end |
| 757 | if ne and get p 6 56 0 |
| 758 | ret neg long 5 |
| 759 | end |
| 760 | if ne and get p 6 1 0 |
| 761 | r = node_drain get swwake w |
| 762 | if lt r 0 |
| 763 | ret r |
| 764 | end |
| 765 | ret 1 |
| 766 | end |
| 767 | ret 0 |
| 768 | end |
| 769 | |
| 770 | note Worker or creator: post a hint on worker w's ack eventfd. |
| 771 | fn sup_ack w ulong to long |
| 772 | if ge w 64 |
| 773 | ret neg long 7 |
| 774 | end |
| 775 | ret node_notify get swack w |
| 776 | end |
| 777 | |
| 778 | note Creator: wake worker w with a work hint. |
| 779 | fn sup_wake w ulong to long |
| 780 | if ge w 64 |
| 781 | ret neg long 7 |
| 782 | end |
| 783 | if le get swpid w 0 |
| 784 | ret neg long 3 |
| 785 | end |
| 786 | ret node_notify get swwake w |
| 787 | end |
| 788 | |
| 789 | fn sup_live c long to ulong |
| 790 | n = mapget c 48 8 |
| 791 | k = ulong 0 |
| 792 | for w ulong n bound 64 |
| 793 | if gt get swpid w 0 |
| 794 | k = add k 1 |
| 795 | end |
| 796 | end |
| 797 | ret k |
| 798 | end |
| 799 | |
| 800 | note Creator: reap worker w, then release what it held. A worker that has not |
| 801 | note exited within about one second gets SIGKILL first. Only after the exact |
| 802 | note PID is reaped are its hold, PID and life pipe released. Returns the raw |
| 803 | note wait status, -3 no live worker, or the waitpid errno (nothing released). |
| 804 | fn sup_reap c long w ulong to long |
| 805 | if ge w 64 |
| 806 | ret neg long 7 |
| 807 | end |
| 808 | pid = get swpid w |
| 809 | if le pid 0 |
| 810 | ret neg long 3 |
| 811 | end |
| 812 | done = false |
| 813 | for t ulong 100 |
| 814 | r = waitpid int pid swws 0 4 1 |
| 815 | if eq r pid |
| 816 | done = true |
| 817 | break |
| 818 | end |
| 819 | if ne r 0 |
| 820 | ret r |
| 821 | end |
| 822 | r = sleepns 10000000 |
| 823 | end |
| 824 | if not done |
| 825 | r = killpid int pid 9 |
| 826 | r = waitpid int pid swws 0 4 0 |
| 827 | if ne r pid |
| 828 | ret r |
| 829 | end |
| 830 | end |
| 831 | st = ulong get swws 0 |
| 832 | st = or st shl ulong get swws 1 8 |
| 833 | put swst w st |
| 834 | r = fclose get swlife w |
| 835 | put swlife w neg int 1 |
| 836 | put swpid w 0 |
| 837 | r = pool_clear c w |
| 838 | r = pool_setw c w 0 2 |
| 839 | ret long st |
| 840 | end |
| 841 | |
| 842 | note Creator: wait up to interval ns for deaths and, when acks is true, acks. |
| 843 | note Ack counts are left pending for sup_take. Every worker whose life pipe |
| 844 | note hung up is reaped. Returns the number reaped, or a negative errno. |
| 845 | fn sup_pollx c long interval long acks bool to long |
| 846 | n = mapget c 48 8 |
| 847 | m = ulong 0 |
| 848 | for w ulong n bound 64 |
| 849 | if gt get swpid w 0 |
| 850 | o = mul m 16 |
| 851 | if acks |
| 852 | sup_gpfd o get swack w |
| 853 | else |
| 854 | sup_gpfd o neg int 1 |
| 855 | end |
| 856 | sup_gpfd add o 8 get swlife w |
| 857 | put swpw m w |
| 858 | m = add m 1 |
| 859 | end |
| 860 | end |
| 861 | if eq m 0 |
| 862 | ret 0 |
| 863 | end |
| 864 | r = pollfds swpoll 0 mul m 16 interval |
| 865 | if lt r 0 |
| 866 | ret r |
| 867 | end |
| 868 | dead = long 0 |
| 869 | for j ulong m bound 64 |
| 870 | o = add mul j 16 14 |
| 871 | if ne get swpoll o 0 |
| 872 | r = sup_reap c get swpw j |
| 873 | if lt r 0 |
| 874 | ret r |
| 875 | end |
| 876 | dead = add dead 1 |
| 877 | end |
| 878 | end |
| 879 | ret dead |
| 880 | end |
| 881 | |
| 882 | note Creator: wait up to interval ns for acks and deaths (see sup_pollx). |
| 883 | fn sup_poll c long interval long to long |
| 884 | ret sup_pollx c interval true |
| 885 | end |
| 886 | |
| 887 | note Creator: stop admission, post every live worker's stop eventfd, then reap |
| 888 | note until all have exited or interval ns pass; survivors get SIGKILL and are |
| 889 | note reaped. Returns how many had to be killed, or a refusal. |
| 890 | fn sup_stop c long interval long to long |
| 891 | r = pool_stop c |
| 892 | if lt r 0 |
| 893 | ret r |
| 894 | end |
| 895 | n = mapget c 48 8 |
| 896 | for w ulong n bound 64 |
| 897 | if gt get swpid w 0 |
| 898 | r = node_notify get swstop w |
| 899 | end |
| 900 | end |
| 901 | dl = add monons interval |
| 902 | for t ulong 100000 |
| 903 | if eq sup_live c 0 |
| 904 | ret 0 |
| 905 | end |
| 906 | now = monons |
| 907 | if ge now dl |
| 908 | break |
| 909 | end |
| 910 | r = sup_pollx c sub dl now false |
| 911 | if lt r 0 |
| 912 | if ne r neg long 4 |
| 913 | break |
| 914 | end |
| 915 | end |
| 916 | end |
| 917 | killed = long 0 |
| 918 | for w ulong n bound 64 |
| 919 | if gt get swpid w 0 |
| 920 | r = killpid int get swpid w 9 |
| 921 | r = sup_reap c w |
| 922 | killed = add killed 1 |
| 923 | end |
| 924 | end |
| 925 | ret killed |
| 926 | end |
| 927 | note Omega Node cooperative scheduling (DRA-287). Concatenate after |
| 928 | note transport.om, pool.om and super.om, before one program with fn main. |
| 929 | note One creator admits, assigns, collects and reviews jobs. Workers never |
| 930 | note write each other's state, and no step waits for every worker. |
| 931 | note Scheduling page: one 128-byte cell per worker w at 128*w. |
| 932 | note Creator writes 0 assigned seq, 8 job id, 16 input epoch, 24 input |
| 933 | note version, 32 interest topics, 40 wake stamp (monons at the last post). |
| 934 | note Worker writes 64 done seq, 72 outcome, 80 wakes, 88 last wake latency |
| 935 | note ns, 96 largest wake latency ns. |
| 936 | note Outbox: worker w's result bytes at 4096*w of a second mapping, written |
| 937 | note before its done seq. Each word has one writer; the creator writes a |
| 938 | note worker word only after it has reaped that worker. |
| 939 | note Job states: 0 free, 1 waiting for deps, 2 ready, 3 running, 4 in review, |
| 940 | note 6 UNKNOWN (its worker died mid-job and the job is not safe to rerun). |
| 941 | note |
| 942 | note Resources and selection policy (P-DRA-14, DRA-395). A request is one |
| 943 | note ulong of four 16-bit counts, kind k at bits 16k..16k+15: kind 0 CPU |
| 944 | note slots, 1 memory MiB, 2 inference slots, 3 caller-defined. scap holds |
| 945 | note the configured capacity of each kind, suse the sum of the needs of the |
| 946 | note jobs that hold resources (sjheld 1). A job takes its whole need when it |
| 947 | note is assigned and gives it back when its worker reports done or is reaped, |
| 948 | note never in part. Every job also needs one idle live worker. |
| 949 | note sjarr: admission order (waiting age; kept across reruns). sjrdy: order |
| 950 | note in which the job last became ready. sjbyp: times it was bypassed. |
| 951 | note Decisions read only these logical counters, never the clock. |
| 952 | note Policy 1, fair fitting (DRA-396): a pick first probes the reserved job; |
| 953 | note otherwise it scans a window of win slots from a persistent cursor and |
| 954 | note takes the oldest admitted ready job that fits. The cursor moves on by |
| 955 | note win after every window scan, so every slot is examined within |
| 956 | note ceil(64/win) window scans. A ready job older than a job assigned in |
| 957 | note the same event was bypassed; once the oldest such job reaches the |
| 958 | note bypass budget it is reserved: it is offered first, and no other job may |
| 959 | note use, of any kind, the capacity it still lacks (others may use only |
| 960 | note free capacity beyond its need). Neither the free capacity it can reach |
| 961 | note nor its age ever shrinks, so it runs once running work releases enough |
| 962 | note (liveness assumes: every running job ends, by completion or by its |
| 963 | note lease, at least one worker stays live, results in review are reviewed, |
| 964 | note and dispatch is not paused). Requests over capacity are refused at |
| 965 | note admission. |
| 966 | note Admission: room is the smaller of the admission headroom and the free |
| 967 | note table slots. A refused caller holds a ticket; while tickets are held |
| 968 | note only the first holder may enter, so holders enter in ticket order |
| 969 | note before anyone new. A ticket not asked about for more than ttl dispatch |
| 970 | note events lapses (asked at event e, it survives while e + ttl is at least |
| 971 | note the current event count). An absent head blocks later holders until |
| 972 | note its ticket lapses; a paused dispatch counts no events, so the block |
| 973 | note lasts until dispatch resumes. |
| 974 | note Leases: a running job with a lease is reported once by sched_overdue |
| 975 | note after its lease passes; the authority then cancels or kills it, which |
| 976 | note releases its resources. |
| 977 | note |
| 978 | note Policy 2, goal-aware fair fitting (DRA-397): policy 1 with a different |
| 979 | note order among the examined jobs that fit: larger unblock value first (the |
| 980 | note waiting jobs, to depth 2, that the job's declared topics would make |
| 981 | note ready), then smaller declared estimate, then older admission. The |
| 982 | note reservation, the hold-back, feasibility and the bypass budget are |
| 983 | note those of policy 1 and come first, so ranking cannot starve old work. |
| 984 | note Values are rescored only when the graph version moved (a job became |
| 985 | note ready, a waiting job was admitted, a job was cancelled, a declaration |
| 986 | note changed), once per pick however many changes came before it. |
| 987 | note Completions, releases and lease expiry replan (every step dispatches) |
| 988 | note without rescoring. A proposal names a job by id and the graph version |
| 989 | note it was computed at, and is rejected when that version is no longer |
| 990 | note current; the version carries the scheduler's incarnation, so a |
| 991 | note proposal made for another scheduler is never current here. |
| 992 | const SJCAP ulong 64 |
| 993 | const SPVER ulong 3 |
| 994 | global scmap long 2 |
| 995 | global sclim ulong 2 |
| 996 | global sjst ulong 64 |
| 997 | global sjdep ulong 64 |
| 998 | global sjid ulong 64 |
| 999 | global sjw ulong 64 |
| 1000 | global sjatt ulong 64 |
| 1001 | global sjfl ulong 64 |
| 1002 | global sjout ulong 64 |
| 1003 | global sjneed ulong 64 |
| 1004 | global sjheld ulong 64 |
| 1005 | global sjarr ulong 64 |
| 1006 | global sjrdy ulong 64 |
| 1007 | global sjbyp ulong 64 |
| 1008 | global sjlse ulong 64 |
| 1009 | global sjdue ulong 64 |
| 1010 | global sttk ulong 64 |
| 1011 | global stts ulong 64 |
| 1012 | global scbusy ulong 64 |
| 1013 | global scseq ulong 64 |
| 1014 | global swcur ulong 2 |
| 1015 | global scpause ulong 1 |
| 1016 | global scap ulong 4 |
| 1017 | global suse ulong 4 |
| 1018 | note Policy words: 0 policy (0 FIFO head-of-line, 1 fair fitting), 1 |
| 1019 | note candidate window in slots, 2 dispatch budget per event, 3 bypass |
| 1020 | note budget, 4 cursor, 5 reserved job slot + 1 (0 none), 6 tickets held, |
| 1021 | note 7 ticket lifetime in dispatch events. |
| 1022 | global scpol ulong 8 |
| 1023 | note Counters (sched_stat): 0 admissions, 1 ready stamps, 2 dispatch events, |
| 1024 | note 3 candidate slot reads, 4 jobs assigned, 5 bypasses, 6 reservations |
| 1025 | note made, 7 impossible requests refused, 8 head-of-line stops, 9 reserved |
| 1026 | note jobs assigned, 10 tickets issued, 11 tickets lapsed, 12 leases overdue, |
| 1027 | note 13 maintenance slot reads, 14 window scans, 15 dispatch events refused |
| 1028 | note because the replay ring was full (DRA-398). |
| 1029 | global scst ulong 16 |
| 1030 | note Goal-aware ranking (policy 2): sjpro the topics a job declares its |
| 1031 | note completion publishes, sjest its declared work estimate in ms, sjunc |
| 1032 | note that estimate's uncertainty in ms, sjval its unblock value in jobs as |
| 1033 | note last scored. scgv: 0 graph version, 1 version last scored, 2 proposed |
| 1034 | note job slot + 1 (0 none), 3 version the proposal named, 4 proposal state |
| 1035 | note (0 no incarnation yet: proposals refused; 1 accepting; 2 the version |
| 1036 | note is exhausted: proposals refused for the rest of this scheduler). The |
| 1037 | note graph version is the scheduler's incarnation (sched_incarnate, once) |
| 1038 | note times 2^40 plus the bumps since, never more than 2^40 - 1 of them: the |
| 1039 | note bump that would carry into the next incarnation's range exhausts the |
| 1040 | note version instead, so schedulers of different incarnations never share a |
| 1041 | note version. Within one scheduler every admission of a job, cancellation |
| 1042 | note of a waiting or ready one and readiness bumps it, so a proposal whose |
| 1043 | note version is current still names the job it was made for. |
| 1044 | global sjpro ulong 64 |
| 1045 | global sjest ulong 64 |
| 1046 | global sjunc ulong 64 |
| 1047 | global sjval ulong 64 |
| 1048 | global scgv ulong 5 |
| 1049 | note Goal counters (sched_stat 32..39): 0 rescores, 1 jobs scored, 2 graph |
| 1050 | note version bumps, 3 proposals accepted, 4 proposals stale, 5 proposals |
| 1051 | note refused, 6 slots read by value traversal, 7 proposals used. |
| 1052 | global scgst ulong 8 |
| 1053 | note Replay ring (DRA-398). While a journal is attached (sfj 0 is 1), each |
| 1054 | note dispatch event that assigned a job or changed the reservation leaves a |
| 1055 | note record of 6 words in sfr: event count, assigned slot bitmap, bypassed |
| 1056 | note slot bitmap (the slots whose bypass count went up), cursor, reserved |
| 1057 | note slot + 1, and 0. A publication that makes waiting jobs ready leaves a |
| 1058 | note readiness record: the current event count, no assigned or bypassed |
| 1059 | note slot, cursor, reserved slot + 1, and the bitmap of the slots it made |
| 1060 | note ready. sfj 1 counts the records waiting; sfj 2 and 3 are the |
| 1061 | note reservation at the start of the current event and the slots it has |
| 1062 | note assigned so far. The journal drains them before it appends any other |
| 1063 | note record, so a transition is never durable before the dispatch |
| 1064 | note decisions and readiness that came before it. With 64 waiting, |
| 1065 | note dispatch assigns nothing and publication is refused (counter 15) |
| 1066 | note until they are drained. |
| 1067 | global sfr ulong 384 |
| 1068 | global sfj ulong 4 |
| 1069 | |
| 1070 | fn sc_cell w ulong off ulong to ulong |
| 1071 | ret mapget get scmap 0 add mul w 128 off 8 |
| 1072 | end |
| 1073 | |
| 1074 | fn sc_set w ulong off ulong v ulong to void |
| 1075 | r = mapset get scmap 0 add mul w 128 off 8 v |
| 1076 | end |
| 1077 | |
| 1078 | note Creator, before any fork: map the scheduling page and the outboxes and |
| 1079 | note set the limits on admitted (a) and in-review (rl) jobs, each 1..64. |
| 1080 | note Returns 0, -6 not creator, -7 bad limit, or a mapping errno. |
| 1081 | fn sched_new c long a ulong rl ulong to long |
| 1082 | if not pool_mine c |
| 1083 | ret neg long 6 |
| 1084 | end |
| 1085 | if or eq a 0 gt a SJCAP |
| 1086 | ret neg long 7 |
| 1087 | end |
| 1088 | if or eq rl 0 gt rl SJCAP |
| 1089 | ret neg long 7 |
| 1090 | end |
| 1091 | s = mapnew neg int 1 0 8192 3 33 |
| 1092 | if le s 0 |
| 1093 | ret s |
| 1094 | end |
| 1095 | o = mapnew neg int 1 0 262144 3 33 |
| 1096 | if le o 0 |
| 1097 | r = mapdrop s |
| 1098 | ret o |
| 1099 | end |
| 1100 | put scmap 0 s |
| 1101 | put scmap 1 o |
| 1102 | put sclim 0 a |
| 1103 | put sclim 1 rl |
| 1104 | for j ulong 64 |
| 1105 | put sjst j 0 |
| 1106 | put sjheld j 0 |
| 1107 | put sjlse j 0 |
| 1108 | put sjdue j 0 |
| 1109 | put sjpro j 0 |
| 1110 | put sjest j 0 |
| 1111 | put sjunc j 0 |
| 1112 | put sjval j 0 |
| 1113 | put scbusy j 0 |
| 1114 | put scseq j 0 |
| 1115 | end |
| 1116 | for k ulong 4 |
| 1117 | put scap k 65535 |
| 1118 | put suse k 0 |
| 1119 | end |
| 1120 | put sfj 1 0 |
| 1121 | for i ulong 16 |
| 1122 | put scst i 0 |
| 1123 | end |
| 1124 | for i ulong 8 |
| 1125 | put scgst i 0 |
| 1126 | end |
| 1127 | for i ulong 5 |
| 1128 | put scgv i 0 |
| 1129 | end |
| 1130 | put scpol 0 1 |
| 1131 | put scpol 1 64 |
| 1132 | put scpol 2 64 |
| 1133 | put scpol 3 4 |
| 1134 | put scpol 4 0 |
| 1135 | put scpol 5 0 |
| 1136 | put scpol 6 0 |
| 1137 | put scpol 7 1000 |
| 1138 | put scpause 0 0 |
| 1139 | ret 0 |
| 1140 | end |
| 1141 | |
| 1142 | note Count of kind k (0..3) in packed request req. |
| 1143 | fn sp_need req ulong k ulong to ulong |
| 1144 | ret and shr req mul k 16 65535 |
| 1145 | end |
| 1146 | |
| 1147 | note Free capacity of kind k. sched_cap never sets a capacity below the |
| 1148 | note use, so this cannot underflow. |
| 1149 | fn sp_free k ulong to ulong |
| 1150 | ret sub get scap k get suse k |
| 1151 | end |
| 1152 | |
| 1153 | note Does req fit in the free capacity once the reserved request res has |
| 1154 | note what it still lacks? Of each kind, res keeps min(free, its need); res 0 |
| 1155 | note is no reservation. This keeps the reserved job's attainable capacity |
| 1156 | note from ever shrinking (the drain). |
| 1157 | fn sp_fits req ulong res ulong to bool |
| 1158 | for k ulong 4 |
| 1159 | f = sp_free k |
| 1160 | r = sp_need res k |
| 1161 | a = ulong 0 |
| 1162 | if gt f r |
| 1163 | a = sub f r |
| 1164 | end |
| 1165 | if gt sp_need req k a |
| 1166 | ret false |
| 1167 | end |
| 1168 | end |
| 1169 | ret true |
| 1170 | end |
| 1171 | |
| 1172 | note Could req ever run, with the configured capacity all free? |
| 1173 | fn sp_feas req ulong to bool |
| 1174 | for k ulong 4 |
| 1175 | if gt sp_need req k get scap k |
| 1176 | ret false |
| 1177 | end |
| 1178 | end |
| 1179 | ret true |
| 1180 | end |
| 1181 | |
| 1182 | note Job j takes its whole need. |
| 1183 | fn sp_take j ulong to void |
| 1184 | for k ulong 4 |
| 1185 | put suse k add get suse k sp_need get sjneed j k |
| 1186 | end |
| 1187 | put sjheld j 1 |
| 1188 | end |
| 1189 | |
| 1190 | note Job j gives back its need, if it holds it. |
| 1191 | fn sp_give j ulong to void |
| 1192 | if eq get sjheld j 0 |
| 1193 | ret |
| 1194 | end |
| 1195 | for k ulong 4 |
| 1196 | put suse k sub get suse k sp_need get sjneed j k |
| 1197 | end |
| 1198 | put sjheld j 0 |
| 1199 | end |
| 1200 | |
| 1201 | note Job j becomes ready, stamped with the next ready order. |
| 1202 | fn sp_ready j ulong to void |
| 1203 | put sjst j 2 |
| 1204 | put sjrdy j get scst 1 |
| 1205 | put scst 1 add get scst 1 1 |
| 1206 | sp_bump |
| 1207 | end |
| 1208 | |
| 1209 | note Creator: counter i of scst, capacity (i 16..19) or use (i 20..23) of a |
| 1210 | note kind, policy word (i 24..31), goal counter (i 32..39), graph version |
| 1211 | note (i 40), proposal state (i 41: 0 no incarnation, 1 accepting, 2 |
| 1212 | note exhausted). |
| 1213 | fn sched_stat i ulong to ulong |
| 1214 | if lt i 16 |
| 1215 | ret get scst i |
| 1216 | end |
| 1217 | if lt i 20 |
| 1218 | ret get scap sub i 16 |
| 1219 | end |
| 1220 | if lt i 24 |
| 1221 | ret get suse sub i 20 |
| 1222 | end |
| 1223 | if lt i 32 |
| 1224 | ret get scpol sub i 24 |
| 1225 | end |
| 1226 | if lt i 40 |
| 1227 | ret get scgst sub i 32 |
| 1228 | end |
| 1229 | if eq i 40 |
| 1230 | ret get scgv 0 |
| 1231 | end |
| 1232 | if eq i 41 |
| 1233 | ret get scgv 4 |
| 1234 | end |
| 1235 | ret 0 |
| 1236 | end |
| 1237 | |
| 1238 | note Creator: would sched_cap caps be accepted? Not when the new capacity of |
| 1239 | note a kind is below its use by running jobs, or below the need of any one |
| 1240 | note admitted job. |
| 1241 | fn sched_capok caps ulong to bool |
| 1242 | for k ulong 4 |
| 1243 | if lt sp_need caps k get suse k |
| 1244 | ret false |
| 1245 | end |
| 1246 | end |
| 1247 | for j ulong 64 |
| 1248 | s = get sjst j |
| 1249 | if and ge s 1 le s 3 |
| 1250 | for k ulong 4 |
| 1251 | if gt sp_need get sjneed j k sp_need caps k |
| 1252 | ret false |
| 1253 | end |
| 1254 | end |
| 1255 | end |
| 1256 | end |
| 1257 | ret true |
| 1258 | end |
| 1259 | |
| 1260 | note Creator: set the capacity of every kind from caps (packed like a |
| 1261 | note request). 0, or -8 when sched_capok refuses (nothing changes). |
| 1262 | fn sched_cap caps ulong to long |
| 1263 | if not sched_capok caps |
| 1264 | ret neg long 8 |
| 1265 | end |
| 1266 | for k ulong 4 |
| 1267 | put scap k sp_need caps k |
| 1268 | end |
| 1269 | ret 0 |
| 1270 | end |
| 1271 | |
| 1272 | note Creator: the configured capacities, packed like a request. |
| 1273 | fn sched_caps to ulong |
| 1274 | v = ulong 0 |
| 1275 | for k ulong 4 |
| 1276 | v = or v shl get scap k mul k 16 |
| 1277 | end |
| 1278 | ret v |
| 1279 | end |
| 1280 | |
| 1281 | note Creator: would sched_policy accept these words? Policy p 0..2, window |
| 1282 | note win 1..64, dispatch budget db 1..64, bypass budget by 1..65535, ticket |
| 1283 | note lifetime ttl 1..1000000. |
| 1284 | fn sched_polok p ulong win ulong db ulong by ulong ttl ulong to bool |
| 1285 | if gt p 2 |
| 1286 | ret false |
| 1287 | end |
| 1288 | if or eq win 0 gt win 64 |
| 1289 | ret false |
| 1290 | end |
| 1291 | if or eq db 0 gt db 64 |
| 1292 | ret false |
| 1293 | end |
| 1294 | if or eq by 0 gt by 65535 |
| 1295 | ret false |
| 1296 | end |
| 1297 | ret and gt ttl 0 le ttl 1000000 |
| 1298 | end |
| 1299 | |
| 1300 | note Creator: policy p (0 FIFO head-of-line, 1 fair fitting, 2 goal-aware |
| 1301 | note fair fitting), candidate window win slots, dispatch budget db jobs per |
| 1302 | note event, bypass budget by, ticket lifetime ttl dispatch events, in the |
| 1303 | note ranges of sched_polok. The cursor and any reservation are kept. 0 or |
| 1304 | note -7. |
| 1305 | fn sched_policy p ulong win ulong db ulong by ulong ttl ulong to long |
| 1306 | if not sched_polok p win db by ttl |
| 1307 | ret neg long 7 |
| 1308 | end |
| 1309 | put scpol 0 p |
| 1310 | put scpol 1 win |
| 1311 | put scpol 2 db |
| 1312 | put scpol 3 by |
| 1313 | put scpol 7 ttl |
| 1314 | ret 0 |
| 1315 | end |
| 1316 | |
| 1317 | note Creator: drop this process's scheduling mappings. |
| 1318 | fn sched_free to long |
| 1319 | r = mapdrop get scmap 1 |
| 1320 | if lt r 0 |
| 1321 | ret r |
| 1322 | end |
| 1323 | ret mapdrop get scmap 0 |
| 1324 | end |
| 1325 | |
| 1326 | note Jobs whose state is in lo..hi. |
| 1327 | fn sched_count lo ulong hi ulong to ulong |
| 1328 | n = ulong 0 |
| 1329 | for j ulong 64 |
| 1330 | s = get sjst j |
| 1331 | if and ge s lo le s hi |
| 1332 | n = add n 1 |
| 1333 | end |
| 1334 | end |
| 1335 | ret n |
| 1336 | end |
| 1337 | |
| 1338 | note Position of id's admission ticket, or 64. |
| 1339 | fn sp_tkpos id ulong to ulong |
| 1340 | for t ulong get scpol 6 bound 64 |
| 1341 | if eq get sttk t id |
| 1342 | ret t |
| 1343 | end |
| 1344 | end |
| 1345 | ret 64 |
| 1346 | end |
| 1347 | |
| 1348 | note Compact the tickets in order, dropping ticket d (64: none) and every |
| 1349 | note ticket not asked about for the ticket lifetime. |
| 1350 | fn sp_tkpack d ulong to void |
| 1351 | k = ulong 0 |
| 1352 | for t ulong get scpol 6 bound 64 |
| 1353 | if ne t d |
| 1354 | if lt add get stts t get scpol 7 get scst 2 |
| 1355 | put scst 11 add get scst 11 1 |
| 1356 | else |
| 1357 | put sttk k get sttk t |
| 1358 | put stts k get stts t |
| 1359 | k = add k 1 |
| 1360 | end |
| 1361 | end |
| 1362 | end |
| 1363 | put scpol 6 k |
| 1364 | end |
| 1365 | |
| 1366 | note Refresh ticket t, or give id a ticket at the end when it has none and |
| 1367 | note the line has room (a caller refused with the line full holds none). |
| 1368 | fn sp_tkhold id ulong t ulong to void |
| 1369 | if lt t 64 |
| 1370 | put stts t get scst 2 |
| 1371 | ret |
| 1372 | end |
| 1373 | n = get scpol 6 |
| 1374 | if lt n 64 |
| 1375 | put sttk n id |
| 1376 | put stts n get scst 2 |
| 1377 | put scpol 6 add n 1 |
| 1378 | put scst 10 add get scst 10 1 |
| 1379 | end |
| 1380 | end |
| 1381 | |
| 1382 | note Creator: may id be admitted now? Room is the smaller of the admission |
| 1383 | note headroom and the free table slots (a job in review or UNKNOWN holds |
| 1384 | note its slot). While tickets are held only the first holder may enter; |
| 1385 | note with none, anyone may while there is room. A refused caller gets or |
| 1386 | note keeps a ticket; every ask by a holder, refused or not, refreshes its |
| 1387 | note ticket's last-asked event, and a caller with room and no ticket gets |
| 1388 | note none. A true answer guarantees the slot for the next sched_admitr |
| 1389 | note (single creator), so a caller may ask before journaling (as jn_admit |
| 1390 | note does). |
| 1391 | fn sched_room id ulong to bool |
| 1392 | sp_tkpack 64 |
| 1393 | t = sp_tkpos id |
| 1394 | a = ulong 0 |
| 1395 | fs = ulong 0 |
| 1396 | for j ulong 64 |
| 1397 | s = get sjst j |
| 1398 | if eq s 0 |
| 1399 | fs = add fs 1 |
| 1400 | end |
| 1401 | if and ge s 1 le s 3 |
| 1402 | a = add a 1 |
| 1403 | end |
| 1404 | end |
| 1405 | room = ulong 0 |
| 1406 | if lt a get sclim 0 |
| 1407 | room = sub get sclim 0 a |
| 1408 | end |
| 1409 | if lt fs room |
| 1410 | room = fs |
| 1411 | end |
| 1412 | if gt room 0 |
| 1413 | if eq get scpol 6 0 |
| 1414 | ret true |
| 1415 | end |
| 1416 | if eq t 0 |
| 1417 | put stts 0 get scst 2 |
| 1418 | ret true |
| 1419 | end |
| 1420 | end |
| 1421 | sp_tkhold id t |
| 1422 | ret false |
| 1423 | end |
| 1424 | |
| 1425 | note Creator: admit job id needing req (packed resources). deps 0 makes it |
| 1426 | note ready at once; otherwise it waits for a publication whose topics meet |
| 1427 | note deps. flags bit 0: safe to rerun after its worker dies. Returns the job |
| 1428 | note slot; -8 when req exceeds the configured capacity of a kind (it could |
| 1429 | note never run); -2 when sched_room refuses: at the admission limit, or |
| 1430 | note ticket holders ahead; the caller keeps a ticket and asks again. |
| 1431 | fn sched_admitr id ulong deps ulong flags ulong req ulong to long |
| 1432 | ret sched_admits id deps flags req sched_slot |
| 1433 | end |
| 1434 | |
| 1435 | note Creator: the lowest free table slot (the one sched_admitr would give |
| 1436 | note the next job), or 64 when none is free. |
| 1437 | fn sched_slot to ulong |
| 1438 | for j ulong 64 |
| 1439 | if eq get sjst j 0 |
| 1440 | ret j |
| 1441 | end |
| 1442 | end |
| 1443 | ret 64 |
| 1444 | end |
| 1445 | |
| 1446 | note Creator: could req ever run, with the configured capacity all free? |
| 1447 | fn sched_feas req ulong to bool |
| 1448 | ret sp_feas req |
| 1449 | end |
| 1450 | |
| 1451 | note Creator: sched_admitr into table slot j, which must be free: the |
| 1452 | note journal records the slot with the admission and recovery puts the job |
| 1453 | note back into it (DRA-398). Refusals as sched_admitr; -2 also when slot j |
| 1454 | note is not free. |
| 1455 | fn sched_admits id ulong deps ulong flags ulong req ulong j ulong to long |
| 1456 | if not sp_feas req |
| 1457 | put scst 7 add get scst 7 1 |
| 1458 | ret neg long 8 |
| 1459 | end |
| 1460 | if not sched_room id |
| 1461 | ret neg long 2 |
| 1462 | end |
| 1463 | if ge j 64 |
| 1464 | ret neg long 2 |
| 1465 | end |
| 1466 | if ne get sjst j 0 |
| 1467 | ret neg long 2 |
| 1468 | end |
| 1469 | t = sp_tkpos id |
| 1470 | if lt t 64 |
| 1471 | sp_tkpack t |
| 1472 | end |
| 1473 | put sjid j id |
| 1474 | put sjdep j deps |
| 1475 | put sjfl j flags |
| 1476 | put sjatt j 0 |
| 1477 | put sjout j 0 |
| 1478 | put sjw j 0 |
| 1479 | put sjneed j req |
| 1480 | put sjheld j 0 |
| 1481 | put sjbyp j 0 |
| 1482 | put sjlse j 0 |
| 1483 | put sjdue j 0 |
| 1484 | put sjarr j get scst 0 |
| 1485 | put scst 0 add get scst 0 1 |
| 1486 | put sjpro j 0 |
| 1487 | put sjest j 0 |
| 1488 | put sjunc j 0 |
| 1489 | put sjval j 0 |
| 1490 | if eq deps 0 |
| 1491 | sp_ready j |
| 1492 | else |
| 1493 | put sjst j 1 |
| 1494 | sp_bump |
| 1495 | end |
| 1496 | ret long j |
| 1497 | end |
| 1498 | |
| 1499 | note Creator: job j (waiting, ready or running) gets a lease of ns from its |
| 1500 | note next assignment, or from now when it runs; 0 removes it. 0; -3 for a |
| 1501 | note slot that is not waiting, ready or running; -7 for ns above 2^50 (about |
| 1502 | note 13 days). Both refusals change nothing. The bound keeps every deadline |
| 1503 | note (the monotonic clock, below 2^63, plus ns) representable: it never |
| 1504 | note wraps into the past or onto 0, the no-deadline value. |
| 1505 | fn sched_lease j ulong ns ulong to long |
| 1506 | if ge j 64 |
| 1507 | ret neg long 3 |
| 1508 | end |
| 1509 | s = get sjst j |
| 1510 | if or lt s 1 gt s 3 |
| 1511 | ret neg long 3 |
| 1512 | end |
| 1513 | if gt ns 1125899906842624 |
| 1514 | ret neg long 7 |
| 1515 | end |
| 1516 | put sjlse j ns |
| 1517 | if eq s 3 |
| 1518 | put sjdue j 0 |
| 1519 | if gt ns 0 |
| 1520 | put sjdue j add ulong monons ns |
| 1521 | end |
| 1522 | end |
| 1523 | ret 0 |
| 1524 | end |
| 1525 | |
| 1526 | note Creator: a running job past its lease whose worker has not reported |
| 1527 | note done, reported once (its deadline is cleared): its slot, or 64. The |
| 1528 | note authority cancels or kills it; the release follows from the worker's |
| 1529 | note report or reap. |
| 1530 | fn sched_overdue to ulong |
| 1531 | now = ulong monons |
| 1532 | for j ulong 64 |
| 1533 | if eq get sjst j 3 |
| 1534 | d = get sjdue j |
| 1535 | if gt d 0 |
| 1536 | if ge now d |
| 1537 | w = get sjw j |
| 1538 | if ne sc_cell w 64 get scseq w |
| 1539 | put sjdue j 0 |
| 1540 | put scst 12 add get scst 12 1 |
| 1541 | ret j |
| 1542 | end |
| 1543 | end |
| 1544 | end |
| 1545 | end |
| 1546 | end |
| 1547 | ret 64 |
| 1548 | end |
| 1549 | |
| 1550 | note Creator: sched_admitr with no resource need beyond one worker. |
| 1551 | fn sched_admit id ulong deps ulong flags ulong to long |
| 1552 | ret sched_admitr id deps flags 0 |
| 1553 | end |
| 1554 | |
| 1555 | note Creator: worker w is woken by publications whose topics meet topics. |
| 1556 | fn sched_want w ulong topics ulong to long |
| 1557 | if ge w 64 |
| 1558 | ret neg long 7 |
| 1559 | end |
| 1560 | sc_set w 32 topics |
| 1561 | ret 0 |
| 1562 | end |
| 1563 | |
| 1564 | fn sc_wake w ulong to void |
| 1565 | sc_set w 40 ulong monons |
| 1566 | r = sup_wake w |
| 1567 | end |
| 1568 | |
| 1569 | note Lowest idle live worker below n, or 64 when none. A worker is idle when |
| 1570 | note the creator has collected its last assignment. |
| 1571 | fn sp_idle n ulong to ulong |
| 1572 | for w ulong n bound 64 |
| 1573 | if and gt get swpid w 0 eq get scbusy w 0 |
| 1574 | ret w |
| 1575 | end |
| 1576 | end |
| 1577 | ret 64 |
| 1578 | end |
| 1579 | |
| 1580 | note Assign job j to idle worker w: it takes its need; the job id and the |
| 1581 | note input epoch and version are written before the seq, then the wake. |
| 1582 | fn sp_start c long j ulong w ulong to void |
| 1583 | q = add get scseq w 1 |
| 1584 | put scseq w q |
| 1585 | put scbusy w add j 1 |
| 1586 | put sjst j 3 |
| 1587 | put sjw j w |
| 1588 | put sjatt j add get sjatt j 1 |
| 1589 | put sjbyp j 0 |
| 1590 | put sjdue j 0 |
| 1591 | if gt get sjlse j 0 |
| 1592 | put sjdue j add ulong monons get sjlse j |
| 1593 | end |
| 1594 | sp_take j |
| 1595 | if eq get scpol 5 add j 1 |
| 1596 | put scpol 5 0 |
| 1597 | put scst 9 add get scst 9 1 |
| 1598 | end |
| 1599 | sc_set w 8 get sjid j |
| 1600 | sc_set w 16 pool_epoch c |
| 1601 | sc_set w 24 node_count pool_current c |
| 1602 | sc_set w 0 q |
| 1603 | sc_wake w |
| 1604 | put scst 4 add get scst 4 1 |
| 1605 | end |
| 1606 | |
| 1607 | note Policy 0, FIFO head-of-line: the stop rule of the reference pump |
| 1608 | note (aien-sovereign-core-mv spark-harness scheduler/core.rs Core::pump, |
| 1609 | note 598-602), not its queue: the head here is the ready job that became |
| 1610 | note ready first (the pump batches newly eligible tasks in task-id order |
| 1611 | note into a bounded queue). The head is chosen when it fits, and when it |
| 1612 | note does not fit nothing is chosen, so a head that does |
| 1613 | note not fit holds back every later job. Returns the slot or 64. |
| 1614 | fn sp_fifo to ulong |
| 1615 | h = ulong 64 |
| 1616 | for j ulong 64 |
| 1617 | put scst 3 add get scst 3 1 |
| 1618 | if eq get sjst j 2 |
| 1619 | if eq h 64 |
| 1620 | h = j |
| 1621 | else |
| 1622 | if lt get sjrdy j get sjrdy h |
| 1623 | h = j |
| 1624 | end |
| 1625 | end |
| 1626 | end |
| 1627 | end |
| 1628 | if eq h 64 |
| 1629 | ret 64 |
| 1630 | end |
| 1631 | if sp_fits get sjneed h 0 |
| 1632 | ret h |
| 1633 | end |
| 1634 | put scst 8 add get scst 8 1 |
| 1635 | ret 64 |
| 1636 | end |
| 1637 | |
| 1638 | note Policy 1, fair fitting: the reserved job first when it fits; else the |
| 1639 | note oldest admitted ready job, among win slots from the cursor, that fits |
| 1640 | note without the capacity the reserved job still lacks; the cursor then |
| 1641 | note moves on by win. Returns the slot or 64. Every slot read counts |
| 1642 | note (counter 3: the reserved probe and the window), at most win + 1 per |
| 1643 | note pick, win + 2 under policy 2 (sp_proposal's probe counts too); |
| 1644 | note counter 14 counts window scans. |
| 1645 | fn sp_fair to ulong |
| 1646 | rq = ulong 0 |
| 1647 | r = get scpol 5 |
| 1648 | if gt r 0 |
| 1649 | rj = sub r 1 |
| 1650 | put scst 3 add get scst 3 1 |
| 1651 | if eq get sjst rj 2 |
| 1652 | if sp_fits get sjneed rj 0 |
| 1653 | ret rj |
| 1654 | end |
| 1655 | rq = get sjneed rj |
| 1656 | else |
| 1657 | put scpol 5 0 |
| 1658 | end |
| 1659 | end |
| 1660 | goal = eq get scpol 0 2 |
| 1661 | if goal |
| 1662 | sp_rescore |
| 1663 | pj = sp_proposal rq |
| 1664 | if lt pj 64 |
| 1665 | ret pj |
| 1666 | end |
| 1667 | end |
| 1668 | win = get scpol 1 |
| 1669 | cur = get scpol 4 |
| 1670 | b = ulong 64 |
| 1671 | put scst 14 add get scst 14 1 |
| 1672 | for i ulong win bound 64 |
| 1673 | put scst 3 add get scst 3 1 |
| 1674 | j = rem add cur i 64 |
| 1675 | if eq get sjst j 2 |
| 1676 | if sp_fits get sjneed j rq |
| 1677 | if eq b 64 |
| 1678 | b = j |
| 1679 | else |
| 1680 | if sp_better goal j b |
| 1681 | b = j |
| 1682 | end |
| 1683 | end |
| 1684 | end |
| 1685 | end |
| 1686 | end |
| 1687 | put scpol 4 rem add cur win 64 |
| 1688 | ret b |
| 1689 | end |
| 1690 | |
| 1691 | note Ranking key, both of ready jobs a and b: is a better? Policy 1: older |
| 1692 | note admission. Policy 2: larger unblock value, then smaller declared |
| 1693 | note estimate, then older admission (admission orders are unique, so there |
| 1694 | note is never a tie). |
| 1695 | fn sp_better goal bool a ulong b ulong to bool |
| 1696 | if goal |
| 1697 | va = get sjval a |
| 1698 | vb = get sjval b |
| 1699 | if ne va vb |
| 1700 | ret gt va vb |
| 1701 | end |
| 1702 | ea = get sjest a |
| 1703 | eb = get sjest b |
| 1704 | if ne ea eb |
| 1705 | ret lt ea eb |
| 1706 | end |
| 1707 | end |
| 1708 | ret lt get sjarr a get sjarr b |
| 1709 | end |
| 1710 | |
| 1711 | note A committed change that can alter an unblock value: a job becomes |
| 1712 | note ready, a waiting job is admitted, a waiting or ready job is cancelled, |
| 1713 | note or a declaration changes. Bumps the graph version, which makes any |
| 1714 | note proposal stale (rejected when next used). Nothing is rescored here: |
| 1715 | note the next policy-2 pick rescores once, however many bumps came before |
| 1716 | note it (coalesced). At 2^40 - 1 bumps the version stays and is exhausted |
| 1717 | note (scgv 4 = 2): from then on proposals are refused and every pick |
| 1718 | note rescores. |
| 1719 | fn sp_bump to void |
| 1720 | put scgst 2 add get scgst 2 1 |
| 1721 | if eq and get scgv 0 1099511627775 1099511627775 |
| 1722 | put scgv 4 2 |
| 1723 | ret |
| 1724 | end |
| 1725 | put scgv 0 add get scgv 0 1 |
| 1726 | end |
| 1727 | |
| 1728 | note Unblock value of ready job j, in jobs: the waiting jobs whose deps meet |
| 1729 | note the topics j declares it unblocks (depth 1), plus the waiting jobs whose |
| 1730 | note deps meet the topics those declare (depth 2), each counted once. Reads |
| 1731 | note at most 128 slots. |
| 1732 | fn sp_value j ulong to ulong |
| 1733 | pro = get sjpro j |
| 1734 | if eq pro 0 |
| 1735 | ret 0 |
| 1736 | end |
| 1737 | n = ulong 0 |
| 1738 | m = ulong 0 |
| 1739 | p2 = ulong 0 |
| 1740 | for k ulong 64 |
| 1741 | if eq get sjst k 1 |
| 1742 | if ne and get sjdep k pro 0 |
| 1743 | m = or m shl ulong 1 k |
| 1744 | p2 = or p2 get sjpro k |
| 1745 | n = add n 1 |
| 1746 | end |
| 1747 | end |
| 1748 | end |
| 1749 | put scgst 6 add get scgst 6 64 |
| 1750 | if eq p2 0 |
| 1751 | ret n |
| 1752 | end |
| 1753 | for k ulong 64 |
| 1754 | if eq get sjst k 1 |
| 1755 | if eq and shr m k 1 0 |
| 1756 | if ne and get sjdep k p2 0 |
| 1757 | n = add n 1 |
| 1758 | end |
| 1759 | end |
| 1760 | end |
| 1761 | end |
| 1762 | put scgst 6 add get scgst 6 64 |
| 1763 | ret n |
| 1764 | end |
| 1765 | |
| 1766 | note Recompute the unblock value of every ready job when the graph version |
| 1767 | note moved since the last scoring, or always once it is exhausted; |
| 1768 | note otherwise nothing. |
| 1769 | fn sp_rescore to void |
| 1770 | v = get scgv 0 |
| 1771 | if and eq get scgv 1 v ne get scgv 4 2 |
| 1772 | ret |
| 1773 | end |
| 1774 | for j ulong 64 |
| 1775 | if eq get sjst j 2 |
| 1776 | put sjval j sp_value j |
| 1777 | put scgst 1 add get scgst 1 1 |
| 1778 | end |
| 1779 | end |
| 1780 | put scgv 1 v |
| 1781 | put scgst 0 add get scgst 0 1 |
| 1782 | put scgst 6 add get scgst 6 64 |
| 1783 | end |
| 1784 | |
| 1785 | note The proposed job, when the proposal is for the current graph version |
| 1786 | note (and that version is not exhausted) and the job is still ready and fits |
| 1787 | note beside the reservation (rq); it is used once. Otherwise the proposal |
| 1788 | note is dropped as stale: 64. |
| 1789 | fn sp_proposal rq ulong to ulong |
| 1790 | p = get scgv 2 |
| 1791 | if eq p 0 |
| 1792 | ret 64 |
| 1793 | end |
| 1794 | put scgv 2 0 |
| 1795 | put scst 3 add get scst 3 1 |
| 1796 | j = sub p 1 |
| 1797 | if and eq get scgv 3 get scgv 0 eq get scgv 4 1 |
| 1798 | if eq get sjst j 2 |
| 1799 | if sp_fits get sjneed j rq |
| 1800 | put scgst 7 add get scgst 7 1 |
| 1801 | ret j |
| 1802 | end |
| 1803 | end |
| 1804 | end |
| 1805 | put scgst 4 add get scgst 4 1 |
| 1806 | ret 64 |
| 1807 | end |
| 1808 | |
| 1809 | note Creator: declare what job j (waiting or ready) is expected to unblock |
| 1810 | note and cost: pro, the topics its completion will publish; est, the work |
| 1811 | note estimate in ms (declared, or derived by the caller from measurements); |
| 1812 | note unc, its uncertainty in ms (recorded, not used to rank). 0, or -3. |
| 1813 | fn sched_goal j ulong pro ulong est ulong unc ulong to long |
| 1814 | if ge j 64 |
| 1815 | ret neg long 3 |
| 1816 | end |
| 1817 | s = get sjst j |
| 1818 | if or eq s 0 gt s 2 |
| 1819 | ret neg long 3 |
| 1820 | end |
| 1821 | put sjpro j pro |
| 1822 | put sjest j est |
| 1823 | put sjunc j unc |
| 1824 | sp_bump |
| 1825 | ret 0 |
| 1826 | end |
| 1827 | |
| 1828 | note Creator: the graph version that proposals must name. |
| 1829 | fn sched_version to ulong |
| 1830 | ret get scgv 0 |
| 1831 | end |
| 1832 | |
| 1833 | note Creator, after sched_new: incarnation n (1..2^24 - 1), distinct |
| 1834 | note for every scheduler that may receive proposals meant for another (the |
| 1835 | note journal fence, DRA-398). The graph version becomes n * 2^40, which no |
| 1836 | note scheduler of another incarnation reaches, any proposal is dropped and |
| 1837 | note proposals are accepted from now on. The last scoring stays below n * |
| 1838 | note 2^40, so the next ranking pass rescores whatever was admitted or |
| 1839 | note declared before, whenever the incarnation comes. Once per |
| 1840 | note scheduler: 0, or -7 (n out of range, or already set or exhausted). |
| 1841 | fn sched_incarnate n ulong to long |
| 1842 | if or eq n 0 ge n 16777216 |
| 1843 | ret neg long 7 |
| 1844 | end |
| 1845 | if ne get scgv 4 0 |
| 1846 | ret neg long 7 |
| 1847 | end |
| 1848 | put scgv 0 shl n 40 |
| 1849 | put scgv 2 0 |
| 1850 | put scgv 4 1 |
| 1851 | ret 0 |
| 1852 | end |
| 1853 | |
| 1854 | note Creator, policy 2: propose the ready job whose id is id for the next |
| 1855 | note pick, computed at graph version v (an outside planner, or an |
| 1856 | note operator). The proposal names the job, not its slot. Reservations and |
| 1857 | note feasibility still come first: it is checked again when used. 0; -6 no |
| 1858 | note incarnation set or the version exhausted; -9 stale (v is not the |
| 1859 | note current version); -3 no ready job, or more than one, has that id; -8 |
| 1860 | note it does not fit beside the reservation; -7 not policy 2. |
| 1861 | fn sched_propose id ulong v ulong to long |
| 1862 | if ne get scpol 0 2 |
| 1863 | ret neg long 7 |
| 1864 | end |
| 1865 | if ne get scgv 4 1 |
| 1866 | put scgst 5 add get scgst 5 1 |
| 1867 | ret neg long 6 |
| 1868 | end |
| 1869 | if ne v get scgv 0 |
| 1870 | put scgst 4 add get scgst 4 1 |
| 1871 | ret neg long 9 |
| 1872 | end |
| 1873 | j = ulong 64 |
| 1874 | n = ulong 0 |
| 1875 | for k ulong 64 |
| 1876 | if and eq get sjst k 2 eq get sjid k id |
| 1877 | j = k |
| 1878 | n = add n 1 |
| 1879 | end |
| 1880 | end |
| 1881 | if ne n 1 |
| 1882 | put scgst 5 add get scgst 5 1 |
| 1883 | ret neg long 3 |
| 1884 | end |
| 1885 | rq = ulong 0 |
| 1886 | r = get scpol 5 |
| 1887 | if gt r 0 |
| 1888 | rq = get sjneed sub r 1 |
| 1889 | end |
| 1890 | if not sp_fits get sjneed j rq |
| 1891 | put scgst 5 add get scgst 5 1 |
| 1892 | ret neg long 8 |
| 1893 | end |
| 1894 | put scgv 2 add j 1 |
| 1895 | put scgv 3 v |
| 1896 | put scgst 3 add get scgst 3 1 |
| 1897 | ret 0 |
| 1898 | end |
| 1899 | |
| 1900 | note After a fair dispatch event in which ya - 1 was the youngest admission |
| 1901 | note assigned (ya 0: none): every ready job admitted before it was bypassed |
| 1902 | note once; with no reservation, the oldest job at the bypass budget is |
| 1903 | note reserved. One pass over the table (64 maintenance reads, counter 13). |
| 1904 | note Returns the bitmap of the slots bypassed. |
| 1905 | fn sp_after ya ulong to ulong |
| 1906 | o = ulong 64 |
| 1907 | bm = ulong 0 |
| 1908 | nores = eq get scpol 5 0 |
| 1909 | for j ulong 64 |
| 1910 | if eq get sjst j 2 |
| 1911 | if gt ya 0 |
| 1912 | if lt add get sjarr j 1 ya |
| 1913 | put sjbyp j add get sjbyp j 1 |
| 1914 | put scst 5 add get scst 5 1 |
| 1915 | bm = or bm shl 1 j |
| 1916 | end |
| 1917 | end |
| 1918 | if nores |
| 1919 | if ge get sjbyp j get scpol 3 |
| 1920 | if eq o 64 |
| 1921 | o = j |
| 1922 | else |
| 1923 | if lt get sjarr j get sjarr o |
| 1924 | o = j |
| 1925 | end |
| 1926 | end |
| 1927 | end |
| 1928 | end |
| 1929 | end |
| 1930 | end |
| 1931 | put scst 13 add get scst 13 64 |
| 1932 | if lt o 64 |
| 1933 | put scpol 5 add o 1 |
| 1934 | put scst 6 add get scst 6 1 |
| 1935 | end |
| 1936 | ret bm |
| 1937 | end |
| 1938 | |
| 1939 | note Creator: assign ready jobs to idle live workers under the policy, at |
| 1940 | note most the dispatch budget per call. Returns the number assigned. With |
| 1941 | note a journal attached and the replay ring full, nothing is assigned |
| 1942 | note (counter 15) until the journal drains it. |
| 1943 | fn sched_dispatch c long to ulong |
| 1944 | if ne get scpause 0 0 |
| 1945 | ret 0 |
| 1946 | end |
| 1947 | if and ne get sfj 0 0 ge get sfj 1 64 |
| 1948 | put scst 15 add get scst 15 1 |
| 1949 | ret 0 |
| 1950 | end |
| 1951 | n = mapget c 48 8 |
| 1952 | k = ulong 0 |
| 1953 | ya = ulong 0 |
| 1954 | put sfj 2 get scpol 5 |
| 1955 | put sfj 3 0 |
| 1956 | fair = ge get scpol 0 1 |
| 1957 | put scst 2 add get scst 2 1 |
| 1958 | for i ulong get scpol 2 bound 64 |
| 1959 | w = sp_idle n |
| 1960 | if ge w 64 |
| 1961 | break |
| 1962 | end |
| 1963 | j = ulong 64 |
| 1964 | if fair |
| 1965 | j = sp_fair |
| 1966 | else |
| 1967 | j = sp_fifo |
| 1968 | end |
| 1969 | if ge j 64 |
| 1970 | break |
| 1971 | end |
| 1972 | if gt add get sjarr j 1 ya |
| 1973 | ya = add get sjarr j 1 |
| 1974 | end |
| 1975 | sp_fmark j |
| 1976 | sp_start c j w |
| 1977 | k = add k 1 |
| 1978 | end |
| 1979 | bm = ulong 0 |
| 1980 | if fair |
| 1981 | bm = sp_after ya |
| 1982 | end |
| 1983 | sp_frend bm |
| 1984 | ret k |
| 1985 | end |
| 1986 | |
| 1987 | note End of a dispatch event with a journal attached: one ring record when |
| 1988 | note it assigned a job or moved the reservation. |
| 1989 | fn sp_frend bm ulong to void |
| 1990 | if eq get sfj 0 0 |
| 1991 | ret |
| 1992 | end |
| 1993 | if or ne get sfj 3 0 ne get scpol 5 get sfj 2 |
| 1994 | sp_frpush get sfj 3 bm 0 |
| 1995 | end |
| 1996 | end |
| 1997 | |
| 1998 | note The current dispatch event assigned slot j (sfj 3). |
| 1999 | fn sp_fmark j ulong to void |
| 2000 | put sfj 3 or get sfj 3 shl 1 j |
| 2001 | end |
| 2002 | |
| 2003 | note Append one replay record (sfr): event, assigned and bypassed slot |
| 2004 | note bitmaps, cursor, reserved slot + 1, slots made ready. The callers |
| 2005 | note leave room. |
| 2006 | fn sp_frpush am ulong bm ulong rd ulong to void |
| 2007 | b = mul get sfj 1 6 |
| 2008 | put sfr b get scst 2 |
| 2009 | put sfr add b 1 am |
| 2010 | put sfr add b 2 bm |
| 2011 | put sfr add b 3 get scpol 4 |
| 2012 | put sfr add b 4 get scpol 5 |
| 2013 | put sfr add b 5 rd |
| 2014 | put sfj 1 add get sfj 1 1 |
| 2015 | end |
| 2016 | |
| 2017 | note Journal: attach (on) or detach the replay ring. Attaching empties it. |
| 2018 | note jn_recover attaches once the scheduler holds the journaled state. |
| 2019 | fn sched_jattach on bool to void |
| 2020 | put sfj 0 0 |
| 2021 | if on |
| 2022 | put sfj 0 1 |
| 2023 | end |
| 2024 | put sfj 1 0 |
| 2025 | end |
| 2026 | |
| 2027 | fn sched_jattached to bool |
| 2028 | ret ne get sfj 0 0 |
| 2029 | end |
| 2030 | |
| 2031 | note Journal: records waiting in the replay ring, word i (0..5) of record k, |
| 2032 | note and emptying it once they are durable. |
| 2033 | fn sched_frn to ulong |
| 2034 | ret get sfj 1 |
| 2035 | end |
| 2036 | fn sched_frw k ulong i ulong to ulong |
| 2037 | ret get sfr add mul k 6 i |
| 2038 | end |
| 2039 | fn sched_frclear to void |
| 2040 | put sfj 1 0 |
| 2041 | end |
| 2042 | |
| 2043 | note Journal, recovery: the cursor and reservation after replay, and the |
| 2044 | note dispatch event count. The reservation names slot res - 1, which must |
| 2045 | note hold a ready job. -7 (nothing changed) for a cursor outside the table |
| 2046 | note or any other reservation, else 0. |
| 2047 | fn sched_frestore cur ulong ev ulong res ulong to long |
| 2048 | if or ge cur 64 gt res 64 |
| 2049 | ret neg long 7 |
| 2050 | end |
| 2051 | if gt res 0 |
| 2052 | if ne get sjst sub res 1 2 |
| 2053 | ret neg long 7 |
| 2054 | end |
| 2055 | end |
| 2056 | put scpol 4 cur |
| 2057 | put scst 2 ev |
| 2058 | put scpol 5 res |
| 2059 | ret 0 |
| 2060 | end |
| 2061 | |
| 2062 | note Journal, recovery: the bypass count of ready job j. 0 or -3. |
| 2063 | fn sched_setbyp j ulong n ulong to long |
| 2064 | if ge j 64 |
| 2065 | ret neg long 3 |
| 2066 | end |
| 2067 | if ne get sjst j 2 |
| 2068 | ret neg long 3 |
| 2069 | end |
| 2070 | put sjbyp j n |
| 2071 | ret 0 |
| 2072 | end |
| 2073 | |
| 2074 | note Journal, recovery: waiting job j was made ready by a publication |
| 2075 | note before the restart. 0 or -3 (j not waiting). |
| 2076 | fn sched_setready j ulong to long |
| 2077 | if ge j 64 |
| 2078 | ret neg long 3 |
| 2079 | end |
| 2080 | if ne get sjst j 1 |
| 2081 | ret neg long 3 |
| 2082 | end |
| 2083 | sp_ready j |
| 2084 | ret 0 |
| 2085 | end |
| 2086 | |
| 2087 | note Creator: move finished jobs into review while review has room. A worker |
| 2088 | note whose result is waiting for room keeps it and gets no new job, so a |
| 2089 | note full review queue stops assignment instead of dropping work. A job |
| 2090 | note gives back its resources as soon as its worker reported done, even |
| 2091 | note while its result waits for room. |
| 2092 | fn sched_collect c long to ulong |
| 2093 | n = mapget c 48 8 |
| 2094 | k = ulong 0 |
| 2095 | for w ulong n bound 64 |
| 2096 | b = get scbusy w |
| 2097 | if gt b 0 |
| 2098 | if eq sc_cell w 64 get scseq w |
| 2099 | j = sub b 1 |
| 2100 | sp_give j |
| 2101 | if ge sched_count 4 4 get sclim 1 |
| 2102 | continue |
| 2103 | end |
| 2104 | put sjst j 4 |
| 2105 | put sjout j sc_cell w 72 |
| 2106 | put scbusy w 0 |
| 2107 | k = add k 1 |
| 2108 | end |
| 2109 | end |
| 2110 | end |
| 2111 | ret k |
| 2112 | end |
| 2113 | |
| 2114 | note Creator, after worker w was reaped: retire its unfinished assignment. |
| 2115 | note A rerunnable job is ready again; any other becomes UNKNOWN (6), since |
| 2116 | note it may have had effects. A finished result is left for sched_collect. |
| 2117 | note Returns 1 when an assignment was retired, 0 when none, -16 still live. |
| 2118 | fn sched_lost c long w ulong to long |
| 2119 | if ge w 64 |
| 2120 | ret neg long 7 |
| 2121 | end |
| 2122 | if gt get swpid w 0 |
| 2123 | ret neg long 16 |
| 2124 | end |
| 2125 | b = get scbusy w |
| 2126 | if eq b 0 |
| 2127 | ret 0 |
| 2128 | end |
| 2129 | if eq sc_cell w 64 get scseq w |
| 2130 | ret 0 |
| 2131 | end |
| 2132 | j = sub b 1 |
| 2133 | sc_set w 64 get scseq w |
| 2134 | put scbusy w 0 |
| 2135 | sp_give j |
| 2136 | if ne and get sjfl j 1 0 |
| 2137 | sp_ready j |
| 2138 | else |
| 2139 | put sjst j 6 |
| 2140 | end |
| 2141 | ret 1 |
| 2142 | end |
| 2143 | |
| 2144 | note Creator loop step: wait up to interval ns for an ack or a death, take |
| 2145 | note acks, retire the jobs of reaped workers, collect, then dispatch. |
| 2146 | note Returns the number of workers reaped, or a negative errno. |
| 2147 | fn sched_step c long interval long to long |
| 2148 | d = sup_poll c interval |
| 2149 | if lt d 0 |
| 2150 | ret d |
| 2151 | end |
| 2152 | n = mapget c 48 8 |
| 2153 | for w ulong n bound 64 |
| 2154 | if gt get swpid w 0 |
| 2155 | r = sup_take get swack w |
| 2156 | else |
| 2157 | r = sched_lost c w |
| 2158 | end |
| 2159 | end |
| 2160 | k = sched_collect c |
| 2161 | k = sched_dispatch c |
| 2162 | ret d |
| 2163 | end |
| 2164 | |
| 2165 | note Creator: publish an artifact, make waiting jobs whose deps meet topics |
| 2166 | note ready, wake each live worker whose interest meets topics, dispatch. |
| 2167 | note With a journal attached the jobs made ready leave a readiness record |
| 2168 | note in the replay ring; when the ring is full nothing is published, -105 |
| 2169 | note (counter 15). Returns the version, or the publish refusal with nothing |
| 2170 | note woken. |
| 2171 | fn sched_publish c long topics ulong src view uchar 4096 n ulong to long |
| 2172 | if and ne get sfj 0 0 ge get sfj 1 64 |
| 2173 | put scst 15 add get scst 15 1 |
| 2174 | ret neg long 105 |
| 2175 | end |
| 2176 | v = pool_publish c topics src n |
| 2177 | if le v 0 |
| 2178 | ret v |
| 2179 | end |
| 2180 | rd = ulong 0 |
| 2181 | for j ulong 64 |
| 2182 | if eq get sjst j 1 |
| 2183 | if ne and get sjdep j topics 0 |
| 2184 | sp_ready j |
| 2185 | rd = or rd shl 1 j |
| 2186 | end |
| 2187 | end |
| 2188 | end |
| 2189 | if and ne rd 0 ne get sfj 0 0 |
| 2190 | sp_frpush 0 0 rd |
| 2191 | end |
| 2192 | m = mapget c 48 8 |
| 2193 | for w ulong m bound 64 |
| 2194 | if gt get swpid w 0 |
| 2195 | if ne and sc_cell w 32 topics 0 |
| 2196 | sc_wake w |
| 2197 | end |
| 2198 | end |
| 2199 | end |
| 2200 | k = sched_dispatch c |
| 2201 | ret v |
| 2202 | end |
| 2203 | |
| 2204 | note Creator: accept the result of job j in review and free its slot. |
| 2205 | note Returns its outcome, or -3 when j is not in review. |
| 2206 | fn sched_review j ulong to long |
| 2207 | if ge j 64 |
| 2208 | ret neg long 3 |
| 2209 | end |
| 2210 | if ne get sjst j 4 |
| 2211 | ret neg long 3 |
| 2212 | end |
| 2213 | put sjst j 0 |
| 2214 | ret long get sjout j |
| 2215 | end |
| 2216 | |
| 2217 | note Creator: free an UNKNOWN job once its outcome has been settled |
| 2218 | note elsewhere. Returns 0, or -3 when j is not UNKNOWN. |
| 2219 | fn sched_settle j ulong to long |
| 2220 | if ge j 64 |
| 2221 | ret neg long 3 |
| 2222 | end |
| 2223 | if ne get sjst j 6 |
| 2224 | ret neg long 3 |
| 2225 | end |
| 2226 | put sjst j 0 |
| 2227 | ret 0 |
| 2228 | end |
| 2229 | |
| 2230 | note Creator: while paused (on true) no job is assigned; running jobs go on |
| 2231 | note and finished results are still collected. Resuming dispatches at once. |
| 2232 | note Returns the number assigned on resume, else 0. |
| 2233 | fn sched_pause c long on bool to ulong |
| 2234 | if on |
| 2235 | put scpause 0 1 |
| 2236 | ret 0 |
| 2237 | end |
| 2238 | put scpause 0 0 |
| 2239 | ret sched_dispatch c |
| 2240 | end |
| 2241 | |
| 2242 | note Creator: cancel job j. A waiting or ready job never started, so it is |
| 2243 | note freed with no effect: 1. A running job needs its worker: 2, and the |
| 2244 | note outcome comes from the worker. A job in review already finished: 3, |
| 2245 | note nothing is cancelled. UNKNOWN stays UNKNOWN: 4. -3 free or bad slot. |
| 2246 | fn sched_cancel j ulong to long |
| 2247 | if ge j 64 |
| 2248 | ret neg long 3 |
| 2249 | end |
| 2250 | s = get sjst j |
| 2251 | if or eq s 1 eq s 2 |
| 2252 | put sjst j 0 |
| 2253 | sp_bump |
| 2254 | if eq get scpol 5 add j 1 |
| 2255 | put scpol 5 0 |
| 2256 | end |
| 2257 | ret 1 |
| 2258 | end |
| 2259 | if eq s 3 |
| 2260 | ret 2 |
| 2261 | end |
| 2262 | if eq s 4 |
| 2263 | ret 3 |
| 2264 | end |
| 2265 | if eq s 6 |
| 2266 | ret 4 |
| 2267 | end |
| 2268 | ret neg long 3 |
| 2269 | end |
| 2270 | |
| 2271 | note Creator: stop every worker within interval ns (sup_stop), retire the |
| 2272 | note assignments of the reaped workers, collect finished results. |
| 2273 | note Returns how many workers had to be killed, or a refusal. |
| 2274 | fn sched_stop c long interval long to long |
| 2275 | k = sup_stop c interval |
| 2276 | if lt k 0 |
| 2277 | ret k |
| 2278 | end |
| 2279 | n = mapget c 48 8 |
| 2280 | for w ulong n bound 64 |
| 2281 | r = sched_lost c w |
| 2282 | end |
| 2283 | m = sched_collect c |
| 2284 | ret k |
| 2285 | end |
| 2286 | |
| 2287 | note Worker w: the assignment seq when a job is waiting, else 0. Job id, |
| 2288 | note input epoch and input version are words 8, 16 and 24 of its cell. |
| 2289 | fn sched_wjob w ulong to ulong |
| 2290 | q = sc_cell w 0 |
| 2291 | if gt q sc_cell w 64 |
| 2292 | ret q |
| 2293 | end |
| 2294 | ret 0 |
| 2295 | end |
| 2296 | |
| 2297 | note Worker w: finish assignment q with outcome and the first n (at most |
| 2298 | note 4096) bytes of src. Bytes and outcome are written before the done seq; |
| 2299 | note then the creator gets an ack. 0, -7 bad n, or the ack refusal. |
| 2300 | fn sched_wdone w ulong q ulong outcome ulong src view uchar 4096 n ulong to long |
| 2301 | if gt n 4096 |
| 2302 | ret neg long 7 |
| 2303 | end |
| 2304 | if gt n 0 |
| 2305 | r = mapwrite get scmap 1 mul w 4096 src 0 n |
| 2306 | end |
| 2307 | sc_set w 72 outcome |
| 2308 | sc_set w 64 q |
| 2309 | ret sup_ack w |
| 2310 | end |
| 2311 | |
| 2312 | note Creator: copy worker w's last result bytes into dst. |
| 2313 | fn sched_result w ulong dst edit uchar 4096 to long |
| 2314 | ret mapread get scmap 1 mul w 4096 dst 0 4096 |
| 2315 | end |
| 2316 | |
| 2317 | note Worker w: sup_wwait that records its wakes and wake latency. |
| 2318 | fn sched_wwait c long w ulong interval long to long |
| 2319 | r = sup_wwait c w interval |
| 2320 | if eq r 1 |
| 2321 | now = ulong monons |
| 2322 | st = sc_cell w 40 |
| 2323 | lat = ulong 0 |
| 2324 | if gt now st |
| 2325 | lat = sub now st |
| 2326 | end |
| 2327 | sc_set w 80 add sc_cell w 80 1 |
| 2328 | sc_set w 88 lat |
| 2329 | if gt lat sc_cell w 96 |
| 2330 | sc_set w 96 lat |
| 2331 | end |
| 2332 | end |
| 2333 | ret r |
| 2334 | end |
| 2335 | |
| 2336 | note Worker w: count the versions of the current epoch that meet its |
| 2337 | note interest and are newer than its cursor, moving the cursor past them. |
| 2338 | note A new epoch restarts the cursor at 0. A worker with no interest scans |
| 2339 | note nothing. Returns the count or a refusal. |
| 2340 | fn sched_wscan c long w ulong to long |
| 2341 | t = sc_cell w 32 |
| 2342 | if eq t 0 |
| 2343 | ret 0 |
| 2344 | end |
| 2345 | h = pool_acquire c w |
| 2346 | if le h 0 |
| 2347 | ret h |
| 2348 | end |
| 2349 | e = mapget c add 256 mul w 8 8 |
| 2350 | if ne get swcur 0 e |
| 2351 | put swcur 0 e |
| 2352 | put swcur 1 0 |
| 2353 | end |
| 2354 | k = long 0 |
| 2355 | for i ulong 65 |
| 2356 | v = node_next h get swcur 1 t |
| 2357 | if lt v 0 |
| 2358 | r = pool_release c w |
| 2359 | ret v |
| 2360 | end |
| 2361 | if eq v 0 |
| 2362 | break |
| 2363 | end |
| 2364 | put swcur 1 ulong v |
| 2365 | k = add k 1 |
| 2366 | end |
| 2367 | r = pool_release c w |
| 2368 | ret k |
| 2369 | end |
| 2370 | note Concatenate after transport.om, pool.om, super.om and sched.om. CPU-only |
| 2371 | note acceptance of DRA-287 with real forked workers: irrelevant changes, |
| 2372 | note coalesced hints, no lost wake-up, no barrier behind a slow worker, full |
| 2373 | note admission and review queues, dead workers, stop under load, idle CPU and |
| 2374 | note wake latency. No GPU, model or network. |
| 2375 | text sok "PASS node sched\n" |
| 2376 | text sidle "idle ticks workers=" |
| 2377 | text screat " creator=" |
| 2378 | text swake " wake rounds=" |
| 2379 | text smean " mean_us=" |
| 2380 | text smax " max_us=" |
| 2381 | text snl "\n" |
| 2382 | text sproc "/proc/" |
| 2383 | text sstat "/stat" |
| 2384 | global stc long 1 |
| 2385 | global stm long 1 |
| 2386 | |
| 2387 | fn st_ok ok bool code int to void |
| 2388 | if not ok |
| 2389 | exit code |
| 2390 | end |
| 2391 | end |
| 2392 | |
| 2393 | fn st_num v ulong to void |
| 2394 | d = new uchar 20 0 |
| 2395 | x = v |
| 2396 | k = ulong 20 |
| 2397 | for i ulong 20 |
| 2398 | k = sub k 1 |
| 2399 | put d k uchar add rem x 10 48 |
| 2400 | x = div x 10 |
| 2401 | if eq x 0 |
| 2402 | break |
| 2403 | end |
| 2404 | end |
| 2405 | r = write 1 d k sub 20 k |
| 2406 | end |
| 2407 | |
| 2408 | note Write "/proc/<pid>/stat" into p; returns its length. |
| 2409 | fn st_path pid ulong p edit uchar 64 to ulong |
| 2410 | d = new uchar 20 0 |
| 2411 | for i ulong 6 |
| 2412 | put p i get sproc i |
| 2413 | end |
| 2414 | x = pid |
| 2415 | k = ulong 20 |
| 2416 | for i ulong 20 |
| 2417 | k = sub k 1 |
| 2418 | put d k uchar add rem x 10 48 |
| 2419 | x = div x 10 |
| 2420 | if eq x 0 |
| 2421 | break |
| 2422 | end |
| 2423 | end |
| 2424 | n = ulong 6 |
| 2425 | for i ulong sub 20 k bound 20 |
| 2426 | put p n get d add k i |
| 2427 | n = add n 1 |
| 2428 | end |
| 2429 | for i ulong 5 |
| 2430 | put p n get sstat i |
| 2431 | n = add n 1 |
| 2432 | end |
| 2433 | ret n |
| 2434 | end |
| 2435 | |
| 2436 | note Sum of fields 14 and 15 (utime, stime) of a /proc stat line of got bytes. |
| 2437 | fn st_parse b view uchar 1024 got ulong to ulong |
| 2438 | rp = ulong 0 |
| 2439 | for i ulong got bound 1023 |
| 2440 | if eq get b i 41 |
| 2441 | rp = i |
| 2442 | end |
| 2443 | end |
| 2444 | field = ulong 2 |
| 2445 | t = ulong 0 |
| 2446 | v = ulong 0 |
| 2447 | for i ulong sub got rp bound 1023 |
| 2448 | c = get b add rp i |
| 2449 | if eq c 32 |
| 2450 | if or eq field 14 eq field 15 |
| 2451 | t = add t v |
| 2452 | end |
| 2453 | field = add field 1 |
| 2454 | v = 0 |
| 2455 | else |
| 2456 | if and ge c 48 le c 57 |
| 2457 | v = add mul v 10 sub ulong c 48 |
| 2458 | end |
| 2459 | end |
| 2460 | end |
| 2461 | ret t |
| 2462 | end |
| 2463 | |
| 2464 | note utime + stime of process pid in clock ticks, from /proc/pid/stat. |
| 2465 | fn st_ticks pid ulong to ulong |
| 2466 | p = new uchar 64 0 |
| 2467 | b = new uchar 1024 0 |
| 2468 | n = st_path pid p |
| 2469 | fd = fopen p 0 n 524288 0 |
| 2470 | if lt fd 0 |
| 2471 | exit 150 |
| 2472 | end |
| 2473 | got = read int fd b 0 1023 |
| 2474 | r = fclose int fd |
| 2475 | if le got 0 |
| 2476 | exit 151 |
| 2477 | end |
| 2478 | ret st_parse b ulong got |
| 2479 | end |
| 2480 | |
| 2481 | note Worker: run the job of assignment q cooperatively for the number of |
| 2482 | note milliseconds in the low four decimal digits of its id, then report |
| 2483 | note outcome id+1 and 64 bytes of the id's low byte. 0 done, 2 stopped, |
| 2484 | note 3 creator gone, 4 wait error, 5 report refused. |
| 2485 | fn st_run c long w ulong q ulong to int |
| 2486 | buf = new uchar 4096 0 |
| 2487 | id = sc_cell w 8 |
| 2488 | dl = add ulong monons mul rem id 10000 1000000 |
| 2489 | for t ulong 1000000 |
| 2490 | now = ulong monons |
| 2491 | if ge now dl |
| 2492 | break |
| 2493 | end |
| 2494 | r = sched_wwait c w long sub dl now |
| 2495 | if eq r 2 |
| 2496 | ret 2 |
| 2497 | end |
| 2498 | if eq r 3 |
| 2499 | ret 3 |
| 2500 | end |
| 2501 | if lt r 0 |
| 2502 | ret 4 |
| 2503 | end |
| 2504 | end |
| 2505 | for j ulong 64 |
| 2506 | put buf j uchar and id 255 |
| 2507 | end |
| 2508 | if ne sched_wdone w q add id 1 buf 64 0 |
| 2509 | ret 5 |
| 2510 | end |
| 2511 | ret 0 |
| 2512 | end |
| 2513 | |
| 2514 | note Worker loop: run an assigned job, else scan the subscribed versions, |
| 2515 | note record how many it has seen, and wait without a deadline. A worker with |
| 2516 | note its lazy flag set sleeps 300 ms before each wait, so hints pile up. |
| 2517 | fn st_worker w ulong to int |
| 2518 | c = get stc 0 |
| 2519 | m = get stm 0 |
| 2520 | seen = ulong 0 |
| 2521 | for it ulong 1000000000 |
| 2522 | q = sched_wjob w |
| 2523 | if gt q 0 |
| 2524 | r = st_run c w q |
| 2525 | if eq r 2 |
| 2526 | ret 0 |
| 2527 | end |
| 2528 | if ne r 0 |
| 2529 | ret add 60 r |
| 2530 | end |
| 2531 | continue |
| 2532 | end |
| 2533 | k = sched_wscan c w |
| 2534 | if eq k neg long 1 |
| 2535 | ret 0 |
| 2536 | end |
| 2537 | if lt k 0 |
| 2538 | ret 59 |
| 2539 | end |
| 2540 | seen = add seen ulong k |
| 2541 | r = mapset m add 64 mul w 8 8 seen |
| 2542 | if ne mapget m add 600 mul w 8 8 0 |
| 2543 | r = sleepns 300000000 |
| 2544 | end |
| 2545 | r = sched_wwait c w neg long 1 |
| 2546 | if eq r 2 |
| 2547 | ret 0 |
| 2548 | end |
| 2549 | if eq r 3 |
| 2550 | ret 41 |
| 2551 | end |
| 2552 | if lt r 0 |
| 2553 | ret 43 |
| 2554 | end |
| 2555 | end |
| 2556 | ret 45 |
| 2557 | end |
| 2558 | |
| 2559 | fn st_spawn c long w ulong to bool |
| 2560 | p = sup_spawn c w |
| 2561 | if eq p 0 |
| 2562 | exit st_worker w |
| 2563 | end |
| 2564 | ret gt p 0 |
| 2565 | end |
| 2566 | |
| 2567 | note Fresh pool of 4 arenas for w workers with limits a and rl, plus the test |
| 2568 | note page. Exits with code on any refusal. |
| 2569 | fn st_setup w ulong a ulong rl ulong code int to long |
| 2570 | c = pool_new 4 w |
| 2571 | st_ok gt c 0 code |
| 2572 | put stc 0 c |
| 2573 | m = mapnew neg int 1 0 4096 3 33 |
| 2574 | st_ok gt m 0 code |
| 2575 | put stm 0 m |
| 2576 | st_ok eq sup_init c 0 code |
| 2577 | st_ok eq sched_new c a rl 0 code |
| 2578 | ret c |
| 2579 | end |
| 2580 | |
| 2581 | fn st_down c long code int to void |
| 2582 | st_ok ge sched_stop c 2000000000 0 code |
| 2583 | sup_closeall |
| 2584 | st_ok eq sched_free 0 code |
| 2585 | st_ok eq pool_free c 0 code |
| 2586 | st_ok eq mapdrop get stm 0 0 code |
| 2587 | end |
| 2588 | |
| 2589 | note Step the creator until at least n jobs are in state st, up to ms. |
| 2590 | fn st_until c long st ulong n ulong ms ulong to bool |
| 2591 | dl = add ulong monons mul ms 1000000 |
| 2592 | for t ulong 1000000 |
| 2593 | if ge sched_count st st n |
| 2594 | ret true |
| 2595 | end |
| 2596 | if ge ulong monons dl |
| 2597 | ret false |
| 2598 | end |
| 2599 | r = sched_step c 10000000 |
| 2600 | end |
| 2601 | ret false |
| 2602 | end |
| 2603 | |
| 2604 | note Wait up to ms for worker w's seen count to reach n. |
| 2605 | fn st_seen w ulong n ulong ms ulong to bool |
| 2606 | dl = add ulong monons mul ms 1000000 |
| 2607 | for t ulong 1000000 |
| 2608 | if ge mapget get stm 0 add 64 mul w 8 8 n |
| 2609 | ret true |
| 2610 | end |
| 2611 | if ge ulong monons dl |
| 2612 | ret false |
| 2613 | end |
| 2614 | r = sleepns 1000000 |
| 2615 | end |
| 2616 | ret false |
| 2617 | end |
| 2618 | |
| 2619 | note Phase A: interests w0 topic 1, w1 topic 2, w2 topic 1 and lazy. Topic 4 |
| 2620 | note publications wake nobody. One topic 1 publication wakes w2; the next 29 |
| 2621 | note land while it sleeps and reach it in exactly one more wake. w0 sees all |
| 2622 | note 30, w1 is never woken. |
| 2623 | fn st_hints to void |
| 2624 | buf = new uchar 4096 0 |
| 2625 | c = st_setup 3 8 8 10 |
| 2626 | m = get stm 0 |
| 2627 | st_ok eq sched_want 0 1 0 11 |
| 2628 | st_ok eq sched_want 1 2 0 12 |
| 2629 | st_ok eq sched_want 2 1 0 13 |
| 2630 | r = mapset m 616 8 1 |
| 2631 | for w ulong 3 |
| 2632 | st_ok st_spawn c w 14 |
| 2633 | end |
| 2634 | r = sleepns 100000000 |
| 2635 | for i ulong 20 |
| 2636 | st_ok gt sched_publish c 4 buf 16 0 15 |
| 2637 | end |
| 2638 | r = sleepns 500000000 |
| 2639 | for w ulong 3 |
| 2640 | st_ok eq sc_cell w 80 0 16 |
| 2641 | st_ok eq mapget m add 64 mul w 8 8 0 17 |
| 2642 | end |
| 2643 | st_ok gt sched_publish c 1 buf 16 0 18 |
| 2644 | st_ok st_seen 2 1 3000 19 |
| 2645 | for i ulong 29 |
| 2646 | st_ok gt sched_publish c 1 buf 16 0 29 |
| 2647 | end |
| 2648 | st_ok st_seen 0 30 3000 44 |
| 2649 | st_ok st_seen 2 30 3000 20 |
| 2650 | r = sleepns 400000000 |
| 2651 | st_ok eq mapget m 64 8 30 21 |
| 2652 | st_ok eq mapget m 80 8 30 22 |
| 2653 | st_ok eq mapget m 72 8 0 23 |
| 2654 | st_ok eq sc_cell 1 80 0 24 |
| 2655 | st_ok eq sc_cell 2 80 2 25 |
| 2656 | st_ok ge sc_cell 0 80 1 26 |
| 2657 | st_ok le sc_cell 0 80 30 27 |
| 2658 | st_down c 28 |
| 2659 | end |
| 2660 | |
| 2661 | fn st_admit id ulong deps ulong fl ulong code int to ulong |
| 2662 | j = sched_admit id deps fl |
| 2663 | st_ok ge j 0 code |
| 2664 | ret ulong j |
| 2665 | end |
| 2666 | |
| 2667 | note Phase B: one slow job and six fast ones on three workers. The fast jobs |
| 2668 | note finish and are reviewed while the slow one still runs (no barrier). |
| 2669 | fn st_nobar to void |
| 2670 | buf = new uchar 4096 0 |
| 2671 | c = st_setup 3 8 8 30 |
| 2672 | for w ulong 3 |
| 2673 | st_ok st_spawn c w 31 |
| 2674 | end |
| 2675 | s = st_admit 11500 0 0 32 |
| 2676 | for i ulong 6 |
| 2677 | j = st_admit add mul add i 2 10000 20 0 0 33 |
| 2678 | end |
| 2679 | st_ok st_until c 4 6 5000 34 |
| 2680 | st_ok eq get sjst s 3 35 |
| 2681 | for j ulong 64 |
| 2682 | if and eq get sjst j 4 ne j s |
| 2683 | st_ok eq sched_review j long add get sjid j 1 36 |
| 2684 | end |
| 2685 | end |
| 2686 | st_ok eq sched_count 1 4 1 37 |
| 2687 | st_ok st_until c 4 1 5000 38 |
| 2688 | w = get sjw s |
| 2689 | st_ok eq sched_review s 11501 39 |
| 2690 | st_ok eq sched_result w buf 4096 40 |
| 2691 | st_ok eq get buf 63 236 41 |
| 2692 | st_ok eq sched_count 1 6 0 42 |
| 2693 | st_down c 43 |
| 2694 | end |
| 2695 | |
| 2696 | note Phase C: admission refuses past 8 and review holds at 2. Workers keep |
| 2697 | note finished results instead of taking more work; reviewing drains it all. |
| 2698 | fn st_full to void |
| 2699 | c = st_setup 3 8 2 45 |
| 2700 | for w ulong 3 |
| 2701 | st_ok st_spawn c w 46 |
| 2702 | end |
| 2703 | for i ulong 8 |
| 2704 | j = st_admit add mul add i 1 10000 20 0 0 47 |
| 2705 | end |
| 2706 | st_ok eq sched_admit 99020 0 0 neg long 2 48 |
| 2707 | st_ok st_until c 4 2 5000 49 |
| 2708 | r = sleepns 300000000 |
| 2709 | for t ulong 20 |
| 2710 | r = sched_step c 10000000 |
| 2711 | end |
| 2712 | st_ok eq sched_count 4 4 2 50 |
| 2713 | st_ok eq sched_count 3 3 3 51 |
| 2714 | st_ok eq sched_count 2 2 3 52 |
| 2715 | for w ulong 3 |
| 2716 | st_ok eq sc_cell w 64 get scseq w 53 |
| 2717 | end |
| 2718 | note Jobs in review no longer count as admitted: 3 held results + 3 ready. |
| 2719 | st_ok eq sched_count 1 3 6 54 |
| 2720 | n = ulong 0 |
| 2721 | for t ulong 400 |
| 2722 | for j ulong 64 |
| 2723 | if eq get sjst j 4 |
| 2724 | st_ok eq sched_review j long add get sjid j 1 55 |
| 2725 | n = add n 1 |
| 2726 | end |
| 2727 | end |
| 2728 | if eq n 8 |
| 2729 | break |
| 2730 | end |
| 2731 | r = sched_step c 10000000 |
| 2732 | end |
| 2733 | st_ok eq n 8 56 |
| 2734 | st_ok ge sched_admit 99020 0 0 0 57 |
| 2735 | st_down c 58 |
| 2736 | end |
| 2737 | |
| 2738 | note Phase D: a job that waits on topic 8 starts only after a topic 8 |
| 2739 | note publication; topic 16 does not start it. |
| 2740 | fn st_deps to void |
| 2741 | buf = new uchar 4096 0 |
| 2742 | c = st_setup 2 8 8 65 |
| 2743 | for w ulong 2 |
| 2744 | st_ok st_spawn c w 66 |
| 2745 | end |
| 2746 | j = st_admit 10020 8 0 67 |
| 2747 | st_ok eq get sjst j 1 68 |
| 2748 | st_ok gt sched_publish c 16 buf 16 0 69 |
| 2749 | st_ok not st_until c 4 1 300 70 |
| 2750 | st_ok eq get sjst j 1 71 |
| 2751 | st_ok gt sched_publish c 8 buf 16 0 72 |
| 2752 | st_ok st_until c 4 1 3000 73 |
| 2753 | st_ok eq sched_review j 10021 74 |
| 2754 | st_down c 75 |
| 2755 | end |
| 2756 | |
| 2757 | note Phase E: kill two workers mid-job. The rerunnable job runs again on the |
| 2758 | note third worker; the other becomes UNKNOWN and is never run again. |
| 2759 | note Respawned workers find their old assignment retired. |
| 2760 | fn st_dead to void |
| 2761 | c = st_setup 3 8 8 76 |
| 2762 | for w ulong 3 |
| 2763 | st_ok st_spawn c w 77 |
| 2764 | end |
| 2765 | x = st_admit 11500 0 0 78 |
| 2766 | y = st_admit 21500 0 1 79 |
| 2767 | st_ok st_until c 3 2 2000 80 |
| 2768 | wx = get sjw x |
| 2769 | wy = get sjw y |
| 2770 | st_ok eq killpid int get swpid wx 9 0 81 |
| 2771 | st_ok eq killpid int get swpid wy 9 0 82 |
| 2772 | st_ok st_until c 6 1 3000 83 |
| 2773 | st_ok eq get sjatt x 1 84 |
| 2774 | st_ok st_until c 4 1 5000 85 |
| 2775 | st_ok eq get sjatt y 2 86 |
| 2776 | st_ok eq sched_review y 21501 87 |
| 2777 | st_ok eq get sjst x 6 88 |
| 2778 | st_ok eq sched_review x neg long 3 89 |
| 2779 | st_ok st_spawn c wx 90 |
| 2780 | st_ok st_spawn c wy 91 |
| 2781 | st_ok eq sc_cell wx 64 get scseq wx 92 |
| 2782 | st_ok eq sc_cell wy 64 get scseq wy 93 |
| 2783 | for t ulong 30 |
| 2784 | r = sched_step c 10000000 |
| 2785 | end |
| 2786 | st_ok eq get sjst x 6 94 |
| 2787 | st_ok eq sched_settle x 0 95 |
| 2788 | st_ok eq sched_count 1 6 0 96 |
| 2789 | st_down c 97 |
| 2790 | end |
| 2791 | |
| 2792 | note Phase F: stop with eight long jobs admitted and three running. Every |
| 2793 | note worker leaves cooperatively well inside the deadline; the three running |
| 2794 | note jobs become UNKNOWN; the five never started stay ready. |
| 2795 | fn st_stop to void |
| 2796 | c = st_setup 3 8 8 115 |
| 2797 | for w ulong 3 |
| 2798 | st_ok st_spawn c w 116 |
| 2799 | end |
| 2800 | for i ulong 8 |
| 2801 | j = st_admit add mul add i 1 10000 5000 0 0 117 |
| 2802 | end |
| 2803 | st_ok st_until c 3 3 2000 118 |
| 2804 | t0 = ulong monons |
| 2805 | st_ok eq sched_stop c 2000000000 0 119 |
| 2806 | st_ok lt sub ulong monons t0 1000000000 120 |
| 2807 | st_ok eq sup_live c 0 121 |
| 2808 | st_ok eq sched_count 6 6 3 122 |
| 2809 | st_ok eq sched_count 2 2 5 123 |
| 2810 | for w ulong 3 |
| 2811 | st_ok eq get swst w 0 124 |
| 2812 | end |
| 2813 | sup_closeall |
| 2814 | st_ok eq sched_free 0 125 |
| 2815 | st_ok eq pool_free c 0 126 |
| 2816 | st_ok eq mapdrop get stm 0 0 127 |
| 2817 | end |
| 2818 | |
| 2819 | note CPU ticks used by both workers (word 1000) and the creator (1008) of the |
| 2820 | note test page while the creator waits 2 s with nothing to do. |
| 2821 | fn st_idlecpu c long to void |
| 2822 | m = get stm 0 |
| 2823 | p0 = ulong get swpid 0 |
| 2824 | p1 = ulong get swpid 1 |
| 2825 | me = ulong getpid |
| 2826 | a0 = add st_ticks p0 st_ticks p1 |
| 2827 | a1 = st_ticks me |
| 2828 | r = sched_step c 2000000000 |
| 2829 | b0 = add st_ticks p0 st_ticks p1 |
| 2830 | b1 = st_ticks me |
| 2831 | r = mapset m 1000 8 sub b0 a0 |
| 2832 | r = mapset m 1008 8 sub b1 a1 |
| 2833 | end |
| 2834 | |
| 2835 | note 200 rounds of one topic 1 publication, each seen by both workers before |
| 2836 | note the next. Returns the sum of the per-round wake latencies in ns. |
| 2837 | fn st_rounds c long to ulong |
| 2838 | buf = new uchar 4096 0 |
| 2839 | sum = ulong 0 |
| 2840 | for i ulong 200 |
| 2841 | st_ok gt sched_publish c 1 buf 16 0 134 |
| 2842 | for w ulong 2 |
| 2843 | st_ok st_seen w add i 1 2000 135 |
| 2844 | sum = add sum sc_cell w 88 |
| 2845 | end |
| 2846 | end |
| 2847 | ret sum |
| 2848 | end |
| 2849 | |
| 2850 | note Phase G: two idle workers block while the creator idles 2 s; then 200 |
| 2851 | note publication rounds wake each worker exactly once per round (no lost and |
| 2852 | note no extra wake-ups). |
| 2853 | fn st_idle to void |
| 2854 | c = st_setup 2 8 8 130 |
| 2855 | m = get stm 0 |
| 2856 | st_ok eq sched_want 0 1 0 131 |
| 2857 | st_ok eq sched_want 1 1 0 132 |
| 2858 | for w ulong 2 |
| 2859 | st_ok st_spawn c w 133 |
| 2860 | end |
| 2861 | r = sleepns 200000000 |
| 2862 | st_idlecpu c |
| 2863 | st_ok le mapget m 1000 8 2 138 |
| 2864 | st_ok le mapget m 1008 8 2 139 |
| 2865 | sum = st_rounds c |
| 2866 | st_ok eq sc_cell 0 80 200 136 |
| 2867 | st_ok eq sc_cell 1 80 200 137 |
| 2868 | r = write 1 sidle 0 len sidle |
| 2869 | st_num mapget m 1000 8 |
| 2870 | r = write 1 screat 0 len screat |
| 2871 | st_num mapget m 1008 8 |
| 2872 | r = write 1 swake 0 len swake |
| 2873 | st_num 200 |
| 2874 | r = write 1 smean 0 len smean |
| 2875 | st_num div sum 400000 |
| 2876 | r = write 1 smax 0 len smax |
| 2877 | mx = sc_cell 0 96 |
| 2878 | if gt sc_cell 1 96 mx |
| 2879 | mx = sc_cell 1 96 |
| 2880 | end |
| 2881 | st_num div mx 1000 |
| 2882 | r = write 1 snl 0 1 |
| 2883 | st_down c 140 |
| 2884 | end |
| 2885 | |
| 2886 | fn st_isarg to bool |
| 2887 | a = new uchar 16 0 |
| 2888 | if ne argcnt 2 |
| 2889 | ret false |
| 2890 | end |
| 2891 | ret eq argread 1 a 0 16 4 |
| 2892 | end |
| 2893 | |
| 2894 | note With one 4-byte argument ("idle"), run only phase G. |
| 2895 | fn main to int |
| 2896 | if st_isarg |
| 2897 | st_idle |
| 2898 | ret 0 |
| 2899 | end |
| 2900 | st_hints |
| 2901 | st_nobar |
| 2902 | st_full |
| 2903 | st_deps |
| 2904 | st_dead |
| 2905 | st_stop |
| 2906 | st_idle |
| 2907 | if ne write 1 sok 0 len sok long len sok |
| 2908 | ret 100 |
| 2909 | end |
| 2910 | ret 0 |
| 2911 | end |