freebsd-dev/sys/x86
Colin Percival c2705ceaeb x86: Speed up clock calibration
Prior to this commit, the TSC and local APIC frequencies were calibrated
at boot time by measuring the clocks before and after a one-second sleep.
This was simple and effective, but had the disadvantage of *requiring a
one-second sleep*.

Rather than making two clock measurements (before and after sleeping) we
now perform many measurements; and rather than simply subtracting the
starting count from the ending count, we calculate a best-fit regression
between the target clock and the reference clock (for which the current
best available timecounter is used). While we do this, we keep track
of an estimate of the uncertainty in the regression slope (aka. the ratio
of clock speeds), and stop measuring when we believe the uncertainty is
less than 1 PPM.

In order to avoid the risk of aliasing resulting from the data-gathering
loop synchronizing with (a multiple of) the frequency of the reference
clock, we add some additional spinning depending upon the iteration number.

For numerical stability and simplicity of implementation, we make use of
floating-point arithmetic for the statistical calculations.

On the author's Dell laptop, this reduces the time spent in calibration
from 2000 ms to 29 ms; on an EC2 c5.xlarge instance, it is reduced from
2000 ms to 2.5 ms.

Reviewed by:	bde (previous version), kib
MFC after:	1 month
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D33802
2022-01-12 12:34:07 -08:00
..
acpica x86: duplicate acpi_wakeup.c per i386 and amd64 2021-09-14 00:23:14 +03:00
bios smbios: Move smbios driver out from x86 machdep code 2021-02-23 21:17:09 +00:00
conf Retire synchronous PPP kernel driver sppp(4). 2021-10-22 11:41:36 -07:00
cpufreq x86: Remove CTLFLAG_NEEDGIANT from sysctls. 2021-12-25 22:24:20 -05:00
include bus_dma: Deduplicate locking helper functions. 2022-01-05 13:50:40 -08:00
iommu dmar: Disable protected memory regions after initialization 2021-10-29 10:08:25 +02:00
isa x86: Remove CTLFLAG_NEEDGIANT from sysctls. 2021-12-25 22:24:20 -05:00
linux Drop "All rights reserved" from my copyright statements. 2021-07-20 10:05:50 +03:00
pci pci: add missing PCI id of Coffee Lake GPU 2021-12-17 23:18:31 +02:00
x86 x86: Speed up clock calibration 2022-01-12 12:34:07 -08:00
xen xen: plug some of set-but-not-used vars 2021-12-15 13:46:17 +00:00