irq_64.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. struct irq_desc *desc = irq_to_desc(i);
  78. spin_lock_irqsave(&desc->lock, flags);
  79. #ifndef CONFIG_SMP
  80. any_count = kstat_irqs(i);
  81. #else
  82. for_each_online_cpu(j)
  83. any_count |= kstat_irqs_cpu(i, j);
  84. #endif
  85. action = desc->action;
  86. if (!action && !any_count)
  87. goto skip;
  88. seq_printf(p, "%3d: ",i);
  89. #ifndef CONFIG_SMP
  90. seq_printf(p, "%10u ", kstat_irqs(i));
  91. #else
  92. for_each_online_cpu(j)
  93. seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
  94. #endif
  95. seq_printf(p, " %8s", desc->chip->name);
  96. seq_printf(p, "-%-8s", desc->name);
  97. if (action) {
  98. seq_printf(p, " %s", action->name);
  99. while ((action = action->next) != NULL)
  100. seq_printf(p, ", %s", action->name);
  101. }
  102. seq_putc(p, '\n');
  103. skip:
  104. spin_unlock_irqrestore(&desc->lock, flags);
  105. } else if (i == nr_irqs) {
  106. seq_printf(p, "NMI: ");
  107. for_each_online_cpu(j)
  108. seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
  109. seq_printf(p, " Non-maskable interrupts\n");
  110. seq_printf(p, "LOC: ");
  111. for_each_online_cpu(j)
  112. seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
  113. seq_printf(p, " Local timer interrupts\n");
  114. #ifdef CONFIG_SMP
  115. seq_printf(p, "RES: ");
  116. for_each_online_cpu(j)
  117. seq_printf(p, "%10u ", cpu_pda(j)->irq_resched_count);
  118. seq_printf(p, " Rescheduling interrupts\n");
  119. seq_printf(p, "CAL: ");
  120. for_each_online_cpu(j)
  121. seq_printf(p, "%10u ", cpu_pda(j)->irq_call_count);
  122. seq_printf(p, " Function call interrupts\n");
  123. seq_printf(p, "TLB: ");
  124. for_each_online_cpu(j)
  125. seq_printf(p, "%10u ", cpu_pda(j)->irq_tlb_count);
  126. seq_printf(p, " TLB shootdowns\n");
  127. #endif
  128. #ifdef CONFIG_X86_MCE
  129. seq_printf(p, "TRM: ");
  130. for_each_online_cpu(j)
  131. seq_printf(p, "%10u ", cpu_pda(j)->irq_thermal_count);
  132. seq_printf(p, " Thermal event interrupts\n");
  133. seq_printf(p, "THR: ");
  134. for_each_online_cpu(j)
  135. seq_printf(p, "%10u ", cpu_pda(j)->irq_threshold_count);
  136. seq_printf(p, " Threshold APIC interrupts\n");
  137. #endif
  138. seq_printf(p, "SPU: ");
  139. for_each_online_cpu(j)
  140. seq_printf(p, "%10u ", cpu_pda(j)->irq_spurious_count);
  141. seq_printf(p, " Spurious interrupts\n");
  142. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  143. }
  144. return 0;
  145. }
  146. /*
  147. * /proc/stat helpers
  148. */
  149. u64 arch_irq_stat_cpu(unsigned int cpu)
  150. {
  151. u64 sum = cpu_pda(cpu)->__nmi_count;
  152. sum += cpu_pda(cpu)->apic_timer_irqs;
  153. #ifdef CONFIG_SMP
  154. sum += cpu_pda(cpu)->irq_resched_count;
  155. sum += cpu_pda(cpu)->irq_call_count;
  156. sum += cpu_pda(cpu)->irq_tlb_count;
  157. #endif
  158. #ifdef CONFIG_X86_MCE
  159. sum += cpu_pda(cpu)->irq_thermal_count;
  160. sum += cpu_pda(cpu)->irq_threshold_count;
  161. #endif
  162. sum += cpu_pda(cpu)->irq_spurious_count;
  163. return sum;
  164. }
  165. u64 arch_irq_stat(void)
  166. {
  167. return atomic_read(&irq_err_count);
  168. }
  169. /*
  170. * do_IRQ handles all normal device IRQ's (the special
  171. * SMP cross-CPU interrupts have their own specific
  172. * handlers).
  173. */
  174. asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
  175. {
  176. struct pt_regs *old_regs = set_irq_regs(regs);
  177. /* high bit used in ret_from_ code */
  178. unsigned vector = ~regs->orig_ax;
  179. unsigned irq;
  180. exit_idle();
  181. irq_enter();
  182. irq = __get_cpu_var(vector_irq)[vector];
  183. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  184. stack_overflow_check(regs);
  185. #endif
  186. if (likely(irq < nr_irqs))
  187. generic_handle_irq(irq);
  188. else {
  189. if (!disable_apic)
  190. ack_APIC_irq();
  191. if (printk_ratelimit())
  192. printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
  193. __func__, smp_processor_id(), vector);
  194. }
  195. irq_exit();
  196. set_irq_regs(old_regs);
  197. return 1;
  198. }
  199. #ifdef CONFIG_HOTPLUG_CPU
  200. void fixup_irqs(cpumask_t map)
  201. {
  202. unsigned int irq;
  203. static int warned;
  204. for (irq = 0; irq < nr_irqs; irq++) {
  205. cpumask_t mask;
  206. int break_affinity = 0;
  207. int set_affinity = 1;
  208. struct irq_desc *desc;
  209. if (irq == 2)
  210. continue;
  211. desc = irq_to_desc(irq);
  212. /* interrupt's are disabled at this point */
  213. spin_lock(&desc->lock);
  214. if (!irq_has_action(irq) ||
  215. cpus_equal(desc->affinity, map)) {
  216. spin_unlock(&desc->lock);
  217. continue;
  218. }
  219. cpus_and(mask, desc->affinity, map);
  220. if (cpus_empty(mask)) {
  221. break_affinity = 1;
  222. mask = map;
  223. }
  224. if (desc->chip->mask)
  225. desc->chip->mask(irq);
  226. if (desc->chip->set_affinity)
  227. desc->chip->set_affinity(irq, mask);
  228. else if (!(warned++))
  229. set_affinity = 0;
  230. if (desc->chip->unmask)
  231. desc->chip->unmask(irq);
  232. spin_unlock(&desc->lock);
  233. if (break_affinity && set_affinity)
  234. printk("Broke affinity for irq %i\n", irq);
  235. else if (!set_affinity)
  236. printk("Cannot set affinity for irq %i\n", irq);
  237. }
  238. /* That doesn't seem sufficient. Give it 1ms. */
  239. local_irq_enable();
  240. mdelay(1);
  241. local_irq_disable();
  242. }
  243. #endif
  244. extern void call_softirq(void);
  245. asmlinkage void do_softirq(void)
  246. {
  247. __u32 pending;
  248. unsigned long flags;
  249. if (in_interrupt())
  250. return;
  251. local_irq_save(flags);
  252. pending = local_softirq_pending();
  253. /* Switch to interrupt stack */
  254. if (pending) {
  255. call_softirq();
  256. WARN_ON_ONCE(softirq_count());
  257. }
  258. local_irq_restore(flags);
  259. }