irq.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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)
  43. {
  44. int j;
  45. seq_printf(p, "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, "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, "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, "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, "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, "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, "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, "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, "ERR: %10u\n", atomic_read(&irq_err_count));
  94. #if defined(CONFIG_X86_IO_APIC)
  95. seq_printf(p, "MIS: %10u\n", 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;
  103. struct irqaction *action;
  104. struct irq_desc *desc;
  105. if (i > nr_irqs)
  106. return 0;
  107. if (i == nr_irqs)
  108. return show_other_interrupts(p);
  109. /* print header */
  110. if (i == 0) {
  111. seq_printf(p, " ");
  112. for_each_online_cpu(j)
  113. seq_printf(p, "CPU%-8d", j);
  114. seq_putc(p, '\n');
  115. }
  116. desc = irq_to_desc(i);
  117. if (!desc)
  118. return 0;
  119. spin_lock_irqsave(&desc->lock, flags);
  120. #ifndef CONFIG_SMP
  121. any_count = kstat_irqs(i);
  122. #else
  123. for_each_online_cpu(j)
  124. any_count |= kstat_irqs_cpu(i, j);
  125. #endif
  126. action = desc->action;
  127. if (!action && !any_count)
  128. goto out;
  129. seq_printf(p, "%3d: ", i);
  130. #ifndef CONFIG_SMP
  131. seq_printf(p, "%10u ", kstat_irqs(i));
  132. #else
  133. for_each_online_cpu(j)
  134. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  135. #endif
  136. seq_printf(p, " %8s", desc->chip->name);
  137. seq_printf(p, "-%-8s", desc->name);
  138. if (action) {
  139. seq_printf(p, " %s", action->name);
  140. while ((action = action->next) != NULL)
  141. seq_printf(p, ", %s", action->name);
  142. }
  143. seq_putc(p, '\n');
  144. out:
  145. spin_unlock_irqrestore(&desc->lock, flags);
  146. return 0;
  147. }
  148. /*
  149. * /proc/stat helpers
  150. */
  151. u64 arch_irq_stat_cpu(unsigned int cpu)
  152. {
  153. u64 sum = irq_stats(cpu)->__nmi_count;
  154. #ifdef CONFIG_X86_LOCAL_APIC
  155. sum += irq_stats(cpu)->apic_timer_irqs;
  156. #endif
  157. if (generic_interrupt_extension)
  158. sum += irq_stats(cpu)->generic_irqs;
  159. #ifdef CONFIG_SMP
  160. sum += irq_stats(cpu)->irq_resched_count;
  161. sum += irq_stats(cpu)->irq_call_count;
  162. sum += irq_stats(cpu)->irq_tlb_count;
  163. #endif
  164. #ifdef CONFIG_X86_MCE
  165. sum += irq_stats(cpu)->irq_thermal_count;
  166. # ifdef CONFIG_X86_64
  167. sum += irq_stats(cpu)->irq_threshold_count;
  168. #endif
  169. #endif
  170. #ifdef CONFIG_X86_LOCAL_APIC
  171. sum += irq_stats(cpu)->irq_spurious_count;
  172. #endif
  173. return sum;
  174. }
  175. u64 arch_irq_stat(void)
  176. {
  177. u64 sum = atomic_read(&irq_err_count);
  178. #ifdef CONFIG_X86_IO_APIC
  179. sum += atomic_read(&irq_mis_count);
  180. #endif
  181. return sum;
  182. }
  183. /*
  184. * do_IRQ handles all normal device IRQ's (the special
  185. * SMP cross-CPU interrupts have their own specific
  186. * handlers).
  187. */
  188. unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
  189. {
  190. struct pt_regs *old_regs = set_irq_regs(regs);
  191. /* high bit used in ret_from_ code */
  192. unsigned vector = ~regs->orig_ax;
  193. unsigned irq;
  194. exit_idle();
  195. irq_enter();
  196. irq = __get_cpu_var(vector_irq)[vector];
  197. if (!handle_irq(irq, regs)) {
  198. #ifdef CONFIG_X86_64
  199. if (!disable_apic)
  200. ack_APIC_irq();
  201. #endif
  202. if (printk_ratelimit())
  203. printk(KERN_EMERG "%s: %d.%d No irq handler for vector (irq %d)\n",
  204. __func__, smp_processor_id(), vector, irq);
  205. }
  206. irq_exit();
  207. set_irq_regs(old_regs);
  208. return 1;
  209. }
  210. /*
  211. * Handler for GENERIC_INTERRUPT_VECTOR.
  212. */
  213. void smp_generic_interrupt(struct pt_regs *regs)
  214. {
  215. struct pt_regs *old_regs = set_irq_regs(regs);
  216. ack_APIC_irq();
  217. exit_idle();
  218. irq_enter();
  219. inc_irq_stat(generic_irqs);
  220. if (generic_interrupt_extension)
  221. generic_interrupt_extension();
  222. irq_exit();
  223. set_irq_regs(old_regs);
  224. }
  225. EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);