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

595 lines · 12000 bytes Raw Blame History
1note Omega Node scheduling comparison (DRA-399). Concatenate after
2note transport.om, pool.om, super.om and sched.om. Runs pinned workloads
3note under arm 0 (FIFO), 1 (fair fitting), 2 (goal-aware, declared estimates
4note within a factor of 2 of the duration) and 3 (goal-aware given the true
5note durations: ORACLE, an upper bound, not a policy result) with real
6note forked workers that sleep for the milliseconds in the low four decimal
7note digits of their job id, on the host's wall clock. Usage: bench-gate
8note (five repetitions of every scenario and arm). Prints one line per run:
9note bench S P R mk_us idle_us dsp_ns dsp_n ev cand maint vread rework res cont ok hwm_kb : waits_us...
10note S scenario 1..6 (blocked head, long chain, fan-out, sustained arrivals,
11note queue pressure, worker failure), P arm (0..3), R repetition; mk makespan
12note (first admission to last review); idle the integral of min(idle live
13note workers, ready jobs that fit the free capacity) over time, in
14note worker-microseconds; dsp time inside sched_dispatch from the creator
15note loop and its calls; ev, cand, maint, vread the scheduler's counters
16note (events, candidate reads, maintenance reads, value reads); rework the
17note jobs that went back to ready after starting; res the reservations made
18note (sched_stat 6); cont the new reservations seen while another ready job
19note was also at the bypass budget (where check 71 can tell oldest from any);
20note ok the jobs reviewed with
21note the expected outcome; hwm_kb the creator's VmHWM; waits from ready to
22note started, per job, in microseconds (sampled after every creator step
23note and every publication). Every policy sees the same jobs, requests,
24note durations, declarations, workers and capacities. Checked in every run:
25note the capacity invariant (exit 70), a new reservation goes to the oldest
26note ready job at the bypass budget (71), every job is reviewed once with
27note its expected outcome before the deadline (72), setup (73..79).
28text bnok "PASS node bench\n"
29text bnhd "bench "
30text bnsp " "
31text bnco " :"
32text bnnl "\n"
33text bnst "/proc/self/status"
34text bnhw "VmHWM:"
35global bnc long 1
36note Run metrics: 0 t0, 1 last review, 2 idle sum ns, 3 last sample, 4
37note dispatch ns, 5 dispatch calls, 6 reviewed, 7 verified, 8 reworks, 9
38note jobs in the scenario, 10 next queue entry, 11 killed, 12 reservation
39note last seen + 1, 13 idle-eligible workers at the last sample, 14 policy,
40note 15 bypass budget, 16 contested reservations.
41global bnm ulong 20
42note Per slot: ready since (ns, 0 not ready), started flag.
43global bnr ulong 64
44global bns ulong 64
45note Waits of this run (us) and their count.
46global bnwt ulong 256
47global bnwn ulong 1
48note Scenario queue: id, deps, request, flags, arrival ms, topics published.
49global bnqi ulong 64
50global bnqd ulong 64
51global bnqr ulong 64
52global bnqf ulong 64
53global bnqt ulong 64
54global bnqp ulong 64
55global bnqn ulong 1
56note 1: arm 3, policy 2 given the true durations as estimates (ORACLE).
57global bne ulong 1
58
59fn bn_ok ok bool code int to void
60if not ok
61exit code
62end
63end
64
65fn bn_num v ulong to void
66d = new uchar 20 0
67x = v
68k = ulong 20
69for i ulong 20
70k = sub k 1
71put d k uchar add rem x 10 48
72x = div x 10
73if eq x 0
74break
75end
76end
77r = write 1 d k sub 20 k
78end
79
80fn bn_sp v ulong to void
81r = write 1 bnsp 0 1
82bn_num v
83end
84
85fn bn_req cpu ulong to ulong
86ret cpu
87end
88
89fn bn_run c long w ulong q ulong to int
90buf = new uchar 4096 0
91id = sc_cell w 8
92dl = add ulong monons mul rem id 10000 1000000
93for t ulong 1000000
94now = ulong monons
95if ge now dl
96break
97end
98r = sched_wwait c w long sub dl now
99if eq r 2
100ret 2
101end
102if eq r 3
103ret 3
104end
105if lt r 0
106ret 4
107end
108end
109if ne sched_wdone w q add id 1 buf 8 0
110ret 5
111end
112ret 0
113end
114
115fn bn_worker w ulong to int
116c = get bnc 0
117for it ulong 1000000000
118q = sched_wjob w
119if gt q 0
120r = bn_run c w q
121if eq r 2
122ret 0
123end
124if ne r 0
125ret add 60 r
126end
127continue
128end
129r = sched_wwait c w neg long 1
130if eq r 2
131ret 0
132end
133if eq r 3
134ret 41
135end
136if lt r 0
137ret 43
138end
139end
140ret 45
141end
142
143note Queue entry: job id (duration in its low four digits), deps, CPU,
144note flags, arrival ms after the start, topics its completion publishes.
145fn bn_q id ulong deps ulong cpu ulong fl ulong at ulong pro ulong to void
146n = get bnqn 0
147put bnqi n id
148put bnqd n deps
149put bnqr n cpu
150put bnqf n fl
151put bnqt n at
152put bnqp n pro
153put bnqn 0 add n 1
154end
155
156note Declared work estimate of job id in ms. Policy 2 is not told the
157note duration: the estimate is the duration times 1/2, 1, 3/2 or 2, chosen
158note by a multiplicative hash of the id (fixed, so every run and repetition
159note declares the same values). Arm 3 (ORACLE) declares the true duration.
160fn bn_est id ulong to ulong
161d = rem id 10000
162if ne get bne 0 0
163ret d
164end
165k = rem div mul id 2654435761 65536 4
166ret div mul d add k 1 2
167end
168
169note Scenario s into the queue; returns (workers, admission limit).
170fn bn_load s ulong to ulong
171put bnqn 0 0
172if eq s 1
173bn_q 10600 0 2 0 0 0
174bn_q 20300 0 4 0 0 0
175for i ulong 6
176bn_q add 30200 mul i 10000 0 1 0 0 0
177end
178ret 64
179end
180if eq s 2
181for i ulong 8
182bn_q add 100300 mul i 10000 0 1 0 0 0
183end
184bn_q 200150 0 1 0 0 2
185for i ulong 5
186bn_q add 210150 mul i 10000 shl ulong 2 i 1 0 0 shl ulong 4 i
187end
188ret 64
189end
190if eq s 3
191for i ulong 6
192bn_q add 300300 mul i 10000 0 1 0 0 0
193end
194bn_q 400100 0 1 0 0 1024
195for i ulong 6
196bn_q add 410200 mul i 10000 1024 1 0 0 0
197end
198ret 64
199end
200if eq s 4
201bn_s4
202ret 64
203end
204if eq s 5
205bn_s5
206ret 8
207end
208bn_s6
209ret 64
210end
211
212note Sustained arrivals: 24 jobs of 100..400 ms needing 1..3 CPU, four
213note every 150 ms.
214fn bn_s4 to void
215for i ulong 24
216d = add 100 mul rem mul i 7 4 100
217id = add add 500000 mul i 10000 d
218at = mul div i 4 150
219bn_q id 0 add 1 rem i 3 0 at 0
220end
221end
222
223note Queue pressure: 30 jobs of 100..300 ms needing 1..2 CPU offered at
224note once against an admission limit of 8.
225fn bn_s5 to void
226for i ulong 30
227d = add 100 mul rem mul i 5 3 100
228id = add add 600000 mul i 10000 d
229bn_q id 0 add 1 rem i 2 0 0 0
230end
231end
232
233note Worker failure: 12 rerunnable jobs of 150..450 ms needing 1..3 CPU;
234note worker 0 is killed 250 ms in while busy.
235fn bn_s6 to void
236for i ulong 12
237d = add 150 mul rem mul i 7 4 100
238id = add add 700000 mul i 10000 d
239bn_q id 0 add 1 rem i 3 1 0 0
240end
241end
242
243note Admit the queue entries that have arrived, in order; a refusal for
244note room (-2, a ticket) stops until the next call.
245fn bn_admit now ulong to void
246for k ulong 64
247i = get bnm 10
248if ge i get bnqn 0
249ret
250end
251if lt sub now get bnm 0 mul get bnqt i 1000000
252ret
253end
254j = sched_admitr get bnqi i get bnqd i get bnqf i bn_req get bnqr i
255if eq j neg long 2
256ret
257end
258bn_ok ge j 0 74
259e = bn_est get bnqi i
260r = sched_goal ulong j get bnqp i e e
261put bnm 10 add i 1
262end
263end
264
265note Topics job id publishes on completion.
266fn bn_pro id ulong to ulong
267for i ulong get bnqn 0 bound 64
268if eq get bnqi i id
269ret get bnqp i
270end
271end
272ret 0
273end
274
275fn bn_inv to void
276for k ulong 4
277s = ulong 0
278for j ulong 64
279if eq get sjheld j 1
280s = add s sp_need get sjneed j k
281end
282end
283bn_ok eq get suse k s 70
284bn_ok le get suse k get scap k 70
285end
286end
287
288note A reservation that appeared since the last sample goes to the oldest
289note ready job at the bypass budget: no older ready job is at the budget.
290note Another ready job at the budget makes it contested (bnm 16).
291fn bn_fair to void
292r = sched_stat 29
293if or eq r 0 eq r get bnm 12
294put bnm 12 r
295ret
296end
297put bnm 12 r
298a = get sjarr sub r 1
299n = ulong 0
300for j ulong 64
301if and eq get sjst j 2 ne j sub r 1
302if ge get sjbyp j get bnm 15
303n = add n 1
304end
305if lt get sjarr j a
306bn_ok lt get sjbyp j get bnm 15 71
307end
308end
309end
310if gt n 0
311put bnm 16 add get bnm 16 1
312end
313end
314
315note Sample after a creator step or publication: waits, reworks, the idle
316note eligible integral, the invariants.
317fn bn_sample to void
318now = ulong monons
319put bnm 2 add get bnm 2 mul get bnm 13 sub now get bnm 3
320put bnm 3 now
321nf = ulong 0
322for j ulong 64
323s = get sjst j
324if eq s 2
325if ne get bns j 0
326put bns j 0
327put bnm 8 add get bnm 8 1
328end
329if eq get bnr j 0
330put bnr j now
331end
332if sp_fits get sjneed j 0
333nf = add nf 1
334end
335end
336if and ge s 3 ne get bnr j 0
337bn_wait sub now get bnr j
338put bnr j 0
339put bns j 1
340end
341end
342put bnm 13 bn_min nf bn_idle
343bn_inv
344if ge get bnm 14 1
345bn_fair
346end
347end
348
349fn bn_wait ns ulong to void
350n = get bnwn 0
351if lt n 256
352put bnwt n div ns 1000
353put bnwn 0 add n 1
354end
355end
356
357fn bn_min a ulong b ulong to ulong
358if lt a b
359ret a
360end
361ret b
362end
363
364fn bn_idle to ulong
365c = get bnc 0
366n = mapget c 48 8
367k = ulong 0
368for w ulong n bound 64
369if and gt get swpid w 0 eq get scbusy w 0
370k = add k 1
371end
372end
373ret k
374end
375
376note sched_step with the dispatch timed.
377fn bn_step c long to void
378d = sup_poll c 1000000
379bn_ok ge d 0 75
380n = mapget c 48 8
381for w ulong n bound 64
382if gt get swpid w 0
383r = sup_take get swack w
384else
385r = sched_lost c w
386end
387end
388k = sched_collect c
389t = ulong monons
390k = sched_dispatch c
391put bnm 4 add get bnm 4 sub ulong monons t
392put bnm 5 add get bnm 5 1
393end
394
395note Review finished jobs (outcome id + 1 is verified work); publish what
396note each declared.
397fn bn_review c long to void
398buf = new uchar 4096 0
399for j ulong 64
400if eq get sjst j 4
401id = get sjid j
402o = sched_review j
403if eq o long add id 1
404put bnm 7 add get bnm 7 1
405end
406put bnm 6 add get bnm 6 1
407put bnm 1 ulong monons
408put bns j 0
409put bnr j 0
410p = bn_pro id
411if ne p 0
412v = sched_publish c p buf 8
413bn_ok gt v 0 76
414bn_sample
415end
416end
417end
418end
419
420fn bn_hwm to ulong
421b = new uchar 4096 0
422fd = fopen bnst 0 len bnst 0 0
423if lt fd 0
424ret 0
425end
426r = pread int fd b 0 4096 long 0
427x = fclose int fd
428if le r 0
429ret 0
430end
431n = ulong r
432h = len bnhw
433for i ulong 4000
434if gt add i h n
435ret 0
436end
437m = true
438for k ulong h bound 8
439if ne get b add i k get bnhw k
440m = false
441end
442end
443if m
444ret bn_digits b add i h n
445end
446end
447ret 0
448end
449
450fn bn_digits b view uchar 4096 i ulong n ulong to ulong
451v = ulong 0
452for k ulong 32
453p = add i k
454if ge p n
455ret v
456end
457ch = get b p
458if and ge ch 48 le ch 57
459v = add mul v 10 sub ulong ch 48
460else
461if gt v 0
462ret v
463end
464end
465end
466ret v
467end
468
469fn bn_reset pol ulong by ulong to void
470for i ulong 20
471put bnm i 0
472end
473for j ulong 64
474put bnr j 0
475put bns j 0
476end
477put bnwn 0 0
478put bnm 14 pol
479put bnm 15 by
480end
481
482note One run of scenario s under arm a (policy 0, 1, 2; arm 3 is policy 2
483note with ORACLE estimates); prints its line.
484fn bn_one s ulong a ulong rep ulong to void
485pol = a
486put bne 0 0
487if eq a 3
488pol = 2
489put bne 0 1
490end
491lim = bn_load s
492c = pool_new 4 2
493bn_ok gt c 0 73
494put bnc 0 c
495bn_ok eq sup_init c 0 73
496bn_ok eq sched_new c lim 64 0 73
497bn_ok eq sched_cap bn_req 4 0 73
498bn_ok eq sched_policy pol 64 64 4 1000 0 73
499bn_reset a 4
500put bnm 9 get bnqn 0
501for w ulong 2
502p = sup_spawn c w
503if eq p 0
504exit bn_worker w
505end
506bn_ok gt p 0 73
507end
508k = sched_pause c true
509put bnm 0 ulong monons
510put bnm 3 get bnm 0
511bn_admit get bnm 0
512bn_sample
513k = sched_pause c false
514bn_loop c s
515bn_ok eq get bnm 6 get bnm 9 72
516bn_ok eq get bnm 7 get bnm 9 72
517bn_print s a rep
518bn_ok ge sched_stop c 2000000000 0 77
519sup_closeall
520bn_ok eq sched_free 0 77
521bn_ok eq pool_free c 0 77
522end
523
524fn bn_loop c long s ulong to void
525dl = add ulong monons 20000000000
526for t ulong 100000000
527bn_sample
528if ge get bnm 6 get bnm 9
529ret
530end
531bn_ok lt ulong monons dl 72
532if and eq s 6 eq get bnm 11 0
533if ge sub ulong monons get bnm 0 250000000
534bn_kill c
535end
536end
537bn_admit ulong monons
538bn_step c
539bn_sample
540bn_review c
541end
542end
543
544note Scenario 6: SIGKILL the busy worker 0 once.
545fn bn_kill c long to void
546if eq get scbusy 0 0
547ret
548end
549r = killpid int get swpid 0 9
550put bnm 11 1
551end
552
553fn bn_print s ulong pol ulong rep ulong to void
554r = write 1 bnhd 0 len bnhd
555bn_num s
556bn_sp pol
557bn_sp rep
558bn_sp div sub get bnm 1 get bnm 0 1000
559bn_sp div get bnm 2 1000
560bn_sp get bnm 4
561bn_sp get bnm 5
562bn_sp sched_stat 2
563bn_sp sched_stat 3
564bn_sp sched_stat 13
565bn_sp sched_stat 38
566bn_sp get bnm 8
567bn_sp sched_stat 6
568bn_sp get bnm 16
569bn_sp get bnm 7
570bn_sp bn_hwm
571r = write 1 bnco 0 len bnco
572for i ulong get bnwn 0 bound 256
573bn_sp get bnwt i
574end
575r = write 1 bnnl 0 1
576end
577
578fn bn_reps to ulong
579ret 5
580end
581
582fn main to int
583n = bn_reps
584for rep ulong n bound 100
585for s ulong 6
586for pol ulong 4
587bn_one add s 1 pol rep
588end
589end
590end
591if ne write 1 bnok 0 len bnok long len bnok
592ret 100
593end
594ret 0
595end