Merge gregkh@master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[pandora-kernel.git] / arch / powerpc / kernel / time.c
index 4a27218..18e59e4 100644 (file)
@@ -32,7 +32,6 @@
  *      2 of the License, or (at your option) any later version.
  */
 
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/sched.h>
@@ -76,7 +75,6 @@
 
 /* keep track of when we need to update the rtc */
 time_t last_rtc_update;
-extern int piranha_simulator;
 #ifdef CONFIG_PPC_ISERIES
 unsigned long iSeries_recal_titan = 0;
 unsigned long iSeries_recal_tb = 0; 
@@ -103,7 +101,7 @@ EXPORT_SYMBOL(tb_ticks_per_sec);    /* for cputime_t conversions */
 u64 tb_to_xs;
 unsigned tb_to_us;
 
-#define TICKLEN_SCALE  (SHIFT_SCALE - 10)
+#define TICKLEN_SCALE  TICK_LENGTH_SHIFT
 u64 last_tick_len;     /* units are ns / 2^TICKLEN_SCALE */
 u64 ticklen_to_xs;     /* 0.64 fraction */
 
@@ -261,7 +259,7 @@ void snapshot_timebases(void)
 
        if (!cpu_has_feature(CPU_FTR_PURR))
                return;
-       for_each_cpu(cpu)
+       for_each_possible_cpu(cpu)
                spin_lock_init(&per_cpu(cpu_purr_data, cpu).lock);
        on_each_cpu(snapshot_tb_and_purr, NULL, 0, 1);
 }
@@ -419,7 +417,7 @@ static __inline__ void timer_check_rtc(void)
 /*
  * This version of gettimeofday has microsecond resolution.
  */
-static inline void __do_gettimeofday(struct timeval *tv, u64 tb_val)
+static inline void __do_gettimeofday(struct timeval *tv)
 {
        unsigned long sec, usec;
        u64 tb_ticks, xsec;
@@ -433,7 +431,12 @@ static inline void __do_gettimeofday(struct timeval *tv, u64 tb_val)
         * without a divide (and in fact, without a multiply)
         */
        temp_varp = do_gtod.varp;
-       tb_ticks = tb_val - temp_varp->tb_orig_stamp;
+
+       /* Sampling the time base must be done after loading
+        * do_gtod.varp in order to avoid racing with update_gtod.
+        */
+       data_barrier(temp_varp);
+       tb_ticks = get_tb() - temp_varp->tb_orig_stamp;
        temp_tb_to_xs = temp_varp->tb_to_xs;
        temp_stamp_xsec = temp_varp->stamp_xsec;
        xsec = temp_stamp_xsec + mulhdu(tb_ticks, temp_tb_to_xs);
@@ -466,7 +469,7 @@ void do_gettimeofday(struct timeval *tv)
                tv->tv_usec = usec;
                return;
        }
-       __do_gettimeofday(tv, get_tb());
+       __do_gettimeofday(tv);
 }
 
 EXPORT_SYMBOL(do_gettimeofday);
@@ -652,6 +655,7 @@ void timer_interrupt(struct pt_regs * regs)
        int next_dec;
        int cpu = smp_processor_id();
        unsigned long ticks;
+       u64 tb_next_jiffy;
 
 #ifdef CONFIG_PPC32
        if (atomic_read(&ppc_n_lost_interrupts) != 0)
@@ -693,11 +697,14 @@ void timer_interrupt(struct pt_regs * regs)
                        continue;
 
                write_seqlock(&xtime_lock);
-               tb_last_jiffy += tb_ticks_per_jiffy;
-               tb_last_stamp = per_cpu(last_jiffy, cpu);
-               do_timer(regs);
-               timer_recalc_offset(tb_last_jiffy);
-               timer_check_rtc();
+               tb_next_jiffy = tb_last_jiffy + tb_ticks_per_jiffy;
+               if (per_cpu(last_jiffy, cpu) >= tb_next_jiffy) {
+                       tb_last_jiffy = tb_next_jiffy;
+                       tb_last_stamp = per_cpu(last_jiffy, cpu);
+                       do_timer(regs);
+                       timer_recalc_offset(tb_last_jiffy);
+                       timer_check_rtc();
+               }
                write_sequnlock(&xtime_lock);
        }
        
@@ -751,7 +758,7 @@ void __init smp_space_timers(unsigned int max_cpus)
         * systems works better if the two threads' timebase interrupts
         * are staggered by half a jiffy with respect to each other.
         */
-       for_each_cpu(i) {
+       for_each_possible_cpu(i) {
                if (i == boot_cpuid)
                        continue;
                if (i == (boot_cpuid ^ 1))
@@ -858,42 +865,50 @@ int do_settimeofday(struct timespec *tv)
 
 EXPORT_SYMBOL(do_settimeofday);
 
-void __init generic_calibrate_decr(void)
+static int __init get_freq(char *name, int cells, unsigned long *val)
 {
        struct device_node *cpu;
        unsigned int *fp;
-       int node_found;
+       int found = 0;
 
-       /*
-        * The cpu node should have a timebase-frequency property
-        * to tell us the rate at which the decrementer counts.
-        */
+       /* The cpu node should have timebase and clock frequency properties */
        cpu = of_find_node_by_type(NULL, "cpu");
 
-       ppc_tb_freq = DEFAULT_TB_FREQ;          /* hardcoded default */
-       node_found = 0;
        if (cpu) {
-               fp = (unsigned int *)get_property(cpu, "timebase-frequency",
-                                                 NULL);
+               fp = (unsigned int *)get_property(cpu, name, NULL);
                if (fp) {
-                       node_found = 1;
-                       ppc_tb_freq = *fp;
+                       found = 1;
+                       *val = 0;
+                       while (cells--)
+                               *val = (*val << 32) | *fp++;
                }
+
+               of_node_put(cpu);
        }
-       if (!node_found)
+
+       return found;
+}
+
+void __init generic_calibrate_decr(void)
+{
+       ppc_tb_freq = DEFAULT_TB_FREQ;          /* hardcoded default */
+
+       if (!get_freq("ibm,extended-timebase-frequency", 2, &ppc_tb_freq) &&
+           !get_freq("timebase-frequency", 1, &ppc_tb_freq)) {
+
                printk(KERN_ERR "WARNING: Estimating decrementer frequency "
                                "(not found)\n");
+       }
 
-       ppc_proc_freq = DEFAULT_PROC_FREQ;
-       node_found = 0;
-       if (cpu) {
-               fp = (unsigned int *)get_property(cpu, "clock-frequency",
-                                                 NULL);
-               if (fp) {
-                       node_found = 1;
-                       ppc_proc_freq = *fp;
-               }
+       ppc_proc_freq = DEFAULT_PROC_FREQ;      /* hardcoded default */
+
+       if (!get_freq("ibm,extended-clock-frequency", 2, &ppc_proc_freq) &&
+           !get_freq("clock-frequency", 1, &ppc_proc_freq)) {
+
+               printk(KERN_ERR "WARNING: Estimating processor frequency "
+                               "(not found)\n");
        }
+
 #ifdef CONFIG_BOOKE
        /* Set the time base to zero */
        mtspr(SPRN_TBWL, 0);
@@ -905,11 +920,6 @@ void __init generic_calibrate_decr(void)
        /* Enable decrementer interrupt */
        mtspr(SPRN_TCR, TCR_DIE);
 #endif
-       if (!node_found)
-               printk(KERN_ERR "WARNING: Estimating processor frequency "
-                               "(not found)\n");
-
-       of_node_put(cpu);
 }
 
 unsigned long get_boot_time(void)
@@ -945,9 +955,9 @@ void __init time_init(void)
        } else {
                /* Normal PowerPC with timebase register */
                ppc_md.calibrate_decr();
-               printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
+               printk(KERN_DEBUG "time_init: decrementer frequency = %lu.%.6lu MHz\n",
                       ppc_tb_freq / 1000000, ppc_tb_freq % 1000000);
-               printk(KERN_INFO "time_init: processor frequency   = %lu.%.6lu MHz\n",
+               printk(KERN_DEBUG "time_init: processor frequency   = %lu.%.6lu MHz\n",
                       ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
                tb_last_stamp = tb_last_jiffy = get_tb();
        }
@@ -1010,10 +1020,7 @@ void __init time_init(void)
        tb_to_ns_scale = scale;
        tb_to_ns_shift = shift;
 
-#ifdef CONFIG_PPC_ISERIES
-       if (!piranha_simulator)
-#endif
-               tm = get_boot_time();
+       tm = get_boot_time();
 
        write_seqlock_irqsave(&xtime_lock, flags);