Skip to content

lab: the ledger's kernel_zero on the kernel's sched clock (#644) - #681

Closed
aledbf wants to merge 2 commits into
mainfrom
lab/644-ledger-anchor
Closed

aledbf wants to merge 2 commits into
mainfrom
lab/644-ledger-anchor

Conversation

@aledbf

@aledbf aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member

Why

The goal is a cold boot to the first SSH login in under 100 ms. The ledger is the instrument that says where the time before the kernel's clock goes. Its kernel_zero landed 19.5 ms (bench) and 12.6 ms (metal) after a marker the kernel writes at its clock's zero (#611). So qemu_start read that much long, and #611 first put ~23 ms in QEMU and the firmware that were not there.

What

The ledger took CLOCK_MONOTONIC's 0, which is the trace's and the journal's clock, for the kernel's 0. CLOCK_MONOTONIC runs on jiffies from timekeeping_init until the switch to kvm-clock at fs_initcall. It loses every tick it misses. At late_initcall the kernel prints both clocks as one tick read them (sched_clock: Marking stable (MONO, …)->(SCHED, …)). Their difference accounted for the whole error in all 24 boots of #611's runs, to within 0.15 ms.

  • internal/lab/ledger.go. The ledger reads that lag (monotonic_lag) and moves the trace and the journal forward by it. Every window is then on the kernel's sched clock, and kernel_zero is the sched clock's 0. A journal without the line refuses the ledger. The lag lands in the first window, the kernel's.
  • ledgerprobe.go records monotonic_lag.
  • Docs. Every number the late anchor gave is corrected, and each is listed below.

Proof: an instrument must see the phase it claims

The marker kernel (kernel/patches/0099 on exp/firmware-split-611) ran with this fix cherry-picked onto the lab-only branch lab/644-proof. Both runs use spin's shape, v20261123.04, QEMU traced and 10 boots. QEMU's trace stamps the 0xdf port write 0.03 to 0.14 ms after the ledger's kernel_zero (measured):

host lab run marker less kernel_zero, ms monotonic_lag, ms
bench 45229897350 +0.05 to +0.14 19.4 to 24.4
metal 45230233764 +0.03 to +0.14 11.9 to 13.8

Before the fix the same check read −19.5 and −12.6 (labs 45177818419, 45177817516).

Numbers that moved

All of these are recomputed from the runs' kept journals (measured):

No cold-budget row used the ledger's anchor. Two rows sit on clocks with errors of their own, now noted beside them with issues:

Closes #644.

🤖 Generated with Claude Code

aledbf and others added 2 commits November 23, 2026 14:38
…MONOTONIC (#644)

The trace and the journal are on CLOCK_MONOTONIC, which runs on jiffies
from timekeeping_init until the switch to kvm-clock and loses the ticks it
misses: 18-21 ms nested, 11-14 on metal. The ledger took its 0 for the
kernel's, so kernel_zero and qemu_start read that much late. The kernel
prints both clocks at one tick ("sched_clock: Marking stable"); the
ledger moves the trace and the journal forward by their difference, and
refuses a journal without the line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
measuring.md's split of lab 45110630795 recomputed with the lag, the
ledger section says what the trace's clock is against the kernel's,
the two cold-budget rows on clocks of their own note #665 and #666, and
log.md has the entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf

aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Replaced by 696: rebased onto main (a conflict in docs/boot-time.md's cold budget with #682/#695, both sides kept, the decompressor row now cites #645's −18.6); no force-push.

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.

lab: the ledger's kernel_zero is 13-20 ms late against a marker at the kernel's clock's zero

1 participant