Bug #13354
closedillumos should calibrate the TSC earlier in the boot process.
100%
Description
- Experimentally derive a sufficiently large value (
microdata
) on the system that will cause a minimum ten microsecond delay when callingtenmicrosec()
. This is essentially to bridge the gap for drivers between whenstartup_modules()
starts loading drivers and when the TSC (timestamp counter) is calibrated (and thus able to be used) when the PSM is loaded. - Measure the speed of the Local APIC clock to calibrate the Local APIC timer.
- Measure the frequency of the timestamp counter (TSC) for use in
gethrtime(9F)
. This allows the TSC to be used (among other things) intenmicrosec()
instead of a busy loop.
The latter two tasks are done rather late in the boot process, as a part of the PSM (platform support module?) initialization. This arrangement is unnecessary and appears to come from a time when Solaris ran on X86 chips that did not include a TSC. The TSC was first introduced in the original Pentium processor, and it's unlikely that illumos has ever been able to run on a system that did not include it (even prior to removing support for 32-bit CPUs). This arrangement also complicates supporting alternatives to the PIT timer for calibration since each new calibration source would need to support performing all of those tasks.
However, if we perform the TSC calibration early in the boot process (prior to startup_modules()
being called), we then no longer need to derive a value for microdata
(with a very small additional bit of work, we can eliminate the need for the variable and the whole microfind.c
file completely). Additionally, the Local APIC can then be calibrated with the TSC instead of the PIT timer (any X86 system illumos supports will have a TSC frequency on the order of 1000x higher than the PIT, so it's more than good enough for this). The later TSC calibration during PSM initialization is then no longer necessary.
With this setup in place, the PIT timer can easily become just one of several possible methods for measuring the TSC frequency. Any alternative methods will only need to support reporting the TSC frequency -- either through measurement, or reporting the known value (e.g. running as a hypervisor guest on hypervisors that report the TSC frequency to guests).
Related issues