X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=arch%2Fpowerpc%2Fkernel%2Ftime.c;h=24e3ad756de02ce124bb2ff05ea4eb9b04c9a033;hb=9464c7cf61b9433057924c36e6e02f303a00e768;hp=a124499e65d9d5d4aff96f5b73b2f877e9725486;hpb=41689045f6a3cbe0550e1d34e9cc20d2e8c432ba;p=linux-2.6.git diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index a124499e6..24e3ad756 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -32,6 +32,7 @@ * 2 of the License, or (at your option) any later version. */ +#include #include #include #include @@ -75,6 +76,7 @@ /* 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; @@ -101,7 +103,7 @@ EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */ u64 tb_to_xs; unsigned tb_to_us; -#define TICKLEN_SCALE TICK_LENGTH_SHIFT +#define TICKLEN_SCALE (SHIFT_SCALE - 10) u64 last_tick_len; /* units are ns / 2^TICKLEN_SCALE */ u64 ticklen_to_xs; /* 0.64 fraction */ @@ -125,8 +127,15 @@ static long timezone_offset; unsigned long ppc_proc_freq; unsigned long ppc_tb_freq; -static u64 tb_last_jiffy __cacheline_aligned_in_smp; -static DEFINE_PER_CPU(u64, last_jiffy); +u64 tb_last_jiffy __cacheline_aligned_in_smp; +unsigned long tb_last_stamp; + +/* + * Note that on ppc32 this only stores the bottom 32 bits of + * the timebase value, but that's enough to tell when a jiffy + * has passed. + */ +DEFINE_PER_CPU(unsigned long, last_jiffy); #ifdef CONFIG_VIRT_CPU_ACCOUNTING /* @@ -410,7 +419,7 @@ static __inline__ void timer_check_rtc(void) /* * This version of gettimeofday has microsecond resolution. */ -static inline void __do_gettimeofday(struct timeval *tv) +static inline void __do_gettimeofday(struct timeval *tv, u64 tb_val) { unsigned long sec, usec; u64 tb_ticks, xsec; @@ -424,12 +433,7 @@ static inline void __do_gettimeofday(struct timeval *tv) * without a divide (and in fact, without a multiply) */ temp_varp = do_gtod.varp; - - /* 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; + tb_ticks = tb_val - 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); @@ -451,7 +455,7 @@ void do_gettimeofday(struct timeval *tv) do { seq = read_seqbegin_irqsave(&xtime_lock, flags); sec = xtime.tv_sec; - nsec = xtime.tv_nsec + tb_ticks_since(tb_last_jiffy); + nsec = xtime.tv_nsec + tb_ticks_since(tb_last_stamp); } while (read_seqretry_irqrestore(&xtime_lock, seq, flags)); usec = nsec / 1000; while (usec >= 1000000) { @@ -462,7 +466,7 @@ void do_gettimeofday(struct timeval *tv) tv->tv_usec = usec; return; } - __do_gettimeofday(tv); + __do_gettimeofday(tv, get_tb()); } EXPORT_SYMBOL(do_gettimeofday); @@ -648,7 +652,6 @@ 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) @@ -690,13 +693,11 @@ void timer_interrupt(struct pt_regs * regs) continue; write_seqlock(&xtime_lock); - 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; - do_timer(regs); - timer_recalc_offset(tb_last_jiffy); - timer_check_rtc(); - } + 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(); write_sequnlock(&xtime_lock); } @@ -741,7 +742,7 @@ void __init smp_space_timers(unsigned int max_cpus) int i; unsigned long half = tb_ticks_per_jiffy / 2; unsigned long offset = tb_ticks_per_jiffy / max_cpus; - u64 previous_tb = per_cpu(last_jiffy, boot_cpuid); + unsigned long previous_tb = per_cpu(last_jiffy, boot_cpuid); /* make sure tb > per_cpu(last_jiffy, cpu) for all cpus always */ previous_tb -= tb_ticks_per_jiffy; @@ -822,7 +823,7 @@ int do_settimeofday(struct timespec *tv) * and therefore the (jiffies - wall_jiffies) computation * has been removed. */ - tb_delta = tb_ticks_since(tb_last_jiffy); + tb_delta = tb_ticks_since(tb_last_stamp); tb_delta = mulhdu(tb_delta, do_gtod.varp->tb_to_xs); /* in xsec */ new_nsec -= SCALE_XSEC(tb_delta, 1000000000); @@ -857,50 +858,42 @@ int do_settimeofday(struct timespec *tv) EXPORT_SYMBOL(do_settimeofday); -static int __init get_freq(char *name, int cells, unsigned long *val) +void __init generic_calibrate_decr(void) { struct device_node *cpu; unsigned int *fp; - int found = 0; + int node_found; - /* The cpu node should have timebase and clock frequency properties */ + /* + * The cpu node should have a timebase-frequency property + * to tell us the rate at which the decrementer counts. + */ 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, name, NULL); + fp = (unsigned int *)get_property(cpu, "timebase-frequency", + NULL); if (fp) { - found = 1; - *val = 0; - while (cells--) - *val = (*val << 32) | *fp++; + node_found = 1; + ppc_tb_freq = *fp; } - - of_node_put(cpu); } - - 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)) { - + if (!node_found) printk(KERN_ERR "WARNING: Estimating decrementer frequency " "(not found)\n"); - } - - 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"); + 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; + } } - #ifdef CONFIG_BOOKE /* Set the time base to zero */ mtspr(SPRN_TBWL, 0); @@ -912,6 +905,11 @@ 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) @@ -942,15 +940,16 @@ void __init time_init(void) if (__USE_RTC()) { /* 601 processor: dec counts down by 128 every 128ns */ ppc_tb_freq = 1000000000; - tb_last_jiffy = get_rtcl(); + tb_last_stamp = get_rtcl(); + tb_last_jiffy = tb_last_stamp; } else { /* Normal PowerPC with timebase register */ ppc_md.calibrate_decr(); - printk(KERN_DEBUG "time_init: decrementer frequency = %lu.%.6lu MHz\n", + printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n", ppc_tb_freq / 1000000, ppc_tb_freq % 1000000); - printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n", + printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n", ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); - tb_last_jiffy = get_tb(); + tb_last_stamp = tb_last_jiffy = get_tb(); } tb_ticks_per_jiffy = ppc_tb_freq / HZ; @@ -1011,7 +1010,10 @@ void __init time_init(void) tb_to_ns_scale = scale; tb_to_ns_shift = shift; - tm = get_boot_time(); +#ifdef CONFIG_PPC_ISERIES + if (!piranha_simulator) +#endif + tm = get_boot_time(); write_seqlock_irqsave(&xtime_lock, flags); @@ -1027,7 +1029,7 @@ void __init time_init(void) do_gtod.varp = &do_gtod.vars[0]; do_gtod.var_idx = 0; do_gtod.varp->tb_orig_stamp = tb_last_jiffy; - __get_cpu_var(last_jiffy) = tb_last_jiffy; + __get_cpu_var(last_jiffy) = tb_last_stamp; do_gtod.varp->stamp_xsec = (u64) xtime.tv_sec * XSEC_PER_SEC; do_gtod.tb_ticks_per_sec = tb_ticks_per_sec; do_gtod.varp->tb_to_xs = tb_to_xs;