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