x86, sparseirq: move irq_desc according to smp_affinity, v7
[deliverable/linux.git] / kernel / irq / numa_migrate.c
1 /*
2 * linux/kernel/irq/handle.c
3 *
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
6 *
7 * This file contains the core interrupt handling code.
8 *
9 * Detailed information is available in Documentation/DocBook/genericirq
10 *
11 */
12
13 #include <linux/irq.h>
14 #include <linux/module.h>
15 #include <linux/random.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel_stat.h>
18
19 #include "internals.h"
20
21 static void init_copy_kstat_irqs(struct irq_desc *old_desc,
22 struct irq_desc *desc,
23 int cpu, int nr)
24 {
25 unsigned long bytes;
26
27 init_kstat_irqs(desc, cpu, nr);
28
29 if (desc->kstat_irqs != old_desc->kstat_irqs) {
30 /* Compute how many bytes we need per irq and allocate them */
31 bytes = nr * sizeof(unsigned int);
32
33 memcpy(desc->kstat_irqs, old_desc->kstat_irqs, bytes);
34 }
35 }
36
37 static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
38 {
39 if (old_desc->kstat_irqs == desc->kstat_irqs)
40 return;
41
42 kfree(old_desc->kstat_irqs);
43 old_desc->kstat_irqs = NULL;
44 }
45
46 static void init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
47 struct irq_desc *desc, int cpu)
48 {
49 memcpy(desc, old_desc, sizeof(struct irq_desc));
50 desc->cpu = cpu;
51 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
52 init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
53 arch_init_copy_chip_data(old_desc, desc, cpu);
54 }
55
56 static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
57 {
58 free_kstat_irqs(old_desc, desc);
59 arch_free_chip_data(old_desc, desc);
60 }
61
62 static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
63 int cpu)
64 {
65 struct irq_desc *desc;
66 unsigned int irq;
67 unsigned long flags;
68 int node;
69
70 irq = old_desc->irq;
71
72 spin_lock_irqsave(&sparse_irq_lock, flags);
73
74 /* We have to check it to avoid races with another CPU */
75 desc = irq_desc_ptrs[irq];
76
77 if (desc && old_desc != desc)
78 goto out_unlock;
79
80 node = cpu_to_node(cpu);
81 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
82 printk(KERN_DEBUG " move irq_desc for %d to cpu %d node %d\n",
83 irq, cpu, node);
84 if (!desc) {
85 printk(KERN_ERR "can not get new irq_desc for moving\n");
86 /* still use old one */
87 desc = old_desc;
88 goto out_unlock;
89 }
90 init_copy_one_irq_desc(irq, old_desc, desc, cpu);
91
92 irq_desc_ptrs[irq] = desc;
93
94 /* free the old one */
95 free_one_irq_desc(old_desc, desc);
96 kfree(old_desc);
97
98 out_unlock:
99 spin_unlock_irqrestore(&sparse_irq_lock, flags);
100
101 return desc;
102 }
103
104 struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
105 {
106 int old_cpu;
107 int node, old_node;
108
109 /* those all static, do move them */
110 if (desc->irq < NR_IRQS_LEGACY)
111 return desc;
112
113 old_cpu = desc->cpu;
114 printk(KERN_DEBUG
115 "try to move irq_desc from cpu %d to %d\n", old_cpu, cpu);
116 if (old_cpu != cpu) {
117 node = cpu_to_node(cpu);
118 old_node = cpu_to_node(old_cpu);
119 if (old_node != node)
120 desc = __real_move_irq_desc(desc, cpu);
121 else
122 desc->cpu = cpu;
123 }
124
125 return desc;
126 }
127
This page took 0.042409 seconds and 5 git commands to generate.