notes

Why the null system call slowed when more cores were busy

Name: ratified 2026-10-18 (calef, convention-rulings Rule 3).

Fatal risk 4's open finding from the 2026-10-04 radon evening, measured on 2026-10-04 (UTC) by the lane/null-system-call-contention lane. The cause and the fix were found under QEMU's TCG, which models no cache and no real inter-processor interrupt; radon then ran the fix the same night, and its result is PARTIAL by the thresholds written before it. 2026-10-05 (UTC): the rest was the lock, and radon measured milestone 761: the rise from one task to four fell from 48 ticks to 10.

The question

On radon the job mix's null_system_call job (64 traps that each bounce off an empty capability slot) cost 108 ticks at one task and 202 at four, while compute grew 6%. Past four it grew only 17% more by 32 tasks. Why does the cheapest system call nearly double when more cores are busy?

per_job is self-timed wall clock, so a task descheduled mid-job charges the wait to that job. But anything that arrives at a uniform rate in time (a timer tick, an IPI, a remote TLB fence) lands on a job in proportion to its length, so it charges null_system_call the same percentage it charges compute. The 6% is that baseline, and the excess, about 1.4 ticks (0.35 us) per trap, has to be paid per trap.

What a null system call touches that another core also writes

Read on all three architectures, from trap entry to return:

What Shared with other cores?
arch::exceptions::SVC_COUNT.fetch_add Yes, one line every system call on every core wrote. Read by the system tests, and by a riscv64 tour line that printed 0 on every captured boot
IPC_TABLES.lock() in sched::current_cap Yes, the kernel's one global lock, taken by every IPC, every schedule() and every capability operation
cpu::current(), held_rank Per core. But PERCPU is aligned to 8, at offset 16 mod 64 on riscv64 and 24 on aarch64, so neighboring cores' blocks share a line (not fixed; see BUGS)

The trap entry and exit assembly touch nothing shared, and a system call never reschedules on its way out (only an interrupt asks for preempt_if_needed). So the candidates were one shared counter and one global lock.

What TCG said

riscv64, script/job-mix --arch riscv64 --smp 4 --release, ticks of the 10 MHz timer. One run per row unless stated; two runs of the first row agreed within 2.5%.

Kernel null_system_call 1 / 4 tasks compute 1 / 4 tasks
main (two runs) 638 / 1,250 and 654 / 1,253 314 / 412 and 323 / 416
SVC_COUNT increment removed 657 / 1,203 328 / 428
...and current_cap reading without the lock (a racy experiment, never committed) 564 / 857 327 / 439

Taking the lock out of the path took away most of the excess; the counter was a small part of it. So the lock got instrumented. --features lock_wait (kernel/src/lock_wait.rs) counts, during the timed windows only, every acquisition that found a lock held and how long it spun, and every current_cap call:

current_cap at 4 tasks calls found IPC_TABLES held wait per call
before the fix 478,659 19.5% 9.94 ticks
at 1 task, for scale 119,659 6 calls 0.008 ticks

9.94 ticks a call is 636 ticks per 64-trap job, against a measured growth of 589 from one task to four in the same run. Waiting for IPC_TABLES was the whole of it, under TCG.

Who held it

A scratch hold-time table keyed by #[track_caller] call site (QEMU only, never committed) put finish_switch far ahead of everything else. Timing inside it found where: of 42.2 million ticks of finish_switch hold at four tasks, 41.2 million were inside threads.remove(prev), on 2,688 calls. That is one per child the spawn job reaps, at 0.3 to 1.5 ms each under TCG across two runs.

remove drops the Thread, and the Thread owns its kernel stack. Freeing the stack is six page unmaps, and each one discharges its TLB obligation on every other hart. On riscv64 that is an SBI remote fence, which interrupts every hart and waits for all of them; on x86_64 an NMI round. All of it ran with the global lock held and interrupts masked. A thread exiting anywhere stalled every IPC and every capability lookup on every core. The shape fits the radon finding. At one task nothing else exits while the null_system_call job runs. At four, other tasks' spawn jobs reap children throughout. Past four, the number of cores that can be waiting stops growing.

START had the mirror image: it built the new thread's stack (six pages mapped) under the same lock, at about 380 ticks a start under TCG, the second largest holder at 32 tasks once the reaper was fixed.

The fix

Each change has its reason in its commit message:

After the fix, same instrument, same machine:

At 4 tasks before after
current_cap wait per call 9.94 ticks 3.02 ticks (2.65 in a run with another lane's QEMU on the host)
all IPC_TABLES waits 18.9 M ticks 4.9 M ticks
reaper's hold, per reap 2,800 to 15,000 ticks (two runs) 12 ticks; the stack's 2,200 is now outside any lock

What is left holding the lock is the IPC path itself: schedule, CALL, REPLY, current_cap, each a few ticks a hold, roughly evenly. That is the contention ipc-tables-lock-inventory.md predicted, and its "free win" (capability tables off the global lock) is the next step, not this one.

What TCG could not say about this fix, and the procedure radon ran it by, are in the first radon run.

What radon said

Five boots on 2026-10-04 (UTC), power-cycled by calef: three of target/board-fix and two of target/board-lock-wait, built from b500b3d48. Transcripts are bench/radon-2026-10-04-fix/. Every boot printed one of 7 kinds, median of 21 repeats and job-mix: done.

per_job on the three boots of the kernel that ships, in 4 MHz ticks, against the 2026-10-04 sweep before the fix:

1 task 4 tasks 32 tasks growth 1 to 4
null_system_call, before 108 202 (195 to 207) 236 94
null_system_call, after 99, 99, 99 147, 146, 147 171, 170, 170 48
compute, after 2,409 2,547 to 2,552 2,898 to 2,917 5.8%

The fix removed about half the excess, so the reading is the middle row: PARTIAL. At four tasks the job fell from 202 to 147 ticks. Nine of those 55 ticks are the one-task cost falling from 108 to 99, which is the shared counter leaving the path, so the growth from one task to four fell from 94 ticks to 48. Taking out compute's preemption share (about 6 ticks either way), the per-trap excess went from about 1.37 ticks to about 0.66: 0.16 us of 0.34 us remains.

Throughput rose with it. jpm_median at four tasks was 932,371, 926,438 and 928,910 against 844,124 to 853,611 before (+9.4% on the medians); at 32 it was 997,945, 998,717 and 998,880 against 897,375 to 901,122 (+11.0%). One task moved 0.6%, so the gain is the multi-core part. The curve now reads 2.85x at four tasks and 3.07x at 32, against 2.62x and 2.78x.

Where the rest is, from boots 4 and 5

The instrumented kernel is slower (null_system_call 118 at one task and 342 to 345 at four; jpm_median 662,475 to 667,670 at four), so its ticks are not comparable with the boots above. That is the cost the module warned of: the clock is read only on the contended path, and at four tasks that path is taken 41% of the time. Its counts are what to read.

At 4 tasks, boots 4 / 5
current_cap calls that found IPC_TABLES held 41.4% / 41.8% (0.015% / 0.012% at 1 task; 51% at 32)
IPC_TABLES share of all lock wait 95% (2,593,130 / 2,646,216 ticks)
current_cap's share of the IPC_TABLES wait 28% (734,022 / 744,371 ticks)
mean wait per contended acquisition 3.70 ticks at current_cap, 3.80 everywhere else
reaper: stack free per reap, no lock held 167 ticks, 42 us (149 at one task)
reaper: removal under IPC_TABLES per reap 2.8 ticks

So the reaper's share is gone on silicon too: the 42 us a reap held the global lock for is now spent holding nothing, and its last critical section is 2.8 ticks. What remains is ordinary contention for IPC_TABLES itself. Four cores run IPC, schedule() and capability lookups through one lock, and nearly half of all acquisitions find it held. The other 72% of the wait belongs to the lock's other acquirers, the hot rows of ipc-tables-lock-inventory.md. They are ipc_call, ipc_receive_cap and ipc_reply (the round_trip job and its two echo servers). They are schedule() twice per switch and finish_switch (the yield job and every block). And they are take_ipc_aborted after each IPC. TCG's hold-time table after the fix put the same ones on top, with start_thread_control_block. KERNEL_MMU (rank 45) now shows 2,800 contended acquisitions a point: the stack frees and builds moved out of IPC_TABLES meet each other there, at 1.6% of the wait.

The next step: each thread's table off the lock

Milestone 761 (capability lookup off the global lock) gives every thread's capability table its own lock, so current_cap stops taking IPC_TABLES. Under TCG the lookups that waited fell from about 20% to almost none.

The radon run that decides it

Boots 1 to 3 of the kernel that ships, read against 99 and 147 from bench/radon-2026-10-04-fix/; boots 4 and 5 with lock_wait, read for site=current_cap and rank=60 name=ipc_tables at four tasks. What each outcome means, written 2026-10-04 (UTC) before any boot:

Boots 1 to 3, null_system_call at 4 tasks Reading
115 or below it worked: the remainder is about compute's preemption share (about 6 ticks) over 99. Risk 4's per-crossing cost under load is explained
116 to 135 partial: the lock was part of the rest. Boots 4 and 5 say whether current_cap still waits (it should not) and what the IPC rows still cost the cores
136 or above the lock was not radon's remaining cause. If boots 4 and 5 show current_cap contention near zero and the job did not move, suspect the line traffic no counter sees (BUGS, PERCPU)

One guard on the single-task cost, since a lock path dearer when uncontended would hide inside the four-task number. null_system_call at 1 task above 101 (99 today, plus 2%) is a regression to explain before any row above is claimed.

Is the rest the lock? Measured 2026-10-05 off radon

Milestone 761 reached main inside #1617 before #1630 landed, so this compares main with an ablation that puts IPC_TABLES back around the lookup and changes nothing else. The appendix has the questions and both tables.

What radon said on 2026-10-05

Nineteen boots, built from c8b5fd09e with 761 and 766 in it, by a run sheet (nifeos/nife:bench/radon-2026-10-05/RUN-SHEET.md) written before any boot. The appendix has every table.

main, three boots 1 task 4 tasks growth 1 to 4
2026-10-04 99 147 48
2026-10-05 110 120 (120, 121, 120) 10

What risk 4's line should say

For the maintainer, who owns design/fatal-risks/README.md. The color is calef's ruling. This lane proposes replacing the open finding's last three sentences ("The rest is the one global lock itself ... half explained and half open") with:

The rest was the same lock on every capability lookup, which milestone 761 removed, and false sharing between cores' per-core blocks, which milestone 766 (each core's PerCpu on its own cache line) removed. On radon (2026-10-05) the null system call's growth from one task to four fell from 48 ticks to 10, half of it the preemption every job pays; undoing 766 alone puts back 7.5. One caveat travels with every single-crossing number on radon: moving the kernel's text by a few bytes, with no code change, moves the null system call by up to 8 ticks (7%), so builds are compared on growth, not level (notes/job-mix/null-system-call-under-load.md).

BUGS

Proposed work