Skip to content

Commit

Permalink
x86: xen: Sync the wallclock when the system time is set
Browse files Browse the repository at this point in the history
Currently the Xen wallclock is only updated every 11 minutes if NTP is
synchronized to its clock source (using the sync_cmos_clock() work).
If a guest is started before NTP is synchronized it may see an
incorrect wallclock time.

Use the pvclock_gtod notifier chain to receive a notification when the
system time has changed and update the wallclock to match.

This chain is called on every timer tick and we want to avoid an extra
(expensive) hypercall on every tick.  Because dom0 has historically
never provided a very accurate wallclock and guests do not expect one,
we can do this simply: the wallclock is only updated if the clock was
set.

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-5-git-send-email-david.vrabel@citrix.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
David Vrabel authored and Thomas Gleixner committed Jun 28, 2013
1 parent 780427f commit 5584880
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions arch/x86/xen/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/kernel_stat.h>
#include <linux/math64.h>
#include <linux/gfp.h>
#include <linux/pvclock_gtod.h>

#include <asm/pvclock.h>
#include <asm/xen/hypervisor.h>
Expand Down Expand Up @@ -212,6 +213,30 @@ static int xen_set_wallclock(const struct timespec *now)
return HYPERVISOR_dom0_op(&op);
}

static int xen_pvclock_gtod_notify(struct notifier_block *nb, unsigned long was_set,
void *priv)
{
struct timespec now;
struct xen_platform_op op;

if (!was_set)
return NOTIFY_OK;

now = __current_kernel_time();

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);
return NOTIFY_OK;
}

static struct notifier_block xen_pvclock_gtod_notifier = {
.notifier_call = xen_pvclock_gtod_notify,
};

static struct clocksource xen_clocksource __read_mostly = {
.name = "xen",
.rating = 400,
Expand Down Expand Up @@ -473,6 +498,9 @@ static void __init xen_time_init(void)
xen_setup_runstate_info(cpu);
xen_setup_timer(cpu);
xen_setup_cpu_clockevents();

if (xen_initial_domain())
pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier);
}

void __init xen_init_time_ops(void)
Expand Down

0 comments on commit 5584880

Please sign in to comment.