blob: 3fd30197da2e285d1cdc6f10f037bff9cbc6f25d [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,
Yinghai Lu85ac16d2009-04-27 18:00:38 -070018 int node, int nr)
Yinghai Lu48a1b102008-12-11 00:15:01 -080019{
Yinghai Lu85ac16d2009-04-27 18:00:38 -070020 init_kstat_irqs(desc, node, nr);
Yinghai Lu48a1b102008-12-11 00:15:01 -080021
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
Mike Travis802bf932009-01-10 21:58:09 -080036static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
Yinghai Lu85ac16d2009-04-27 18:00:38 -070037 struct irq_desc *desc, int node)
Yinghai Lu48a1b102008-12-11 00:15:01 -080038{
39 memcpy(desc, old_desc, sizeof(struct irq_desc));
Yinghai Lu85ac16d2009-04-27 18:00:38 -070040 if (!alloc_desc_masks(desc, node, false)) {
Mike Travis802bf932009-01-10 21:58:09 -080041 printk(KERN_ERR "irq %d: can not get new irq_desc cpumask "
42 "for migration.\n", irq);
43 return false;
44 }
Ingo Molnar793f7b12008-12-26 19:02:20 +010045 spin_lock_init(&desc->lock);
Yinghai Lu85ac16d2009-04-27 18:00:38 -070046 desc->node = node;
Yinghai Lu48a1b102008-12-11 00:15:01 -080047 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu85ac16d2009-04-27 18:00:38 -070048 init_copy_kstat_irqs(old_desc, desc, node, nr_cpu_ids);
Mike Travis7f7ace02009-01-10 21:58:08 -080049 init_copy_desc_masks(old_desc, desc);
Yinghai Lu85ac16d2009-04-27 18:00:38 -070050 arch_init_copy_chip_data(old_desc, desc, node);
Mike Travis802bf932009-01-10 21:58:09 -080051 return true;
Yinghai Lu48a1b102008-12-11 00:15:01 -080052}
53
54static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
55{
56 free_kstat_irqs(old_desc, desc);
Yinghai Lu9756b152009-03-30 20:37:20 -070057 free_desc_masks(old_desc, desc);
Yinghai Lu48a1b102008-12-11 00:15:01 -080058 arch_free_chip_data(old_desc, desc);
59}
60
61static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
Yinghai Lu85ac16d2009-04-27 18:00:38 -070062 int node)
Yinghai Lu48a1b102008-12-11 00:15:01 -080063{
64 struct irq_desc *desc;
65 unsigned int irq;
66 unsigned long flags;
Yinghai Lu48a1b102008-12-11 00:15:01 -080067
68 irq = old_desc->irq;
69
70 spin_lock_irqsave(&sparse_irq_lock, flags);
71
72 /* We have to check it to avoid races with another CPU */
73 desc = irq_desc_ptrs[irq];
74
75 if (desc && old_desc != desc)
Yinghai Lu10b888d2009-01-31 14:50:07 -080076 goto out_unlock;
Yinghai Lu48a1b102008-12-11 00:15:01 -080077
Yinghai Lu48a1b102008-12-11 00:15:01 -080078 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 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -070086 if (!init_copy_one_irq_desc(irq, old_desc, desc, node)) {
Mike Travis7f7ace02009-01-10 21:58:08 -080087 /* still use old one */
88 kfree(desc);
89 desc = old_desc;
90 goto out_unlock;
91 }
Yinghai Lu48a1b102008-12-11 00:15:01 -080092
93 irq_desc_ptrs[irq] = desc;
Yinghai Lu10b888d2009-01-31 14:50:07 -080094 spin_unlock_irqrestore(&sparse_irq_lock, flags);
Yinghai Lu48a1b102008-12-11 00:15:01 -080095
96 /* free the old one */
97 free_one_irq_desc(old_desc, desc);
98 kfree(old_desc);
Yinghai Lu10b888d2009-01-31 14:50:07 -080099
100 return desc;
Yinghai Lu48a1b102008-12-11 00:15:01 -0800101
102out_unlock:
103 spin_unlock_irqrestore(&sparse_irq_lock, flags);
104
105 return desc;
106}
107
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700108struct irq_desc *move_irq_desc(struct irq_desc *desc, int node)
Yinghai Lu48a1b102008-12-11 00:15:01 -0800109{
Yinghai Luad7d6c72009-08-04 09:01:33 -0700110 /* those static or target node is -1, do not move them */
111 if (desc->irq < NR_IRQS_LEGACY || node == -1)
Yinghai Lu48a1b102008-12-11 00:15:01 -0800112 return desc;
113
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700114 if (desc->node != node)
115 desc = __real_move_irq_desc(desc, node);
Yinghai Lu48a1b102008-12-11 00:15:01 -0800116
117 return desc;
118}
119