Il 11/12/2013 11:58, Vadim Rozenfeld ha scritto: >> > + curr_time = (((tsc_ref->tsc_scale >> 32) * native_read_tsc()) >> 32) + >> > + tsc_ref->tsc_offset; >> > + tsc_ref->tsc_offset = kvm->arch.hv_ref_time - curr_time; >> > >> > Why do you need kvm->arch.hv_ref_time at all? Can you just use >> > "get_kernel_ns() + kvm->arch.kvmclock_offset - kvm->arch.hv_ref_count"? >> > Then the same code can set tsc_ref->tsc_offset in both cases. >> > >> > In fact, it's not clear to me what hv_ref_time is for, and how it >> > is different from > OK, let me explain how it works. > Hyper-V allows guest to use invariant TSC provided by host as a time > stamp source (KeQueryPerformanceCounter). Guest is calling rdtsc and > normalizing it to 10MHz frequency, it is why we need "tsc_scale". > "tsc_offset" is needed for migration or pause/resume cycles. > When we pause a VM, we need to save the current vTSC value > ("hv_ref_time"), which is rdtsc * tsc_scale + tsc_offset. > Then, during resume, we need to recalculate the new tsc_scale > as well as the new tsc_offset value. > tsc_offset = old(saved) vTSC - new vTSC In practice "save" means KVM_GET_CLOCK, and "restore" means KVM_SET_CLOCK, right? > So maybe hv_ref_time is not a good name, but we use it > for keeping the old vTSC value, saved before stopping VM. Ok, this was roughly my understanding as well. My understanding is also that (((tsc_ref->tsc_scale >> 32) * native_read_tsc()) >> 32) + tsc_ref->tsc_offset returns exactly the same value as HV_X64_MSR_TIME_REF_COUNT. Thus we do not need kvm->arch.hv_ref_time. We can use the value of HV_X64_MSR_TIME_REF_COUNT, which is "(get_kernel_ns() + kvm->arch.kvmclock_offset - kvm->arch.hv_ref_count) / 100", to compute tsc_offset, like this: curr_time = (((tsc_ref->tsc_scale >> 32) * native_read_tsc()) >> 32); tsc_ref->tsc_offset = get_hv_x64_msr_time_ref_count() - curr_time; This code can be applied always: when the TSC page is initialized and when KVM_SET_CLOCK is called. You do not need to do anything for KVM_GET_CLOCK. Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html