Bug #13354


illumos should calibrate the TSC earlier in the boot process.

Added by Jason King over 1 year ago. Updated 11 months ago.

Start date:
Due date:
% Done:


Estimated time:
Gerrit CR:


Since time immemorial, illumos has used the i8253/8254 PIT timer to do three key tasks during boot:
  • Experimentally derive a sufficiently large value (microdata) on the system that will cause a minimum ten microsecond delay when calling tenmicrosec(). This is essentially to bridge the gap for drivers between when startup_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) in tenmicrosec() 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

Related to illumos gate - Bug #13961: Add HPET as a TSC calibration sourceClosedJason King


Also available in: Atom PDF