numa_migrate.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 void 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. spin_lock_init(&desc->lock);
  37. desc->cpu = cpu;
  38. lockdep_set_class(&desc->lock, &irq_desc_lock_class);
  39. init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
  40. arch_init_copy_chip_data(old_desc, desc, cpu);
  41. }
  42. static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
  43. {
  44. free_kstat_irqs(old_desc, desc);
  45. arch_free_chip_data(old_desc, desc);
  46. }
  47. static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
  48. int cpu)
  49. {
  50. struct irq_desc *desc;
  51. unsigned int irq;
  52. unsigned long flags;
  53. int node;
  54. irq = old_desc->irq;
  55. spin_lock_irqsave(&sparse_irq_lock, flags);
  56. /* We have to check it to avoid races with another CPU */
  57. desc = irq_desc_ptrs[irq];
  58. if (desc && old_desc != desc)
  59. goto out_unlock;
  60. node = cpu_to_node(cpu);
  61. desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
  62. if (!desc) {
  63. printk(KERN_ERR "irq %d: can not get new irq_desc for migration.\n", irq);
  64. /* still use old one */
  65. desc = old_desc;
  66. goto out_unlock;
  67. }
  68. init_copy_one_irq_desc(irq, old_desc, desc, cpu);
  69. irq_desc_ptrs[irq] = desc;
  70. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  71. /* free the old one */
  72. free_one_irq_desc(old_desc, desc);
  73. spin_unlock(&old_desc->lock);
  74. kfree(old_desc);
  75. spin_lock(&desc->lock);
  76. return desc;
  77. out_unlock:
  78. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  79. return desc;
  80. }
  81. struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
  82. {
  83. int old_cpu;
  84. int node, old_node;
  85. /* those all static, do move them */
  86. if (desc->irq < NR_IRQS_LEGACY)
  87. return desc;
  88. old_cpu = desc->cpu;
  89. if (old_cpu != cpu) {
  90. node = cpu_to_node(cpu);
  91. old_node = cpu_to_node(old_cpu);
  92. if (old_node != node)
  93. desc = __real_move_irq_desc(desc, cpu);
  94. else
  95. desc->cpu = cpu;
  96. }
  97. return desc;
  98. }