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

527 lines · 10503 bytes Raw Blame History
1note Concatenate after transport.om, pool.om and super.om. CPU-only acceptance
2note of epoch turnover, held old versions, worker death, respawn, orphaning and
3note bounded teardown with real forked processes. No GPU, model or network.
4text pok "PASS node pool\n"
5global ptc long 1
6global ptm long 1
7global pth long 1
8global ptws uchar 4
9
10fn pt_ok ok bool code int to void
11if not ok
12exit code
13end
14end
15
16fn pt_fd4 p view uchar 8 off ulong to int
17v = ulong get p off
18v = or v shl ulong get p add off 1 8
19v = or v shl ulong get p add off 2 16
20v = or v shl ulong get p add off 3 24
21ret int v
22end
23
24fn pt_byte e ulong v ulong to uchar
25ret uchar and add mul e 16 v 255
26end
27
28note Creator: publish n full records into the current epoch, bytes f(epoch, v).
29fn pt_fill c long n ulong to bool
30buf = new uchar 4096 0
31e = pool_epoch c
32h = pool_current c
33if lt h 0
34ret false
35end
36for k ulong n bound 64
37v = add mapget h 16 8 1
38b = pt_byte e v
39for j ulong 4096
40put buf j b
41end
42if ne pool_publish c 1 buf 4096 long v
43ret false
44end
45end
46ret true
47end
48
49note 0 when arena h holds exactly n complete records of its own epoch, else a code.
50fn pt_verify h long n ulong to int
51buf = new uchar 4096 0
52e = node_epoch h
53cur = ulong 0
54cnt = ulong 0
55for k ulong 65
56v = node_next h cur 1
57if eq v 0
58break
59end
60if lt v 0
61ret 1
62end
63cur = ulong v
64if ne node_read h cur buf 4096
65ret 2
66end
67b = pt_byte e cur
68for j ulong 4096
69if ne get buf j b
70ret 3
71end
72end
73cnt = add cnt 1
74end
75if ne cnt n
76ret 4
77end
78ret 0
79end
80
81fn pt_refusals to void
82pt_ok eq pool_new 0 4 neg long 7 10
83pt_ok eq pool_new 9 4 neg long 7 11
84pt_ok eq pool_new 2 0 neg long 7 12
85pt_ok eq pool_new 2 65 neg long 7 13
86c = pool_new 2 4
87pt_ok gt c 0 14
88pt_ok eq pool_epoch c 1 15
89pt_ok eq pool_acquire c 4 neg long 7 16
90pt_ok eq pool_release c 4 neg long 7 17
91pt_ok eq node_epoch pool_current c 1 18
92pt_ok eq node_reset pool_current c 0 neg long 7 19
93pt_ok eq pool_free c 0 20
94end
95
96note One process: the creator also plays worker slots 0 and 1, whose holds are
97note plain words. Epoch numbers never repeat; arenas are reused only unheld.
98fn pt_epochs to void
99dst = new uchar 4096 0
100c = pool_new 2 4
101pt_ok gt c 0 21
102pt_ok pt_fill c 1 22
103h1 = pool_acquire c 0
104pt_ok eq h1 pool_current c 23
105pt_ok eq mapget c 256 8 1 24
106pt_ok eq pool_roll c 2 25
107pt_ok ne pool_current c h1 26
108pt_ok eq node_next pool_current c 0 1 0 27
109pt_ok eq pool_roll c neg long 9 28
110pt_ok eq pool_epoch c 2 29
111pt_ok eq pt_verify h1 1 0 30
112pt_ok eq pool_release c 0 0 31
113pt_ok eq pool_roll c 3 32
114pt_ok eq pool_slot c 3 0 33
115pt_ok eq node_read h1 1 dst neg long 7 34
116pt_ok eq node_epoch h1 3 35
117pt_ok pt_fill c 64 36
118for j ulong 4096
119put dst j pt_byte 4 1
120end
121pt_ok eq pool_publish c 1 dst 4096 1 37
122pt_ok eq pool_epoch c 4 38
123h4 = pool_acquire c 1
124pt_ok eq node_epoch h4 4 39
125pt_ok pt_fill c 63 40
126pt_ok eq pool_epoch c 4 41
127pt_ok eq pool_roll c 5 42
128pt_ok pt_fill c 64 43
129pt_ok eq pool_publish c 1 dst 1 neg long 9 44
130pt_ok eq pool_epoch c 5 45
131pt_ok eq pt_verify h4 64 0 46
132pt_ok eq pool_stop c 0 47
133pt_ok eq pool_roll c neg long 1 48
134pt_ok eq pool_acquire c 2 neg long 1 49
135pt_ok eq mapget c 272 8 0 50
136pt_ok eq pool_free c 0 51
137end
138
139note The announce race, made deterministic by running the protocol steps in
140note the order that breaks a hold without its recheck: worker 2 read epoch e,
141note the creator moved past e and picked e's arena, then worker 2 stores its
142note hold. The recheck must refuse; reuse of the arena must then proceed.
143fn pt_race to void
144c = pool_new 2 4
145pt_ok gt c 0 140
146pt_ok pt_fill c 1 141
147e = pool_epoch c
148pt_ok eq pool_roll c 2 142
149pt_ok eq pool_pick c 0 143
150pt_ok eq pool_hold c 2 e neg long 8 144
151pt_ok eq mapget c 272 8 0 145
152pt_ok eq pool_reuse c 0 3 3 146
153pt_ok eq pool_acquire c 2 pool_current c 147
154pt_ok eq pool_hold c 4 3 neg long 7 148
155pt_ok eq pool_free c 0 149
156end
157
158note Worker phase: 1 acquire and verify, 2 verify the held epoch again,
159note 3 release, acquire the current epoch and verify, 4 stall ignoring stop.
160fn pt_step c long w ulong ph ulong to int
161buf = new uchar 4096 0
162m = get ptm 0
163n = mapget m 8 8
164if eq ph 1
165if ne pool_roll c neg long 6
166ret 11
167end
168if ne pool_stop c neg long 6
169ret 12
170end
171if ne pool_clear c w neg long 6
172ret 13
173end
174h = pool_acquire c w
175if le h 0
176ret 14
177end
178put pth 0 h
179if ne node_publish h 1 buf 1 neg long 6
180ret 15
181end
182ret pt_verify h n
183end
184if eq ph 2
185ret pt_verify get pth 0 mapget m 16 8
186end
187if eq ph 3
188r = pool_release c w
189h = pool_acquire c w
190if le h 0
191ret 16
192end
193put pth 0 h
194ret pt_verify h n
195end
196if eq ph 4
197r = sleepns 30000000000
198ret 17
199end
200ret 18
201end
202
203fn pt_worker w ulong to int
204c = get ptc 0
205m = get ptm 0
206put pth 0 0
207for it ulong 64
208r = sup_wwait c w 5000000000
209if eq r 2
210if gt get pth 0 0
211r = pool_release c w
212end
213ret 0
214end
215if eq r 3
216ret 41
217end
218if eq r 0
219ret 42
220end
221if ne r 1
222ret 43
223end
224res = pt_step c w mapget m 0 8
225r = mapset m add 64 mul w 8 8 ulong res
226if ne sup_ack w 0
227ret 44
228end
229end
230ret 45
231end
232
233note Creator: wake worker w for phase ph and wait up to about 5 s for its ack.
234note Returns the worker's phase result, or 90 no ack, 91 the worker died.
235fn pt_phase c long w ulong ph ulong to int
236m = get ptm 0
237r = mapset m 0 8 ph
238r = mapset m add 64 mul w 8 8 99
239if ne sup_wake w 0
240ret 92
241end
242for t ulong 500
243if gt sup_take get swack w 0
244ret int mapget m add 64 mul w 8 8
245end
246if le get swpid w 0
247ret 91
248end
249r = sup_poll c 10000000
250end
251ret 90
252end
253
254fn pt_spawn c long w ulong to bool
255p = sup_spawn c w
256if eq p 0
257exit pt_worker w
258end
259ret gt p 0
260end
261
262fn pt_procs to void
263c = pool_new 2 4
264pt_ok gt c 0 52
265put ptc 0 c
266m = mapnew neg int 1 0 4096 3 33
267pt_ok gt m 0 53
268put ptm 0 m
269pt_ok eq sup_init c 0 54
270pt_ok pt_fill c 8 55
271r = mapset m 8 8 8
272r = mapset m 16 8 8
273pt_ok pt_spawn c 0 56
274pt_ok pt_spawn c 1 57
275pt_ok pt_spawn c 2 58
276pt_ok eq sup_spawn c 2 neg long 16 59
277for w ulong 3
278pt_ok eq pt_phase c w 1 0 60
279end
280pt_ok eq mapget c 272 8 1 61
281pt_ok eq mapget c 1288 8 1 62
282pt_ok eq pool_roll c 2 63
283pt_ok pt_fill c 5 64
284pt_ok eq pool_roll c neg long 9 65
285note An older epoch stays complete for its holder after newer publication.
286pt_ok eq pt_phase c 0 2 0 66
287r = mapset m 8 8 5
288pt_ok eq pt_phase c 0 3 0 67
289pt_ok eq pt_phase c 1 3 0 68
290pt_ok eq mapget c 256 8 2 69
291pt_ok eq pool_roll c neg long 9 70
292note Kill the last holder of epoch 1. Its death is seen through its life pipe.
293pt_ok eq killpid int get swpid 2 9 0 71
294dead = long 0
295for t ulong 500
296dead = add dead sup_poll c 10000000
297if gt dead 0
298break
299end
300end
301pt_ok eq dead 1 72
302pt_ok eq and get swst 2 127 9 73
303pt_ok eq mapget c 272 8 0 74
304pt_ok eq mapget c 1296 8 2 75
305pt_ok eq pool_roll c 3 76
306pt_ok pt_fill c 3 77
307r = mapset m 8 8 3
308pt_ok pt_spawn c 2 78
309pt_ok eq pt_phase c 2 3 0 79
310r = mapset m 0 8 4
311pt_ok eq sup_wake 1 0 80
312r = sleepns 100000000
313note A pending ack from the stalled worker must not turn the stop wait into a
314note spin that kills it before the 2 s deadline.
315pt_ok eq sup_ack 1 0 89
316t0 = monons
317k = sup_stop c 2000000000
318pt_ok ge sub monons t0 1900000000 90
319pt_ok eq k 1 81
320pt_ok eq get swst 0 0 82
321pt_ok eq get swst 2 0 83
322pt_ok eq and get swst 1 127 9 84
323pt_ok eq waitpid neg int 1 ptws 0 4 1 neg long 10 85
324pt_ok eq sup_live c 0 86
325sup_closeall
326pt_ok eq pool_free c 0 87
327pt_ok eq mapdrop m 0 88
328end
329
330note A creator that exits without stopping its worker must not leave the worker
331note waiting: the worker sees the creator's life pipe hang up and reports 3.
332fn pt_orphan to void
333pf = new uchar 8 0
334b = new uchar 1 0
335pt_ok ge pipefds pf 0 8 524288 0 93
336rd = pt_fd4 pf 0
337wr = pt_fd4 pf 4
338s = fork
339if eq s 0
340c = pool_new 1 1
341if le c 0
342exit 50
343end
344if ne sup_init c 0
345exit 51
346end
347put ptc 0 c
348p = sup_spawn c 0
349if eq p 0
350r = sup_wwait c 0 5000000000
351put b 0 uchar and ulong add r 128 255
352r = write wr b 0 1
353exit 0
354end
355exit 0
356end
357pt_ok gt s 0 94
358r = fclose wr
359pt_ok eq waitpid int s ptws 0 4 0 s 95
360pt_ok eq get ptws 0 0 96
361pt_ok gt waitio rd 1 6000000000 0 97
362pt_ok eq read rd b 0 1 1 98
363pt_ok eq get b 0 131 99
364r = fclose rd
365end
366
367note Stress: 0 when arena h shows only complete records of epoch e from start
368note to end of one hold. A reclaimed held arena changes its epoch, drops its
369note count or rewrites bytes, so a missing hold check shows up here.
370fn pt_scan h long e ulong to int
371buf = new uchar 4096 0
372if ne node_epoch h e
373ret 1
374end
375cur = ulong 0
376for k ulong 65
377v = node_next h cur 1
378if eq v 0
379break
380end
381if lt v 0
382ret 2
383end
384cur = ulong v
385if ne node_read h cur buf 4096
386ret 3
387end
388b = pt_byte e cur
389for j ulong 4096
390if ne get buf j b
391ret 4
392end
393end
394end
395if ne node_epoch h e
396ret 5
397end
398ret 0
399end
400
401fn pt_sworker w ulong to int
402c = get ptc 0
403m = get ptm 0
404n = ulong 0
405for it ulong 10000000
406if pool_stopped c
407r = mapset m add 64 mul w 8 8 n
408ret 0
409end
410h = pool_acquire c w
411if eq h neg long 1
412r = mapset m add 64 mul w 8 8 n
413ret 0
414end
415if gt h 0
416r = pt_scan h mapget c add 256 mul w 8 8
417if ne r 0
418ret add 20 r
419end
420q = pool_release c w
421n = add n 1
422end
423end
424ret 29
425end
426
427fn pt_num v ulong to void
428d = new uchar 20 0
429x = v
430k = ulong 20
431for i ulong 20
432k = sub k 1
433put d k uchar add rem x 10 48
434x = div x 10
435if eq x 0
436break
437end
438end
439r = write 1 d k sub 20 k
440end
441
442text pstress "stress rolls="
443text pbusy " busy="
444text preads " reads="
445text pnl "\n"
446text psp " "
447
448note Two workers acquire, scan and release in a tight loop while the creator
449note rolls 2000 epochs over two arenas, publishing four records per epoch.
450fn pt_stress to void
451c = pool_new 2 2
452pt_ok gt c 0 120
453put ptc 0 c
454m = mapnew neg int 1 0 4096 3 33
455pt_ok gt m 0 121
456put ptm 0 m
457pt_ok eq sup_init c 0 122
458pt_ok pt_fill c 4 123
459for w ulong 2
460p = sup_spawn c w
461if eq p 0
462exit pt_sworker w
463end
464pt_ok gt p 0 124
465end
466rolls = ulong 0
467busy = ulong 0
468for i ulong 100000000
469if ge rolls 2000
470break
471end
472r = pool_roll c
473if eq r neg long 9
474busy = add busy 1
475if eq and busy 1023 0
476pt_ok eq sup_poll c 0 0 133
477end
478cpurelax
479continue
480end
481pt_ok gt r 0 125
482rolls = add rolls 1
483pt_ok pt_fill c 4 126
484end
485pt_ok eq rolls 2000 127
486pt_ok eq sup_stop c 5000000000 0 128
487pt_ok eq get swst 0 0 129
488pt_ok eq get swst 1 0 130
489r = write 1 pstress 0 len pstress
490pt_num rolls
491r = write 1 pbusy 0 len pbusy
492pt_num busy
493r = write 1 preads 0 len preads
494pt_num mapget m 64 8
495r = write 1 psp 0 1
496pt_num mapget m 72 8
497r = write 1 pnl 0 1
498sup_closeall
499pt_ok eq pool_free c 0 131
500pt_ok eq mapdrop m 0 132
501end
502
503fn pt_isarg to bool
504a = new uchar 16 0
505if ne argcnt 2
506ret false
507end
508ret eq argread 1 a 0 16 6
509end
510
511note With one argument (any 6 bytes, "stress"), run only the stress phase.
512fn main to int
513if pt_isarg
514pt_stress
515ret 0
516end
517pt_refusals
518pt_epochs
519pt_race
520pt_orphan
521pt_procs
522pt_stress
523if ne write 1 pok 0 len pok long len pok
524ret 100
525end
526ret 0
527end