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 / gpu / rx / regulate.om

189 lines · 5518 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/rx/regulate.om: pure-Omega ADAPTIVE-M4 bounded resource regulation (replaces src/runtime/rx_regulate.{h,c}).
3note Hysteresis + dwell regime state machine, authority-independent envelope enforcement,
4note fairness preservation, idempotent condition seq, and emergency-stop refusal.
5note Compose: si/directives/om2.om gpu/rx/regulate.om gpu/rx/skillroute.om gpu/rx/test.om
6
7const RX_OK int 0
8const RX_NOOP int 1
9const RX_ERR_ARG int -1
10const RX_ERR_BOUNDS int -2
11const RX_ERR_HALTED int -3
12
13const RX_REG_NOMINAL uint 0
14const RX_REG_EXPAND uint 1
15const RX_REG_PROTECT uint 2
16
17const SR_OK int 0
18const SR_E_ARG int -40
19const SR_E_NO_CANDIDATE int -41
20const SR_E_REMOTE int -42
21const SR_E_STALE int -45
22const SR_E_WITHDRAWN int -46
23const SR_E_UNAVAILABLE int -47
24const SR_E_MACHINE int -48
25
26const SR_WHY_GONE uint 0x001
27const SR_WHY_UNAVAILABLE uint 0x002
28const SR_WHY_AUTHORITY uint 0x004
29const SR_WHY_NOT_SKILL uint 0x008
30const SR_WHY_NOT_EXECUTABLE uint 0x010
31const SR_WHY_DIGEST uint 0x020
32const SR_WHY_REMOTE_REFUSED uint 0x040
33const SR_WHY_PIN uint 0x080
34const SR_WHY_MACHINE uint 0x100
35const SR_WHY_MACHINE_UNKNOWN uint 0x200
36
37note All structs for gpu/rx/ declared before first fn (required by omc).
38struct RxBudget slots uint mem ulong energy ulong starv ulong loc uint end
39struct RxEnv smin uint smax uint mmin ulong mmax ulong emin ulong emax ulong chi ulong clo ulong phi ulong plo ulong dwell ulong end
40struct RxPolicy ver ulong slots ulong mem ulong energy ulong regime ulong cseq ulong dwell ulong flips ulong end
41struct RxRegState app_ver ulong refused ulong halted int end
42struct SrReq op uint req_held int local_only int pin_ver uint pin_dlo ulong pin_dhi ulong pin_mset int pin_mid uint prio_cost int end
43struct SrRoute verdict int entry_idx int skill_id uint ver uint machine_id uint remote int gen ulong why uint n_adm uint end
44
45note ---- rx_regulate envelope & decision ----
46
47fn rx_regulate_envelope_ok e view RxEnv base view RxBudget to int
48if or eq get e smin 0 gt get e smin get e smax
49ret RX_ERR_ARG
50end
51if or gt get e mmin get e mmax gt get e emin get e emax
52ret RX_ERR_ARG
53end
54if or lt get base slots get e smin gt get base slots get e smax
55ret RX_ERR_ARG
56end
57if or lt get base mem get e mmin gt get base mem get e mmax
58ret RX_ERR_ARG
59end
60if or lt get base energy get e emin gt get base energy get e emax
61ret RX_ERR_ARG
62end
63if ge get e clo get e chi
64ret RX_ERR_ARG
65end
66if or ge get e plo get e phi gt get e phi 100
67ret RX_ERR_ARG
68end
69if eq get e dwell 0
70ret RX_ERR_ARG
71end
72ret RX_OK
73end
74
75fn rx_regulate_policy_for e view RxEnv base view RxBudget regime uint dst edit RxBudget to void
76put dst slots get base slots
77put dst mem get base mem
78put dst energy get base energy
79put dst starv get base starv
80put dst loc get base loc
81if eq regime RX_REG_EXPAND
82put dst slots get e smax
83put dst mem get e mmax
84put dst energy get e emax
85else
86if eq regime RX_REG_PROTECT
87put dst slots get e smin
88put dst mem get e mmin
89put dst energy get e emin
90end
91end
92ret
93end
94
95fn rx_regulate_decide e view RxEnv regime uint cur_dwell ulong contention ulong pressure ulong to uint
96settled = ge cur_dwell get e dwell
97note Protection enters immediately and takes precedence over expansion.
98if ge pressure get e phi
99ret RX_REG_PROTECT
100end
101if eq regime RX_REG_PROTECT
102if or eq settled false gt pressure get e plo
103ret RX_REG_PROTECT
104end
105if ge contention get e chi
106ret RX_REG_EXPAND
107end
108ret RX_REG_NOMINAL
109end
110if eq regime RX_REG_EXPAND
111if or eq settled false gt contention get e clo
112ret RX_REG_EXPAND
113end
114ret RX_REG_NOMINAL
115end
116if ge contention get e chi
117ret RX_REG_EXPAND
118end
119ret RX_REG_NOMINAL
120end
121
122note Reaction step: decides next regime from condition (cseq, contention, pressure).
123note Same cseq is an idempotent no-op (returns RX_NOOP).
124fn rx_regulate_step e view RxEnv base view RxBudget pol edit RxPolicy cseq ulong contention ulong pressure ulong to int
125if eq cseq get pol cseq
126ret RX_NOOP
127end
128reg = uint get pol regime
129dw = get pol dwell
130nxt = rx_regulate_decide e reg dw contention pressure
131put pol cseq cseq
132if eq nxt reg
133put pol dwell add dw 1
134ret RX_OK
135end
136b = new RxBudget 0 0 0 0 0
137rx_regulate_policy_for e base nxt edit b
138put pol ver add get pol ver 1
139put pol slots ulong get b slots
140put pol mem get b mem
141put pol energy get b energy
142put pol regime ulong nxt
143put pol dwell ulong 0
144put pol flips add get pol flips 1
145ret RX_OK
146end
147
148fn rx_policy_in_envelope e view RxEnv pol view RxPolicy to bool
149if gt get pol slots ulong 0xffffffff
150ret false
151end
152sl = uint get pol slots
153if or lt sl get e smin gt sl get e smax
154ret false
155end
156if or lt get pol mem get e mmin gt get pol mem get e mmax
157ret false
158end
159if or lt get pol energy get e emin gt get pol energy get e emax
160ret false
161end
162if gt get pol regime ulong RX_REG_PROTECT
163ret false
164end
165ret true
166end
167
168note Host step: installs policy into applied budget iff not halted, version is new, and within envelope.
169note Fairness fields (starv, loc) always come from base budget and are never regulated away.
170fn rx_regulate_apply e view RxEnv base view RxBudget pol view RxPolicy st edit RxRegState app edit RxBudget to int
171if ne get st halted 0
172put st refused add get st refused 1
173ret RX_ERR_HALTED
174end
175if eq get pol ver get st app_ver
176ret RX_NOOP
177end
178if eq rx_policy_in_envelope e pol false
179put st refused add get st refused 1
180ret RX_ERR_BOUNDS
181end
182put app slots uint get pol slots
183put app mem get pol mem
184put app energy get pol energy
185put app starv get base starv
186put app loc get base loc
187put st app_ver get pol ver
188ret RX_OK
189end