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 / spec / omegese-cpu-workers.md

97 lines · 5561 bytes Raw Blame History Rendered
1# CPU worker facilities
2
3Status: DRAFT, ham/om-threads. Additive to OM-2 and the OM-3 draft. Not MERGED or DEPLOYED.
4
5## Scheduler words
6
7Program mode, AArch64 Linux and x86linux only. Function mode is error 9,
8x86efi error 25, a contract expression error 30. Every result is long,
9a successful kernel result or minus errno. No allocation or privilege change.
10
11| word | operands | kernel operation |
12|---|---|---|
13| cpuset | pid int, A byte array, off ulong, n ulong | sched_setaffinity |
14| cpuget | pid int, A writable byte array, off ulong, n ulong | sched_getaffinity |
15| cpunow | none | getcpu, CPU result only |
16| setprio | which int, who int, priority int | setpriority |
17| getprio | which int, who int | getpriority, raw kernel value 20 minus nice |
18
19The byte slices are checked before the syscall (trap 3). Affinity masks use
20Linux bit numbering, low CPU first. A zero pid means the calling thread, not
21all threads. cpuget returns the number of mask bytes copied, not zero.
22The kernel rejects a mask with no permitted online CPU with -22. cpuget needs
23a sufficiently large, machine-word-sized buffer. cpunow is a snapshot, not a
24promise about subsequent scheduling unless the thread has one allowed CPU.
25setprio retains ordinary Linux authorization checks; it does not bypass nice
26limits. which 0 is PRIO_PROCESS, who 0 the calling thread. Higher nice reduces
27priority. These words are effects, never contract predicates.
28
29Syscall authority: Linux asm-generic/unistd.h and x86 syscall_64.tbl.
30AArch64 numbers: 122,123,168,140,141. x86linux: 203,204,309,141,140.
31
32## Reversible decision
33
34Choose raw Linux scheduler operations and caller-owned buffers, not a hidden
35worker runtime or allocator. Existing host words already use checked slices and
36negative errno. Revert the additive host words and the benchmark caller to undo.
37Thread design and its checked-sharing/lifecycle evidence will be a separate head.
38
39## Gate
40
41seed/host/affinity/sched.cases uses the existing Omega OM-2 conductor. It checks
42inherited-mask selection, single-core observation, readback, invalid mask and
43pid, out-of-bounds slice, priority read/set/readback and invalid which. Compiler
44mutants replace setaffinity by getaffinity on both targets; invalid-mask check
45must catch both. x86 runs are EMULATED, not native x86 qualification.
46
47bench/omc_efficiency/run.om calls cpuset/setprio in its conductor child instead
48of launching taskset/nice. Other children and the coordinator retain their
49inherited scheduler state. Pool locking remains the launcher's responsibility.
50
51The priority child independently reads /proc/thread-self/stat field 19. Offset checks
52use off 9 with sentinels; AArch64 and x86 offset-removal mutants must fail at
53fixture exit 14. Set/get syscall-swap mutants must fail at exit 3. The fixture
54also pins the last inherited core and checks cpunow there (exit 17/18), so a
55cpunow that ignores the getcpu result fails even when the first inherited core
56is CPU 0; the AArch64 and x86 load-removal mutants must fail at exit 18. The
57last-core pin runs on every pool shape (on a one-core pool the last core is the
58first), so exit 18 holds on single-core pools too; only a one-core mask of CPU 0
59cannot tell a constant 0 from getcpu, and there the mutant rows fail. Under a nice 19
60pool setprio 0 0 19 is a no-op, so the priority child also asks for nice 18:
61without CAP_SYS_NICE the result must be -13 with nice still 19, and where it is
62allowed nice must read 18 and raw getprio 2 (exit 19 otherwise). The AArch64 and
63x86 mutants that hardwire the setprio operand to 19 must fail at exit 19. Caller cases
64compose the existing run.om helpers with only its main replaced: cpk1, runpk,
65child and selfpin run unchanged, then a real conductor child checks its single
66allowed core and priority. Invalid CPU 1024 is refused with exit 118.
67
68## Constant provenance
69
70WolframLanguageEvaluator query
71`Table[{w,FromDigits[Reverse[ToCharacterCode[w]],256]},{w,{"cpuset","cpuget","cpunow","setprio","getprio"}}]`
72returned `{cpuset,127979077595235}`, `{cpuget,127978876268643}`,
73`{cpunow,131320478265443}`, `{setprio,31359662648747379}`,
74`{getprio,31359662648747367}`. These are keyword encodings, not measurements.
75
76## Coordinator build and compatibility
77
78Build run.om with this head's seeded compiler, even when its BASE argument is
79an older compiler. BASE and CAND still select the benchmark arms; they do not
80select the compiler used to build the coordinator. This is an implementation
81addendum to the frozen OMC-EFF-4 driver description, not a change to its rounds,
82metrics, validity rules, affinity target or priority adjustment. The frozen
83protocol files and historical receipts are left unchanged.
84
85selfpin runs after child working-directory and stream setup, immediately before
86execprog. It preserves the former nice -n 19 adjustment, including an inherited
87negative nice: getprio gives raw = 20 minus nice, so setprio gets
88min(19,39 minus raw). WolframLanguageEvaluator
89`FullSimplify[20 - raw + 19 == 39 - raw]` returned True.
90The coordinator and unrelated subprocesses keep their inherited scheduler state.
91
92The priority oracle is /proc/thread-self/stat because the Linux word targets
93the calling thread. On the Spark's x86 emulator probe, /proc/self/stat supplied
94synthetic zero priority/nice fields while /proc/thread-self/stat reported
95priority 39 and nice 19, consistent with raw getprio 1. The per-thread oracle
96therefore preserves an independent kernel check on both targets instead of
97accepting the emulator's synthetic process record. No priority check is skipped.