irq_64.c 7.2 KB

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