numa_migrate.c 2.7 KB

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