Skip to content

Add fixed time partitions to the scheduler - #11

Merged
Quant-TheodoreFelix merged 3 commits into
mainfrom
time-partitions
Nov 21, 2026
Merged

Quant-TheodoreFelix merged 3 commits into
mainfrom
time-partitions

Conversation

@Quant-TheodoreFelix

@Quant-TheodoreFelix Quant-TheodoreFelix commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

What and why

Adds fixed time partitions. Until now one task could change when another task ran through the scheduler, which is a channel between tasks that should not be able to signal each other. With a partition table, a domain runs only in its own windows, and what the other domains do does not change which of its tasks run or in which order.

  • Domains and the table: a table of up to 16 entries names a domain (0 to 7) and a number of ticks (1 to 255) per entry. The tick stays 1 second. Time left over in a window is not given to another domain, the CPU waits.
  • Always compiled in: with no table set there is one domain, and the scheduler makes the same decision as before for the same sequence of events, when no tick is skipped.
  • New crate k0-part: the pure core (Core) and the clock arithmetic. k0-sched is the glue around it. Each domain has its own ready queue and its own list of timed waiters. A timeout is served only when its domain runs, so it can fire late and never early.
  • Guard and hold: the interrupt of a tick that changes the domain is taken one fortieth of a tick early. The kernel does the switch work and then holds until the tick instant. Every return to EL0 passes one exit check (k0_leave).
  • Authority: the capability PartCtl (kind 9, boot slot 5) cannot be copied. PART_SET_TABLE (17) and PART_SET_DOMAIN (18) need it. Deleting it seals the table and the domains until the next boot.
  • Interface: bootinfo is version 5, the first untyped slot is 6, and the root CNode has 1024 slots in every image (the cargo feature root-cnode-1024 is gone). Images built for the previous main are not compatible.
  • Self-test: the root task tests refusals and one round of a nine tick table at every boot, then deletes PartCtl. So every image built today runs sealed with one domain. No image uses more than one domain yet.
  • Proofs: proofs/lean holds Lean 4 proofs about an abstract model of the scheduler. They are not proofs about the Rust code and are not run in CI. A host test ties the two together: it runs 1600 recorded scripts through the Rust Core and compares each with the model's result.

The claim is narrow: fixed time partitions close the channel between domains that goes through the scheduler. design/en/scheduling.md and SECURITY.md state it with its limits.

How it was tested

  • tools/host-test.sh
  • tools/qemu-boot-test.sh
  • New or changed behavior has a test

Details:

  • Host tests: 415 pass on an AArch64 host (327 on other hosts, without k0-mm), also from a git archive export of the branch. k0-part has 36: property tests of the real Core (two runs with different workloads in the other domains give a domain the same trace, window bounds, no donated slack, the default table against a frozen copy of the old scheduler), clock arithmetic, and the recorded scripts of the Lean model.
  • Boot matrix: all 82 rows of tools/boot-matrix.sh pass locally (Apple M5 Pro, QEMU 11.1.3, K0_MATRIX_HVF=1), with no retry of the window test. tools/qemu-boot-test.sh runs as the judge of its pass rows.
  • CI: the run for this pull request passed on both runners: the host tests (415 on the ARM runner, 327 on the other), and all 71 rows of the boot matrix on QEMU 7.2 with no retry of the window test. The jobs took 30 and 33 minutes of the 45 minute limit.
  • Lean: lake build has no error and no warning, leanchecker accepts the five modules, lake exe vectors --check finds no difference in the 1600 scripts, and an external type checker (nanoda) accepts all 60911 exported declarations.
  • Broken kernels: two deliberately wrong kernels were booted in a scratch copy and both fail the window test. One expires the timeouts of every domain at every tick, the other lets a cut task run on in the window of an empty domain.
  • Review: three reviewers (isolation, timer and kernel paths, interface and tests) and two re-checks of the proofs found no code defect above low severity. Sentences of the proof README that said more than the theorems were corrected. One of them ran a fixed workload in one domain under several different workloads in the other domains on the real kernel, with two tables, and the order of that domain's events was the same in every run.

Not covered:

  • No test sees the guard, the hold or the TLB flush at a change of domain. They change only timing, and EL0 has no clock to time them. Removing any of the three leaves every test passing.
  • The rule that console input reaches a waiting reader only in the reader's own window has no test.
  • The changes made after the review were tested but not reviewed again: interrupts are masked at hand-off before the tick is read, the WFI and WFE trap passes the exit check, the stop line is printed under a table, the self-test has two more checks, and tools/boot-matrix.sh runs a row again when its window test retried. The matrix had no retry, so that second run was never taken, and the WFI and WFE trap path was not exercised.
  • k0-sched, k0-ipc and the kernel glue still have no host tests.
  • The proofs are about a model. Nothing ran on real hardware.

Security notes

  • Unsafe: 30 new or changed blocks in the kernel and its crates, each with its // SAFETY: comment. The largest part is the rewritten scheduler glue.
  • Trust boundaries touched: the system call boundary (two new calls, both refused without PartCtl) and the timer interrupt path.
  • New kernel state reachable from EL0: the partition table and a task's domain, both only through PartCtl. A task without it can change neither.
  • Dependencies: none from outside the workspace. The new crate k0-part depends on k0-slice.
  • Limits that stay:
    • A kernel path longer than the guard that is in flight when the guard starts delays the next window (CAP_REVOKE, large deletes).
    • Caches and branch predictors are not flushed.
    • The time of console input interrupts and of the UART work in the tick handler lands in whichever domain runs.
    • Kernel state other than the scheduler is shared: the UART and the boot log, the single console waiter slot, the kernel memory pools.
    • A stall longer than a tick skips windows.
    • An endpoint shared across domains is a channel by design, and so is any other capability operation on an object shared with another domain.
    • A task woken by console input inside the guard of an empty incoming window still skips its first tick rotation. This stays inside its own domain.
  • Policy text to confirm: the documents add a severity line for time partition findings to ci/threat_model.md and one sentence on which reports are welcome to SECURITY.md.
  • Advisories: no status is changed here.

AI assistance

The design, the code, the tests, the proofs, the tools and the documents in this pull request were made with Claude (Anthropic). Claude agents reviewed the design, the code and the proofs, and wrote the documents, and their confirmed findings were fixed. The scope and the design decisions were chosen by the maintainer. The results under "How it was tested" are from real runs on the machine named there.

Contributor License Agreement

  • I have signed the CLA. If this is the first pull request that needs your signature, comment the sentence from CONTRIBUTING.md on this pull request. The CLA signatures check shows who still needs to sign.
  • Or: every change in this pull request is trivial as defined in section 12 of the CLA.

Quant-TheodoreFelix and others added 3 commits November 21, 2026 16:08
- Domains run in windows of whole ticks from a table that the `PartCtl` capability sets
- The new crate `k0-part` holds the pure core and the clock arithmetic
- A tick that changes the domain is taken early and the kernel holds until the tick instant
- Bootinfo is version 5 and the root CNode has 1024 slots in every image
- The root task tests refusals and one round of windows at boot and then seals the table

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
- Five files under `proofs/lean` prove properties of an abstract model and not of the Rust code
- `ModelVectors.lean` writes the recorded scripts that the host test of `k0-part` compares with

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
@Quant-TheodoreFelix
Quant-TheodoreFelix merged commit 1e4d69e into main Nov 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant