As a preface, we need to establish the difference between accuracy and precision when it comes to clock sources.
Accuracy is how close to real time you are on average, or as you say, what has the least drift. A clock that can tell you when an hour, or a day, or a year has passed and be very close to those time periods is accurate.
Precision is how tightly packed things are. A clock that can tell you when very tiny periods of time has passed is precise.
The two characteristics are very often in opposition - error compounds.
The HPET, for example, has precision right in its name. An HPET is good for when you need to time very small periods, but is not necessarily accurate over longer periods.
Another clock that is precise is the TSC. TSCs in a number of early x86/x86-64 processors had issues with consistency in different power modes, or across multiple CPUs/cores, but for at least a decade or so Intel and AMD CPUs have had constant and invariant TSCs. On such systems, Linux prefers the TSC as the primary clock source. As an aside, APIC timers are generally TSC-linked, so they're effectively the same clock but as an interrupt source.
But, neither of these are necessarily accurate over long times (though they are really good!), and if you turn off the computer you lose track of time.
This is where the RTC comes in. x86 CMOS RTC is generally good for accuracy, but not precision. While you can get it to generate interrupts at up to 8kHz, maybe even 32kHz, you can only reliably read it at 1-second precision, so you have to keep track of those higher-precision numbers yourself if you want them, and at that point you're better off with something else.
And then there's the PIT, which is... really not that bad as a clock source? Generally they're within 1 or 2 seconds of drift each day, which isn't too bad. But they have their own oscillator that operates at a much a looser frequency than an HPET or TSC, and they don't have passive counter options like the HPET, TSC, and RTC.
But we've neglected one clock source: NTP. If you have access to a network, NTP can offer significantly better accuracy than an RTC, better precision than the readable counter in the RTC, and doesn't require a battery backup or active power consumption to keep time. Referencing Linux as an example again, a typical x86 setup will use the TSC as the local clock source, use the RTC as a boot timestamp until network is available, and use NTP to regularly synchronize for accurate time.
So what's the most accurate clock on x86? The network card.
tldr: lol they're all actually about the same as they typically all use the same crystal source (or at least the same type of crystal), so expect ~20ppm (~2s/day) for anything. If you want accuracy, use NTP.
_________________ toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor
|