Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 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> |
Jaswinder Singh Rajput | 6a02e71 | 2009-01-04 16:22:17 +0530 | [diff] [blame] | 8 | #include <linux/smp.h> |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 9 | #include <linux/ftrace.h> |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 10 | |
Ingo Molnar | 7b6aa33 | 2009-02-17 13:58:15 +0100 | [diff] [blame] | 11 | #include <asm/apic.h> |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 12 | #include <asm/io_apic.h> |
Ingo Molnar | c3d8000 | 2008-12-23 15:15:17 +0100 | [diff] [blame] | 13 | #include <asm/irq.h> |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 14 | #include <asm/idle.h> |
Andi Kleen | 01ca79f | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 15 | #include <asm/mce.h> |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 16 | |
| 17 | atomic_t irq_err_count; |
| 18 | |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 19 | /* Function pointer for generic interrupt vector handling */ |
| 20 | void (*generic_interrupt_extension)(void) = NULL; |
| 21 | |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 22 | /* |
| 23 | * 'what should we do if we get a hw irq event on an illegal vector'. |
| 24 | * each architecture has to answer this themselves. |
| 25 | */ |
| 26 | void ack_bad_irq(unsigned int irq) |
| 27 | { |
Cyrill Gorcunov | edea714 | 2009-04-12 20:47:39 +0400 | [diff] [blame] | 28 | if (printk_ratelimit()) |
| 29 | pr_err("unexpected IRQ trap at vector %02x\n", irq); |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 30 | |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 31 | /* |
| 32 | * Currently unexpected vectors happen only on SMP and APIC. |
| 33 | * We _must_ ack these because every local APIC has only N |
| 34 | * irq slots per priority level, and a 'hanging, unacked' IRQ |
| 35 | * holds up an irq slot - in excessive cases (when multiple |
| 36 | * unexpected vectors occur) that might lock up the APIC |
| 37 | * completely. |
| 38 | * But only ack when the APIC is enabled -AK |
| 39 | */ |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 40 | ack_APIC_irq(); |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Brian Gerst | 1b437c8 | 2009-01-19 00:38:57 +0900 | [diff] [blame] | 43 | #define irq_stats(x) (&per_cpu(irq_stat, x)) |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 44 | /* |
| 45 | * /proc/interrupts printing: |
| 46 | */ |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 47 | static int show_other_interrupts(struct seq_file *p, int prec) |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 48 | { |
| 49 | int j; |
| 50 | |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 51 | seq_printf(p, "%*s: ", prec, "NMI"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 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 |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 56 | seq_printf(p, "%*s: ", prec, "LOC"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 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"); |
Jaswinder Singh Rajput | 474e56b | 2009-03-23 02:08:34 +0530 | [diff] [blame] | 60 | |
| 61 | seq_printf(p, "%*s: ", prec, "SPU"); |
| 62 | for_each_online_cpu(j) |
| 63 | seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count); |
| 64 | seq_printf(p, " Spurious interrupts\n"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 65 | #endif |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 66 | if (generic_interrupt_extension) { |
Hidetoshi Seto | 59d1381 | 2009-03-25 10:50:34 +0900 | [diff] [blame] | 67 | seq_printf(p, "%*s: ", prec, "PLT"); |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 68 | for_each_online_cpu(j) |
| 69 | seq_printf(p, "%10u ", irq_stats(j)->generic_irqs); |
| 70 | seq_printf(p, " Platform interrupts\n"); |
| 71 | } |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_SMP |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 73 | seq_printf(p, "%*s: ", prec, "RES"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 74 | for_each_online_cpu(j) |
| 75 | seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count); |
| 76 | seq_printf(p, " Rescheduling interrupts\n"); |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 77 | seq_printf(p, "%*s: ", prec, "CAL"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 78 | for_each_online_cpu(j) |
| 79 | seq_printf(p, "%10u ", irq_stats(j)->irq_call_count); |
| 80 | seq_printf(p, " Function call interrupts\n"); |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 81 | seq_printf(p, "%*s: ", prec, "TLB"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 82 | for_each_online_cpu(j) |
| 83 | seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count); |
| 84 | seq_printf(p, " TLB shootdowns\n"); |
| 85 | #endif |
| 86 | #ifdef CONFIG_X86_MCE |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 87 | seq_printf(p, "%*s: ", prec, "TRM"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 88 | for_each_online_cpu(j) |
| 89 | seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count); |
| 90 | seq_printf(p, " Thermal event interrupts\n"); |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 91 | # ifdef CONFIG_X86_MCE_THRESHOLD |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 92 | seq_printf(p, "%*s: ", prec, "THR"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 93 | for_each_online_cpu(j) |
| 94 | seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count); |
| 95 | seq_printf(p, " Threshold APIC interrupts\n"); |
| 96 | # endif |
| 97 | #endif |
Hidetoshi Seto | 8051dbd | 2009-06-02 16:53:23 +0900 | [diff] [blame^] | 98 | #ifdef CONFIG_X86_NEW_MCE |
Andi Kleen | 01ca79f | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 99 | seq_printf(p, "%*s: ", prec, "MCE"); |
| 100 | for_each_online_cpu(j) |
| 101 | seq_printf(p, "%10u ", per_cpu(mce_exception_count, j)); |
| 102 | seq_printf(p, " Machine check exceptions\n"); |
Andi Kleen | ca84f69 | 2009-05-27 21:56:57 +0200 | [diff] [blame] | 103 | seq_printf(p, "%*s: ", prec, "MCP"); |
| 104 | for_each_online_cpu(j) |
| 105 | seq_printf(p, "%10u ", per_cpu(mce_poll_count, j)); |
| 106 | seq_printf(p, " Machine check polls\n"); |
Andi Kleen | 01ca79f | 2009-05-27 21:56:52 +0200 | [diff] [blame] | 107 | #endif |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 108 | seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count)); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 109 | #if defined(CONFIG_X86_IO_APIC) |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 110 | seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count)); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 111 | #endif |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | int show_interrupts(struct seq_file *p, void *v) |
| 116 | { |
| 117 | unsigned long flags, any_count = 0; |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 118 | int i = *(loff_t *) v, j, prec; |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 119 | struct irqaction *action; |
| 120 | struct irq_desc *desc; |
| 121 | |
| 122 | if (i > nr_irqs) |
| 123 | return 0; |
| 124 | |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 125 | for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec) |
| 126 | j *= 10; |
| 127 | |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 128 | if (i == nr_irqs) |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 129 | return show_other_interrupts(p, prec); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 130 | |
| 131 | /* print header */ |
| 132 | if (i == 0) { |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 133 | seq_printf(p, "%*s", prec + 8, ""); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 134 | for_each_online_cpu(j) |
Ingo Molnar | e9f95e6 | 2008-10-21 15:49:59 +0200 | [diff] [blame] | 135 | seq_printf(p, "CPU%-8d", j); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 136 | seq_putc(p, '\n'); |
| 137 | } |
| 138 | |
| 139 | desc = irq_to_desc(i); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 140 | if (!desc) |
| 141 | return 0; |
| 142 | |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 143 | spin_lock_irqsave(&desc->lock, flags); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 144 | for_each_online_cpu(j) |
| 145 | any_count |= kstat_irqs_cpu(i, j); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 146 | action = desc->action; |
| 147 | if (!action && !any_count) |
| 148 | goto out; |
| 149 | |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 150 | seq_printf(p, "%*d: ", prec, i); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 151 | for_each_online_cpu(j) |
| 152 | seq_printf(p, "%10u ", kstat_irqs_cpu(i, j)); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 153 | seq_printf(p, " %8s", desc->chip->name); |
| 154 | seq_printf(p, "-%-8s", desc->name); |
| 155 | |
| 156 | if (action) { |
| 157 | seq_printf(p, " %s", action->name); |
| 158 | while ((action = action->next) != NULL) |
| 159 | seq_printf(p, ", %s", action->name); |
| 160 | } |
| 161 | |
| 162 | seq_putc(p, '\n'); |
| 163 | out: |
| 164 | spin_unlock_irqrestore(&desc->lock, flags); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * /proc/stat helpers |
| 170 | */ |
| 171 | u64 arch_irq_stat_cpu(unsigned int cpu) |
| 172 | { |
| 173 | u64 sum = irq_stats(cpu)->__nmi_count; |
| 174 | |
| 175 | #ifdef CONFIG_X86_LOCAL_APIC |
| 176 | sum += irq_stats(cpu)->apic_timer_irqs; |
Jaswinder Singh Rajput | 474e56b | 2009-03-23 02:08:34 +0530 | [diff] [blame] | 177 | sum += irq_stats(cpu)->irq_spurious_count; |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 178 | #endif |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 179 | if (generic_interrupt_extension) |
| 180 | sum += irq_stats(cpu)->generic_irqs; |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 181 | #ifdef CONFIG_SMP |
| 182 | sum += irq_stats(cpu)->irq_resched_count; |
| 183 | sum += irq_stats(cpu)->irq_call_count; |
| 184 | sum += irq_stats(cpu)->irq_tlb_count; |
| 185 | #endif |
| 186 | #ifdef CONFIG_X86_MCE |
| 187 | sum += irq_stats(cpu)->irq_thermal_count; |
Andi Kleen | 4efc067 | 2009-04-28 19:07:31 +0200 | [diff] [blame] | 188 | # ifdef CONFIG_X86_MCE_THRESHOLD |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 189 | sum += irq_stats(cpu)->irq_threshold_count; |
Cyrill Gorcunov | edea714 | 2009-04-12 20:47:39 +0400 | [diff] [blame] | 190 | # endif |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 191 | #endif |
Hidetoshi Seto | 8051dbd | 2009-06-02 16:53:23 +0900 | [diff] [blame^] | 192 | #ifdef CONFIG_X86_NEW_MCE |
| 193 | sum += per_cpu(mce_exception_count, cpu); |
| 194 | sum += per_cpu(mce_poll_count, cpu); |
| 195 | #endif |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 196 | return sum; |
| 197 | } |
| 198 | |
| 199 | u64 arch_irq_stat(void) |
| 200 | { |
| 201 | u64 sum = atomic_read(&irq_err_count); |
| 202 | |
| 203 | #ifdef CONFIG_X86_IO_APIC |
| 204 | sum += atomic_read(&irq_mis_count); |
| 205 | #endif |
| 206 | return sum; |
| 207 | } |
Ingo Molnar | c3d8000 | 2008-12-23 15:15:17 +0100 | [diff] [blame] | 208 | |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * do_IRQ handles all normal device IRQ's (the special |
| 212 | * SMP cross-CPU interrupts have their own specific |
| 213 | * handlers). |
| 214 | */ |
| 215 | unsigned int __irq_entry do_IRQ(struct pt_regs *regs) |
| 216 | { |
| 217 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 218 | |
| 219 | /* high bit used in ret_from_ code */ |
| 220 | unsigned vector = ~regs->orig_ax; |
| 221 | unsigned irq; |
| 222 | |
| 223 | exit_idle(); |
| 224 | irq_enter(); |
| 225 | |
| 226 | irq = __get_cpu_var(vector_irq)[vector]; |
| 227 | |
| 228 | if (!handle_irq(irq, regs)) { |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame] | 229 | ack_APIC_irq(); |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 230 | |
| 231 | if (printk_ratelimit()) |
Cyrill Gorcunov | edea714 | 2009-04-12 20:47:39 +0400 | [diff] [blame] | 232 | pr_emerg("%s: %d.%d No irq handler for vector (irq %d)\n", |
| 233 | __func__, smp_processor_id(), vector, irq); |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | irq_exit(); |
| 237 | |
| 238 | set_irq_regs(old_regs); |
| 239 | return 1; |
| 240 | } |
| 241 | |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 242 | /* |
| 243 | * Handler for GENERIC_INTERRUPT_VECTOR. |
| 244 | */ |
| 245 | void 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 Molnar | c3d8000 | 2008-12-23 15:15:17 +0100 | [diff] [blame] | 265 | EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq); |