Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 1 | /* |
Yinghai Lu | b909895 | 2008-12-19 13:48:34 -0800 | [diff] [blame] | 2 | * NUMA irq-desc migration code |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 3 | * |
Yinghai Lu | b909895 | 2008-12-19 13:48:34 -0800 | [diff] [blame] | 4 | * Migrate IRQ data structures (irq_desc, chip_data, etc.) over to |
| 5 | * the new "home node" of the IRQ. |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/irq.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/random.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/kernel_stat.h> |
| 13 | |
| 14 | #include "internals.h" |
| 15 | |
| 16 | static void init_copy_kstat_irqs(struct irq_desc *old_desc, |
| 17 | struct irq_desc *desc, |
| 18 | int cpu, int nr) |
| 19 | { |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 20 | init_kstat_irqs(desc, cpu, nr); |
| 21 | |
Yinghai Lu | 005bf0e6 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 22 | if (desc->kstat_irqs != old_desc->kstat_irqs) |
| 23 | memcpy(desc->kstat_irqs, old_desc->kstat_irqs, |
| 24 | nr * sizeof(*desc->kstat_irqs)); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc) |
| 28 | { |
| 29 | if (old_desc->kstat_irqs == desc->kstat_irqs) |
| 30 | return; |
| 31 | |
| 32 | kfree(old_desc->kstat_irqs); |
| 33 | old_desc->kstat_irqs = NULL; |
| 34 | } |
| 35 | |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 36 | static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc, |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 37 | struct irq_desc *desc, int cpu) |
| 38 | { |
| 39 | memcpy(desc, old_desc, sizeof(struct irq_desc)); |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 40 | if (!init_alloc_desc_masks(desc, cpu, false)) { |
| 41 | printk(KERN_ERR "irq %d: can not get new irq_desc cpumask " |
| 42 | "for migration.\n", irq); |
| 43 | return false; |
| 44 | } |
Ingo Molnar | 793f7b1 | 2008-12-26 19:02:20 +0100 | [diff] [blame] | 45 | spin_lock_init(&desc->lock); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 46 | desc->cpu = cpu; |
| 47 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
| 48 | init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids); |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 49 | init_copy_desc_masks(old_desc, desc); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 50 | arch_init_copy_chip_data(old_desc, desc, cpu); |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 51 | return true; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc) |
| 55 | { |
| 56 | free_kstat_irqs(old_desc, desc); |
Yinghai Lu | 9756b15 | 2009-03-30 20:37:20 -0700 | [diff] [blame] | 57 | free_desc_masks(old_desc, desc); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 58 | arch_free_chip_data(old_desc, desc); |
| 59 | } |
| 60 | |
| 61 | static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc, |
| 62 | int cpu) |
| 63 | { |
| 64 | struct irq_desc *desc; |
| 65 | unsigned int irq; |
| 66 | unsigned long flags; |
| 67 | int node; |
| 68 | |
| 69 | irq = old_desc->irq; |
| 70 | |
| 71 | spin_lock_irqsave(&sparse_irq_lock, flags); |
| 72 | |
| 73 | /* We have to check it to avoid races with another CPU */ |
| 74 | desc = irq_desc_ptrs[irq]; |
| 75 | |
| 76 | if (desc && old_desc != desc) |
Yinghai Lu | 10b888d | 2009-01-31 14:50:07 -0800 | [diff] [blame] | 77 | goto out_unlock; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 78 | |
| 79 | node = cpu_to_node(cpu); |
| 80 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 81 | if (!desc) { |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 82 | printk(KERN_ERR "irq %d: can not get new irq_desc " |
| 83 | "for migration.\n", irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 84 | /* still use old one */ |
| 85 | desc = old_desc; |
| 86 | goto out_unlock; |
| 87 | } |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 88 | if (!init_copy_one_irq_desc(irq, old_desc, desc, cpu)) { |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 89 | /* still use old one */ |
| 90 | kfree(desc); |
| 91 | desc = old_desc; |
| 92 | goto out_unlock; |
| 93 | } |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 94 | |
| 95 | irq_desc_ptrs[irq] = desc; |
Yinghai Lu | 10b888d | 2009-01-31 14:50:07 -0800 | [diff] [blame] | 96 | spin_unlock_irqrestore(&sparse_irq_lock, flags); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 97 | |
| 98 | /* free the old one */ |
| 99 | free_one_irq_desc(old_desc, desc); |
Yinghai Lu | 10b888d | 2009-01-31 14:50:07 -0800 | [diff] [blame] | 100 | spin_unlock(&old_desc->lock); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 101 | kfree(old_desc); |
Yinghai Lu | 10b888d | 2009-01-31 14:50:07 -0800 | [diff] [blame] | 102 | spin_lock(&desc->lock); |
| 103 | |
| 104 | return desc; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 105 | |
| 106 | out_unlock: |
| 107 | spin_unlock_irqrestore(&sparse_irq_lock, flags); |
| 108 | |
| 109 | return desc; |
| 110 | } |
| 111 | |
| 112 | struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu) |
| 113 | { |
| 114 | int old_cpu; |
| 115 | int node, old_node; |
| 116 | |
| 117 | /* those all static, do move them */ |
| 118 | if (desc->irq < NR_IRQS_LEGACY) |
| 119 | return desc; |
| 120 | |
| 121 | old_cpu = desc->cpu; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 122 | if (old_cpu != cpu) { |
| 123 | node = cpu_to_node(cpu); |
| 124 | old_node = cpu_to_node(old_cpu); |
| 125 | if (old_node != node) |
| 126 | desc = __real_move_irq_desc(desc, cpu); |
| 127 | else |
| 128 | desc->cpu = cpu; |
| 129 | } |
| 130 | |
| 131 | return desc; |
| 132 | } |
| 133 | |