@@ -59,10 +59,9 @@ static unsigned long clocktick __read_mostly; /* timer cycles per tick */
5959 */
6060irqreturn_t __irq_entry timer_interrupt (int irq , void * dev_id )
6161{
62- unsigned long now , now2 ;
62+ unsigned long now ;
6363 unsigned long next_tick ;
64- unsigned long cycles_elapsed , ticks_elapsed = 1 ;
65- unsigned long cycles_remainder ;
64+ unsigned long ticks_elapsed = 0 ;
6665 unsigned int cpu = smp_processor_id ();
6766 struct cpuinfo_parisc * cpuinfo = & per_cpu (cpu_data , cpu );
6867
@@ -71,102 +70,49 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
7170
7271 profile_tick (CPU_PROFILING );
7372
74- /* Initialize next_tick to the expected tick time. */
73+ /* Initialize next_tick to the old expected tick time. */
7574 next_tick = cpuinfo -> it_value ;
7675
77- /* Get current cycle counter (Control Register 16). */
78- now = mfctl (16 );
79-
80- cycles_elapsed = now - next_tick ;
81-
82- if ((cycles_elapsed >> 6 ) < cpt ) {
83- /* use "cheap" math (add/subtract) instead
84- * of the more expensive div/mul method
85- */
86- cycles_remainder = cycles_elapsed ;
87- while (cycles_remainder > cpt ) {
88- cycles_remainder -= cpt ;
89- ticks_elapsed ++ ;
90- }
91- } else {
92- /* TODO: Reduce this to one fdiv op */
93- cycles_remainder = cycles_elapsed % cpt ;
94- ticks_elapsed += cycles_elapsed / cpt ;
95- }
96-
97- /* convert from "division remainder" to "remainder of clock tick" */
98- cycles_remainder = cpt - cycles_remainder ;
99-
100- /* Determine when (in CR16 cycles) next IT interrupt will fire.
101- * We want IT to fire modulo clocktick even if we miss/skip some.
102- * But those interrupts don't in fact get delivered that regularly.
103- */
104- next_tick = now + cycles_remainder ;
76+ /* Calculate how many ticks have elapsed. */
77+ do {
78+ ++ ticks_elapsed ;
79+ next_tick += cpt ;
80+ now = mfctl (16 );
81+ } while (next_tick - now > cpt );
10582
83+ /* Store (in CR16 cycles) up to when we are accounting right now. */
10684 cpuinfo -> it_value = next_tick ;
10785
108- /* Program the IT when to deliver the next interrupt.
109- * Only bottom 32-bits of next_tick are writable in CR16!
110- */
111- mtctl (next_tick , 16 );
86+ /* Go do system house keeping. */
87+ if (cpu == 0 )
88+ xtime_update (ticks_elapsed );
89+
90+ update_process_times (user_mode (get_irq_regs ()));
11291
113- /* Skip one clocktick on purpose if we missed next_tick .
92+ /* Skip clockticks on purpose if we know we would miss those .
11493 * The new CR16 must be "later" than current CR16 otherwise
11594 * itimer would not fire until CR16 wrapped - e.g 4 seconds
11695 * later on a 1Ghz processor. We'll account for the missed
117- * tick on the next timer interrupt.
96+ * ticks on the next timer interrupt.
97+ * We want IT to fire modulo clocktick even if we miss/skip some.
98+ * But those interrupts don't in fact get delivered that regularly.
11899 *
119100 * "next_tick - now" will always give the difference regardless
120101 * if one or the other wrapped. If "now" is "bigger" we'll end up
121102 * with a very large unsigned number.
122103 */
123- now2 = mfctl (16 );
124- if (next_tick - now2 > cpt )
125- mtctl (next_tick + cpt , 16 );
104+ while (next_tick - mfctl (16 ) > cpt )
105+ next_tick += cpt ;
126106
127- #if 1
128- /*
129- * GGG: DEBUG code for how many cycles programming CR16 used.
130- */
131- if (unlikely (now2 - now > 0x3000 )) /* 12K cycles */
132- printk (KERN_CRIT "timer_interrupt(CPU %d): SLOW! 0x%lx cycles!"
133- " cyc %lX rem %lX "
134- " next/now %lX/%lX\n" ,
135- cpu , now2 - now , cycles_elapsed , cycles_remainder ,
136- next_tick , now );
137- #endif
138-
139- /* Can we differentiate between "early CR16" (aka Scenario 1) and
140- * "long delay" (aka Scenario 3)? I don't think so.
141- *
142- * Timer_interrupt will be delivered at least a few hundred cycles
143- * after the IT fires. But it's arbitrary how much time passes
144- * before we call it "late". I've picked one second.
145- *
146- * It's important NO printk's are between reading CR16 and
147- * setting up the next value. May introduce huge variance.
148- */
149- if (unlikely (ticks_elapsed > HZ )) {
150- /* Scenario 3: very long delay? bad in any case */
151- printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!"
152- " cycles %lX rem %lX "
153- " next/now %lX/%lX\n" ,
154- cpu ,
155- cycles_elapsed , cycles_remainder ,
156- next_tick , now );
157- }
158-
159- /* Done mucking with unreliable delivery of interrupts.
160- * Go do system house keeping.
107+ /* Program the IT when to deliver the next interrupt.
108+ * Only bottom 32-bits of next_tick are writable in CR16!
109+ * Timer interrupt will be delivered at least a few hundred cycles
110+ * after the IT fires, so if we are too close (<= 500 cycles) to the
111+ * next cycle, simply skip it.
161112 */
162-
163- if (!-- cpuinfo -> prof_counter ) {
164- cpuinfo -> prof_counter = cpuinfo -> prof_multiplier ;
165- update_process_times (user_mode (get_irq_regs ()));
166- }
167-
168- if (cpu == 0 )
169- xtime_update (ticks_elapsed );
113+ if (next_tick - mfctl (16 ) <= 500 )
114+ next_tick += cpt ;
115+ mtctl (next_tick , 16 );
170116
171117 return IRQ_HANDLED ;
172118}
0 commit comments