2 * NUMA irq-desc migration code
4 * Migrate IRQ data structures (irq_desc, chip_data, etc.) over to
5 * the new "home node" of the IRQ.
9 #include <linux/slab.h>
10 #include <linux/module.h>
11 #include <linux/random.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
15 #include "internals.h"
17 static void init_copy_kstat_irqs(struct irq_desc
*old_desc
,
18 struct irq_desc
*desc
,
21 init_kstat_irqs(desc
, node
, nr
);
23 if (desc
->kstat_irqs
!= old_desc
->kstat_irqs
)
24 memcpy(desc
->kstat_irqs
, old_desc
->kstat_irqs
,
25 nr
* sizeof(*desc
->kstat_irqs
));
28 static void free_kstat_irqs(struct irq_desc
*old_desc
, struct irq_desc
*desc
)
30 if (old_desc
->kstat_irqs
== desc
->kstat_irqs
)
33 kfree(old_desc
->kstat_irqs
);
34 old_desc
->kstat_irqs
= NULL
;
37 static bool init_copy_one_irq_desc(int irq
, struct irq_desc
*old_desc
,
38 struct irq_desc
*desc
, int node
)
40 memcpy(desc
, old_desc
, sizeof(struct irq_desc
));
41 if (!alloc_desc_masks(desc
, node
, false)) {
42 printk(KERN_ERR
"irq %d: can not get new irq_desc cpumask "
43 "for migration.\n", irq
);
46 raw_spin_lock_init(&desc
->lock
);
48 lockdep_set_class(&desc
->lock
, &irq_desc_lock_class
);
49 init_copy_kstat_irqs(old_desc
, desc
, node
, nr_cpu_ids
);
50 init_copy_desc_masks(old_desc
, desc
);
51 arch_init_copy_chip_data(old_desc
, desc
, node
);
55 static void free_one_irq_desc(struct irq_desc
*old_desc
, struct irq_desc
*desc
)
57 free_kstat_irqs(old_desc
, desc
);
58 free_desc_masks(old_desc
, desc
);
59 arch_free_chip_data(old_desc
, desc
);
62 static struct irq_desc
*__real_move_irq_desc(struct irq_desc
*old_desc
,
65 struct irq_desc
*desc
;
71 raw_spin_lock_irqsave(&sparse_irq_lock
, flags
);
73 /* We have to check it to avoid races with another CPU */
74 desc
= irq_to_desc(irq
);
76 if (desc
&& old_desc
!= desc
)
79 desc
= kzalloc_node(sizeof(*desc
), GFP_ATOMIC
, node
);
81 printk(KERN_ERR
"irq %d: can not get new irq_desc "
82 "for migration.\n", irq
);
83 /* still use old one */
87 if (!init_copy_one_irq_desc(irq
, old_desc
, desc
, node
)) {
88 /* still use old one */
94 replace_irq_desc(irq
, desc
);
95 raw_spin_unlock_irqrestore(&sparse_irq_lock
, flags
);
97 /* free the old one */
98 free_one_irq_desc(old_desc
, desc
);
104 raw_spin_unlock_irqrestore(&sparse_irq_lock
, flags
);
109 struct irq_desc
*move_irq_desc(struct irq_desc
*desc
, int node
)
111 /* those static or target node is -1, do not move them */
112 if (desc
->irq
< NR_IRQS_LEGACY
|| node
== -1)
115 if (desc
->node
!= node
)
116 desc
= __real_move_irq_desc(desc
, node
);