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. unsigned long bytes;
  18. init_kstat_irqs(desc, cpu, nr);
  19. if (desc->kstat_irqs != old_desc->kstat_irqs) {
  20. /* Compute how many bytes we need per irq and allocate them */
  21. bytes = nr * sizeof(unsigned int);
  22. memcpy(desc->kstat_irqs, old_desc->kstat_irqs, bytes);
  23. }
  24. }
  25. static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
  26. {
  27. if (old_desc->kstat_irqs == desc->kstat_irqs)
  28. return;
  29. kfree(old_desc->kstat_irqs);
  30. old_desc->kstat_irqs = NULL;
  31. }
  32. static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
  33. struct irq_desc *desc, int cpu)
  34. {
  35. memcpy(desc, old_desc, sizeof(struct irq_desc));
  36. if (!init_alloc_desc_masks(desc, cpu, false)) {
  37. printk(KERN_ERR "irq %d: can not get new irq_desc cpumask "
  38. "for migration.\n", irq);
  39. return false;
  40. }
  41. spin_lock_init(&desc->lock);
  42. desc->cpu = cpu;
  43. lockdep_set_class(&desc->lock, &irq_desc_lock_class);
  44. init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
  45. init_copy_desc_masks(old_desc, desc);
  46. arch_init_copy_chip_data(old_desc, desc, cpu);
  47. return true;
  48. }
  49. static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
  50. {
  51. free_kstat_irqs(old_desc, desc);
  52. arch_free_chip_data(old_desc, desc);
  53. }
  54. static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
  55. int cpu)
  56. {
  57. struct irq_desc *desc;
  58. unsigned int irq;
  59. unsigned long flags;
  60. int node;
  61. irq = old_desc->irq;
  62. spin_lock_irqsave(&sparse_irq_lock, flags);
  63. /* We have to check it to avoid races with another CPU */
  64. desc = irq_desc_ptrs[irq];
  65. if (desc && old_desc != desc)
  66. goto out_unlock;
  67. node = cpu_to_node(cpu);
  68. desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
  69. if (!desc) {
  70. printk(KERN_ERR "irq %d: can not get new irq_desc "
  71. "for migration.\n", irq);
  72. /* still use old one */
  73. desc = old_desc;
  74. goto out_unlock;
  75. }
  76. if (!init_copy_one_irq_desc(irq, old_desc, desc, cpu)) {
  77. /* still use old one */
  78. kfree(desc);
  79. desc = old_desc;
  80. goto out_unlock;
  81. }
  82. irq_desc_ptrs[irq] = desc;
  83. /* free the old one */
  84. free_one_irq_desc(old_desc, desc);
  85. kfree(old_desc);
  86. out_unlock:
  87. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  88. return desc;
  89. }
  90. struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
  91. {
  92. int old_cpu;
  93. int node, old_node;
  94. /* those all static, do move them */
  95. if (desc->irq < NR_IRQS_LEGACY)
  96. return desc;
  97. old_cpu = desc->cpu;
  98. if (old_cpu != cpu) {
  99. node = cpu_to_node(cpu);
  100. old_node = cpu_to_node(old_cpu);
  101. if (old_node != node)
  102. desc = __real_move_irq_desc(desc, cpu);
  103. else
  104. desc->cpu = cpu;
  105. }
  106. return desc;
  107. }