hv: cache tsc_offset

Guest write tsc: cache the offset into run_context.tsc_offset;
Guest read tsc : use run_context.tsc_offset to calculate guest_tsc.

Signed-off-by: Qi Yadong <yadong.qi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Qi Yadong
2018-04-09 10:56:25 +08:00
committed by Jack Ren
parent 51414536fa
commit ef0c5ec2e3
4 changed files with 12 additions and 15 deletions

View File

@@ -191,8 +191,8 @@ int rdmsr_handler(struct vcpu *vcpu)
}
case MSR_IA32_TIME_STAMP_COUNTER:
{
/*Add the TSC_offset to host TSC to get guest TSC */
v = rdtsc() + exec_vmread64(VMX_TSC_OFFSET_FULL);
/* Add the TSC_offset to host TSC to get guest TSC */
v = rdtsc() + vcpu->arch_vcpu.contexts[cur_context].tsc_offset;
break;
}
@@ -287,7 +287,8 @@ int wrmsr_handler(struct vcpu *vcpu)
case MSR_IA32_TIME_STAMP_COUNTER:
{
/*Caculate TSC offset from changed TSC MSR value*/
exec_vmwrite64(VMX_TSC_OFFSET_FULL, v - rdtsc());
cur_context->tsc_offset = v - rdtsc();
exec_vmwrite64(VMX_TSC_OFFSET_FULL, cur_context->tsc_offset);
break;
}