irq_64.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  3. *
  4. * This file contains the lowest level x86_64-specific interrupt
  5. * entry and irq statistics code. All the remaining irq logic is
  6. * done by the generic kernel/irq/ code and in the
  7. * x86_64-specific irq controller code. (e.g. i8259.c and
  8. * io_apic.c.)
  9. */
  10. #include <linux/kernel_stat.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/seq_file.h>
  13. #include <linux/module.h>
  14. #include <linux/delay.h>
  15. #include <asm/uaccess.h>
  16. #include <asm/io_apic.h>
  17. #include <asm/idle.h>
  18. #include <asm/smp.h>
  19. atomic_t irq_err_count;
  20. /*
  21. * 'what should we do if we get a hw irq event on an illegal vector'.
  22. * each architecture has to answer this themselves.
  23. */
  24. void ack_bad_irq(unsigned int irq)
  25. {
  26. printk(KERN_WARNING "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 don't ack when the APIC is disabled. -AK
  35. */
  36. if (!disable_apic)
  37. ack_APIC_irq();
  38. }
  39. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  40. /*
  41. * Probabilistic stack overflow check:
  42. *
  43. * Only check the stack in process context, because everything else
  44. * runs on the big interrupt stacks. Checking reliably is too expensive,
  45. * so we just check from interrupts.
  46. */
  47. static inline void stack_overflow_check(struct pt_regs *regs)
  48. {
  49. u64 curbase = (u64)task_stack_page(current);
  50. static unsigned long warned = -60*HZ;
  51. if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE &&
  52. regs->sp < curbase + sizeof(struct thread_info) + 128 &&
  53. time_after(jiffies, warned + 60*HZ)) {
  54. printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
  55. current->comm, curbase, regs->sp);
  56. show_stack(NULL,NULL);
  57. warned = jiffies;
  58. }
  59. }
  60. #endif
  61. /*
  62. * Generic, controller-independent functions:
  63. */
  64. int show_interrupts(struct seq_file *p, void *v)
  65. {
  66. int i = *(loff_t *) v, j;
  67. struct irqaction * action;
  68. unsigned long flags;
  69. if (i == 0) {
  70. seq_printf(p, " ");
  71. for_each_online_cpu(j)
  72. seq_printf(p, "CPU%-8d",j);
  73. seq_putc(p, '\n');
  74. }
  75. if (i < NR_IRQS) {
  76. unsigned any_count = 0;
  77. spin_lock_irqsave(&irq_desc[i].lock, flags);
  78. #ifndef CONFIG_SMP
  79. any_count = kstat_irqs(i);
  80. #else
  81. for_each_online_cpu(j)
  82. any_count |= kstat_cpu(j).irqs[i];
  83. #endif
  84. action = irq_desc[i].action;
  85. if (!action && !any_count)
  86. goto skip;
  87. seq_printf(p, "%3d: ",i);
  88. #ifndef CONFIG_SMP
  89. seq_printf(p, "%10u ", kstat_irqs(i));
  90. #else
  91. for_each_online_cpu(j)
  92. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  93. #endif
  94. seq_printf(p, " %8s", irq_desc[i].chip->name);
  95. seq_printf(p, "-%-8s", irq_desc[i].name);
  96. if (action) {
  97. seq_printf(p, " %s", action->name);
  98. while ((action = action->next) != NULL)
  99. seq_printf(p, ", %s", action->name);
  100. }
  101. seq_putc(p, '\n');
  102. skip:
  103. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  104. } else if (i == NR_IRQS) {
  105. seq_printf(p, "NMI: ");
  106. for_each_online_cpu(j)
  107. seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
  108. seq_printf(p, " Non-maskable interrupts\n");
  109. seq_printf(p, "LOC: ");
  110. for_each_online_cpu(j)
  111. seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
  112. seq_printf(p, " Local timer interrupts\n");
  113. #ifdef CONFIG_SMP
  114. seq_printf(p, "RES: ");
  115. for_each_online_cpu(j)
  116. seq_printf(p, "%10u ", cpu_pda(j)->irq_resched_count);
  117. seq_printf(p, " Rescheduling interrupts\n");
  118. seq_printf(p, "CAL: ");
  119. for_each_online_cpu(j)
  120. seq_printf(p, "%10u ", cpu_pda(j)->irq_call_count);
  121. seq_printf(p, " Function call interrupts\n");
  122. seq_printf(p, "TLB: ");
  123. for_each_online_cpu(j)
  124. seq_printf(p, "%10u ", cpu_pda(j)->irq_tlb_count);
  125. seq_printf(p, " TLB shootdowns\n");
  126. #endif
  127. #ifdef CONFIG_X86_MCE
  128. seq_printf(p, "TRM: ");
  129. for_each_online_cpu(j)
  130. seq_printf(p, "%10u ", cpu_pda(j)->irq_thermal_count);
  131. seq_printf(p, " Thermal event interrupts\n");
  132. seq_printf(p, "THR: ");
  133. for_each_online_cpu(j)
  134. seq_printf(p, "%10u ", cpu_pda(j)->irq_threshold_count);
  135. seq_printf(p, " Threshold APIC interrupts\n");
  136. #endif
  137. seq_printf(p, "SPU: ");
  138. for_each_online_cpu(j)
  139. seq_printf(p, "%10u ", cpu_pda(j)->irq_spurious_count);
  140. seq_printf(p, " Spurious interrupts\n");
  141. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  142. }
  143. return 0;
  144. }
  145. /*
  146. * /proc/stat helpers
  147. */
  148. u64 arch_irq_stat_cpu(unsigned int cpu)
  149. {
  150. u64 sum = cpu_pda(cpu)->__nmi_count;
  151. sum += cpu_pda(cpu)->apic_timer_irqs;
  152. #ifdef CONFIG_SMP
  153. sum += cpu_pda(cpu)->irq_resched_count;
  154. sum += cpu_pda(cpu)->irq_call_count;
  155. sum += cpu_pda(cpu)->irq_tlb_count;
  156. #endif
  157. #ifdef CONFIG_X86_MCE
  158. sum += cpu_pda(cpu)->irq_thermal_count;
  159. sum += cpu_pda(cpu)->irq_threshold_count;
  160. #endif
  161. sum += cpu_pda(cpu)->irq_spurious_count;
  162. return sum;
  163. }
  164. u64 arch_irq_stat(void)
  165. {
  166. return atomic_read(&irq_err_count);
  167. }
  168. /*
  169. * do_IRQ handles all normal device IRQ's (the special
  170. * SMP cross-CPU interrupts have their own specific
  171. * handlers).
  172. */
  173. asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
  174. {
  175. struct pt_regs *old_regs = set_irq_regs(regs);
  176. /* high bit used in ret_from_ code */
  177. unsigned vector = ~regs->orig_ax;
  178. unsigned irq;
  179. exit_idle();
  180. irq_enter();
  181. irq = __get_cpu_var(vector_irq)[vector];
  182. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  183. stack_overflow_check(regs);
  184. #endif
  185. if (likely(irq < NR_IRQS))
  186. generic_handle_irq(irq);
  187. else {
  188. if (!disable_apic)
  189. ack_APIC_irq();
  190. if (printk_ratelimit())
  191. printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
  192. __func__, smp_processor_id(), vector);
  193. }
  194. irq_exit();
  195. set_irq_regs(old_regs);
  196. return 1;
  197. }
  198. #ifdef CONFIG_HOTPLUG_CPU
  199. void fixup_irqs(cpumask_t map)
  200. {
  201. unsigned int irq;
  202. static int warned;
  203. for (irq = 0; irq < NR_IRQS; irq++) {
  204. cpumask_t mask;
  205. int break_affinity = 0;
  206. int set_affinity = 1;
  207. if (irq == 2)
  208. continue;
  209. /* interrupt's are disabled at this point */
  210. spin_lock(&irq_desc[irq].lock);
  211. if (!irq_has_action(irq) ||
  212. cpus_equal(irq_desc[irq].affinity, map)) {
  213. spin_unlock(&irq_desc[irq].lock);
  214. continue;
  215. }
  216. cpus_and(mask, irq_desc[irq].affinity, map);
  217. if (cpus_empty(mask)) {
  218. break_affinity = 1;
  219. mask = map;
  220. }
  221. if (irq_desc[irq].chip->mask)
  222. irq_desc[irq].chip->mask(irq);
  223. if (irq_desc[irq].chip->set_affinity)
  224. irq_desc[irq].chip->set_affinity(irq, mask);
  225. else if (!(warned++))
  226. set_affinity = 0;
  227. if (irq_desc[irq].chip->unmask)
  228. irq_desc[irq].chip->unmask(irq);
  229. spin_unlock(&irq_desc[irq].lock);
  230. if (break_affinity && set_affinity)
  231. printk("Broke affinity for irq %i\n", irq);
  232. else if (!set_affinity)
  233. printk("Cannot set affinity for irq %i\n", irq);
  234. }
  235. /* That doesn't seem sufficient. Give it 1ms. */
  236. local_irq_enable();
  237. mdelay(1);
  238. local_irq_disable();
  239. }
  240. #endif
  241. extern void call_softirq(void);
  242. asmlinkage void do_softirq(void)
  243. {
  244. __u32 pending;
  245. unsigned long flags;
  246. if (in_interrupt())
  247. return;
  248. local_irq_save(flags);
  249. pending = local_softirq_pending();
  250. /* Switch to interrupt stack */
  251. if (pending) {
  252. call_softirq();
  253. WARN_ON_ONCE(softirq_count());
  254. }
  255. local_irq_restore(flags);
  256. }