PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/x86/kernel/irq.c

https://bitbucket.org/droidzone/supernova-kernel
C | 366 lines | 260 code | 57 blank | 49 comment | 39 complexity | cf231e3ca6955b67140e227df238f215 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 <linux/ftrace.h>
  10. #include <asm/apic.h>
  11. #include <asm/io_apic.h>
  12. #include <asm/irq.h>
  13. #include <asm/idle.h>
  14. #include <asm/mce.h>
  15. #include <asm/hw_irq.h>
  16. atomic_t irq_err_count;
  17. /* Function pointer for generic interrupt vector handling */
  18. void (*x86_platform_ipi_callback)(void) = NULL;
  19. /*
  20. * 'what should we do if we get a hw irq event on an illegal vector'.
  21. * each architecture has to answer this themselves.
  22. */
  23. void ack_bad_irq(unsigned int irq)
  24. {
  25. if (printk_ratelimit())
  26. pr_err("unexpected IRQ trap at vector %02x\n", irq);
  27. /*
  28. * Currently unexpected vectors happen only on SMP and APIC.
  29. * We _must_ ack these because every local APIC has only N
  30. * irq slots per priority level, and a 'hanging, unacked' IRQ
  31. * holds up an irq slot - in excessive cases (when multiple
  32. * unexpected vectors occur) that might lock up the APIC
  33. * completely.
  34. * But only ack when the APIC is enabled -AK
  35. */
  36. ack_APIC_irq();
  37. }
  38. #define irq_stats(x) (&per_cpu(irq_stat, x))
  39. /*
  40. * /proc/interrupts printing:
  41. */
  42. static int show_other_interrupts(struct seq_file *p, int prec)
  43. {
  44. int j;
  45. seq_printf(p, "%*s: ", prec, "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, "%*s: ", prec, "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. seq_printf(p, "%*s: ", prec, "SPU");
  55. for_each_online_cpu(j)
  56. seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
  57. seq_printf(p, " Spurious interrupts\n");
  58. seq_printf(p, "%*s: ", prec, "PMI");
  59. for_each_online_cpu(j)
  60. seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs);
  61. seq_printf(p, " Performance monitoring interrupts\n");
  62. seq_printf(p, "%*s: ", prec, "PND");
  63. for_each_online_cpu(j)
  64. seq_printf(p, "%10u ", irq_stats(j)->apic_pending_irqs);
  65. seq_printf(p, " Performance pending work\n");
  66. #endif
  67. if (x86_platform_ipi_callback) {
  68. seq_printf(p, "%*s: ", prec, "PLT");
  69. for_each_online_cpu(j)
  70. seq_printf(p, "%10u ", irq_stats(j)->x86_platform_ipis);
  71. seq_printf(p, " Platform interrupts\n");
  72. }
  73. #ifdef CONFIG_SMP
  74. seq_printf(p, "%*s: ", prec, "RES");
  75. for_each_online_cpu(j)
  76. seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
  77. seq_printf(p, " Rescheduling interrupts\n");
  78. seq_printf(p, "%*s: ", prec, "CAL");
  79. for_each_online_cpu(j)
  80. seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
  81. seq_printf(p, " Function call interrupts\n");
  82. seq_printf(p, "%*s: ", prec, "TLB");
  83. for_each_online_cpu(j)
  84. seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
  85. seq_printf(p, " TLB shootdowns\n");
  86. #endif
  87. #ifdef CONFIG_X86_THERMAL_VECTOR
  88. seq_printf(p, "%*s: ", prec, "TRM");
  89. for_each_online_cpu(j)
  90. seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
  91. seq_printf(p, " Thermal event interrupts\n");
  92. #endif
  93. #ifdef CONFIG_X86_MCE_THRESHOLD
  94. seq_printf(p, "%*s: ", prec, "THR");
  95. for_each_online_cpu(j)
  96. seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
  97. seq_printf(p, " Threshold APIC interrupts\n");
  98. #endif
  99. #ifdef CONFIG_X86_MCE
  100. seq_printf(p, "%*s: ", prec, "MCE");
  101. for_each_online_cpu(j)
  102. seq_printf(p, "%10u ", per_cpu(mce_exception_count, j));
  103. seq_printf(p, " Machine check exceptions\n");
  104. seq_printf(p, "%*s: ", prec, "MCP");
  105. for_each_online_cpu(j)
  106. seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
  107. seq_printf(p, " Machine check polls\n");
  108. #endif
  109. seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  110. #if defined(CONFIG_X86_IO_APIC)
  111. seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
  112. #endif
  113. return 0;
  114. }
  115. int show_interrupts(struct seq_file *p, void *v)
  116. {
  117. unsigned long flags, any_count = 0;
  118. int i = *(loff_t *) v, j, prec;
  119. struct irqaction *action;
  120. struct irq_desc *desc;
  121. if (i > nr_irqs)
  122. return 0;
  123. for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
  124. j *= 10;
  125. if (i == nr_irqs)
  126. return show_other_interrupts(p, prec);
  127. /* print header */
  128. if (i == 0) {
  129. seq_printf(p, "%*s", prec + 8, "");
  130. for_each_online_cpu(j)
  131. seq_printf(p, "CPU%-8d", j);
  132. seq_putc(p, '\n');
  133. }
  134. desc = irq_to_desc(i);
  135. if (!desc)
  136. return 0;
  137. raw_spin_lock_irqsave(&desc->lock, flags);
  138. for_each_online_cpu(j)
  139. any_count |= kstat_irqs_cpu(i, j);
  140. action = desc->action;
  141. if (!action && !any_count)
  142. goto out;
  143. seq_printf(p, "%*d: ", prec, i);
  144. for_each_online_cpu(j)
  145. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  146. seq_printf(p, " %8s", desc->chip->name);
  147. seq_printf(p, "-%-8s", desc->name);
  148. if (action) {
  149. seq_printf(p, " %s", action->name);
  150. while ((action = action->next) != NULL)
  151. seq_printf(p, ", %s", action->name);
  152. }
  153. seq_putc(p, '\n');
  154. out:
  155. raw_spin_unlock_irqrestore(&desc->lock, flags);
  156. return 0;
  157. }
  158. /*
  159. * /proc/stat helpers
  160. */
  161. u64 arch_irq_stat_cpu(unsigned int cpu)
  162. {
  163. u64 sum = irq_stats(cpu)->__nmi_count;
  164. #ifdef CONFIG_X86_LOCAL_APIC
  165. sum += irq_stats(cpu)->apic_timer_irqs;
  166. sum += irq_stats(cpu)->irq_spurious_count;
  167. sum += irq_stats(cpu)->apic_perf_irqs;
  168. sum += irq_stats(cpu)->apic_pending_irqs;
  169. #endif
  170. if (x86_platform_ipi_callback)
  171. sum += irq_stats(cpu)->x86_platform_ipis;
  172. #ifdef CONFIG_SMP
  173. sum += irq_stats(cpu)->irq_resched_count;
  174. sum += irq_stats(cpu)->irq_call_count;
  175. sum += irq_stats(cpu)->irq_tlb_count;
  176. #endif
  177. #ifdef CONFIG_X86_THERMAL_VECTOR
  178. sum += irq_stats(cpu)->irq_thermal_count;
  179. #endif
  180. #ifdef CONFIG_X86_MCE_THRESHOLD
  181. sum += irq_stats(cpu)->irq_threshold_count;
  182. #endif
  183. #ifdef CONFIG_X86_MCE
  184. sum += per_cpu(mce_exception_count, cpu);
  185. sum += per_cpu(mce_poll_count, cpu);
  186. #endif
  187. return sum;
  188. }
  189. u64 arch_irq_stat(void)
  190. {
  191. u64 sum = atomic_read(&irq_err_count);
  192. #ifdef CONFIG_X86_IO_APIC
  193. sum += atomic_read(&irq_mis_count);
  194. #endif
  195. return sum;
  196. }
  197. /*
  198. * do_IRQ handles all normal device IRQ's (the special
  199. * SMP cross-CPU interrupts have their own specific
  200. * handlers).
  201. */
  202. unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
  203. {
  204. struct pt_regs *old_regs = set_irq_regs(regs);
  205. /* high bit used in ret_from_ code */
  206. unsigned vector = ~regs->orig_ax;
  207. unsigned irq;
  208. exit_idle();
  209. irq_enter();
  210. irq = __get_cpu_var(vector_irq)[vector];
  211. if (!handle_irq(irq, regs)) {
  212. ack_APIC_irq();
  213. if (printk_ratelimit())
  214. pr_emerg("%s: %d.%d No irq handler for vector (irq %d)\n",
  215. __func__, smp_processor_id(), vector, irq);
  216. }
  217. irq_exit();
  218. set_irq_regs(old_regs);
  219. return 1;
  220. }
  221. /*
  222. * Handler for X86_PLATFORM_IPI_VECTOR.
  223. */
  224. void smp_x86_platform_ipi(struct pt_regs *regs)
  225. {
  226. struct pt_regs *old_regs = set_irq_regs(regs);
  227. ack_APIC_irq();
  228. exit_idle();
  229. irq_enter();
  230. inc_irq_stat(x86_platform_ipis);
  231. if (x86_platform_ipi_callback)
  232. x86_platform_ipi_callback();
  233. irq_exit();
  234. set_irq_regs(old_regs);
  235. }
  236. EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);
  237. #ifdef CONFIG_HOTPLUG_CPU
  238. /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
  239. void fixup_irqs(void)
  240. {
  241. unsigned int irq, vector;
  242. static int warned;
  243. struct irq_desc *desc;
  244. for_each_irq_desc(irq, desc) {
  245. int break_affinity = 0;
  246. int set_affinity = 1;
  247. const struct cpumask *affinity;
  248. if (!desc)
  249. continue;
  250. if (irq == 2)
  251. continue;
  252. /* interrupt's are disabled at this point */
  253. raw_spin_lock(&desc->lock);
  254. affinity = desc->affinity;
  255. if (!irq_has_action(irq) ||
  256. cpumask_equal(affinity, cpu_online_mask)) {
  257. raw_spin_unlock(&desc->lock);
  258. continue;
  259. }
  260. /*
  261. * Complete the irq move. This cpu is going down and for
  262. * non intr-remapping case, we can't wait till this interrupt
  263. * arrives at this cpu before completing the irq move.
  264. */
  265. irq_force_complete_move(irq);
  266. if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) {
  267. break_affinity = 1;
  268. affinity = cpu_all_mask;
  269. }
  270. if (!(desc->status & IRQ_MOVE_PCNTXT) && desc->chip->mask)
  271. desc->chip->mask(irq);
  272. if (desc->chip->set_affinity)
  273. desc->chip->set_affinity(irq, affinity);
  274. else if (!(warned++))
  275. set_affinity = 0;
  276. if (!(desc->status & IRQ_MOVE_PCNTXT) && desc->chip->unmask)
  277. desc->chip->unmask(irq);
  278. raw_spin_unlock(&desc->lock);
  279. if (break_affinity && set_affinity)
  280. printk("Broke affinity for irq %i\n", irq);
  281. else if (!set_affinity)
  282. printk("Cannot set affinity for irq %i\n", irq);
  283. }
  284. /*
  285. * We can remove mdelay() and then send spuriuous interrupts to
  286. * new cpu targets for all the irqs that were handled previously by
  287. * this cpu. While it works, I have seen spurious interrupt messages
  288. * (nothing wrong but still...).
  289. *
  290. * So for now, retain mdelay(1) and check the IRR and then send those
  291. * interrupts to new targets as this cpu is already offlined...
  292. */
  293. mdelay(1);
  294. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  295. unsigned int irr;
  296. if (__get_cpu_var(vector_irq)[vector] < 0)
  297. continue;
  298. irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
  299. if (irr & (1 << (vector % 32))) {
  300. irq = __get_cpu_var(vector_irq)[vector];
  301. desc = irq_to_desc(irq);
  302. raw_spin_lock(&desc->lock);
  303. if (desc->chip->retrigger)
  304. desc->chip->retrigger(irq);
  305. raw_spin_unlock(&desc->lock);
  306. }
  307. }
  308. }
  309. #endif