1. clock
- Wall clock; Used to represent date and time; After synchronization, the local clock of our server can jump backward or forward in time
- Monotonic clock; Used to calculate duration; The time ALWAYS moves forward and will not be impacted by variations leading to jumps in time
2. Wall clock
- Linux uses UTC as wall clock
- UTC is not accurate because earth's rotation speed varies
- UTC does not contain Leap Second, so Linux adjust the UTC time to real earth rotation by inserting leap seconds into UTC time scale
3. Wall clock Synchronization
- Normal solution: synchronize with NTP (Network Time Protocol). Because of the network delay, there will be at least a 35 millisecond deviation, and the maximum may exceed 1 second.
- Good solution: receive accurate wall time with GPS, synchronize with other servers via PTP, and can achieve sub-microsecond precision
- Google solution: Google uses a GPS receiver to receive a standard wall clock, and then deploys the atomic clock through the computer room, so that its accuracy can reach an error of only 1 second every 20 million years, in this way to prevent the failure of the GPS receiver. Send accurate time to other servers with TrueTime API
- Google Spanner (distributed database) is based on this.
4. Resolve Leap Second Issues
- Bad Solution: notify the kernel, and allow it to insert the leap second, which cause stepping the system clock backwards
- Good Solution: Slew the leap second (since RHEL 6.8 and RHEL 7.2), allowing this second to be spread out over a period of time instead of an immediate step back in time
5. How computer manage time?
- Clock interrupts is based quartz crystal oscillator. Computer update the wall time during each clock interrupt
- How to deal with 1 microseconds (small precision)?
BogoMIPS
Ref:
https://access.redhat.com/articles/15145
https://itnext.io/as-a-software-developer-why-should-you-care-about-the-monotonic-clock-7d9c8533595c
https://donggeitnote.com/2021/06/23/clock/