From: Linus Torvalds Date: Wed, 9 Dec 2009 03:27:08 +0000 (-0800) Subject: Merge branch 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git... X-Git-Tag: upstream/snapshot3+hdmi~16424 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=60d8ce2cd6c283132928c11f3fd57ff4187287e0;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git Merge branch 'timers-for-linus' of git://git./linux/kernel/git/tip/linux-2.6-tip * 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: timers, init: Limit the number of per cpu calibration bootup messages posix-cpu-timers: optimize and document timer_create callback clockevents: Add missing include to pacify sparse x86: vmiclock: Fix printk format x86: Fix printk format due to variable type change sparc: fix printk for change of variable type clocksource/events: Fix fallout of generic code changes nohz: Allow 32-bit machines to sleep for more than 2.15 seconds nohz: Track last do_timer() cpu nohz: Prevent clocksource wrapping during idle nohz: Type cast printk argument mips: Use generic mult/shift factor calculation for clocks clocksource: Provide a generic mult/shift factor calculation clockevents: Use u32 for mult and shift factors nohz: Introduce arch_needs_cpu nohz: Reuse ktime in sub-functions of tick_check_idle. time: Remove xtime_cache time: Implement logarithmic time accumulation --- 60d8ce2cd6c283132928c11f3fd57ff4187287e0 diff --cc kernel/time/clocksource.c index 4a31090,72a2dcb..d422c7b --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@@ -105,8 -105,61 +105,61 @@@ u64 timecounter_cyc2time(struct timecou return nsec; } -EXPORT_SYMBOL(timecounter_cyc2time); +EXPORT_SYMBOL_GPL(timecounter_cyc2time); + /** + * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks + * @mult: pointer to mult variable + * @shift: pointer to shift variable + * @from: frequency to convert from + * @to: frequency to convert to + * @minsec: guaranteed runtime conversion range in seconds + * + * The function evaluates the shift/mult pair for the scaled math + * operations of clocksources and clockevents. + * + * @to and @from are frequency values in HZ. For clock sources @to is + * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock + * event @to is the counter frequency and @from is NSEC_PER_SEC. + * + * The @minsec conversion range argument controls the time frame in + * seconds which must be covered by the runtime conversion with the + * calculated mult and shift factors. This guarantees that no 64bit + * overflow happens when the input value of the conversion is + * multiplied with the calculated mult factor. Larger ranges may + * reduce the conversion accuracy by chosing smaller mult and shift + * factors. + */ + void + clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec) + { + u64 tmp; + u32 sft, sftacc= 32; + + /* + * Calculate the shift factor which is limiting the conversion + * range: + */ + tmp = ((u64)minsec * from) >> 32; + while (tmp) { + tmp >>=1; + sftacc--; + } + + /* + * Find the conversion shift/mult pair which has the best + * accuracy and fits the maxsec conversion range: + */ + for (sft = 32; sft > 0; sft--) { + tmp = (u64) to << sft; + do_div(tmp, from); + if ((tmp >> sftacc) == 0) + break; + } + *mult = tmp; + *shift = sft; + } + /*[Clocksource internal variables]--------- * curr_clocksource: * currently selected clocksource.