Skip to content

Commit 160494d

Browse files
committed
parisc: Optimize timer interrupt function
Restructure the timer interrupt function to better cope with missed timer irqs. Optimize the calculation when the next interrupt should happen and skip irqs if they would happen too shortly after exit of the irq function. The update_process_times() call is done anyway at every timer irq, so we can safely drop the prof_counter and prof_multiplier variables from the per_cpu structure. Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 82cbd56 commit 160494d

3 files changed

Lines changed: 29 additions & 92 deletions

File tree

‎arch/parisc/include/asm/processor.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,14 @@ struct system_cpuinfo_parisc {
9393
/* Per CPU data structure - ie varies per CPU. */
9494
struct cpuinfo_parisc {
9595
unsigned long it_value; /* Interval Timer at last timer Intr */
96-
unsigned long it_delta; /* Interval delta (tic_10ms / HZ * 100) */
9796
unsigned long irq_count; /* number of IRQ's since boot */
98-
unsigned long irq_max_cr16; /* longest time to handle a single IRQ */
9997
unsigned long cpuid; /* aka slot_number or set to NO_PROC_ID */
10098
unsigned long hpa; /* Host Physical address */
10199
unsigned long txn_addr; /* MMIO addr of EIR or id_eid */
102100
#ifdef CONFIG_SMP
103101
unsigned long pending_ipi; /* bitmap of type ipi_message_type */
104102
#endif
105103
unsigned long bh_count; /* number of times bh was invoked */
106-
unsigned long prof_counter; /* per CPU profiling support */
107-
unsigned long prof_multiplier; /* per CPU profiling support */
108104
unsigned long fp_rev;
109105
unsigned long fp_model;
110106
unsigned int state;

‎arch/parisc/kernel/processor.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ DEFINE_PER_CPU(struct cpuinfo_parisc, cpu_data);
7878
static void
7979
init_percpu_prof(unsigned long cpunum)
8080
{
81-
struct cpuinfo_parisc *p;
82-
83-
p = &per_cpu(cpu_data, cpunum);
84-
p->prof_counter = 1;
85-
p->prof_multiplier = 1;
8681
}
8782

8883

‎arch/parisc/kernel/time.c‎

Lines changed: 29 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ static unsigned long clocktick __read_mostly; /* timer cycles per tick */
5959
*/
6060
irqreturn_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

Comments
 (0)