debuggers.hg

view linux-2.4.28-xen-sparse/arch/xen/kernel/time.c @ 3350:c55cd4b21325

bitkeeper revision 1.1159.1.497 (41c85fb6Idmg_bfo7zG528C4ntiZkw)

Merge scramble.cl.cam.ac.uk:/local/scratch/kaf24/xen-2.0-testing.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xen-unstable.bk
author kaf24@scramble.cl.cam.ac.uk
date Tue Dec 21 17:39:02 2004 +0000 (2004-12-21)
parents ddf5b350364f 52a19a143c6b
children feb29654f4d9
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2002-2003 - Rolf Neugebauer - Intel Research Cambridge
4 * (C) 2002-2003 - Keir Fraser - University of Cambridge
5 ****************************************************************************
6 *
7 * File: arch/xen/kernel/time.c
8 * Author: Rolf Neugebauer and Keir Fraser
9 *
10 * Description: Interface with Xen to get correct notion of time
11 */
13 /*
14 * linux/arch/i386/kernel/time.c
15 *
16 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
17 *
18 * This file contains the PC-specific time handling details:
19 * reading the RTC at bootup, etc..
20 * 1994-07-02 Alan Modra
21 * fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime
22 * 1995-03-26 Markus Kuhn
23 * fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887
24 * precision CMOS clock update
25 * 1996-05-03 Ingo Molnar
26 * fixed time warps in do_[slow|fast]_gettimeoffset()
27 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
28 * "A Kernel Model for Precision Timekeeping" by Dave Mills
29 * 1998-09-05 (Various)
30 * More robust do_fast_gettimeoffset() algorithm implemented
31 * (works with APM, Cyrix 6x86MX and Centaur C6),
32 * monotonic gettimeofday() with fast_get_timeoffset(),
33 * drift-proof precision TSC calibration on boot
34 * (C. Scott Ananian <cananian@alumni.princeton.edu>, Andrew D.
35 * Balsa <andrebalsa@altern.org>, Philip Gladstone <philip@raptor.com>;
36 * ported from 2.0.35 Jumbo-9 by Michael Krause <m.krause@tu-harburg.de>).
37 * 1998-12-16 Andrea Arcangeli
38 * Fixed Jumbo-9 code in 2.1.131: do_gettimeofday was missing 1 jiffy
39 * because was not accounting lost_ticks.
40 * 1998-12-24 Copyright (C) 1998 Andrea Arcangeli
41 * Fixed a xtime SMP race (we need the xtime_lock rw spinlock to
42 * serialize accesses to xtime/lost_ticks).
43 */
45 #include <asm/smp.h>
46 #include <asm/irq.h>
47 #include <asm/msr.h>
48 #include <asm/delay.h>
49 #include <asm/mpspec.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 #include <asm/div64.h>
54 #include <asm/hypervisor.h>
55 #include <asm-xen/xen-public/dom0_ops.h>
57 #include <linux/mc146818rtc.h>
58 #include <linux/kernel.h>
59 #include <linux/interrupt.h>
60 #include <linux/time.h>
61 #include <linux/init.h>
62 #include <linux/smp.h>
63 #include <linux/irq.h>
64 #include <linux/sysctl.h>
65 #include <linux/sysrq.h>
67 spinlock_t rtc_lock = SPIN_LOCK_UNLOCKED;
68 extern rwlock_t xtime_lock;
69 extern unsigned long wall_jiffies;
71 unsigned long cpu_khz; /* get this from Xen, used elsewhere */
73 static unsigned int rdtsc_bitshift;
74 static u32 st_scale_f; /* convert ticks -> usecs */
75 static u32 st_scale_i; /* convert ticks -> usecs */
77 /* These are peridically updated in shared_info, and then copied here. */
78 static u32 shadow_tsc_stamp;
79 static u64 shadow_system_time;
80 static u32 shadow_time_version;
81 static struct timeval shadow_tv;
83 /*
84 * We use this to ensure that gettimeofday() is monotonically increasing. We
85 * only break this guarantee if the wall clock jumps backwards "a long way".
86 */
87 static struct timeval last_seen_tv = {0,0};
89 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
90 /* Periodically propagate synchronised time base to the RTC and to Xen. */
91 static long last_update_to_rtc, last_update_to_xen;
92 #endif
94 /* Periodically take synchronised time base from Xen, if we need it. */
95 static long last_update_from_xen; /* UTC seconds when last read Xen clock. */
97 /* Keep track of last time we did processing/updating of jiffies and xtime. */
98 static u64 processed_system_time; /* System time (ns) at last processing. */
100 #define NS_PER_TICK (1000000000ULL/HZ)
102 #define HANDLE_USEC_UNDERFLOW(_tv) \
103 do { \
104 while ( (_tv).tv_usec < 0 ) \
105 { \
106 (_tv).tv_usec += 1000000; \
107 (_tv).tv_sec--; \
108 } \
109 } while ( 0 )
110 #define HANDLE_USEC_OVERFLOW(_tv) \
111 do { \
112 while ( (_tv).tv_usec >= 1000000 ) \
113 { \
114 (_tv).tv_usec -= 1000000; \
115 (_tv).tv_sec++; \
116 } \
117 } while ( 0 )
119 /* Dynamically-mapped IRQs. */
120 static int time_irq, debug_irq;
122 /* Does this guest OS track Xen time, or set its wall clock independently? */
123 static int independent_wallclock = 0;
124 static int __init __independent_wallclock(char *str)
125 {
126 independent_wallclock = 1;
127 return 1;
128 }
129 __setup("independent_wallclock", __independent_wallclock);
130 #define INDEPENDENT_WALLCLOCK() \
131 (independent_wallclock || (xen_start_info.flags & SIF_INITDOMAIN))
133 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
134 /*
135 * In order to set the CMOS clock precisely, set_rtc_mmss has to be
136 * called 500 ms after the second nowtime has started, because when
137 * nowtime is written into the registers of the CMOS clock, it will
138 * jump to the next second precisely 500 ms later. Check the Motorola
139 * MC146818A or Dallas DS12887 data sheet for details.
140 *
141 * BUG: This routine does not handle hour overflow properly; it just
142 * sets the minutes. Usually you'll only notice that after reboot!
143 */
144 static int set_rtc_mmss(unsigned long nowtime)
145 {
146 int retval = 0;
147 int real_seconds, real_minutes, cmos_minutes;
148 unsigned char save_control, save_freq_select;
150 /* gets recalled with irq locally disabled */
151 spin_lock(&rtc_lock);
152 save_control = CMOS_READ(RTC_CONTROL);
153 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
155 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
156 CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
158 cmos_minutes = CMOS_READ(RTC_MINUTES);
159 if ( !(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD )
160 BCD_TO_BIN(cmos_minutes);
162 /*
163 * since we're only adjusting minutes and seconds, don't interfere with
164 * hour overflow. This avoids messing with unknown time zones but requires
165 * your RTC not to be off by more than 15 minutes
166 */
167 real_seconds = nowtime % 60;
168 real_minutes = nowtime / 60;
169 if ( ((abs(real_minutes - cmos_minutes) + 15)/30) & 1 )
170 real_minutes += 30; /* correct for half hour time zone */
171 real_minutes %= 60;
173 if ( abs(real_minutes - cmos_minutes) < 30 )
174 {
175 if ( !(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD )
176 {
177 BIN_TO_BCD(real_seconds);
178 BIN_TO_BCD(real_minutes);
179 }
180 CMOS_WRITE(real_seconds,RTC_SECONDS);
181 CMOS_WRITE(real_minutes,RTC_MINUTES);
182 }
183 else
184 {
185 printk(KERN_WARNING
186 "set_rtc_mmss: can't update from %d to %d\n",
187 cmos_minutes, real_minutes);
188 retval = -1;
189 }
191 /* The following flags have to be released exactly in this order,
192 * otherwise the DS12887 (popular MC146818A clone with integrated
193 * battery and quartz) will not reset the oscillator and will not
194 * update precisely 500 ms later. You won't find this mentioned in
195 * the Dallas Semiconductor data sheets, but who believes data
196 * sheets anyway ... -- Markus Kuhn
197 */
198 CMOS_WRITE(save_control, RTC_CONTROL);
199 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
200 spin_unlock(&rtc_lock);
202 return retval;
203 }
204 #endif
207 /*
208 * Reads a consistent set of time-base values from Xen, into a shadow data
209 * area. Must be called with the xtime_lock held for writing.
210 */
211 static void __get_time_values_from_xen(void)
212 {
213 do {
214 shadow_time_version = HYPERVISOR_shared_info->time_version2;
215 rmb();
216 shadow_tv.tv_sec = HYPERVISOR_shared_info->wc_sec;
217 shadow_tv.tv_usec = HYPERVISOR_shared_info->wc_usec;
218 shadow_tsc_stamp =
219 (u32)(HYPERVISOR_shared_info->tsc_timestamp >> rdtsc_bitshift);
220 shadow_system_time = HYPERVISOR_shared_info->system_time;
221 rmb();
222 }
223 while ( shadow_time_version != HYPERVISOR_shared_info->time_version1 );
224 }
226 #define TIME_VALUES_UP_TO_DATE \
227 ({ rmb(); (shadow_time_version == HYPERVISOR_shared_info->time_version2); })
230 /*
231 * Returns the system time elapsed, in ns, since the current shadow_timestamp
232 * was calculated. Must be called with the xtime_lock held for reading.
233 */
234 static inline unsigned long __get_time_delta_usecs(void)
235 {
236 s32 delta_tsc;
237 u32 low;
238 u64 delta, tsc;
240 rdtscll(tsc);
241 low = (u32)(tsc >> rdtsc_bitshift);
242 delta_tsc = (s32)(low - shadow_tsc_stamp);
243 if ( unlikely(delta_tsc < 0) ) delta_tsc = 0;
244 delta = ((u64)delta_tsc * st_scale_f);
245 delta >>= 32;
246 delta += ((u64)delta_tsc * st_scale_i);
248 return (unsigned long)delta;
249 }
252 /*
253 * Returns the current time-of-day in UTC timeval format.
254 */
255 void do_gettimeofday(struct timeval *tv)
256 {
257 unsigned long flags, lost;
258 struct timeval _tv;
260 again:
261 read_lock_irqsave(&xtime_lock, flags);
263 _tv.tv_usec = __get_time_delta_usecs();
264 if ( (lost = (jiffies - wall_jiffies)) != 0 )
265 _tv.tv_usec += lost * (1000000 / HZ);
266 _tv.tv_sec = xtime.tv_sec;
267 _tv.tv_usec += xtime.tv_usec;
269 _tv.tv_usec +=
270 (unsigned long)(shadow_system_time - processed_system_time) / 1000UL;
272 if ( unlikely(!TIME_VALUES_UP_TO_DATE) )
273 {
274 /*
275 * We may have blocked for a long time, rendering our calculations
276 * invalid (e.g. the time delta may have overflowed). Detect that
277 * and recalculate with fresh values.
278 */
279 read_unlock_irqrestore(&xtime_lock, flags);
280 write_lock_irqsave(&xtime_lock, flags);
281 __get_time_values_from_xen();
282 write_unlock_irqrestore(&xtime_lock, flags);
283 goto again;
284 }
286 HANDLE_USEC_OVERFLOW(_tv);
288 /* Ensure that time-of-day is monotonically increasing. */
289 if ( (_tv.tv_sec < last_seen_tv.tv_sec) ||
290 ((_tv.tv_sec == last_seen_tv.tv_sec) &&
291 (_tv.tv_usec < last_seen_tv.tv_usec)) )
292 _tv = last_seen_tv;
293 last_seen_tv = _tv;
295 read_unlock_irqrestore(&xtime_lock, flags);
297 *tv = _tv;
298 }
301 /*
302 * Sets the current time-of-day based on passed-in UTC timeval parameter.
303 */
304 void do_settimeofday(struct timeval *tv)
305 {
306 struct timeval newtv;
307 suseconds_t usec;
309 if ( !INDEPENDENT_WALLCLOCK() )
310 return;
312 write_lock_irq(&xtime_lock);
314 /*
315 * Ensure we don't get blocked for a long time so that our time delta
316 * overflows. If that were to happen then our shadow time values would
317 * be stale, so we can retry with fresh ones.
318 */
319 again:
320 usec = tv->tv_usec - __get_time_delta_usecs();
321 usec -=
322 (unsigned long)(shadow_system_time - processed_system_time) / 1000UL;
323 if ( unlikely(!TIME_VALUES_UP_TO_DATE) )
324 {
325 __get_time_values_from_xen();
326 goto again;
327 }
328 tv->tv_usec = usec;
330 HANDLE_USEC_UNDERFLOW(*tv);
332 newtv = *tv;
334 tv->tv_usec -= (jiffies - wall_jiffies) * (1000000 / HZ);
335 HANDLE_USEC_UNDERFLOW(*tv);
337 xtime = *tv;
338 time_adjust = 0; /* stop active adjtime() */
339 time_status |= STA_UNSYNC;
340 time_maxerror = NTP_PHASE_LIMIT;
341 time_esterror = NTP_PHASE_LIMIT;
343 /* Reset all our running time counts. They make no sense now. */
344 last_seen_tv.tv_sec = 0;
345 last_update_from_xen = 0;
347 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
348 if ( xen_start_info.flags & SIF_INITDOMAIN )
349 {
350 dom0_op_t op;
351 last_update_to_rtc = last_update_to_xen = 0;
352 op.cmd = DOM0_SETTIME;
353 op.u.settime.secs = newtv.tv_sec;
354 op.u.settime.usecs = newtv.tv_usec;
355 op.u.settime.system_time = shadow_system_time;
356 write_unlock_irq(&xtime_lock);
357 HYPERVISOR_dom0_op(&op);
358 }
359 else
360 #endif
361 {
362 write_unlock_irq(&xtime_lock);
363 }
364 }
367 asmlinkage long sys_stime(int *tptr)
368 {
369 int value;
370 struct timeval tv;
372 if ( !capable(CAP_SYS_TIME) )
373 return -EPERM;
375 if ( get_user(value, tptr) )
376 return -EFAULT;
378 tv.tv_sec = value;
379 tv.tv_usec = 0;
381 do_settimeofday(&tv);
383 return 0;
384 }
387 /* Convert jiffies to system time. Call with xtime_lock held for reading. */
388 static inline u64 __jiffies_to_st(unsigned long j)
389 {
390 return processed_system_time + ((j - jiffies) * NS_PER_TICK);
391 }
394 static inline void do_timer_interrupt(int irq, void *dev_id,
395 struct pt_regs *regs)
396 {
397 s64 delta;
398 unsigned long ticks = 0;
399 long sec_diff;
401 do {
402 __get_time_values_from_xen();
404 delta = (s64)(shadow_system_time +
405 ((s64)__get_time_delta_usecs() * 1000LL) -
406 processed_system_time);
407 }
408 while ( !TIME_VALUES_UP_TO_DATE );
410 if ( unlikely(delta < 0) )
411 {
412 printk("Timer ISR: Time went backwards: %lld\n", delta);
413 return;
414 }
416 /* Process elapsed jiffies since last call. */
417 while ( delta >= NS_PER_TICK )
418 {
419 ticks++;
420 delta -= NS_PER_TICK;
421 processed_system_time += NS_PER_TICK;
422 }
424 if ( ticks != 0 )
425 {
426 do_timer_ticks(ticks);
428 if ( user_mode(regs) )
429 update_process_times_us(ticks, 0);
430 else
431 update_process_times_us(0, ticks);
432 }
434 /*
435 * Take synchronised time from Xen once a minute if we're not
436 * synchronised ourselves, and we haven't chosen to keep an independent
437 * time base.
438 */
439 if ( !INDEPENDENT_WALLCLOCK() &&
440 ((time_status & STA_UNSYNC) != 0) &&
441 (xtime.tv_sec > (last_update_from_xen + 60)) )
442 {
443 /* Adjust shadow timeval for jiffies that haven't updated xtime yet. */
444 shadow_tv.tv_usec -= (jiffies - wall_jiffies) * (1000000/HZ);
445 HANDLE_USEC_UNDERFLOW(shadow_tv);
447 /*
448 * Reset our running time counts if they are invalidated by a warp
449 * backwards of more than 500ms.
450 */
451 sec_diff = xtime.tv_sec - shadow_tv.tv_sec;
452 if ( unlikely(abs(sec_diff) > 1) ||
453 unlikely(((sec_diff * 1000000) +
454 xtime.tv_usec - shadow_tv.tv_usec) > 500000) )
455 {
456 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
457 last_update_to_rtc = last_update_to_xen = 0;
458 #endif
459 last_seen_tv.tv_sec = 0;
460 }
462 /* Update our unsynchronised xtime appropriately. */
463 xtime = shadow_tv;
465 last_update_from_xen = xtime.tv_sec;
466 }
468 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
469 if ( (xen_start_info.flags & SIF_INITDOMAIN) &&
470 ((time_status & STA_UNSYNC) == 0) )
471 {
472 /* Send synchronised time to Xen approximately every minute. */
473 if ( xtime.tv_sec > (last_update_to_xen + 60) )
474 {
475 dom0_op_t op;
476 struct timeval tv = xtime;
478 tv.tv_usec += (jiffies - wall_jiffies) * (1000000/HZ);
479 HANDLE_USEC_OVERFLOW(tv);
481 op.cmd = DOM0_SETTIME;
482 op.u.settime.secs = tv.tv_sec;
483 op.u.settime.usecs = tv.tv_usec;
484 op.u.settime.system_time = shadow_system_time;
485 HYPERVISOR_dom0_op(&op);
487 last_update_to_xen = xtime.tv_sec;
488 }
490 /*
491 * If we have an externally synchronized Linux clock, then update CMOS
492 * clock accordingly every ~11 minutes. Set_rtc_mmss() has to be called
493 * as close as possible to 500 ms before the new second starts.
494 */
495 if ( (xtime.tv_sec > (last_update_to_rtc + 660)) &&
496 (xtime.tv_usec >= (500000 - ((unsigned) tick) / 2)) &&
497 (xtime.tv_usec <= (500000 + ((unsigned) tick) / 2)) )
498 {
499 if ( set_rtc_mmss(xtime.tv_sec) == 0 )
500 last_update_to_rtc = xtime.tv_sec;
501 else
502 last_update_to_rtc = xtime.tv_sec - 600;
503 }
504 }
505 #endif
506 }
509 static void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
510 {
511 write_lock(&xtime_lock);
512 do_timer_interrupt(irq, NULL, regs);
513 write_unlock(&xtime_lock);
514 }
516 static struct irqaction irq_timer = {
517 timer_interrupt,
518 SA_INTERRUPT,
519 0,
520 "timer",
521 NULL,
522 NULL
523 };
526 /*
527 * This function works out when the the next timer function has to be
528 * executed (by looking at the timer list) and sets the Xen one-shot
529 * domain timer to the appropriate value. This is typically called in
530 * cpu_idle() before the domain blocks.
531 *
532 * The function returns a non-0 value on error conditions.
533 *
534 * It must be called with interrupts disabled.
535 */
536 extern spinlock_t timerlist_lock;
537 int set_timeout_timer(void)
538 {
539 struct timer_list *timer;
540 u64 alarm = 0;
541 int ret = 0;
543 spin_lock(&timerlist_lock);
545 /*
546 * This is safe against long blocking (since calculations are not based on
547 * TSC deltas). It is also safe against warped system time since
548 * suspend-resume is cooperative and we would first get locked out. It is
549 * safe against normal updates of jiffies since interrupts are off.
550 */
551 if ( (timer = next_timer_event()) != NULL )
552 alarm = __jiffies_to_st(timer->expires);
554 /* Tasks on the timer task queue expect to be executed on the next tick. */
555 if ( TQ_ACTIVE(tq_timer) )
556 alarm = __jiffies_to_st(jiffies + 1);
558 /* Failure is pretty bad, but we'd best soldier on. */
559 if ( HYPERVISOR_set_timer_op(alarm) != 0 )
560 ret = -1;
562 spin_unlock(&timerlist_lock);
564 return ret;
565 }
568 /* Time debugging. */
569 static void dbg_time_int(int irq, void *dev_id, struct pt_regs *ptregs)
570 {
571 unsigned long flags, j;
572 u64 s_now, j_st;
573 struct timeval s_tv, tv;
575 struct timer_list *timer;
576 u64 t_st;
578 read_lock_irqsave(&xtime_lock, flags);
579 s_tv.tv_sec = shadow_tv.tv_sec;
580 s_tv.tv_usec = shadow_tv.tv_usec;
581 s_now = shadow_system_time;
582 read_unlock_irqrestore(&xtime_lock, flags);
584 do_gettimeofday(&tv);
586 j = jiffies;
587 j_st = __jiffies_to_st(j);
589 timer = next_timer_event();
590 t_st = __jiffies_to_st(timer->expires);
592 printk(KERN_ALERT "time: shadow_st=0x%X:%08X\n",
593 (u32)(s_now>>32), (u32)s_now);
594 printk(KERN_ALERT "time: wct=%lds %ldus shadow_wct=%lds %ldus\n",
595 tv.tv_sec, tv.tv_usec, s_tv.tv_sec, s_tv.tv_usec);
596 printk(KERN_ALERT "time: jiffies=%lu(0x%X:%08X) timeout=%lu(0x%X:%08X)\n",
597 jiffies,(u32)(j_st>>32), (u32)j_st,
598 timer->expires,(u32)(t_st>>32), (u32)t_st);
599 printk(KERN_ALERT "time: processed_system_time=0x%X:%08X\n",
600 (u32)(processed_system_time>>32), (u32)processed_system_time);
602 #ifdef CONFIG_MAGIC_SYSRQ
603 handle_sysrq('t',NULL,NULL,NULL);
604 #endif
605 }
607 static struct irqaction dbg_time = {
608 dbg_time_int,
609 SA_SHIRQ,
610 0,
611 "timer_dbg",
612 &dbg_time_int,
613 NULL
614 };
616 void __init time_init(void)
617 {
618 unsigned long long alarm;
619 u64 __cpu_khz, __cpu_ghz, cpu_freq, scale, scale2;
620 unsigned int cpu_ghz;
622 __cpu_khz = __cpu_ghz = cpu_freq = HYPERVISOR_shared_info->cpu_freq;
623 do_div(__cpu_khz, 1000UL);
624 cpu_khz = (u32)__cpu_khz;
625 do_div(__cpu_ghz, 1000000000UL);
626 cpu_ghz = (unsigned int)__cpu_ghz;
628 printk("Xen reported: %lu.%03lu MHz processor.\n",
629 cpu_khz / 1000, cpu_khz % 1000);
631 xtime.tv_sec = HYPERVISOR_shared_info->wc_sec;
632 xtime.tv_usec = HYPERVISOR_shared_info->wc_usec;
633 processed_system_time = shadow_system_time;
635 for ( rdtsc_bitshift = 0; cpu_ghz != 0; rdtsc_bitshift++, cpu_ghz >>= 1 )
636 continue;
638 scale = 1000000LL << (32 + rdtsc_bitshift);
639 do_div(scale, (u32)cpu_freq);
641 if ( (cpu_freq >> 32) != 0 )
642 {
643 scale2 = 1000000LL << rdtsc_bitshift;
644 do_div(scale2, (u32)(cpu_freq>>32));
645 scale += scale2;
646 }
648 st_scale_f = scale & 0xffffffff;
649 st_scale_i = scale >> 32;
651 __get_time_values_from_xen();
652 processed_system_time = shadow_system_time;
654 time_irq = bind_virq_to_irq(VIRQ_TIMER);
655 debug_irq = bind_virq_to_irq(VIRQ_DEBUG);
657 (void)setup_irq(time_irq, &irq_timer);
658 (void)setup_irq(debug_irq, &dbg_time);
660 rdtscll(alarm);
661 }
663 void time_suspend(void)
664 {
665 }
667 void time_resume(void)
668 {
669 unsigned long flags;
670 write_lock_irqsave(&xtime_lock, flags);
671 /* Get timebases for new environment. */
672 __get_time_values_from_xen();
673 /* Reset our own concept of passage of system time. */
674 processed_system_time = shadow_system_time;
675 /* Accept a warp in UTC (wall-clock) time. */
676 last_seen_tv.tv_sec = 0;
677 /* Make sure we resync UTC time with Xen on next timer interrupt. */
678 last_update_from_xen = 0;
679 write_unlock_irqrestore(&xtime_lock, flags);
680 }
682 /*
683 * /proc/sys/xen: This really belongs in another file. It can stay here for
684 * now however.
685 */
686 static ctl_table xen_subtable[] = {
687 {1, "independent_wallclock", &independent_wallclock,
688 sizeof(independent_wallclock), 0644, NULL, proc_dointvec},
689 {0}
690 };
691 static ctl_table xen_table[] = {
692 {123, "xen", NULL, 0, 0555, xen_subtable},
693 {0}
694 };
695 static int __init xen_sysctl_init(void)
696 {
697 (void)register_sysctl_table(xen_table, 0);
698 return 0;
699 }
700 __initcall(xen_sysctl_init);