On Mon, Nov 25, 2019 at 07:06:19PM -0800, Pratik Vyas wrote:
> Hi tech@,
>
> This patch fixes vmm pvclock accuracy issues. Shift math error
> discovered by George Koehler. This diff also fixes the error in tsc
> multiplier which was correct only if the host timecounter is tsc.
>
> --
> Pratik
>
Provided there is no reported fallout for just this piece, ok mlarkin@.
-ml
>
> Index: sys/arch/amd64/amd64/vmm.c
> ===================================================================
> RCS file: /home/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 26 Nov 2019 00:08:10 -0000
> @@ -28,7 +28,6 @@
> #include <sys/rwlock.h>
> #include <sys/pledge.h>
> #include <sys/memrange.h>
> -#include <sys/timetc.h>
>
> #include <uvm/uvm_extern.h>
>
> @@ -6879,8 +6878,11 @@ void
> vmm_init_pvclock(struct vcpu *vcpu, paddr_t gpa)
> {
> vcpu->vc_pvclock_system_gpa = gpa;
> - vcpu->vc_pvclock_system_tsc_mul =
> - (int) ((1000000000L << 20) / tc_getfrequency());
> + if (tsc_frequency > 0)
> + vcpu->vc_pvclock_system_tsc_mul =
> + (int) ((1000000000L << 20) / tsc_frequency);
> + else
> + vcpu->vc_pvclock_system_tsc_mul = 0;
> vmm_update_pvclock(vcpu);
> }
>
> @@ -6906,7 +6908,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;
>