irq.c 4.5 KB

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