irq_64.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. spin_lock_irqsave(&irq_desc[i].lock, flags);
  58. action = irq_desc[i].action;
  59. if (!action)
  60. goto skip;
  61. seq_printf(p, "%3d: ",i);
  62. #ifndef CONFIG_SMP
  63. seq_printf(p, "%10u ", kstat_irqs(i));
  64. #else
  65. for_each_online_cpu(j)
  66. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  67. #endif
  68. seq_printf(p, " %8s", irq_desc[i].chip->name);
  69. seq_printf(p, "-%-8s", irq_desc[i].name);
  70. seq_printf(p, " %s", action->name);
  71. for (action=action->next; action; action = action->next)
  72. seq_printf(p, ", %s", action->name);
  73. seq_putc(p, '\n');
  74. skip:
  75. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  76. } else if (i == NR_IRQS) {
  77. seq_printf(p, "NMI: ");
  78. for_each_online_cpu(j)
  79. seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
  80. seq_printf(p, " Non-maskable interrupts\n");
  81. seq_printf(p, "LOC: ");
  82. for_each_online_cpu(j)
  83. seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
  84. seq_printf(p, " Local timer interrupts\n");
  85. #ifdef CONFIG_SMP
  86. seq_printf(p, "RES: ");
  87. for_each_online_cpu(j)
  88. seq_printf(p, "%10u ", cpu_pda(j)->irq_resched_count);
  89. seq_printf(p, " Rescheduling interrupts\n");
  90. seq_printf(p, "CAL: ");
  91. for_each_online_cpu(j)
  92. seq_printf(p, "%10u ", cpu_pda(j)->irq_call_count);
  93. seq_printf(p, " function call interrupts\n");
  94. seq_printf(p, "TLB: ");
  95. for_each_online_cpu(j)
  96. seq_printf(p, "%10u ", cpu_pda(j)->irq_tlb_count);
  97. seq_printf(p, " TLB shootdowns\n");
  98. #endif
  99. seq_printf(p, "TRM: ");
  100. for_each_online_cpu(j)
  101. seq_printf(p, "%10u ", cpu_pda(j)->irq_thermal_count);
  102. seq_printf(p, " Thermal event interrupts\n");
  103. seq_printf(p, "THR: ");
  104. for_each_online_cpu(j)
  105. seq_printf(p, "%10u ", cpu_pda(j)->irq_threshold_count);
  106. seq_printf(p, " Threshold APIC interrupts\n");
  107. seq_printf(p, "SPU: ");
  108. for_each_online_cpu(j)
  109. seq_printf(p, "%10u ", cpu_pda(j)->irq_spurious_count);
  110. seq_printf(p, " Spurious interrupts\n");
  111. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  112. }
  113. return 0;
  114. }
  115. /*
  116. * do_IRQ handles all normal device IRQ's (the special
  117. * SMP cross-CPU interrupts have their own specific
  118. * handlers).
  119. */
  120. asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
  121. {
  122. struct pt_regs *old_regs = set_irq_regs(regs);
  123. /* high bit used in ret_from_ code */
  124. unsigned vector = ~regs->orig_rax;
  125. unsigned irq;
  126. exit_idle();
  127. irq_enter();
  128. irq = __get_cpu_var(vector_irq)[vector];
  129. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  130. stack_overflow_check(regs);
  131. #endif
  132. if (likely(irq < NR_IRQS))
  133. generic_handle_irq(irq);
  134. else {
  135. if (!disable_apic)
  136. ack_APIC_irq();
  137. if (printk_ratelimit())
  138. printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
  139. __func__, smp_processor_id(), vector);
  140. }
  141. irq_exit();
  142. set_irq_regs(old_regs);
  143. return 1;
  144. }
  145. #ifdef CONFIG_HOTPLUG_CPU
  146. void fixup_irqs(cpumask_t map)
  147. {
  148. unsigned int irq;
  149. static int warned;
  150. for (irq = 0; irq < NR_IRQS; irq++) {
  151. cpumask_t mask;
  152. int break_affinity = 0;
  153. int set_affinity = 1;
  154. if (irq == 2)
  155. continue;
  156. /* interrupt's are disabled at this point */
  157. spin_lock(&irq_desc[irq].lock);
  158. if (!irq_has_action(irq) ||
  159. cpus_equal(irq_desc[irq].affinity, map)) {
  160. spin_unlock(&irq_desc[irq].lock);
  161. continue;
  162. }
  163. cpus_and(mask, irq_desc[irq].affinity, map);
  164. if (cpus_empty(mask)) {
  165. break_affinity = 1;
  166. mask = map;
  167. }
  168. if (irq_desc[irq].chip->mask)
  169. irq_desc[irq].chip->mask(irq);
  170. if (irq_desc[irq].chip->set_affinity)
  171. irq_desc[irq].chip->set_affinity(irq, mask);
  172. else if (!(warned++))
  173. set_affinity = 0;
  174. if (irq_desc[irq].chip->unmask)
  175. irq_desc[irq].chip->unmask(irq);
  176. spin_unlock(&irq_desc[irq].lock);
  177. if (break_affinity && set_affinity)
  178. printk("Broke affinity for irq %i\n", irq);
  179. else if (!set_affinity)
  180. printk("Cannot set affinity for irq %i\n", irq);
  181. }
  182. /* That doesn't seem sufficient. Give it 1ms. */
  183. local_irq_enable();
  184. mdelay(1);
  185. local_irq_disable();
  186. }
  187. #endif
  188. extern void call_softirq(void);
  189. asmlinkage void do_softirq(void)
  190. {
  191. __u32 pending;
  192. unsigned long flags;
  193. if (in_interrupt())
  194. return;
  195. local_irq_save(flags);
  196. pending = local_softirq_pending();
  197. /* Switch to interrupt stack */
  198. if (pending) {
  199. call_softirq();
  200. WARN_ON_ONCE(softirq_count());
  201. }
  202. local_irq_restore(flags);
  203. }