aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/xen/enlighten.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/xen/enlighten.c')
-rw-r--r--arch/arm/xen/enlighten.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index fc7ea529f462..75cd7345c654 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -12,6 +12,7 @@
12#include <xen/page.h> 12#include <xen/page.h>
13#include <xen/interface/sched.h> 13#include <xen/interface/sched.h>
14#include <xen/xen-ops.h> 14#include <xen/xen-ops.h>
15#include <asm/paravirt.h>
15#include <asm/xen/hypervisor.h> 16#include <asm/xen/hypervisor.h>
16#include <asm/xen/hypercall.h> 17#include <asm/xen/hypercall.h>
17#include <asm/system_misc.h> 18#include <asm/system_misc.h>
@@ -25,6 +26,10 @@
25#include <linux/cpufreq.h> 26#include <linux/cpufreq.h>
26#include <linux/cpu.h> 27#include <linux/cpu.h>
27#include <linux/console.h> 28#include <linux/console.h>
29#include <linux/pvclock_gtod.h>
30#include <linux/time64.h>
31#include <linux/timekeeping.h>
32#include <linux/timekeeper_internal.h>
28 33
29#include <linux/mm.h> 34#include <linux/mm.h>
30 35
@@ -79,6 +84,83 @@ int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
79} 84}
80EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range); 85EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
81 86
87static unsigned long long xen_stolen_accounting(int cpu)
88{
89 struct vcpu_runstate_info state;
90
91 BUG_ON(cpu != smp_processor_id());
92
93 xen_get_runstate_snapshot(&state);
94
95 WARN_ON(state.state != RUNSTATE_running);
96
97 return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline];
98}
99
100static void xen_read_wallclock(struct timespec64 *ts)
101{
102 u32 version;
103 struct timespec64 now, ts_monotonic;
104 struct shared_info *s = HYPERVISOR_shared_info;
105 struct pvclock_wall_clock *wall_clock = &(s->wc);
106
107 /* get wallclock at system boot */
108 do {
109 version = wall_clock->version;
110 rmb(); /* fetch version before time */
111 now.tv_sec = ((uint64_t)wall_clock->sec_hi << 32) | wall_clock->sec;
112 now.tv_nsec = wall_clock->nsec;
113 rmb(); /* fetch time before checking version */
114 } while ((wall_clock->version & 1) || (version != wall_clock->version));
115
116 /* time since system boot */
117 ktime_get_ts64(&ts_monotonic);
118 *ts = timespec64_add(now, ts_monotonic);
119}
120
121static 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
160static struct notifier_block xen_pvclock_gtod_notifier = {
161 .notifier_call = xen_pvclock_gtod_notify,
162};
163
82static void xen_percpu_init(void) 164static void xen_percpu_init(void)
83{ 165{
84 struct vcpu_register_vcpu_info info; 166 struct vcpu_register_vcpu_info info;
@@ -104,6 +186,8 @@ static void xen_percpu_init(void)
104 BUG_ON(err); 186 BUG_ON(err);
105 per_cpu(xen_vcpu, cpu) = vcpup; 187 per_cpu(xen_vcpu, cpu) = vcpup;
106 188
189 xen_setup_runstate_info(cpu);
190
107after_register_vcpu_info: 191after_register_vcpu_info:
108 enable_percpu_irq(xen_events_irq, 0); 192 enable_percpu_irq(xen_events_irq, 0);
109 put_cpu(); 193 put_cpu();
@@ -271,6 +355,11 @@ static int __init xen_guest_init(void)
271 355
272 register_cpu_notifier(&xen_cpu_notifier); 356 register_cpu_notifier(&xen_cpu_notifier);
273 357
358 pv_time_ops.steal_clock = xen_stolen_accounting;
359 static_key_slow_inc(&paravirt_steal_enabled);
360 if (xen_initial_domain())
361 pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier);
362
274 return 0; 363 return 0;
275} 364}
276early_initcall(xen_guest_init); 365early_initcall(xen_guest_init);
@@ -282,6 +371,11 @@ static int __init xen_pm_init(void)
282 371
283 pm_power_off = xen_power_off; 372 pm_power_off = xen_power_off;
284 arm_pm_restart = xen_restart; 373 arm_pm_restart = xen_restart;
374 if (!xen_initial_domain()) {
375 struct timespec64 ts;
376 xen_read_wallclock(&ts);
377 do_settimeofday64(&ts);
378 }
285 379
286 return 0; 380 return 0;
287} 381}
@@ -307,5 +401,6 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_memory_op);
307EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op); 401EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op);
308EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op); 402EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op);
309EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op); 403EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op);
404EXPORT_SYMBOL_GPL(HYPERVISOR_platform_op);
310EXPORT_SYMBOL_GPL(HYPERVISOR_multicall); 405EXPORT_SYMBOL_GPL(HYPERVISOR_multicall);
311EXPORT_SYMBOL_GPL(privcmd_call); 406EXPORT_SYMBOL_GPL(privcmd_call);