Merge commit 'v2.6.29-rc1' into perfcounters/core
[linux-2.6] / arch / x86 / kernel / irq.c
1 /*
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>
8 #include <linux/smp.h>
9
10 #include <asm/apic.h>
11 #include <asm/io_apic.h>
12 #include <asm/irq.h>
13
14 atomic_t irq_err_count;
15
16 /*
17  * 'what should we do if we get a hw irq event on an illegal vector'.
18  * each architecture has to answer this themselves.
19  */
20 void ack_bad_irq(unsigned int irq)
21 {
22         printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
23
24 #ifdef CONFIG_X86_LOCAL_APIC
25         /*
26          * Currently unexpected vectors happen only on SMP and APIC.
27          * We _must_ ack these because every local APIC has only N
28          * irq slots per priority level, and a 'hanging, unacked' IRQ
29          * holds up an irq slot - in excessive cases (when multiple
30          * unexpected vectors occur) that might lock up the APIC
31          * completely.
32          * But only ack when the APIC is enabled -AK
33          */
34         if (cpu_has_apic)
35                 ack_APIC_irq();
36 #endif
37 }
38
39 #ifdef CONFIG_X86_32
40 # define irq_stats(x)           (&per_cpu(irq_stat, x))
41 #else
42 # define irq_stats(x)           cpu_pda(x)
43 #endif
44 /*
45  * /proc/interrupts printing:
46  */
47 static int show_other_interrupts(struct seq_file *p)
48 {
49         int j;
50
51         seq_printf(p, "NMI: ");
52         for_each_online_cpu(j)
53                 seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
54         seq_printf(p, "  Non-maskable interrupts\n");
55 #ifdef CONFIG_X86_LOCAL_APIC
56         seq_printf(p, "LOC: ");
57         for_each_online_cpu(j)
58                 seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
59         seq_printf(p, "  Local timer interrupts\n");
60         seq_printf(p, "CNT: ");
61         for_each_online_cpu(j)
62                 seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs);
63         seq_printf(p, "  Performance counter interrupts\n");
64 #endif
65 #ifdef CONFIG_SMP
66         seq_printf(p, "RES: ");
67         for_each_online_cpu(j)
68                 seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
69         seq_printf(p, "  Rescheduling interrupts\n");
70         seq_printf(p, "CAL: ");
71         for_each_online_cpu(j)
72                 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
73         seq_printf(p, "  Function call interrupts\n");
74         seq_printf(p, "TLB: ");
75         for_each_online_cpu(j)
76                 seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
77         seq_printf(p, "  TLB shootdowns\n");
78 #endif
79 #ifdef CONFIG_X86_MCE
80         seq_printf(p, "TRM: ");
81         for_each_online_cpu(j)
82                 seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
83         seq_printf(p, "  Thermal event interrupts\n");
84 # ifdef CONFIG_X86_64
85         seq_printf(p, "THR: ");
86         for_each_online_cpu(j)
87                 seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
88         seq_printf(p, "  Threshold APIC interrupts\n");
89 # endif
90 #endif
91 #ifdef CONFIG_X86_LOCAL_APIC
92         seq_printf(p, "SPU: ");
93         for_each_online_cpu(j)
94                 seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
95         seq_printf(p, "  Spurious interrupts\n");
96 #endif
97         seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
98 #if defined(CONFIG_X86_IO_APIC)
99         seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
100 #endif
101         return 0;
102 }
103
104 int show_interrupts(struct seq_file *p, void *v)
105 {
106         unsigned long flags, any_count = 0;
107         int i = *(loff_t *) v, j;
108         struct irqaction *action;
109         struct irq_desc *desc;
110
111         if (i > nr_irqs)
112                 return 0;
113
114         if (i == nr_irqs)
115                 return show_other_interrupts(p);
116
117         /* print header */
118         if (i == 0) {
119                 seq_printf(p, "           ");
120                 for_each_online_cpu(j)
121                         seq_printf(p, "CPU%-8d", j);
122                 seq_putc(p, '\n');
123         }
124
125         desc = irq_to_desc(i);
126         if (!desc)
127                 return 0;
128
129         spin_lock_irqsave(&desc->lock, flags);
130 #ifndef CONFIG_SMP
131         any_count = kstat_irqs(i);
132 #else
133         for_each_online_cpu(j)
134                 any_count |= kstat_irqs_cpu(i, j);
135 #endif
136         action = desc->action;
137         if (!action && !any_count)
138                 goto out;
139
140         seq_printf(p, "%3d: ", i);
141 #ifndef CONFIG_SMP
142         seq_printf(p, "%10u ", kstat_irqs(i));
143 #else
144         for_each_online_cpu(j)
145                 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
146 #endif
147         seq_printf(p, " %8s", desc->chip->name);
148         seq_printf(p, "-%-8s", desc->name);
149
150         if (action) {
151                 seq_printf(p, "  %s", action->name);
152                 while ((action = action->next) != NULL)
153                         seq_printf(p, ", %s", action->name);
154         }
155
156         seq_putc(p, '\n');
157 out:
158         spin_unlock_irqrestore(&desc->lock, flags);
159         return 0;
160 }
161
162 /*
163  * /proc/stat helpers
164  */
165 u64 arch_irq_stat_cpu(unsigned int cpu)
166 {
167         u64 sum = irq_stats(cpu)->__nmi_count;
168
169 #ifdef CONFIG_X86_LOCAL_APIC
170         sum += irq_stats(cpu)->apic_timer_irqs;
171         sum += irq_stats(cpu)->apic_perf_irqs;
172 #endif
173 #ifdef CONFIG_SMP
174         sum += irq_stats(cpu)->irq_resched_count;
175         sum += irq_stats(cpu)->irq_call_count;
176         sum += irq_stats(cpu)->irq_tlb_count;
177 #endif
178 #ifdef CONFIG_X86_MCE
179         sum += irq_stats(cpu)->irq_thermal_count;
180 # ifdef CONFIG_X86_64
181         sum += irq_stats(cpu)->irq_threshold_count;
182 #endif
183 #endif
184 #ifdef CONFIG_X86_LOCAL_APIC
185         sum += irq_stats(cpu)->irq_spurious_count;
186 #endif
187         return sum;
188 }
189
190 u64 arch_irq_stat(void)
191 {
192         u64 sum = atomic_read(&irq_err_count);
193
194 #ifdef CONFIG_X86_IO_APIC
195         sum += atomic_read(&irq_mis_count);
196 #endif
197         return sum;
198 }
199
200 EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);