irq.c 4.6 KB

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