diff mbox

[3/3] KVM: x86: zero kvmclock_offset when vcpu0 initializes kvmclock system MSR

Message ID 20150528014929.546279051@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marcelo Tosatti May 28, 2015, 1:47 a.m. UTC
Initialize kvmclock base, on kvmclock system MSR write time,
so that the guest sees kvmclock counting from zero.

This matches baremetal behaviour when kvmclock in guest
sets sched clock stable.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

---
 arch/x86/kvm/x86.c |    5 +++++
 1 file changed, 5 insertions(+)



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Paolo Bonzini May 28, 2015, 8:52 a.m. UTC | #1
On 28/05/2015 03:47, Marcelo Tosatti wrote:
> Initialize kvmclock base, on kvmclock system MSR write time,
> so that the guest sees kvmclock counting from zero.
> 
> This matches baremetal behaviour when kvmclock in guest
> sets sched clock stable.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> ---
>  arch/x86/kvm/x86.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> Index: kvm/arch/x86/kvm/x86.c
> ===================================================================
> --- kvm.orig/arch/x86/kvm/x86.c	2015-05-27 17:40:46.948189811 -0300
> +++ kvm/arch/x86/kvm/x86.c	2015-05-27 22:43:47.340413347 -0300
> @@ -1703,6 +1703,8 @@
>  	/* If the host uses TSC clocksource, then it is stable */
>  	if (use_master_clock)
>  		pvclock_flags |= PVCLOCK_TSC_STABLE_BIT;
> +	if (ka->kvmclk_counts_from_zero)

Not defined anywhere.

> +		pvclock_flags |= PVCLOCK_COUNTS_FROM_ZERO;

Why can't this be unconditional?

Paolo

>  	vcpu->hv_clock.flags = pvclock_flags;
>  
> @@ -2282,6 +2284,9 @@
>  					&vcpu->requests);
>  
>  			ka->boot_vcpu_runs_old_kvmclock = tmp;
> +
> +			ka->kvmclock_offset = -get_kernel_ns();
> +			ka->kvmclk_counts_from_zero = true;
>  		}
>  
>  		vcpu->arch.time = data;
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: kvm/arch/x86/kvm/x86.c
===================================================================
--- kvm.orig/arch/x86/kvm/x86.c	2015-05-27 17:40:46.948189811 -0300
+++ kvm/arch/x86/kvm/x86.c	2015-05-27 22:43:47.340413347 -0300
@@ -1703,6 +1703,8 @@ 
 	/* If the host uses TSC clocksource, then it is stable */
 	if (use_master_clock)
 		pvclock_flags |= PVCLOCK_TSC_STABLE_BIT;
+	if (ka->kvmclk_counts_from_zero)
+		pvclock_flags |= PVCLOCK_COUNTS_FROM_ZERO;
 
 	vcpu->hv_clock.flags = pvclock_flags;
 
@@ -2282,6 +2284,9 @@ 
 					&vcpu->requests);
 
 			ka->boot_vcpu_runs_old_kvmclock = tmp;
+
+			ka->kvmclock_offset = -get_kernel_ns();
+			ka->kvmclk_counts_from_zero = true;
 		}
 
 		vcpu->arch.time = data;