Reputation: 38947
According to the Linux man page under Ubuntu
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since
some unspecified starting point.
CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
Similar to CLOCK_MONOTONIC, but provides access to a raw hard‐
ware-based time that is not subject to NTP adjustments.
According to the webster online dictionary Monotonic means:
2: having the property either of never increasing or of never decreasing as the values of the independent variable or the subscripts of the terms increase.
In other words, it won't jump backwards. I can see that this would be an important property if you were timing some code.
However, the difference between the normal and raw version isn't clear. Can someone shed some light into how NTP can still affect CLOCK_MONOTONIC?
Upvotes: 59
Views: 48111
Reputation: 93860
CLOCK_MONOTONIC
never experiences discontinuities due to NTP time adjustments, but it does change in frequency as NTP learns what error exists between the local oscillator and the upstream servers.
CLOCK_MONOTONIC_RAW
is simply the local oscillator, not disciplined by NTP. This could be very useful if you want to implement some other time synchronization algorithm against a clock which is not fighting you due to NTP. While ntpd (the reference implementation of NTP protocol and the most widespread NTP daemon) is reputed to be "gentle" with time adjustments, it's more accurate to say it's gentle with the absolute time. It's willing to slew the clock by 500ppm which is pretty dramatic if you're in a position to measure your clock frequency against some other standard.
The utility of CLOCK_MONOTONIC_RAW
is going to be limited until facilities like pthread_timedwait_monotonic
offer an option to use that timebase.
Upvotes: 51
Reputation: 21507
ntpd
doesn't cause the time to jump if the difference is below a certain threshold. adjtime-like adjustment is used instead, affecting both CLOCK_MONOTONIC
and CLOCK_REALTIME
(but not CLOCK_MONOTONIC_RAW
, apparently).
Upvotes: 3