aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/irq/numa_migrate.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/irq/numa_migrate.c')
-rw-r--r--kernel/irq/numa_migrate.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/kernel/irq/numa_migrate.c b/kernel/irq/numa_migrate.c
new file mode 100644
index 000000000000..089c3746358a
--- /dev/null
+++ b/kernel/irq/numa_migrate.c
@@ -0,0 +1,122 @@
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
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
16static void init_copy_kstat_irqs(struct irq_desc *old_desc,
17 struct irq_desc *desc,
18 int cpu, int nr)
19{
20 unsigned long bytes;
21
22 init_kstat_irqs(desc, cpu, nr);
23
24 if (desc->kstat_irqs != old_desc->kstat_irqs) {
25 /* Compute how many bytes we need per irq and allocate them */
26 bytes = nr * sizeof(unsigned int);
27
28 memcpy(desc->kstat_irqs, old_desc->kstat_irqs, bytes);
29 }
30}
31
32static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
33{
34 if (old_desc->kstat_irqs == desc->kstat_irqs)
35 return;
36
37 kfree(old_desc->kstat_irqs);
38 old_desc->kstat_irqs = NULL;
39}
40
41static void init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
42 struct irq_desc *desc, int cpu)
43{
44 memcpy(desc, old_desc, sizeof(struct irq_desc));
45 desc->cpu = cpu;
46 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
47 init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
48 arch_init_copy_chip_data(old_desc, desc, cpu);
49}
50
51static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
52{
53 free_kstat_irqs(old_desc, desc);
54 arch_free_chip_data(old_desc, desc);
55}
56
57static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
58 int cpu)
59{
60 struct irq_desc *desc;
61 unsigned int irq;
62 unsigned long flags;
63 int node;
64
65 irq = old_desc->irq;
66
67 spin_lock_irqsave(&sparse_irq_lock, flags);
68
69 /* We have to check it to avoid races with another CPU */
70 desc = irq_desc_ptrs[irq];
71
72 if (desc && old_desc != desc)
73 goto out_unlock;
74
75 node = cpu_to_node(cpu);
76 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
77 printk(KERN_DEBUG " move irq_desc for %d to cpu %d node %d\n",
78 irq, cpu, node);
79 if (!desc) {
80 printk(KERN_ERR "can not get new irq_desc for moving\n");
81 /* still use old one */
82 desc = old_desc;
83 goto out_unlock;
84 }
85 init_copy_one_irq_desc(irq, old_desc, desc, cpu);
86
87 irq_desc_ptrs[irq] = desc;
88
89 /* free the old one */
90 free_one_irq_desc(old_desc, desc);
91 kfree(old_desc);
92
93out_unlock:
94 spin_unlock_irqrestore(&sparse_irq_lock, flags);
95
96 return desc;
97}
98
99struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
100{
101 int old_cpu;
102 int node, old_node;
103
104 /* those all static, do move them */
105 if (desc->irq < NR_IRQS_LEGACY)
106 return desc;
107
108 old_cpu = desc->cpu;
109 printk(KERN_DEBUG
110 "try to move irq_desc from cpu %d to %d\n", old_cpu, cpu);
111 if (old_cpu != cpu) {
112 node = cpu_to_node(cpu);
113 old_node = cpu_to_node(old_cpu);
114 if (old_node != node)
115 desc = __real_move_irq_desc(desc, cpu);
116 else
117 desc->cpu = cpu;
118 }
119
120 return desc;
121}
122