Skip to content

feat(time,syscall): add CMOS RTC wall clock, HPET ns clocks, itimers, and POSIX timers (N2.6b, #66) - #146

Merged
YUZHEthefool merged 1 commit into
mainfrom
feat/n2-6b-timers-and-clocks
Nov 28, 2026
Merged

YUZHEthefool merged 1 commit into
mainfrom
feat/n2-6b-timers-and-clocks

Conversation

@YUZHEthefool

Copy link
Copy Markdown
Member

Summary

Completes #66 N2.6 (Signals & Timers) with N2.6b (Timers & Clocks):

  • Single syscall table & Linux x86_64 ABI pinning:
    • Declared getitimer(36), alarm(37), setitimer(38), timer_create(222), timer_settime(223), timer_gettime(224), timer_getoverrun(225), timer_delete(226), clock_getres(229), and clock_nanosleep(230) in kernel/seccomp/syscall_table.rs and wired exhaustive DispatchedSyscall arms in kernel/kernel_core/syscall/mod.rs.
    • Added #[repr(C)] ITimerVal (32B), ITimerSpec (32B), and SigEvent (64B) in kernel/kernel_core/syscall/abi.rs and pinned all three in scripts/tools/abi_layout_oracle.py (Leg A/B/C vs native x86_64 <time.h>, <sys/time.h>, <signal.h>).
  • CMOS RTC wall clock & HPET nanosecond monotonic timekeeping:
    • Added MC146818 CMOS RTC boot reader (read_cmos_rtc_unix_secs with bounded UIP wait, double-read consistency, BCD/binary + 12h/24h decoding, and Howard Hinnant Gregorian-to-Unix epoch conversion) and 64-bit HPET nanosecond counter provider (elapsed_ns, resolution_ns) in kernel/arch/hpet.rs, registered during boot in kernel/src/main.rs.
    • Added strictly monotonic monotonic_ns() (fetch_max floor), wall-clock realtime_ns(), and clock_resolution_ns(coarse) in kernel/kernel_core/time.rs.
    • Updated clock_gettime, gettimeofday, and FUTEX_CLOCK_REALTIME / FUTEX_LOCK_PI absolute deadlines in kernel/kernel_core/syscall/futex.rs so realtime clocks use wall-clock Unix epoch ns while monotonic clocks stay monotonic uptime ns.
    • Implemented clock_getres(229) (including NULL res validity query) and clock_nanosleep(230) (relative + TIMER_ABSTIME across CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_BOOTTIME, with POSIX rem write-back on relative EINTR only).
  • Zero-PCB-bloat interval timers & POSIX per-process timers:
    • Added an out-of-line bounded TimerRegistry in kernel/kernel_core/time.rs (MAX_POSIX_TIMERS_PER_PROCESS = 32, zero bytes added to Process or ThreadGroup) with a lock-free single-load NEXT_TIMER_EXPIRY_NS IRQ fast path in on_timer_tick() and process-context deferred signal delivery (drain_deferred_process_timers() in kernel/kernel_core/scheduler_hook.rs).
    • Implemented alarm(37), getitimer(36), setitimer(38) (ITIMER_REAL one-shot & periodic SIGALRM; ITIMER_VIRTUAL/ITIMER_PROF queryable/disarmable and EOPNOTSUPP on non-zero arm), and timer_create/timer_settime/timer_gettime/timer_getoverrun/timer_delete (SIGEV_SIGNAL, SIGEV_NONE, SIGEV_THREAD_ID, TIMER_ABSTIME, periodic overrun tracking, SI_TIMER + sigev_value delivery).
    • Enforced POSIX lifecycle semantics: fork does not inherit timers, execve deletes POSIX timers while preserving ITIMER_REAL (cleanup_posix_timers_for_exec), and last-live-thread exit reclaims all timers (cleanup_all_timers_for_process).

Verification

  • cargo fmt --all && make fmt-check — PASS
  • make abi-check — PASS (16 structs, 131 values, 17 tripwires, C-leg: run)
  • make lint — PASS
  • bash scripts/tools/hosted_subcrate_tests.sh — PASS (kernel-core 231/231, arch 11/11, seccomp 20/20, lsm-hook-census 5/5, mitigation-mappings 5/5)
  • make clippy && make build — PASS
  • ZERO_OS_STRICT_TESTS=1 bash scripts/gates/boot/boot_check.sh — STRICT PASS (50/50)
  • ZERO_OS_STRICT_TESTS=1 SMP_CORES=4 bash scripts/gates/boot/kernel_test.sh — STRICT PASS (50/50)
  • make test-ring3-mm — PASS
  • make test-kcov — PASS (KCOV-E2E PASS)

Part of #66

@github-actions github-actions Bot added area: boot Bootloader, early boot, kernel entry, and image layout area: arch/x86 x86_64 interrupts, context switch, APIC, SMP, and TLB operations area: process/ABI Processes, syscalls, usercopy, signals, ELF, and Linux ABI area: scheduler/concurrency Scheduling, CPU-local state, synchronization, RCU, and lock ordering area: security Capabilities, LSM, seccomp, audit, hardening, crypto, and livepatch area: tooling/CI Build system, scripts, hooks, automation, and repository tooling size: XL At least 1000 review lines, excluding generated/binary artifacts enhancement New feature or request labels Nov 28, 2026
@YUZHEthefool
YUZHEthefool merged commit 6f142fe into main Nov 28, 2026
17 checks passed
@YUZHEthefool
YUZHEthefool deleted the feat/n2-6b-timers-and-clocks branch November 28, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: arch/x86 x86_64 interrupts, context switch, APIC, SMP, and TLB operations area: boot Bootloader, early boot, kernel entry, and image layout area: process/ABI Processes, syscalls, usercopy, signals, ELF, and Linux ABI area: scheduler/concurrency Scheduling, CPU-local state, synchronization, RCU, and lock ordering area: security Capabilities, LSM, seccomp, audit, hardening, crypto, and livepatch area: tooling/CI Build system, scripts, hooks, automation, and repository tooling enhancement New feature or request size: XL At least 1000 review lines, excluding generated/binary artifacts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant