irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. spin_lock_irqsave(&desc->lock, flags);
  111. #ifndef CONFIG_SMP
  112. any_count = kstat_irqs(i);
  113. #else
  114. for_each_online_cpu(j)
  115. any_count |= kstat_irqs_cpu(i, j);
  116. #endif
  117. action = desc->action;
  118. if (!action && !any_count)
  119. goto out;
  120. seq_printf(p, "%3d: ", i);
  121. #ifndef CONFIG_SMP
  122. seq_printf(p, "%10u ", kstat_irqs(i));
  123. #else
  124. for_each_online_cpu(j)
  125. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  126. #endif
  127. seq_printf(p, " %8s", desc->chip->name);
  128. seq_printf(p, "-%-8s", desc->name);
  129. if (action) {
  130. seq_printf(p, " %s", action->name);
  131. while ((action = action->next) != NULL)
  132. seq_printf(p, ", %s", action->name);
  133. }
  134. seq_putc(p, '\n');
  135. out:
  136. spin_unlock_irqrestore(&desc->lock, flags);
  137. return 0;
  138. }
  139. /*
  140. * /proc/stat helpers
  141. */
  142. u64 arch_irq_stat_cpu(unsigned int cpu)
  143. {
  144. u64 sum = irq_stats(cpu)->__nmi_count;
  145. #ifdef CONFIG_X86_LOCAL_APIC
  146. sum += irq_stats(cpu)->apic_timer_irqs;
  147. #endif
  148. #ifdef CONFIG_SMP
  149. sum += irq_stats(cpu)->irq_resched_count;
  150. sum += irq_stats(cpu)->irq_call_count;
  151. sum += irq_stats(cpu)->irq_tlb_count;
  152. #endif
  153. #ifdef CONFIG_X86_MCE
  154. sum += irq_stats(cpu)->irq_thermal_count;
  155. # ifdef CONFIG_X86_64
  156. sum += irq_stats(cpu)->irq_threshold_count;
  157. #endif
  158. #endif
  159. #ifdef CONFIG_X86_LOCAL_APIC
  160. sum += irq_stats(cpu)->irq_spurious_count;
  161. #endif
  162. return sum;
  163. }
  164. u64 arch_irq_stat(void)
  165. {
  166. u64 sum = atomic_read(&irq_err_count);
  167. #ifdef CONFIG_X86_IO_APIC
  168. sum += atomic_read(&irq_mis_count);
  169. #endif
  170. return sum;
  171. }