irq_64.c 7.3 KB

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