blob: 849cfabb1fdceef2390c8447bfa7d190acd04848 [file] [log] [blame]
Thomas Gleixner6b39ba72008-10-16 11:32:24 +02001/*
2 * Common interrupt code for 32 and 64 bit
3 */
4#include <linux/cpu.h>
5#include <linux/interrupt.h>
6#include <linux/kernel_stat.h>
7#include <linux/seq_file.h>
Jaswinder Singh Rajput6a02e712009-01-04 16:22:17 +05308#include <linux/smp.h>
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -08009#include <linux/ftrace.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020010
11#include <asm/apic.h>
12#include <asm/io_apic.h>
Ingo Molnarc3d80002008-12-23 15:15:17 +010013#include <asm/irq.h>
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -080014#include <asm/idle.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020015
16atomic_t irq_err_count;
17
Dimitri Sivanichacaabe72009-03-04 12:56:05 -060018/* Function pointer for generic interrupt vector handling */
19void (*generic_interrupt_extension)(void) = NULL;
20
Thomas Gleixner249f6d92008-10-16 12:18:50 +020021/*
22 * 'what should we do if we get a hw irq event on an illegal vector'.
23 * each architecture has to answer this themselves.
24 */
25void ack_bad_irq(unsigned int irq)
26{
27 printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
28
29#ifdef CONFIG_X86_LOCAL_APIC
30 /*
31 * Currently unexpected vectors happen only on SMP and APIC.
32 * We _must_ ack these because every local APIC has only N
33 * irq slots per priority level, and a 'hanging, unacked' IRQ
34 * holds up an irq slot - in excessive cases (when multiple
35 * unexpected vectors occur) that might lock up the APIC
36 * completely.
37 * But only ack when the APIC is enabled -AK
38 */
39 if (cpu_has_apic)
40 ack_APIC_irq();
41#endif
42}
43
Brian Gerst1b437c82009-01-19 00:38:57 +090044#define irq_stats(x) (&per_cpu(irq_stat, x))
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020045/*
46 * /proc/interrupts printing:
47 */
Jan Beulich7a81d9a2009-03-12 12:45:15 +000048static int show_other_interrupts(struct seq_file *p, int prec)
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020049{
50 int j;
51
Jan Beulich7a81d9a2009-03-12 12:45:15 +000052 seq_printf(p, "%*s: ", prec, "NMI");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020053 for_each_online_cpu(j)
54 seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
55 seq_printf(p, " Non-maskable interrupts\n");
56#ifdef CONFIG_X86_LOCAL_APIC
Jan Beulich7a81d9a2009-03-12 12:45:15 +000057 seq_printf(p, "%*s: ", prec, "LOC");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020058 for_each_online_cpu(j)
59 seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
60 seq_printf(p, " Local timer interrupts\n");
Jaswinder Singh Rajput474e56b2009-03-23 02:08:34 +053061
62 seq_printf(p, "%*s: ", prec, "SPU");
63 for_each_online_cpu(j)
64 seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
65 seq_printf(p, " Spurious interrupts\n");
Hidetoshi Seto7333a802009-03-25 10:50:34 +090066 seq_printf(p, "%*s: ", prec, "CNT");
Ingo Molnar241771e2008-12-03 10:39:53 +010067 for_each_online_cpu(j)
68 seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs);
69 seq_printf(p, " Performance counter interrupts\n");
Luis Henriques0f3fd872009-04-13 20:24:50 +010070 seq_printf(p, "%*s: ", prec, "PND");
Peter Zijlstrab6276f32009-04-06 11:45:03 +020071 for_each_online_cpu(j)
72 seq_printf(p, "%10u ", irq_stats(j)->apic_pending_irqs);
73 seq_printf(p, " Performance pending work\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020074#endif
Dimitri Sivanichacaabe72009-03-04 12:56:05 -060075 if (generic_interrupt_extension) {
76 seq_printf(p, "PLT: ");
77 for_each_online_cpu(j)
78 seq_printf(p, "%10u ", irq_stats(j)->generic_irqs);
79 seq_printf(p, " Platform interrupts\n");
80 }
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020081#ifdef CONFIG_SMP
Jan Beulich7a81d9a2009-03-12 12:45:15 +000082 seq_printf(p, "%*s: ", prec, "RES");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020083 for_each_online_cpu(j)
84 seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
85 seq_printf(p, " Rescheduling interrupts\n");
Jan Beulich7a81d9a2009-03-12 12:45:15 +000086 seq_printf(p, "%*s: ", prec, "CAL");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020087 for_each_online_cpu(j)
88 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
89 seq_printf(p, " Function call interrupts\n");
Jan Beulich7a81d9a2009-03-12 12:45:15 +000090 seq_printf(p, "%*s: ", prec, "TLB");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020091 for_each_online_cpu(j)
92 seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
93 seq_printf(p, " TLB shootdowns\n");
94#endif
95#ifdef CONFIG_X86_MCE
Jan Beulich7a81d9a2009-03-12 12:45:15 +000096 seq_printf(p, "%*s: ", prec, "TRM");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020097 for_each_online_cpu(j)
98 seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
99 seq_printf(p, " Thermal event interrupts\n");
100# ifdef CONFIG_X86_64
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000101 seq_printf(p, "%*s: ", prec, "THR");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200102 for_each_online_cpu(j)
103 seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
104 seq_printf(p, " Threshold APIC interrupts\n");
105# endif
106#endif
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000107 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200108#if defined(CONFIG_X86_IO_APIC)
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000109 seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200110#endif
111 return 0;
112}
113
114int show_interrupts(struct seq_file *p, void *v)
115{
116 unsigned long flags, any_count = 0;
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000117 int i = *(loff_t *) v, j, prec;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200118 struct irqaction *action;
119 struct irq_desc *desc;
120
121 if (i > nr_irqs)
122 return 0;
123
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000124 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
125 j *= 10;
126
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200127 if (i == nr_irqs)
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000128 return show_other_interrupts(p, prec);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200129
130 /* print header */
131 if (i == 0) {
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000132 seq_printf(p, "%*s", prec + 8, "");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200133 for_each_online_cpu(j)
Ingo Molnare9f95e62008-10-21 15:49:59 +0200134 seq_printf(p, "CPU%-8d", j);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200135 seq_putc(p, '\n');
136 }
137
138 desc = irq_to_desc(i);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800139 if (!desc)
140 return 0;
141
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200142 spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200143 for_each_online_cpu(j)
144 any_count |= kstat_irqs_cpu(i, j);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200145 action = desc->action;
146 if (!action && !any_count)
147 goto out;
148
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000149 seq_printf(p, "%*d: ", prec, i);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200150 for_each_online_cpu(j)
151 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200152 seq_printf(p, " %8s", desc->chip->name);
153 seq_printf(p, "-%-8s", desc->name);
154
155 if (action) {
156 seq_printf(p, " %s", action->name);
157 while ((action = action->next) != NULL)
158 seq_printf(p, ", %s", action->name);
159 }
160
161 seq_putc(p, '\n');
162out:
163 spin_unlock_irqrestore(&desc->lock, flags);
164 return 0;
165}
166
167/*
168 * /proc/stat helpers
169 */
170u64 arch_irq_stat_cpu(unsigned int cpu)
171{
172 u64 sum = irq_stats(cpu)->__nmi_count;
173
174#ifdef CONFIG_X86_LOCAL_APIC
175 sum += irq_stats(cpu)->apic_timer_irqs;
Jaswinder Singh Rajput474e56b2009-03-23 02:08:34 +0530176 sum += irq_stats(cpu)->irq_spurious_count;
Ingo Molnar241771e2008-12-03 10:39:53 +0100177 sum += irq_stats(cpu)->apic_perf_irqs;
Peter Zijlstrab6276f32009-04-06 11:45:03 +0200178 sum += irq_stats(cpu)->apic_pending_irqs;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200179#endif
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600180 if (generic_interrupt_extension)
181 sum += irq_stats(cpu)->generic_irqs;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200182#ifdef CONFIG_SMP
183 sum += irq_stats(cpu)->irq_resched_count;
184 sum += irq_stats(cpu)->irq_call_count;
185 sum += irq_stats(cpu)->irq_tlb_count;
186#endif
187#ifdef CONFIG_X86_MCE
188 sum += irq_stats(cpu)->irq_thermal_count;
189# ifdef CONFIG_X86_64
190 sum += irq_stats(cpu)->irq_threshold_count;
191#endif
192#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200193 return sum;
194}
195
196u64 arch_irq_stat(void)
197{
198 u64 sum = atomic_read(&irq_err_count);
199
200#ifdef CONFIG_X86_IO_APIC
201 sum += atomic_read(&irq_mis_count);
202#endif
203 return sum;
204}
Ingo Molnarc3d80002008-12-23 15:15:17 +0100205
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800206
207/*
208 * do_IRQ handles all normal device IRQ's (the special
209 * SMP cross-CPU interrupts have their own specific
210 * handlers).
211 */
212unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
213{
214 struct pt_regs *old_regs = set_irq_regs(regs);
215
216 /* high bit used in ret_from_ code */
217 unsigned vector = ~regs->orig_ax;
218 unsigned irq;
219
220 exit_idle();
221 irq_enter();
222
223 irq = __get_cpu_var(vector_irq)[vector];
224
225 if (!handle_irq(irq, regs)) {
226#ifdef CONFIG_X86_64
227 if (!disable_apic)
228 ack_APIC_irq();
229#endif
230
231 if (printk_ratelimit())
232 printk(KERN_EMERG "%s: %d.%d No irq handler for vector (irq %d)\n",
233 __func__, smp_processor_id(), vector, irq);
234 }
235
236 irq_exit();
237
238 set_irq_regs(old_regs);
239 return 1;
240}
241
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600242/*
243 * Handler for GENERIC_INTERRUPT_VECTOR.
244 */
245void smp_generic_interrupt(struct pt_regs *regs)
246{
247 struct pt_regs *old_regs = set_irq_regs(regs);
248
249 ack_APIC_irq();
250
251 exit_idle();
252
253 irq_enter();
254
255 inc_irq_stat(generic_irqs);
256
257 if (generic_interrupt_extension)
258 generic_interrupt_extension();
259
260 irq_exit();
261
262 set_irq_regs(old_regs);
263}
264
Ingo Molnarc3d80002008-12-23 15:15:17 +0100265EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);