blob: e7f1f16402c1d425ef781b177421723734e58f65 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Yinghai Lu48a1b102008-12-11 00:15:01 -080010#include <linux/module.h>
11#include <linux/random.h>
12#include <linux/interrupt.h>
13#include <linux/kernel_stat.h>
14
15#include "internals.h"
16
17static void init_copy_kstat_irqs(struct irq_desc *old_desc,
18 struct irq_desc *desc,
Yinghai Lu85ac16d2009-04-27 18:00:38 -070019 int node, int nr)
Yinghai Lu48a1b102008-12-11 00:15:01 -080020{
Yinghai Lu85ac16d2009-04-27 18:00:38 -070021 init_kstat_irqs(desc, node, nr);
Yinghai Lu48a1b102008-12-11 00:15:01 -080022
Yinghai Lu005bf0e62009-02-08 16:18:03 -080023 if (desc->kstat_irqs != old_desc->kstat_irqs)
24 memcpy(desc->kstat_irqs, old_desc->kstat_irqs,
25 nr * sizeof(*desc->kstat_irqs));
Yinghai Lu48a1b102008-12-11 00:15:01 -080026}
27
28static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
29{
30 if (old_desc->kstat_irqs == desc->kstat_irqs)
31 return;
32
33 kfree(old_desc->kstat_irqs);
34 old_desc->kstat_irqs = NULL;
35}
36
Mike Travis802bf932009-01-10 21:58:09 -080037static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
Yinghai Lu85ac16d2009-04-27 18:00:38 -070038 struct irq_desc *desc, int node)
Yinghai Lu48a1b102008-12-11 00:15:01 -080039{
40 memcpy(desc, old_desc, sizeof(struct irq_desc));
Yinghai Lu85ac16d2009-04-27 18:00:38 -070041 if (!alloc_desc_masks(desc, node, false)) {
Mike Travis802bf932009-01-10 21:58:09 -080042 printk(KERN_ERR "irq %d: can not get new irq_desc cpumask "
43 "for migration.\n", irq);
44 return false;
45 }
Thomas Gleixner239007b2009-11-17 16:46:45 +010046 raw_spin_lock_init(&desc->lock);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020047 desc->irq_data.node = node;
Yinghai Lu48a1b102008-12-11 00:15:01 -080048 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
Yinghai Lu85ac16d2009-04-27 18:00:38 -070049 init_copy_kstat_irqs(old_desc, desc, node, nr_cpu_ids);
Mike Travis7f7ace02009-01-10 21:58:08 -080050 init_copy_desc_masks(old_desc, desc);
Yinghai Lu85ac16d2009-04-27 18:00:38 -070051 arch_init_copy_chip_data(old_desc, desc, node);
Mike Travis802bf932009-01-10 21:58:09 -080052 return true;
Yinghai Lu48a1b102008-12-11 00:15:01 -080053}
54
55static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
56{
57 free_kstat_irqs(old_desc, desc);
Yinghai Lu9756b152009-03-30 20:37:20 -070058 free_desc_masks(old_desc, desc);
Yinghai Lu48a1b102008-12-11 00:15:01 -080059 arch_free_chip_data(old_desc, desc);
60}
61
62static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
Yinghai Lu85ac16d2009-04-27 18:00:38 -070063 int node)
Yinghai Lu48a1b102008-12-11 00:15:01 -080064{
65 struct irq_desc *desc;
66 unsigned int irq;
67 unsigned long flags;
Yinghai Lu48a1b102008-12-11 00:15:01 -080068
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020069 irq = old_desc->irq_data.irq;
Yinghai Lu48a1b102008-12-11 00:15:01 -080070
Thomas Gleixner239007b2009-11-17 16:46:45 +010071 raw_spin_lock_irqsave(&sparse_irq_lock, flags);
Yinghai Lu48a1b102008-12-11 00:15:01 -080072
73 /* We have to check it to avoid races with another CPU */
Yinghai Lu99558f02010-02-10 01:20:34 -080074 desc = irq_to_desc(irq);
Yinghai Lu48a1b102008-12-11 00:15:01 -080075
76 if (desc && old_desc != desc)
Yinghai Lu10b888d2009-01-31 14:50:07 -080077 goto out_unlock;
Yinghai Lu48a1b102008-12-11 00:15:01 -080078
Yinghai Lu48a1b102008-12-11 00:15:01 -080079 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
Yinghai Lu48a1b102008-12-11 00:15:01 -080080 if (!desc) {
Mike Travis7f7ace02009-01-10 21:58:08 -080081 printk(KERN_ERR "irq %d: can not get new irq_desc "
82 "for migration.\n", irq);
Yinghai Lu48a1b102008-12-11 00:15:01 -080083 /* still use old one */
84 desc = old_desc;
85 goto out_unlock;
86 }
Yinghai Lu85ac16d2009-04-27 18:00:38 -070087 if (!init_copy_one_irq_desc(irq, old_desc, desc, node)) {
Mike Travis7f7ace02009-01-10 21:58:08 -080088 /* still use old one */
89 kfree(desc);
90 desc = old_desc;
91 goto out_unlock;
92 }
Yinghai Lu48a1b102008-12-11 00:15:01 -080093
Yinghai Lu99558f02010-02-10 01:20:34 -080094 replace_irq_desc(irq, desc);
Thomas Gleixner239007b2009-11-17 16:46:45 +010095 raw_spin_unlock_irqrestore(&sparse_irq_lock, flags);
Yinghai Lu48a1b102008-12-11 00:15:01 -080096
97 /* free the old one */
98 free_one_irq_desc(old_desc, desc);
99 kfree(old_desc);
Yinghai Lu10b888d2009-01-31 14:50:07 -0800100
101 return desc;
Yinghai Lu48a1b102008-12-11 00:15:01 -0800102
103out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100104 raw_spin_unlock_irqrestore(&sparse_irq_lock, flags);
Yinghai Lu48a1b102008-12-11 00:15:01 -0800105
106 return desc;
107}
108
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700109struct irq_desc *move_irq_desc(struct irq_desc *desc, int node)
Yinghai Lu48a1b102008-12-11 00:15:01 -0800110{
Yinghai Luad7d6c72009-08-04 09:01:33 -0700111 /* those static or target node is -1, do not move them */
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200112 if (desc->irq_data.irq < NR_IRQS_LEGACY || node == -1)
Yinghai Lu48a1b102008-12-11 00:15:01 -0800113 return desc;
114
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200115 if (desc->irq_data.node != node)
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700116 desc = __real_move_irq_desc(desc, node);
Yinghai Lu48a1b102008-12-11 00:15:01 -0800117
118 return desc;
119}
120