Timekeeping in virtual machines: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
m s/suck/such
Document pvclock
Line 38:
 
== pvclock ==
 
pvclock is a simple protocol and the fastest way to properly track system time in a VM.
 
To use it, write a 64-bit 4-byte aligned physical address to MSR_KVM_SYSTEM_TIME_NEW (<code>0x4b564d01</code>).
The presence of this MSR is indicated by bit 3 in EAX from leaf 0x4000001 of CPUID.
 
The host will write the following structure to this address:
 
<source lang="C">
Line 50 ⟶ 57:
u8 pad[2];
};
 
The host will automatically update this structure when necessary (e.g. when finishing a migration).
 
The system time is calculated with <code>(rdtsc() - tsc_timestamp >> tsc_shift) * tsc_to_system_mul + system_time</code>.
 
The version field is used to detect when the structure has been / is being updated.
If the version is odd an update is in progress and the guest must not read the other fields yet.
</source>
 
Line 69 ⟶ 83:
 
* [https://docs.kernel.org/virt/kvm/x86/hypercalls.html Linux KVM Hypercall]
* [https://docs.kernel.org/virt/kvm/x86/msr.html KVM-specific MSRs]
* [https://opensource.com/article/17/6/timekeeping-linux-vms An introduction to timekeeping in Linux VMs]