David Vrabel
2013-Jun-19 15:25 UTC
[PATCH 3/4] x86/xen: sync the wallclock when the system time is stepped
From: David Vrabel <david.vrabel@citrix.com> The Xen wallclock is a software only clock within the Xen hypervisor that is used by: a) PV guests as the equivalent of a hardware RTC; and b) the hypervisor as the clock source for the emulated RTC provided to HVM guests. Currently the Xen wallclock is only updated every 11 minutes if NTP is synchronized to its clock source. If a guest is started before NTP is synchronized it may see an incorrect wallclock time. Use the clock_was_set notifier chain to receive a notification when the system time is stepped and update the wallclock to match the current system time. Signed-off-by: David Vrabel <david.vrabel@citrix.com> --- arch/x86/xen/time.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index a1947ac..c4bb255 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -211,6 +211,26 @@ static int xen_set_wallclock(const struct timespec *now) return HYPERVISOR_dom0_op(&op); } + +static int xen_clock_was_set_notify(struct notifier_block *nb, unsigned long unused, + void *priv) +{ + struct timespec now; + int ret; + + /* + * Set the Xen wallclock from Linux system time. + */ + now = current_kernel_time(); + xen_set_wallclock(&now); + + return NOTIFY_OK; +} + +static struct notifier_block xen_clock_was_set_notifier = { + .notifier_call = xen_clock_was_set_notify, +}; + static struct clocksource xen_clocksource __read_mostly = { .name = "xen", @@ -473,6 +493,10 @@ static void __init xen_time_init(void) xen_setup_runstate_info(cpu); xen_setup_timer(cpu); xen_setup_cpu_clockevents(); + + if (xen_initial_domain()) + atomic_notifier_chain_register(&clock_was_set_notifier_list, + &xen_clock_was_set_notifier); } void __init xen_init_time_ops(void) -- 1.7.2.5
Jan Beulich
2013-Jun-20 10:43 UTC
Re: [PATCH 3/4] x86/xen: sync the wallclock when the system time is stepped
>>> On 19.06.13 at 17:25, David Vrabel <david.vrabel@citrix.com> wrote: > --- a/arch/x86/xen/time.c > +++ b/arch/x86/xen/time.c > @@ -211,6 +211,26 @@ static int xen_set_wallclock(const struct timespec *now) > > return HYPERVISOR_dom0_op(&op); > } > + > +static int xen_clock_was_set_notify(struct notifier_block *nb, unsigned long unused, > + void *priv) > +{ > + struct timespec now; > + int ret;Unused variable. Jan> + > + /* > + * Set the Xen wallclock from Linux system time. > + */ > + now = current_kernel_time(); > + xen_set_wallclock(&now); > + > + return NOTIFY_OK; > +} > + > +static struct notifier_block xen_clock_was_set_notifier = { > + .notifier_call = xen_clock_was_set_notify, > +}; > + > > static struct clocksource xen_clocksource __read_mostly = { > .name = "xen",
David Vrabel
2013-Jun-20 19:16 UTC
[PATCH 3/4] x86/xen: sync the wallclock when the system time is stepped
From: David Vrabel <david.vrabel@citrix.com> The Xen wallclock is a software only clock within the Xen hypervisor that is used by: a) PV guests as the equivalent of a hardware RTC; and b) the hypervisor as the clock source for the emulated RTC provided to HVM guests. Currently the Xen wallclock is only updated every 11 minutes if NTP is synchronized to its clock source. If a guest is started before NTP is synchronized it may see an incorrect wallclock time. Use the clock_was_set notifier chain to receive a notification when the system time is stepped and update the wallclock to match the current system time. Signed-off-by: David Vrabel <david.vrabel@citrix.com> --- arch/x86/xen/time.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index a1947ac..ad077ca 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -211,6 +211,25 @@ static int xen_set_wallclock(const struct timespec *now) return HYPERVISOR_dom0_op(&op); } + +static int xen_clock_was_set_notify(struct notifier_block *nb, unsigned long unused, + void *priv) +{ + struct timespec now; + + /* + * Set the Xen wallclock from Linux system time. + */ + now = current_kernel_time(); + xen_set_wallclock(&now); + + return NOTIFY_OK; +} + +static struct notifier_block xen_clock_was_set_notifier = { + .notifier_call = xen_clock_was_set_notify, +}; + static struct clocksource xen_clocksource __read_mostly = { .name = "xen", @@ -473,6 +492,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()) + register_clock_was_set_notifier(&xen_clock_was_set_notifier); } void __init xen_init_time_ops(void) -- 1.7.2.5