What is the difference between CLOCK_MONOTONIC & CLOCK_MONOTONIC_RAW?

我只是一个虾纸丫 提交于 2019-11-30 06:22:09

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/14270300/what-is-the-difference-between-clock-monotonic-clock-monotonic-raw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!