numa_migrate.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. 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. if (!desc) {
  67. printk(KERN_ERR "irq %d: can not get new irq_desc "
  68. "for migration.\n", irq);
  69. /* still use old one */
  70. desc = old_desc;
  71. goto out_unlock;
  72. }
  73. if (!init_copy_one_irq_desc(irq, old_desc, desc, cpu)) {
  74. /* still use old one */
  75. kfree(desc);
  76. desc = old_desc;
  77. goto out_unlock;
  78. }
  79. irq_desc_ptrs[irq] = desc;
  80. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  81. /* free the old one */
  82. free_one_irq_desc(old_desc, desc);
  83. spin_unlock(&old_desc->lock);
  84. kfree(old_desc);
  85. spin_lock(&desc->lock);
  86. return desc;
  87. out_unlock:
  88. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  89. return desc;
  90. }
  91. struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
  92. {
  93. int old_cpu;
  94. int node, old_node;
  95. /* those all static, do move them */
  96. if (desc->irq < NR_IRQS_LEGACY)
  97. return desc;
  98. old_cpu = desc->cpu;
  99. if (old_cpu != cpu) {
  100. node = cpu_to_node(cpu);
  101. old_node = cpu_to_node(old_cpu);
  102. if (old_node != node)
  103. desc = __real_move_irq_desc(desc, cpu);
  104. else
  105. desc->cpu = cpu;
  106. }
  107. return desc;
  108. }