clock stability, TSC, and QEMU

nia <[email protected]> Sun, 9 May 2021 06:23:02 +0000
Newsgroups gmane.os.netbsd.ports.x86-64
Message-ID <YJd/[email protected]>
hello,

when running NetBSD as a QEMU guest, there seem to be problems
with clock stability.

i remember having this problem when using a commercial KVM-based VM
host. erlang is very sensitive to monotonic clock drift, and
will abort if it detects it. my application would infrequently
abort regardless of kern.timecounter.hardware (although ACPI-Safe
annecdotally made it less worse) due to the monotonic clock
stepping backwards.

when running NetBSD as a QEMU guest with NVMM, the following
message is printed to dmesg on boot:

autoconfiguration ERROR: 9225914709 cycle TSC drift observed

(kern.timecounter.hardware defaults to hpet)

QEMU has a -rtc setting, but I'm unsure of best option
to pick for NetBSD:

-rtc [base=utc|localtime|<datetime>][,clock=host|rt|vm][,driftfix=none|slew]
	set the RTC base and clock, enable drift fix for clock ticks (x86 only)

additionally, on my laptop running -curent, I get spammed
with warnings about TSC drift when waking from suspend:
http://gnats.netbsd.org/55694
It is defaulting to using TSC as a timecounter -
I wonder if NetBSD should be relying on TSC less.