Skip to content

Commit 1604f31

Browse files
Matthew WilcoxMatthew Wilcox
authored andcommitted
[PA-RISC] Fix time.c for new do_timer() calling convention
do_timer now wants to know how many ticks have elapsed. Now that we have to calculate that, we can eliminate some of the clever code that avoided having to calculate that. Also add some more documentation. I'd like to thank Grant Grundler for helping me with this. Signed-off-by: Matthew Wilcox <willy@parisc-linux.org>
1 parent 1070c96 commit 1604f31

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

‎arch/parisc/kernel/time.c‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,28 @@ static unsigned long clocktick __read_mostly; /* timer cycles per tick */
3838
extern void smp_do_timer(struct pt_regs *regs);
3939
#endif
4040

41+
/*
42+
* We keep time on PA-RISC Linux by using the Interval Timer which is
43+
* a pair of registers; one is read-only and one is write-only; both
44+
* accessed through CR16. The read-only register is 32 or 64 bits wide,
45+
* and increments by 1 every CPU clock tick. The architecture only
46+
* guarantees us a rate between 0.5 and 2, but all implementations use a
47+
* rate of 1. The write-only register is 32-bits wide. When the lowest
48+
* 32 bits of the read-only register compare equal to the write-only
49+
* register, it raises a maskable external interrupt. Each processor has
50+
* an Interval Timer of its own and they are not synchronised.
51+
*
52+
* We want to generate an interrupt every 1/HZ seconds. So we program
53+
* CR16 to interrupt every @clocktick cycles. The it_value in cpu_data
54+
* is programmed with the intended time of the next tick. We can be
55+
* held off for an arbitrarily long period of time by interrupts being
56+
* disabled, so we may miss one or more ticks.
57+
*/
4158
irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
4259
{
4360
unsigned long now;
4461
unsigned long next_tick;
45-
unsigned long cycles_elapsed;
62+
unsigned long cycles_elapsed, ticks_elapsed;
4663
unsigned long cycles_remainder;
4764
unsigned int cpu = smp_processor_id();
4865

@@ -67,11 +84,14 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
6784
* of the more expensive div/mul method
6885
*/
6986
cycles_remainder = cycles_elapsed;
87+
ticks_elapsed = 1;
7088
while (cycles_remainder > cpt) {
7189
cycles_remainder -= cpt;
90+
ticks_elapsed++;
7291
}
7392
} else {
7493
cycles_remainder = cycles_elapsed % cpt;
94+
ticks_elapsed = 1 + cycles_elapsed / cpt;
7595
}
7696

7797
/* Can we differentiate between "early CR16" (aka Scenario 1) and
@@ -81,18 +101,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
81101
* cycles after the IT fires. But it's arbitrary how much time passes
82102
* before we call it "late". I've picked one second.
83103
*/
84-
/* aproximate HZ with shifts. Intended math is "(elapsed/clocktick) > HZ" */
85-
#if HZ == 1000
86-
if (cycles_elapsed > (cpt << 10) )
87-
#elif HZ == 250
88-
if (cycles_elapsed > (cpt << 8) )
89-
#elif HZ == 100
90-
if (cycles_elapsed > (cpt << 7) )
91-
#else
92-
#warn WTF is HZ set to anyway?
93-
if (cycles_elapsed > (HZ * cpt) )
94-
#endif
95-
{
104+
if (ticks_elapsed > HZ) {
96105
/* Scenario 3: very long delay? bad in any case */
97106
printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!"
98107
" cycles %lX rem %lX "
@@ -136,7 +145,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
136145
#endif
137146
if (cpu == 0) {
138147
write_seqlock(&xtime_lock);
139-
do_timer(regs);
148+
do_timer(ticks_elapsed);
140149
write_sequnlock(&xtime_lock);
141150
}
142151

0 commit comments

Comments
 (0)