Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/runtime/slab_arena.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / runtime / slab_arena.om` 220 lines ยท 5684 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Single scheduler serializes these transitions for both lease clients. 3 om2 4 5 note ZoneHeader. OM-2 layout and field identifiers are limited to eight bytes. 6 layout zonehdr 128 7 field epoch ulong at 0 little 8 field active uint at 8 little 9 field cand uint at 12 little 10 field streak uint at 16 little 11 field z2count uint at 20 little 12 field z3count uint at 24 little 13 field fifo uint at 28 little 14 field owner uint at 32 little 15 field flags uint at 36 little 16 field detours ulong at 40 little 17 field accepted uint at 48 little 18 field rejected uint at 52 little 19 field reserved uchar 72 at 56 little 20 end 21 22 note SlabSlot 23 layout slabslot 64 24 field layer_id ushort at 0 little 25 field expert ushort at 2 little 26 field zone_id uchar at 4 little 27 field state uchar at 5 little 28 field planes uchar at 6 little 29 field pad uchar at 7 little 30 field lba ulong at 8 little 31 field dest ulong at 16 little 32 field touch ulong at 24 little 33 field hash64 ulong at 32 little 34 field hits uint at 40 little 35 field reserved uchar 20 at 44 little 36 end 37 38 note PrefetchHint 39 layout prefhint 32 40 field epoch ulong at 0 little 41 field layer_id ushort at 8 little 42 field expert ushort at 10 little 43 field zone uchar at 12 little 44 field planes uchar at 13 little 45 field score ushort at 14 little 46 field status uchar at 16 little 47 field reserved uchar 15 at 17 little 48 end 49 50 fn put_word bytes edit uchar * pos ulong width ulong value ulong to void 51 for i ulong width 52 put bytes add pos i uchar and shr value mul i 8 255 53 end 54 end 55 56 fn get_word bytes view uchar * pos ulong width ulong to ulong 57 value = ulong 0 58 for i ulong width 59 value = or value shl ulong get bytes add pos i mul i 8 60 end 61 ret value 62 end 63 64 export fn slab_init header out uchar 128 domain uint protected_count uint fifo_count uint to void 65 for i ulong 128 66 put header i 0 67 end 68 put_word header 8 4 ulong domain 69 put_word header 12 4 ulong domain 70 put_word header 20 4 ulong protected_count 71 put_word header 24 4 ulong fifo_count 72 put header 36 1 73 end 74 75 export fn slab_acquire_lease h edit zonehdr owner uint to bool 76 if or lt owner 1 gt owner 2 77 ret false 78 end 79 if ne get h owner 0 80 ret false 81 end 82 put h owner owner 83 ret true 84 end 85 86 export fn slab_release_lease h edit zonehdr owner uint to bool 87 if or lt owner 1 gt owner 2 88 ret false 89 end 90 if ne get h owner owner 91 ret false 92 end 93 put h owner 0 94 ret true 95 end 96 97 note A true return authorizes the scheduler to replace the protected pack. 98 export fn z2_check_promotion h edit zonehdr turn ulong domain uint to bool 99 if ne get h owner 1 100 ret false 101 end 102 previous = get h epoch 103 if le turn previous 104 ret false 105 end 106 put h epoch turn 107 if or eq domain get h active eq domain `4294967295` 108 put h cand get h active 109 put h streak 0 110 ret false 111 end 112 if or ne domain get h cand gt sub turn previous 1 113 put h streak 0 114 end 115 put h cand domain 116 if lt get h streak 2 117 put h streak add get h streak 1 118 ret false 119 end 120 put h active domain 121 put h streak 0 122 ret true 123 end 124 125 fn arena_shape h view zonehdr slots view uchar * to bool 126 count = add ulong get h z2count ulong get h z3count 127 ret eq len slots mul count 64 128 end 129 130 note Return the absolute slot index. A busy FIFO head stalls without advancing. 131 export fn z3_claim_fifo_slot h edit zonehdr slots view uchar * to long 132 if or ne get h owner 1 not arena_shape h slots 133 ret -1 134 end 135 head = get h fifo 136 count = get h z3count 137 if ge head count 138 ret -1 139 end 140 index = add ulong get h z2count ulong head 141 state = get slots add mul index 64 5 142 if and ne state 0 ne state 2 143 ret -1 144 end 145 put h fifo rem add head 1 count 146 ret long index 147 end 148 149 fn reject_hint h edit zonehdr hint edit prefhint to uchar 150 put hint status 3 151 put h rejected add get h rejected 1 152 ret 3 153 end 154 155 fn contains_expert slots view uchar * hint view prefhint to bool 156 for i ulong div len slots 64 157 base = mul i 64 158 state = get slots add base 5 159 if and gt state 0 le state 3 160 if eq get_word slots base 2 ulong get hint layer_id 161 if eq get_word slots add base 2 2 ulong get hint expert 162 ret true 163 end 164 end 165 end 166 end 167 ret false 168 end 169 170 note Terminal statuses replay idempotently. A busy FIFO leaves a valid hint pending. 171 note Caller supplies a fixed array of contiguous 64-byte records in zone order. 172 export fn slab_admit_hint h edit zonehdr slots edit uchar * hint edit prefhint to uchar 173 status = get hint status 174 if and gt status 0 le status 3 175 ret status 176 end 177 if ne get h owner 1 178 ret reject_hint h hint 179 end 180 if ne status 0 181 ret reject_hint h hint 182 end 183 if or ne get hint layer_id 0 ge get hint expert 384 184 ret reject_hint h hint 185 end 186 if or ne get hint zone 2 ne get hint epoch get h epoch 187 ret reject_hint h hint 188 end 189 planes = get hint planes 190 flags = get h flags 191 if or and ne planes 3 ne planes 1 and eq planes 1 ne flags 2 192 ret reject_hint h hint 193 end 194 if or not arena_shape h slots ge get h fifo get h z3count 195 ret reject_hint h hint 196 end 197 if contains_expert slots hint 198 put hint status 1 199 ret 1 200 end 201 victim = z3_claim_fifo_slot h slots 202 if lt victim 0 203 ret 0 204 end 205 offset = mul ulong victim 64 206 dest = get_word slots add offset 16 8 207 for j ulong 64 208 put slots add offset j 0 209 end 210 put_word slots offset 2 ulong get hint layer_id 211 put_word slots add offset 2 2 ulong get hint expert 212 put slots add offset 4 2 213 put slots add offset 5 1 214 put slots add offset 6 planes 215 put_word slots add offset 16 8 dest 216 put_word slots add offset 24 8 get h epoch 217 put hint status 2 218 put h accepted add get h accepted 1 219 ret 2 220 end