]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - arch/powerpc/kernel/time.c
[POWERPC] Add starting of secondary 86xx CPUs.
[karo-tx-linux.git] / arch / powerpc / kernel / time.c
index 0b34db28916fd1fc038aaed7194f692f9fdd7172..528e7f84cb67703a5516a4083ca4af4ca5bbb19b 100644 (file)
@@ -76,7 +76,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; 
@@ -99,6 +98,7 @@ unsigned long tb_ticks_per_jiffy;
 unsigned long tb_ticks_per_usec = 100; /* sane default */
 EXPORT_SYMBOL(tb_ticks_per_usec);
 unsigned long tb_ticks_per_sec;
+EXPORT_SYMBOL(tb_ticks_per_sec);       /* for cputime_t conversions */
 u64 tb_to_xs;
 unsigned tb_to_us;
 
@@ -143,9 +143,13 @@ DEFINE_PER_CPU(unsigned long, last_jiffy);
  * These are all stored as 0.64 fixed-point binary fractions.
  */
 u64 __cputime_jiffies_factor;
+EXPORT_SYMBOL(__cputime_jiffies_factor);
 u64 __cputime_msec_factor;
+EXPORT_SYMBOL(__cputime_msec_factor);
 u64 __cputime_sec_factor;
+EXPORT_SYMBOL(__cputime_sec_factor);
 u64 __cputime_clockt_factor;
+EXPORT_SYMBOL(__cputime_clockt_factor);
 
 static void calc_cputime_factors(void)
 {
@@ -256,7 +260,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);
 }
@@ -498,9 +502,9 @@ static inline void update_gtod(u64 new_tb_stamp, u64 new_stamp_xsec,
         * the two values of tb_update_count match and are even then the
         * tb_to_xs and stamp_xsec values are consistent.  If not, then it
         * loops back and reads them again until this criteria is met.
+        * We expect the caller to have done the first increment of
+        * vdso_data->tb_update_count already.
         */
-       ++(vdso_data->tb_update_count);
-       smp_wmb();
        vdso_data->tb_orig_stamp = new_tb_stamp;
        vdso_data->stamp_xsec = new_stamp_xsec;
        vdso_data->tb_to_xs = new_tb_to_xs;
@@ -525,20 +529,15 @@ static __inline__ void timer_recalc_offset(u64 cur_tb)
        unsigned long offset;
        u64 new_stamp_xsec;
        u64 tlen, t2x;
+       u64 tb, xsec_old, xsec_new;
+       struct gettimeofday_vars *varp;
 
        if (__USE_RTC())
                return;
        tlen = current_tick_length();
        offset = cur_tb - do_gtod.varp->tb_orig_stamp;
-       if (tlen == last_tick_len && offset < 0x80000000u) {
-               /* check that we're still in sync; if not, resync */
-               struct timeval tv;
-               __do_gettimeofday(&tv, cur_tb);
-               if (tv.tv_sec <= xtime.tv_sec &&
-                   (tv.tv_sec < xtime.tv_sec ||
-                    tv.tv_usec * 1000 <= xtime.tv_nsec))
-                       return;
-       }
+       if (tlen == last_tick_len && offset < 0x80000000u)
+               return;
        if (tlen != last_tick_len) {
                t2x = mulhdu(tlen << TICKLEN_SHIFT, ticklen_to_xs);
                last_tick_len = tlen;
@@ -547,6 +546,21 @@ static __inline__ void timer_recalc_offset(u64 cur_tb)
        new_stamp_xsec = (u64) xtime.tv_nsec * XSEC_PER_SEC;
        do_div(new_stamp_xsec, 1000000000);
        new_stamp_xsec += (u64) xtime.tv_sec * XSEC_PER_SEC;
+
+       ++vdso_data->tb_update_count;
+       smp_mb();
+
+       /*
+        * Make sure time doesn't go backwards for userspace gettimeofday.
+        */
+       tb = get_tb();
+       varp = do_gtod.varp;
+       xsec_old = mulhdu(tb - varp->tb_orig_stamp, varp->tb_to_xs)
+               + varp->stamp_xsec;
+       xsec_new = mulhdu(tb - cur_tb, t2x) + new_stamp_xsec;
+       if (xsec_new < xsec_old)
+               new_stamp_xsec += xsec_old - xsec_new;
+
        update_gtod(cur_tb, new_stamp_xsec, t2x);
 }
 
@@ -736,7 +750,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))
@@ -795,6 +809,10 @@ int do_settimeofday(struct timespec *tv)
        }
 #endif
 
+       /* Make userspace gettimeofday spin until we're done. */
+       ++vdso_data->tb_update_count;
+       smp_mb();
+
        /*
         * Subtract off the number of nanoseconds since the
         * beginning of the last tick.
@@ -926,9 +944,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();
        }
@@ -956,10 +974,16 @@ void __init time_init(void)
         * It is computed as:
         * ticklen_to_xs = 2^N / (tb_ticks_per_jiffy * 1e9)
         * where N = 64 + 20 - TICKLEN_SCALE - TICKLEN_SHIFT
-        * so as to give the result as a 0.64 fixed-point fraction.
+        * which turns out to be N = 51 - SHIFT_HZ.
+        * This gives the result as a 0.64 fixed-point fraction.
+        * That value is reduced by an offset amounting to 1 xsec per
+        * 2^31 timebase ticks to avoid problems with time going backwards
+        * by 1 xsec when we do timer_recalc_offset due to losing the
+        * fractional xsec.  That offset is equal to ppc_tb_freq/2^51
+        * since there are 2^20 xsec in a second.
         */
-       div128_by_32(1ULL << (64 + 20 - TICKLEN_SCALE - TICKLEN_SHIFT), 0,
-                    tb_ticks_per_jiffy, &res);
+       div128_by_32((1ULL << 51) - ppc_tb_freq, 0,
+                    tb_ticks_per_jiffy << SHIFT_HZ, &res);
        div128_by_32(res.result_high, res.result_low, NSEC_PER_SEC, &res);
        ticklen_to_xs = res.result_low;
 
@@ -985,10 +1009,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);