numa_migrate.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. /* free the old one */
  71. free_one_irq_desc(old_desc, desc);
  72. kfree(old_desc);
  73. out_unlock:
  74. spin_unlock_irqrestore(&sparse_irq_lock, flags);
  75. return desc;
  76. }
  77. struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
  78. {
  79. int old_cpu;
  80. int node, old_node;
  81. /* those all static, do move them */
  82. if (desc->irq < NR_IRQS_LEGACY)
  83. return desc;
  84. old_cpu = desc->cpu;
  85. if (old_cpu != cpu) {
  86. node = cpu_to_node(cpu);
  87. old_node = cpu_to_node(old_cpu);
  88. if (old_node != node)
  89. desc = __real_move_irq_desc(desc, cpu);
  90. else
  91. desc->cpu = cpu;
  92. }
  93. return desc;
  94. }