SchOS/kernel/arch/x86_64
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz bbc512a51c time: read the clock from the TSC, not from counting interrupts
A timer interrupt that arrives while interrupts are disabled is not delayed,
it is lost -- the LAPIC in periodic mode holds one pending interrupt and drops
the rest. So anything the kernel does with interrupts off for longer than
10 ms makes `ticks` run slow, and it never catches up.

That has now presented twice as "uptime is wrong": once as an interrupt storm
taking 83% of the CPU, once as heavy console output on a display that is
expensive to draw to. Both times the tick was the messenger, and both times it
looked like a timekeeping bug.

monotonic() reads the TSC instead. It is a counter in the silicon that
advances whether or not this kernel is paying attention, it is already
measured against the PIT at boot, and reading it is one instruction and no
lock. wallclock(), /proc/uptime, sysinfo, getrusage and times() all go through
it now.

`ticks` keeps the job it is good at -- the scheduler preempts on it, sleep()
counts it -- where losing one means a slightly longer sleep rather than a
wrong answer about what time it is.

Lost ticks are no longer harmful, which makes them invisible, which is worse.
So /proc/interrupts now says

    timer: 3383 ticks taken, 3387 expected

and names the gap when it grows, because a machine dropping timer interrupts
is spending too long with interrupts disabled, and that is worth knowing
before it turns into a clock that lies.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
2026-09-13 13:57:26 +02:00
..
acpi.c acpi: take the RSDP from the loader when firmware gives it to us 2026-08-09 22:02:57 +02:00
e820.c boot: one hand-off contract, defined once 2026-08-10 21:37:36 +02:00
entry.S entry: enable SYSCALL on the UEFI hand-off path 2026-08-09 21:51:16 +02:00
entryother.S Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
ioapic.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
lapic.c time: read the clock from the TSC, not from counting interrupts 2026-09-13 13:57:26 +02:00
mp.c docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00
swtch.S Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
trap.c docs: four directories, and a rule for when a thing leaves the roadmap 2026-09-12 17:13:35 +02:00
trapasm.S Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
vectors.S Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
vm.c gfx: the console and the crash screen stop drawing on a driver by name 2026-08-15 17:04:10 +02:00