ia64/xen-unstable

view linux-2.6.10-xen-sparse/arch/xen/i386/kernel/time.c @ 3469:bf476d24f798

bitkeeper revision 1.1159.223.7 (41f02e18RcwEdT0BXMaReeOUBf3KVw)

timer_tsc.c, time.c:
Fix time restore bug.
author kaf24@scramble.cl.cam.ac.uk
date Thu Jan 20 22:18:00 2005 +0000 (2005-01-20)
parents 56a5e9ed0e89
children c90e94e09339
line source
1 /*
2 * linux/arch/i386/kernel/time.c
3 *
4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
5 *
6 * This file contains the PC-specific time handling details:
7 * reading the RTC at bootup, etc..
8 * 1994-07-02 Alan Modra
9 * fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime
10 * 1995-03-26 Markus Kuhn
11 * fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887
12 * precision CMOS clock update
13 * 1996-05-03 Ingo Molnar
14 * fixed time warps in do_[slow|fast]_gettimeoffset()
15 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
16 * "A Kernel Model for Precision Timekeeping" by Dave Mills
17 * 1998-09-05 (Various)
18 * More robust do_fast_gettimeoffset() algorithm implemented
19 * (works with APM, Cyrix 6x86MX and Centaur C6),
20 * monotonic gettimeofday() with fast_get_timeoffset(),
21 * drift-proof precision TSC calibration on boot
22 * (C. Scott Ananian <cananian@alumni.princeton.edu>, Andrew D.
23 * Balsa <andrebalsa@altern.org>, Philip Gladstone <philip@raptor.com>;
24 * ported from 2.0.35 Jumbo-9 by Michael Krause <m.krause@tu-harburg.de>).
25 * 1998-12-16 Andrea Arcangeli
26 * Fixed Jumbo-9 code in 2.1.131: do_gettimeofday was missing 1 jiffy
27 * because was not accounting lost_ticks.
28 * 1998-12-24 Copyright (C) 1998 Andrea Arcangeli
29 * Fixed a xtime SMP race (we need the xtime_lock rw spinlock to
30 * serialize accesses to xtime/lost_ticks).
31 */
33 #include <linux/errno.h>
34 #include <linux/sched.h>
35 #include <linux/kernel.h>
36 #include <linux/param.h>
37 #include <linux/string.h>
38 #include <linux/mm.h>
39 #include <linux/interrupt.h>
40 #include <linux/time.h>
41 #include <linux/delay.h>
42 #include <linux/init.h>
43 #include <linux/smp.h>
44 #include <linux/module.h>
45 #include <linux/sysdev.h>
46 #include <linux/bcd.h>
47 #include <linux/efi.h>
48 #include <linux/sysctl.h>
50 #include <asm/io.h>
51 #include <asm/smp.h>
52 #include <asm/irq.h>
53 #include <asm/msr.h>
54 #include <asm/delay.h>
55 #include <asm/mpspec.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
58 #include <asm/timer.h>
60 #include "mach_time.h"
62 #include <linux/timex.h>
63 #include <linux/config.h>
65 #include <asm/hpet.h>
67 #include <asm/arch_hooks.h>
69 #include "io_ports.h"
71 extern spinlock_t i8259A_lock;
72 int pit_latch_buggy; /* extern */
74 u64 jiffies_64 = INITIAL_JIFFIES;
76 EXPORT_SYMBOL(jiffies_64);
78 unsigned long cpu_khz; /* Detected as we calibrate the TSC */
80 extern unsigned long wall_jiffies;
82 spinlock_t rtc_lock = SPIN_LOCK_UNLOCKED;
84 spinlock_t i8253_lock = SPIN_LOCK_UNLOCKED;
85 EXPORT_SYMBOL(i8253_lock);
87 extern struct init_timer_opts timer_tsc_init;
88 extern struct timer_opts timer_tsc;
89 struct timer_opts *cur_timer = &timer_tsc;
91 /* These are peridically updated in shared_info, and then copied here. */
92 u32 shadow_tsc_stamp;
93 u64 shadow_system_time;
94 static u32 shadow_time_version;
95 static struct timeval shadow_tv;
96 extern u64 processed_system_time;
98 /*
99 * We use this to ensure that gettimeofday() is monotonically increasing. We
100 * only break this guarantee if the wall clock jumps backwards "a long way".
101 */
102 static struct timeval last_seen_tv = {0,0};
104 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
105 /* Periodically propagate synchronised time base to the RTC and to Xen. */
106 static long last_rtc_update, last_update_to_xen;
107 #endif
109 /* Periodically take synchronised time base from Xen, if we need it. */
110 static long last_update_from_xen; /* UTC seconds when last read Xen clock. */
112 /* Keep track of last time we did processing/updating of jiffies and xtime. */
113 u64 processed_system_time; /* System time (ns) at last processing. */
115 #define NS_PER_TICK (1000000000ULL/HZ)
117 #define HANDLE_USEC_UNDERFLOW(_tv) do { \
118 while ((_tv).tv_usec < 0) { \
119 (_tv).tv_usec += USEC_PER_SEC; \
120 (_tv).tv_sec--; \
121 } \
122 } while (0)
123 #define HANDLE_USEC_OVERFLOW(_tv) do { \
124 while ((_tv).tv_usec >= USEC_PER_SEC) { \
125 (_tv).tv_usec -= USEC_PER_SEC; \
126 (_tv).tv_sec++; \
127 } \
128 } while (0)
129 static inline void __normalize_time(time_t *sec, s64 *nsec)
130 {
131 while (*nsec >= NSEC_PER_SEC) {
132 (*nsec) -= NSEC_PER_SEC;
133 (*sec)++;
134 }
135 while (*nsec < 0) {
136 (*nsec) += NSEC_PER_SEC;
137 (*sec)--;
138 }
139 }
141 /* Does this guest OS track Xen time, or set its wall clock independently? */
142 static int independent_wallclock = 0;
143 static int __init __independent_wallclock(char *str)
144 {
145 independent_wallclock = 1;
146 return 1;
147 }
148 __setup("independent_wallclock", __independent_wallclock);
149 #define INDEPENDENT_WALLCLOCK() \
150 (independent_wallclock || (xen_start_info.flags & SIF_INITDOMAIN))
152 /*
153 * Reads a consistent set of time-base values from Xen, into a shadow data
154 * area. Must be called with the xtime_lock held for writing.
155 */
156 static void __get_time_values_from_xen(void)
157 {
158 shared_info_t *s = HYPERVISOR_shared_info;
160 do {
161 shadow_time_version = s->time_version2;
162 rmb();
163 shadow_tv.tv_sec = s->wc_sec;
164 shadow_tv.tv_usec = s->wc_usec;
165 shadow_tsc_stamp = (u32)s->tsc_timestamp;
166 shadow_system_time = s->system_time;
167 rmb();
168 }
169 while (shadow_time_version != s->time_version1);
171 cur_timer->mark_offset();
172 }
174 #define TIME_VALUES_UP_TO_DATE \
175 ({ rmb(); (shadow_time_version == HYPERVISOR_shared_info->time_version2); })
177 /*
178 * This version of gettimeofday has microsecond resolution
179 * and better than microsecond precision on fast x86 machines with TSC.
180 */
181 void do_gettimeofday(struct timeval *tv)
182 {
183 unsigned long seq;
184 unsigned long usec, sec;
185 unsigned long max_ntp_tick;
186 unsigned long flags;
187 s64 nsec;
189 do {
190 unsigned long lost;
192 seq = read_seqbegin(&xtime_lock);
194 usec = cur_timer->get_offset();
195 lost = jiffies - wall_jiffies;
197 /*
198 * If time_adjust is negative then NTP is slowing the clock
199 * so make sure not to go into next possible interval.
200 * Better to lose some accuracy than have time go backwards..
201 */
202 if (unlikely(time_adjust < 0)) {
203 max_ntp_tick = (USEC_PER_SEC / HZ) - tickadj;
204 usec = min(usec, max_ntp_tick);
206 if (lost)
207 usec += lost * max_ntp_tick;
208 }
209 else if (unlikely(lost))
210 usec += lost * (USEC_PER_SEC / HZ);
212 sec = xtime.tv_sec;
213 usec += (xtime.tv_nsec / NSEC_PER_USEC);
215 nsec = shadow_system_time - processed_system_time;
216 __normalize_time(&sec, &nsec);
217 usec += (long)nsec / NSEC_PER_USEC;
219 if (unlikely(!TIME_VALUES_UP_TO_DATE)) {
220 /*
221 * We may have blocked for a long time,
222 * rendering our calculations invalid
223 * (e.g. the time delta may have
224 * overflowed). Detect that and recalculate
225 * with fresh values.
226 */
227 write_seqlock_irqsave(&xtime_lock, flags);
228 __get_time_values_from_xen();
229 write_sequnlock_irqrestore(&xtime_lock, flags);
230 continue;
231 }
232 } while (read_seqretry(&xtime_lock, seq));
234 while (usec >= USEC_PER_SEC) {
235 usec -= USEC_PER_SEC;
236 sec++;
237 }
239 /* Ensure that time-of-day is monotonically increasing. */
240 if ((sec < last_seen_tv.tv_sec) ||
241 ((sec == last_seen_tv.tv_sec) && (usec < last_seen_tv.tv_usec))) {
242 sec = last_seen_tv.tv_sec;
243 usec = last_seen_tv.tv_usec;
244 } else {
245 last_seen_tv.tv_sec = sec;
246 last_seen_tv.tv_usec = usec;
247 }
249 tv->tv_sec = sec;
250 tv->tv_usec = usec;
251 }
253 EXPORT_SYMBOL(do_gettimeofday);
255 int do_settimeofday(struct timespec *tv)
256 {
257 time_t wtm_sec, sec = tv->tv_sec;
258 long wtm_nsec;
259 s64 nsec;
260 struct timespec xentime;
262 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
263 return -EINVAL;
265 if (!INDEPENDENT_WALLCLOCK())
266 return 0; /* Silent failure? */
268 write_seqlock_irq(&xtime_lock);
270 /*
271 * Ensure we don't get blocked for a long time so that our time delta
272 * overflows. If that were to happen then our shadow time values would
273 * be stale, so we can retry with fresh ones.
274 */
275 again:
276 nsec = (s64)tv->tv_nsec -
277 ((s64)cur_timer->get_offset() * (s64)NSEC_PER_USEC);
278 if (unlikely(!TIME_VALUES_UP_TO_DATE)) {
279 __get_time_values_from_xen();
280 goto again;
281 }
283 __normalize_time(&sec, &nsec);
284 set_normalized_timespec(&xentime, sec, nsec);
286 /*
287 * This is revolting. We need to set "xtime" correctly. However, the
288 * value in this location is the value at the most recent update of
289 * wall time. Discover what correction gettimeofday() would have
290 * made, and then undo it!
291 */
292 nsec -= (jiffies - wall_jiffies) * TICK_NSEC;
294 nsec -= (shadow_system_time - processed_system_time);
296 __normalize_time(&sec, &nsec);
297 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
298 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
300 set_normalized_timespec(&xtime, sec, nsec);
301 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
303 time_adjust = 0; /* stop active adjtime() */
304 time_status |= STA_UNSYNC;
305 time_maxerror = NTP_PHASE_LIMIT;
306 time_esterror = NTP_PHASE_LIMIT;
308 /* Reset all our running time counts. They make no sense now. */
309 last_seen_tv.tv_sec = 0;
310 last_update_from_xen = 0;
312 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
313 if (xen_start_info.flags & SIF_INITDOMAIN) {
314 dom0_op_t op;
315 last_rtc_update = last_update_to_xen = 0;
316 op.cmd = DOM0_SETTIME;
317 op.u.settime.secs = xentime.tv_sec;
318 op.u.settime.usecs = xentime.tv_nsec / NSEC_PER_USEC;
319 op.u.settime.system_time = shadow_system_time;
320 write_sequnlock_irq(&xtime_lock);
321 HYPERVISOR_dom0_op(&op);
322 } else
323 #endif
324 write_sequnlock_irq(&xtime_lock);
326 clock_was_set();
327 return 0;
328 }
330 EXPORT_SYMBOL(do_settimeofday);
332 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
333 static int set_rtc_mmss(unsigned long nowtime)
334 {
335 int retval;
337 /* gets recalled with irq locally disabled */
338 spin_lock(&rtc_lock);
339 if (efi_enabled)
340 retval = efi_set_rtc_mmss(nowtime);
341 else
342 retval = mach_set_rtc_mmss(nowtime);
343 spin_unlock(&rtc_lock);
345 return retval;
346 }
347 #endif
349 /* monotonic_clock(): returns # of nanoseconds passed since time_init()
350 * Note: This function is required to return accurate
351 * time even in the absence of multiple timer ticks.
352 */
353 unsigned long long monotonic_clock(void)
354 {
355 return cur_timer->monotonic_clock();
356 }
357 EXPORT_SYMBOL(monotonic_clock);
359 #if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
360 unsigned long profile_pc(struct pt_regs *regs)
361 {
362 unsigned long pc = instruction_pointer(regs);
364 if (in_lock_functions(pc))
365 return *(unsigned long *)(regs->ebp + 4);
367 return pc;
368 }
369 EXPORT_SYMBOL(profile_pc);
370 #endif
372 /*
373 * timer_interrupt() needs to keep up the real-time clock,
374 * as well as call the "do_timer()" routine every clocktick
375 */
376 static inline void do_timer_interrupt(int irq, void *dev_id,
377 struct pt_regs *regs)
378 {
379 time_t wtm_sec, sec;
380 s64 delta, nsec;
381 long sec_diff, wtm_nsec;
383 do {
384 __get_time_values_from_xen();
386 delta = (s64)(shadow_system_time +
387 ((s64)cur_timer->get_offset() *
388 (s64)NSEC_PER_USEC) -
389 processed_system_time);
390 }
391 while (!TIME_VALUES_UP_TO_DATE);
393 if (unlikely(delta < 0)) {
394 printk("Timer ISR: Time went backwards: %lld %lld %lld %lld\n",
395 delta, shadow_system_time,
396 ((s64)cur_timer->get_offset() * (s64)NSEC_PER_USEC),
397 processed_system_time);
398 return;
399 }
401 /* Process elapsed jiffies since last call. */
402 while (delta >= NS_PER_TICK) {
403 delta -= NS_PER_TICK;
404 processed_system_time += NS_PER_TICK;
405 do_timer(regs);
406 #ifndef CONFIG_SMP
407 update_process_times(user_mode(regs));
408 #endif
409 if (regs)
410 profile_tick(CPU_PROFILING, regs);
411 }
413 /*
414 * Take synchronised time from Xen once a minute if we're not
415 * synchronised ourselves, and we haven't chosen to keep an independent
416 * time base.
417 */
418 if (!INDEPENDENT_WALLCLOCK() &&
419 ((time_status & STA_UNSYNC) != 0) &&
420 (xtime.tv_sec > (last_update_from_xen + 60))) {
421 /* Adjust shadow for jiffies that haven't updated xtime yet. */
422 shadow_tv.tv_usec -=
423 (jiffies - wall_jiffies) * (USEC_PER_SEC / HZ);
424 HANDLE_USEC_UNDERFLOW(shadow_tv);
426 /*
427 * Reset our running time counts if they are invalidated by
428 * a warp backwards of more than 500ms.
429 */
430 sec_diff = xtime.tv_sec - shadow_tv.tv_sec;
431 if (unlikely(abs(sec_diff) > 1) ||
432 unlikely(((sec_diff * USEC_PER_SEC) +
433 (xtime.tv_nsec / NSEC_PER_USEC) -
434 shadow_tv.tv_usec) > 500000)) {
435 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
436 last_rtc_update = last_update_to_xen = 0;
437 #endif
438 last_seen_tv.tv_sec = 0;
439 }
441 /* Update our unsynchronised xtime appropriately. */
442 sec = shadow_tv.tv_sec;
443 nsec = shadow_tv.tv_usec * NSEC_PER_USEC;
445 __normalize_time(&sec, &nsec);
446 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
447 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
449 set_normalized_timespec(&xtime, sec, nsec);
450 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
452 last_update_from_xen = sec;
453 }
455 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
456 if (!(xen_start_info.flags & SIF_INITDOMAIN))
457 return;
459 /* Send synchronised time to Xen approximately every minute. */
460 if (((time_status & STA_UNSYNC) == 0) &&
461 (xtime.tv_sec > (last_update_to_xen + 60))) {
462 dom0_op_t op;
463 struct timeval tv;
465 tv.tv_sec = xtime.tv_sec;
466 tv.tv_usec = xtime.tv_nsec / NSEC_PER_USEC;
467 tv.tv_usec += (jiffies - wall_jiffies) * (USEC_PER_SEC/HZ);
468 HANDLE_USEC_OVERFLOW(tv);
470 op.cmd = DOM0_SETTIME;
471 op.u.settime.secs = tv.tv_sec;
472 op.u.settime.usecs = tv.tv_usec;
473 op.u.settime.system_time = shadow_system_time;
474 HYPERVISOR_dom0_op(&op);
476 last_update_to_xen = xtime.tv_sec;
477 }
479 /*
480 * If we have an externally synchronized Linux clock, then update
481 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
482 * called as close as possible to 500 ms before the new second starts.
483 */
484 if ((time_status & STA_UNSYNC) == 0 &&
485 xtime.tv_sec > last_rtc_update + 660 &&
486 (xtime.tv_nsec / 1000)
487 >= USEC_AFTER - ((unsigned) TICK_SIZE) / 2 &&
488 (xtime.tv_nsec / 1000)
489 <= USEC_BEFORE + ((unsigned) TICK_SIZE) / 2) {
490 /* horrible...FIXME */
491 if (efi_enabled) {
492 if (efi_set_rtc_mmss(xtime.tv_sec) == 0)
493 last_rtc_update = xtime.tv_sec;
494 else
495 last_rtc_update = xtime.tv_sec - 600;
496 } else if (set_rtc_mmss(xtime.tv_sec) == 0)
497 last_rtc_update = xtime.tv_sec;
498 else
499 last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
500 }
501 #endif
502 }
504 /*
505 * This is the same as the above, except we _also_ save the current
506 * Time Stamp Counter value at the time of the timer interrupt, so that
507 * we later on can estimate the time of day more exactly.
508 */
509 irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
510 {
511 /*
512 * Here we are in the timer irq handler. We just have irqs locally
513 * disabled but we don't know if the timer_bh is running on the other
514 * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
515 * the irq version of write_lock because as just said we have irq
516 * locally disabled. -arca
517 */
518 write_seqlock(&xtime_lock);
519 do_timer_interrupt(irq, NULL, regs);
520 write_sequnlock(&xtime_lock);
521 return IRQ_HANDLED;
522 }
524 /* not static: needed by APM */
525 unsigned long get_cmos_time(void)
526 {
527 unsigned long retval;
529 spin_lock(&rtc_lock);
531 if (efi_enabled)
532 retval = efi_get_time();
533 else
534 retval = mach_get_cmos_time();
536 spin_unlock(&rtc_lock);
538 return retval;
539 }
541 static long clock_cmos_diff, sleep_start;
543 static int timer_suspend(struct sys_device *dev, u32 state)
544 {
545 /*
546 * Estimate time zone so that set_time can update the clock
547 */
548 clock_cmos_diff = -get_cmos_time();
549 clock_cmos_diff += get_seconds();
550 sleep_start = get_cmos_time();
551 return 0;
552 }
554 static int timer_resume(struct sys_device *dev)
555 {
556 unsigned long flags;
557 unsigned long sec;
558 unsigned long sleep_length;
560 #ifdef CONFIG_HPET_TIMER
561 if (is_hpet_enabled())
562 hpet_reenable();
563 #endif
564 sec = get_cmos_time() + clock_cmos_diff;
565 sleep_length = get_cmos_time() - sleep_start;
566 write_seqlock_irqsave(&xtime_lock, flags);
567 xtime.tv_sec = sec;
568 xtime.tv_nsec = 0;
569 write_sequnlock_irqrestore(&xtime_lock, flags);
570 jiffies += sleep_length * HZ;
571 return 0;
572 }
574 static struct sysdev_class timer_sysclass = {
575 .resume = timer_resume,
576 .suspend = timer_suspend,
577 set_kset_name("timer"),
578 };
581 /* XXX this driverfs stuff should probably go elsewhere later -john */
582 static struct sys_device device_timer = {
583 .id = 0,
584 .cls = &timer_sysclass,
585 };
587 static int time_init_device(void)
588 {
589 int error = sysdev_class_register(&timer_sysclass);
590 if (!error)
591 error = sysdev_register(&device_timer);
592 return error;
593 }
595 device_initcall(time_init_device);
597 #ifdef CONFIG_HPET_TIMER
598 extern void (*late_time_init)(void);
599 /* Duplicate of time_init() below, with hpet_enable part added */
600 void __init hpet_time_init(void)
601 {
602 xtime.tv_sec = get_cmos_time();
603 xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
604 set_normalized_timespec(&wall_to_monotonic,
605 -xtime.tv_sec, -xtime.tv_nsec);
607 if (hpet_enable() >= 0) {
608 printk("Using HPET for base-timer\n");
609 }
611 cur_timer = select_timer();
612 printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
614 time_init_hook();
615 }
616 #endif
618 /* Dynamically-mapped IRQ. */
619 static int TIMER_IRQ;
621 static struct irqaction irq_timer = {
622 timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer",
623 NULL, NULL
624 };
626 void __init time_init(void)
627 {
628 #ifdef CONFIG_HPET_TIMER
629 if (is_hpet_capable()) {
630 /*
631 * HPET initialization needs to do memory-mapped io. So, let
632 * us do a late initialization after mem_init().
633 */
634 late_time_init = hpet_time_init;
635 return;
636 }
637 #endif
638 __get_time_values_from_xen();
639 xtime.tv_sec = shadow_tv.tv_sec;
640 xtime.tv_nsec = shadow_tv.tv_usec * NSEC_PER_USEC;
641 set_normalized_timespec(&wall_to_monotonic,
642 -xtime.tv_sec, -xtime.tv_nsec);
643 processed_system_time = shadow_system_time;
645 if (timer_tsc_init.init(NULL) != 0)
646 BUG();
647 printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
649 TIMER_IRQ = bind_virq_to_irq(VIRQ_TIMER);
651 (void)setup_irq(TIMER_IRQ, &irq_timer);
652 }
654 /* Convert jiffies to system time. Call with xtime_lock held for reading. */
655 static inline u64 __jiffies_to_st(unsigned long j)
656 {
657 return processed_system_time + ((j - jiffies) * NS_PER_TICK);
658 }
660 /*
661 * This function works out when the the next timer function has to be
662 * executed (by looking at the timer list) and sets the Xen one-shot
663 * domain timer to the appropriate value. This is typically called in
664 * cpu_idle() before the domain blocks.
665 *
666 * The function returns a non-0 value on error conditions.
667 *
668 * It must be called with interrupts disabled.
669 */
670 int set_timeout_timer(void)
671 {
672 u64 alarm = 0;
673 int ret = 0;
675 /*
676 * This is safe against long blocking (since calculations are
677 * not based on TSC deltas). It is also safe against warped
678 * system time since suspend-resume is cooperative and we
679 * would first get locked out. It is safe against normal
680 * updates of jiffies since interrupts are off.
681 */
682 alarm = __jiffies_to_st(next_timer_interrupt());
684 /* Failure is pretty bad, but we'd best soldier on. */
685 if ( HYPERVISOR_set_timer_op(alarm) != 0 )
686 ret = -1;
688 return ret;
689 }
691 void time_suspend(void)
692 {
693 /* nothing */
694 }
696 /* No locking required. We are only CPU running, and interrupts are off. */
697 void time_resume(void)
698 {
699 if (timer_tsc_init.init(NULL) != 0)
700 BUG();
702 /* Get timebases for new environment. */
703 __get_time_values_from_xen();
705 /* Reset our own concept of passage of system time. */
706 processed_system_time = shadow_system_time;
708 /* Accept a warp in UTC (wall-clock) time. */
709 last_seen_tv.tv_sec = 0;
711 /* Make sure we resync UTC time with Xen on next timer interrupt. */
712 last_update_from_xen = 0;
713 }
715 /*
716 * /proc/sys/xen: This really belongs in another file. It can stay here for
717 * now however.
718 */
719 static ctl_table xen_subtable[] = {
720 {1, "independent_wallclock", &independent_wallclock,
721 sizeof(independent_wallclock), 0644, NULL, proc_dointvec},
722 {0}
723 };
724 static ctl_table xen_table[] = {
725 {123, "xen", NULL, 0, 0555, xen_subtable},
726 {0}
727 };
728 static int __init xen_sysctl_init(void)
729 {
730 (void)register_sysctl_table(xen_table, 0);
731 return 0;
732 }
733 __initcall(xen_sysctl_init);