Clocks: Linux System Time vs TSC vs RTC

system time( date command) is rtc time.
but date application may not go to HW to get the time from RTC. It has its own userspace way of maintaining the time.

TSC is a free running timer which stat during boot , 7 seconds before kernel boot. that offset will always remain. To use TSC you should use clock_get_time(monotinic) api.
The normal way Linux maintains time counter like CLOCK_REALTIME or CLOCK_MONOTONIC does depend on the TSC rate, the origin is however arbitrary, so there is always at least an relatively large offset between the two.

As for drift, this depends on the use or not of NTP (or more generally of any method that locks the Linux clock on an external time reference). You basically have two cases:

  • No NTP, then TSC is 31.25 MHz exactly as measured by the Linux system time and Linux time and TSC do not drift, this is because there is no other reference, and the Linux realtime itself will drift against an external reference
  • NTP active, then TSC will appear to drift against Linux time, by an amount dependent on the instantaneous accuracy of the crystal, unless you use the fine tuning capabilities built inside TSC, basically you could have a SW level lock against an external reference to also make TSC appear to be exactly 31.25 MHz and also implicitly locked to the Linux time in that case. Observing 31.249 MHz corresponds to a frequency error of 32 ppm, this is not an impossible value, you could expect to observe any value between 31.25 +/- 50 ppm (the exact range depends on the quality of the crystal used, combined with aging and temperature effects).
    o The situation gets more complicated if you use SC7 and/or lock TSC on the 32,768Hz clock

RTC is normally synchronous with the 32,768Hz clock, and so will drift against both TSC and Linux time (32,768 Hz reference is independent of the crystal reference) and is automatically started at cold boot reset, so TSC and RTC have both a static offset and a drift against each other.

We will check more on the date application and report back.
Meanwhile request you to use clock_get_time to measure the time.

1 Like