diff options
Diffstat (limited to 'arch/parisc/kernel/time.c')
-rw-r--r-- | arch/parisc/kernel/time.c | 90 |
1 files changed, 54 insertions, 36 deletions
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c index d4dd05674c62..a79c6f9e7e2c 100644 --- a/arch/parisc/kernel/time.c +++ b/arch/parisc/kernel/time.c | |||
@@ -56,9 +56,9 @@ static unsigned long clocktick __read_mostly; /* timer cycles per tick */ | |||
56 | */ | 56 | */ |
57 | irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id) | 57 | irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id) |
58 | { | 58 | { |
59 | unsigned long now; | 59 | unsigned long now, now2; |
60 | unsigned long next_tick; | 60 | unsigned long next_tick; |
61 | unsigned long cycles_elapsed, ticks_elapsed; | 61 | unsigned long cycles_elapsed, ticks_elapsed = 1; |
62 | unsigned long cycles_remainder; | 62 | unsigned long cycles_remainder; |
63 | unsigned int cpu = smp_processor_id(); | 63 | unsigned int cpu = smp_processor_id(); |
64 | struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu); | 64 | struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu); |
@@ -71,44 +71,24 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id) | |||
71 | /* Initialize next_tick to the expected tick time. */ | 71 | /* Initialize next_tick to the expected tick time. */ |
72 | next_tick = cpuinfo->it_value; | 72 | next_tick = cpuinfo->it_value; |
73 | 73 | ||
74 | /* Get current interval timer. | 74 | /* Get current cycle counter (Control Register 16). */ |
75 | * CR16 reads as 64 bits in CPU wide mode. | ||
76 | * CR16 reads as 32 bits in CPU narrow mode. | ||
77 | */ | ||
78 | now = mfctl(16); | 75 | now = mfctl(16); |
79 | 76 | ||
80 | cycles_elapsed = now - next_tick; | 77 | cycles_elapsed = now - next_tick; |
81 | 78 | ||
82 | if ((cycles_elapsed >> 5) < cpt) { | 79 | if ((cycles_elapsed >> 6) < cpt) { |
83 | /* use "cheap" math (add/subtract) instead | 80 | /* use "cheap" math (add/subtract) instead |
84 | * of the more expensive div/mul method | 81 | * of the more expensive div/mul method |
85 | */ | 82 | */ |
86 | cycles_remainder = cycles_elapsed; | 83 | cycles_remainder = cycles_elapsed; |
87 | ticks_elapsed = 1; | ||
88 | while (cycles_remainder > cpt) { | 84 | while (cycles_remainder > cpt) { |
89 | cycles_remainder -= cpt; | 85 | cycles_remainder -= cpt; |
90 | ticks_elapsed++; | 86 | ticks_elapsed++; |
91 | } | 87 | } |
92 | } else { | 88 | } else { |
89 | /* TODO: Reduce this to one fdiv op */ | ||
93 | cycles_remainder = cycles_elapsed % cpt; | 90 | cycles_remainder = cycles_elapsed % cpt; |
94 | ticks_elapsed = 1 + cycles_elapsed / cpt; | 91 | ticks_elapsed += cycles_elapsed / cpt; |
95 | } | ||
96 | |||
97 | /* Can we differentiate between "early CR16" (aka Scenario 1) and | ||
98 | * "long delay" (aka Scenario 3)? I don't think so. | ||
99 | * | ||
100 | * We expected timer_interrupt to be delivered at least a few hundred | ||
101 | * cycles after the IT fires. But it's arbitrary how much time passes | ||
102 | * before we call it "late". I've picked one second. | ||
103 | */ | ||
104 | if (unlikely(ticks_elapsed > HZ)) { | ||
105 | /* Scenario 3: very long delay? bad in any case */ | ||
106 | printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!" | ||
107 | " cycles %lX rem %lX " | ||
108 | " next/now %lX/%lX\n", | ||
109 | cpu, | ||
110 | cycles_elapsed, cycles_remainder, | ||
111 | next_tick, now ); | ||
112 | } | 92 | } |
113 | 93 | ||
114 | /* convert from "division remainder" to "remainder of clock tick" */ | 94 | /* convert from "division remainder" to "remainder of clock tick" */ |
@@ -122,18 +102,56 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id) | |||
122 | 102 | ||
123 | cpuinfo->it_value = next_tick; | 103 | cpuinfo->it_value = next_tick; |
124 | 104 | ||
125 | /* Skip one clocktick on purpose if we are likely to miss next_tick. | 105 | /* Program the IT when to deliver the next interrupt. |
126 | * We want to avoid the new next_tick being less than CR16. | 106 | * Only bottom 32-bits of next_tick are writable in CR16! |
127 | * If that happened, itimer wouldn't fire until CR16 wrapped. | ||
128 | * We'll catch the tick we missed on the tick after that. | ||
129 | */ | 107 | */ |
130 | if (!(cycles_remainder >> 13)) | ||
131 | next_tick += cpt; | ||
132 | |||
133 | /* Program the IT when to deliver the next interrupt. */ | ||
134 | /* Only bottom 32-bits of next_tick are written to cr16. */ | ||
135 | mtctl(next_tick, 16); | 108 | mtctl(next_tick, 16); |
136 | 109 | ||
110 | /* Skip one clocktick on purpose if we missed next_tick. | ||
111 | * The new CR16 must be "later" than current CR16 otherwise | ||
112 | * itimer would not fire until CR16 wrapped - e.g 4 seconds | ||
113 | * later on a 1Ghz processor. We'll account for the missed | ||
114 | * tick on the next timer interrupt. | ||
115 | * | ||
116 | * "next_tick - now" will always give the difference regardless | ||
117 | * if one or the other wrapped. If "now" is "bigger" we'll end up | ||
118 | * with a very large unsigned number. | ||
119 | */ | ||
120 | now2 = mfctl(16); | ||
121 | if (next_tick - now2 > cpt) | ||
122 | mtctl(next_tick+cpt, 16); | ||
123 | |||
124 | #if 1 | ||
125 | /* | ||
126 | * GGG: DEBUG code for how many cycles programming CR16 used. | ||
127 | */ | ||
128 | if (unlikely(now2 - now > 0x3000)) /* 12K cycles */ | ||
129 | printk (KERN_CRIT "timer_interrupt(CPU %d): SLOW! 0x%lx cycles!" | ||
130 | " cyc %lX rem %lX " | ||
131 | " next/now %lX/%lX\n", | ||
132 | cpu, now2 - now, cycles_elapsed, cycles_remainder, | ||
133 | next_tick, now ); | ||
134 | #endif | ||
135 | |||
136 | /* Can we differentiate between "early CR16" (aka Scenario 1) and | ||
137 | * "long delay" (aka Scenario 3)? I don't think so. | ||
138 | * | ||
139 | * Timer_interrupt will be delivered at least a few hundred cycles | ||
140 | * after the IT fires. But it's arbitrary how much time passes | ||
141 | * before we call it "late". I've picked one second. | ||
142 | * | ||
143 | * It's important NO printk's are between reading CR16 and | ||
144 | * setting up the next value. May introduce huge variance. | ||
145 | */ | ||
146 | if (unlikely(ticks_elapsed > HZ)) { | ||
147 | /* Scenario 3: very long delay? bad in any case */ | ||
148 | printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!" | ||
149 | " cycles %lX rem %lX " | ||
150 | " next/now %lX/%lX\n", | ||
151 | cpu, | ||
152 | cycles_elapsed, cycles_remainder, | ||
153 | next_tick, now ); | ||
154 | } | ||
137 | 155 | ||
138 | /* Done mucking with unreliable delivery of interrupts. | 156 | /* Done mucking with unreliable delivery of interrupts. |
139 | * Go do system house keeping. | 157 | * Go do system house keeping. |
@@ -173,7 +191,7 @@ EXPORT_SYMBOL(profile_pc); | |||
173 | 191 | ||
174 | /* clock source code */ | 192 | /* clock source code */ |
175 | 193 | ||
176 | static cycle_t read_cr16(void) | 194 | static cycle_t read_cr16(struct clocksource *cs) |
177 | { | 195 | { |
178 | return get_cycles(); | 196 | return get_cycles(); |
179 | } | 197 | } |