All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for David Vrabel <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org,
	john.stultz@linaro.org, david.vrabel@citrix.com, hpa@zytor.com,
	tglx@linutronix.de, mingo@kernel.org
Subject: [tip:timers/core] x86: xen: Sync the CMOS RTC as well as the Xen wallclock
Date: Fri, 28 Jun 2013 14:19:21 -0700	[thread overview]
Message-ID: <tip-47433b8c9d7480a3eebd99df38e857ce85a37cee__27366.2334577695$1372454423$gmane$org@git.kernel.org> (raw)
In-Reply-To: <1372329348-20841-6-git-send-email-david.vrabel@citrix.com>

Commit-ID:  47433b8c9d7480a3eebd99df38e857ce85a37cee
Gitweb:     http://git.kernel.org/tip/47433b8c9d7480a3eebd99df38e857ce85a37cee
Author:     David Vrabel <david.vrabel@citrix.com>
AuthorDate: Thu, 27 Jun 2013 11:35:48 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 28 Jun 2013 23:15:07 +0200

x86: xen: Sync the CMOS RTC as well as the Xen wallclock

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 is there to keep the hardware RTC
synchronized. On a guest this is pointless.

On Dom0 we can use the native implementaion which actually updates the
hardware RTC, but we still need to keep the software emulation of RTC
for the guests up to date. The subscription to the pvclock_notifier
allows us to emulate this easily. The notifier is called at every tick
and when the clock was set.

Right now we only use that notifier when the clock was set, but due to
the fact that it is called periodically from the timekeeping update
code, we can utilize it to emulate the NTP driven drift compensation
of update_persistant_clock() for the Xen wall (software) clock.

Add a 11 minutes periodic update to the pvclock_gtod notifier callback
to achieve that. The static variable 'next' which maintains that 11
minutes update cycle is protected by the core code serialization so
there is no need to add a Xen specific serialization mechanism.

[ tglx: Massaged changelog and added a few comments ]

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: <xen-devel@lists.xen.org>
Link: http://lkml.kernel.org/r/1372329348-20841-6-git-send-email-david.vrabel@citrix.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/xen/time.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index 3364850..7a5671b 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -199,37 +199,42 @@ 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 int xen_pvclock_gtod_notify(struct notifier_block *nb,
+				   unsigned long was_set, void *priv)
 {
-	struct timespec now;
-	struct xen_platform_op op;
+	/* Protected by the calling core code serialization */
+	static struct timespec next_sync;
 
-	if (!was_set)
-		return NOTIFY_OK;
+	struct xen_platform_op op;
+	struct timespec now;
 
 	now = __current_kernel_time();
 
+	/*
+	 * We only take the expensive HV call when the clock was set
+	 * or when the 11 minutes RTC synchronization time elapsed.
+	 */
+	if (!was_set && timespec_compare(&now, &next_sync) < 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);
+
+	/*
+	 * Move the next drift compensation time 11 minutes
+	 * ahead. That's emulating the sync_cmos_clock() update for
+	 * the hardware RTC.
+	 */
+	next_sync = now;
+	next_sync.tv_sec += 11 * 60;
+
 	return NOTIFY_OK;
 }
 
@@ -513,7 +518,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

  parent reply	other threads:[~2013-06-28 21:19 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27 10:35 [PATCHv6 0/5] xen: maintain an accurate persistent clock in more cases David Vrabel
2013-06-27 10:35 ` [PATCH 1/5] hrtimers: support resuming with two or more CPUs online (but stopped) David Vrabel
2013-06-27 10:35 ` David Vrabel
2013-06-28 21:18   ` [tip:timers/core] hrtimers: Support " tip-bot for David Vrabel
2013-06-28 21:18   ` tip-bot for David Vrabel
2013-07-05  9:30     ` Artem Savkov
2013-07-05 10:07       ` David Vrabel
2013-07-05 10:07       ` David Vrabel
2013-07-05 10:10         ` Thomas Gleixner
2013-07-05 10:10         ` Thomas Gleixner
2013-07-05 10:25         ` Thomas Gleixner
2013-07-05 10:25         ` Thomas Gleixner
2013-07-05 10:36           ` Thomas Gleixner
2013-07-05 10:36           ` Thomas Gleixner
2013-07-05 10:45             ` Artem Savkov
2013-07-05 10:45             ` Artem Savkov
2013-07-05 13:26               ` Thomas Gleixner
2013-07-05 13:26               ` Thomas Gleixner
2013-07-05 10:38           ` Artem Savkov
2013-07-05 10:38           ` Artem Savkov
2013-07-05 13:46           ` David Vrabel
2013-07-05 13:51             ` Thomas Gleixner
2013-07-05 13:51             ` Thomas Gleixner
2013-07-05 13:46           ` David Vrabel
2013-07-05 10:09       ` Thomas Gleixner
2013-07-05 10:09       ` Thomas Gleixner
2013-07-05  9:30     ` Artem Savkov
2013-06-28 21:18   ` [tip:timers/core] xen: Remove clock_was_set() call in the resume path tip-bot for David Vrabel
2013-06-28 21:18   ` tip-bot for David Vrabel
2013-06-27 10:35 ` [PATCH 2/5] time: pass flags instead of multiple bools to timekeeping_update() David Vrabel
2013-06-27 17:39   ` John Stultz
2013-06-27 17:39   ` John Stultz
2013-06-28 21:18   ` [tip:timers/core] timekeeping: Pass " tip-bot for David Vrabel
2013-06-28 21:18   ` tip-bot for David Vrabel
2013-06-27 10:35 ` [PATCH 2/5] time: pass " David Vrabel
2013-06-27 10:35 ` [PATCH 3/5] time: indicate that the clock was set in the pvclock gtod notifier chain David Vrabel
2013-06-27 10:35   ` David Vrabel
2013-06-27 17:37   ` John Stultz
2013-06-27 17:37   ` John Stultz
2013-06-28 10:20     ` David Vrabel
2013-06-28 10:20     ` David Vrabel
2013-06-28 21:19   ` [tip:timers/core] timekeeping: Indicate that clock was set in the pvclock gtod notifier tip-bot for David Vrabel
2013-06-28 21:19   ` tip-bot for David Vrabel
2013-06-27 10:35 ` [PATCH 4/5] x86/xen: sync the wallclock when the system time is set David Vrabel
2013-06-28 21:19   ` [tip:timers/core] x86: xen: Sync " tip-bot for David Vrabel
2013-06-28 21:19   ` tip-bot for David Vrabel
2013-06-27 10:35 ` [PATCH 4/5] x86/xen: sync " David Vrabel
2013-06-27 10:35 ` [PATCH 5/5] x86/xen: sync the CMOS RTC as well as the Xen wallclock David Vrabel
2013-06-28 15:38   ` Thomas Gleixner
2013-06-28 15:49     ` David Vrabel
2013-06-28 15:49     ` David Vrabel
2013-06-28 16:09       ` Thomas Gleixner
2013-06-28 16:51         ` David Vrabel
2013-06-28 20:41           ` Thomas Gleixner
2013-06-28 20:41           ` Thomas Gleixner
2013-06-28 16:51         ` David Vrabel
2013-06-28 16:09       ` Thomas Gleixner
2013-06-28 15:38   ` Thomas Gleixner
2013-06-28 21:19   ` [tip:timers/core] x86: xen: Sync " tip-bot for David Vrabel
2013-06-28 21:19   ` tip-bot for David Vrabel [this message]
2013-06-27 10:35 ` [PATCH 5/5] x86/xen: sync " David Vrabel
2013-06-28 13:14 ` [PATCHv6 0/5] xen: maintain an accurate persistent clock in more cases Thomas Gleixner
2013-06-28 13:14 ` Thomas Gleixner
2013-06-28 15:01   ` Konrad Rzeszutek Wilk
2013-06-28 15:01   ` Konrad Rzeszutek Wilk
2013-06-28 15:12     ` Thomas Gleixner
2013-06-28 15:12     ` Thomas Gleixner
2013-06-28 16:19       ` Konrad Rzeszutek Wilk
2013-06-28 16:19       ` Konrad Rzeszutek Wilk
2013-06-28 18:58         ` Thomas Gleixner
2013-06-28 18:58           ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='tip-47433b8c9d7480a3eebd99df38e857ce85a37cee__27366.2334577695$1372454423$gmane$org@git.kernel.org' \
    --to=tipbot@zytor.com \
    --cc=david.vrabel@citrix.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.