numa_migrate.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * NUMA irq-desc migration code
  3. *
  4. * Migrate IRQ data structures (irq_desc, chip_data, etc.) over to
  5. * the new "home node" of the IRQ.
  6. */
  7. #include <linux/irq.h>
  8. #include <linux/module.h>
  9. #include <linux/random.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/kernel_stat.h>
  12. #include "internals.h"
  13. static void init_copy_kstat_irqs(struct irq_desc *old_desc,
  14. struct irq_desc *desc,
  15. int cpu, int nr)
  16. {
  17. init_kstat_irqs(desc, cpu, nr);
  18. if (desc->kstat_irqs != old_desc->kstat_irqs)
  19. memcpy(desc->kstat_irqs, old_desc->kstat_irqs,
  20. nr * sizeof(*desc->kstat_irqs));
  21. }
  22. static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
  23. {
  24. if (old_desc->kstat_irqs == desc->kstat_irqs)
  25. return;
  26. kfree(old_desc->kstat_irqs);
  27. old_desc->kstat_irqs = NULL;
  28. }
  29. static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
  30. struct irq_desc *desc, int cpu)
  31. {
  32. memcpy(desc, old_desc, sizeof(struct irq_desc));
  33. if (!init_alloc_desc_masks(desc, cpu, false)) {
  34. printk(KERN_ERR "irq %d: can not get new irq_desc cpumask "
  35. "for migration.\n", irq);
  36. return false;
  37. }
  38. spin_lock_init(&desc->lock);
  39. desc->cpu = cpu;
  40. lockdep_set_class(&desc->lock, &irq_desc_lock_class);
  41. init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
  42. init_copy_desc_masks(old_desc, desc);
  43. arch_init_copy_chip_data(old_desc, desc, cpu);
  44. return true;
  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. free_desc_masks(old_desc, desc);
  50. arch_free_chip_data(old_desc, desc);
  51. }
  52. static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
  53. int cpu)
  54. {
  55. struct irq_desc *desc;
  56. unsigned int irq;
  57. unsigned long flags;
  58. int node;
  59. irq = old_desc->irq;
  60. spin_lock_irqsave(&sparse_irq_lock, flags);
  61. /* We have to check it to avoid races with another CPU */
  62. desc = irq_desc_ptrs[irq];
  63. if (desc && old_desc != desc)
  64. goto out_unlock;
  65. node = cpu_to_node(cpu);
  66. desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
  67. if (!desc) {
  68. printk(KERN_ERR "irq %d: can not get new irq_desc "
  69. "for migration.\n", irq);
  70. /* still use old one */
  71. desc = old_desc;
  72. goto out_unlock;
  73. }
  74. if (!init_copy_one_irq_desc(irq, old_desc, desc, cpu)) {
  75. /* still use old one */
  76. kfree(desc);
  77. desc = old_desc;
  78. goto out_unlock;
  79. }
  80. irq_desc_ptrs[irq] = desc;
  81. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  82. /* free the old one */
  83. free_one_irq_desc(old_desc, desc);
  84. spin_unlock(&old_desc->lock);
  85. kfree(old_desc);
  86. spin_lock(&desc->lock);
  87. return desc;
  88. out_unlock:
  89. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  90. return desc;
  91. }
  92. struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
  93. {
  94. int old_cpu;
  95. int node, old_node;
  96. /* those all static, do move them */
  97. if (desc->irq < NR_IRQS_LEGACY)
  98. return desc;
  99. old_cpu = desc->cpu;
  100. if (old_cpu != cpu) {
  101. node = cpu_to_node(cpu);
  102. old_node = cpu_to_node(old_cpu);
  103. if (old_node != node)
  104. desc = __real_move_irq_desc(desc, cpu);
  105. else
  106. desc->cpu = cpu;
  107. }
  108. return desc;
  109. }