[libvirt] [PATCH] qemu: hyperv: Add enlightenment support for TSC timekeeping

Vadim Rozenfeld vrozenfe at redhat.com
Wed Feb 5 07:54:48 UTC 2014


On Tue, 2014-02-04 at 16:04 +0100, Peter Krempa wrote:
> [adding Vadim as he implemented the qemu/kvm parts]
> 
> On 01/22/14 11:35, Daniel P. Berrange wrote:
> > On Tue, Jan 21, 2014 at 06:54:34PM +0100, Peter Krempa wrote:
> >> The hyperv enlightenment features allow to ease guests timekeeping by
> >> allowing to store offset from the TSC as a reference. Add the support
> >> for enabling this flag in qemu.
> > 
> > I'm not sure I entirely understand what this is doing with TSC, but
> > we do have a generic  <timer> element for controlling various attributes
> > of platform timers. I can't help thinking it'd be better to keep this
> > TSC related setting there instead
> 
> This functionality provides hypercalls defined by the Microsoft's
> "enlightenment" standards. These provide calibration data and actual
> values that can be used by the guest to calculate time. [1]
> 
> The actual implementation uses data provided by the kvmclock code:
> 
> +	case HV_X64_MSR_TIME_REF_COUNT: {
> +		data =
> +		     div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
> +		break;
> +	}
> 
> along with a few values that will allow the guest to use the data.
> 
> Technically this is a new timer for VM's running windows and as with
> kvmclock, cpu features are used to show the availability of this feature
> to the guest.
> 
> There is yet another "enlightenment" option for windows guests that run
> on platforms that support the invariant TSC (iTSC). This option will add
> hypercall to retrieve calibration data so that the host processors iTSC
> will be used as the timing source eliminating the need to read the timer
> value via a hypercall.

Technically, it is not a hypercall, just a normal call RDTSC, but then
kernel normalizes the returned value to 10MHz and adds offset. Kernel
(KVM) shares scale and offset date with a guest through a dedicated page
allocated by guest. We have pretty good working prototype at the moment,
but this part has not been committed to upstream yet.

Best regards,
Vadim.

> 
> I agree on your idea of moving this option into the <timer> section. How
> about naming it <timer name="hv-rtc"> ?
> 
> > 
> > Daniel
> > 
> 
> Peter
> 
> [1]:
> http://msdn.microsoft.com/en-us/library/windows/hardware/ff542637(v=vs.85).aspx
> 





More information about the libvir-list mailing list