diff options
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2015-11-23 05:41:12 -0500 |
---|---|---|
committer | David Vrabel <david.vrabel@citrix.com> | 2015-12-21 09:40:58 -0500 |
commit | 7d5f6f81ddbb5b532a832cbeb65472541b22a7c2 (patch) | |
tree | a9a8e39e26c595f011f35675cd2a7f36e99324ee /arch/arm/xen/enlighten.c | |
parent | e709fba132db696bbc21fca2e7f736198ec53eda (diff) |
xen/arm: set the system time in Xen via the XENPF_settime64 hypercall
If Linux is running as dom0, call XENPF_settime64 to update the system
time in Xen on pvclock_gtod notifications.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/arm/xen/enlighten.c')
-rw-r--r-- | arch/arm/xen/enlighten.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 6370222b8053..75cd7345c654 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c | |||
@@ -26,7 +26,10 @@ | |||
26 | #include <linux/cpufreq.h> | 26 | #include <linux/cpufreq.h> |
27 | #include <linux/cpu.h> | 27 | #include <linux/cpu.h> |
28 | #include <linux/console.h> | 28 | #include <linux/console.h> |
29 | #include <linux/pvclock_gtod.h> | ||
30 | #include <linux/time64.h> | ||
29 | #include <linux/timekeeping.h> | 31 | #include <linux/timekeeping.h> |
32 | #include <linux/timekeeper_internal.h> | ||
30 | 33 | ||
31 | #include <linux/mm.h> | 34 | #include <linux/mm.h> |
32 | 35 | ||
@@ -115,6 +118,49 @@ static void xen_read_wallclock(struct timespec64 *ts) | |||
115 | *ts = timespec64_add(now, ts_monotonic); | 118 | *ts = timespec64_add(now, ts_monotonic); |
116 | } | 119 | } |
117 | 120 | ||
121 | static int xen_pvclock_gtod_notify(struct notifier_block *nb, | ||
122 | unsigned long was_set, void *priv) | ||
123 | { | ||
124 | /* Protected by the calling core code serialization */ | ||
125 | static struct timespec64 next_sync; | ||
126 | |||
127 | struct xen_platform_op op; | ||
128 | struct timespec64 now, system_time; | ||
129 | struct timekeeper *tk = priv; | ||
130 | |||
131 | now.tv_sec = tk->xtime_sec; | ||
132 | now.tv_nsec = (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); | ||
133 | system_time = timespec64_add(now, tk->wall_to_monotonic); | ||
134 | |||
135 | /* | ||
136 | * We only take the expensive HV call when the clock was set | ||
137 | * or when the 11 minutes RTC synchronization time elapsed. | ||
138 | */ | ||
139 | if (!was_set && timespec64_compare(&now, &next_sync) < 0) | ||
140 | return NOTIFY_OK; | ||
141 | |||
142 | op.cmd = XENPF_settime64; | ||
143 | op.u.settime64.mbz = 0; | ||
144 | op.u.settime64.secs = now.tv_sec; | ||
145 | op.u.settime64.nsecs = now.tv_nsec; | ||
146 | op.u.settime64.system_time = timespec64_to_ns(&system_time); | ||
147 | (void)HYPERVISOR_platform_op(&op); | ||
148 | |||
149 | /* | ||
150 | * Move the next drift compensation time 11 minutes | ||
151 | * ahead. That's emulating the sync_cmos_clock() update for | ||
152 | * the hardware RTC. | ||
153 | */ | ||
154 | next_sync = now; | ||
155 | next_sync.tv_sec += 11 * 60; | ||
156 | |||
157 | return NOTIFY_OK; | ||
158 | } | ||
159 | |||
160 | static struct notifier_block xen_pvclock_gtod_notifier = { | ||
161 | .notifier_call = xen_pvclock_gtod_notify, | ||
162 | }; | ||
163 | |||
118 | static void xen_percpu_init(void) | 164 | static void xen_percpu_init(void) |
119 | { | 165 | { |
120 | struct vcpu_register_vcpu_info info; | 166 | struct vcpu_register_vcpu_info info; |
@@ -311,6 +357,8 @@ static int __init xen_guest_init(void) | |||
311 | 357 | ||
312 | pv_time_ops.steal_clock = xen_stolen_accounting; | 358 | pv_time_ops.steal_clock = xen_stolen_accounting; |
313 | static_key_slow_inc(¶virt_steal_enabled); | 359 | static_key_slow_inc(¶virt_steal_enabled); |
360 | if (xen_initial_domain()) | ||
361 | pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier); | ||
314 | 362 | ||
315 | return 0; | 363 | return 0; |
316 | } | 364 | } |