irq.c 4.5 KB

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