public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
@ 2012-07-20 16:44 Bruce Rogers
  2012-07-24  0:44 ` Marcelo Tosatti
  0 siblings, 1 reply; 6+ messages in thread
From: Bruce Rogers @ 2012-07-20 16:44 UTC (permalink / raw)
  To: kvm; +Cc: Zamsden, glommer

When a guest migrates to a new host, the system time difference from the
previous host is used in the updates to the kvmclock system time visible
to the guest, resulting in a continuation of correct kvmclock based guest
timekeeping.

The wall clock component of the kvmclock provided time is currently not
updated with this same time offset. Since the Linux guest caches the
wall clock based time, this discrepency is not noticed until the guest is
rebooted. After reboot the guest's time calculations are off.

This patch adjusts the wall clock by the kvmclock_offset, resulting in
correct guest time after a reboot.

Cc: Glauber Costa <glommer@redhat.com>
Cc: Zachary Amsden <zamsden@gmail.com>
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
 arch/x86/kvm/x86.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index be6d549..14c290d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
 	 */
 	getboottime(&boot);
 
+	if (kvm->arch.kvmclock_offset) {
+		struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
+		boot = timespec_sub(boot, ts);
+	}
 	wc.sec = boot.tv_sec;
 	wc.nsec = boot.tv_nsec;
 	wc.version = version;
-- 
1.7.7



^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
@ 2012-07-19 15:21 Bruce Rogers
  0 siblings, 0 replies; 6+ messages in thread
From: Bruce Rogers @ 2012-07-19 15:21 UTC (permalink / raw)
  To: kvm; +Cc: Bruce Rogers, Glauber Costa, Zachary Amsden

When a guest migrates to a new host, the system time difference from the
previous host is used in the updates to the kvmclock system time visible
to the guest, resulting in a continuation of correct kvmclock based guest
timekeeping.

The wall clock component of the kvmclock provided time is currently not
updated with this same time offset. Since the Linux guest caches the
wall clock based time, this discrepency is not noticed until the guest is
rebooted. After reboot the guest's time calculations are off.

This patch adjusts the wall clock by the kvmclock_offset, resulting in
correct guest time after a reboot.

Cc: Glauber Costa <glommer@redhat.com>
Cc: Zachary Amsden <zamsden@redhat.com>
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
 arch/x86/kvm/x86.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index be6d549..14c290d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
 	 */
 	getboottime(&boot);
 
+	if (kvm->arch.kvmclock_offset) {
+		struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
+		boot = timespec_sub(boot, ts);
+	}
 	wc.sec = boot.tv_sec;
 	wc.nsec = boot.tv_nsec;
 	wc.version = version;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-08-01 20:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-20 16:44 [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time Bruce Rogers
2012-07-24  0:44 ` Marcelo Tosatti
2012-08-01 20:21   ` Marcelo Tosatti
2012-08-01 20:36     ` Marcelo Tosatti
2012-08-01 20:53     ` Bruce Rogers
  -- strict thread matches above, loose matches on Subject: below --
2012-07-19 15:21 Bruce Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox