irq.c 5.2 KB

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