1eef391Sep 6, 2026 · bluetoothpaste
kcore, nightwatch: a claim is taken when it is published, not when patience runs out
A K-Core's queue is filled in two steps: the producer claims a position
with a compare-and-swap on `tail`, and publishes it afterwards by storing
the process pointer into the slot. Between the two the position belongs
to the producer and to nobody else — and that gap is not small
everywhere: on the board it can hold an SMI, on the stand a descheduled
vCPU. The consumer read `tail` as well as the slot, and when the tail
said "claimed" while the slot still said "not yet" it waited a million
spins and then MOVED HEAD PAST THE CLAIM: it took the position from
under a producer that was still walking up to it. The pocket was then
published behind the head, where nobody would ever look; its owner kept
kcore_pending set, so no later notify of its own could submit it again;
and it waited for an answer to a question nobody would ever open. The
warning it printed on the way was debug_printf, which the shipped kernel
compiles to nothing; the count it decremented had not been incremented
yet, so every depth in the machine read 0xFFFFFFFF until the producer
caught up. And 4096 claims later the head would have come round to that
stale pointer and served a dead entry as a fresh one.
The consumer now owns `head` and judges nothing but the slot there. An
empty slot means "nothing to take" whether nothing was claimed or a claim
is still in flight — the consumer cannot tell and does not need to: the
head stays, the run loop goes round, and the sleep gate reads `count`
under CLI. `count` now rises at the claim rather than after the publish,
so it says "claimed and not yet consumed": a claim in flight keeps the
K-Core awake and it comes back to the slot; a queue with nothing claimed
lets it sleep, and the producer's IPI, sent after the publish, wakes it.
A stalled producer costs the consumer exactly the stall and nothing else.
The fence between the publish and the doorbell stays where it was, and
its reason is now written down: in x2APIC mode the doorbell is a WRMSR
to the ICR, which may complete before the slot store is globally visible
(Intel SDM Vol 3A §10.12.3). KCORE_POP_SPIN_LIMIT and its unused twin
in kernel_config.h are gone.
Nightwatch could not have named this. The strand that loses a submit
spins in result_wait on PAUSE (no WAITPKG on this stand, and WAITPKG
keeps it on the CPU anyway), so it is always on a CPU — and POCKET
UNSERVED was gated on being OFF one, while ANSWER OWED steps over a
strand whose kcore_pending is set. Neither spoke; the machine simply
stopped. The off-CPU gate was, by accident, also what kept the proof
from convicting a shell whose proc_exec is being served for minutes off
a slow medium — the guide pops a pocket only after finishing with it, so
the pocket stands at the head the whole time. The fact that separates
those two is the K-Core's own knowledge of whom it serves: each queue
now records the strand inside guide_process_one, and POCKET UNSERVED
asks that record instead of the CPU.
logcheck kcoreclaim widens the gap from both sides: every application
submit stands claimed and unpublished for two milliseconds (the display
daemon and the shell are left alone so the machine stays typeable), and
the K-Cores never sleep, so the consumer is awake to meet every one of
them — without that second half the meeting was a coin toss, and the
staged loss struck the first bench in one run and the third in the
next. bench must complete three runs on sixteen cores, no verdict.
kcoreclaimmut puts the old consumer back — its patience cut from a
million spins to a thousand, because the shape is the defect and not the
number: any patience loses to a producer delayed longer, and an SMI is
not consulted about how long it may take — and requires the machine to
stop short of three runs and Nightwatch to say why: POCKET UNSERVED.
yieldrace and yieldracemut are retired: their anchor was the guide's
yield branch, which the previous commit removed, and the two-consumer
race they staged is impossible by construction now that the yield is
not a pocket.
The first full matrix under this change passed six of six and showed
the second thing Nightwatch could not do. UEFI STRICT 16c printed ten
POCKET UNSERVED verdicts against the shell's very first pocket, every one
of them "at uptime 0 ms": the watch kept its time by the ClockBoard's
uptime, which is the PIT tick count mirrored for userspace, and that
count stands at zero until IRQ0 first reaches the BSP — after userspace
has started on a big machine. Zero was also the rate limiter's "never
looked", so every idle turn looked, "two consecutive looks" were
microseconds apart, and a pocket in flight for a moment while the
K-Cores were still starting was convicted. The off-CPU gate had hidden
this too. The watch now keeps time by pit_get_uptime_ms — the HPET main
counter where there is one, running from hpet_init — does not look at all
while the clock reads zero, and judges persistence by TIME: a suspect
carries the moment it was first seen in its position and is stuck only
when that is a full NIGHTWATCH_LOOK_MS ago, whatever the limiter does.
Measured. The queue change went through the full matrix — BIOS and UEFI
× 1c/4c/16c, STRICT, fresh image — 6/6 with zero panics; it was that
matrix's UEFI 16c log that showed the ten boot-time verdicts and led to
the clock. The clock change was then checked where it had failed: a
UEFI STRICT 16c boot with bench twice, hw, and 25 s at an idle prompt
prints no EVIDENCE block at all and no verdict. logcheck kcoreclaim is
PASS 3/3 (three completed bench runs, no verdict); kcoreclaimmut is
PASS 2/2, the first bench never completing and Nightwatch saying "pid 3
gen 1 working — POCKET UNSERVED: ring head=67 tail=68, kcore_pending=1"
— a strand ON a CPU, which the old gate would have passed over. An
earlier shape of the mutation without the awake K-Cores lost the third
bench instead of the first, and counted the row at risk instead of the
completion row; both are fixed and the shapes are described in the
scenario.