aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/lib
diff options
context:
space:
mode:
authorPeter De Schrijver <pdeschrijver@nvidia.com>2014-06-12 11:58:28 -0400
committerStephen Warren <swarren@nvidia.com>2014-06-16 14:48:07 -0400
commit5930c1a1f7f8439883d0a2173c6ce51d577e36ec (patch)
treed1cbc3e409c5c534d2c9113fdb0f0ebff16ba410 /arch/arm/lib
parente6639117d624d5c8f531d22456a69e38dc23c501 (diff)
ARM: choose highest resolution delay timer
In case there are several possible delay timers, choose the one with the highest resolution. This code relies on the fact secondary CPUs have not yet been brought online when register_current_timer_delay() is called. This is ensured by implementing calibration_delay_done(), Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com> Acked-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'arch/arm/lib')
-rw-r--r--arch/arm/lib/delay.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
index 5306de350133..312d43eb686a 100644
--- a/arch/arm/lib/delay.c
+++ b/arch/arm/lib/delay.c
@@ -19,6 +19,7 @@
19 * Author: Will Deacon <will.deacon@arm.com> 19 * Author: Will Deacon <will.deacon@arm.com>
20 */ 20 */
21 21
22#include <linux/clocksource.h>
22#include <linux/delay.h> 23#include <linux/delay.h>
23#include <linux/init.h> 24#include <linux/init.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -36,6 +37,7 @@ struct arm_delay_ops arm_delay_ops = {
36 37
37static const struct delay_timer *delay_timer; 38static const struct delay_timer *delay_timer;
38static bool delay_calibrated; 39static bool delay_calibrated;
40static u64 delay_res;
39 41
40int read_current_timer(unsigned long *timer_val) 42int read_current_timer(unsigned long *timer_val)
41{ 43{
@@ -47,6 +49,11 @@ int read_current_timer(unsigned long *timer_val)
47} 49}
48EXPORT_SYMBOL_GPL(read_current_timer); 50EXPORT_SYMBOL_GPL(read_current_timer);
49 51
52static inline u64 cyc_to_ns(u64 cyc, u32 mult, u32 shift)
53{
54 return (cyc * mult) >> shift;
55}
56
50static void __timer_delay(unsigned long cycles) 57static void __timer_delay(unsigned long cycles)
51{ 58{
52 cycles_t start = get_cycles(); 59 cycles_t start = get_cycles();
@@ -69,18 +76,24 @@ static void __timer_udelay(unsigned long usecs)
69 76
70void __init register_current_timer_delay(const struct delay_timer *timer) 77void __init register_current_timer_delay(const struct delay_timer *timer)
71{ 78{
72 if (!delay_calibrated) { 79 u32 new_mult, new_shift;
73 pr_info("Switching to timer-based delay loop\n"); 80 u64 res;
81
82 clocks_calc_mult_shift(&new_mult, &new_shift, timer->freq,
83 NSEC_PER_SEC, 3600);
84 res = cyc_to_ns(1ULL, new_mult, new_shift);
85
86 if (!delay_calibrated && (!delay_res || (res < delay_res))) {
87 pr_info("Switching to timer-based delay loop, resolution %lluns\n", res);
74 delay_timer = timer; 88 delay_timer = timer;
75 lpj_fine = timer->freq / HZ; 89 lpj_fine = timer->freq / HZ;
90 delay_res = res;
76 91
77 /* cpufreq may scale loops_per_jiffy, so keep a private copy */ 92 /* cpufreq may scale loops_per_jiffy, so keep a private copy */
78 arm_delay_ops.ticks_per_jiffy = lpj_fine; 93 arm_delay_ops.ticks_per_jiffy = lpj_fine;
79 arm_delay_ops.delay = __timer_delay; 94 arm_delay_ops.delay = __timer_delay;
80 arm_delay_ops.const_udelay = __timer_const_udelay; 95 arm_delay_ops.const_udelay = __timer_const_udelay;
81 arm_delay_ops.udelay = __timer_udelay; 96 arm_delay_ops.udelay = __timer_udelay;
82
83 delay_calibrated = true;
84 } else { 97 } else {
85 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n"); 98 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
86 } 99 }
@@ -91,3 +104,8 @@ unsigned long calibrate_delay_is_known(void)
91 delay_calibrated = true; 104 delay_calibrated = true;
92 return lpj_fine; 105 return lpj_fine;
93} 106}
107
108void calibration_delay_done(void)
109{
110 delay_calibrated = true;
111}