ia64/xen-unstable

view linux-2.6.11-xen-sparse/arch/xen/i386/kernel/time.c @ 4295:573e67095682

bitkeeper revision 1.1159.272.10 (4242f845cpppoqILZOUsc9BDNxlTUA)

Set a block timeout at least a jiffy ahead, to have same behaviour
as native Linux.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Mar 24 17:26:29 2005 +0000 (2005-03-24)
parents cff0d3baf599
children 7e0520c972fb 2fa2e30bcbde
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/mca.h>
49 #include <linux/sysctl.h>
51 #include <asm/io.h>
52 #include <asm/smp.h>
53 #include <asm/irq.h>
54 #include <asm/msr.h>
55 #include <asm/delay.h>
56 #include <asm/mpspec.h>
57 #include <asm/uaccess.h>
58 #include <asm/processor.h>
59 #include <asm/timer.h>
61 #include "mach_time.h"
63 #include <linux/timex.h>
64 #include <linux/config.h>
66 #include <asm/hpet.h>
68 #include <asm/arch_hooks.h>
70 #include "io_ports.h"
72 extern spinlock_t i8259A_lock;
73 int pit_latch_buggy; /* extern */
75 u64 jiffies_64 = INITIAL_JIFFIES;
77 EXPORT_SYMBOL(jiffies_64);
79 unsigned long cpu_khz; /* Detected as we calibrate the TSC */
81 extern unsigned long wall_jiffies;
83 DEFINE_SPINLOCK(rtc_lock);
85 DEFINE_SPINLOCK(i8253_lock);
86 EXPORT_SYMBOL(i8253_lock);
88 extern struct init_timer_opts timer_tsc_init;
89 extern struct timer_opts timer_tsc;
90 struct timer_opts *cur_timer = &timer_tsc;
92 /* These are peridically updated in shared_info, and then copied here. */
93 u32 shadow_tsc_stamp;
94 u64 shadow_system_time;
95 static u32 shadow_time_version;
96 static struct timeval shadow_tv;
97 extern u64 processed_system_time;
99 /*
100 * We use this to ensure that gettimeofday() is monotonically increasing. We
101 * only break this guarantee if the wall clock jumps backwards "a long way".
102 */
103 static struct timeval last_seen_tv = {0,0};
105 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
106 /* Periodically propagate synchronised time base to the RTC and to Xen. */
107 static long last_rtc_update, last_update_to_xen;
108 #endif
110 /* Periodically take synchronised time base from Xen, if we need it. */
111 static long last_update_from_xen; /* UTC seconds when last read Xen clock. */
113 /* Keep track of last time we did processing/updating of jiffies and xtime. */
114 u64 processed_system_time; /* System time (ns) at last processing. */
116 #define NS_PER_TICK (1000000000ULL/HZ)
118 #define HANDLE_USEC_UNDERFLOW(_tv) do { \
119 while ((_tv).tv_usec < 0) { \
120 (_tv).tv_usec += USEC_PER_SEC; \
121 (_tv).tv_sec--; \
122 } \
123 } while (0)
124 #define HANDLE_USEC_OVERFLOW(_tv) do { \
125 while ((_tv).tv_usec >= USEC_PER_SEC) { \
126 (_tv).tv_usec -= USEC_PER_SEC; \
127 (_tv).tv_sec++; \
128 } \
129 } while (0)
130 static inline void __normalize_time(time_t *sec, s64 *nsec)
131 {
132 while (*nsec >= NSEC_PER_SEC) {
133 (*nsec) -= NSEC_PER_SEC;
134 (*sec)++;
135 }
136 while (*nsec < 0) {
137 (*nsec) += NSEC_PER_SEC;
138 (*sec)--;
139 }
140 }
142 /* Does this guest OS track Xen time, or set its wall clock independently? */
143 static int independent_wallclock = 0;
144 static int __init __independent_wallclock(char *str)
145 {
146 independent_wallclock = 1;
147 return 1;
148 }
149 __setup("independent_wallclock", __independent_wallclock);
150 #define INDEPENDENT_WALLCLOCK() \
151 (independent_wallclock || (xen_start_info.flags & SIF_INITDOMAIN))
153 /*
154 * Reads a consistent set of time-base values from Xen, into a shadow data
155 * area. Must be called with the xtime_lock held for writing.
156 */
157 static void __get_time_values_from_xen(void)
158 {
159 shared_info_t *s = HYPERVISOR_shared_info;
161 do {
162 shadow_time_version = s->time_version2;
163 rmb();
164 shadow_tv.tv_sec = s->wc_sec;
165 shadow_tv.tv_usec = s->wc_usec;
166 shadow_tsc_stamp = (u32)s->tsc_timestamp;
167 shadow_system_time = s->system_time;
168 rmb();
169 }
170 while (shadow_time_version != s->time_version1);
172 cur_timer->mark_offset();
173 }
175 #define TIME_VALUES_UP_TO_DATE \
176 ({ rmb(); (shadow_time_version == HYPERVISOR_shared_info->time_version2); })
178 /*
179 * This version of gettimeofday has microsecond resolution
180 * and better than microsecond precision on fast x86 machines with TSC.
181 */
182 void do_gettimeofday(struct timeval *tv)
183 {
184 unsigned long seq;
185 unsigned long usec, sec;
186 unsigned long max_ntp_tick;
187 unsigned long flags;
188 s64 nsec;
190 do {
191 unsigned long lost;
193 seq = read_seqbegin(&xtime_lock);
195 usec = cur_timer->get_offset();
196 lost = jiffies - wall_jiffies;
198 /*
199 * If time_adjust is negative then NTP is slowing the clock
200 * so make sure not to go into next possible interval.
201 * Better to lose some accuracy than have time go backwards..
202 */
203 if (unlikely(time_adjust < 0)) {
204 max_ntp_tick = (USEC_PER_SEC / HZ) - tickadj;
205 usec = min(usec, max_ntp_tick);
207 if (lost)
208 usec += lost * max_ntp_tick;
209 }
210 else if (unlikely(lost))
211 usec += lost * (USEC_PER_SEC / HZ);
213 sec = xtime.tv_sec;
214 usec += (xtime.tv_nsec / NSEC_PER_USEC);
216 nsec = shadow_system_time - processed_system_time;
217 __normalize_time(&sec, &nsec);
218 usec += (long)nsec / NSEC_PER_USEC;
220 if (unlikely(!TIME_VALUES_UP_TO_DATE)) {
221 /*
222 * We may have blocked for a long time,
223 * rendering our calculations invalid
224 * (e.g. the time delta may have
225 * overflowed). Detect that and recalculate
226 * with fresh values.
227 */
228 write_seqlock_irqsave(&xtime_lock, flags);
229 __get_time_values_from_xen();
230 write_sequnlock_irqrestore(&xtime_lock, flags);
231 continue;
232 }
233 } while (read_seqretry(&xtime_lock, seq));
235 while (usec >= USEC_PER_SEC) {
236 usec -= USEC_PER_SEC;
237 sec++;
238 }
240 /* Ensure that time-of-day is monotonically increasing. */
241 if ((sec < last_seen_tv.tv_sec) ||
242 ((sec == last_seen_tv.tv_sec) && (usec < last_seen_tv.tv_usec))) {
243 sec = last_seen_tv.tv_sec;
244 usec = last_seen_tv.tv_usec;
245 } else {
246 last_seen_tv.tv_sec = sec;
247 last_seen_tv.tv_usec = usec;
248 }
250 tv->tv_sec = sec;
251 tv->tv_usec = usec;
252 }
254 EXPORT_SYMBOL(do_gettimeofday);
256 int do_settimeofday(struct timespec *tv)
257 {
258 time_t wtm_sec, sec = tv->tv_sec;
259 long wtm_nsec;
260 s64 nsec;
261 struct timespec xentime;
263 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
264 return -EINVAL;
266 if (!INDEPENDENT_WALLCLOCK())
267 return 0; /* Silent failure? */
269 write_seqlock_irq(&xtime_lock);
271 /*
272 * Ensure we don't get blocked for a long time so that our time delta
273 * overflows. If that were to happen then our shadow time values would
274 * be stale, so we can retry with fresh ones.
275 */
276 again:
277 nsec = (s64)tv->tv_nsec -
278 ((s64)cur_timer->get_offset() * (s64)NSEC_PER_USEC);
279 if (unlikely(!TIME_VALUES_UP_TO_DATE)) {
280 __get_time_values_from_xen();
281 goto again;
282 }
284 __normalize_time(&sec, &nsec);
285 set_normalized_timespec(&xentime, sec, nsec);
287 /*
288 * This is revolting. We need to set "xtime" correctly. However, the
289 * value in this location is the value at the most recent update of
290 * wall time. Discover what correction gettimeofday() would have
291 * made, and then undo it!
292 */
293 nsec -= (jiffies - wall_jiffies) * TICK_NSEC;
295 nsec -= (shadow_system_time - processed_system_time);
297 __normalize_time(&sec, &nsec);
298 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
299 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
301 set_normalized_timespec(&xtime, sec, nsec);
302 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
304 time_adjust = 0; /* stop active adjtime() */
305 time_status |= STA_UNSYNC;
306 time_maxerror = NTP_PHASE_LIMIT;
307 time_esterror = NTP_PHASE_LIMIT;
309 /* Reset all our running time counts. They make no sense now. */
310 last_seen_tv.tv_sec = 0;
311 last_update_from_xen = 0;
313 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
314 if (xen_start_info.flags & SIF_INITDOMAIN) {
315 dom0_op_t op;
316 last_rtc_update = last_update_to_xen = 0;
317 op.cmd = DOM0_SETTIME;
318 op.u.settime.secs = xentime.tv_sec;
319 op.u.settime.usecs = xentime.tv_nsec / NSEC_PER_USEC;
320 op.u.settime.system_time = shadow_system_time;
321 write_sequnlock_irq(&xtime_lock);
322 HYPERVISOR_dom0_op(&op);
323 } else
324 #endif
325 write_sequnlock_irq(&xtime_lock);
327 clock_was_set();
328 return 0;
329 }
331 EXPORT_SYMBOL(do_settimeofday);
333 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
334 static int set_rtc_mmss(unsigned long nowtime)
335 {
336 int retval;
338 /* gets recalled with irq locally disabled */
339 spin_lock(&rtc_lock);
340 if (efi_enabled)
341 retval = efi_set_rtc_mmss(nowtime);
342 else
343 retval = mach_set_rtc_mmss(nowtime);
344 spin_unlock(&rtc_lock);
346 return retval;
347 }
348 #endif
350 /* monotonic_clock(): returns # of nanoseconds passed since time_init()
351 * Note: This function is required to return accurate
352 * time even in the absence of multiple timer ticks.
353 */
354 unsigned long long monotonic_clock(void)
355 {
356 return cur_timer->monotonic_clock();
357 }
358 EXPORT_SYMBOL(monotonic_clock);
360 #if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
361 unsigned long profile_pc(struct pt_regs *regs)
362 {
363 unsigned long pc = instruction_pointer(regs);
365 if (in_lock_functions(pc))
366 return *(unsigned long *)(regs->ebp + 4);
368 return pc;
369 }
370 EXPORT_SYMBOL(profile_pc);
371 #endif
373 /*
374 * timer_interrupt() needs to keep up the real-time clock,
375 * as well as call the "do_timer()" routine every clocktick
376 */
377 static inline void do_timer_interrupt(int irq, void *dev_id,
378 struct pt_regs *regs)
379 {
380 time_t wtm_sec, sec;
381 s64 delta, nsec;
382 long sec_diff, wtm_nsec;
384 do {
385 __get_time_values_from_xen();
387 delta = (s64)(shadow_system_time +
388 ((s64)cur_timer->get_offset() *
389 (s64)NSEC_PER_USEC) -
390 processed_system_time);
391 }
392 while (!TIME_VALUES_UP_TO_DATE);
394 if (unlikely(delta < 0)) {
395 printk("Timer ISR: Time went backwards: %lld %lld %lld %lld\n",
396 delta, shadow_system_time,
397 ((s64)cur_timer->get_offset() * (s64)NSEC_PER_USEC),
398 processed_system_time);
399 return;
400 }
402 /* Process elapsed jiffies since last call. */
403 while (delta >= NS_PER_TICK) {
404 delta -= NS_PER_TICK;
405 processed_system_time += NS_PER_TICK;
406 do_timer(regs);
407 #ifndef CONFIG_SMP
408 update_process_times(user_mode(regs));
409 #endif
410 if (regs)
411 profile_tick(CPU_PROFILING, regs);
412 }
414 /*
415 * Take synchronised time from Xen once a minute if we're not
416 * synchronised ourselves, and we haven't chosen to keep an independent
417 * time base.
418 */
419 if (!INDEPENDENT_WALLCLOCK() &&
420 ((time_status & STA_UNSYNC) != 0) &&
421 (xtime.tv_sec > (last_update_from_xen + 60))) {
422 /* Adjust shadow for jiffies that haven't updated xtime yet. */
423 shadow_tv.tv_usec -=
424 (jiffies - wall_jiffies) * (USEC_PER_SEC / HZ);
425 HANDLE_USEC_UNDERFLOW(shadow_tv);
427 /*
428 * Reset our running time counts if they are invalidated by
429 * a warp backwards of more than 500ms.
430 */
431 sec_diff = xtime.tv_sec - shadow_tv.tv_sec;
432 if (unlikely(abs(sec_diff) > 1) ||
433 unlikely(((sec_diff * USEC_PER_SEC) +
434 (xtime.tv_nsec / NSEC_PER_USEC) -
435 shadow_tv.tv_usec) > 500000)) {
436 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
437 last_rtc_update = last_update_to_xen = 0;
438 #endif
439 last_seen_tv.tv_sec = 0;
440 }
442 /* Update our unsynchronised xtime appropriately. */
443 sec = shadow_tv.tv_sec;
444 nsec = shadow_tv.tv_usec * NSEC_PER_USEC;
446 __normalize_time(&sec, &nsec);
447 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
448 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
450 set_normalized_timespec(&xtime, sec, nsec);
451 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
453 last_update_from_xen = sec;
454 }
456 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
457 if (!(xen_start_info.flags & SIF_INITDOMAIN))
458 return;
460 /* Send synchronised time to Xen approximately every minute. */
461 if (((time_status & STA_UNSYNC) == 0) &&
462 (xtime.tv_sec > (last_update_to_xen + 60))) {
463 dom0_op_t op;
464 struct timeval tv;
466 tv.tv_sec = xtime.tv_sec;
467 tv.tv_usec = xtime.tv_nsec / NSEC_PER_USEC;
468 tv.tv_usec += (jiffies - wall_jiffies) * (USEC_PER_SEC/HZ);
469 HANDLE_USEC_OVERFLOW(tv);
471 op.cmd = DOM0_SETTIME;
472 op.u.settime.secs = tv.tv_sec;
473 op.u.settime.usecs = tv.tv_usec;
474 op.u.settime.system_time = shadow_system_time;
475 HYPERVISOR_dom0_op(&op);
477 last_update_to_xen = xtime.tv_sec;
478 }
480 /*
481 * If we have an externally synchronized Linux clock, then update
482 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
483 * called as close as possible to 500 ms before the new second starts.
484 */
485 if ((time_status & STA_UNSYNC) == 0 &&
486 xtime.tv_sec > last_rtc_update + 660 &&
487 (xtime.tv_nsec / 1000)
488 >= USEC_AFTER - ((unsigned) TICK_SIZE) / 2 &&
489 (xtime.tv_nsec / 1000)
490 <= USEC_BEFORE + ((unsigned) TICK_SIZE) / 2) {
491 /* horrible...FIXME */
492 if (efi_enabled) {
493 if (efi_set_rtc_mmss(xtime.tv_sec) == 0)
494 last_rtc_update = xtime.tv_sec;
495 else
496 last_rtc_update = xtime.tv_sec - 600;
497 } else if (set_rtc_mmss(xtime.tv_sec) == 0)
498 last_rtc_update = xtime.tv_sec;
499 else
500 last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
501 }
502 #endif
503 }
505 /*
506 * This is the same as the above, except we _also_ save the current
507 * Time Stamp Counter value at the time of the timer interrupt, so that
508 * we later on can estimate the time of day more exactly.
509 */
510 irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
511 {
512 /*
513 * Here we are in the timer irq handler. We just have irqs locally
514 * disabled but we don't know if the timer_bh is running on the other
515 * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
516 * the irq version of write_lock because as just said we have irq
517 * locally disabled. -arca
518 */
519 write_seqlock(&xtime_lock);
520 do_timer_interrupt(irq, NULL, regs);
521 write_sequnlock(&xtime_lock);
522 return IRQ_HANDLED;
523 }
525 /* not static: needed by APM */
526 unsigned long get_cmos_time(void)
527 {
528 unsigned long retval;
530 spin_lock(&rtc_lock);
532 if (efi_enabled)
533 retval = efi_get_time();
534 else
535 retval = mach_get_cmos_time();
537 spin_unlock(&rtc_lock);
539 return retval;
540 }
542 static long clock_cmos_diff, sleep_start;
544 static int timer_suspend(struct sys_device *dev, u32 state)
545 {
546 /*
547 * Estimate time zone so that set_time can update the clock
548 */
549 clock_cmos_diff = -get_cmos_time();
550 clock_cmos_diff += get_seconds();
551 sleep_start = get_cmos_time();
552 return 0;
553 }
555 static int timer_resume(struct sys_device *dev)
556 {
557 unsigned long flags;
558 unsigned long sec;
559 unsigned long sleep_length;
561 #ifdef CONFIG_HPET_TIMER
562 if (is_hpet_enabled())
563 hpet_reenable();
564 #endif
565 sec = get_cmos_time() + clock_cmos_diff;
566 sleep_length = (get_cmos_time() - sleep_start) * HZ;
567 write_seqlock_irqsave(&xtime_lock, flags);
568 xtime.tv_sec = sec;
569 xtime.tv_nsec = 0;
570 write_sequnlock_irqrestore(&xtime_lock, flags);
571 jiffies += sleep_length;
572 wall_jiffies += sleep_length;
573 return 0;
574 }
576 static struct sysdev_class timer_sysclass = {
577 .resume = timer_resume,
578 .suspend = timer_suspend,
579 set_kset_name("timer"),
580 };
583 /* XXX this driverfs stuff should probably go elsewhere later -john */
584 static struct sys_device device_timer = {
585 .id = 0,
586 .cls = &timer_sysclass,
587 };
589 static int time_init_device(void)
590 {
591 int error = sysdev_class_register(&timer_sysclass);
592 if (!error)
593 error = sysdev_register(&device_timer);
594 return error;
595 }
597 device_initcall(time_init_device);
599 #ifdef CONFIG_HPET_TIMER
600 extern void (*late_time_init)(void);
601 /* Duplicate of time_init() below, with hpet_enable part added */
602 void __init hpet_time_init(void)
603 {
604 xtime.tv_sec = get_cmos_time();
605 xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
606 set_normalized_timespec(&wall_to_monotonic,
607 -xtime.tv_sec, -xtime.tv_nsec);
609 if (hpet_enable() >= 0) {
610 printk("Using HPET for base-timer\n");
611 }
613 cur_timer = select_timer();
614 printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
616 time_init_hook();
617 }
618 #endif
620 /* Dynamically-mapped IRQ. */
621 static int TIMER_IRQ;
623 static struct irqaction irq_timer = {
624 timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer",
625 NULL, NULL
626 };
628 void __init time_init(void)
629 {
630 #ifdef CONFIG_HPET_TIMER
631 if (is_hpet_capable()) {
632 /*
633 * HPET initialization needs to do memory-mapped io. So, let
634 * us do a late initialization after mem_init().
635 */
636 late_time_init = hpet_time_init;
637 return;
638 }
639 #endif
640 __get_time_values_from_xen();
641 xtime.tv_sec = shadow_tv.tv_sec;
642 xtime.tv_nsec = shadow_tv.tv_usec * NSEC_PER_USEC;
643 set_normalized_timespec(&wall_to_monotonic,
644 -xtime.tv_sec, -xtime.tv_nsec);
645 processed_system_time = shadow_system_time;
647 if (timer_tsc_init.init(NULL) != 0)
648 BUG();
649 printk(KERN_INFO "Using %s for high-res timesource\n",cur_timer->name);
651 TIMER_IRQ = bind_virq_to_irq(VIRQ_TIMER);
653 (void)setup_irq(TIMER_IRQ, &irq_timer);
654 }
656 /* Convert jiffies to system time. Call with xtime_lock held for reading. */
657 static inline u64 __jiffies_to_st(unsigned long j)
658 {
659 return processed_system_time + ((j - jiffies) * NS_PER_TICK);
660 }
662 /*
663 * This function works out when the the next timer function has to be
664 * executed (by looking at the timer list) and sets the Xen one-shot
665 * domain timer to the appropriate value. This is typically called in
666 * cpu_idle() before the domain blocks.
667 *
668 * The function returns a non-0 value on error conditions.
669 *
670 * It must be called with interrupts disabled.
671 */
672 int set_timeout_timer(void)
673 {
674 u64 alarm = 0;
675 int ret = 0;
676 unsigned long j;
678 /*
679 * This is safe against long blocking (since calculations are
680 * not based on TSC deltas). It is also safe against warped
681 * system time since suspend-resume is cooperative and we
682 * would first get locked out. It is safe against normal
683 * updates of jiffies since interrupts are off.
684 */
685 j = next_timer_interrupt();
686 if (j < (jiffies + 1))
687 j = jiffies + 1;
688 alarm = __jiffies_to_st(j);
690 /* Failure is pretty bad, but we'd best soldier on. */
691 if ( HYPERVISOR_set_timer_op(alarm) != 0 )
692 ret = -1;
694 return ret;
695 }
697 void time_suspend(void)
698 {
699 /* nothing */
700 }
702 /* No locking required. We are only CPU running, and interrupts are off. */
703 void time_resume(void)
704 {
705 if (timer_tsc_init.init(NULL) != 0)
706 BUG();
708 /* Get timebases for new environment. */
709 __get_time_values_from_xen();
711 /* Reset our own concept of passage of system time. */
712 processed_system_time = shadow_system_time;
714 /* Accept a warp in UTC (wall-clock) time. */
715 last_seen_tv.tv_sec = 0;
717 /* Make sure we resync UTC time with Xen on next timer interrupt. */
718 last_update_from_xen = 0;
719 }
721 /*
722 * /proc/sys/xen: This really belongs in another file. It can stay here for
723 * now however.
724 */
725 static ctl_table xen_subtable[] = {
726 {1, "independent_wallclock", &independent_wallclock,
727 sizeof(independent_wallclock), 0644, NULL, proc_dointvec},
728 {0}
729 };
730 static ctl_table xen_table[] = {
731 {123, "xen", NULL, 0, 0555, xen_subtable},
732 {0}
733 };
734 static int __init xen_sysctl_init(void)
735 {
736 (void)register_sysctl_table(xen_table, 0);
737 return 0;
738 }
739 __initcall(xen_sysctl_init);