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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/random.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/kernel_stat.h> |
| 14 | |
| 15 | #include "internals.h" |
| 16 | |
| 17 | static void init_copy_kstat_irqs(struct irq_desc *old_desc, |
| 18 | struct irq_desc *desc, |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 19 | int node, int nr) |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 20 | { |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 21 | init_kstat_irqs(desc, node, nr); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 22 | |
Yinghai Lu | 005bf0e6 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 23 | if (desc->kstat_irqs != old_desc->kstat_irqs) |
| 24 | memcpy(desc->kstat_irqs, old_desc->kstat_irqs, |
| 25 | nr * sizeof(*desc->kstat_irqs)); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc) |
| 29 | { |
| 30 | if (old_desc->kstat_irqs == desc->kstat_irqs) |
| 31 | return; |
| 32 | |
| 33 | kfree(old_desc->kstat_irqs); |
| 34 | old_desc->kstat_irqs = NULL; |
| 35 | } |
| 36 | |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 37 | static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc, |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 38 | struct irq_desc *desc, int node) |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 39 | { |
| 40 | memcpy(desc, old_desc, sizeof(struct irq_desc)); |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 41 | if (!alloc_desc_masks(desc, node, false)) { |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 42 | printk(KERN_ERR "irq %d: can not get new irq_desc cpumask " |
| 43 | "for migration.\n", irq); |
| 44 | return false; |
| 45 | } |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 46 | raw_spin_lock_init(&desc->lock); |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 47 | desc->irq_data.node = node; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 48 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 49 | init_copy_kstat_irqs(old_desc, desc, node, nr_cpu_ids); |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 50 | init_copy_desc_masks(old_desc, desc); |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 51 | arch_init_copy_chip_data(old_desc, desc, node); |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 52 | return true; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc) |
| 56 | { |
| 57 | free_kstat_irqs(old_desc, desc); |
Yinghai Lu | 9756b15 | 2009-03-30 20:37:20 -0700 | [diff] [blame] | 58 | free_desc_masks(old_desc, desc); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 59 | arch_free_chip_data(old_desc, desc); |
| 60 | } |
| 61 | |
| 62 | static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc, |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 63 | int node) |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 64 | { |
| 65 | struct irq_desc *desc; |
| 66 | unsigned int irq; |
| 67 | unsigned long flags; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 68 | |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 69 | irq = old_desc->irq_data.irq; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 70 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 71 | raw_spin_lock_irqsave(&sparse_irq_lock, flags); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 72 | |
| 73 | /* We have to check it to avoid races with another CPU */ |
Yinghai Lu | 99558f0 | 2010-02-10 01:20:34 -0800 | [diff] [blame] | 74 | desc = irq_to_desc(irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 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 | |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 79 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 80 | if (!desc) { |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 81 | printk(KERN_ERR "irq %d: can not get new irq_desc " |
| 82 | "for migration.\n", irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 83 | /* still use old one */ |
| 84 | desc = old_desc; |
| 85 | goto out_unlock; |
| 86 | } |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 87 | if (!init_copy_one_irq_desc(irq, old_desc, desc, node)) { |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 88 | /* still use old one */ |
| 89 | kfree(desc); |
| 90 | desc = old_desc; |
| 91 | goto out_unlock; |
| 92 | } |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 93 | |
Yinghai Lu | 99558f0 | 2010-02-10 01:20:34 -0800 | [diff] [blame] | 94 | replace_irq_desc(irq, desc); |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 95 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 96 | |
| 97 | /* free the old one */ |
| 98 | free_one_irq_desc(old_desc, desc); |
| 99 | kfree(old_desc); |
Yinghai Lu | 10b888d | 2009-01-31 14:50:07 -0800 | [diff] [blame] | 100 | |
| 101 | return desc; |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 102 | |
| 103 | out_unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 104 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 105 | |
| 106 | return desc; |
| 107 | } |
| 108 | |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 109 | struct irq_desc *move_irq_desc(struct irq_desc *desc, int node) |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 110 | { |
Yinghai Lu | ad7d6c7 | 2009-08-04 09:01:33 -0700 | [diff] [blame] | 111 | /* those static or target node is -1, do not move them */ |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 112 | if (desc->irq_data.irq < NR_IRQS_LEGACY || node == -1) |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 113 | return desc; |
| 114 | |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 115 | if (desc->irq_data.node != node) |
Yinghai Lu | 85ac16d | 2009-04-27 18:00:38 -0700 | [diff] [blame] | 116 | desc = __real_move_irq_desc(desc, node); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 117 | |
| 118 | return desc; |
| 119 | } |
| 120 | |