irq_64.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  21. /*
  22. * Probabilistic stack overflow check:
  23. *
  24. * Only check the stack in process context, because everything else
  25. * runs on the big interrupt stacks. Checking reliably is too expensive,
  26. * so we just check from interrupts.
  27. */
  28. static inline void stack_overflow_check(struct pt_regs *regs)
  29. {
  30. u64 curbase = (u64)task_stack_page(current);
  31. static unsigned long warned = -60*HZ;
  32. if (regs->rsp >= curbase && regs->rsp <= curbase + THREAD_SIZE &&
  33. regs->rsp < curbase + sizeof(struct thread_info) + 128 &&
  34. time_after(jiffies, warned + 60*HZ)) {
  35. printk("do_IRQ: %s near stack overflow (cur:%Lx,rsp:%lx)\n",
  36. current->comm, curbase, regs->rsp);
  37. show_stack(NULL,NULL);
  38. warned = jiffies;
  39. }
  40. }
  41. #endif
  42. /*
  43. * Generic, controller-independent functions:
  44. */
  45. int show_interrupts(struct seq_file *p, void *v)
  46. {
  47. int i = *(loff_t *) v, j;
  48. struct irqaction * action;
  49. unsigned long flags;
  50. if (i == 0) {
  51. seq_printf(p, " ");
  52. for_each_online_cpu(j)
  53. seq_printf(p, "CPU%-8d",j);
  54. seq_putc(p, '\n');
  55. }
  56. if (i < NR_IRQS) {
  57. unsigned any_count = 0;
  58. spin_lock_irqsave(&irq_desc[i].lock, flags);
  59. #ifndef CONFIG_SMP
  60. any_count = kstat_irqs(i);
  61. #else
  62. for_each_online_cpu(j)
  63. any_count |= kstat_cpu(j).irqs[i];
  64. #endif
  65. action = irq_desc[i].action;
  66. if (!action && !any_count)
  67. goto skip;
  68. seq_printf(p, "%3d: ",i);
  69. #ifndef CONFIG_SMP
  70. seq_printf(p, "%10u ", kstat_irqs(i));
  71. #else
  72. for_each_online_cpu(j)
  73. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  74. #endif
  75. seq_printf(p, " %8s", irq_desc[i].chip->name);
  76. seq_printf(p, "-%-8s", irq_desc[i].name);
  77. if (action) {
  78. seq_printf(p, " %s", action->name);
  79. while ((action = action->next) != NULL)
  80. seq_printf(p, ", %s", action->name);
  81. }
  82. seq_putc(p, '\n');
  83. skip:
  84. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  85. } else if (i == NR_IRQS) {
  86. seq_printf(p, "NMI: ");
  87. for_each_online_cpu(j)
  88. seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
  89. seq_printf(p, " Non-maskable interrupts\n");
  90. seq_printf(p, "LOC: ");
  91. for_each_online_cpu(j)
  92. seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
  93. seq_printf(p, " Local timer interrupts\n");
  94. #ifdef CONFIG_SMP
  95. seq_printf(p, "RES: ");
  96. for_each_online_cpu(j)
  97. seq_printf(p, "%10u ", cpu_pda(j)->irq_resched_count);
  98. seq_printf(p, " Rescheduling interrupts\n");
  99. seq_printf(p, "CAL: ");
  100. for_each_online_cpu(j)
  101. seq_printf(p, "%10u ", cpu_pda(j)->irq_call_count);
  102. seq_printf(p, " function call interrupts\n");
  103. seq_printf(p, "TLB: ");
  104. for_each_online_cpu(j)
  105. seq_printf(p, "%10u ", cpu_pda(j)->irq_tlb_count);
  106. seq_printf(p, " TLB shootdowns\n");
  107. #endif
  108. seq_printf(p, "TRM: ");
  109. for_each_online_cpu(j)
  110. seq_printf(p, "%10u ", cpu_pda(j)->irq_thermal_count);
  111. seq_printf(p, " Thermal event interrupts\n");
  112. seq_printf(p, "THR: ");
  113. for_each_online_cpu(j)
  114. seq_printf(p, "%10u ", cpu_pda(j)->irq_threshold_count);
  115. seq_printf(p, " Threshold APIC interrupts\n");
  116. seq_printf(p, "SPU: ");
  117. for_each_online_cpu(j)
  118. seq_printf(p, "%10u ", cpu_pda(j)->irq_spurious_count);
  119. seq_printf(p, " Spurious interrupts\n");
  120. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  121. }
  122. return 0;
  123. }
  124. /*
  125. * do_IRQ handles all normal device IRQ's (the special
  126. * SMP cross-CPU interrupts have their own specific
  127. * handlers).
  128. */
  129. asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
  130. {
  131. struct pt_regs *old_regs = set_irq_regs(regs);
  132. /* high bit used in ret_from_ code */
  133. unsigned vector = ~regs->orig_rax;
  134. unsigned irq;
  135. exit_idle();
  136. irq_enter();
  137. irq = __get_cpu_var(vector_irq)[vector];
  138. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  139. stack_overflow_check(regs);
  140. #endif
  141. if (likely(irq < NR_IRQS))
  142. generic_handle_irq(irq);
  143. else {
  144. if (!disable_apic)
  145. ack_APIC_irq();
  146. if (printk_ratelimit())
  147. printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
  148. __func__, smp_processor_id(), vector);
  149. }
  150. irq_exit();
  151. set_irq_regs(old_regs);
  152. return 1;
  153. }
  154. #ifdef CONFIG_HOTPLUG_CPU
  155. void fixup_irqs(cpumask_t map)
  156. {
  157. unsigned int irq;
  158. static int warned;
  159. for (irq = 0; irq < NR_IRQS; irq++) {
  160. cpumask_t mask;
  161. int break_affinity = 0;
  162. int set_affinity = 1;
  163. if (irq == 2)
  164. continue;
  165. /* interrupt's are disabled at this point */
  166. spin_lock(&irq_desc[irq].lock);
  167. if (!irq_has_action(irq) ||
  168. cpus_equal(irq_desc[irq].affinity, map)) {
  169. spin_unlock(&irq_desc[irq].lock);
  170. continue;
  171. }
  172. cpus_and(mask, irq_desc[irq].affinity, map);
  173. if (cpus_empty(mask)) {
  174. break_affinity = 1;
  175. mask = map;
  176. }
  177. if (irq_desc[irq].chip->mask)
  178. irq_desc[irq].chip->mask(irq);
  179. if (irq_desc[irq].chip->set_affinity)
  180. irq_desc[irq].chip->set_affinity(irq, mask);
  181. else if (!(warned++))
  182. set_affinity = 0;
  183. if (irq_desc[irq].chip->unmask)
  184. irq_desc[irq].chip->unmask(irq);
  185. spin_unlock(&irq_desc[irq].lock);
  186. if (break_affinity && set_affinity)
  187. printk("Broke affinity for irq %i\n", irq);
  188. else if (!set_affinity)
  189. printk("Cannot set affinity for irq %i\n", irq);
  190. }
  191. /* That doesn't seem sufficient. Give it 1ms. */
  192. local_irq_enable();
  193. mdelay(1);
  194. local_irq_disable();
  195. }
  196. #endif
  197. extern void call_softirq(void);
  198. asmlinkage void do_softirq(void)
  199. {
  200. __u32 pending;
  201. unsigned long flags;
  202. if (in_interrupt())
  203. return;
  204. local_irq_save(flags);
  205. pending = local_softirq_pending();
  206. /* Switch to interrupt stack */
  207. if (pending) {
  208. call_softirq();
  209. WARN_ON_ONCE(softirq_count());
  210. }
  211. local_irq_restore(flags);
  212. }