blob: f001a4ea641491daec89640d8ba3f3bc2da4779c [file] [log] [blame]
Yinghai Lu48a1b102008-12-11 00:15:01 -08001/*
Yinghai Lub9098952008-12-19 13:48:34 -08002 * NUMA irq-desc migration code
Yinghai Lu48a1b102008-12-11 00:15:01 -08003 *
Yinghai Lub9098952008-12-19 13:48:34 -08004 * Migrate IRQ data structures (irq_desc, chip_data, etc.) over to
5 * the new "home node" of the IRQ.
Yinghai Lu48a1b102008-12-11 00:15:01 -08006 */
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));
Ingo Molnar793f7b12008-12-26 19:02:20 +010045 spin_lock_init(&desc->lock);
Yinghai Lu48a1b102008-12-11 00:15:01 -080046 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 Travis7f7ace02009-01-10 21:58:08 -080049 init_copy_desc_masks(old_desc, desc);
Yinghai Lu48a1b102008-12-11 00:15:01 -080050 arch_init_copy_chip_data(old_desc, desc, cpu);
51}
52
53static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
54{
55 free_kstat_irqs(old_desc, desc);
56 arch_free_chip_data(old_desc, desc);
57}
58
59static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
60 int cpu)
61{
62 struct irq_desc *desc;
63 unsigned int irq;
64 unsigned long flags;
65 int node;
66
67 irq = old_desc->irq;
68
69 spin_lock_irqsave(&sparse_irq_lock, flags);
70
71 /* We have to check it to avoid races with another CPU */
72 desc = irq_desc_ptrs[irq];
73
74 if (desc && old_desc != desc)
75 goto out_unlock;
76
77 node = cpu_to_node(cpu);
78 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
Yinghai Lu48a1b102008-12-11 00:15:01 -080079 if (!desc) {
Mike Travis7f7ace02009-01-10 21:58:08 -080080 printk(KERN_ERR "irq %d: can not get new irq_desc "
81 "for migration.\n", irq);
Yinghai Lu48a1b102008-12-11 00:15:01 -080082 /* still use old one */
83 desc = old_desc;
84 goto out_unlock;
85 }
Mike Travis7f7ace02009-01-10 21:58:08 -080086 if (!init_alloc_desc_masks(desc, node, false)) {
87 printk(KERN_ERR "irq %d: can not get new irq_desc cpumask "
88 "for migration.\n", irq);
89 /* still use old one */
90 kfree(desc);
91 desc = old_desc;
92 goto out_unlock;
93 }
Yinghai Lu48a1b102008-12-11 00:15:01 -080094 init_copy_one_irq_desc(irq, old_desc, desc, cpu);
95
96 irq_desc_ptrs[irq] = desc;
97
98 /* free the old one */
99 free_one_irq_desc(old_desc, desc);
100 kfree(old_desc);
101
102out_unlock:
103 spin_unlock_irqrestore(&sparse_irq_lock, flags);
104
105 return desc;
106}
107
108struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
109{
110 int old_cpu;
111 int node, old_node;
112
113 /* those all static, do move them */
114 if (desc->irq < NR_IRQS_LEGACY)
115 return desc;
116
117 old_cpu = desc->cpu;
Yinghai Lu48a1b102008-12-11 00:15:01 -0800118 if (old_cpu != cpu) {
119 node = cpu_to_node(cpu);
120 old_node = cpu_to_node(old_cpu);
121 if (old_node != node)
122 desc = __real_move_irq_desc(desc, cpu);
123 else
124 desc->cpu = cpu;
125 }
126
127 return desc;
128}
129