irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #endif
  54. #ifdef CONFIG_SMP
  55. seq_printf(p, "RES: ");
  56. for_each_online_cpu(j)
  57. seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
  58. seq_printf(p, " Rescheduling interrupts\n");
  59. seq_printf(p, "CAL: ");
  60. for_each_online_cpu(j)
  61. seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
  62. seq_printf(p, " Function call interrupts\n");
  63. seq_printf(p, "TLB: ");
  64. for_each_online_cpu(j)
  65. seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
  66. seq_printf(p, " TLB shootdowns\n");
  67. #endif
  68. #ifdef CONFIG_X86_MCE
  69. seq_printf(p, "TRM: ");
  70. for_each_online_cpu(j)
  71. seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
  72. seq_printf(p, " Thermal event interrupts\n");
  73. # ifdef CONFIG_X86_64
  74. seq_printf(p, "THR: ");
  75. for_each_online_cpu(j)
  76. seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
  77. seq_printf(p, " Threshold APIC interrupts\n");
  78. # endif
  79. #endif
  80. #ifdef CONFIG_X86_LOCAL_APIC
  81. seq_printf(p, "SPU: ");
  82. for_each_online_cpu(j)
  83. seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
  84. seq_printf(p, " Spurious interrupts\n");
  85. #endif
  86. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  87. #if defined(CONFIG_X86_IO_APIC)
  88. seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
  89. #endif
  90. return 0;
  91. }
  92. int show_interrupts(struct seq_file *p, void *v)
  93. {
  94. unsigned long flags, any_count = 0;
  95. int i = *(loff_t *) v, j;
  96. struct irqaction *action;
  97. struct irq_desc *desc;
  98. if (i > nr_irqs)
  99. return 0;
  100. if (i == nr_irqs)
  101. return show_other_interrupts(p);
  102. /* print header */
  103. if (i == 0) {
  104. seq_printf(p, " ");
  105. for_each_online_cpu(j)
  106. seq_printf(p, "CPU%-8d", j);
  107. seq_putc(p, '\n');
  108. }
  109. desc = irq_to_desc(i);
  110. if (!desc)
  111. return 0;
  112. spin_lock_irqsave(&desc->lock, flags);
  113. #ifndef CONFIG_SMP
  114. any_count = kstat_irqs(i);
  115. #else
  116. for_each_online_cpu(j)
  117. any_count |= kstat_irqs_cpu(i, j);
  118. #endif
  119. action = desc->action;
  120. if (!action && !any_count)
  121. goto out;
  122. seq_printf(p, "%3d: ", i);
  123. #ifndef CONFIG_SMP
  124. seq_printf(p, "%10u ", kstat_irqs(i));
  125. #else
  126. for_each_online_cpu(j)
  127. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  128. #endif
  129. seq_printf(p, " %8s", desc->chip->name);
  130. seq_printf(p, "-%-8s", desc->name);
  131. if (action) {
  132. seq_printf(p, " %s", action->name);
  133. while ((action = action->next) != NULL)
  134. seq_printf(p, ", %s", action->name);
  135. }
  136. seq_putc(p, '\n');
  137. out:
  138. spin_unlock_irqrestore(&desc->lock, flags);
  139. return 0;
  140. }
  141. /*
  142. * /proc/stat helpers
  143. */
  144. u64 arch_irq_stat_cpu(unsigned int cpu)
  145. {
  146. u64 sum = irq_stats(cpu)->__nmi_count;
  147. #ifdef CONFIG_X86_LOCAL_APIC
  148. sum += irq_stats(cpu)->apic_timer_irqs;
  149. #endif
  150. #ifdef CONFIG_SMP
  151. sum += irq_stats(cpu)->irq_resched_count;
  152. sum += irq_stats(cpu)->irq_call_count;
  153. sum += irq_stats(cpu)->irq_tlb_count;
  154. #endif
  155. #ifdef CONFIG_X86_MCE
  156. sum += irq_stats(cpu)->irq_thermal_count;
  157. # ifdef CONFIG_X86_64
  158. sum += irq_stats(cpu)->irq_threshold_count;
  159. #endif
  160. #endif
  161. #ifdef CONFIG_X86_LOCAL_APIC
  162. sum += irq_stats(cpu)->irq_spurious_count;
  163. #endif
  164. return sum;
  165. }
  166. u64 arch_irq_stat(void)
  167. {
  168. u64 sum = atomic_read(&irq_err_count);
  169. #ifdef CONFIG_X86_IO_APIC
  170. sum += atomic_read(&irq_mis_count);
  171. #endif
  172. return sum;
  173. }