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

210 lines · 3461 bytes Raw Blame History
1note Scheduler gate. Select one CPU from the inherited mask so no wider pool is touched.
2om2
3global mask uchar 128
4global check uchar 128
5global status uchar 4
6fn reap p long to int
7r = waitpid int p status 0 4 0
8if or ne r p ne get status 0 0
9ret 99
10end
11ret int get status 1
12end
13fn badslice to int
14p = fork
15if eq p 0
16n = ulong 129
17r = cpuget 0 mask 0 n
18exit 90
19end
20ret reap p
21end
22text pstat "/proc/thread-self/stat"
23fn statnice to long
24b = new uchar 1024 0
25fd = fopen pstat 0 len pstat 0 0
26if lt fd 0
27ret -1
28end
29n = read int fd b 0 1024
30c = fclose int fd
31if le n 0
32ret -1
33end
34p = ulong 0
35for i ulong ulong n
36if eq get b i 41
37p = add i 2
38end
39end
40if eq p 0
41ret -1
42end
43note Skip fields 3 through 18 after the final closing parenthesis of comm.
44for colidx ulong 16
45while lt p ulong n
46if eq get b p 32
47p = add p 1
48break
49end
50p = add p 1
51end
52end
53v = long 0
54while lt p ulong n
55d = get b p
56if or lt d 48 gt d 57
57break
58end
59v = add mul v 10 long sub d 48
60p = add p 1
61end
62ret v
63end
64fn priority to int
65p = fork
66if eq p 0
67v = getprio 0 0
68if or lt v 1 gt v 40
69exit 10
70end
71r = setprio 0 0 19
72if ne r 0
73exit 11
74end
75if ne getprio 0 0 1
76exit 12
77end
78if ne statnice 19
79exit 16
80end
81note Under a nice 19 pool setprio 0 0 19 changes nothing, so a lowering that drops or hardwires the
82note priority operand passes the checks above. Ask for nice 18: without CAP_SYS_NICE (RLIMIT_NICE 0)
83note the kernel refuses with -13 and nice stays 19; where it is allowed nice must become 18.
84r = setprio 0 0 18
85if eq r 0
86if ne statnice 18
87exit 19
88end
89if ne getprio 0 0 2
90exit 19
91end
92else
93if ne r -13
94exit 19
95end
96if ne statnice 19
97exit 19
98end
99end
100r = setprio 99 0 19
101if ne r -22
102exit 13
103end
104exit 0
105end
106ret reap p
107end
108fn offset core ulong to int
109b = new uchar 144 0
110put b add 9 div core 8 shl uchar 1 uchar rem core 8
111r = cpuset 0 b 9 128
112if or ne r 0 ne cpunow long core
113ret 14
114end
115for i ulong 144
116put b i 0
117end
118r = cpuget 0 b 9 128
119if le r 0
120ret 15
121end
122if ne get b add 9 div core 8 shl uchar 1 uchar rem core 8
123ret 15
124end
125for i ulong 9
126if ne get b i 0
127ret 15
128end
129end
130ret 0
131end
132fn main to int
133n = cpuget 0 mask 0 128
134if le n 0
135ret 1
136end
137core = ulong 1024
138for i ulong 128
139if ne get mask i 0
140for j ulong 8
141if ne and get mask i shl uchar 1 uchar j 0
142core = add mul i 8 j
143break
144end
145end
146break
147end
148end
149if eq core 1024
150ret 2
151end
152note The last inherited core too: on a pool whose first core is CPU 0 a cpunow that always
153note gives 0 would pass the first-core check. Pin the last inherited core on every pool shape
154note (with one core it is the first core) so a cpunow that ignores getcpu fails here at 18 on
155note every mask except the single core CPU 0, where 0 is the correct answer.
156last = core
157for i ulong 128
158for j ulong 8
159if ne and get mask i shl uchar 1 uchar j 0
160last = add mul i 8 j
161end
162end
163end
164r = cpuset 0 check 0 128
165if ne r -22
166ret 3
167end
168note check is still all zero here (the empty-mask case above); set the last core's bit, then clear it.
169put check div last 8 shl uchar 1 uchar rem last 8
170r = cpuset 0 check 0 128
171put check div last 8 0
172if ne r 0
173ret 17
174end
175if ne cpunow long last
176ret 18
177end
178put check div core 8 shl uchar 1 uchar rem core 8
179r = cpuset 0 check 0 128
180if ne r 0
181ret 4
182end
183if ne cpunow long core
184ret 5
185end
186for i ulong 128
187put mask i 0
188end
189n = cpuget 0 mask 0 128
190if le n 0
191ret 6
192end
193for i ulong 128
194if ne get mask i get check i
195ret 7
196end
197end
198r = cpuget 2147483647 mask 0 128
199if ne r -3
200ret 8
201end
202if ne badslice 103
203ret 9
204end
205k = offset core
206if ne k 0
207ret k
208end
209ret priority
210end