What is the difference between CLOCK_MONOTONIC & CLOCK_MONOTONIC_RAW?

前端 未结 2 1567
予麋鹿
予麋鹿 2020-12-13 08:55

According to the Linux man page under Ubuntu

CLOCK_MONOTONIC
      Clock that cannot be set and  represents  monotonic  time  since
      some unspecified st         


        
相关标签:
2条回答
  • 2020-12-13 09:20

    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).

    0 讨论(0)
  • 2020-12-13 09:29

    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.

    0 讨论(0)
提交回复
热议问题