aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sh/intc
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2012-01-24 03:41:55 -0500
committerPaul Mundt <lethal@linux-sh.org>2012-01-24 03:41:55 -0500
commitb59f9f9775e643435bba76e30e59e47c19c56dee (patch)
tree55bc067e5d2da0fc01ef9808ded60d9234dde165 /drivers/sh/intc
parent30377642138aadeef35a31c2f90dba0b6fa7b91a (diff)
sh: intc: optimize intc IRQ lookup
This ensures that the sense/prio lists are sorted at registration time, enabling us to use a simple binary search for an optimized lookup (something that had been on the TODO for some time). Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'drivers/sh/intc')
-rw-r--r--drivers/sh/intc/chip.c27
-rw-r--r--drivers/sh/intc/core.c9
-rw-r--r--drivers/sh/intc/internals.h8
3 files changed, 22 insertions, 22 deletions
diff --git a/drivers/sh/intc/chip.c b/drivers/sh/intc/chip.c
index db10adf63dd7..012df2676a26 100644
--- a/drivers/sh/intc/chip.c
+++ b/drivers/sh/intc/chip.c
@@ -2,13 +2,14 @@
2 * IRQ chip definitions for INTC IRQs. 2 * IRQ chip definitions for INTC IRQs.
3 * 3 *
4 * Copyright (C) 2007, 2008 Magnus Damm 4 * Copyright (C) 2007, 2008 Magnus Damm
5 * Copyright (C) 2009, 2010 Paul Mundt 5 * Copyright (C) 2009 - 2012 Paul Mundt
6 * 6 *
7 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details. 9 * for more details.
10 */ 10 */
11#include <linux/cpumask.h> 11#include <linux/cpumask.h>
12#include <linux/bsearch.h>
12#include <linux/io.h> 13#include <linux/io.h>
13#include "internals.h" 14#include "internals.h"
14 15
@@ -117,28 +118,12 @@ static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,
117 unsigned int nr_hp, 118 unsigned int nr_hp,
118 unsigned int irq) 119 unsigned int irq)
119{ 120{
120 int i; 121 struct intc_handle_int key;
121
122 /*
123 * this doesn't scale well, but...
124 *
125 * this function should only be used for cerain uncommon
126 * operations such as intc_set_priority() and intc_set_type()
127 * and in those rare cases performance doesn't matter that much.
128 * keeping the memory footprint low is more important.
129 *
130 * one rather simple way to speed this up and still keep the
131 * memory footprint down is to make sure the array is sorted
132 * and then perform a bisect to lookup the irq.
133 */
134 for (i = 0; i < nr_hp; i++) {
135 if ((hp + i)->irq != irq)
136 continue;
137 122
138 return hp + i; 123 key.irq = irq;
139 } 124 key.handle = 0;
140 125
141 return NULL; 126 return bsearch(&key, hp, nr_hp, sizeof(*hp), intc_handle_int_cmp);
142} 127}
143 128
144int intc_set_priority(unsigned int irq, unsigned int prio) 129int intc_set_priority(unsigned int irq, unsigned int prio)
diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index c64690dda4a0..8e1fcd5e5f0d 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -2,7 +2,7 @@
2 * Shared interrupt handling code for IPR and INTC2 types of IRQs. 2 * Shared interrupt handling code for IPR and INTC2 types of IRQs.
3 * 3 *
4 * Copyright (C) 2007, 2008 Magnus Damm 4 * Copyright (C) 2007, 2008 Magnus Damm
5 * Copyright (C) 2009, 2010 Paul Mundt 5 * Copyright (C) 2009 - 2012 Paul Mundt
6 * 6 *
7 * Based on intc2.c and ipr.c 7 * Based on intc2.c and ipr.c
8 * 8 *
@@ -31,6 +31,7 @@
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/radix-tree.h> 32#include <linux/radix-tree.h>
33#include <linux/export.h> 33#include <linux/export.h>
34#include <linux/sort.h>
34#include "internals.h" 35#include "internals.h"
35 36
36LIST_HEAD(intc_list); 37LIST_HEAD(intc_list);
@@ -267,6 +268,9 @@ int __init register_intc_controller(struct intc_desc *desc)
267 k += save_reg(d, k, hw->prio_regs[i].set_reg, smp); 268 k += save_reg(d, k, hw->prio_regs[i].set_reg, smp);
268 k += save_reg(d, k, hw->prio_regs[i].clr_reg, smp); 269 k += save_reg(d, k, hw->prio_regs[i].clr_reg, smp);
269 } 270 }
271
272 sort(d->prio, hw->nr_prio_regs, sizeof(*d->prio),
273 intc_handle_int_cmp, NULL);
270 } 274 }
271 275
272 if (hw->sense_regs) { 276 if (hw->sense_regs) {
@@ -277,6 +281,9 @@ int __init register_intc_controller(struct intc_desc *desc)
277 281
278 for (i = 0; i < hw->nr_sense_regs; i++) 282 for (i = 0; i < hw->nr_sense_regs; i++)
279 k += save_reg(d, k, hw->sense_regs[i].reg, 0); 283 k += save_reg(d, k, hw->sense_regs[i].reg, 0);
284
285 sort(d->sense, hw->nr_sense_regs, sizeof(*d->sense),
286 intc_handle_int_cmp, NULL);
280 } 287 }
281 288
282 if (hw->subgroups) 289 if (hw->subgroups)
diff --git a/drivers/sh/intc/internals.h b/drivers/sh/intc/internals.h
index 422b72df089e..f034a979a16f 100644
--- a/drivers/sh/intc/internals.h
+++ b/drivers/sh/intc/internals.h
@@ -108,6 +108,14 @@ static inline void activate_irq(int irq)
108#endif 108#endif
109} 109}
110 110
111static inline int intc_handle_int_cmp(const void *a, const void *b)
112{
113 const struct intc_handle_int *_a = a;
114 const struct intc_handle_int *_b = b;
115
116 return _a->irq - _b->irq;
117}
118
111/* access.c */ 119/* access.c */
112extern unsigned long 120extern unsigned long
113(*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data); 121(*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data);