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
omega-mv / seed / node / auth.om
| 1 | note Omega Node proposals, authority and cancellation (DRA-288). Concatenate |
| 2 | note after transport.om, pool.om, super.om, sched.om and |
| 3 | note seed/authority/action.om, before one program with fn main. |
| 4 | note A worker proposes and the creator alone decides and commits. A proposal |
| 5 | note is typed and bound to its operation identity, the job id and |
| 6 | note assignment seq, the worker slot and incarnation, the input epoch and |
| 7 | note version it read, and the authority generation it holds. Every effect is |
| 8 | note one action record of seed/authority/action.om per operation identity: |
| 9 | note started with actstart, closed with actrecon or actlost. A performed |
| 10 | note operation is never started again and an UNKNOWN one is never retried; |
| 11 | note one with no external effect (class 2) whose worker died is closed as |
| 12 | note not performed, so it may run again. |
| 13 | note Control page (16384 bytes), cell of worker w at 128*w. Creator writes |
| 14 | note 0 control seq, 8 cancel target (assignment seq, 0 none), 16 decided |
| 15 | note proposal seq, 24 verdict, 32 generation at the decision. Worker |
| 16 | note writes 64 control ack seq, 72 proposal seq, 80 report seq, 88 report |
| 17 | note outcome, 96 tool wait status, 104 paused as last seen, 112 running tool |
| 18 | note pid (its process group), 120 tool output bytes held. Word 8192 mirrors |
| 19 | note the authority generation and 8200 the paused flag. |
| 20 | note Proposal page: 4096 bytes per worker at 4096*w. Words 0..15: 0 version |
| 21 | note 1, 1 kind 1, 2 job id, 3 assignment seq, 4 slot, 5 incarnation, 6 input |
| 22 | note epoch, 7 input version, 8 generation, 9..12 operation identity, 13 class |
| 23 | note (1 external effect, 2 no external effect, 3 idempotent external effect |
| 24 | note whose completion is visible as a key, see journal.om), 14 and 15 zero. |
| 25 | note Bytes 128..4095 hold the running tool's output. |
| 26 | note Verdicts: 0 granted, 1 malformed, 2 not the worker's assignment, 3 other |
| 27 | note incarnation, 4 stale input, 5 stale authority, 6 cancelled, 7 already |
| 28 | note performed or UNKNOWN, 8 attempt limit, 9 refused by the action contract. |
| 29 | note Outcomes, as action.om receipts: 0 UNKNOWN, 1 not performed, 2 performed. |
| 30 | text audevnul "/dev/null" |
| 31 | global aumap long 2 |
| 32 | global auctl int 64 |
| 33 | global auinc ulong 64 |
| 34 | global augen ulong 1 |
| 35 | global aurec ulong 2048 |
| 36 | global auuse ulong 64 |
| 37 | global aujob ulong 64 |
| 38 | global aured ulong 64 |
| 39 | global aupf uchar 8 |
| 40 | global aufd int 1 |
| 41 | |
| 42 | fn au_cell w ulong off ulong to ulong |
| 43 | ret mapget get aumap 0 add mul w 128 off 8 |
| 44 | end |
| 45 | |
| 46 | fn au_set w ulong off ulong v ulong to void |
| 47 | r = mapset get aumap 0 add mul w 128 off 8 v |
| 48 | end |
| 49 | |
| 50 | fn au_pw w ulong i ulong to ulong |
| 51 | ret mapget get aumap 1 add mul w 4096 mul i 8 8 |
| 52 | end |
| 53 | |
| 54 | fn au_spw w ulong i ulong v ulong to void |
| 55 | r = mapset get aumap 1 add mul w 4096 mul i 8 8 v |
| 56 | end |
| 57 | |
| 58 | fn au_pfd off ulong to int |
| 59 | v = ulong get aupf off |
| 60 | v = or v shl ulong get aupf add off 1 8 |
| 61 | v = or v shl ulong get aupf add off 2 16 |
| 62 | v = or v shl ulong get aupf add off 3 24 |
| 63 | ret int v |
| 64 | end |
| 65 | |
| 66 | note Poll record at off; a negative fd keeps its bit pattern, so the kernel |
| 67 | note ignores that record. |
| 68 | fn au_lpfd p edit uchar 40 off ulong fd int to void |
| 69 | u = bitcast uint fd |
| 70 | for i ulong 4 |
| 71 | put p add off i uchar and shr u uint mul i 8 255 |
| 72 | end |
| 73 | put p add off 4 1 |
| 74 | end |
| 75 | |
| 76 | note Creator, after sup_init and before any spawn: map the control and |
| 77 | note proposal pages, one control eventfd per worker slot, generation 1. |
| 78 | note 0, -6 not creator, or a negative errno. |
| 79 | fn auth_new c long to long |
| 80 | if not pool_mine c |
| 81 | ret neg long 6 |
| 82 | end |
| 83 | a = mapnew neg int 1 0 16384 3 33 |
| 84 | if le a 0 |
| 85 | ret a |
| 86 | end |
| 87 | b = mapnew neg int 1 0 262144 3 33 |
| 88 | if le b 0 |
| 89 | r = mapdrop a |
| 90 | ret b |
| 91 | end |
| 92 | put aumap 0 a |
| 93 | put aumap 1 b |
| 94 | for i ulong 64 |
| 95 | put auctl i neg int 1 |
| 96 | put auinc i 0 |
| 97 | put auuse i 0 |
| 98 | put aujob i 0 |
| 99 | put aured i 0 |
| 100 | end |
| 101 | n = mapget c 48 8 |
| 102 | for i ulong n bound 64 |
| 103 | e = eventfd uint 0 |
| 104 | if lt e 0 |
| 105 | x = auth_free |
| 106 | ret e |
| 107 | end |
| 108 | put auctl i int e |
| 109 | end |
| 110 | put augen 0 1 |
| 111 | r = mapset a 8192 8 1 |
| 112 | r = mapset a 8200 8 0 |
| 113 | ret 0 |
| 114 | end |
| 115 | |
| 116 | note Creator: close the control eventfds and drop both pages. |
| 117 | fn auth_free to long |
| 118 | for i ulong 64 |
| 119 | if ge get auctl i 0 |
| 120 | r = fclose get auctl i |
| 121 | end |
| 122 | put auctl i neg int 1 |
| 123 | end |
| 124 | r = mapdrop get aumap 1 |
| 125 | if lt r 0 |
| 126 | ret r |
| 127 | end |
| 128 | ret mapdrop get aumap 0 |
| 129 | end |
| 130 | |
| 131 | note Creator: start a new incarnation of worker slot w (sup_spawn). The child |
| 132 | note inherits its incarnation number. 0 in the child, else as sup_spawn. |
| 133 | fn auth_spawn c long w ulong to long |
| 134 | if ge w 64 |
| 135 | ret neg long 7 |
| 136 | end |
| 137 | if ne get swpid w 0 |
| 138 | ret neg long 16 |
| 139 | end |
| 140 | put auinc w add get auinc w 1 |
| 141 | ret sup_spawn c w |
| 142 | end |
| 143 | |
| 144 | note Creator: post control to worker w. A nonzero target asks it to cancel |
| 145 | note that assignment. The state words go first, then the seq, then the hint. |
| 146 | fn au_ctl w ulong target ulong to void |
| 147 | if gt target 0 |
| 148 | au_set w 8 target |
| 149 | end |
| 150 | au_set w 0 add au_cell w 0 1 |
| 151 | r = node_notify get auctl w |
| 152 | end |
| 153 | |
| 154 | note Worker w: bounded control handler. Records the paused flag it saw and |
| 155 | note acknowledges the control seq; returns the cancel target (0 none). |
| 156 | fn auth_wctl w ulong to ulong |
| 157 | s = au_cell w 0 |
| 158 | au_set w 104 mapget get aumap 0 8200 8 |
| 159 | au_set w 64 s |
| 160 | ret au_cell w 8 |
| 161 | end |
| 162 | |
| 163 | note Worker w: wait up to interval ns. 3 creator gone, 2 stop, 4 control, |
| 164 | note 5 descriptor x readable or hung up (x negative: none), 1 work hint, |
| 165 | note 0 timeout, or a negative errno. Creator loss outranks stop, stop |
| 166 | note outranks control, control outranks output and work. Control and work |
| 167 | note hints are drained; reread the shared state after any return. |
| 168 | fn auth_wwait c long w ulong x int interval long to long |
| 169 | p = new uchar 40 0 |
| 170 | if ge w 64 |
| 171 | ret neg long 7 |
| 172 | end |
| 173 | iv = interval |
| 174 | if pool_stopped c |
| 175 | iv = long 0 |
| 176 | end |
| 177 | au_lpfd p 0 get swwake w |
| 178 | au_lpfd p 8 get swstop w |
| 179 | au_lpfd p 16 get swpar 0 |
| 180 | au_lpfd p 24 get auctl w |
| 181 | au_lpfd p 32 x |
| 182 | r = pollfds p 0 40 iv |
| 183 | if lt r 0 |
| 184 | ret r |
| 185 | end |
| 186 | if ne get p 22 0 |
| 187 | ret 3 |
| 188 | end |
| 189 | if pool_stopped c |
| 190 | ret 2 |
| 191 | end |
| 192 | if ne and get p 14 1 0 |
| 193 | r = node_drain get swstop w |
| 194 | ret 2 |
| 195 | end |
| 196 | if ne get p 30 0 |
| 197 | r = node_drain get auctl w |
| 198 | ret 4 |
| 199 | end |
| 200 | if ne get p 38 0 |
| 201 | ret 5 |
| 202 | end |
| 203 | if ne and get p 6 1 0 |
| 204 | r = node_drain get swwake w |
| 205 | ret 1 |
| 206 | end |
| 207 | ret 0 |
| 208 | end |
| 209 | |
| 210 | note Worker w: propose the effect of assignment q with operation identity |
| 211 | note op and class (1 external effect, 2 none, 3 keyed idempotent). The words go first, then the |
| 212 | note proposal seq, then an ack to the creator. 0 or the ack refusal. |
| 213 | fn auth_propose w ulong q ulong op view ulong 4 class ulong to long |
| 214 | if ge w 64 |
| 215 | ret neg long 7 |
| 216 | end |
| 217 | au_spw w 0 1 |
| 218 | au_spw w 1 1 |
| 219 | au_spw w 2 sc_cell w 8 |
| 220 | au_spw w 3 q |
| 221 | au_spw w 4 w |
| 222 | au_spw w 5 get auinc w |
| 223 | au_spw w 6 sc_cell w 16 |
| 224 | au_spw w 7 sc_cell w 24 |
| 225 | au_spw w 8 mapget get aumap 0 8192 8 |
| 226 | for i ulong 4 |
| 227 | au_spw w add 9 i get op i |
| 228 | end |
| 229 | au_spw w 13 class |
| 230 | au_spw w 14 0 |
| 231 | au_spw w 15 0 |
| 232 | au_set w 72 q |
| 233 | ret sup_ack w |
| 234 | end |
| 235 | |
| 236 | note Worker w: wait up to interval ns for the decision on proposal q, |
| 237 | note handling control meanwhile. The verdict (0 granted), 102 stop, 103 |
| 238 | note creator gone, 110 no decision yet, or a negative errno. |
| 239 | fn auth_wdecide c long w ulong q ulong interval long to long |
| 240 | dl = add ulong monons ulong interval |
| 241 | for it ulong 100000000 |
| 242 | if eq au_cell w 16 q |
| 243 | ret long au_cell w 24 |
| 244 | end |
| 245 | now = ulong monons |
| 246 | if ge now dl |
| 247 | ret 110 |
| 248 | end |
| 249 | r = auth_wwait c w neg int 1 long sub dl now |
| 250 | if lt r 0 |
| 251 | ret r |
| 252 | end |
| 253 | if or eq r 2 eq r 3 |
| 254 | ret add 100 r |
| 255 | end |
| 256 | if eq r 4 |
| 257 | t = auth_wctl w |
| 258 | end |
| 259 | end |
| 260 | ret 110 |
| 261 | end |
| 262 | |
| 263 | note Worker w: fork the packed argv pk (pn bytes) as the leader of a new |
| 264 | note process group, stdin on /dev/null, stdout and stderr on a pipe whose |
| 265 | note read end is left in aufd. Both sides call setpgid, so the group exists |
| 266 | note before either side goes on. The pid, or a negative errno. |
| 267 | fn au_fork w ulong pk view uchar 4096 pn ulong to long |
| 268 | r = pipefds aupf 0 8 524288 |
| 269 | if lt r 0 |
| 270 | ret r |
| 271 | end |
| 272 | rfd = au_pfd 0 |
| 273 | wfd = au_pfd 4 |
| 274 | dn = fopen audevnul 0 len audevnul 524288 0 |
| 275 | pid = fork |
| 276 | if eq pid 0 |
| 277 | r = setpgid 0 0 |
| 278 | r = dupfd wfd 1 0 |
| 279 | r = dupfd wfd 2 0 |
| 280 | if ge dn 0 |
| 281 | r = dupfd int dn 0 0 |
| 282 | end |
| 283 | r = execprog pk 0 pn |
| 284 | exit 127 |
| 285 | end |
| 286 | r = fclose wfd |
| 287 | if ge dn 0 |
| 288 | r = fclose int dn |
| 289 | end |
| 290 | if lt pid 0 |
| 291 | r = fclose rfd |
| 292 | ret pid |
| 293 | end |
| 294 | r = setpgid int pid int pid |
| 295 | au_set w 120 0 |
| 296 | au_set w 112 ulong pid |
| 297 | put aufd 0 rfd |
| 298 | ret pid |
| 299 | end |
| 300 | |
| 301 | note Worker w: move available tool output into its proposal page from byte |
| 302 | note 128 (bytes past 4096 are dropped). false at end of file or on error. |
| 303 | fn au_out w ulong rfd int to bool |
| 304 | buf = new uchar 4096 0 |
| 305 | n = read rfd buf 0 4096 |
| 306 | if eq n 0 |
| 307 | ret false |
| 308 | end |
| 309 | if lt n 0 |
| 310 | ret or eq n neg long 4 eq n neg long 11 |
| 311 | end |
| 312 | k = au_cell w 120 |
| 313 | m = ulong n |
| 314 | if gt add k m 3968 |
| 315 | m = sub 3968 k |
| 316 | end |
| 317 | if gt m 0 |
| 318 | h = get aumap 1 |
| 319 | off = add mul w 4096 add 128 k |
| 320 | r = mapwrite h off buf 0 m |
| 321 | au_set w 120 add k m |
| 322 | end |
| 323 | ret true |
| 324 | end |
| 325 | |
| 326 | note Outcome of a reaped tool from its wait status: it exited, so it ran |
| 327 | note (2); it was killed or crashed, so an external effect is UNKNOWN (0) and |
| 328 | note a class 2 tool had none (1). |
| 329 | fn au_outcome st ulong class ulong to long |
| 330 | if eq and st 127 0 |
| 331 | ret 2 |
| 332 | end |
| 333 | if eq class 2 |
| 334 | ret 1 |
| 335 | end |
| 336 | ret 0 |
| 337 | end |
| 338 | |
| 339 | note Worker w: finish tool pid of assignment q. Without kill, wait for its |
| 340 | note exit while still obeying control. With kill, a tool that has already |
| 341 | note exited is not cancelled; otherwise SIGKILL its whole group. Its wait |
| 342 | note status alone decides the outcome, never the fact that a kill was sent. |
| 343 | note Group members left behind are killed either way. |
| 344 | fn au_end c long w ulong q ulong pid long class ulong kill bool to long |
| 345 | ws = new uchar 4 0 |
| 346 | k = kill |
| 347 | g = long 0 |
| 348 | if not k |
| 349 | for it ulong 100000000 |
| 350 | g = waitpid int pid ws 0 4 1 |
| 351 | if ne g 0 |
| 352 | break |
| 353 | end |
| 354 | r = auth_wwait c w neg int 1 5000000 |
| 355 | if eq r 4 |
| 356 | if eq auth_wctl w q |
| 357 | k = true |
| 358 | break |
| 359 | end |
| 360 | end |
| 361 | if or eq r 2 eq r 3 |
| 362 | k = true |
| 363 | break |
| 364 | end |
| 365 | end |
| 366 | end |
| 367 | if k |
| 368 | g = waitpid int pid ws 0 4 1 |
| 369 | end |
| 370 | if eq g 0 |
| 371 | r = killpid neg int pid 9 |
| 372 | if lt r 0 |
| 373 | r = killpid int pid 9 |
| 374 | end |
| 375 | g = waitpid int pid ws 0 4 0 |
| 376 | else |
| 377 | r = killpid neg int pid 9 |
| 378 | end |
| 379 | r = fclose get aufd 0 |
| 380 | put aufd 0 neg int 1 |
| 381 | au_set w 112 0 |
| 382 | if lt g 0 |
| 383 | au_set w 96 65535 |
| 384 | ret 0 |
| 385 | end |
| 386 | st = or ulong get ws 0 shl ulong get ws 1 8 |
| 387 | au_set w 96 st |
| 388 | ret au_outcome st class |
| 389 | end |
| 390 | |
| 391 | note Worker w: run the granted tool pk of assignment q (see au_fork). Its |
| 392 | note output goes to the proposal page; cancellation of q, stop or creator |
| 393 | note loss kill its process group. Returns the outcome: 1 when q was |
| 394 | note cancelled before the tool started or the fork failed, else from |
| 395 | note au_end. The wait status is in cell word 96. |
| 396 | fn auth_wtool c long w ulong q ulong pk view uchar 4096 pn ulong class ulong to long |
| 397 | if eq auth_wctl w q |
| 398 | ret 1 |
| 399 | end |
| 400 | pid = au_fork w pk pn |
| 401 | if le pid 0 |
| 402 | ret 1 |
| 403 | end |
| 404 | rfd = get aufd 0 |
| 405 | for it ulong 100000000 |
| 406 | r = auth_wwait c w rfd 1000000000 |
| 407 | if eq r 5 |
| 408 | if not au_out w rfd |
| 409 | ret au_end c w q pid class false |
| 410 | end |
| 411 | end |
| 412 | if eq r 4 |
| 413 | if eq auth_wctl w q |
| 414 | ret au_end c w q pid class true |
| 415 | end |
| 416 | end |
| 417 | if or eq r 2 eq r 3 |
| 418 | ret au_end c w q pid class true |
| 419 | end |
| 420 | if lt r 0 |
| 421 | ret au_end c w q pid class true |
| 422 | end |
| 423 | end |
| 424 | ret au_end c w q pid class true |
| 425 | end |
| 426 | |
| 427 | note Worker w: report the outcome of the granted tool of assignment q. |
| 428 | fn auth_wreport w ulong q ulong outcome ulong to long |
| 429 | au_set w 88 outcome |
| 430 | au_set w 80 q |
| 431 | ret sup_ack w |
| 432 | end |
| 433 | |
| 434 | note Creator: the action slot whose operation identity is op, or -1. |
| 435 | fn au_find op view ulong 4 to long |
| 436 | for k ulong 64 |
| 437 | if ne get auuse k 0 |
| 438 | m = true |
| 439 | for i ulong 4 |
| 440 | if ne get aurec add mul k 32 add 8 i get op i |
| 441 | m = false |
| 442 | end |
| 443 | end |
| 444 | if m |
| 445 | ret long k |
| 446 | end |
| 447 | end |
| 448 | end |
| 449 | ret neg long 1 |
| 450 | end |
| 451 | |
| 452 | note Creator: a new ready action record for op and class in a free slot, |
| 453 | note bound to the current generation; -1 when all 64 are in use. |
| 454 | note Identities: operation and request op, scope node, provider class, |
| 455 | note policy 1, grant 1. Attempt limit 3, epoch 1, no expiry in practice. |
| 456 | fn au_alloc op view ulong 4 class ulong to long |
| 457 | for k ulong 64 |
| 458 | if eq get auuse k 0 |
| 459 | b = mul k 32 |
| 460 | for i ulong 32 |
| 461 | put aurec add b i 0 |
| 462 | end |
| 463 | put aurec b 1 |
| 464 | put aurec add b 1 1 |
| 465 | put aurec add b 3 3 |
| 466 | put aurec add b 4 get augen 0 |
| 467 | put aurec add b 5 1 |
| 468 | put aurec add b 6 9223372036854775807 |
| 469 | for i ulong 4 |
| 470 | put aurec add b add 8 i get op i |
| 471 | put aurec add b add 12 i get op i |
| 472 | end |
| 473 | put aurec add b 16 1313817669 |
| 474 | put aurec add b 20 class |
| 475 | put aurec add b 24 1 |
| 476 | put aurec add b 28 1 |
| 477 | put auuse k 1 |
| 478 | ret long k |
| 479 | end |
| 480 | end |
| 481 | ret neg long 1 |
| 482 | end |
| 483 | |
| 484 | fn au_load k ulong r edit ulong 32 to void |
| 485 | for i ulong 32 |
| 486 | put r i get aurec add mul k 32 i |
| 487 | end |
| 488 | end |
| 489 | |
| 490 | fn au_save k ulong r view ulong 32 to void |
| 491 | for i ulong 32 |
| 492 | put aurec add mul k 32 i get r i |
| 493 | end |
| 494 | end |
| 495 | |
| 496 | note Creator: commit the start of the operation proposed by worker w. |
| 497 | note A ready record moves to the current generation; actstart checks the |
| 498 | note state, the attempt limit and the credential. The verdict. |
| 499 | fn au_commit w ulong to ulong |
| 500 | op = new ulong 4 0 |
| 501 | r = new ulong 32 0 |
| 502 | cr = new ulong 32 0 |
| 503 | for i ulong 4 |
| 504 | put op i au_pw w add 9 i |
| 505 | end |
| 506 | k = au_find op |
| 507 | if lt k 0 |
| 508 | k = au_alloc op au_pw w 13 |
| 509 | if lt k 0 |
| 510 | ret 9 |
| 511 | end |
| 512 | end |
| 513 | au_load ulong k r |
| 514 | if and eq get r 1 1 ne get r 4 get augen 0 |
| 515 | put r 4 get augen 0 |
| 516 | end |
| 517 | for i ulong 32 |
| 518 | put cr i get r i |
| 519 | end |
| 520 | put cr 1 1 |
| 521 | put cr 2 1 |
| 522 | put cr 3 0 |
| 523 | put cr 4 get augen 0 |
| 524 | put cr 6 0 |
| 525 | put cr 7 0 |
| 526 | e = actstart r cr |
| 527 | if eq e 0 |
| 528 | au_save ulong k r |
| 529 | put aujob w add ulong k 1 |
| 530 | ret 0 |
| 531 | end |
| 532 | if or eq e 21 eq e 22 |
| 533 | ret 7 |
| 534 | end |
| 535 | if eq e 23 |
| 536 | ret 8 |
| 537 | end |
| 538 | if eq e 31 |
| 539 | ret 5 |
| 540 | end |
| 541 | ret 9 |
| 542 | end |
| 543 | |
| 544 | note Creator: a proposal is stale when the input it read is not the |
| 545 | note assignment's, its epoch is no longer current, or a newer version on the |
| 546 | note job's dependency topics has been published since. |
| 547 | fn au_stale c long w ulong j ulong to bool |
| 548 | if ne au_pw w 6 sc_cell w 16 |
| 549 | ret true |
| 550 | end |
| 551 | if ne au_pw w 7 sc_cell w 24 |
| 552 | ret true |
| 553 | end |
| 554 | if ne au_pw w 6 pool_epoch c |
| 555 | ret true |
| 556 | end |
| 557 | t = get sjdep j |
| 558 | if eq t 0 |
| 559 | ret false |
| 560 | end |
| 561 | h = pool_current c |
| 562 | if le h 0 |
| 563 | ret true |
| 564 | end |
| 565 | ret ne node_next h au_pw w 7 t 0 |
| 566 | end |
| 567 | |
| 568 | note Creator: check the pending proposal of worker w; the verdict. |
| 569 | fn au_valid c long w ulong to ulong |
| 570 | q = au_cell w 72 |
| 571 | if or ne au_pw w 0 1 ne au_pw w 1 1 |
| 572 | ret 1 |
| 573 | end |
| 574 | cl = au_pw w 13 |
| 575 | if or eq cl 0 gt cl 3 |
| 576 | ret 1 |
| 577 | end |
| 578 | if or ne au_pw w 14 0 ne au_pw w 15 0 |
| 579 | ret 1 |
| 580 | end |
| 581 | b = get scbusy w |
| 582 | if eq b 0 |
| 583 | ret 2 |
| 584 | end |
| 585 | j = sub b 1 |
| 586 | if ne get sjst j 3 |
| 587 | ret 2 |
| 588 | end |
| 589 | if or ne au_pw w 3 q ne q sc_cell w 0 |
| 590 | ret 2 |
| 591 | end |
| 592 | if or ne au_pw w 2 get sjid j ne au_pw w 4 w |
| 593 | ret 2 |
| 594 | end |
| 595 | if ne au_pw w 5 get auinc w |
| 596 | ret 3 |
| 597 | end |
| 598 | if au_stale c w j |
| 599 | ret 4 |
| 600 | end |
| 601 | if ne au_pw w 8 get augen 0 |
| 602 | ret 5 |
| 603 | end |
| 604 | if eq au_cell w 8 q |
| 605 | ret 6 |
| 606 | end |
| 607 | ret 0 |
| 608 | end |
| 609 | |
| 610 | note Creator: decide worker w's pending proposal. A grant is journaled |
| 611 | note (START, made durable) before the verdict is published; if the journal |
| 612 | note refuses, the action is closed as not performed and the verdict is 9. |
| 613 | fn au_decide c long w ulong to void |
| 614 | q = au_cell w 72 |
| 615 | v = au_valid c w |
| 616 | if eq v 0 |
| 617 | v = au_commit w |
| 618 | end |
| 619 | if eq v 0 |
| 620 | if ne au_jstart w 0 |
| 621 | e = au_recon sub get aujob w 1 1 |
| 622 | put aujob w 0 |
| 623 | v = 9 |
| 624 | end |
| 625 | end |
| 626 | if eq v 0 |
| 627 | jn_hit 2 |
| 628 | end |
| 629 | au_set w 24 v |
| 630 | au_set w 32 get augen 0 |
| 631 | au_set w 16 q |
| 632 | r = sup_wake w |
| 633 | end |
| 634 | |
| 635 | fn au_jstart w ulong to ulong |
| 636 | op = new ulong 4 0 |
| 637 | k = sub get aujob w 1 |
| 638 | for i ulong 4 |
| 639 | put op i au_pw w add 9 i |
| 640 | end |
| 641 | b = mul k 32 |
| 642 | ret jn_start op au_pw w 13 au_pw w 2 get aurec add b 2 get aurec add b 4 |
| 643 | end |
| 644 | |
| 645 | note Journal DONE for the action in slot b-1 of worker w's job. |
| 646 | fn au_jdone b ulong o ulong w ulong how ulong to ulong |
| 647 | op = new ulong 4 0 |
| 648 | k = sub b 1 |
| 649 | for i ulong 4 |
| 650 | put op i get aurec add mul k 32 add 8 i |
| 651 | end |
| 652 | ret jn_done op o au_pw w 2 how |
| 653 | end |
| 654 | |
| 655 | note Creator: apply receipt outcome o to action slot k (actrecon). An |
| 656 | note outcome of 0 leaves the action UNKNOWN. |
| 657 | fn au_recon k ulong o ulong to ulong |
| 658 | r = new ulong 32 0 |
| 659 | s = new ulong 32 0 |
| 660 | au_load k r |
| 661 | for i ulong 32 |
| 662 | put s i get r i |
| 663 | end |
| 664 | put s 0 1 |
| 665 | put s 1 o |
| 666 | put s 3 1 |
| 667 | put s 6 0 |
| 668 | put s 7 0 |
| 669 | e = actrecon r s |
| 670 | au_save k r |
| 671 | ret e |
| 672 | end |
| 673 | |
| 674 | note Creator: record worker w's report. DONE is made durable before the |
| 675 | note action record changes; if the journal refuses, the report stays |
| 676 | note unrecorded and is tried again at the next step. |
| 677 | fn au_record w ulong to void |
| 678 | b = get aujob w |
| 679 | if eq b 0 |
| 680 | put aured w au_cell w 80 |
| 681 | ret |
| 682 | end |
| 683 | jn_hit 3 |
| 684 | if ne au_jdone b au_cell w 88 w 1 0 |
| 685 | ret |
| 686 | end |
| 687 | jn_hit 4 |
| 688 | put aured w au_cell w 80 |
| 689 | put aujob w 0 |
| 690 | e = au_recon sub b 1 au_cell w 88 |
| 691 | end |
| 692 | |
| 693 | note Creator, after worker w was reaped: kill the process group of a tool |
| 694 | note it left running and close its in-flight action. One of class 2 (no |
| 695 | note external effect) is not performed (DONE how 6, as jn_settle closes it |
| 696 | note at a restart), so its rerunnable job may start again; any other is |
| 697 | note UNKNOWN (actlost, DONE how 2) and never runs again (DRA-292). |
| 698 | fn au_lost w ulong to void |
| 699 | r = new ulong 32 0 |
| 700 | p = au_cell w 112 |
| 701 | if gt p 0 |
| 702 | x = killpid neg int p 9 |
| 703 | au_set w 112 0 |
| 704 | end |
| 705 | b = get aujob w |
| 706 | if eq b 0 |
| 707 | ret |
| 708 | end |
| 709 | k = sub b 1 |
| 710 | if eq get aurec add mul k 32 20 2 |
| 711 | if ne au_jdone b 1 w 6 0 |
| 712 | ret |
| 713 | end |
| 714 | put aujob w 0 |
| 715 | e = au_recon k 1 |
| 716 | ret |
| 717 | end |
| 718 | if ne au_jdone b 0 w 2 0 |
| 719 | ret |
| 720 | end |
| 721 | put aujob w 0 |
| 722 | au_load k r |
| 723 | e = actlost r |
| 724 | au_save k r |
| 725 | end |
| 726 | |
| 727 | note Creator, after sched_step: make the dispatch decisions so far durable |
| 728 | note (jn_drain), record tool reports, close the actions of reaped workers, |
| 729 | note and decide pending proposals unless paused. Returns the number of |
| 730 | note proposals decided. |
| 731 | fn auth_step c long to ulong |
| 732 | dr = jn_drain |
| 733 | n = mapget c 48 8 |
| 734 | k = ulong 0 |
| 735 | for w ulong n bound 64 |
| 736 | if gt au_cell w 80 get aured w |
| 737 | au_record w |
| 738 | end |
| 739 | if gt get swpid w 0 |
| 740 | if and eq get scpause 0 0 gt au_cell w 72 au_cell w 16 |
| 741 | au_decide c w |
| 742 | k = add k 1 |
| 743 | end |
| 744 | else |
| 745 | au_lost w |
| 746 | end |
| 747 | end |
| 748 | ret k |
| 749 | end |
| 750 | |
| 751 | note Creator: revoke the current authority. The generation moves on, so a |
| 752 | note pending or later proposal made under the old one is refused (5), and |
| 753 | note every granted tool still running is told to cancel. Its outcome is |
| 754 | note recorded as reported: performed if it had already exited, UNKNOWN if |
| 755 | note it was killed. Returns the new generation, or 0 with nothing changed |
| 756 | note when the journal refused REVOKE. |
| 757 | fn auth_revoke c long to ulong |
| 758 | g = add get augen 0 1 |
| 759 | if ne jn_rec 6 g 0 0 0 |
| 760 | ret 0 |
| 761 | end |
| 762 | put augen 0 g |
| 763 | r = mapset get aumap 0 8192 8 g |
| 764 | n = mapget c 48 8 |
| 765 | for w ulong n bound 64 |
| 766 | if and gt get swpid w 0 gt get aujob w 0 |
| 767 | au_ctl w au_cell w 16 |
| 768 | end |
| 769 | end |
| 770 | ret g |
| 771 | end |
| 772 | |
| 773 | note Creator: pause (on true) or resume. While paused no job is assigned and |
| 774 | note no proposal is decided; running tools go on. Every live worker gets a |
| 775 | note control notification and acknowledges it. Returns sched_pause's count, |
| 776 | note or -5 with nothing changed when the journal refused PAUSE. |
| 777 | fn auth_pause c long on bool to long |
| 778 | v = ulong 0 |
| 779 | if on |
| 780 | v = 1 |
| 781 | end |
| 782 | if ne jn_rec 7 v 0 0 0 |
| 783 | ret neg long 5 |
| 784 | end |
| 785 | r = mapset get aumap 0 8200 8 v |
| 786 | n = mapget c 48 8 |
| 787 | for w ulong n bound 64 |
| 788 | if gt get swpid w 0 |
| 789 | au_ctl w 0 |
| 790 | end |
| 791 | end |
| 792 | ret long sched_pause c on |
| 793 | end |
| 794 | |
| 795 | note Creator: cancel job j. 1 freed before it started (no effect), 2 its |
| 796 | note worker was told to cancel and the outcome comes from its report (a |
| 797 | note pending proposal is refused with 6), 3 already finished, 4 UNKNOWN, |
| 798 | note -3 no such job. CANCEL is journaled first; a job freed before it |
| 799 | note started is also released (outcome 300). -5 when the journal refused |
| 800 | note CANCEL (nothing changed) or that RELEASE (the job is freed, and the |
| 801 | note journal, now failed, releases it as cancelled at recovery). |
| 802 | fn auth_cancel c long j ulong to long |
| 803 | if ge j 64 |
| 804 | ret neg long 3 |
| 805 | end |
| 806 | id = get sjid j |
| 807 | if ne jn_rec 8 id 0 0 0 |
| 808 | ret neg long 5 |
| 809 | end |
| 810 | s = sched_cancel j |
| 811 | if eq s 1 |
| 812 | if ne jn_rec 5 id 300 0 0 |
| 813 | ret neg long 5 |
| 814 | end |
| 815 | end |
| 816 | if eq s 2 |
| 817 | w = get sjw j |
| 818 | au_ctl w sc_cell w 0 |
| 819 | end |
| 820 | ret s |
| 821 | end |
| 822 | |
| 823 | note Creator, after auth_new, jn_open and sched_new, before any spawn: |
| 824 | note settle and release from the journal (jn_recover), then install every |
| 825 | note journaled action into the action records, move the generation past |
| 826 | note every journaled one and restore the paused flag. 0 or an error. |
| 827 | fn auth_recover c long to ulong |
| 828 | e = jn_recover c |
| 829 | if ne e 0 |
| 830 | ret e |
| 831 | end |
| 832 | op = new ulong 4 0 |
| 833 | for k ulong 64 |
| 834 | if ne jn_act k 0 0 |
| 835 | for i ulong 4 |
| 836 | put op i jn_act k add 1 i |
| 837 | end |
| 838 | s = au_alloc op jn_act k 5 |
| 839 | if lt s 0 |
| 840 | ret 32 |
| 841 | end |
| 842 | b = mul ulong s 32 |
| 843 | put aurec add b 1 jn_act k 6 |
| 844 | put aurec add b 2 jn_act k 7 |
| 845 | put aurec add b 4 jn_act k 8 |
| 846 | end |
| 847 | end |
| 848 | put augen 0 jn_gen |
| 849 | r = mapset get aumap 0 8192 8 jn_gen |
| 850 | if ne jn_stat 2 0 |
| 851 | r = mapset get aumap 0 8200 8 1 |
| 852 | x = sched_pause c true |
| 853 | end |
| 854 | ret 0 |
| 855 | end |
| 856 | |
| 857 | note Creator: word i (0..31) of the action record for op, or -1 if none. |
| 858 | fn auth_act op view ulong 4 i ulong to long |
| 859 | k = au_find op |
| 860 | if or lt k 0 gt i 31 |
| 861 | ret neg long 1 |
| 862 | end |
| 863 | ret long get aurec add mul ulong k 32 i |
| 864 | end |
| 865 | |
| 866 | note Worker w's control or proposal cell word, for the creator's view. |
| 867 | fn auth_cell w ulong off ulong to ulong |
| 868 | ret au_cell w off |
| 869 | end |
| 870 | |
| 871 | note Copy up to 3968 bytes of worker w's tool output into dst; the count. |
| 872 | fn auth_wout w ulong dst edit uchar 4096 to ulong |
| 873 | n = au_cell w 120 |
| 874 | if gt n 3968 |
| 875 | n = 3968 |
| 876 | end |
| 877 | if gt n 0 |
| 878 | r = mapread get aumap 1 add mul w 4096 128 dst 0 n |
| 879 | end |
| 880 | ret n |
| 881 | end |