David Vrabel
2013-Jun-27  10:35 UTC
[PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock
From: David Vrabel <david.vrabel@citrix.com>
Adjustments to Xen''s persistent clock via update_persistent_clock()
don''t actually persist, as the Xen wallclock is a software only clock
and modifications to it do not modify the underlying CMOS RTC.
The x86_platform.set_wallclock hook can be used to keep the hardware
RTC synchronized (as on bare metal).  Because the Xen wallclock is now
kept synchronized by pvclock_gtod notifier, xen_set_wallclock() need
not do this and dom0 can simply use the native implementation.
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 arch/x86/xen/time.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index 3364850..20e395a 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -199,37 +199,35 @@ static void xen_get_wallclock(struct timespec *now)
 
 static int xen_set_wallclock(const struct timespec *now)
 {
-	struct xen_platform_op op;
-
-	/* do nothing for domU */
-	if (!xen_initial_domain())
-		return -1;
-
-	op.cmd = XENPF_settime;
-	op.u.settime.secs = now->tv_sec;
-	op.u.settime.nsecs = now->tv_nsec;
-	op.u.settime.system_time = xen_clocksource_read();
-
-	return HYPERVISOR_dom0_op(&op);
+	return -1;
 }
 
 static int xen_pvclock_gtod_notify(struct notifier_block *nb, unsigned long
was_set,
 				   void *priv)
 {
+	static struct timespec next;
 	struct timespec now;
 	struct xen_platform_op op;
 
-	if (!was_set)
-		return NOTIFY_OK;
-
 	now = __current_kernel_time();
 
+	if (!was_set && timespec_compare(&now, &next) < 0)
+		return NOTIFY_OK;
+
 	op.cmd = XENPF_settime;
 	op.u.settime.secs = now.tv_sec;
 	op.u.settime.nsecs = now.tv_nsec;
 	op.u.settime.system_time = xen_clocksource_read();
 
 	(void)HYPERVISOR_dom0_op(&op);
+
+	/*
+	 * Don''t update the wallclock for another 11 minutes. This is
+	 * the same period as the sync_cmos_clock() work.
+	 */
+	next = now;
+	next.tv_sec += 11*60;
+
 	return NOTIFY_OK;
 }
 
@@ -513,7 +511,9 @@ void __init xen_init_time_ops(void)
 
 	x86_platform.calibrate_tsc = xen_tsc_khz;
 	x86_platform.get_wallclock = xen_get_wallclock;
-	x86_platform.set_wallclock = xen_set_wallclock;
+	/* Dom0 uses the native method to set the hardware RTC. */
+	if (!xen_initial_domain())
+		x86_platform.set_wallclock = xen_set_wallclock;
 }
 
 #ifdef CONFIG_XEN_PVHVM
-- 
1.7.2.5
Thomas Gleixner
2013-Jun-28  15:38 UTC
Re: [PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock
On Thu, 27 Jun 2013, David Vrabel wrote:> From: David Vrabel <david.vrabel@citrix.com> > > Adjustments to Xen''s persistent clock via update_persistent_clock() > don''t actually persist, as the Xen wallclock is a software only clock > and modifications to it do not modify the underlying CMOS RTC. > > The x86_platform.set_wallclock hook can be used to keep the hardware > RTC synchronized (as on bare metal). Because the Xen wallclock is now > kept synchronized by pvclock_gtod notifier, xen_set_wallclock() need > not do this and dom0 can simply use the native implementation.I can understand that part, but ...> static int xen_pvclock_gtod_notify(struct notifier_block *nb, unsigned long was_set, > void *priv) > { > + static struct timespec next; > struct timespec now; > struct xen_platform_op op; > > - if (!was_set) > - return NOTIFY_OK; > - > now = __current_kernel_time(); > > + if (!was_set && timespec_compare(&now, &next) < 0) > + return NOTIFY_OK; > + > op.cmd = XENPF_settime; > op.u.settime.secs = now.tv_sec; > op.u.settime.nsecs = now.tv_nsec; > op.u.settime.system_time = xen_clocksource_read(); > > (void)HYPERVISOR_dom0_op(&op); > + > + /* > + * Don''t update the wallclock for another 11 minutes. This is > + * the same period as the sync_cmos_clock() work. > + */ > + next = now; > + next.tv_sec += 11*60; > +How is this related to the changelog? /me is confused .....
David Vrabel
2013-Jun-28  15:49 UTC
Re: [PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock
On 28/06/13 16:38, Thomas Gleixner wrote:> On Thu, 27 Jun 2013, David Vrabel wrote: > >> From: David Vrabel <david.vrabel@citrix.com> >> >> Adjustments to Xen''s persistent clock via update_persistent_clock() >> don''t actually persist, as the Xen wallclock is a software only clock >> and modifications to it do not modify the underlying CMOS RTC. >> >> The x86_platform.set_wallclock hook can be used to keep the hardware >> RTC synchronized (as on bare metal). Because the Xen wallclock is now >> kept synchronized by pvclock_gtod notifier, xen_set_wallclock() need >> not do this and dom0 can simply use the native implementation. > > I can understand that part, but ... > >> static int xen_pvclock_gtod_notify(struct notifier_block *nb, unsigned long was_set, >> void *priv) >> { >> + static struct timespec next; >> struct timespec now; >> struct xen_platform_op op; >> >> - if (!was_set) >> - return NOTIFY_OK; >> - >> now = __current_kernel_time(); >> >> + if (!was_set && timespec_compare(&now, &next) < 0) >> + return NOTIFY_OK; >> + >> op.cmd = XENPF_settime; >> op.u.settime.secs = now.tv_sec; >> op.u.settime.nsecs = now.tv_nsec; >> op.u.settime.system_time = xen_clocksource_read(); >> >> (void)HYPERVISOR_dom0_op(&op); >> + >> + /* >> + * Don''t update the wallclock for another 11 minutes. This is >> + * the same period as the sync_cmos_clock() work. >> + */ >> + next = now; >> + next.tv_sec += 11*60; >> + > > How is this related to the changelog? /me is confused .....Before: Xen wallclock set when time is stepped. Xen wallclock set every 11 minutes (by sync_cmos_clock()). Hardware RTC never set. After: Xen wallclock set when time is stepped. Xen wallclock set every 11 minutes (in pvclock gtod notifier). Hardware RTC set every 11 minutes (by sync_cmos_clock()). I''ll update the changelog to be more descriptive: Adjustments to Xen''s persistent clock via update_persistent_clock() don''t actually persist, as the Xen wallclock is a software only clock and modifications to it do not modify the underlying CMOS RTC. The x86_platform.set_wallclock hook can be used to keep the hardware RTC synchronized (as on bare metal). If (in dom0) we make the Xen wallclock periodically synchronized by the pvclock_gtod notifier, the set_wallclock hook need not update the Xen wallclock and the native implementation can be used. Is that better? David
Thomas Gleixner
2013-Jun-28  16:09 UTC
Re: [PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock
On Fri, 28 Jun 2013, David Vrabel wrote:> > Before: > > Xen wallclock set when time is stepped. > Xen wallclock set every 11 minutes (by sync_cmos_clock()). > Hardware RTC never set. > > After: > > Xen wallclock set when time is stepped. > Xen wallclock set every 11 minutes (in pvclock gtod notifier).Ah, you are emulating the sync_cmos_clock() behaviour for the xen wallclock via the periodic pvclock_gtod notifier call.> Hardware RTC set every 11 minutes (by sync_cmos_clock()). > > I''ll update the changelog to be more descriptive: > > Adjustments to Xen''s persistent clock via update_persistent_clock() > don''t actually persist, as the Xen wallclock is a software only clock > and modifications to it do not modify the underlying CMOS RTC. > > The x86_platform.set_wallclock hook can be used to keep the hardware > RTC synchronized (as on bare metal). If (in dom0) we make the Xen > wallclock periodically synchronized by the pvclock_gtod notifier, the > set_wallclock hook need not update the Xen wallclock and the native > implementation can be used.Yep. I''ll pick that up. Thanks, tglx
David Vrabel
2013-Jun-28  16:51 UTC
Re: [PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock
On 28/06/13 17:09, Thomas Gleixner wrote:> On Fri, 28 Jun 2013, David Vrabel wrote: >> >> Before: >> >> Xen wallclock set when time is stepped. >> Xen wallclock set every 11 minutes (by sync_cmos_clock()). >> Hardware RTC never set. >> >> After: >> >> Xen wallclock set when time is stepped. >> Xen wallclock set every 11 minutes (in pvclock gtod notifier). > > Ah, you are emulating the sync_cmos_clock() behaviour for the xen > wallclock via the periodic pvclock_gtod notifier call. > >> Hardware RTC set every 11 minutes (by sync_cmos_clock()). >> >> I''ll update the changelog to be more descriptive: >> >> Adjustments to Xen''s persistent clock via update_persistent_clock() >> don''t actually persist, as the Xen wallclock is a software only clock >> and modifications to it do not modify the underlying CMOS RTC. >> >> The x86_platform.set_wallclock hook can be used to keep the hardware >> RTC synchronized (as on bare metal). If (in dom0) we make the Xen >> wallclock periodically synchronized by the pvclock_gtod notifier, the >> set_wallclock hook need not update the Xen wallclock and the native >> implementation can be used. > > Yep. I''ll pick that up.If it helps, I''ve made this change as well as splitting the xen part of the hrtimers patch out into a separate commit. The following changes since commit 52efa9eb9ea36b457b23b1b5d3dd9ce64d110715: x86: increase precision of x86_platform.get/set_wallclock() (2013-06-26 18:07:16 +0100) are available in the git repository at: git://xenbits.xen.org/people/dvrabel/linux.git wallclock-v8 David Vrabel (6): hrtimers: support resuming with two or more CPUs online (but stopped) time: pass flags instead of multiple bools to timekeeping_update() time: indicate that the clock was set in the pvclock gtod notifier chain xen: remove unnecessary call to clock_was_set() during resume x86/xen: sync the wallclock when the system time is set x86/xen: sync the CMOS RTC as well as the Xen wallclock arch/x86/xen/time.c | 42 +++++++++++++++++++++++++++++++++++------- drivers/xen/manage.c | 3 --- include/linux/pvclock_gtod.h | 7 +++++++ kernel/hrtimer.c | 15 ++++++++++++--- kernel/time/timekeeping.c | 39 ++++++++++++++++++++++++--------------- 5 files changed, 78 insertions(+), 28 deletions(-) David
Thomas Gleixner
2013-Jun-28  20:41 UTC
Re: [PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock
On Fri, 28 Jun 2013, David Vrabel wrote:> On 28/06/13 17:09, Thomas Gleixner wrote: > > Yep. I''ll pick that up. > > If it helps, I''ve made this change as well as splitting the xen part of > the hrtimers patch out into a separate commit.Fun. I already have that same split in my pending queue :) Thanks, tglx