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> |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 15 | |
| 16 | atomic_t irq_err_count; |
| 17 | |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 18 | /* Function pointer for generic interrupt vector handling */ |
| 19 | void (*generic_interrupt_extension)(void) = NULL; |
| 20 | |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 21 | /* |
| 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 | */ |
| 25 | void ack_bad_irq(unsigned int irq) |
| 26 | { |
Cyrill Gorcunov | edea714 | 2009-04-12 20:47:39 +0400 | [diff] [blame] | 27 | if (printk_ratelimit()) |
| 28 | pr_err("unexpected IRQ trap at vector %02x\n", irq); |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 29 | |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 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 | */ |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame^] | 39 | ack_APIC_irq(); |
Thomas Gleixner | 249f6d9 | 2008-10-16 12:18:50 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Brian Gerst | 1b437c8 | 2009-01-19 00:38:57 +0900 | [diff] [blame] | 42 | #define irq_stats(x) (&per_cpu(irq_stat, x)) |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 43 | /* |
| 44 | * /proc/interrupts printing: |
| 45 | */ |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 46 | static int show_other_interrupts(struct seq_file *p, int prec) |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 47 | { |
| 48 | int j; |
| 49 | |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 50 | seq_printf(p, "%*s: ", prec, "NMI"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 51 | for_each_online_cpu(j) |
| 52 | seq_printf(p, "%10u ", irq_stats(j)->__nmi_count); |
| 53 | seq_printf(p, " Non-maskable interrupts\n"); |
| 54 | #ifdef CONFIG_X86_LOCAL_APIC |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 55 | seq_printf(p, "%*s: ", prec, "LOC"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 56 | for_each_online_cpu(j) |
| 57 | seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs); |
| 58 | seq_printf(p, " Local timer interrupts\n"); |
Jaswinder Singh Rajput | 474e56b | 2009-03-23 02:08:34 +0530 | [diff] [blame] | 59 | |
| 60 | seq_printf(p, "%*s: ", prec, "SPU"); |
| 61 | for_each_online_cpu(j) |
| 62 | seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count); |
| 63 | seq_printf(p, " Spurious interrupts\n"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 64 | #endif |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 65 | if (generic_interrupt_extension) { |
| 66 | seq_printf(p, "PLT: "); |
| 67 | for_each_online_cpu(j) |
| 68 | seq_printf(p, "%10u ", irq_stats(j)->generic_irqs); |
| 69 | seq_printf(p, " Platform interrupts\n"); |
| 70 | } |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_SMP |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 72 | seq_printf(p, "%*s: ", prec, "RES"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 73 | for_each_online_cpu(j) |
| 74 | seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count); |
| 75 | seq_printf(p, " Rescheduling interrupts\n"); |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 76 | seq_printf(p, "%*s: ", prec, "CAL"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 77 | for_each_online_cpu(j) |
| 78 | seq_printf(p, "%10u ", irq_stats(j)->irq_call_count); |
| 79 | seq_printf(p, " Function call interrupts\n"); |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 80 | seq_printf(p, "%*s: ", prec, "TLB"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 81 | for_each_online_cpu(j) |
| 82 | seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count); |
| 83 | seq_printf(p, " TLB shootdowns\n"); |
| 84 | #endif |
| 85 | #ifdef CONFIG_X86_MCE |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 86 | seq_printf(p, "%*s: ", prec, "TRM"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 87 | for_each_online_cpu(j) |
| 88 | seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count); |
| 89 | seq_printf(p, " Thermal event interrupts\n"); |
| 90 | # ifdef CONFIG_X86_64 |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 91 | seq_printf(p, "%*s: ", prec, "THR"); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 92 | for_each_online_cpu(j) |
| 93 | seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count); |
| 94 | seq_printf(p, " Threshold APIC interrupts\n"); |
| 95 | # endif |
| 96 | #endif |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 97 | 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] | 98 | #if defined(CONFIG_X86_IO_APIC) |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 99 | 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] | 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; |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 107 | int i = *(loff_t *) v, j, prec; |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 108 | struct irqaction *action; |
| 109 | struct irq_desc *desc; |
| 110 | |
| 111 | if (i > nr_irqs) |
| 112 | return 0; |
| 113 | |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 114 | for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec) |
| 115 | j *= 10; |
| 116 | |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 117 | if (i == nr_irqs) |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 118 | return show_other_interrupts(p, prec); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 119 | |
| 120 | /* print header */ |
| 121 | if (i == 0) { |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 122 | seq_printf(p, "%*s", prec + 8, ""); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 123 | for_each_online_cpu(j) |
Ingo Molnar | e9f95e6 | 2008-10-21 15:49:59 +0200 | [diff] [blame] | 124 | seq_printf(p, "CPU%-8d", j); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 125 | seq_putc(p, '\n'); |
| 126 | } |
| 127 | |
| 128 | desc = irq_to_desc(i); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 129 | if (!desc) |
| 130 | return 0; |
| 131 | |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 132 | spin_lock_irqsave(&desc->lock, flags); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 133 | for_each_online_cpu(j) |
| 134 | any_count |= kstat_irqs_cpu(i, j); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 135 | action = desc->action; |
| 136 | if (!action && !any_count) |
| 137 | goto out; |
| 138 | |
Jan Beulich | 7a81d9a | 2009-03-12 12:45:15 +0000 | [diff] [blame] | 139 | seq_printf(p, "%*d: ", prec, i); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 140 | for_each_online_cpu(j) |
| 141 | seq_printf(p, "%10u ", kstat_irqs_cpu(i, j)); |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 142 | seq_printf(p, " %8s", desc->chip->name); |
| 143 | seq_printf(p, "-%-8s", desc->name); |
| 144 | |
| 145 | if (action) { |
| 146 | seq_printf(p, " %s", action->name); |
| 147 | while ((action = action->next) != NULL) |
| 148 | seq_printf(p, ", %s", action->name); |
| 149 | } |
| 150 | |
| 151 | seq_putc(p, '\n'); |
| 152 | out: |
| 153 | spin_unlock_irqrestore(&desc->lock, flags); |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * /proc/stat helpers |
| 159 | */ |
| 160 | u64 arch_irq_stat_cpu(unsigned int cpu) |
| 161 | { |
| 162 | u64 sum = irq_stats(cpu)->__nmi_count; |
| 163 | |
| 164 | #ifdef CONFIG_X86_LOCAL_APIC |
| 165 | sum += irq_stats(cpu)->apic_timer_irqs; |
Jaswinder Singh Rajput | 474e56b | 2009-03-23 02:08:34 +0530 | [diff] [blame] | 166 | sum += irq_stats(cpu)->irq_spurious_count; |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 167 | #endif |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 168 | if (generic_interrupt_extension) |
| 169 | sum += irq_stats(cpu)->generic_irqs; |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 170 | #ifdef CONFIG_SMP |
| 171 | sum += irq_stats(cpu)->irq_resched_count; |
| 172 | sum += irq_stats(cpu)->irq_call_count; |
| 173 | sum += irq_stats(cpu)->irq_tlb_count; |
| 174 | #endif |
| 175 | #ifdef CONFIG_X86_MCE |
| 176 | sum += irq_stats(cpu)->irq_thermal_count; |
| 177 | # ifdef CONFIG_X86_64 |
| 178 | sum += irq_stats(cpu)->irq_threshold_count; |
Cyrill Gorcunov | edea714 | 2009-04-12 20:47:39 +0400 | [diff] [blame] | 179 | # endif |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 180 | #endif |
Thomas Gleixner | 6b39ba7 | 2008-10-16 11:32:24 +0200 | [diff] [blame] | 181 | return sum; |
| 182 | } |
| 183 | |
| 184 | u64 arch_irq_stat(void) |
| 185 | { |
| 186 | u64 sum = atomic_read(&irq_err_count); |
| 187 | |
| 188 | #ifdef CONFIG_X86_IO_APIC |
| 189 | sum += atomic_read(&irq_mis_count); |
| 190 | #endif |
| 191 | return sum; |
| 192 | } |
Ingo Molnar | c3d8000 | 2008-12-23 15:15:17 +0100 | [diff] [blame] | 193 | |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * do_IRQ handles all normal device IRQ's (the special |
| 197 | * SMP cross-CPU interrupts have their own specific |
| 198 | * handlers). |
| 199 | */ |
| 200 | unsigned int __irq_entry do_IRQ(struct pt_regs *regs) |
| 201 | { |
| 202 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 203 | |
| 204 | /* high bit used in ret_from_ code */ |
| 205 | unsigned vector = ~regs->orig_ax; |
| 206 | unsigned irq; |
| 207 | |
| 208 | exit_idle(); |
| 209 | irq_enter(); |
| 210 | |
| 211 | irq = __get_cpu_var(vector_irq)[vector]; |
| 212 | |
| 213 | if (!handle_irq(irq, regs)) { |
Cyrill Gorcunov | 08306ce | 2009-04-12 20:47:41 +0400 | [diff] [blame^] | 214 | ack_APIC_irq(); |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 215 | |
| 216 | if (printk_ratelimit()) |
Cyrill Gorcunov | edea714 | 2009-04-12 20:47:39 +0400 | [diff] [blame] | 217 | pr_emerg("%s: %d.%d No irq handler for vector (irq %d)\n", |
| 218 | __func__, smp_processor_id(), vector, irq); |
Jeremy Fitzhardinge | 7c1d7cd | 2009-02-06 14:09:41 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | irq_exit(); |
| 222 | |
| 223 | set_irq_regs(old_regs); |
| 224 | return 1; |
| 225 | } |
| 226 | |
Dimitri Sivanich | acaabe7 | 2009-03-04 12:56:05 -0600 | [diff] [blame] | 227 | /* |
| 228 | * Handler for GENERIC_INTERRUPT_VECTOR. |
| 229 | */ |
| 230 | void smp_generic_interrupt(struct pt_regs *regs) |
| 231 | { |
| 232 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 233 | |
| 234 | ack_APIC_irq(); |
| 235 | |
| 236 | exit_idle(); |
| 237 | |
| 238 | irq_enter(); |
| 239 | |
| 240 | inc_irq_stat(generic_irqs); |
| 241 | |
| 242 | if (generic_interrupt_extension) |
| 243 | generic_interrupt_extension(); |
| 244 | |
| 245 | irq_exit(); |
| 246 | |
| 247 | set_irq_regs(old_regs); |
| 248 | } |
| 249 | |
Ingo Molnar | c3d8000 | 2008-12-23 15:15:17 +0100 | [diff] [blame] | 250 | EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq); |