numa_migrate.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/kernel/irq/handle.c
  3. *
  4. * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
  5. * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
  6. *
  7. * This file contains the core interrupt handling code.
  8. *
  9. * Detailed information is available in Documentation/DocBook/genericirq
  10. *
  11. */
  12. #include <linux/irq.h>
  13. #include <linux/module.h>
  14. #include <linux/random.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel_stat.h>
  17. #include "internals.h"
  18. static void init_copy_kstat_irqs(struct irq_desc *old_desc,
  19. struct irq_desc *desc,
  20. int cpu, int nr)
  21. {
  22. unsigned long bytes;
  23. init_kstat_irqs(desc, cpu, nr);
  24. if (desc->kstat_irqs != old_desc->kstat_irqs) {
  25. /* Compute how many bytes we need per irq and allocate them */
  26. bytes = nr * sizeof(unsigned int);
  27. memcpy(desc->kstat_irqs, old_desc->kstat_irqs, bytes);
  28. }
  29. }
  30. static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
  31. {
  32. if (old_desc->kstat_irqs == desc->kstat_irqs)
  33. return;
  34. kfree(old_desc->kstat_irqs);
  35. old_desc->kstat_irqs = NULL;
  36. }
  37. static void init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
  38. struct irq_desc *desc, int cpu)
  39. {
  40. memcpy(desc, old_desc, sizeof(struct irq_desc));
  41. desc->cpu = cpu;
  42. lockdep_set_class(&desc->lock, &irq_desc_lock_class);
  43. init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
  44. arch_init_copy_chip_data(old_desc, desc, cpu);
  45. }
  46. static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
  47. {
  48. free_kstat_irqs(old_desc, desc);
  49. arch_free_chip_data(old_desc, desc);
  50. }
  51. static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
  52. int cpu)
  53. {
  54. struct irq_desc *desc;
  55. unsigned int irq;
  56. unsigned long flags;
  57. int node;
  58. irq = old_desc->irq;
  59. spin_lock_irqsave(&sparse_irq_lock, flags);
  60. /* We have to check it to avoid races with another CPU */
  61. desc = irq_desc_ptrs[irq];
  62. if (desc && old_desc != desc)
  63. goto out_unlock;
  64. node = cpu_to_node(cpu);
  65. desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
  66. printk(KERN_DEBUG " move irq_desc for %d to cpu %d node %d\n",
  67. irq, cpu, node);
  68. if (!desc) {
  69. printk(KERN_ERR "can not get new irq_desc for moving\n");
  70. /* still use old one */
  71. desc = old_desc;
  72. goto out_unlock;
  73. }
  74. init_copy_one_irq_desc(irq, old_desc, desc, cpu);
  75. irq_desc_ptrs[irq] = desc;
  76. /* free the old one */
  77. free_one_irq_desc(old_desc, desc);
  78. kfree(old_desc);
  79. out_unlock:
  80. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  81. return desc;
  82. }
  83. struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
  84. {
  85. int old_cpu;
  86. int node, old_node;
  87. /* those all static, do move them */
  88. if (desc->irq < NR_IRQS_LEGACY)
  89. return desc;
  90. old_cpu = desc->cpu;
  91. printk(KERN_DEBUG
  92. "try to move irq_desc from cpu %d to %d\n", old_cpu, cpu);
  93. if (old_cpu != cpu) {
  94. node = cpu_to_node(cpu);
  95. old_node = cpu_to_node(old_cpu);
  96. if (old_node != node)
  97. desc = __real_move_irq_desc(desc, cpu);
  98. else
  99. desc->cpu = cpu;
  100. }
  101. return desc;
  102. }