Skip to content

feat(time): monotonic uptime + high-resolution clock for userland (#467) - #700

Merged
alexis900 merged 1 commit into
developfrom
feat/467-monotonic-clock
Oct 13, 2026
Merged

alexis900 merged 1 commit into
developfrom
feat/467-monotonic-clock

Conversation

@alexis900

Copy link
Copy Markdown
Collaborator

Fixes #467.

What

Ring 3 gets a monotonic clock. ObInfoClass::Uptime (46) returns { uptime_ms: u64, tick_hz: u32, _pad } and HighResTime (47) returns { tsc: u64, tsc_khz: u32, _pad }, matching docs/design/monotonic-clock-design.md.

  • Kernel: hal::uptime_ms() from the single BSP-only tick counter (monotonic, SMP-safe); net::tcp::tcp_high_res_time() (calibrated TSC) — routed through the baselined module because boot_benchmark is not importable from hal/syscall (same precedent as tcp_deadline_from_ms). Query arms in syscall/ob/query/time.rs.
  • libneodos: ob_uptime() / ob_uptime_ms() / ob_high_res_time().
  • userbin/uptime: up 0h 1m 22s (monotonic 82739 ms, tick 1000 Hz); -r raw ms; -v high-res TSC.
  • Bug fixed: timers::register_hal_hooks reported the tick rate as 1e9/TICK_INTERVAL_US = 1 MHz although the period is 1000 us (1 kHz). Ticks-to-ms was 1000x too small and services::deadline_from_now produced 1000x-too-long shutdown deadlines. Now 1e6/TICK_INTERVAL_US = 1000 Hz.

Acceptance (#467)

Verification

  • QEMU neodev test: 956/956. VirtualBox neodev test --backend virtualbox: 956/956.
  • Guest (VBox NAT, e1000): uptime -> up 0h 1m 22s (monotonic 82739 ms, tick 1000 Hz); uptime -v -> high-res: tsc=... tsc_khz=2707983.
  • check-deps clean; check-irq-locks OK.

Note

Full packaging requires the one-line NeoDev image-allowlist addition (uptime), same as netcli/netsrv/tcptest (separate repo).

- hal: uptime_ms() from the single BSP-only timer tick counter (monotonic,
  SMP-safe) returning (ms, tick_hz).
- net/tcp: tcp_high_res_time() (calibrated TSC + kHz), routed via the baselined
  module because boot_benchmark is not importable from hal/syscall.
- ObInfoClass::Uptime (46) = {uptime_ms, tick_hz}, HighResTime (47) = {tsc, tsc_khz}.
- libneodos: ob_uptime()/ob_uptime_ms()/ob_high_res_time().
- userbin/uptime: shows 'up Xd Xh Xm Xs (monotonic N ms, tick H Hz)'; -r raw ms,
  -v high-res.
- timers: fix the HAL tick rate (1e9/TICK_INTERVAL_US -> 1e6/TICK_INTERVAL_US).
  The period is 1000 us (1 kHz) but the rate was reported as 1 MHz, making
  ticks->ms 1000x too small and service shutdown deadlines 1000x too long.
- tests: sys_uptime_monotonic, sys_highres_time_advances.
- docs: mark the monotonic-clock design Implemented.

Verified: QEMU 956/956; VirtualBox 956/956; guest 'uptime' ->
'up 0h 1m 22s (monotonic 82739 ms, tick 1000 Hz)' + high-res TSC.
@alexis900
alexis900 merged commit 7445965 into develop Oct 13, 2026
3 checks passed
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.

[KERNEL] Monotonic uptime / high-resolution clock for userland

1 participant