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 / sched-test.om

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