diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-01-13 18:45:38 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 20:32:31 -0500 |
commit | 6c9ae009b298753a3baf71298d676a68b5a10c8f (patch) | |
tree | 95a7e4ca54fe8e96c95cedd4e8d6450659015212 | |
parent | 558bbb2fc75fd9676e07e347c021865e326c56db (diff) |
irq: use per_cpu kstat_irqs
Use modern per_cpu API to increment {soft|hard}irq counters, and use
per_cpu allocation for (struct irq_desc)->kstats_irq instead of an array.
This gives better SMP/NUMA locality and saves few instructions per irq.
With small nr_cpuids values (8 for example), kstats_irq was a small array
(less than L1_CACHE_BYTES), potentially source of false sharing.
In the !CONFIG_SPARSE_IRQ case, remove the huge, NUMA/cache unfriendly
kstat_irqs_all[NR_IRQS][NR_CPUS] array.
Note: we still populate kstats_irq for all possible irqs in
early_irq_init(). We probably could use on-demand allocations. (Code
included in alloc_descs()). Problem is not all IRQS are used with a prior
alloc_descs() call.
kstat_irqs_this_cpu() is not used anymore, remove it.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Reviewed-by: Christoph Lameter <cl@linux.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/irqdesc.h | 2 | ||||
-rw-r--r-- | include/linux/kernel_stat.h | 19 | ||||
-rw-r--r-- | kernel/irq/irqdesc.c | 40 |
3 files changed, 40 insertions, 21 deletions
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index 979c68cc7458..6a64c6fa81af 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h | |||
@@ -57,7 +57,7 @@ struct irq_desc { | |||
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | struct timer_rand_state *timer_rand_state; | 59 | struct timer_rand_state *timer_rand_state; |
60 | unsigned int *kstat_irqs; | 60 | unsigned int __percpu *kstat_irqs; |
61 | irq_flow_handler_t handle_irq; | 61 | irq_flow_handler_t handle_irq; |
62 | struct irqaction *action; /* IRQ action list */ | 62 | struct irqaction *action; /* IRQ action list */ |
63 | unsigned int status; /* IRQ status */ | 63 | unsigned int status; /* IRQ status */ |
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 44e83ba12b5b..0cce2db580c3 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h | |||
@@ -46,16 +46,14 @@ DECLARE_PER_CPU(struct kernel_stat, kstat); | |||
46 | extern unsigned long long nr_context_switches(void); | 46 | extern unsigned long long nr_context_switches(void); |
47 | 47 | ||
48 | #ifndef CONFIG_GENERIC_HARDIRQS | 48 | #ifndef CONFIG_GENERIC_HARDIRQS |
49 | #define kstat_irqs_this_cpu(irq) \ | ||
50 | (this_cpu_read(kstat.irqs[irq]) | ||
51 | 49 | ||
52 | struct irq_desc; | 50 | struct irq_desc; |
53 | 51 | ||
54 | static inline void kstat_incr_irqs_this_cpu(unsigned int irq, | 52 | static inline void kstat_incr_irqs_this_cpu(unsigned int irq, |
55 | struct irq_desc *desc) | 53 | struct irq_desc *desc) |
56 | { | 54 | { |
57 | kstat_this_cpu.irqs[irq]++; | 55 | __this_cpu_inc(kstat.irqs[irq]); |
58 | kstat_this_cpu.irqs_sum++; | 56 | __this_cpu_inc(kstat.irqs_sum); |
59 | } | 57 | } |
60 | 58 | ||
61 | static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) | 59 | static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) |
@@ -65,17 +63,18 @@ static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) | |||
65 | #else | 63 | #else |
66 | #include <linux/irq.h> | 64 | #include <linux/irq.h> |
67 | extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu); | 65 | extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu); |
68 | #define kstat_irqs_this_cpu(DESC) \ | 66 | |
69 | ((DESC)->kstat_irqs[smp_processor_id()]) | 67 | #define kstat_incr_irqs_this_cpu(irqno, DESC) \ |
70 | #define kstat_incr_irqs_this_cpu(irqno, DESC) do {\ | 68 | do { \ |
71 | ((DESC)->kstat_irqs[smp_processor_id()]++);\ | 69 | __this_cpu_inc(*(DESC)->kstat_irqs); \ |
72 | kstat_this_cpu.irqs_sum++; } while (0) | 70 | __this_cpu_inc(kstat.irqs_sum); \ |
71 | } while (0) | ||
73 | 72 | ||
74 | #endif | 73 | #endif |
75 | 74 | ||
76 | static inline void kstat_incr_softirqs_this_cpu(unsigned int irq) | 75 | static inline void kstat_incr_softirqs_this_cpu(unsigned int irq) |
77 | { | 76 | { |
78 | kstat_this_cpu.softirqs[irq]++; | 77 | __this_cpu_inc(kstat.softirqs[irq]); |
79 | } | 78 | } |
80 | 79 | ||
81 | static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) | 80 | static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) |
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 9988d03797f5..282f20230e67 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c | |||
@@ -72,6 +72,8 @@ static inline int desc_node(struct irq_desc *desc) { return 0; } | |||
72 | 72 | ||
73 | static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node) | 73 | static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node) |
74 | { | 74 | { |
75 | int cpu; | ||
76 | |||
75 | desc->irq_data.irq = irq; | 77 | desc->irq_data.irq = irq; |
76 | desc->irq_data.chip = &no_irq_chip; | 78 | desc->irq_data.chip = &no_irq_chip; |
77 | desc->irq_data.chip_data = NULL; | 79 | desc->irq_data.chip_data = NULL; |
@@ -83,7 +85,8 @@ static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node) | |||
83 | desc->irq_count = 0; | 85 | desc->irq_count = 0; |
84 | desc->irqs_unhandled = 0; | 86 | desc->irqs_unhandled = 0; |
85 | desc->name = NULL; | 87 | desc->name = NULL; |
86 | memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs))); | 88 | for_each_possible_cpu(cpu) |
89 | *per_cpu_ptr(desc->kstat_irqs, cpu) = 0; | ||
87 | desc_smp_init(desc, node); | 90 | desc_smp_init(desc, node); |
88 | } | 91 | } |
89 | 92 | ||
@@ -133,8 +136,7 @@ static struct irq_desc *alloc_desc(int irq, int node) | |||
133 | if (!desc) | 136 | if (!desc) |
134 | return NULL; | 137 | return NULL; |
135 | /* allocate based on nr_cpu_ids */ | 138 | /* allocate based on nr_cpu_ids */ |
136 | desc->kstat_irqs = kzalloc_node(nr_cpu_ids * sizeof(*desc->kstat_irqs), | 139 | desc->kstat_irqs = alloc_percpu(unsigned int); |
137 | gfp, node); | ||
138 | if (!desc->kstat_irqs) | 140 | if (!desc->kstat_irqs) |
139 | goto err_desc; | 141 | goto err_desc; |
140 | 142 | ||
@@ -149,7 +151,7 @@ static struct irq_desc *alloc_desc(int irq, int node) | |||
149 | return desc; | 151 | return desc; |
150 | 152 | ||
151 | err_kstat: | 153 | err_kstat: |
152 | kfree(desc->kstat_irqs); | 154 | free_percpu(desc->kstat_irqs); |
153 | err_desc: | 155 | err_desc: |
154 | kfree(desc); | 156 | kfree(desc); |
155 | return NULL; | 157 | return NULL; |
@@ -166,7 +168,7 @@ static void free_desc(unsigned int irq) | |||
166 | mutex_unlock(&sparse_irq_lock); | 168 | mutex_unlock(&sparse_irq_lock); |
167 | 169 | ||
168 | free_masks(desc); | 170 | free_masks(desc); |
169 | kfree(desc->kstat_irqs); | 171 | free_percpu(desc->kstat_irqs); |
170 | kfree(desc); | 172 | kfree(desc); |
171 | } | 173 | } |
172 | 174 | ||
@@ -234,7 +236,6 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { | |||
234 | } | 236 | } |
235 | }; | 237 | }; |
236 | 238 | ||
237 | static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS]; | ||
238 | int __init early_irq_init(void) | 239 | int __init early_irq_init(void) |
239 | { | 240 | { |
240 | int count, i, node = first_online_node; | 241 | int count, i, node = first_online_node; |
@@ -250,7 +251,8 @@ int __init early_irq_init(void) | |||
250 | for (i = 0; i < count; i++) { | 251 | for (i = 0; i < count; i++) { |
251 | desc[i].irq_data.irq = i; | 252 | desc[i].irq_data.irq = i; |
252 | desc[i].irq_data.chip = &no_irq_chip; | 253 | desc[i].irq_data.chip = &no_irq_chip; |
253 | desc[i].kstat_irqs = kstat_irqs_all[i]; | 254 | /* TODO : do this allocation on-demand ... */ |
255 | desc[i].kstat_irqs = alloc_percpu(unsigned int); | ||
254 | alloc_masks(desc + i, GFP_KERNEL, node); | 256 | alloc_masks(desc + i, GFP_KERNEL, node); |
255 | desc_smp_init(desc + i, node); | 257 | desc_smp_init(desc + i, node); |
256 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); | 258 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
@@ -275,6 +277,22 @@ static void free_desc(unsigned int irq) | |||
275 | 277 | ||
276 | static inline int alloc_descs(unsigned int start, unsigned int cnt, int node) | 278 | static inline int alloc_descs(unsigned int start, unsigned int cnt, int node) |
277 | { | 279 | { |
280 | #if defined(CONFIG_KSTAT_IRQS_ONDEMAND) | ||
281 | struct irq_desc *desc; | ||
282 | unsigned int i; | ||
283 | |||
284 | for (i = 0; i < cnt; i++) { | ||
285 | desc = irq_to_desc(start + i); | ||
286 | if (desc && !desc->kstat_irqs) { | ||
287 | unsigned int __percpu *stats = alloc_percpu(unsigned int); | ||
288 | |||
289 | if (!stats) | ||
290 | return -1; | ||
291 | if (cmpxchg(&desc->kstat_irqs, NULL, stats) != NULL) | ||
292 | free_percpu(stats); | ||
293 | } | ||
294 | } | ||
295 | #endif | ||
278 | return start; | 296 | return start; |
279 | } | 297 | } |
280 | #endif /* !CONFIG_SPARSE_IRQ */ | 298 | #endif /* !CONFIG_SPARSE_IRQ */ |
@@ -391,7 +409,9 @@ void dynamic_irq_cleanup(unsigned int irq) | |||
391 | unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) | 409 | unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) |
392 | { | 410 | { |
393 | struct irq_desc *desc = irq_to_desc(irq); | 411 | struct irq_desc *desc = irq_to_desc(irq); |
394 | return desc ? desc->kstat_irqs[cpu] : 0; | 412 | |
413 | return desc && desc->kstat_irqs ? | ||
414 | *per_cpu_ptr(desc->kstat_irqs, cpu) : 0; | ||
395 | } | 415 | } |
396 | 416 | ||
397 | #ifdef CONFIG_GENERIC_HARDIRQS | 417 | #ifdef CONFIG_GENERIC_HARDIRQS |
@@ -401,10 +421,10 @@ unsigned int kstat_irqs(unsigned int irq) | |||
401 | int cpu; | 421 | int cpu; |
402 | int sum = 0; | 422 | int sum = 0; |
403 | 423 | ||
404 | if (!desc) | 424 | if (!desc || !desc->kstat_irqs) |
405 | return 0; | 425 | return 0; |
406 | for_each_possible_cpu(cpu) | 426 | for_each_possible_cpu(cpu) |
407 | sum += desc->kstat_irqs[cpu]; | 427 | sum += *per_cpu_ptr(desc->kstat_irqs, cpu); |
408 | return sum; | 428 | return sum; |
409 | } | 429 | } |
410 | #endif /* CONFIG_GENERIC_HARDIRQS */ | 430 | #endif /* CONFIG_GENERIC_HARDIRQS */ |