blob: c500cfe422b66ffb45445266702341d0b358d1c3 [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{
Yinghai Lu48a1b102008-12-11 00:15:01 -080020 init_kstat_irqs(desc, cpu, nr);
21
Yinghai Lu005bf0e62009-02-08 16:18:03 -080022 if (desc->kstat_irqs != old_desc->kstat_irqs)
23 memcpy(desc->kstat_irqs, old_desc->kstat_irqs,
24 nr * sizeof(*desc->kstat_irqs));
Yinghai Lu48a1b102008-12-11 00:15:01 -080025}
26
27static 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
36static void init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
37 struct irq_desc *desc, int cpu)
38{
39 memcpy(desc, old_desc, sizeof(struct irq_desc));
Ingo Molnar793f7b12008-12-26 19:02:20 +010040 spin_lock_init(&desc->lock);
Yinghai Lu48a1b102008-12-11 00:15:01 -080041 desc->cpu = cpu;
42 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
43 init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
44 arch_init_copy_chip_data(old_desc, desc, cpu);
45}
46
47static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
48{
49 free_kstat_irqs(old_desc, desc);
50 arch_free_chip_data(old_desc, desc);
51}
52
53static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
54 int cpu)
55{
56 struct irq_desc *desc;
57 unsigned int irq;
58 unsigned long flags;
59 int node;
60
61 irq = old_desc->irq;
62
63 spin_lock_irqsave(&sparse_irq_lock, flags);
64
65 /* We have to check it to avoid races with another CPU */
66 desc = irq_desc_ptrs[irq];
67
68 if (desc && old_desc != desc)
69 goto out_unlock;
70
71 node = cpu_to_node(cpu);
72 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
Yinghai Lu48a1b102008-12-11 00:15:01 -080073 if (!desc) {
Ingo Molnar8b07cd42008-12-26 19:10:04 +010074 printk(KERN_ERR "irq %d: can not get new irq_desc for migration.\n", irq);
Yinghai Lu48a1b102008-12-11 00:15:01 -080075 /* still use old one */
76 desc = old_desc;
77 goto out_unlock;
78 }
79 init_copy_one_irq_desc(irq, old_desc, desc, cpu);
80
81 irq_desc_ptrs[irq] = desc;
82
83 /* free the old one */
84 free_one_irq_desc(old_desc, desc);
85 kfree(old_desc);
86
87out_unlock:
88 spin_unlock_irqrestore(&sparse_irq_lock, flags);
89
90 return desc;
91}
92
93struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
94{
95 int old_cpu;
96 int node, old_node;
97
98 /* those all static, do move them */
99 if (desc->irq < NR_IRQS_LEGACY)
100 return desc;
101
102 old_cpu = desc->cpu;
Yinghai Lu48a1b102008-12-11 00:15:01 -0800103 if (old_cpu != cpu) {
104 node = cpu_to_node(cpu);
105 old_node = cpu_to_node(old_cpu);
106 if (old_node != node)
107 desc = __real_move_irq_desc(desc, cpu);
108 else
109 desc->cpu = cpu;
110 }
111
112 return desc;
113}
114