* George Koehler <[email protected]> [2019-11-16 18:59:08 -0500]:

        I adapted some code from OpenBSD pvclock(4) into a Linux
kernel module, and used it to fix the clock in a Void Linux virtual
guest (which had been using the broken i8254 pit).  In the Linux
module, I set "shift = 12", ignoring the shift = -20 from vmm(4).
This seems to fix the tsc-to-nanosecond conversion, so the Void guest
is now my only virtual machine with a precise clock.



Hi George,

I concur with your math and indeed the diff below fixes it for me.

ok?

--
Pratik

Index: sys/arch/amd64/amd64/vmm.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/vmm.c,v
retrieving revision 1.254
diff -u -p -a -u -r1.254 vmm.c
--- sys/arch/amd64/amd64/vmm.c  22 Sep 2019 08:47:54 -0000      1.254
+++ sys/arch/amd64/amd64/vmm.c  17 Nov 2019 07:11:04 -0000
@@ -6906,7 +6906,7 @@ vmm_update_pvclock(struct vcpu *vcpu)
                nanotime(&tv);
                pvclock_ti->ti_system_time =
                    tv.tv_sec * 1000000000L + tv.tv_nsec;
-               pvclock_ti->ti_tsc_shift = -20;
+               pvclock_ti->ti_tsc_shift = 12;
                pvclock_ti->ti_tsc_to_system_mul =
                    vcpu->vc_pvclock_system_tsc_mul;
                pvclock_ti->ti_flags = PVCLOCK_FLAG_TSC_STABLE;

Reply via email to