irq_64.c 7.1 KB

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