roadmap BUILT

106. A wait that ends on either the interrupt or the deadline

Built 2026-09-26 (PR #1378). A Timer kernel object, Timer::ARM(deadline, notification) and CANCEL, on aarch64, riscv64 and x86_64, as §147 (a timer a userspace service cannot hold) ruled. The kernel owns the comparator and signals a notification at the deadline; a thread waiting on that notification, or blocked receiving with it bound, wakes on either.

Why this exists

There was no timed wait anywhere in the kernel. Every consumer that wanted to act at a time yielded in a loop instead, at a derived cost of about 10^5 to one against a timed wait (notes/timed-wait.md, section 5). The one that forced the question was net_stack: smoltcp's retransmits need a poll at a deadline, and the only way to get one was to keep a hart spinning through every backoff.

It waited, after §147 ruled on 2026-09-05 (calef, option 1, the new object), on the TCB binding of §101 (notification objects), which milestone 151 (notification objects) built (#1351). Until 2026-09-26 this block still gated on milestone 263 (can a userspace process hold a timer, on all three architectures), which was stale from the day §147 ruled: 263's answer was §147's input, not a separate gate.

The history of the fork is in §147 and in notes/timed-wait.md, which priced it. Milestone 51 (wall-clock time, the date command, and an NTP service) offered three shapes. calef preferred a userspace timer service on 2026-09-05, milestone 263 found riscv64 has no comparator U-mode can hold, and §147 ruled the same day.

What was built

piece where
objtype::TIMER = 5, abi::timer::{ARM = 0, CANCEL = 1}, and counter_ticks_for crates/moho_abi/src/lib.rs
the decision core: one deadline per timer, the cached earliest, the expiry walk crates/inter_process_communication/src/timer.rs
three Kani harnesses, each with a replayable falsification the same file, falsifications/timer.verification.*
the registry, ARM, CANCEL, the tick's one comparison, expire_timers, the region sweep kernel/src/sched.rs
Object::Timer, the system call arm, RETYPE_OBJ(TIMER) kernel/src/cap.rs, kernel/src/system_call.rs
timer_arm, timer_cancel, sleep_until, retype_sleeper crates/user_mode_runtime/src/lib.rs
five kernel tests, all three ISAs kernel/src/user/timer_tests.rs

The kernel tests prove what the harnesses cannot:

A fifth test measures the before and after.

CANCEL is §147's by implication rather than by name. §147 names only ARM, but the common case in notes/timed-wait.md section 2 is a retransmit timer thrown away when its ACK arrives. Without a cancel, a consumer would re-arm to a far deadline, which is a cancel spelled worse.

The consumers converted

consumer before after
std::thread::sleep yield until the counter passes ARM, then WAIT; the loop survives as a fallback
net_stack's wait_for_nic yield and re-poll across a retransmit window Irq::WAIT ends on a frame or smoltcp's deadline
the network time client's retry gap yield for 2 ms one tick asleep
swish's ^C watch yield between looks 10 ms asleep between looks

net_stack's notification is made and bound by its spawner (kernel/src/user/virtual_io_service.rs), because a running thread cannot bind itself. See the proposal below.

Confirmed, and still provisional

calef confirmed the surface on 2026-09-27 (UTC): objtype::TIMER = 5, Timer::ARM(deadline, notification, bits) = 0 and Timer::CANCEL = 1. He declined a slack argument after reading the prior art (Zircon's zx_timer_set, Mach's mk_timer, seL4's badge bits, Linux's timerfd, kqueue): "Keep it confirmed. We will build a slack if we need it."

Still provisional: the Object::Timer variant name, the TimerId type, the note name notes/timer.md, the module inter_process_communication::timer, and the runtime names timer_arm, timer_cancel, sleep_until and retype_sleeper.

What it cost, measured

The before and after: 200 ms asleep

From a_timer_sleep_costs_a_wake_where_a_yield_loop_costs_a_core, run on each ISA under QEMU on 2026-09-26 (patagonia, script/test --test timer_tests). The yield loop is the one thread::sleep ran until this milestone; the timer sleep is its new body.

ISA yield loop: yields yield loop: ticks charged timer: wakes timer: ticks charged
aarch64 69,951 20 of 20 1 0
riscv64 34,102 20 of 20 1 0
x86_64 53,087 (15,526 on the one-core leg) 20 (13) 1 0

So a sleeping thread went from a whole core for the duration, and tens of thousands of scheduler passes, to one wake and nothing charged. That is the 10^5 to one notes/timed-wait.md derived, measured end to end at the low end of its range on emulated cores; a faster real core spins more.

The IPC fastpath: unchanged within a few bytes

script/fastpath-footprint, release build, against the baselines milestone 151 recorded from CI. riscv64 and x86_64 are local runs and match CI's:

ISA ipc_call_reply ipc_send_recv system_call_entry (flat)
riscv64 6186 -> 6200 B (+14) 4854 -> 4862 B (+8) 1894 -> 1912 B (+18)
x86_64 8542 -> 8598 B (+56) 6512 -> 6560 B (+48) 1701 -> 1733 B (+32)
aarch64 7280 -> 7280 B (0) 5572 -> 5572 B (0) 1512 -> 1528 B (+16)

The closure grows by the Timer arm of invoke's object match, which the IPC roots pass through; timer_invoke itself is out of line. §147's scaffold measured system_call_entry at +12, +158 and +96 B. The aarch64 row is CI's (run 36276567183), because a local aarch64 build disagrees with CI's, as milestone 151 also found.

Instructions: icount, against milestone 151's CI figures

script/bench --check, TCG with icount, all three passing the 10% tripwire. The left figures are milestone 151's from CI run 36258812324 and the right ones this branch's on patagonia, so a small move can be build difference rather than this change.

ISA ipc_rtt call_reply ipc_rtt_el0
aarch64 1045327 -> 1045334 (+7) 1061673 -> 1061676 (+3) 11034763 -> 11050503 (+0.14%)
riscv64 171076 -> 171449 (+0.22%) 177534 -> 177534 (0) 1865150 -> 1866611 (+0.08%)
x86_64 17313622 -> 17313736 (+114) 17830619 -> 17827655 (-0.02%) not measured

The idle tick pays one relaxed load, one counter read and one compare, which notes/timed-wait.md section 3 priced at about 30 debug-build instructions per tick per core. It lands in benches long enough to span ticks, which is why only the _el0 row moves.

Proposed: binding a notification to yourself

A running thread holds no ThreadControlBlock capability to itself, so it cannot BIND a notification to itself. Milestone 151's handoff named this as 106's to propose. The options, with the seven questions answered, are in notes/timer.md ("Binding a notification to yourself: PROPOSED"). The short form:

Nothing in this milestone waits on the answer. The first consumer that might is timetable under milestone 129 (scheduled execution: a cron whose every entry is a grant).

BUGS

What it unblocks

Follow-on

Index row

Built 2026-09-26 on §147 option 1: a Timer object whose ARM(deadline, notification) signals a notification at the deadline, on all three ISAs, proved and falsified. thread::sleep, net_stack's retransmit window, the NTP retry gap and the shell's ^C watch no longer spin. Self-binding is proposed, not built.