irq.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. #include <linux/ftrace.h>
  10. #include <asm/apic.h>
  11. #include <asm/io_apic.h>
  12. #include <asm/irq.h>
  13. #include <asm/idle.h>
  14. atomic_t irq_err_count;
  15. /* Function pointer for generic interrupt vector handling */
  16. void (*generic_interrupt_extension)(void) = NULL;
  17. /*
  18. * 'what should we do if we get a hw irq event on an illegal vector'.
  19. * each architecture has to answer this themselves.
  20. */
  21. void ack_bad_irq(unsigned int irq)
  22. {
  23. printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
  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. #define irq_stats(x) (&per_cpu(irq_stat, x))
  39. /*
  40. * /proc/interrupts printing:
  41. */
  42. static int show_other_interrupts(struct seq_file *p, int prec)
  43. {
  44. int j;
  45. seq_printf(p, "%*s: ", prec, "NMI");
  46. for_each_online_cpu(j)
  47. seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
  48. seq_printf(p, " Non-maskable interrupts\n");
  49. #ifdef CONFIG_X86_LOCAL_APIC
  50. seq_printf(p, "%*s: ", prec, "LOC");
  51. for_each_online_cpu(j)
  52. seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
  53. seq_printf(p, " Local timer interrupts\n");
  54. #endif
  55. if (generic_interrupt_extension) {
  56. seq_printf(p, "PLT: ");
  57. for_each_online_cpu(j)
  58. seq_printf(p, "%10u ", irq_stats(j)->generic_irqs);
  59. seq_printf(p, " Platform interrupts\n");
  60. }
  61. #ifdef CONFIG_SMP
  62. seq_printf(p, "%*s: ", prec, "RES");
  63. for_each_online_cpu(j)
  64. seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
  65. seq_printf(p, " Rescheduling interrupts\n");
  66. seq_printf(p, "%*s: ", prec, "CAL");
  67. for_each_online_cpu(j)
  68. seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
  69. seq_printf(p, " Function call interrupts\n");
  70. seq_printf(p, "%*s: ", prec, "TLB");
  71. for_each_online_cpu(j)
  72. seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
  73. seq_printf(p, " TLB shootdowns\n");
  74. #endif
  75. #ifdef CONFIG_X86_MCE
  76. seq_printf(p, "%*s: ", prec, "TRM");
  77. for_each_online_cpu(j)
  78. seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
  79. seq_printf(p, " Thermal event interrupts\n");
  80. # ifdef CONFIG_X86_64
  81. seq_printf(p, "%*s: ", prec, "THR");
  82. for_each_online_cpu(j)
  83. seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
  84. seq_printf(p, " Threshold APIC interrupts\n");
  85. # endif
  86. #endif
  87. #ifdef CONFIG_X86_LOCAL_APIC
  88. seq_printf(p, "%*s: ", prec, "SPU");
  89. for_each_online_cpu(j)
  90. seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
  91. seq_printf(p, " Spurious interrupts\n");
  92. #endif
  93. seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  94. #if defined(CONFIG_X86_IO_APIC)
  95. seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
  96. #endif
  97. return 0;
  98. }
  99. int show_interrupts(struct seq_file *p, void *v)
  100. {
  101. unsigned long flags, any_count = 0;
  102. int i = *(loff_t *) v, j, prec;
  103. struct irqaction *action;
  104. struct irq_desc *desc;
  105. if (i > nr_irqs)
  106. return 0;
  107. for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
  108. j *= 10;
  109. if (i == nr_irqs)
  110. return show_other_interrupts(p, prec);
  111. /* print header */
  112. if (i == 0) {
  113. seq_printf(p, "%*s", prec + 8, "");
  114. for_each_online_cpu(j)
  115. seq_printf(p, "CPU%-8d", j);
  116. seq_putc(p, '\n');
  117. }
  118. desc = irq_to_desc(i);
  119. if (!desc)
  120. return 0;
  121. spin_lock_irqsave(&desc->lock, flags);
  122. #ifndef CONFIG_SMP
  123. any_count = kstat_irqs(i);
  124. #else
  125. for_each_online_cpu(j)
  126. any_count |= kstat_irqs_cpu(i, j);
  127. #endif
  128. action = desc->action;
  129. if (!action && !any_count)
  130. goto out;
  131. seq_printf(p, "%*d: ", prec, i);
  132. #ifndef CONFIG_SMP
  133. seq_printf(p, "%10u ", kstat_irqs(i));
  134. #else
  135. for_each_online_cpu(j)
  136. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  137. #endif
  138. seq_printf(p, " %8s", desc->chip->name);
  139. seq_printf(p, "-%-8s", desc->name);
  140. if (action) {
  141. seq_printf(p, " %s", action->name);
  142. while ((action = action->next) != NULL)
  143. seq_printf(p, ", %s", action->name);
  144. }
  145. seq_putc(p, '\n');
  146. out:
  147. spin_unlock_irqrestore(&desc->lock, flags);
  148. return 0;
  149. }
  150. /*
  151. * /proc/stat helpers
  152. */
  153. u64 arch_irq_stat_cpu(unsigned int cpu)
  154. {
  155. u64 sum = irq_stats(cpu)->__nmi_count;
  156. #ifdef CONFIG_X86_LOCAL_APIC
  157. sum += irq_stats(cpu)->apic_timer_irqs;
  158. #endif
  159. if (generic_interrupt_extension)
  160. sum += irq_stats(cpu)->generic_irqs;
  161. #ifdef CONFIG_SMP
  162. sum += irq_stats(cpu)->irq_resched_count;
  163. sum += irq_stats(cpu)->irq_call_count;
  164. sum += irq_stats(cpu)->irq_tlb_count;
  165. #endif
  166. #ifdef CONFIG_X86_MCE
  167. sum += irq_stats(cpu)->irq_thermal_count;
  168. # ifdef CONFIG_X86_64
  169. sum += irq_stats(cpu)->irq_threshold_count;
  170. #endif
  171. #endif
  172. #ifdef CONFIG_X86_LOCAL_APIC
  173. sum += irq_stats(cpu)->irq_spurious_count;
  174. #endif
  175. return sum;
  176. }
  177. u64 arch_irq_stat(void)
  178. {
  179. u64 sum = atomic_read(&irq_err_count);
  180. #ifdef CONFIG_X86_IO_APIC
  181. sum += atomic_read(&irq_mis_count);
  182. #endif
  183. return sum;
  184. }
  185. /*
  186. * do_IRQ handles all normal device IRQ's (the special
  187. * SMP cross-CPU interrupts have their own specific
  188. * handlers).
  189. */
  190. unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
  191. {
  192. struct pt_regs *old_regs = set_irq_regs(regs);
  193. /* high bit used in ret_from_ code */
  194. unsigned vector = ~regs->orig_ax;
  195. unsigned irq;
  196. exit_idle();
  197. irq_enter();
  198. irq = __get_cpu_var(vector_irq)[vector];
  199. if (!handle_irq(irq, regs)) {
  200. #ifdef CONFIG_X86_64
  201. if (!disable_apic)
  202. ack_APIC_irq();
  203. #endif
  204. if (printk_ratelimit())
  205. printk(KERN_EMERG "%s: %d.%d No irq handler for vector (irq %d)\n",
  206. __func__, smp_processor_id(), vector, irq);
  207. }
  208. irq_exit();
  209. set_irq_regs(old_regs);
  210. return 1;
  211. }
  212. /*
  213. * Handler for GENERIC_INTERRUPT_VECTOR.
  214. */
  215. void smp_generic_interrupt(struct pt_regs *regs)
  216. {
  217. struct pt_regs *old_regs = set_irq_regs(regs);
  218. ack_APIC_irq();
  219. exit_idle();
  220. irq_enter();
  221. inc_irq_stat(generic_irqs);
  222. if (generic_interrupt_extension)
  223. generic_interrupt_extension();
  224. irq_exit();
  225. set_irq_regs(old_regs);
  226. }
  227. EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);