2.2.0-final
[davej-history.git] / arch / i386 / kernel / time.c
blobec2ea5d606f8871b403ba159a975bf753861cf1c
1 /*
2 * linux/arch/i386/kernel/time.c
4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
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).
33 /* What about the "updated NTP code" stuff in 2.0 time.c? It's not in
34 * 2.1, perhaps it should be ported, too.
36 * What about the BUGGY_NEPTUN_TIMER stuff in do_slow_gettimeoffset()?
37 * Whatever it fixes, is it also fixed in the new code from the Jumbo
38 * patch, so that that code can be used instead?
40 * The CPU Hz should probably be displayed in check_bugs() together
41 * with the CPU vendor and type. Perhaps even only in MHz, though that
42 * takes away some of the fun of the new code :)
44 * - Michael Krause */
46 #include <linux/errno.h>
47 #include <linux/sched.h>
48 #include <linux/kernel.h>
49 #include <linux/param.h>
50 #include <linux/string.h>
51 #include <linux/mm.h>
52 #include <linux/interrupt.h>
53 #include <linux/time.h>
54 #include <linux/delay.h>
55 #include <linux/init.h>
56 #include <linux/smp.h>
58 #include <asm/processor.h>
59 #include <asm/uaccess.h>
60 #include <asm/io.h>
61 #include <asm/irq.h>
62 #include <asm/delay.h>
64 #include <linux/mc146818rtc.h>
65 #include <linux/timex.h>
66 #include <linux/config.h>
68 #include <asm/fixmap.h>
69 #include <asm/cobalt.h>
72 * for x86_do_profile()
74 #include "irq.h"
77 unsigned long cpu_hz; /* Detected as we calibrate the TSC */
79 /* Number of usecs that the last interrupt was delayed */
80 static int delay_at_last_interrupt;
82 static unsigned long last_tsc_low; /* lsb 32 bits of Time Stamp Counter */
84 /* Cached *multiplier* to convert TSC counts to microseconds.
85 * (see the equation below).
86 * Equal to 2^32 * (1 / (clocks per usec) ).
87 * Initialized in time_init.
89 static unsigned long fast_gettimeoffset_quotient=0;
91 extern rwlock_t xtime_lock;
93 static inline unsigned long do_fast_gettimeoffset(void)
95 register unsigned long eax asm("ax");
96 register unsigned long edx asm("dx");
98 /* Read the Time Stamp Counter */
99 __asm__("rdtsc"
100 :"=a" (eax), "=d" (edx));
102 /* .. relative to previous jiffy (32 bits is enough) */
103 eax -= last_tsc_low; /* tsc_low delta */
106 * Time offset = (tsc_low delta) * fast_gettimeoffset_quotient
107 * = (tsc_low delta) * (usecs_per_clock)
108 * = (tsc_low delta) * (usecs_per_jiffy / clocks_per_jiffy)
110 * Using a mull instead of a divl saves up to 31 clock cycles
111 * in the critical path.
114 __asm__("mull %2"
115 :"=a" (eax), "=d" (edx)
116 :"g" (fast_gettimeoffset_quotient),
117 "0" (eax));
119 /* our adjusted time offset in microseconds */
120 return delay_at_last_interrupt + edx;
123 #define TICK_SIZE tick
125 #ifndef CONFIG_X86_TSC
127 /* This function must be called with interrupts disabled
128 * It was inspired by Steve McCanne's microtime-i386 for BSD. -- jrs
130 * However, the pc-audio speaker driver changes the divisor so that
131 * it gets interrupted rather more often - it loads 64 into the
132 * counter rather than 11932! This has an adverse impact on
133 * do_gettimeoffset() -- it stops working! What is also not
134 * good is that the interval that our timer function gets called
135 * is no longer 10.0002 ms, but 9.9767 ms. To get around this
136 * would require using a different timing source. Maybe someone
137 * could use the RTC - I know that this can interrupt at frequencies
138 * ranging from 8192Hz to 2Hz. If I had the energy, I'd somehow fix
139 * it so that at startup, the timer code in sched.c would select
140 * using either the RTC or the 8253 timer. The decision would be
141 * based on whether there was any other device around that needed
142 * to trample on the 8253. I'd set up the RTC to interrupt at 1024 Hz,
143 * and then do some jiggery to have a version of do_timer that
144 * advanced the clock by 1/1024 s. Every time that reached over 1/100
145 * of a second, then do all the old code. If the time was kept correct
146 * then do_gettimeoffset could just return 0 - there is no low order
147 * divider that can be accessed.
149 * Ideally, you would be able to use the RTC for the speaker driver,
150 * but it appears that the speaker driver really needs interrupt more
151 * often than every 120 us or so.
153 * Anyway, this needs more thought.... pjsg (1993-08-28)
155 * If you are really that interested, you should be reading
156 * comp.protocols.time.ntp!
159 static unsigned long do_slow_gettimeoffset(void)
161 int count;
163 static int count_p = LATCH; /* for the first call after boot */
164 static unsigned long jiffies_p = 0;
167 * cache volatile jiffies temporarily; we have IRQs turned off.
169 unsigned long jiffies_t;
171 /* timer count may underflow right here */
172 outb_p(0x00, 0x43); /* latch the count ASAP */
174 count = inb_p(0x40); /* read the latched count */
177 * We do this guaranteed double memory access instead of a _p
178 * postfix in the previous port access. Wheee, hackady hack
180 jiffies_t = jiffies;
182 count |= inb_p(0x40) << 8;
185 * avoiding timer inconsistencies (they are rare, but they happen)...
186 * there are two kinds of problems that must be avoided here:
187 * 1. the timer counter underflows
188 * 2. hardware problem with the timer, not giving us continuous time,
189 * the counter does small "jumps" upwards on some Pentium systems,
190 * (see c't 95/10 page 335 for Neptun bug.)
193 /* you can safely undefine this if you don't have the Neptune chipset */
195 #define BUGGY_NEPTUN_TIMER
197 if( jiffies_t == jiffies_p ) {
198 if( count > count_p ) {
199 /* the nutcase */
201 outb_p(0x0A, 0x20);
203 /* assumption about timer being IRQ1 */
204 if( inb(0x20) & 0x01 ) {
206 * We cannot detect lost timer interrupts ...
207 * well, that's why we call them lost, don't we? :)
208 * [hmm, on the Pentium and Alpha we can ... sort of]
210 count -= LATCH;
211 } else {
212 #ifdef BUGGY_NEPTUN_TIMER
214 * for the Neptun bug we know that the 'latch'
215 * command doesnt latch the high and low value
216 * of the counter atomically. Thus we have to
217 * substract 256 from the counter
218 * ... funny, isnt it? :)
221 count -= 256;
222 #else
223 printk("do_slow_gettimeoffset(): hardware timer problem?\n");
224 #endif
227 } else
228 jiffies_p = jiffies_t;
230 count_p = count;
232 count = ((LATCH-1) - count) * TICK_SIZE;
233 count = (count + LATCH/2) / LATCH;
235 return count;
238 static unsigned long (*do_gettimeoffset)(void) = do_slow_gettimeoffset;
240 #else
242 #define do_gettimeoffset() do_fast_gettimeoffset()
244 #endif
247 * This version of gettimeofday has microsecond resolution
248 * and better than microsecond precision on fast x86 machines with TSC.
250 void do_gettimeofday(struct timeval *tv)
252 extern volatile unsigned long lost_ticks;
253 unsigned long flags;
254 unsigned long usec, sec;
256 read_lock_irqsave(&xtime_lock, flags);
257 usec = do_gettimeoffset();
259 unsigned long lost = lost_ticks;
260 if (lost)
261 usec += lost * (1000000 / HZ);
263 sec = xtime.tv_sec;
264 usec += xtime.tv_usec;
265 read_unlock_irqrestore(&xtime_lock, flags);
267 while (usec >= 1000000) {
268 usec -= 1000000;
269 sec++;
272 tv->tv_sec = sec;
273 tv->tv_usec = usec;
276 void do_settimeofday(struct timeval *tv)
278 write_lock_irq(&xtime_lock);
279 /* This is revolting. We need to set the xtime.tv_usec
280 * correctly. However, the value in this location is
281 * is value at the last tick.
282 * Discover what correction gettimeofday
283 * would have done, and then undo it!
285 tv->tv_usec -= do_gettimeoffset();
287 while (tv->tv_usec < 0) {
288 tv->tv_usec += 1000000;
289 tv->tv_sec--;
292 xtime = *tv;
293 time_adjust = 0; /* stop active adjtime() */
294 time_status |= STA_UNSYNC;
295 time_state = TIME_ERROR; /* p. 24, (a) */
296 time_maxerror = NTP_PHASE_LIMIT;
297 time_esterror = NTP_PHASE_LIMIT;
298 write_unlock_irq(&xtime_lock);
302 * In order to set the CMOS clock precisely, set_rtc_mmss has to be
303 * called 500 ms after the second nowtime has started, because when
304 * nowtime is written into the registers of the CMOS clock, it will
305 * jump to the next second precisely 500 ms later. Check the Motorola
306 * MC146818A or Dallas DS12887 data sheet for details.
308 * BUG: This routine does not handle hour overflow properly; it just
309 * sets the minutes. Usually you'll only notice that after reboot!
311 static int set_rtc_mmss(unsigned long nowtime)
313 int retval = 0;
314 int real_seconds, real_minutes, cmos_minutes;
315 unsigned char save_control, save_freq_select;
317 save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being set */
318 CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
320 save_freq_select = CMOS_READ(RTC_FREQ_SELECT); /* stop and reset prescaler */
321 CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
323 cmos_minutes = CMOS_READ(RTC_MINUTES);
324 if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
325 BCD_TO_BIN(cmos_minutes);
328 * since we're only adjusting minutes and seconds,
329 * don't interfere with hour overflow. This avoids
330 * messing with unknown time zones but requires your
331 * RTC not to be off by more than 15 minutes
333 real_seconds = nowtime % 60;
334 real_minutes = nowtime / 60;
335 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
336 real_minutes += 30; /* correct for half hour time zone */
337 real_minutes %= 60;
339 if (abs(real_minutes - cmos_minutes) < 30) {
340 if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
341 BIN_TO_BCD(real_seconds);
342 BIN_TO_BCD(real_minutes);
344 CMOS_WRITE(real_seconds,RTC_SECONDS);
345 CMOS_WRITE(real_minutes,RTC_MINUTES);
346 } else {
347 printk(KERN_WARNING
348 "set_rtc_mmss: can't update from %d to %d\n",
349 cmos_minutes, real_minutes);
350 retval = -1;
353 /* The following flags have to be released exactly in this order,
354 * otherwise the DS12887 (popular MC146818A clone with integrated
355 * battery and quartz) will not reset the oscillator and will not
356 * update precisely 500 ms later. You won't find this mentioned in
357 * the Dallas Semiconductor data sheets, but who believes data
358 * sheets anyway ... -- Markus Kuhn
360 CMOS_WRITE(save_control, RTC_CONTROL);
361 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
363 return retval;
366 /* last time the cmos clock got updated */
367 static long last_rtc_update = 0;
370 * timer_interrupt() needs to keep up the real-time clock,
371 * as well as call the "do_timer()" routine every clocktick
373 static inline void do_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
375 #ifdef CONFIG_VISWS
376 /* Clear the interrupt */
377 co_cpu_write(CO_CPU_STAT,co_cpu_read(CO_CPU_STAT) & ~CO_STAT_TIMEINTR);
378 #endif
379 do_timer(regs);
381 * In the SMP case we use the local APIC timer interrupt to do the
382 * profiling, except when we simulate SMP mode on a uniprocessor
383 * system, in that case we have to call the local interrupt handler.
385 #ifndef __SMP__
386 if (!user_mode(regs))
387 x86_do_profile(regs->eip);
388 #else
389 if (!smp_found_config)
390 smp_local_timer_interrupt(regs);
391 #endif
394 * If we have an externally synchronized Linux clock, then update
395 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
396 * called as close as possible to 500 ms before the new second starts.
398 if ((time_status & STA_UNSYNC) == 0 &&
399 xtime.tv_sec > last_rtc_update + 660 &&
400 xtime.tv_usec >= 500000 - ((unsigned) tick) / 2 &&
401 xtime.tv_usec <= 500000 + ((unsigned) tick) / 2) {
402 if (set_rtc_mmss(xtime.tv_sec) == 0)
403 last_rtc_update = xtime.tv_sec;
404 else
405 last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
408 #ifdef CONFIG_MCA
409 if( MCA_bus ) {
410 /* The PS/2 uses level-triggered interrupts. You can't
411 turn them off, nor would you want to (any attempt to
412 enable edge-triggered interrupts usually gets intercepted by a
413 special hardware circuit). Hence we have to acknowledge
414 the timer interrupt. Through some incredibly stupid
415 design idea, the reset for IRQ 0 is done by setting the
416 high bit of the PPI port B (0x61). Note that some PS/2s,
417 notably the 55SX, work fine if this is removed. */
419 irq = inb_p( 0x61 ); /* read the current state */
420 outb_p( irq|0x80, 0x61 ); /* reset the IRQ */
422 #endif
425 static int use_tsc = 0;
428 * This is the same as the above, except we _also_ save the current
429 * Time Stamp Counter value at the time of the timer interrupt, so that
430 * we later on can estimate the time of day more exactly.
432 static void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
434 int count;
437 * Here we are in the timer irq handler. We just have irqs locally
438 * disabled but we don't know if the timer_bh is running on the other
439 * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
440 * the irq version of write_lock because as just said we have irq
441 * locally disabled. -arca
443 write_lock(&xtime_lock);
445 if (use_tsc)
448 * It is important that these two operations happen almost at
449 * the same time. We do the RDTSC stuff first, since it's
450 * faster. To avoid any inconsistencies, we need interrupts
451 * disabled locally.
455 * Interrupts are just disabled locally since the timer irq
456 * has the SA_INTERRUPT flag set. -arca
459 /* read Pentium cycle counter */
460 __asm__("rdtsc" : "=a" (last_tsc_low) : : "edx");
462 outb_p(0x00, 0x43); /* latch the count ASAP */
464 count = inb_p(0x40); /* read the latched count */
465 count |= inb(0x40) << 8;
467 count = ((LATCH-1) - count) * TICK_SIZE;
468 delay_at_last_interrupt = (count + LATCH/2) / LATCH;
471 do_timer_interrupt(irq, NULL, regs);
473 write_unlock(&xtime_lock);
477 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
478 * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
479 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
481 * [For the Julian calendar (which was used in Russia before 1917,
482 * Britain & colonies before 1752, anywhere else before 1582,
483 * and is still in use by some communities) leave out the
484 * -year/100+year/400 terms, and add 10.]
486 * This algorithm was first published by Gauss (I think).
488 * WARNING: this function will overflow on 2106-02-07 06:28:16 on
489 * machines were long is 32-bit! (However, as time_t is signed, we
490 * will already get problems at other places on 2038-01-19 03:14:08)
492 static inline unsigned long mktime(unsigned int year, unsigned int mon,
493 unsigned int day, unsigned int hour,
494 unsigned int min, unsigned int sec)
496 if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
497 mon += 12; /* Puts Feb last since it has leap day */
498 year -= 1;
500 return (((
501 (unsigned long)(year/4 - year/100 + year/400 + 367*mon/12 + day) +
502 year*365 - 719499
503 )*24 + hour /* now have hours */
504 )*60 + min /* now have minutes */
505 )*60 + sec; /* finally seconds */
508 /* not static: needed by APM */
509 unsigned long get_cmos_time(void)
511 unsigned int year, mon, day, hour, min, sec;
512 int i;
514 /* The Linux interpretation of the CMOS clock register contents:
515 * When the Update-In-Progress (UIP) flag goes from 1 to 0, the
516 * RTC registers show the second which has precisely just started.
517 * Let's hope other operating systems interpret the RTC the same way.
519 /* read RTC exactly on falling edge of update flag */
520 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */
521 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP)
522 break;
523 for (i = 0 ; i < 1000000 ; i++) /* must try at least 2.228 ms */
524 if (!(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))
525 break;
526 do { /* Isn't this overkill ? UIP above should guarantee consistency */
527 sec = CMOS_READ(RTC_SECONDS);
528 min = CMOS_READ(RTC_MINUTES);
529 hour = CMOS_READ(RTC_HOURS);
530 day = CMOS_READ(RTC_DAY_OF_MONTH);
531 mon = CMOS_READ(RTC_MONTH);
532 year = CMOS_READ(RTC_YEAR);
533 } while (sec != CMOS_READ(RTC_SECONDS));
534 if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
536 BCD_TO_BIN(sec);
537 BCD_TO_BIN(min);
538 BCD_TO_BIN(hour);
539 BCD_TO_BIN(day);
540 BCD_TO_BIN(mon);
541 BCD_TO_BIN(year);
543 if ((year += 1900) < 1970)
544 year += 100;
545 return mktime(year, mon, day, hour, min, sec);
548 static struct irqaction irq0 = { timer_interrupt, SA_INTERRUPT, 0, "timer", NULL, NULL};
550 /* ------ Calibrate the TSC -------
551 * Return 2^32 * (1 / (TSC clocks per usec)) for do_fast_gettimeoffset().
552 * Too much 64-bit arithmetic here to do this cleanly in C, and for
553 * accuracy's sake we want to keep the overhead on the CTC speaker (channel 2)
554 * output busy loop as low as possible. We avoid reading the CTC registers
555 * directly because of the awkward 8-bit access mechanism of the 82C54
556 * device.
559 __initfunc(static unsigned long calibrate_tsc(void))
561 unsigned long retval;
563 __asm__( /* set the Gate high, program CTC channel 2 for mode 0
564 * (interrupt on terminal count mode), binary count,
565 * load 5 * LATCH count, (LSB and MSB)
566 * to begin countdown, read the TSC and busy wait.
567 * BTW LATCH is calculated in timex.h from the HZ value
570 /* Set the Gate high, disable speaker */
571 "inb $0x61, %%al\n\t" /* Read port */
572 "andb $0xfd, %%al\n\t" /* Turn off speaker Data */
573 "orb $0x01, %%al\n\t" /* Set Gate high */
574 "outb %%al, $0x61\n\t" /* Write port */
576 /* Now let's take care of CTC channel 2 */
577 "movb $0xb0, %%al\n\t" /* binary, mode 0, LSB/MSB, ch 2*/
578 "outb %%al, $0x43\n\t" /* Write to CTC command port */
579 "movl %1, %%eax\n\t"
580 "outb %%al, $0x42\n\t" /* LSB of count */
581 "shrl $8, %%eax\n\t"
582 "outb %%al, $0x42\n\t" /* MSB of count */
584 /* Read the TSC; counting has just started */
585 "rdtsc\n\t"
586 /* Move the value for safe-keeping. */
587 "movl %%eax, %%ebx\n\t"
588 "movl %%edx, %%ecx\n\t"
590 /* Busy wait. Only 50 ms wasted at boot time. */
591 "0: inb $0x61, %%al\n\t" /* Read Speaker Output Port */
592 "testb $0x20, %%al\n\t" /* Check CTC channel 2 output (bit 5) */
593 "jz 0b\n\t"
595 /* And read the TSC. 5 jiffies (50.00077ms) have elapsed. */
596 "rdtsc\n\t"
598 /* Great. So far so good. Store last TSC reading in
599 * last_tsc_low (only 32 lsb bits needed) */
600 "movl %%eax, last_tsc_low\n\t"
601 /* And now calculate the difference between the readings. */
602 "subl %%ebx, %%eax\n\t"
603 "sbbl %%ecx, %%edx\n\t" /* 64-bit subtract */
604 /* but probably edx = 0 at this point (see below). */
605 /* Now we have 5 * (TSC counts per jiffy) in eax. We want
606 * to calculate TSC->microsecond conversion factor. */
608 /* Note that edx (high 32-bits of difference) will now be
609 * zero iff CPU clock speed is less than 85 GHz. Moore's
610 * law says that this is likely to be true for the next
611 * 12 years or so. You will have to change this code to
612 * do a real 64-by-64 divide before that time's up. */
613 "movl %%eax, %%ecx\n\t"
614 "xorl %%eax, %%eax\n\t"
615 "movl %2, %%edx\n\t"
616 "divl %%ecx\n\t" /* eax= 2^32 / (1 * TSC counts per microsecond) */
617 /* Return eax for the use of fast_gettimeoffset */
618 "movl %%eax, %0\n\t"
619 : "=r" (retval)
620 : "r" (5 * LATCH), "r" (5 * 1000020/HZ)
621 : /* we clobber: */ "ax", "bx", "cx", "dx", "cc", "memory");
622 return retval;
625 __initfunc(void time_init(void))
627 xtime.tv_sec = get_cmos_time();
628 xtime.tv_usec = 0;
631 * If we have APM enabled or the CPU clock speed is variable
632 * (CPU stops clock on HLT or slows clock to save power)
633 * then the TSC timestamps may diverge by up to 1 jiffy from
634 * 'real time' but nothing will break.
635 * The most frequent case is that the CPU is "woken" from a halt
636 * state by the timer interrupt itself, so we get 0 error. In the
637 * rare cases where a driver would "wake" the CPU and request a
638 * timestamp, the maximum error is < 1 jiffy. But timestamps are
639 * still perfectly ordered.
640 * Note that the TSC counter will be reset if APM suspends
641 * to disk; this won't break the kernel, though, 'cuz we're
642 * smart. See arch/i386/kernel/apm.c.
645 * Firstly we have to do a CPU check for chips with
646 * a potentially buggy TSC. At this point we haven't run
647 * the ident/bugs checks so we must run this hook as it
648 * may turn off the TSC flag.
650 * NOTE: this doesnt yet handle SMP 486 machines where only
651 * some CPU's have a TSC. Thats never worked and nobody has
652 * moaned if you have the only one in the world - you fix it!
655 dodgy_tsc();
657 if (boot_cpu_data.x86_capability & X86_FEATURE_TSC) {
658 #ifndef do_gettimeoffset
659 do_gettimeoffset = do_fast_gettimeoffset;
660 #endif
661 do_get_fast_time = do_gettimeofday;
662 use_tsc = 1;
663 fast_gettimeoffset_quotient = calibrate_tsc();
665 /* report CPU clock rate in Hz.
666 * The formula is (10^6 * 2^32) / (2^32 * 1 / (clocks/us)) =
667 * clock/second. Our precision is about 100 ppm.
669 { unsigned long eax=0, edx=1000000;
670 __asm__("divl %2"
671 :"=a" (cpu_hz), "=d" (edx)
672 :"r" (fast_gettimeoffset_quotient),
673 "0" (eax), "1" (edx));
674 printk("Detected %ld Hz processor.\n", cpu_hz);
678 #ifdef CONFIG_VISWS
679 printk("Starting Cobalt Timer system clock\n");
681 /* Set the countdown value */
682 co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
684 /* Start the timer */
685 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
687 /* Enable (unmask) the timer interrupt */
688 co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
690 /* Wire cpu IDT entry to s/w handler (and Cobalt APIC to IDT) */
691 setup_x86_irq(CO_IRQ_TIMER, &irq0);
692 #else
693 setup_x86_irq(0, &irq0);
694 #endif