interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / node / schedpol-gate.om

3683 lines · 94675 bytes Raw Blame History
1note Omega Node transport, concatenate with a program-mode consumer.
2note Trusted forked processes only. This is transport, not write authority.
3note One publisher PID, 64 immutable records per epoch; reuse only via node_reset.
4note Layout: 4096 byte header then 64 slots of 4160 bytes.
5note Header u64: magic, ABI, published count, stop, publisher PID, epoch.
6note Slot u64: version, length, topic mask; payload begins at offset 64.
7const NCAP ulong 64
8const NBYTES ulong 270336
9const NMAGIC ulong 1313817669
10
11fn node_new to long
12h = mapnew neg int 1 0 NBYTES 3 33
13if le h 0
14ret h
15end
16r = mapset h 8 8 1
17r = mapset h 32 8 ulong getpid
18r = mapset h 0 8 NMAGIC
19ret h
20end
21
22fn node_valid h long to bool
23ret and eq mapget h 0 8 NMAGIC eq mapget h 8 8 1
24end
25
26fn node_offset v ulong to ulong
27ret add 4096 mul sub v 1 4160
28end
29
30note Return version, or -1 stopped, -2 full, -3 length, -4 topic,
31note -5 invalid header, -6 wrong publisher. Refusals do not publish.
32fn node_publish h long topics ulong src view uchar 4096 n ulong to long
33if not node_valid h
34ret neg long 5
35end
36if ne mapget h 32 8 ulong getpid
37ret neg long 6
38end
39if ne mapget h 24 8 0
40ret neg long 1
41end
42if gt n 4096
43ret neg long 3
44end
45if eq topics 0
46ret neg long 4
47end
48v = mapget h 16 8
49if gt v NCAP
50ret neg long 5
51end
52if eq v NCAP
53ret neg long 2
54end
55v = add v 1
56off = node_offset v
57r = mapwrite h add off 64 src 0 n
58r = mapset h add off 8 8 n
59r = mapset h add off 16 8 topics
60note mapset has barriers before and after its aligned store.
61r = mapset h off 8 v
62r = mapset h 16 8 v
63ret long v
64end
65
66note Header and record checks precede copying. No partial publication is read.
67note Returns payload length, -5 invalid header/record, -7 unavailable version.
68fn node_read h long v ulong dst edit uchar 4096 to long
69if not node_valid h
70ret neg long 5
71end
72if or eq v 0 gt v NCAP
73ret neg long 7
74end
75latest = mapget h 16 8
76if gt latest NCAP
77ret neg long 5
78end
79if gt v latest
80ret neg long 7
81end
82off = node_offset v
83if ne mapget h off 8 v
84ret neg long 5
85end
86n = mapget h add off 8 8
87if gt n 4096
88ret neg long 5
89end
90ret mapread h add off 64 dst 0 n
91end
92
93note Return the next matching version after cursor, zero if caught up,
94note or negative refusal. Caller advances its cursor through returned versions.
95fn node_next h long cursor ulong topics ulong to long
96if not node_valid h
97ret neg long 5
98end
99if or gt cursor NCAP eq topics 0
100ret neg long 7
101end
102latest = mapget h 16 8
103if or gt latest NCAP gt cursor latest
104ret neg long 5
105end
106v = cursor
107note At most NCAP published slots can be examined.
108while lt v latest bound 64
109v = add v 1
110off = node_offset v
111if ne mapget h off 8 v
112ret neg long 5
113end
114if ne and mapget h add off 16 8 topics 0
115ret long v
116end
117end
118ret 0
119end
120
121fn node_stop h long to long
122if not node_valid h
123ret neg long 5
124end
125if ne mapget h 32 8 ulong getpid
126ret neg long 6
127end
128ret mapset h 24 8 1
129end
130
131note Creator only. Retire every record so a pool can reuse the arena for a new
132note epoch. The caller must first prove no reader holds the old epoch (pool.om).
133note The count drops to zero before any record version is cleared.
134fn node_reset h long epoch ulong to long
135if not node_valid h
136ret neg long 5
137end
138if ne mapget h 32 8 ulong getpid
139ret neg long 6
140end
141if eq epoch 0
142ret neg long 7
143end
144r = mapset h 16 8 0
145for i ulong NCAP
146r = mapset h node_offset add i 1 8 0
147end
148r = mapset h 24 8 0
149r = mapset h 40 8 epoch
150ret 0
151end
152
153fn node_epoch h long to ulong
154ret mapget h 40 8
155end
156
157note The latest published version of the arena's current epoch (0 when empty).
158fn node_count h long to ulong
159ret mapget h 16 8
160end
161
162note One nonblocking eventfd per consumer. Saturation means already readable.
163note Interrupted operations retry at most 64 times, then return EINTR.
164fn node_notify fd int to long
165buf = new uchar 8 0
166put buf 0 1
167for i ulong 64
168r = write fd buf 0 8
169if eq r 8
170ret 0
171end
172if eq r neg long 11
173ret 0
174end
175if ne r neg long 4
176if lt r 0
177ret r
178end
179ret neg long 5
180end
181end
182ret neg long 4
183end
184
185fn node_drain fd int to long
186buf = new uchar 8 0
187for i ulong 64
188r = read fd buf 0 8
189if or eq r 8 eq r neg long 11
190ret 0
191end
192if ne r neg long 4
193if lt r 0
194ret r
195end
196ret neg long 5
197end
198end
199ret neg long 4
200end
201
202fn node_pollfd p edit uchar 16 off ulong fd int to void
203for i ulong 4
204put p add off i uchar and shr uint fd uint mul i 8 255
205end
206put p add off 4 1
207end
208
209note Returns 2 stop, 1 wake, 0 timeout or negative errno.
210note Control takes priority when both descriptors are ready.
211note EINTR returns to caller so it can recompute its monotonic deadline.
212fn node_wait h long wake int stop int interval long to long
213p = new uchar 16 0
214if not node_valid h
215ret neg long 5
216end
217if or lt wake 0 lt stop 0
218ret neg long 9
219end
220if eq wake stop
221ret neg long 22
222end
223if ne mapget h 24 8 0
224ret 2
225end
226node_pollfd p 0 wake
227node_pollfd p 8 stop
228r = pollfds p 0 16 interval
229if lt r 0
230ret r
231end
232if ne mapget h 24 8 0
233ret 2
234end
235if ne and get p 14 56 0
236ret neg long 5
237end
238if ne and get p 14 1 0
239r = node_drain stop
240if lt r 0
241ret r
242end
243ret 2
244end
245if ne and get p 6 56 0
246ret neg long 5
247end
248if ne and get p 6 1 0
249r = node_drain wake
250if lt r 0
251ret r
252end
253ret 1
254end
255ret 0
256end
257note Omega Node epoch pool. Concatenate after transport.om, before super.om.
258note K arenas (1..8) and one control page are mapped before any worker fork,
259note so every forked worker inherits the same shared mappings.
260note Single writer: the creator writes the current epoch, the arena table and
261note every arena record. Worker w alone writes hold word w while it lives;
262note the creator clears hold w only after it has reaped worker w.
263note Control u64: 0 magic, 8 ABI, 16 current epoch, 24 stop, 32 creator PID,
264note 40 arena count K, 48 worker slots W, 64+8k arena handle k,
265note 128+8k epoch of arena k (0 free), 256+8w hold of worker w (0 none),
266note 768+8w worker PID, 1280+8w worker state (0 empty, 1 live, 2 reaped).
267const PMAGIC ulong 1347374924
268const PCAP ulong 8
269const PWCAP ulong 64
270const PBYTES ulong 4096
271
272fn pool_valid c long to bool
273ret and eq mapget c 0 8 PMAGIC eq mapget c 8 8 1
274end
275
276fn pool_mine c long to bool
277ret eq mapget c 32 8 ulong getpid
278end
279
280fn pool_arena c long k ulong to long
281ret long mapget c add 64 mul k 8 8
282end
283
284note Drop the first n arenas and the control page of a pool being refused.
285fn pool_unwind c long n ulong to long
286for i ulong n bound 8
287r = mapdrop pool_arena c i
288end
289ret mapdrop c
290end
291
292note Return the control handle, or -7 bad size, or a negative mapping errno.
293note Arena 0 starts as epoch 1. Call before forking any worker.
294fn pool_new k ulong w ulong to long
295if or eq k 0 gt k PCAP
296ret neg long 7
297end
298if or eq w 0 gt w PWCAP
299ret neg long 7
300end
301c = mapnew neg int 1 0 PBYTES 3 33
302if le c 0
303ret c
304end
305r = mapset c 32 8 ulong getpid
306r = mapset c 40 8 k
307r = mapset c 48 8 w
308for i ulong k bound 8
309h = node_new
310if le h 0
311r = pool_unwind c i
312ret h
313end
314r = mapset c add 64 mul i 8 8 ulong h
315end
316r = node_reset pool_arena c 0 1
317r = mapset c 128 8 1
318r = mapset c 16 8 1
319r = mapset c 8 8 1
320r = mapset c 0 8 PMAGIC
321ret c
322end
323
324note Arena index holding epoch e, or -5 when no arena holds it.
325fn pool_slot c long e ulong to long
326k = mapget c 40 8
327if gt k PCAP
328ret neg long 5
329end
330for i ulong k bound 8
331if eq mapget c add 128 mul i 8 8 e
332ret long i
333end
334end
335ret neg long 5
336end
337
338note Creator: the arena of the current epoch, or a negative refusal.
339fn pool_current c long to long
340if not pool_valid c
341ret neg long 5
342end
343k = pool_slot c mapget c 16 8
344if lt k 0
345ret k
346end
347ret pool_arena c ulong k
348end
349
350fn pool_epoch c long to ulong
351ret mapget c 16 8
352end
353
354note Worker step: store hold e for worker w, then read the epoch again. mapset
355note and mapget fence both sides, so a creator that moved the epoch before it
356note scanned holds either sees this hold or this read sees the move. Returns
357note the arena of e, -8 when the epoch moved, or -5 when no arena holds e.
358note Every refusal clears the hold.
359fn pool_hold c long w ulong e ulong to long
360if ge w mapget c 48 8
361ret neg long 7
362end
363hw = add 256 mul w 8
364r = mapset c hw 8 e
365if ne mapget c 16 8 e
366r = mapset c hw 8 0
367ret neg long 8
368end
369k = pool_slot c e
370if lt k 0
371r = mapset c hw 8 0
372ret k
373end
374h = pool_arena c ulong k
375if ne node_epoch h e
376r = mapset c hw 8 0
377ret neg long 5
378end
379ret h
380end
381
382note Worker w holds the current epoch and returns its arena. Returns -1
383note stopped, -5 invalid, -7 bad worker, -8 the epoch kept moving.
384fn pool_acquire c long w ulong to long
385if not pool_valid c
386ret neg long 5
387end
388if ge w mapget c 48 8
389ret neg long 7
390end
391for t ulong 16
392if ne mapget c 24 8 0
393r = mapset c add 256 mul w 8 8 0
394ret neg long 1
395end
396h = pool_hold c w mapget c 16 8
397if ne h neg long 8
398ret h
399end
400end
401ret neg long 8
402end
403
404note Worker w gives up its hold. Its old arena must not be read afterwards.
405fn pool_release c long w ulong to long
406if ge w mapget c 48 8
407ret neg long 7
408end
409ret mapset c add 256 mul w 8 8 0
410end
411
412fn pool_held c long e ulong to bool
413n = mapget c 48 8
414for w ulong n bound 64
415if eq mapget c add 256 mul w 8 8 e
416ret true
417end
418end
419ret false
420end
421
422note Creator step: retire arena i and open epoch n in it, then publish n.
423fn pool_reuse c long i ulong n ulong to long
424off = add 128 mul i 8
425r = mapset c off 8 0
426r = node_reset pool_arena c i n
427if lt r 0
428ret r
429end
430r = mapset c off 8 n
431r = mapset c 16 8 n
432ret long n
433end
434
435note Creator step: an arena that is free or whose older epoch no worker holds,
436note or -9. Call only after the current epoch has moved past that arena.
437fn pool_pick c long to long
438e = mapget c 16 8
439k = mapget c 40 8
440for i ulong k bound 8
441ek = mapget c add 128 mul i 8 8
442if ne ek e
443if or eq ek 0 not pool_held c ek
444ret long i
445end
446end
447end
448ret neg long 9
449end
450
451note Creator: open the next epoch in a free or unheld arena and make it current.
452note Returns the new epoch, -1 stopped, -5 invalid, -6 not creator, or -9 when
453note every other arena is still held: the pool fails closed, nothing changes.
454fn pool_roll c long to long
455if not pool_valid c
456ret neg long 5
457end
458if not pool_mine c
459ret neg long 6
460end
461if ne mapget c 24 8 0
462ret neg long 1
463end
464k = pool_pick c
465if lt k 0
466ret k
467end
468ret pool_reuse c ulong k add mapget c 16 8 1
469end
470
471note Creator: publish to the current epoch; when it is full, roll once and retry.
472note Returns the version, or the refusal of the publish or of the roll.
473fn pool_publish c long topics ulong src view uchar 4096 n ulong to long
474h = pool_current c
475if lt h 0
476ret h
477end
478v = node_publish h topics src n
479if ne v neg long 2
480ret v
481end
482r = pool_roll c
483if lt r 0
484ret r
485end
486h = pool_current c
487if lt h 0
488ret h
489end
490ret node_publish h topics src n
491end
492
493fn pool_stop c long to long
494if not pool_valid c
495ret neg long 5
496end
497if not pool_mine c
498ret neg long 6
499end
500ret mapset c 24 8 1
501end
502
503fn pool_stopped c long to bool
504ret ne mapget c 24 8 0
505end
506
507note Creator: record worker w's PID and state for observers.
508fn pool_setw c long w ulong pid ulong st ulong to long
509if not pool_mine c
510ret neg long 6
511end
512if ge w mapget c 48 8
513ret neg long 7
514end
515r = mapset c add 768 mul w 8 8 pid
516ret mapset c add 1280 mul w 8 8 st
517end
518
519note Creator: clear hold w. Only after worker w has been reaped.
520fn pool_clear c long w ulong to long
521if not pool_mine c
522ret neg long 6
523end
524if ge w mapget c 48 8
525ret neg long 7
526end
527ret mapset c add 256 mul w 8 8 0
528end
529
530note Drop every mapping of the pool in this process. Other processes keep
531note their own inherited mappings until they drop them or exit.
532fn pool_free c long to long
533ret pool_unwind c mapget c 40 8
534end
535note Omega Node worker supervision. Concatenate after transport.om and pool.om.
536note The creator forks trusted workers from its own binary: sup_spawn returns 0
537note in the child, which runs its worker function and exits with its result.
538note Death is seen without polling PIDs. Worker w alone holds the write end of
539note its close-on-exec life pipe, so its exit hangs up the creator's read end.
540note Every worker holds the read end of the creator's life pipe, whose only
541note writer is the creator, so creator death hangs up every worker.
542note Per worker: wake, stop and ack eventfds, kept across respawns.
543note Workers must not exec: exec closes the life pipe and reads as death.
544global swpid long 64
545global swwake int 64
546global swstop int 64
547global swack int 64
548global swlife int 64
549global swst ulong 64
550global swpw ulong 64
551global swpar int 2
552global swme ulong 1
553global swws uchar 4
554global swpf uchar 8
555global swpoll uchar 1024
556
557fn sup_fd off ulong to int
558v = ulong get swpf off
559v = or v shl ulong get swpf add off 1 8
560v = or v shl ulong get swpf add off 2 16
561v = or v shl ulong get swpf add off 3 24
562ret int v
563end
564
565note Poll record j at swpoll offset off; a negative fd is stored as itself
566note (bit pattern) so the kernel ignores that record.
567fn sup_gpfd off ulong fd int to void
568u = bitcast uint fd
569for i ulong 4
570put swpoll add off i uchar and shr u uint mul i 8 255
571end
572put swpoll add off 4 1
573put swpoll add off 5 0
574put swpoll add off 6 0
575put swpoll add off 7 0
576end
577
578fn sup_lpfd p edit uchar 24 off ulong fd int to void
579for i ulong 4
580put p add off i uchar and shr uint fd uint mul i 8 255
581end
582put p add off 4 1
583end
584
585note Read and reset an eventfd counter: the number of hints since the last
586note take, 0 when none is pending, or a negative errno.
587fn sup_take fd int to long
588buf = new uchar 8 0
589for i ulong 64
590r = read fd buf 0 8
591if eq r 8
592v = ulong 0
593for j ulong 8
594v = or v shl ulong get buf j mul j 8
595end
596ret long and v 9223372036854775807
597end
598if eq r neg long 11
599ret 0
600end
601if ne r neg long 4
602if lt r 0
603ret r
604end
605ret neg long 5
606end
607end
608ret neg long 4
609end
610
611fn sup_closeall to void
612for i ulong 64
613if ge get swwake i 0
614r = fclose get swwake i
615end
616if ge get swstop i 0
617r = fclose get swstop i
618end
619if ge get swack i 0
620r = fclose get swack i
621end
622if ge get swlife i 0
623r = fclose get swlife i
624end
625put swwake i neg int 1
626put swstop i neg int 1
627put swack i neg int 1
628put swlife i neg int 1
629end
630for i ulong 2
631if ge get swpar i 0
632r = fclose get swpar i
633end
634put swpar i neg int 1
635end
636end
637
638note Creator: create the creator life pipe and three eventfds per worker slot.
639note Call once after pool_new and before sup_spawn. 0 or a negative errno;
640note a failure closes everything this call opened.
641fn sup_init c long to long
642if not pool_mine c
643ret neg long 6
644end
645for i ulong 64
646put swpid i 0
647put swst i 0
648put swwake i neg int 1
649put swstop i neg int 1
650put swack i neg int 1
651put swlife i neg int 1
652end
653put swme 0 0
654put swpar 0 neg int 1
655put swpar 1 neg int 1
656r = pipefds swpf 0 8 524288
657if lt r 0
658ret r
659end
660put swpar 0 sup_fd 0
661put swpar 1 sup_fd 4
662n = mapget c 48 8
663for i ulong n bound 64
664a = eventfd uint 0
665if lt a 0
666sup_closeall
667ret a
668end
669put swwake i int a
670a = eventfd uint 0
671if lt a 0
672sup_closeall
673ret a
674end
675put swstop i int a
676a = eventfd uint 0
677if lt a 0
678sup_closeall
679ret a
680end
681put swack i int a
682end
683ret 0
684end
685
686note Creator: fork worker w. Returns 0 in the child, the child PID in the
687note creator, -7 bad slot, -16 slot still live, or a negative errno. The
688note child keeps only its own life write end; the creator keeps the read end.
689fn sup_spawn c long w ulong to long
690if not pool_mine c
691ret neg long 6
692end
693if ge w mapget c 48 8
694ret neg long 7
695end
696if ne get swpid w 0
697ret neg long 16
698end
699r = pipefds swpf 0 8 524288
700if lt r 0
701ret r
702end
703rd = sup_fd 0
704wr = sup_fd 4
705pid = fork
706if eq pid 0
707r = fclose get swpar 1
708put swpar 1 neg int 1
709r = fclose rd
710put swlife w wr
711put swme 0 add w 1
712ret 0
713end
714r = fclose wr
715if lt pid 0
716r = fclose rd
717ret pid
718end
719put swpid w pid
720put swlife w rd
721r = pool_setw c w ulong pid 1
722ret pid
723end
724
725note Worker: 3 creator gone, 2 stop, 1 wake hint, 0 timeout, negative errno.
726note Creator loss outranks stop, which outranks work. A set stop flag makes
727note the poll nonblocking. Hints are drained; rescan shared state after 1.
728fn sup_wwait c long w ulong interval long to long
729p = new uchar 24 0
730if ge w 64
731ret neg long 7
732end
733iv = interval
734if pool_stopped c
735iv = 0
736end
737sup_lpfd p 0 get swwake w
738sup_lpfd p 8 get swstop w
739sup_lpfd p 16 get swpar 0
740r = pollfds p 0 24 iv
741if lt r 0
742ret r
743end
744if ne get p 22 0
745ret 3
746end
747if pool_stopped c
748ret 2
749end
750if ne and get p 14 56 0
751ret neg long 5
752end
753if ne and get p 14 1 0
754r = node_drain get swstop w
755ret 2
756end
757if ne and get p 6 56 0
758ret neg long 5
759end
760if ne and get p 6 1 0
761r = node_drain get swwake w
762if lt r 0
763ret r
764end
765ret 1
766end
767ret 0
768end
769
770note Worker or creator: post a hint on worker w's ack eventfd.
771fn sup_ack w ulong to long
772if ge w 64
773ret neg long 7
774end
775ret node_notify get swack w
776end
777
778note Creator: wake worker w with a work hint.
779fn sup_wake w ulong to long
780if ge w 64
781ret neg long 7
782end
783if le get swpid w 0
784ret neg long 3
785end
786ret node_notify get swwake w
787end
788
789fn sup_live c long to ulong
790n = mapget c 48 8
791k = ulong 0
792for w ulong n bound 64
793if gt get swpid w 0
794k = add k 1
795end
796end
797ret k
798end
799
800note Creator: reap worker w, then release what it held. A worker that has not
801note exited within about one second gets SIGKILL first. Only after the exact
802note PID is reaped are its hold, PID and life pipe released. Returns the raw
803note wait status, -3 no live worker, or the waitpid errno (nothing released).
804fn sup_reap c long w ulong to long
805if ge w 64
806ret neg long 7
807end
808pid = get swpid w
809if le pid 0
810ret neg long 3
811end
812done = false
813for t ulong 100
814r = waitpid int pid swws 0 4 1
815if eq r pid
816done = true
817break
818end
819if ne r 0
820ret r
821end
822r = sleepns 10000000
823end
824if not done
825r = killpid int pid 9
826r = waitpid int pid swws 0 4 0
827if ne r pid
828ret r
829end
830end
831st = ulong get swws 0
832st = or st shl ulong get swws 1 8
833put swst w st
834r = fclose get swlife w
835put swlife w neg int 1
836put swpid w 0
837r = pool_clear c w
838r = pool_setw c w 0 2
839ret long st
840end
841
842note Creator: wait up to interval ns for deaths and, when acks is true, acks.
843note Ack counts are left pending for sup_take. Every worker whose life pipe
844note hung up is reaped. Returns the number reaped, or a negative errno.
845fn sup_pollx c long interval long acks bool to long
846n = mapget c 48 8
847m = ulong 0
848for w ulong n bound 64
849if gt get swpid w 0
850o = mul m 16
851if acks
852sup_gpfd o get swack w
853else
854sup_gpfd o neg int 1
855end
856sup_gpfd add o 8 get swlife w
857put swpw m w
858m = add m 1
859end
860end
861if eq m 0
862ret 0
863end
864r = pollfds swpoll 0 mul m 16 interval
865if lt r 0
866ret r
867end
868dead = long 0
869for j ulong m bound 64
870o = add mul j 16 14
871if ne get swpoll o 0
872r = sup_reap c get swpw j
873if lt r 0
874ret r
875end
876dead = add dead 1
877end
878end
879ret dead
880end
881
882note Creator: wait up to interval ns for acks and deaths (see sup_pollx).
883fn sup_poll c long interval long to long
884ret sup_pollx c interval true
885end
886
887note Creator: stop admission, post every live worker's stop eventfd, then reap
888note until all have exited or interval ns pass; survivors get SIGKILL and are
889note reaped. Returns how many had to be killed, or a refusal.
890fn sup_stop c long interval long to long
891r = pool_stop c
892if lt r 0
893ret r
894end
895n = mapget c 48 8
896for w ulong n bound 64
897if gt get swpid w 0
898r = node_notify get swstop w
899end
900end
901dl = add monons interval
902for t ulong 100000
903if eq sup_live c 0
904ret 0
905end
906now = monons
907if ge now dl
908break
909end
910r = sup_pollx c sub dl now false
911if lt r 0
912if ne r neg long 4
913break
914end
915end
916end
917killed = long 0
918for w ulong n bound 64
919if gt get swpid w 0
920r = killpid int get swpid w 9
921r = sup_reap c w
922killed = add killed 1
923end
924end
925ret killed
926end
927note Omega Node cooperative scheduling (DRA-287). Concatenate after
928note transport.om, pool.om and super.om, before one program with fn main.
929note One creator admits, assigns, collects and reviews jobs. Workers never
930note write each other's state, and no step waits for every worker.
931note Scheduling page: one 128-byte cell per worker w at 128*w.
932note Creator writes 0 assigned seq, 8 job id, 16 input epoch, 24 input
933note version, 32 interest topics, 40 wake stamp (monons at the last post).
934note Worker writes 64 done seq, 72 outcome, 80 wakes, 88 last wake latency
935note ns, 96 largest wake latency ns.
936note Outbox: worker w's result bytes at 4096*w of a second mapping, written
937note before its done seq. Each word has one writer; the creator writes a
938note worker word only after it has reaped that worker.
939note Job states: 0 free, 1 waiting for deps, 2 ready, 3 running, 4 in review,
940note 6 UNKNOWN (its worker died mid-job and the job is not safe to rerun).
941note
942note Resources and selection policy (P-DRA-14, DRA-395). A request is one
943note ulong of four 16-bit counts, kind k at bits 16k..16k+15: kind 0 CPU
944note slots, 1 memory MiB, 2 inference slots, 3 caller-defined. scap holds
945note the configured capacity of each kind, suse the sum of the needs of the
946note jobs that hold resources (sjheld 1). A job takes its whole need when it
947note is assigned and gives it back when its worker reports done or is reaped,
948note never in part. Every job also needs one idle live worker.
949note sjarr: admission order (waiting age; kept across reruns). sjrdy: order
950note in which the job last became ready. sjbyp: times it was bypassed.
951note Decisions read only these logical counters, never the clock.
952note Policy 1, fair fitting (DRA-396): a pick first probes the reserved job;
953note otherwise it scans a window of win slots from a persistent cursor and
954note takes the oldest admitted ready job that fits. The cursor moves on by
955note win after every window scan, so every slot is examined within
956note ceil(64/win) window scans. A ready job older than a job assigned in
957note the same event was bypassed; once the oldest such job reaches the
958note bypass budget it is reserved: it is offered first, and no other job may
959note use, of any kind, the capacity it still lacks (others may use only
960note free capacity beyond its need). Neither the free capacity it can reach
961note nor its age ever shrinks, so it runs once running work releases enough
962note (liveness assumes: every running job ends, by completion or by its
963note lease, at least one worker stays live, results in review are reviewed,
964note and dispatch is not paused). Requests over capacity are refused at
965note admission.
966note Admission: room is the smaller of the admission headroom and the free
967note table slots. A refused caller holds a ticket; while tickets are held
968note only the first holder may enter, so holders enter in ticket order
969note before anyone new. A ticket not asked about for more than ttl dispatch
970note events lapses (asked at event e, it survives while e + ttl is at least
971note the current event count). An absent head blocks later holders until
972note its ticket lapses; a paused dispatch counts no events, so the block
973note lasts until dispatch resumes.
974note Leases: a running job with a lease is reported once by sched_overdue
975note after its lease passes; the authority then cancels or kills it, which
976note releases its resources.
977note
978note Policy 2, goal-aware fair fitting (DRA-397): policy 1 with a different
979note order among the examined jobs that fit: larger unblock value first (the
980note waiting jobs, to depth 2, that the job's declared topics would make
981note ready), then smaller declared estimate, then older admission. The
982note reservation, the hold-back, feasibility and the bypass budget are
983note those of policy 1 and come first, so ranking cannot starve old work.
984note Values are rescored only when the graph version moved (a job became
985note ready, a waiting job was admitted, a job was cancelled, a declaration
986note changed), once per pick however many changes came before it.
987note Completions, releases and lease expiry replan (every step dispatches)
988note without rescoring. A proposal names a job by id and the graph version
989note it was computed at, and is rejected when that version is no longer
990note current; the version carries the scheduler's incarnation, so a
991note proposal made for another scheduler is never current here.
992const SJCAP ulong 64
993const SPVER ulong 3
994global scmap long 2
995global sclim ulong 2
996global sjst ulong 64
997global sjdep ulong 64
998global sjid ulong 64
999global sjw ulong 64
1000global sjatt ulong 64
1001global sjfl ulong 64
1002global sjout ulong 64
1003global sjneed ulong 64
1004global sjheld ulong 64
1005global sjarr ulong 64
1006global sjrdy ulong 64
1007global sjbyp ulong 64
1008global sjlse ulong 64
1009global sjdue ulong 64
1010global sttk ulong 64
1011global stts ulong 64
1012global scbusy ulong 64
1013global scseq ulong 64
1014global swcur ulong 2
1015global scpause ulong 1
1016global scap ulong 4
1017global suse ulong 4
1018note Policy words: 0 policy (0 FIFO head-of-line, 1 fair fitting), 1
1019note candidate window in slots, 2 dispatch budget per event, 3 bypass
1020note budget, 4 cursor, 5 reserved job slot + 1 (0 none), 6 tickets held,
1021note 7 ticket lifetime in dispatch events.
1022global scpol ulong 8
1023note Counters (sched_stat): 0 admissions, 1 ready stamps, 2 dispatch events,
1024note 3 candidate slot reads, 4 jobs assigned, 5 bypasses, 6 reservations
1025note made, 7 impossible requests refused, 8 head-of-line stops, 9 reserved
1026note jobs assigned, 10 tickets issued, 11 tickets lapsed, 12 leases overdue,
1027note 13 maintenance slot reads, 14 window scans, 15 dispatch events refused
1028note because the replay ring was full (DRA-398).
1029global scst ulong 16
1030note Goal-aware ranking (policy 2): sjpro the topics a job declares its
1031note completion publishes, sjest its declared work estimate in ms, sjunc
1032note that estimate's uncertainty in ms, sjval its unblock value in jobs as
1033note last scored. scgv: 0 graph version, 1 version last scored, 2 proposed
1034note job slot + 1 (0 none), 3 version the proposal named, 4 proposal state
1035note (0 no incarnation yet: proposals refused; 1 accepting; 2 the version
1036note is exhausted: proposals refused for the rest of this scheduler). The
1037note graph version is the scheduler's incarnation (sched_incarnate, once)
1038note times 2^40 plus the bumps since, never more than 2^40 - 1 of them: the
1039note bump that would carry into the next incarnation's range exhausts the
1040note version instead, so schedulers of different incarnations never share a
1041note version. Within one scheduler every admission of a job, cancellation
1042note of a waiting or ready one and readiness bumps it, so a proposal whose
1043note version is current still names the job it was made for.
1044global sjpro ulong 64
1045global sjest ulong 64
1046global sjunc ulong 64
1047global sjval ulong 64
1048global scgv ulong 5
1049note Goal counters (sched_stat 32..39): 0 rescores, 1 jobs scored, 2 graph
1050note version bumps, 3 proposals accepted, 4 proposals stale, 5 proposals
1051note refused, 6 slots read by value traversal, 7 proposals used.
1052global scgst ulong 8
1053note Replay ring (DRA-398). While a journal is attached (sfj 0 is 1), each
1054note dispatch event that assigned a job or changed the reservation leaves a
1055note record of 6 words in sfr: event count, assigned slot bitmap, bypassed
1056note slot bitmap (the slots whose bypass count went up), cursor, reserved
1057note slot + 1, and 0. A publication that makes waiting jobs ready leaves a
1058note readiness record: the current event count, no assigned or bypassed
1059note slot, cursor, reserved slot + 1, and the bitmap of the slots it made
1060note ready. sfj 1 counts the records waiting; sfj 2 and 3 are the
1061note reservation at the start of the current event and the slots it has
1062note assigned so far. The journal drains them before it appends any other
1063note record, so a transition is never durable before the dispatch
1064note decisions and readiness that came before it. With 64 waiting,
1065note dispatch assigns nothing and publication is refused (counter 15)
1066note until they are drained.
1067global sfr ulong 384
1068global sfj ulong 4
1069
1070fn sc_cell w ulong off ulong to ulong
1071ret mapget get scmap 0 add mul w 128 off 8
1072end
1073
1074fn sc_set w ulong off ulong v ulong to void
1075r = mapset get scmap 0 add mul w 128 off 8 v
1076end
1077
1078note Creator, before any fork: map the scheduling page and the outboxes and
1079note set the limits on admitted (a) and in-review (rl) jobs, each 1..64.
1080note Returns 0, -6 not creator, -7 bad limit, or a mapping errno.
1081fn sched_new c long a ulong rl ulong to long
1082if not pool_mine c
1083ret neg long 6
1084end
1085if or eq a 0 gt a SJCAP
1086ret neg long 7
1087end
1088if or eq rl 0 gt rl SJCAP
1089ret neg long 7
1090end
1091s = mapnew neg int 1 0 8192 3 33
1092if le s 0
1093ret s
1094end
1095o = mapnew neg int 1 0 262144 3 33
1096if le o 0
1097r = mapdrop s
1098ret o
1099end
1100put scmap 0 s
1101put scmap 1 o
1102put sclim 0 a
1103put sclim 1 rl
1104for j ulong 64
1105put sjst j 0
1106put sjheld j 0
1107put sjlse j 0
1108put sjdue j 0
1109put sjpro j 0
1110put sjest j 0
1111put sjunc j 0
1112put sjval j 0
1113put scbusy j 0
1114put scseq j 0
1115end
1116for k ulong 4
1117put scap k 65535
1118put suse k 0
1119end
1120put sfj 1 0
1121for i ulong 16
1122put scst i 0
1123end
1124for i ulong 8
1125put scgst i 0
1126end
1127for i ulong 5
1128put scgv i 0
1129end
1130put scpol 0 1
1131put scpol 1 64
1132put scpol 2 64
1133put scpol 3 4
1134put scpol 4 0
1135put scpol 5 0
1136put scpol 6 0
1137put scpol 7 1000
1138put scpause 0 0
1139ret 0
1140end
1141
1142note Count of kind k (0..3) in packed request req.
1143fn sp_need req ulong k ulong to ulong
1144ret and shr req mul k 16 65535
1145end
1146
1147note Free capacity of kind k. sched_cap never sets a capacity below the
1148note use, so this cannot underflow.
1149fn sp_free k ulong to ulong
1150ret sub get scap k get suse k
1151end
1152
1153note Does req fit in the free capacity once the reserved request res has
1154note what it still lacks? Of each kind, res keeps min(free, its need); res 0
1155note is no reservation. This keeps the reserved job's attainable capacity
1156note from ever shrinking (the drain).
1157fn sp_fits req ulong res ulong to bool
1158for k ulong 4
1159f = sp_free k
1160r = sp_need res k
1161a = ulong 0
1162if gt f r
1163a = sub f r
1164end
1165if gt sp_need req k a
1166ret false
1167end
1168end
1169ret true
1170end
1171
1172note Could req ever run, with the configured capacity all free?
1173fn sp_feas req ulong to bool
1174for k ulong 4
1175if gt sp_need req k get scap k
1176ret false
1177end
1178end
1179ret true
1180end
1181
1182note Job j takes its whole need.
1183fn sp_take j ulong to void
1184for k ulong 4
1185put suse k add get suse k sp_need get sjneed j k
1186end
1187put sjheld j 1
1188end
1189
1190note Job j gives back its need, if it holds it.
1191fn sp_give j ulong to void
1192if eq get sjheld j 0
1193ret
1194end
1195for k ulong 4
1196put suse k sub get suse k sp_need get sjneed j k
1197end
1198put sjheld j 0
1199end
1200
1201note Job j becomes ready, stamped with the next ready order.
1202fn sp_ready j ulong to void
1203put sjst j 2
1204put sjrdy j get scst 1
1205put scst 1 add get scst 1 1
1206sp_bump
1207end
1208
1209note Creator: counter i of scst, capacity (i 16..19) or use (i 20..23) of a
1210note kind, policy word (i 24..31), goal counter (i 32..39), graph version
1211note (i 40), proposal state (i 41: 0 no incarnation, 1 accepting, 2
1212note exhausted).
1213fn sched_stat i ulong to ulong
1214if lt i 16
1215ret get scst i
1216end
1217if lt i 20
1218ret get scap sub i 16
1219end
1220if lt i 24
1221ret get suse sub i 20
1222end
1223if lt i 32
1224ret get scpol sub i 24
1225end
1226if lt i 40
1227ret get scgst sub i 32
1228end
1229if eq i 40
1230ret get scgv 0
1231end
1232if eq i 41
1233ret get scgv 4
1234end
1235ret 0
1236end
1237
1238note Creator: would sched_cap caps be accepted? Not when the new capacity of
1239note a kind is below its use by running jobs, or below the need of any one
1240note admitted job.
1241fn sched_capok caps ulong to bool
1242for k ulong 4
1243if lt sp_need caps k get suse k
1244ret false
1245end
1246end
1247for j ulong 64
1248s = get sjst j
1249if and ge s 1 le s 3
1250for k ulong 4
1251if gt sp_need get sjneed j k sp_need caps k
1252ret false
1253end
1254end
1255end
1256end
1257ret true
1258end
1259
1260note Creator: set the capacity of every kind from caps (packed like a
1261note request). 0, or -8 when sched_capok refuses (nothing changes).
1262fn sched_cap caps ulong to long
1263if not sched_capok caps
1264ret neg long 8
1265end
1266for k ulong 4
1267put scap k sp_need caps k
1268end
1269ret 0
1270end
1271
1272note Creator: the configured capacities, packed like a request.
1273fn sched_caps to ulong
1274v = ulong 0
1275for k ulong 4
1276v = or v shl get scap k mul k 16
1277end
1278ret v
1279end
1280
1281note Creator: would sched_policy accept these words? Policy p 0..2, window
1282note win 1..64, dispatch budget db 1..64, bypass budget by 1..65535, ticket
1283note lifetime ttl 1..1000000.
1284fn sched_polok p ulong win ulong db ulong by ulong ttl ulong to bool
1285if gt p 2
1286ret false
1287end
1288if or eq win 0 gt win 64
1289ret false
1290end
1291if or eq db 0 gt db 64
1292ret false
1293end
1294if or eq by 0 gt by 65535
1295ret false
1296end
1297ret and gt ttl 0 le ttl 1000000
1298end
1299
1300note Creator: policy p (0 FIFO head-of-line, 1 fair fitting, 2 goal-aware
1301note fair fitting), candidate window win slots, dispatch budget db jobs per
1302note event, bypass budget by, ticket lifetime ttl dispatch events, in the
1303note ranges of sched_polok. The cursor and any reservation are kept. 0 or
1304note -7.
1305fn sched_policy p ulong win ulong db ulong by ulong ttl ulong to long
1306if not sched_polok p win db by ttl
1307ret neg long 7
1308end
1309put scpol 0 p
1310put scpol 1 win
1311put scpol 2 db
1312put scpol 3 by
1313put scpol 7 ttl
1314ret 0
1315end
1316
1317note Creator: drop this process's scheduling mappings.
1318fn sched_free to long
1319r = mapdrop get scmap 1
1320if lt r 0
1321ret r
1322end
1323ret mapdrop get scmap 0
1324end
1325
1326note Jobs whose state is in lo..hi.
1327fn sched_count lo ulong hi ulong to ulong
1328n = ulong 0
1329for j ulong 64
1330s = get sjst j
1331if and ge s lo le s hi
1332n = add n 1
1333end
1334end
1335ret n
1336end
1337
1338note Position of id's admission ticket, or 64.
1339fn sp_tkpos id ulong to ulong
1340for t ulong get scpol 6 bound 64
1341if eq get sttk t id
1342ret t
1343end
1344end
1345ret 64
1346end
1347
1348note Compact the tickets in order, dropping ticket d (64: none) and every
1349note ticket not asked about for the ticket lifetime.
1350fn sp_tkpack d ulong to void
1351k = ulong 0
1352for t ulong get scpol 6 bound 64
1353if ne t d
1354if lt add get stts t get scpol 7 get scst 2
1355put scst 11 add get scst 11 1
1356else
1357put sttk k get sttk t
1358put stts k get stts t
1359k = add k 1
1360end
1361end
1362end
1363put scpol 6 k
1364end
1365
1366note Refresh ticket t, or give id a ticket at the end when it has none and
1367note the line has room (a caller refused with the line full holds none).
1368fn sp_tkhold id ulong t ulong to void
1369if lt t 64
1370put stts t get scst 2
1371ret
1372end
1373n = get scpol 6
1374if lt n 64
1375put sttk n id
1376put stts n get scst 2
1377put scpol 6 add n 1
1378put scst 10 add get scst 10 1
1379end
1380end
1381
1382note Creator: may id be admitted now? Room is the smaller of the admission
1383note headroom and the free table slots (a job in review or UNKNOWN holds
1384note its slot). While tickets are held only the first holder may enter;
1385note with none, anyone may while there is room. A refused caller gets or
1386note keeps a ticket; every ask by a holder, refused or not, refreshes its
1387note ticket's last-asked event, and a caller with room and no ticket gets
1388note none. A true answer guarantees the slot for the next sched_admitr
1389note (single creator), so a caller may ask before journaling (as jn_admit
1390note does).
1391fn sched_room id ulong to bool
1392sp_tkpack 64
1393t = sp_tkpos id
1394a = ulong 0
1395fs = ulong 0
1396for j ulong 64
1397s = get sjst j
1398if eq s 0
1399fs = add fs 1
1400end
1401if and ge s 1 le s 3
1402a = add a 1
1403end
1404end
1405room = ulong 0
1406if lt a get sclim 0
1407room = sub get sclim 0 a
1408end
1409if lt fs room
1410room = fs
1411end
1412if gt room 0
1413if eq get scpol 6 0
1414ret true
1415end
1416if eq t 0
1417put stts 0 get scst 2
1418ret true
1419end
1420end
1421sp_tkhold id t
1422ret false
1423end
1424
1425note Creator: admit job id needing req (packed resources). deps 0 makes it
1426note ready at once; otherwise it waits for a publication whose topics meet
1427note deps. flags bit 0: safe to rerun after its worker dies. Returns the job
1428note slot; -8 when req exceeds the configured capacity of a kind (it could
1429note never run); -2 when sched_room refuses: at the admission limit, or
1430note ticket holders ahead; the caller keeps a ticket and asks again.
1431fn sched_admitr id ulong deps ulong flags ulong req ulong to long
1432ret sched_admits id deps flags req sched_slot
1433end
1434
1435note Creator: the lowest free table slot (the one sched_admitr would give
1436note the next job), or 64 when none is free.
1437fn sched_slot to ulong
1438for j ulong 64
1439if eq get sjst j 0
1440ret j
1441end
1442end
1443ret 64
1444end
1445
1446note Creator: could req ever run, with the configured capacity all free?
1447fn sched_feas req ulong to bool
1448ret sp_feas req
1449end
1450
1451note Creator: sched_admitr into table slot j, which must be free: the
1452note journal records the slot with the admission and recovery puts the job
1453note back into it (DRA-398). Refusals as sched_admitr; -2 also when slot j
1454note is not free.
1455fn sched_admits id ulong deps ulong flags ulong req ulong j ulong to long
1456if not sp_feas req
1457put scst 7 add get scst 7 1
1458ret neg long 8
1459end
1460if not sched_room id
1461ret neg long 2
1462end
1463if ge j 64
1464ret neg long 2
1465end
1466if ne get sjst j 0
1467ret neg long 2
1468end
1469t = sp_tkpos id
1470if lt t 64
1471sp_tkpack t
1472end
1473put sjid j id
1474put sjdep j deps
1475put sjfl j flags
1476put sjatt j 0
1477put sjout j 0
1478put sjw j 0
1479put sjneed j req
1480put sjheld j 0
1481put sjbyp j 0
1482put sjlse j 0
1483put sjdue j 0
1484put sjarr j get scst 0
1485put scst 0 add get scst 0 1
1486put sjpro j 0
1487put sjest j 0
1488put sjunc j 0
1489put sjval j 0
1490if eq deps 0
1491sp_ready j
1492else
1493put sjst j 1
1494sp_bump
1495end
1496ret long j
1497end
1498
1499note Creator: job j (waiting, ready or running) gets a lease of ns from its
1500note next assignment, or from now when it runs; 0 removes it. 0; -3 for a
1501note slot that is not waiting, ready or running; -7 for ns above 2^50 (about
1502note 13 days). Both refusals change nothing. The bound keeps every deadline
1503note (the monotonic clock, below 2^63, plus ns) representable: it never
1504note wraps into the past or onto 0, the no-deadline value.
1505fn sched_lease j ulong ns ulong to long
1506if ge j 64
1507ret neg long 3
1508end
1509s = get sjst j
1510if or lt s 1 gt s 3
1511ret neg long 3
1512end
1513if gt ns 1125899906842624
1514ret neg long 7
1515end
1516put sjlse j ns
1517if eq s 3
1518put sjdue j 0
1519if gt ns 0
1520put sjdue j add ulong monons ns
1521end
1522end
1523ret 0
1524end
1525
1526note Creator: a running job past its lease whose worker has not reported
1527note done, reported once (its deadline is cleared): its slot, or 64. The
1528note authority cancels or kills it; the release follows from the worker's
1529note report or reap.
1530fn sched_overdue to ulong
1531now = ulong monons
1532for j ulong 64
1533if eq get sjst j 3
1534d = get sjdue j
1535if gt d 0
1536if ge now d
1537w = get sjw j
1538if ne sc_cell w 64 get scseq w
1539put sjdue j 0
1540put scst 12 add get scst 12 1
1541ret j
1542end
1543end
1544end
1545end
1546end
1547ret 64
1548end
1549
1550note Creator: sched_admitr with no resource need beyond one worker.
1551fn sched_admit id ulong deps ulong flags ulong to long
1552ret sched_admitr id deps flags 0
1553end
1554
1555note Creator: worker w is woken by publications whose topics meet topics.
1556fn sched_want w ulong topics ulong to long
1557if ge w 64
1558ret neg long 7
1559end
1560sc_set w 32 topics
1561ret 0
1562end
1563
1564fn sc_wake w ulong to void
1565sc_set w 40 ulong monons
1566r = sup_wake w
1567end
1568
1569note Lowest idle live worker below n, or 64 when none. A worker is idle when
1570note the creator has collected its last assignment.
1571fn sp_idle n ulong to ulong
1572for w ulong n bound 64
1573if and gt get swpid w 0 eq get scbusy w 0
1574ret w
1575end
1576end
1577ret 64
1578end
1579
1580note Assign job j to idle worker w: it takes its need; the job id and the
1581note input epoch and version are written before the seq, then the wake.
1582fn sp_start c long j ulong w ulong to void
1583q = add get scseq w 1
1584put scseq w q
1585put scbusy w add j 1
1586put sjst j 3
1587put sjw j w
1588put sjatt j add get sjatt j 1
1589put sjbyp j 0
1590put sjdue j 0
1591if gt get sjlse j 0
1592put sjdue j add ulong monons get sjlse j
1593end
1594sp_take j
1595if eq get scpol 5 add j 1
1596put scpol 5 0
1597put scst 9 add get scst 9 1
1598end
1599sc_set w 8 get sjid j
1600sc_set w 16 pool_epoch c
1601sc_set w 24 node_count pool_current c
1602sc_set w 0 q
1603sc_wake w
1604put scst 4 add get scst 4 1
1605end
1606
1607note Policy 0, FIFO head-of-line: the stop rule of the reference pump
1608note (aien-sovereign-core-mv spark-harness scheduler/core.rs Core::pump,
1609note 598-602), not its queue: the head here is the ready job that became
1610note ready first (the pump batches newly eligible tasks in task-id order
1611note into a bounded queue). The head is chosen when it fits, and when it
1612note does not fit nothing is chosen, so a head that does
1613note not fit holds back every later job. Returns the slot or 64.
1614fn sp_fifo to ulong
1615h = ulong 64
1616for j ulong 64
1617put scst 3 add get scst 3 1
1618if eq get sjst j 2
1619if eq h 64
1620h = j
1621else
1622if lt get sjrdy j get sjrdy h
1623h = j
1624end
1625end
1626end
1627end
1628if eq h 64
1629ret 64
1630end
1631if sp_fits get sjneed h 0
1632ret h
1633end
1634put scst 8 add get scst 8 1
1635ret 64
1636end
1637
1638note Policy 1, fair fitting: the reserved job first when it fits; else the
1639note oldest admitted ready job, among win slots from the cursor, that fits
1640note without the capacity the reserved job still lacks; the cursor then
1641note moves on by win. Returns the slot or 64. Every slot read counts
1642note (counter 3: the reserved probe and the window), at most win + 1 per
1643note pick, win + 2 under policy 2 (sp_proposal's probe counts too);
1644note counter 14 counts window scans.
1645fn sp_fair to ulong
1646rq = ulong 0
1647r = get scpol 5
1648if gt r 0
1649rj = sub r 1
1650put scst 3 add get scst 3 1
1651if eq get sjst rj 2
1652if sp_fits get sjneed rj 0
1653ret rj
1654end
1655rq = get sjneed rj
1656else
1657put scpol 5 0
1658end
1659end
1660goal = eq get scpol 0 2
1661if goal
1662sp_rescore
1663pj = sp_proposal rq
1664if lt pj 64
1665ret pj
1666end
1667end
1668win = get scpol 1
1669cur = get scpol 4
1670b = ulong 64
1671put scst 14 add get scst 14 1
1672for i ulong win bound 64
1673put scst 3 add get scst 3 1
1674j = rem add cur i 64
1675if eq get sjst j 2
1676if sp_fits get sjneed j rq
1677if eq b 64
1678b = j
1679else
1680if sp_better goal j b
1681b = j
1682end
1683end
1684end
1685end
1686end
1687put scpol 4 rem add cur win 64
1688ret b
1689end
1690
1691note Ranking key, both of ready jobs a and b: is a better? Policy 1: older
1692note admission. Policy 2: larger unblock value, then smaller declared
1693note estimate, then older admission (admission orders are unique, so there
1694note is never a tie).
1695fn sp_better goal bool a ulong b ulong to bool
1696if goal
1697va = get sjval a
1698vb = get sjval b
1699if ne va vb
1700ret gt va vb
1701end
1702ea = get sjest a
1703eb = get sjest b
1704if ne ea eb
1705ret lt ea eb
1706end
1707end
1708ret lt get sjarr a get sjarr b
1709end
1710
1711note A committed change that can alter an unblock value: a job becomes
1712note ready, a waiting job is admitted, a waiting or ready job is cancelled,
1713note or a declaration changes. Bumps the graph version, which makes any
1714note proposal stale (rejected when next used). Nothing is rescored here:
1715note the next policy-2 pick rescores once, however many bumps came before
1716note it (coalesced). At 2^40 - 1 bumps the version stays and is exhausted
1717note (scgv 4 = 2): from then on proposals are refused and every pick
1718note rescores.
1719fn sp_bump to void
1720put scgst 2 add get scgst 2 1
1721if eq and get scgv 0 1099511627775 1099511627775
1722put scgv 4 2
1723ret
1724end
1725put scgv 0 add get scgv 0 1
1726end
1727
1728note Unblock value of ready job j, in jobs: the waiting jobs whose deps meet
1729note the topics j declares it unblocks (depth 1), plus the waiting jobs whose
1730note deps meet the topics those declare (depth 2), each counted once. Reads
1731note at most 128 slots.
1732fn sp_value j ulong to ulong
1733pro = get sjpro j
1734if eq pro 0
1735ret 0
1736end
1737n = ulong 0
1738m = ulong 0
1739p2 = ulong 0
1740for k ulong 64
1741if eq get sjst k 1
1742if ne and get sjdep k pro 0
1743m = or m shl ulong 1 k
1744p2 = or p2 get sjpro k
1745n = add n 1
1746end
1747end
1748end
1749put scgst 6 add get scgst 6 64
1750if eq p2 0
1751ret n
1752end
1753for k ulong 64
1754if eq get sjst k 1
1755if eq and shr m k 1 0
1756if ne and get sjdep k p2 0
1757n = add n 1
1758end
1759end
1760end
1761end
1762put scgst 6 add get scgst 6 64
1763ret n
1764end
1765
1766note Recompute the unblock value of every ready job when the graph version
1767note moved since the last scoring, or always once it is exhausted;
1768note otherwise nothing.
1769fn sp_rescore to void
1770v = get scgv 0
1771if and eq get scgv 1 v ne get scgv 4 2
1772ret
1773end
1774for j ulong 64
1775if eq get sjst j 2
1776put sjval j sp_value j
1777put scgst 1 add get scgst 1 1
1778end
1779end
1780put scgv 1 v
1781put scgst 0 add get scgst 0 1
1782put scgst 6 add get scgst 6 64
1783end
1784
1785note The proposed job, when the proposal is for the current graph version
1786note (and that version is not exhausted) and the job is still ready and fits
1787note beside the reservation (rq); it is used once. Otherwise the proposal
1788note is dropped as stale: 64.
1789fn sp_proposal rq ulong to ulong
1790p = get scgv 2
1791if eq p 0
1792ret 64
1793end
1794put scgv 2 0
1795put scst 3 add get scst 3 1
1796j = sub p 1
1797if and eq get scgv 3 get scgv 0 eq get scgv 4 1
1798if eq get sjst j 2
1799if sp_fits get sjneed j rq
1800put scgst 7 add get scgst 7 1
1801ret j
1802end
1803end
1804end
1805put scgst 4 add get scgst 4 1
1806ret 64
1807end
1808
1809note Creator: declare what job j (waiting or ready) is expected to unblock
1810note and cost: pro, the topics its completion will publish; est, the work
1811note estimate in ms (declared, or derived by the caller from measurements);
1812note unc, its uncertainty in ms (recorded, not used to rank). 0, or -3.
1813fn sched_goal j ulong pro ulong est ulong unc ulong to long
1814if ge j 64
1815ret neg long 3
1816end
1817s = get sjst j
1818if or eq s 0 gt s 2
1819ret neg long 3
1820end
1821put sjpro j pro
1822put sjest j est
1823put sjunc j unc
1824sp_bump
1825ret 0
1826end
1827
1828note Creator: the graph version that proposals must name.
1829fn sched_version to ulong
1830ret get scgv 0
1831end
1832
1833note Creator, after sched_new: incarnation n (1..2^24 - 1), distinct
1834note for every scheduler that may receive proposals meant for another (the
1835note journal fence, DRA-398). The graph version becomes n * 2^40, which no
1836note scheduler of another incarnation reaches, any proposal is dropped and
1837note proposals are accepted from now on. The last scoring stays below n *
1838note 2^40, so the next ranking pass rescores whatever was admitted or
1839note declared before, whenever the incarnation comes. Once per
1840note scheduler: 0, or -7 (n out of range, or already set or exhausted).
1841fn sched_incarnate n ulong to long
1842if or eq n 0 ge n 16777216
1843ret neg long 7
1844end
1845if ne get scgv 4 0
1846ret neg long 7
1847end
1848put scgv 0 shl n 40
1849put scgv 2 0
1850put scgv 4 1
1851ret 0
1852end
1853
1854note Creator, policy 2: propose the ready job whose id is id for the next
1855note pick, computed at graph version v (an outside planner, or an
1856note operator). The proposal names the job, not its slot. Reservations and
1857note feasibility still come first: it is checked again when used. 0; -6 no
1858note incarnation set or the version exhausted; -9 stale (v is not the
1859note current version); -3 no ready job, or more than one, has that id; -8
1860note it does not fit beside the reservation; -7 not policy 2.
1861fn sched_propose id ulong v ulong to long
1862if ne get scpol 0 2
1863ret neg long 7
1864end
1865if ne get scgv 4 1
1866put scgst 5 add get scgst 5 1
1867ret neg long 6
1868end
1869if ne v get scgv 0
1870put scgst 4 add get scgst 4 1
1871ret neg long 9
1872end
1873j = ulong 64
1874n = ulong 0
1875for k ulong 64
1876if and eq get sjst k 2 eq get sjid k id
1877j = k
1878n = add n 1
1879end
1880end
1881if ne n 1
1882put scgst 5 add get scgst 5 1
1883ret neg long 3
1884end
1885rq = ulong 0
1886r = get scpol 5
1887if gt r 0
1888rq = get sjneed sub r 1
1889end
1890if not sp_fits get sjneed j rq
1891put scgst 5 add get scgst 5 1
1892ret neg long 8
1893end
1894put scgv 2 add j 1
1895put scgv 3 v
1896put scgst 3 add get scgst 3 1
1897ret 0
1898end
1899
1900note After a fair dispatch event in which ya - 1 was the youngest admission
1901note assigned (ya 0: none): every ready job admitted before it was bypassed
1902note once; with no reservation, the oldest job at the bypass budget is
1903note reserved. One pass over the table (64 maintenance reads, counter 13).
1904note Returns the bitmap of the slots bypassed.
1905fn sp_after ya ulong to ulong
1906o = ulong 64
1907bm = ulong 0
1908nores = eq get scpol 5 0
1909for j ulong 64
1910if eq get sjst j 2
1911if gt ya 0
1912if lt add get sjarr j 1 ya
1913put sjbyp j add get sjbyp j 1
1914put scst 5 add get scst 5 1
1915bm = or bm shl 1 j
1916end
1917end
1918if nores
1919if ge get sjbyp j get scpol 3
1920if eq o 64
1921o = j
1922else
1923if lt get sjarr j get sjarr o
1924o = j
1925end
1926end
1927end
1928end
1929end
1930end
1931put scst 13 add get scst 13 64
1932if lt o 64
1933put scpol 5 add o 1
1934put scst 6 add get scst 6 1
1935end
1936ret bm
1937end
1938
1939note Creator: assign ready jobs to idle live workers under the policy, at
1940note most the dispatch budget per call. Returns the number assigned. With
1941note a journal attached and the replay ring full, nothing is assigned
1942note (counter 15) until the journal drains it.
1943fn sched_dispatch c long to ulong
1944if ne get scpause 0 0
1945ret 0
1946end
1947if and ne get sfj 0 0 ge get sfj 1 64
1948put scst 15 add get scst 15 1
1949ret 0
1950end
1951n = mapget c 48 8
1952k = ulong 0
1953ya = ulong 0
1954put sfj 2 get scpol 5
1955put sfj 3 0
1956fair = ge get scpol 0 1
1957put scst 2 add get scst 2 1
1958for i ulong get scpol 2 bound 64
1959w = sp_idle n
1960if ge w 64
1961break
1962end
1963j = ulong 64
1964if fair
1965j = sp_fair
1966else
1967j = sp_fifo
1968end
1969if ge j 64
1970break
1971end
1972if gt add get sjarr j 1 ya
1973ya = add get sjarr j 1
1974end
1975sp_fmark j
1976sp_start c j w
1977k = add k 1
1978end
1979bm = ulong 0
1980if fair
1981bm = sp_after ya
1982end
1983sp_frend bm
1984ret k
1985end
1986
1987note End of a dispatch event with a journal attached: one ring record when
1988note it assigned a job or moved the reservation.
1989fn sp_frend bm ulong to void
1990if eq get sfj 0 0
1991ret
1992end
1993if or ne get sfj 3 0 ne get scpol 5 get sfj 2
1994sp_frpush get sfj 3 bm 0
1995end
1996end
1997
1998note The current dispatch event assigned slot j (sfj 3).
1999fn sp_fmark j ulong to void
2000put sfj 3 or get sfj 3 shl 1 j
2001end
2002
2003note Append one replay record (sfr): event, assigned and bypassed slot
2004note bitmaps, cursor, reserved slot + 1, slots made ready. The callers
2005note leave room.
2006fn sp_frpush am ulong bm ulong rd ulong to void
2007b = mul get sfj 1 6
2008put sfr b get scst 2
2009put sfr add b 1 am
2010put sfr add b 2 bm
2011put sfr add b 3 get scpol 4
2012put sfr add b 4 get scpol 5
2013put sfr add b 5 rd
2014put sfj 1 add get sfj 1 1
2015end
2016
2017note Journal: attach (on) or detach the replay ring. Attaching empties it.
2018note jn_recover attaches once the scheduler holds the journaled state.
2019fn sched_jattach on bool to void
2020put sfj 0 0
2021if on
2022put sfj 0 1
2023end
2024put sfj 1 0
2025end
2026
2027fn sched_jattached to bool
2028ret ne get sfj 0 0
2029end
2030
2031note Journal: records waiting in the replay ring, word i (0..5) of record k,
2032note and emptying it once they are durable.
2033fn sched_frn to ulong
2034ret get sfj 1
2035end
2036fn sched_frw k ulong i ulong to ulong
2037ret get sfr add mul k 6 i
2038end
2039fn sched_frclear to void
2040put sfj 1 0
2041end
2042
2043note Journal, recovery: the cursor and reservation after replay, and the
2044note dispatch event count. The reservation names slot res - 1, which must
2045note hold a ready job. -7 (nothing changed) for a cursor outside the table
2046note or any other reservation, else 0.
2047fn sched_frestore cur ulong ev ulong res ulong to long
2048if or ge cur 64 gt res 64
2049ret neg long 7
2050end
2051if gt res 0
2052if ne get sjst sub res 1 2
2053ret neg long 7
2054end
2055end
2056put scpol 4 cur
2057put scst 2 ev
2058put scpol 5 res
2059ret 0
2060end
2061
2062note Journal, recovery: the bypass count of ready job j. 0 or -3.
2063fn sched_setbyp j ulong n ulong to long
2064if ge j 64
2065ret neg long 3
2066end
2067if ne get sjst j 2
2068ret neg long 3
2069end
2070put sjbyp j n
2071ret 0
2072end
2073
2074note Journal, recovery: waiting job j was made ready by a publication
2075note before the restart. 0 or -3 (j not waiting).
2076fn sched_setready j ulong to long
2077if ge j 64
2078ret neg long 3
2079end
2080if ne get sjst j 1
2081ret neg long 3
2082end
2083sp_ready j
2084ret 0
2085end
2086
2087note Creator: move finished jobs into review while review has room. A worker
2088note whose result is waiting for room keeps it and gets no new job, so a
2089note full review queue stops assignment instead of dropping work. A job
2090note gives back its resources as soon as its worker reported done, even
2091note while its result waits for room.
2092fn sched_collect c long to ulong
2093n = mapget c 48 8
2094k = ulong 0
2095for w ulong n bound 64
2096b = get scbusy w
2097if gt b 0
2098if eq sc_cell w 64 get scseq w
2099j = sub b 1
2100sp_give j
2101if ge sched_count 4 4 get sclim 1
2102continue
2103end
2104put sjst j 4
2105put sjout j sc_cell w 72
2106put scbusy w 0
2107k = add k 1
2108end
2109end
2110end
2111ret k
2112end
2113
2114note Creator, after worker w was reaped: retire its unfinished assignment.
2115note A rerunnable job is ready again; any other becomes UNKNOWN (6), since
2116note it may have had effects. A finished result is left for sched_collect.
2117note Returns 1 when an assignment was retired, 0 when none, -16 still live.
2118fn sched_lost c long w ulong to long
2119if ge w 64
2120ret neg long 7
2121end
2122if gt get swpid w 0
2123ret neg long 16
2124end
2125b = get scbusy w
2126if eq b 0
2127ret 0
2128end
2129if eq sc_cell w 64 get scseq w
2130ret 0
2131end
2132j = sub b 1
2133sc_set w 64 get scseq w
2134put scbusy w 0
2135sp_give j
2136if ne and get sjfl j 1 0
2137sp_ready j
2138else
2139put sjst j 6
2140end
2141ret 1
2142end
2143
2144note Creator loop step: wait up to interval ns for an ack or a death, take
2145note acks, retire the jobs of reaped workers, collect, then dispatch.
2146note Returns the number of workers reaped, or a negative errno.
2147fn sched_step c long interval long to long
2148d = sup_poll c interval
2149if lt d 0
2150ret d
2151end
2152n = mapget c 48 8
2153for w ulong n bound 64
2154if gt get swpid w 0
2155r = sup_take get swack w
2156else
2157r = sched_lost c w
2158end
2159end
2160k = sched_collect c
2161k = sched_dispatch c
2162ret d
2163end
2164
2165note Creator: publish an artifact, make waiting jobs whose deps meet topics
2166note ready, wake each live worker whose interest meets topics, dispatch.
2167note With a journal attached the jobs made ready leave a readiness record
2168note in the replay ring; when the ring is full nothing is published, -105
2169note (counter 15). Returns the version, or the publish refusal with nothing
2170note woken.
2171fn sched_publish c long topics ulong src view uchar 4096 n ulong to long
2172if and ne get sfj 0 0 ge get sfj 1 64
2173put scst 15 add get scst 15 1
2174ret neg long 105
2175end
2176v = pool_publish c topics src n
2177if le v 0
2178ret v
2179end
2180rd = ulong 0
2181for j ulong 64
2182if eq get sjst j 1
2183if ne and get sjdep j topics 0
2184sp_ready j
2185rd = or rd shl 1 j
2186end
2187end
2188end
2189if and ne rd 0 ne get sfj 0 0
2190sp_frpush 0 0 rd
2191end
2192m = mapget c 48 8
2193for w ulong m bound 64
2194if gt get swpid w 0
2195if ne and sc_cell w 32 topics 0
2196sc_wake w
2197end
2198end
2199end
2200k = sched_dispatch c
2201ret v
2202end
2203
2204note Creator: accept the result of job j in review and free its slot.
2205note Returns its outcome, or -3 when j is not in review.
2206fn sched_review j ulong to long
2207if ge j 64
2208ret neg long 3
2209end
2210if ne get sjst j 4
2211ret neg long 3
2212end
2213put sjst j 0
2214ret long get sjout j
2215end
2216
2217note Creator: free an UNKNOWN job once its outcome has been settled
2218note elsewhere. Returns 0, or -3 when j is not UNKNOWN.
2219fn sched_settle j ulong to long
2220if ge j 64
2221ret neg long 3
2222end
2223if ne get sjst j 6
2224ret neg long 3
2225end
2226put sjst j 0
2227ret 0
2228end
2229
2230note Creator: while paused (on true) no job is assigned; running jobs go on
2231note and finished results are still collected. Resuming dispatches at once.
2232note Returns the number assigned on resume, else 0.
2233fn sched_pause c long on bool to ulong
2234if on
2235put scpause 0 1
2236ret 0
2237end
2238put scpause 0 0
2239ret sched_dispatch c
2240end
2241
2242note Creator: cancel job j. A waiting or ready job never started, so it is
2243note freed with no effect: 1. A running job needs its worker: 2, and the
2244note outcome comes from the worker. A job in review already finished: 3,
2245note nothing is cancelled. UNKNOWN stays UNKNOWN: 4. -3 free or bad slot.
2246fn sched_cancel j ulong to long
2247if ge j 64
2248ret neg long 3
2249end
2250s = get sjst j
2251if or eq s 1 eq s 2
2252put sjst j 0
2253sp_bump
2254if eq get scpol 5 add j 1
2255put scpol 5 0
2256end
2257ret 1
2258end
2259if eq s 3
2260ret 2
2261end
2262if eq s 4
2263ret 3
2264end
2265if eq s 6
2266ret 4
2267end
2268ret neg long 3
2269end
2270
2271note Creator: stop every worker within interval ns (sup_stop), retire the
2272note assignments of the reaped workers, collect finished results.
2273note Returns how many workers had to be killed, or a refusal.
2274fn sched_stop c long interval long to long
2275k = sup_stop c interval
2276if lt k 0
2277ret k
2278end
2279n = mapget c 48 8
2280for w ulong n bound 64
2281r = sched_lost c w
2282end
2283m = sched_collect c
2284ret k
2285end
2286
2287note Worker w: the assignment seq when a job is waiting, else 0. Job id,
2288note input epoch and input version are words 8, 16 and 24 of its cell.
2289fn sched_wjob w ulong to ulong
2290q = sc_cell w 0
2291if gt q sc_cell w 64
2292ret q
2293end
2294ret 0
2295end
2296
2297note Worker w: finish assignment q with outcome and the first n (at most
2298note 4096) bytes of src. Bytes and outcome are written before the done seq;
2299note then the creator gets an ack. 0, -7 bad n, or the ack refusal.
2300fn sched_wdone w ulong q ulong outcome ulong src view uchar 4096 n ulong to long
2301if gt n 4096
2302ret neg long 7
2303end
2304if gt n 0
2305r = mapwrite get scmap 1 mul w 4096 src 0 n
2306end
2307sc_set w 72 outcome
2308sc_set w 64 q
2309ret sup_ack w
2310end
2311
2312note Creator: copy worker w's last result bytes into dst.
2313fn sched_result w ulong dst edit uchar 4096 to long
2314ret mapread get scmap 1 mul w 4096 dst 0 4096
2315end
2316
2317note Worker w: sup_wwait that records its wakes and wake latency.
2318fn sched_wwait c long w ulong interval long to long
2319r = sup_wwait c w interval
2320if eq r 1
2321now = ulong monons
2322st = sc_cell w 40
2323lat = ulong 0
2324if gt now st
2325lat = sub now st
2326end
2327sc_set w 80 add sc_cell w 80 1
2328sc_set w 88 lat
2329if gt lat sc_cell w 96
2330sc_set w 96 lat
2331end
2332end
2333ret r
2334end
2335
2336note Worker w: count the versions of the current epoch that meet its
2337note interest and are newer than its cursor, moving the cursor past them.
2338note A new epoch restarts the cursor at 0. A worker with no interest scans
2339note nothing. Returns the count or a refusal.
2340fn sched_wscan c long w ulong to long
2341t = sc_cell w 32
2342if eq t 0
2343ret 0
2344end
2345h = pool_acquire c w
2346if le h 0
2347ret h
2348end
2349e = mapget c add 256 mul w 8 8
2350if ne get swcur 0 e
2351put swcur 0 e
2352put swcur 1 0
2353end
2354k = long 0
2355for i ulong 65
2356v = node_next h get swcur 1 t
2357if lt v 0
2358r = pool_release c w
2359ret v
2360end
2361if eq v 0
2362break
2363end
2364put swcur 1 ulong v
2365k = add k 1
2366end
2367r = pool_release c w
2368ret k
2369end
2370note Concatenate after transport.om, pool.om, super.om and sched.om. CPU-only
2371note acceptance of the resource-aware selection policy (P-DRA-14) with real
2372note forked workers: impossible requests, the capacity invariant under churn,
2373note ready order, the head-of-line scenarios of the reference pump
2374note (aien-sovereign-core-mv spark-harness scheduler/core.rs Core::pump),
2375note starvation under repeated small arrivals, admission tickets, lease
2376note expiry and cancellation of a reserved job.
2377note After every creator step the test checks that no kind is used beyond its
2378note capacity and that the use equals the needs of the jobs holding them.
2379note Argument "fifo" runs policy 0, "noreserve" policy 1 with the bypass
2380note budget out of reach: the negative controls. No GPU, model or network.
2381text pok "PASS node schedpol\n"
2382text pst "schedpol events="
2383text pex " examined="
2384text pas " assigned="
2385text phol " hol_stops="
2386text pbyp " bypasses="
2387text pres " reservations="
2388text pnl "\n"
2389text ptr "schedpol goal trace "
2390text psp " "
2391text pw1 "schedpol hol witness head="
2392text pw2 " fits_behind="
2393text pw3 " free_cpu="
2394text pw4 " idle_worker="
2395global ptc long 1
2396note Mode: 0 default policy, 1 fifo, 2 noreserve, 3 goal (policy 2).
2397global ptm ulong 1
2398note Step-bound snapshot (pt_snap): event count, candidate reads,
2399note maintenance reads, assigned, cursor, window scans.
2400global ptb ulong 6
2401note Phase G trace: ids in review order.
2402global ptt ulong 16
2403global ptn ulong 1
2404note Value-read bound baseline: stats 38, 32, 33 at the last check.
2405global ptv ulong 3
2406
2407fn pt_ok ok bool code int to void
2408if not ok
2409exit code
2410end
2411end
2412
2413fn pt_num v ulong to void
2414d = new uchar 20 0
2415x = v
2416k = ulong 20
2417for i ulong 20
2418k = sub k 1
2419put d k uchar add rem x 10 48
2420x = div x 10
2421if eq x 0
2422break
2423end
2424end
2425r = write 1 d k sub 20 k
2426end
2427
2428note Packed request: cpu slots, memory MiB, inference slots, kind 3.
2429fn pt_req cpu ulong mem ulong inf ulong x ulong to ulong
2430ret or or cpu shl mem 16 or shl inf 32 shl x 48
2431end
2432
2433note Worker: run assignment q for the milliseconds in the low four decimal
2434note digits of its job id, then report outcome id+1 and 8 bytes. 0 done,
2435note 2 stopped, 3 creator gone, 4 wait error, 5 report refused.
2436fn pt_run c long w ulong q ulong to int
2437buf = new uchar 4096 0
2438id = sc_cell w 8
2439dl = add ulong monons mul rem id 10000 1000000
2440for t ulong 1000000
2441now = ulong monons
2442if ge now dl
2443break
2444end
2445r = sched_wwait c w long sub dl now
2446if eq r 2
2447ret 2
2448end
2449if eq r 3
2450ret 3
2451end
2452if lt r 0
2453ret 4
2454end
2455end
2456if ne sched_wdone w q add id 1 buf 8 0
2457ret 5
2458end
2459ret 0
2460end
2461
2462fn pt_worker w ulong to int
2463c = get ptc 0
2464for it ulong 1000000000
2465q = sched_wjob w
2466if gt q 0
2467r = pt_run c w q
2468if eq r 2
2469ret 0
2470end
2471if ne r 0
2472ret add 60 r
2473end
2474continue
2475end
2476r = sched_wwait c w neg long 1
2477if eq r 2
2478ret 0
2479end
2480if eq r 3
2481ret 41
2482end
2483if lt r 0
2484ret 43
2485end
2486end
2487ret 45
2488end
2489
2490fn pt_spawn c long w ulong to bool
2491p = sup_spawn c w
2492if eq p 0
2493exit pt_worker w
2494end
2495ret gt p 0
2496end
2497
2498note Fresh pool for w workers (spawned), admission limit a, review limit rl,
2499note capacities caps. Exits with code on any refusal.
2500fn pt_setup w ulong a ulong rl ulong caps ulong code int to long
2501c = pool_new 4 w
2502pt_ok gt c 0 code
2503put ptc 0 c
2504pt_ok eq sup_init c 0 code
2505pt_ok eq sched_new c a rl 0 code
2506pt_ok eq sched_cap caps 0 code
2507put ptv 0 sched_stat 38
2508put ptv 1 sched_stat 32
2509put ptv 2 sched_stat 33
2510if eq get ptm 0 1
2511pt_ok eq sched_policy 0 64 64 4 1000 0 code
2512end
2513if eq get ptm 0 2
2514pt_ok eq sched_policy 1 64 64 65535 1000 0 code
2515end
2516if eq get ptm 0 3
2517pt_ok eq sched_policy 2 64 64 4 1000 0 code
2518end
2519for i ulong w bound 64
2520pt_ok pt_spawn c i code
2521end
2522ret c
2523end
2524
2525fn pt_down c long code int to void
2526pt_ok ge sched_stop c 2000000000 0 code
2527sup_closeall
2528pt_ok eq sched_free 0 code
2529pt_ok eq pool_free c 0 code
2530end
2531
2532note The capacity invariant: of each kind the use is at most the capacity
2533note and equals the sum of the needs of the jobs that hold resources; only
2534note a running job holds them, and every running job whose worker has not
2535note reported done holds them.
2536fn pt_inv code int to void
2537for j ulong 64
2538if eq get sjst j 3
2539w = get sjw j
2540if ne sc_cell w 64 get scseq w
2541pt_ok eq get sjheld j 1 code
2542end
2543end
2544end
2545for k ulong 4
2546s = ulong 0
2547for j ulong 64
2548if eq get sjheld j 1
2549pt_ok eq get sjst j 3 code
2550s = add s sp_need get sjneed j k
2551end
2552end
2553pt_ok eq get suse k s code
2554pt_ok le get suse k get scap k code
2555end
2556end
2557
2558note One creator step of up to 10 ms, then the invariant and the scan
2559note bounds since the last step. An event makes at most one pick more than
2560note it assigns, so candidate reads are at most (assigned + events) x
2561note (window + 1), the reserved probe included, plus one proposal probe per
2562note pick under policy 2, or x 64 under FIFO (policy 0), 9; maintenance reads
2563note at most 64 per event, 14; the cursor moved by exactly the window per
2564note window scan, mod 64, 15 (the traversal witness: window scans cover
2565note consecutive windows, so ceil(64/win) of them examine every slot); value
2566note reads at most 64 per rescoring plus 128 per job scored, 8.
2567fn pt_step c long code int to void
2568pt_snap
2569r = sched_step c 10000000
2570pt_ok ge r 0 code
2571pt_inv code
2572pt_check
2573end
2574
2575note Snapshot the counters the step bounds compare against (ptb).
2576fn pt_snap to void
2577put ptb 0 sched_stat 2
2578put ptb 1 sched_stat 3
2579put ptb 2 sched_stat 13
2580put ptb 3 sched_stat 4
2581put ptb 4 sched_stat 28
2582put ptb 5 sched_stat 14
2583end
2584
2585note The bounds since pt_snap (exits 9, 14, 15, 8).
2586fn pt_check to void
2587w = add sched_stat 25 1
2588if eq sched_stat 24 0
2589w = ulong 64
2590end
2591if eq sched_stat 24 2
2592w = add w 1
2593end
2594ev = sub sched_stat 2 get ptb 0
2595lim = mul add sub sched_stat 4 get ptb 3 ev w
2596pt_ok le sub sched_stat 3 get ptb 1 lim 9
2597pt_ok le sub sched_stat 13 get ptb 2 mul ev 64 14
2598pt_cursor get ptb 4 get ptb 5
2599pt_vbound
2600end
2601
2602note Resume dispatch (it dispatches at once) inside the step bounds.
2603fn pt_resume c long to void
2604pt_snap
2605k = sched_pause c false
2606pt_check
2607end
2608
2609note The cursor moved by the window once per window scan since (u0, s0).
2610fn pt_cursor u0 ulong s0 ulong to void
2611d = mul sched_stat 25 sub sched_stat 14 s0
2612pt_ok eq sched_stat 28 rem add u0 d 64 15
2613end
2614
2615note The value-read bound since the last call (phase checks, exit 8).
2616fn pt_vbound to void
2617v = sched_stat 38
2618lim = add mul sub sched_stat 32 get ptv 1 64 mul sub sched_stat 33 get ptv 2 128
2619pt_ok le sub v get ptv 0 lim 8
2620put ptv 0 v
2621put ptv 1 sched_stat 32
2622put ptv 2 sched_stat 33
2623end
2624
2625note Step until job j is in a state in lo..hi, up to ms. True when reached.
2626fn pt_until c long j ulong lo ulong hi ulong ms ulong code int to bool
2627dl = add ulong monons mul ms 1000000
2628for t ulong 1000000
2629s = get sjst j
2630if and ge s lo le s hi
2631ret true
2632end
2633if ge ulong monons dl
2634ret false
2635end
2636pt_step c code
2637end
2638ret false
2639end
2640
2641note Review every job in review whose outcome is its id + 1.
2642fn pt_review code int to ulong
2643n = ulong 0
2644for j ulong 64
2645if eq get sjst j 4
2646pt_ok eq sched_review j long add get sjid j 1 code
2647n = add n 1
2648end
2649end
2650ret n
2651end
2652
2653note Step and review until n jobs were reviewed, up to ms.
2654fn pt_drain c long n ulong ms ulong code int to void
2655dl = add ulong monons mul ms 1000000
2656k = ulong 0
2657for t ulong 1000000
2658k = add k pt_review code
2659if ge k n
2660ret
2661end
2662pt_ok lt ulong monons dl code
2663pt_step c code
2664end
2665exit code
2666end
2667
2668fn pt_admit id ulong deps ulong req ulong code int to ulong
2669j = sched_admitr id deps 0 req
2670pt_ok ge j 0 code
2671ret ulong j
2672end
2673
2674note Phase C: a request beyond the capacity of any kind is refused (-8) and
2675note counted; lowering a capacity below an admitted job's need, or below
2676note the use of two running jobs that each fit it alone, is refused and
2677note changes nothing.
2678fn pt_impossible to void
2679c = pt_setup 2 8 8 pt_req 4 1024 1 8 30
2680pt_ok eq sched_admitr 1 0 0 pt_req 5 0 0 0 neg long 8 31
2681pt_ok eq sched_admitr 2 0 0 pt_req 1 1025 0 0 neg long 8 32
2682pt_ok eq sched_admitr 3 0 0 pt_req 0 0 2 0 neg long 8 33
2683pt_ok eq sched_stat 7 3 34
2684a = pt_admit 4 0 pt_req 3 0 0 0 35
2685pt_ok eq sched_cap pt_req 2 1024 1 8 neg long 8 36
2686pt_ok eq sched_stat 16 4 37
2687pt_ok eq sched_cancel a 1 38
2688pt_ok eq sched_cap pt_req 2 1024 1 8 0 39
2689pt_ok eq sched_stat 16 2 40
2690pt_ok eq sched_cap pt_req 4 1024 1 8 0 130
2691p = pt_admit 130400 0 pt_req 2 0 0 0 130
2692q = pt_admit 140400 0 pt_req 2 0 0 0 130
2693pt_ok pt_until c p 3 3 2000 130 130
2694pt_ok pt_until c q 3 3 2000 130 130
2695pt_ok eq sched_cap pt_req 3 1024 1 8 neg long 8 131
2696pt_ok eq sched_stat 16 4 132
2697pt_drain c 2 3000 133
2698pt_ok eq sched_cap pt_req 3 1024 1 8 0 134
2699pt_down c 41
2700end
2701
2702note Phase D: 12 jobs with mixed CPU, memory and inference needs on three
2703note workers, capacities 4 CPU, 1024 MiB, 1 inference slot. Every job runs
2704note once and returns its outcome; the invariant holds at every step and
2705note every resource is free at the end.
2706fn pt_churn to void
2707c = pt_setup 3 16 8 pt_req 4 1024 1 0 42
2708for i ulong 12
2709cpu = add rem i 3 1
2710mem = mul add rem i 6 1 100
2711inf = rem i 2
2712id = add mul add i 1 10000 add 30 mul rem i 4 15
2713j = pt_admit id 0 pt_req cpu mem inf 0 43
2714end
2715pt_drain c 12 10000 44
2716for k ulong 4
2717pt_ok eq get suse k 0 45
2718end
2719pt_ok eq sched_count 1 6 0 46
2720pt_ok eq sched_stat 4 12 47
2721pt_down c 48
2722end
2723
2724note Some running job whose worker has reported done (its result waits
2725note for review room).
2726fn pt_held to bool
2727for j ulong 64
2728if eq get sjst j 3
2729w = get sjw j
2730if eq sc_cell w 64 get scseq w
2731ret true
2732end
2733end
2734end
2735ret false
2736end
2737
2738note Phase V: release while review is full. Review limit 1, two workers,
2739note 2 CPU: j1 and j2 (1 CPU, 50 ms) both finish; one enters review, the
2740note other's result waits for room, yet both CPUs are free at once and j3
2741note (2 CPU) runs before anything is reviewed.
2742fn pt_release to void
2743c = pt_setup 2 8 1 pt_req 2 1024 1 8 120
2744j1 = pt_admit 150050 0 pt_req 1 0 0 0 120
2745j2 = pt_admit 160050 0 pt_req 1 0 0 0 120
2746dl = add ulong monons 2000000000
2747for t ulong 1000000
2748if eq sched_count 4 4 1
2749if pt_held
2750break
2751end
2752end
2753pt_ok lt ulong monons dl 121
2754pt_step c 121
2755end
2756note The done report may land after the last collect: one more step
2757note collects it (review stays full, so nothing else changes).
2758pt_step c 121
2759pt_ok eq get suse 0 0 122
2760j3 = pt_admit 170050 0 pt_req 2 0 0 0 123
2761pt_ok pt_until c j3 3 4 2000 123 124
2762pt_drain c 3 3000 125
2763pt_down c 126
2764end
2765
2766note Phase F: ready order. With one worker, x is admitted first waiting on
2767note topic 8 and y second ready at once; then topic 8 is published. FIFO
2768note (policy 0) serves the job that became ready first, y; fair fitting
2769note serves the job admitted first, x (waiting age counts from admission).
2770fn pt_order to void
2771buf = new uchar 4096 0
2772c = pt_setup 1 8 8 pt_req 4 1024 1 8 50
2773x = pt_admit 60050 8 0 51
2774y = pt_admit 70050 0 0 52
2775pt_snap
2776pt_ok gt sched_publish c 8 buf 16 0 53
2777pt_check
2778if eq sched_stat 24 0
2779pt_ok eq get sjst y 3 54
2780pt_ok eq get sjst x 2 55
2781else
2782pt_ok eq get sjst x 3 54
2783pt_ok eq get sjst y 2 55
2784end
2785pt_drain c 2 3000 56
2786pt_down c 57
2787end
2788
2789note Witness of a head-of-line block, read with no step in between: a runs
2790note unfinished holding its need, the head h is ready and does not fit, x
2791note is ready and fits, a live worker is idle, and dispatch stopped at the
2792note head at least once since h0 (codes code..code+4 when not).
2793fn pt_witness c long a ulong h ulong x ulong h0 ulong code int to void
2794w = get sjw a
2795pt_ok eq get sjst a 3 code
2796pt_ok ne sc_cell w 64 get scseq w code
2797pt_ok eq get sjheld a 1 code
2798pt_ok eq get sjst h 2 add code 1
2799pt_ok not sp_fits get sjneed h 0 add code 1
2800pt_ok eq get sjst x 2 add code 2
2801pt_ok sp_fits get sjneed x 0 add code 2
2802i = sp_idle mapget c 48 8
2803pt_ok lt i 64 add code 3
2804pt_ok gt sched_stat 8 h0 add code 4
2805r = write 1 pw1 0 len pw1
2806pt_num get sjid h
2807r = write 1 pw2 0 len pw2
2808pt_num get sjid x
2809r = write 1 pw3 0 len pw3
2810pt_num sp_free 0
2811r = write 1 pw4 0 len pw4
2812pt_num i
2813r = write 1 phol 0 len phol
2814pt_num sub sched_stat 8 h0
2815r = write 1 pnl 0 1
2816end
2817
2818note Phase A: the blocked head. a (3 CPU, 800 ms) runs; then b (2 CPU,
2819note cannot fit) and c (1 CPU, fits) arrive with no dependency. The target:
2820note c runs while a still runs and b waits (0). When c has not run within
2821note 400 ms, the witness is checked and printed and the phase returns 11:
2822note c stayed idle behind b although a CPU and a worker were free.
2823fn pt_blocked to int
2824c = pt_setup 3 8 8 pt_req 4 1024 1 8 10
2825a = pt_admit 10800 0 pt_req 3 0 0 0 10
2826pt_ok pt_until c a 3 3 2000 10 10
2827b = pt_admit 20050 0 pt_req 2 0 0 0 10
2828x = pt_admit 30050 0 pt_req 1 0 0 0 10
2829h0 = sched_stat 8
2830v = int 0
2831if pt_until c x 3 4 400 10
2832pt_ok eq get sjst a 3 12
2833pt_ok eq get sjst b 2 13
2834else
2835pt_witness c a b x h0 12
2836v = int 11
2837end
2838pt_drain c 3 5000 17
2839pt_down c 18
2840ret v
2841end
2842
2843note Phase B: a second head-of-line case, after the pump's queue-of-two
2844note scenario (the bounded queue itself is not modelled: every admitted
2845note job is in the table). a (3 CPU, 800 ms) runs, b and d (2 CPU) cannot
2846note fit, e (1 CPU) fits. Target: e runs while a still runs (0); else the
2847note witness and 21.
2848fn pt_exclude to int
2849c = pt_setup 3 8 8 pt_req 4 1024 1 8 20
2850a = pt_admit 10800 0 pt_req 3 0 0 0 20
2851pt_ok pt_until c a 3 3 2000 20 20
2852b = pt_admit 20050 0 pt_req 2 0 0 0 20
2853d = pt_admit 40050 0 pt_req 2 0 0 0 20
2854e = pt_admit 50050 0 pt_req 1 0 0 0 20
2855h0 = sched_stat 8
2856v = int 0
2857if pt_until c e 3 4 400 20
2858pt_ok eq get sjst a 3 22
2859else
2860pt_witness c a b e h0 22
2861v = int 21
2862end
2863pt_drain c 4 5000 27
2864pt_down c 28
2865ret v
2866end
2867
2868note Phase S: starvation under repeated small arrivals. Three workers, 4
2869note CPU. Small jobs (1 CPU) start staggered (100, 200, 300 ms), and each
2870note that finishes is replaced by one of 300 ms, so the small jobs never
2871note all end together; big (4 CPU, 50 ms) needs every CPU free. The target:
2872note big runs within 4 s. 61 means it never did: the small jobs kept the
2873note CPU partly busy (the "noreserve" control).
2874fn pt_starve to void
2875c = pt_setup 3 16 8 pt_req 4 1024 1 8 60
2876for i ulong 3
2877j = pt_admit mul add i 1 100100 0 pt_req 1 0 0 0 60
2878end
2879s = ulong 4
2880g = pt_admit 90050 0 pt_req 4 0 0 0 60
2881dl = add ulong monons 4000000000
2882ok = false
2883for t ulong 1000000
2884if ge get sjst g 3
2885ok = true
2886break
2887end
2888if ge ulong monons dl
2889break
2890end
2891if lt sched_count 1 3 4
2892j = pt_admit add mul s 100000 300 0 pt_req 1 0 0 0 60
2893s = add s 1
2894end
2895pt_step c 60
2896n = pt_review 60
2897end
2898pt_ok ok 61
2899pt_ok ge sched_stat 6 1 62
2900pt_ok ge sched_stat 9 1 63
2901pt_drain c sched_count 1 4 5000 64
2902pt_stats
2903pt_ok eq get suse 0 0 65
2904pt_down c 66
2905end
2906
2907note Phase Q: admission tickets. Limit 2: p1 (400 ms) and p2 (900 ms) fill
2908note it; X then Y are refused and hold tickets in that order. When p1 is
2909note reviewed there is room for one: Y asking first is refused (75), X is
2910note admitted (76); Y enters once more room returns (78). A ticket not
2911note asked about for the lifetime (20 events) lapses, so a new caller is
2912note admitted although the old holder never came back (80). The wait for
2913note the lapse reviews whatever finishes, 140900 included when it outlasts
2914note that job's 900 ms, so the last drain waits for the jobs still
2915note outstanding, not a fixed two: a fixed two timed out (80) whenever the
2916note loop had already reviewed 140900.
2917fn pt_tickets to void
2918c = pt_setup 2 2 8 pt_req 4 1024 1 8 70
2919pt_ok eq sched_policy sched_stat 24 64 64 sched_stat 27 1000 0 70
2920p1 = pt_admit 100400 0 0 70
2921p2 = pt_admit 110900 0 0 70
2922pt_ok eq sched_admitr 120050 0 0 0 neg long 2 71
2923pt_ok eq sched_admitr 130050 0 0 0 neg long 2 72
2924pt_ok eq sched_stat 30 2 73
2925pt_drain c 1 3000 74
2926pt_ok eq sched_admitr 130050 0 0 0 neg long 2 75
2927pt_ok ge sched_admitr 120050 0 0 0 0 76
2928pt_drain c 2 3000 77
2929pt_ok ge sched_admitr 130050 0 0 0 0 78
2930pt_ok eq sched_policy sched_stat 24 64 64 sched_stat 27 20 0 79
2931f = pt_admit 140900 0 0 79
2932pt_ok eq sched_admitr 150050 0 0 0 neg long 2 79
2933e0 = sched_stat 2
2934dl = add ulong monons 3000000000
2935for t ulong 1000000
2936if le sched_count 1 3 1
2937if gt sched_stat 2 add e0 21
2938break
2939end
2940end
2941pt_ok lt ulong monons dl 79
2942pt_step c 79
2943n = pt_review 79
2944end
2945pt_ok ge sched_admitr 160050 0 0 0 0 80
2946pt_ok ge sched_stat 11 1 80
2947pt_drain c sched_count 1 4 3000 80
2948pt_down c 80
2949end
2950
2951note Step until sched_overdue reports a job, up to 2 s: its slot, or 64.
2952fn pt_waitod c long code int to ulong
2953t0 = ulong monons
2954for t ulong 1000000
2955o = sched_overdue
2956if lt o 64
2957ret o
2958end
2959if gt sub ulong monons t0 2000000000
2960ret 64
2961end
2962pt_step c code
2963end
2964ret 64
2965end
2966
2967note Phase L: lease expiry. h (2 of 2 CPU, 3 s, not safe to rerun) has a
2968note 200 ms lease: its deadline is at least 200 ms after h was admitted, and
2969note sched_overdue reports it once, at or after that deadline (83); the
2970note creator kills its worker; h becomes UNKNOWN and its CPU is free.
2971note h2 (2 CPU, 400 ms, safe to rerun, 100 ms lease) is killed the same
2972note way: it is ready or running again with its admission age kept, and
2973note completes. Then a new 2-CPU job runs.
2974fn pt_lease to void
2975c = pt_setup 3 8 8 pt_req 2 1024 1 8 81
2976t0 = ulong monons
2977h = pt_admit 173000 0 pt_req 2 0 0 0 81
2978pt_ok eq sched_lease h 200000000 0 81
2979pt_ok pt_until c h 3 3 2000 81 81
2980due = get sjdue h
2981pt_ok ge due add t0 200000000 83
2982o = pt_waitod c 82
2983pt_ok eq o h 82
2984pt_ok ge ulong monons due 83
2985pt_ok eq sched_overdue 64 84
2986r = killpid int get swpid get sjw h 9
2987pt_ok pt_until c h 6 6 2000 85 85
2988pt_ok eq get suse 0 0 86
2989pt_ok eq sched_settle h 0 87
2990x = sched_admitr 180400 0 1 pt_req 2 0 0 0
2991pt_ok ge x 0 140
2992h2 = ulong x
2993pt_ok eq sched_lease h2 100000000 0 140
2994pt_ok pt_until c h2 3 3 2000 140 140
2995ar = get sjarr h2
2996pt_ok eq pt_waitod c 141 h2 141
2997w = get sjw h2
2998r = killpid int get swpid w 9
2999dl = add ulong monons 2000000000
3000for t ulong 1000000
3001if eq get swpid w 0
3002break
3003end
3004pt_ok lt ulong monons dl 142
3005pt_step c 142
3006end
3007pt_ok eq get sjarr h2 ar 143
3008s = get sjst h2
3009pt_ok and ge s 2 le s 3 144
3010pt_drain c 1 3000 145
3011z = pt_admit 190050 0 pt_req 2 0 0 0 88
3012pt_drain c 1 3000 88
3013pt_down c 89
3014end
3015
3016note Phase R: cancellation of a reserved job. Bypass budget 1: a (1 of 2
3017note CPU) runs, b (2 CPU) waits, x (1 CPU) runs past it, so b is reserved.
3018note Cancelling b frees it with no effect and clears the reservation.
3019fn pt_rcancel to void
3020c = pt_setup 2 8 8 pt_req 2 1024 1 8 90
3021pt_ok eq sched_policy sched_stat 24 64 64 1 1000 0 90
3022a = pt_admit 190600 0 pt_req 1 0 0 0 90
3023pt_ok pt_until c a 3 3 2000 90 90
3024b = pt_admit 200050 0 pt_req 2 0 0 0 90
3025x = pt_admit 210050 0 pt_req 1 0 0 0 90
3026pt_ok pt_until c x 3 4 400 90 91
3027pt_ok eq sched_stat 29 add b 1 92
3028pt_ok eq sched_cancel b 1 93
3029pt_ok eq sched_stat 29 0 94
3030pt_drain c 2 3000 95
3031pt_ok eq get suse 0 0 96
3032pt_down c 97
3033end
3034
3035note Phase W: bounded candidate work. Window 4 slots, dispatch budget 2,
3036note two workers, so an event may pick twice: 12 ready jobs fill slots
3037note 0..11, beyond any one window. Each pick reads at most 5 slots (the
3038note reserved probe and the window, exit 9), every window scan moves the
3039note cursor on by 4 (15), and all 12 run. 101 means some never did.
3040fn pt_window to void
3041c = pt_setup 2 16 16 pt_req 4 1024 1 8 101
3042pt_ok eq sched_policy sched_stat 24 4 2 sched_stat 27 1000 0 101
3043for i ulong 12
3044j = pt_admit add mul add i 1 10000 30 0 0 101
3045end
3046pt_drain c 12 5000 101
3047pt_ok eq sched_stat 4 12 102
3048pt_down c 103
3049end
3050
3051note Phase T: ticket order with several openings. Limit 3 held by p1, p2
3052note (400 ms) and p3, which waits on a topic nobody publishes; X, Y, Z are
3053note refused in that order and hold tickets (104). p1 and p2 are reviewed,
3054note so there are exactly two openings: Y asking first is refused (105), and
3055note so is a new caller W, who takes a ticket behind Z (106); X enters
3056note (107), then Y (108). p3 is cancelled and X and Y are reviewed, so there
3057note are three openings: W asking first is refused, then Z and W enter (109).
3058fn pt_torder to void
3059c = pt_setup 3 3 8 pt_req 4 1024 1 8 104
3060p = pt_admit 400400 0 0 104
3061p = pt_admit 410400 0 0 104
3062p3 = pt_admit 420050 4096 0 104
3063pt_ok eq sched_admitr 430050 0 0 0 neg long 2 104
3064pt_ok eq sched_admitr 440050 0 0 0 neg long 2 104
3065pt_ok eq sched_admitr 450050 0 0 0 neg long 2 104
3066pt_ok eq sched_stat 30 3 104
3067pt_drain c 2 3000 104
3068pt_ok eq sched_admitr 440050 0 0 0 neg long 2 105
3069pt_ok eq sched_admitr 460050 0 0 0 neg long 2 106
3070pt_ok eq sched_stat 30 4 106
3071pt_ok ge sched_admitr 430050 0 0 0 0 107
3072pt_ok ge sched_admitr 440050 0 0 0 0 108
3073pt_ok eq sched_cancel p3 1 108
3074pt_drain c 2 3000 108
3075pt_ok eq sched_admitr 460050 0 0 0 neg long 2 109
3076pt_ok ge sched_admitr 450050 0 0 0 0 109
3077pt_ok ge sched_admitr 460050 0 0 0 0 109
3078pt_drain c 2 3000 109
3079pt_down c 109
3080end
3081
3082note Phase X: the table, not the admission limit, is full. Admission limit
3083note and review limit 64; 64 jobs finish and wait in review, so none is
3084note admitted, waiting, ready or running. A new caller is refused and takes
3085note a ticket (190, 191), as is a second (192). One review frees one slot:
3086note the second holder is refused, the first enters (193, 194).
3087fn pt_slots to void
3088c = pt_setup 3 64 64 pt_req 4 1024 1 8 190
3089for i ulong 64
3090j = pt_admit add 500001 mul i 10000 0 0 190
3091end
3092dl = add ulong monons 5000000000
3093for t ulong 1000000
3094if eq sched_count 4 4 64
3095break
3096end
3097pt_ok lt ulong monons dl 190
3098pt_step c 190
3099end
3100pt_ok not sched_room 600050 191
3101pt_ok eq sched_stat 30 1 191
3102pt_ok eq sched_admitr 600050 0 0 0 neg long 2 192
3103pt_ok eq sched_admitr 610050 0 0 0 neg long 2 192
3104pt_ok eq sched_stat 30 2 192
3105pt_ok eq sched_review 0 long add get sjid 0 1 193
3106pt_ok eq sched_admitr 610050 0 0 0 neg long 2 193
3107pt_ok ge sched_admitr 600050 0 0 0 0 194
3108n = pt_review 194
3109pt_ok ge sched_admitr 610050 0 0 0 0 194
3110pt_drain c 2 3000 194
3111pt_down c 194
3112end
3113
3114note Phase Z: reserved progress needs review progress. Review limit 1, two
3115note workers, 2 CPU, bypass budget 1. p finishes and waits in review,
3116note unreviewed. a (1 CPU) and x (1 CPU) run past b (2 CPU), so b is
3117note reserved (196). a and x finish; their workers keep the results, since
3118note review is full, so b is ready at every step for 600 ms (197) and all
3119note CPU is free at the end of that interval (198). Reviewing p lets a into
3120note review, frees its worker, and b runs (199).
3121fn pt_live to void
3122c = pt_setup 2 8 1 pt_req 2 1024 1 8 195
3123pt_ok eq sched_policy sched_stat 24 64 64 1 1000 0 195
3124p = pt_admit 470050 0 pt_req 1 0 0 0 195
3125pt_ok pt_until c p 4 4 2000 195 195
3126k = sched_pause c true
3127a = pt_admit 480050 0 pt_req 1 0 0 0 195
3128b = pt_admit 490050 0 pt_req 2 0 0 0 195
3129x = pt_admit 510050 0 pt_req 1 0 0 0 195
3130pt_resume c
3131pt_ok eq sched_stat 29 add b 1 196
3132dl = add ulong monons 600000000
3133for t ulong 1000000
3134if ge ulong monons dl
3135break
3136end
3137pt_step c 197
3138pt_ok eq get sjst b 2 197
3139end
3140pt_ok eq get suse 0 0 198
3141pt_ok eq sched_review p long add get sjid p 1 199
3142pt_ok pt_until c b 3 4 2000 199 199
3143pt_drain c 3 3000 199
3144pt_down c 199
3145end
3146
3147note Phase M: lease bounds (2^50 ns, about 13 days). Waiting job w refuses
3148note 2^50 + 1 and 2^64 - 1 (-7) with its lease unchanged (200, 201) and
3149note accepts 2^50 (202). Job r, leased 2^50 before it is assigned, runs with
3150note a deadline ahead of the clock and nothing overdue (203); running, it
3151note refuses both too large values with lease and deadline unchanged (204,
3152note 205) and accepts a renewal of 2^49 measured from now: the new deadline
3153note lies between clock + 2^49 read just before and just after the call
3154note (206), and nothing is overdue; it then completes (207).
3155fn pt_lbound to void
3156c = pt_setup 1 8 8 pt_req 2 1024 1 8 200
3157mx = ulong 1125899906842624
3158w = pt_admit 220050 1 0 200
3159pt_ok eq sched_lease w add mx 1 neg long 7 200
3160pt_ok eq get sjlse w 0 200
3161pt_ok eq sched_lease w sub ulong 0 1 neg long 7 201
3162pt_ok eq get sjlse w 0 201
3163pt_ok eq sched_lease w mx 0 202
3164pt_ok eq get sjlse w mx 202
3165r = pt_admit 230600 0 pt_req 1 0 0 0 203
3166pt_ok eq sched_lease r mx 0 203
3167pt_ok pt_until c r 3 3 2000 203 203
3168d = get sjdue r
3169pt_ok gt d ulong monons 203
3170pt_ok eq sched_overdue 64 203
3171pt_ok eq sched_lease r sub ulong 0 1 neg long 7 204
3172pt_ok and eq get sjdue r d eq get sjlse r mx 204
3173pt_ok eq sched_lease r add mx 1 neg long 7 205
3174pt_ok and eq get sjdue r d eq get sjlse r mx 205
3175w = ulong monons
3176pt_ok eq sched_lease r div mx 2 0 206
3177t2 = ulong monons
3178pt_ok ge get sjdue r add w div mx 2 206
3179pt_ok le get sjdue r add t2 div mx 2 206
3180pt_ok eq sched_overdue 64 206
3181pt_drain c 1 3000 207
3182pt_down c 207
3183end
3184
3185note Phase N: every ask renews a ticket, a successful one too. Admission
3186note limit 1, ticket lifetime 2. o waits on a topic nobody publishes and
3187note fills the limit; X is refused at event e and holds a ticket. o is
3188note cancelled; at event e + 1 X asks and is told yes, which renews its
3189note ticket (210). At e + 3 the ticket still holds (asked at e + 1, lifetime
3190note 2), so newcomer Y is refused (211); at e + 4 it lapses, exactly one
3191note lapse is counted and Y, now first, is admitted (212).
3192fn pt_renew to void
3193c = pt_setup 1 1 8 pt_req 2 1024 1 8 210
3194pt_ok eq sched_policy sched_stat 24 64 64 sched_stat 27 2 0 210
3195o = pt_admit 240050 1 0 210
3196pt_ok eq sched_admitr 250050 0 0 0 neg long 2 210
3197pt_ok eq sched_cancel o 1 210
3198k = sched_dispatch c
3199pt_ok sched_room 250050 210
3200k = sched_dispatch c
3201k = sched_dispatch c
3202pt_ok eq sched_admitr 260050 0 0 0 neg long 2 211
3203l0 = sched_stat 11
3204k = sched_dispatch c
3205pt_ok ge sched_admitr 260050 0 0 0 0 212
3206pt_ok eq sched_stat 11 add l0 1 212
3207pt_drain c 1 3000 212
3208pt_down c 212
3209end
3210
3211note Phase U: the dispatch budget binds. Four idle workers, dispatch budget
3212note 2, six ready 1-CPU jobs and 4 CPU: one dispatch assigns exactly 2
3213note (220); all six then complete (221).
3214fn pt_budget to void
3215c = pt_setup 4 16 16 pt_req 4 1024 1 8 220
3216pt_ok eq sched_policy sched_stat 24 64 2 sched_stat 27 1000 0 220
3217for i ulong 6
3218j = pt_admit add 270100 mul i 10000 0 pt_req 1 0 0 0 220
3219end
3220a0 = sched_stat 4
3221k = sched_dispatch c
3222pt_ok and eq k 2 eq sub sched_stat 4 a0 2 220
3223pt_drain c 6 5000 221
3224pt_down c 221
3225end
3226
3227fn pt_mode to void
3228a = new uchar 16 0
3229if ne argcnt 2
3230ret
3231end
3232n = argread 1 a 0 16
3233if eq n 4
3234if eq get a 0 102
3235put ptm 0 1
3236end
3237if eq get a 0 103
3238put ptm 0 3
3239end
3240end
3241if eq n 9
3242put ptm 0 2
3243end
3244end
3245
3246note Step, then review every job in review in slot order, appending its id
3247note to the trace and publishing the topics it declared (as the workflow
3248note does after accepting a result).
3249fn pt_gstep c long buf edit uchar 4096 code int to void
3250pt_step c code
3251for j ulong 64
3252if eq get sjst j 4
3253p = get sjpro j
3254n = get ptn 0
3255if lt n 16
3256put ptt n get sjid j
3257end
3258put ptn 0 add n 1
3259pt_ok eq sched_review j long add get sjid j 1 code
3260if ne p 0
3261pt_snap
3262pt_ok gt sched_publish c p buf 16 0 code
3263pt_check
3264end
3265end
3266end
3267end
3268
3269fn pt_gadmit id ulong deps ulong pro ulong code int to ulong
3270j = pt_admit id deps pt_req 1 0 0 0 code
3271if ne pro 0
3272pt_ok eq sched_goal j pro 50 10 0 code
3273end
3274ret j
3275end
3276
3277note One run of the goal workload, one worker, policy 2, bypass budget 4,
3278note admitted while paused: x (no value), z (unblocks d: value 1), a
3279note (unblocks b, which unblocks c: value 2), f (unblocks g1..g3: value 3).
3280note A decision is made when the worker frees, before the finished job's
3281note topics are published. Order: f a z b x d c g1 g2 g3. f and a first
3282note (useful work); x, bypassed in 4 events, is reserved and runs 5th.
3283fn pt_grun code int to void
3284buf = new uchar 4096 0
3285c = pt_setup 1 16 16 pt_req 1 1024 1 8 code
3286pt_ok eq sched_policy 2 64 64 4 1000 0 code
3287k = sched_pause c true
3288put ptn 0 0
3289j = pt_gadmit 220050 0 0 code
3290j = pt_gadmit 230050 0 128 code
3291j = pt_gadmit 240050 128 0 code
3292j = pt_gadmit 250050 0 32 code
3293j = pt_gadmit 260050 32 64 code
3294j = pt_gadmit 270050 64 0 code
3295j = pt_gadmit 280050 0 256 code
3296for i ulong 3
3297j = pt_gadmit add 290050 mul i 10000 256 0 code
3298end
3299pt_resume c
3300dl = add ulong monons 5000000000
3301for t ulong 1000000
3302if ge get ptn 0 10
3303break
3304end
3305pt_ok lt ulong monons dl code
3306pt_gstep c buf code
3307end
3308pt_down c code
3309end
3310
3311note Phase G: goal-aware ranking. The goal workload runs twice; both traces
3312note must equal the expected order (151 first run, 152 second): repeated
3313note identical inputs, identical decisions.
3314fn pt_goal to void
3315ex = new ulong 10 0
3316put ex 0 280050
3317put ex 1 250050
3318put ex 2 230050
3319put ex 3 260050
3320put ex 4 220050
3321put ex 5 240050
3322put ex 6 270050
3323put ex 7 290050
3324put ex 8 300050
3325put ex 9 310050
3326for r ulong 2
3327code = int add 151 r
3328pt_grun 150
3329pt_ok eq get ptn 0 10 code
3330for i ulong 10
3331if ne get ptt i get ex i
3332pt_trace
3333exit code
3334end
3335end
3336end
3337end
3338
3339fn pt_trace to void
3340r = write 1 ptr 0 len ptr
3341for i ulong get ptn 0 bound 16
3342pt_num get ptt i
3343r = write 1 psp 0 1
3344end
3345r = write 1 pnl 0 1
3346end
3347
3348note Phase H: rescoring. Policy 2, paused: one ready job r and two jobs
3349note waiting on topic 512, then r declares topic 512: four graph changes,
3350note no rescoring (160). The first pick rescores once for all four (161).
3351note r completing and being reviewed with nothing published changes no
3352note value: no rescoring (162). Publishing 512 readies both waiting jobs:
3353note two changes, one more rescoring at the next pick (163). The work of
3354note every rescoring is bounded (checked at each step, exit 8). Cancelling
3355note a waiting job is one more change (165).
3356fn pt_rescores to void
3357buf = new uchar 4096 0
3358c = pt_setup 1 8 8 pt_req 4 1024 1 8 160
3359pt_ok eq sched_policy 2 64 64 4 1000 0 160
3360k = sched_pause c true
3361r = pt_admit 320050 0 pt_req 1 0 0 0 160
3362w1 = pt_admit 330050 512 pt_req 1 0 0 0 160
3363w2 = pt_admit 340050 512 pt_req 1 0 0 0 160
3364pt_ok eq sched_goal r 512 50 10 0 160
3365pt_ok eq sched_stat 34 4 160
3366pt_ok eq sched_stat 32 0 160
3367pt_resume c
3368pt_ok eq sched_stat 32 1 161
3369pt_ok eq get sjval r 2 161
3370pt_drain c 1 2000 162
3371pt_ok eq sched_stat 32 1 162
3372pt_ok eq sched_stat 34 4 162
3373pt_snap
3374pt_ok gt sched_publish c 512 buf 16 0 163
3375pt_check
3376pt_ok eq sched_stat 34 6 163
3377pt_ok eq sched_stat 32 2 163
3378pt_drain c 2 2000 164
3379pt_ok eq sched_stat 32 2 165
3380w3 = pt_admit 345050 4096 pt_req 1 0 0 0 165
3381b0 = sched_stat 34
3382pt_ok eq sched_cancel w3 1 165
3383pt_ok eq sched_stat 34 add b0 1 165
3384pt_down c 166
3385end
3386
3387note Phase K: the policy-2 key on two free slots, a and b. Larger unblock
3388note value first, even when b is older and cheaper (180); equal values:
3389note smaller estimate first, even when b is older (181); equal values and
3390note estimates: older admission first (182); outside policy 2 only the
3391note admission age counts (183).
3392fn pt_key to void
3393a = ulong 60
3394b = ulong 61
3395put sjval a 2
3396put sjval b 1
3397put sjest a 90
3398put sjest b 10
3399put sjarr a 9
3400put sjarr b 8
3401pt_ok sp_better true a b 180
3402pt_ok not sp_better true b a 180
3403put sjval b 2
3404put sjest a 10
3405put sjest b 90
3406pt_ok sp_better true a b 181
3407pt_ok not sp_better true b a 181
3408put sjest b 10
3409pt_ok sp_better true b a 182
3410pt_ok not sp_better true a b 182
3411put sjval a 5
3412put sjest b 1
3413pt_ok sp_better false b a 183
3414pt_ok not sp_better false a b 183
3415for i ulong 2
3416put sjval add a i 0
3417put sjest add a i 0
3418put sjarr add a i 0
3419end
3420end
3421
3422note Phase P: proposals. Policy 2, paused. p1 (value 0) and p2 (value 1)
3423note are ready. A proposal naming an older graph version is refused (170)
3424note and counted (171); one naming an id with no ready job is refused
3425note (172); p1 at the current version is accepted (173) and used over the
3426note higher ranked p2 (174). A proposal made stale by a later change is
3427note rejected when next used and counted: p3 runs by rank, after p2 (175,
3428note 176). Outside policy 2: -7 (177).
3429fn pt_proposals to void
3430c = pt_setup 1 8 8 pt_req 4 1024 1 8 170
3431pt_ok eq sched_incarnate 1 0 170
3432pt_ok eq sched_policy 2 64 64 4 1000 0 170
3433k = sched_pause c true
3434p1 = pt_admit 350050 0 pt_req 1 0 0 0 170
3435p2 = pt_admit 360050 0 pt_req 1 0 0 0 170
3436q = pt_admit 370050 1024 pt_req 1 0 0 0 170
3437pt_ok eq sched_goal p2 1024 50 10 0 170
3438v = sched_version
3439p3 = pt_admit 380050 0 pt_req 1 0 0 0 170
3440pt_ok eq sched_propose 350050 v neg long 9 170
3441pt_ok eq sched_stat 36 1 171
3442v = sched_version
3443pt_ok eq sched_propose 999999 v neg long 3 172
3444pt_ok eq sched_propose 350050 v 0 173
3445pt_resume c
3446pt_ok eq get sjst p1 3 174
3447pt_ok eq sched_stat 39 1 174
3448k = sched_pause c true
3449v = sched_version
3450pt_ok eq sched_propose 380050 v 0 175
3451p4 = pt_admit 390050 2048 pt_req 1 0 0 0 175
3452pt_ok eq sched_goal p3 0 10 1 0 175
3453pt_resume c
3454pt_ok pt_until c p2 3 4 2000 175 175
3455pt_ok eq get sjst p3 2 176
3456pt_ok eq sched_stat 39 1 176
3457pt_ok eq sched_stat 36 2 176
3458pt_ok eq sched_cancel p4 1 176
3459pt_ok eq sched_cancel q 1 176
3460pt_drain c 3 3000 176
3461pt_ok eq sched_policy 1 64 64 4 1000 0 177
3462pt_ok eq sched_propose 350050 sched_version neg long 7 177
3463pt_down c 178
3464end
3465
3466note Phase I: a proposal from an earlier scheduler. Scheduler 1
3467note (incarnation 1) admits a into slot 0 and hands out the version;
3468note scheduler 2 (incarnation 2) admits b into slot 0 with as many bumps.
3469note There the old version is stale (184); a's id names no job even at the
3470note current version, b's is accepted, and incarnation 0 is refused (185).
3471fn pt_incarn to void
3472c = pt_setup 1 8 8 pt_req 4 1024 1 8 184
3473pt_ok eq sched_incarnate 1 0 184
3474pt_ok eq sched_policy 2 64 64 4 1000 0 184
3475k = sched_pause c true
3476a = pt_admit 670050 0 pt_req 1 0 0 0 184
3477pt_ok eq a 0 184
3478v1 = sched_version
3479pt_ok eq sched_cancel a 1 184
3480pt_down c 184
3481c = pt_setup 1 8 8 pt_req 4 1024 1 8 184
3482pt_ok eq sched_incarnate 2 0 184
3483pt_ok eq sched_policy 2 64 64 4 1000 0 184
3484k = sched_pause c true
3485b = pt_admit 680050 0 pt_req 1 0 0 0 184
3486pt_ok eq b 0 184
3487pt_ok eq sched_propose 670050 v1 neg long 9 184
3488pt_ok eq sched_propose 670050 sched_version neg long 3 185
3489pt_ok eq sched_propose 680050 sched_version 0 185
3490pt_ok eq sched_incarnate 0 neg long 7 185
3491pt_ok eq sched_cancel b 1 185
3492pt_down c 185
3493end
3494
3495note Phase R2: a proposal beside a reservation. Policy 2, bypass budget 1,
3496note two workers, 5 CPU. h (2 CPU, 5 s) runs; then B and B2 (4 CPU each)
3497note and s1 (1 CPU, 1.5 s) are admitted: s1 runs, B and B2 are bypassed and
3498note B, the older, is reserved. x (2 CPU) is refused beside it and counted
3499note (186). Cancelling B clears the reservation and x is accepted (187).
3500note An event with no idle worker reserves B2 and leaves the proposal
3501note pending (188). Once s1 is done, the next pick finds x no longer fits
3502note beside B2: the proposal is dropped and counted stale, and x does not
3503note run (189). Once h is done B2 fits; y (1 CPU) is accepted beside it,
3504note and at the next event B2 runs first, then y is used; x (2 CPU, 0
3505note left) stays ready and, bypassed by y, is now the reservation (179).
3506fn pt_propres to void
3507c = pt_setup 2 8 8 pt_req 5 1024 2 8 186
3508pt_ok eq sched_incarnate 1 0 186
3509pt_ok eq sched_policy 2 64 64 1 1000 0 186
3510k = sched_pause c true
3511h = pt_admit 625000 0 pt_req 2 0 0 0 186
3512pt_resume c
3513k = sched_pause c true
3514pt_ok eq get sjst h 3 186
3515b = pt_admit 630050 0 pt_req 4 0 0 0 186
3516b2 = pt_admit 640050 0 pt_req 4 0 0 0 186
3517s1 = pt_admit 651500 0 pt_req 1 0 0 0 186
3518pt_resume c
3519k = sched_pause c true
3520pt_ok eq get sjst s1 3 186
3521pt_ok eq sched_stat 29 add b 1 186
3522x = pt_admit 660050 0 pt_req 2 0 0 0 186
3523r0 = sched_stat 37
3524pt_ok eq sched_propose 660050 sched_version neg long 8 186
3525pt_ok eq sched_stat 37 add r0 1 186
3526pt_ok eq sched_cancel b 1 187
3527pt_ok eq sched_stat 29 0 187
3528pt_ok eq sched_propose 660050 sched_version 0 187
3529pt_resume c
3530k = sched_pause c true
3531pt_ok eq sched_stat 29 add b2 1 188
3532pt_ok gt get scgv 2 0 188
3533pt_ok pt_until c s1 4 4 3000 188 188
3534s0 = sched_stat 36
3535pt_resume c
3536k = sched_pause c true
3537pt_ok eq sched_stat 36 add s0 1 189
3538pt_ok eq get sjst x 2 189
3539pt_ok eq get scgv 2 0 189
3540y = pt_admit 690050 0 pt_req 1 0 0 0 179
3541pt_ok pt_until c h 4 4 6000 179 179
3542pt_ok eq sched_propose 690050 sched_version 0 179
3543s0 = sched_stat 39
3544pt_resume c
3545k = sched_pause c true
3546pt_ok eq get sjst b2 3 179
3547pt_ok eq get sjst y 3 179
3548pt_ok eq sched_stat 39 add s0 1 179
3549pt_ok eq sched_stat 29 add x 1 179
3550pt_ok eq get sjst x 2 179
3551pt_ok eq sched_cancel x 1 179
3552pt_drain c 4 8000 179
3553pt_down c 189
3554end
3555
3556fn pt_stats to void
3557r = write 1 pst 0 len pst
3558pt_num sched_stat 2
3559r = write 1 pex 0 len pex
3560pt_num sched_stat 3
3561r = write 1 pas 0 len pas
3562pt_num sched_stat 4
3563r = write 1 phol 0 len phol
3564pt_num sched_stat 8
3565r = write 1 pbyp 0 len pbyp
3566pt_num sched_stat 5
3567r = write 1 pres 0 len pres
3568pt_num sched_stat 6
3569r = write 1 pnl 0 1
3570end
3571
3572note Phase X: proposal guards. Without an incarnation a proposal is refused
3573note (120); a second incarnation is refused (121); after the first one a
3574note proposal is accepted and used (122). The version is then set to the
3575note last revision of incarnation 5 (2^40 - 1 bumps): a proposal made there
3576note is accepted, and the next bump exhausts the version instead of
3577note carrying it into incarnation 6's range (123); proposals are refused
3578note (124), the pending one is dropped at use (125) and every pick rescores
3579note (126). In a new scheduler, two ready jobs share an id: a proposal
3580note naming it is refused (127).
3581fn pt_incx to void
3582c = pt_setup 1 8 8 pt_req 4 1024 1 8 120
3583pt_ok eq sched_policy 2 64 64 4 1000 0 120
3584k = sched_pause c true
3585a = pt_admit 710050 0 pt_req 1 0 0 0 120
3586pt_ok eq sched_propose 710050 sched_version neg long 6 120
3587pt_ok eq sched_stat 41 0 120
3588pt_ok eq sched_incarnate 5 0 121
3589pt_ok eq sched_incarnate 6 neg long 7 121
3590pt_ok eq sched_propose 710050 sched_version 0 122
3591pt_ok eq sp_proposal 0 a 122
3592put scgv 0 add shl ulong 5 40 1099511627775
3593v = sched_version
3594pt_ok eq sched_propose 710050 v 0 123
3595pt_ok eq sched_goal a 0 10 1 0 123
3596pt_ok eq sched_version v 123
3597pt_ok eq shr sched_version 40 5 123
3598pt_ok eq sched_stat 41 2 123
3599pt_ok eq sched_propose 710050 v neg long 6 124
3600pt_ok eq sp_proposal 0 64 125
3601r0 = sched_stat 32
3602sp_rescore
3603sp_rescore
3604pt_ok eq sched_stat 32 add r0 2 126
3605pt_ok eq sched_cancel a 1 126
3606pt_down c 126
3607c = pt_setup 1 8 8 pt_req 4 1024 1 8 127
3608pt_ok eq sched_incarnate 7 0 127
3609pt_ok eq sched_policy 2 64 64 4 1000 0 127
3610k = sched_pause c true
3611b1 = pt_admit 720050 0 pt_req 1 0 0 0 127
3612b2 = pt_admit 720050 0 pt_req 1 0 0 0 127
3613pt_ok ne b1 b2 127
3614pt_ok eq sched_propose 720050 sched_version neg long 3 127
3615pt_ok eq sched_cancel b1 1 127
3616pt_ok eq sched_cancel b2 1 127
3617pt_down c 127
3618end
3619
3620note Phase L: a late first incarnation must not mark stale values current.
3621note Paused, one worker, policy 2: an older unrelated job u, a younger
3622note producer p declaring topic 64 and a job d waiting on it are admitted
3623note and declared, then the scheduler incarnates. At resume the one pick
3624note rescores and takes p (value 1); with the values left unscored they all
3625note read 0 and u (older, no estimate) would run instead (128).
3626fn pt_incl to void
3627c = pt_setup 1 8 8 pt_req 4 1024 1 8 128
3628pt_ok eq sched_policy 2 64 64 4 1000 0 128
3629k = sched_pause c true
3630u = pt_admit 730300 0 pt_req 1 0 0 0 128
3631p = pt_admit 740300 0 pt_req 1 0 0 0 128
3632d = pt_admit 750300 64 pt_req 1 0 0 0 128
3633pt_ok eq sched_goal p 64 300 0 0 128
3634pt_ok eq sched_incarnate 8 0 128
3635pt_resume c
3636pt_ok eq get sjst p 3 128
3637pt_ok eq get sjst u 2 128
3638pt_ok eq sched_cancel u 1 128
3639pt_ok eq sched_cancel d 1 128
3640pt_drain c 1 3000 128
3641pt_down c 128
3642end
3643
3644note The regression phases A and B return their verdict, so both run and
3645note print their witness; the first failing one is the exit status.
3646fn main to int
3647pt_mode
3648pt_impossible
3649pt_churn
3650pt_release
3651pt_order
3652ra = pt_blocked
3653rb = pt_exclude
3654if ne ra 0
3655ret ra
3656end
3657if ne rb 0
3658ret rb
3659end
3660pt_starve
3661pt_tickets
3662pt_lease
3663pt_rcancel
3664pt_window
3665pt_torder
3666pt_slots
3667pt_live
3668pt_goal
3669pt_rescores
3670pt_proposals
3671pt_incarn
3672pt_propres
3673pt_incx
3674pt_incl
3675pt_key
3676pt_lbound
3677pt_renew
3678pt_budget
3679if ne write 1 pok 0 len pok long len pok
3680ret 100
3681end
3682ret 0
3683end