Module Time_utils.Clock

Clocks.

Both are clock_gettime via C stubs. The distinction matters and is not stylistic: now_monotonic_ns never decreases and is the only one safe to subtract, while now_realtime_ns tracks the wall clock and can step backwards.

There is no cycle counter here, deliberately. Reading a TSC is architecture-specific and needs a calibration this project does not perform, so rather than offer an interface that implies the capability, there is none. Use now_monotonic_ns.

val now_monotonic_ns : unit -> int64

Monotonic nanoseconds. Never decreases, so differences are always non-negative.

The epoch is unspecified — the absolute value means nothing and only differences are defined. This is the clock to measure any duration with.

val now_realtime_ns : unit -> int64

Wall-clock nanoseconds since the Unix epoch.

Steps. NTP correction, a manual clock change or a VM resume can move it backwards, so subtracting two readings can yield a negative duration. Use it for timestamps a human or an audit record will read, never to measure elapsed time.