x86/tsc: Make calibration refinement more robust
authorDaniel Vacek <neelx@redhat.com>
Mon, 5 Nov 2018 17:10:40 +0000 (18:10 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 6 Nov 2018 20:53:15 +0000 (21:53 +0100)
commita786ef152cdcfebc923a67f63c7815806eefcf81
tree3a29cf70452df09bb81b51b867e1ca5e37f25e09
parent651022382c7f8da46cb4872a545ee1da6d097d2a
x86/tsc: Make calibration refinement more robust

The threshold in tsc_read_refs() is constant which may favor slower CPUs
but may not be optimal for simple reading of reference on faster ones.

Hence make it proportional to tsc_khz when available to compensate for
this. The threshold guards against any disturbance like IRQs, NMIs, SMIs
or CPU stealing by host on guest systems so rename it accordingly and
fix comments as well.

Also on some systems there is noticeable DMI bus contention at some point
during boot keeping the readout failing (observed with about one in ~300
boots when testing). In that case retry also the second readout instead of
simply bailing out unrefined. Usually the next second the readout returns
fast just fine without any issues.

Signed-off-by: Daniel Vacek <neelx@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lkml.kernel.org/r/1541437840-29293-1-git-send-email-neelx@redhat.com
arch/x86/kernel/tsc.c