On 18/03/21 15:52, Vitaly Kuznetsov wrote:
Paolo Bonzini <pbonzini@xxxxxxxxxx> writes:
On 18/03/21 15:09, Vitaly Kuznetsov wrote:
+static inline void check_tsc_msr_tsc_page(struct ms_hyperv_tsc_page *tsc_page)
+{
+ u64 r1, r2, t1, t2;
+ s64 delta_ns;
+
+ /* Compare TSC page clocksource with HV_X64_MSR_TIME_REF_COUNT */
+ t1 = mul_u64_u64_shr64(rdtsc(), tsc_page->tsc_scale) + tsc_page->tsc_offset;
+ r1 = rdmsr(HV_X64_MSR_TIME_REF_COUNT);
+ nop_loop();
+ t2 = mul_u64_u64_shr64(rdtsc(), tsc_page->tsc_scale) + tsc_page->tsc_offset;
+ r2 = rdmsr(HV_X64_MSR_TIME_REF_COUNT);
+
+ delta_ns = ((r2 - r1) - (t2 - t1)) * 100;
+ if (delta_ns < 0)
+ delta_ns = -delta_ns;
+
+ /* 1% tolerance */
+ GUEST_ASSERT(delta_ns * 100 < (t2 - t1) * 100);
+}
+
I think you should also be able to check r1 and r2 individually, not
just r1 and r2. Is that correct?
Right, we could've checked r1 == t1 and r2 == t2 actually (with some
tiny margin of course). Let me try that.
np, I can do that too. Just checking my recollection of the TLFS.
Paolo