Commit b5eb78f7 authored by Yinghai Lu's avatar Yinghai Lu Committed by H. Peter Anvin

sparseirq: Use radix_tree instead of ptrs array

Use radix_tree irq_desc_tree instead of irq_desc_ptrs.

-v2: according to Eric and cyrill to use radix_tree_lookup_slot and
     radix_tree_replace_slot
Signed-off-by: default avatarYinghai Lu <yinghai@kernel.org>
LKML-Reference: <1265793639-15071-32-git-send-email-yinghai@kernel.org>
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
parent 99558f0b
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/rculist.h> #include <linux/rculist.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/radix-tree.h>
#include <trace/events/irq.h> #include <trace/events/irq.h>
#include "internals.h" #include "internals.h"
...@@ -127,7 +128,26 @@ static void init_one_irq_desc(int irq, struct irq_desc *desc, int node) ...@@ -127,7 +128,26 @@ static void init_one_irq_desc(int irq, struct irq_desc *desc, int node)
*/ */
DEFINE_RAW_SPINLOCK(sparse_irq_lock); DEFINE_RAW_SPINLOCK(sparse_irq_lock);
static struct irq_desc **irq_desc_ptrs __read_mostly; static RADIX_TREE(irq_desc_tree, GFP_ATOMIC);
static void set_irq_desc(unsigned int irq, struct irq_desc *desc)
{
radix_tree_insert(&irq_desc_tree, irq, desc);
}
struct irq_desc *irq_to_desc(unsigned int irq)
{
return radix_tree_lookup(&irq_desc_tree, irq);
}
void replace_irq_desc(unsigned int irq, struct irq_desc *desc)
{
void **ptr;
ptr = radix_tree_lookup_slot(&irq_desc_tree, irq);
if (ptr)
radix_tree_replace_slot(ptr, desc);
}
static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = {
[0 ... NR_IRQS_LEGACY-1] = { [0 ... NR_IRQS_LEGACY-1] = {
...@@ -159,9 +179,6 @@ int __init early_irq_init(void) ...@@ -159,9 +179,6 @@ int __init early_irq_init(void)
legacy_count = ARRAY_SIZE(irq_desc_legacy); legacy_count = ARRAY_SIZE(irq_desc_legacy);
node = first_online_node; node = first_online_node;
/* allocate irq_desc_ptrs array based on nr_irqs */
irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT);
/* allocate based on nr_cpu_ids */ /* allocate based on nr_cpu_ids */
kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids * kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids *
sizeof(int), GFP_NOWAIT, node); sizeof(int), GFP_NOWAIT, node);
...@@ -175,28 +192,12 @@ int __init early_irq_init(void) ...@@ -175,28 +192,12 @@ int __init early_irq_init(void)
lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
alloc_desc_masks(&desc[i], node, true); alloc_desc_masks(&desc[i], node, true);
init_desc_masks(&desc[i]); init_desc_masks(&desc[i]);
irq_desc_ptrs[i] = desc + i; set_irq_desc(i, &desc[i]);
} }
for (i = legacy_count; i < nr_irqs; i++)
irq_desc_ptrs[i] = NULL;
return arch_early_irq_init(); return arch_early_irq_init();
} }
struct irq_desc *irq_to_desc(unsigned int irq)
{
if (irq_desc_ptrs && irq < nr_irqs)
return irq_desc_ptrs[irq];
return NULL;
}
void replace_irq_desc(unsigned int irq, struct irq_desc *desc)
{
irq_desc_ptrs[irq] = desc;
}
struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
{ {
struct irq_desc *desc; struct irq_desc *desc;
...@@ -208,14 +209,14 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) ...@@ -208,14 +209,14 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
return NULL; return NULL;
} }
desc = irq_desc_ptrs[irq]; desc = irq_to_desc(irq);
if (desc) if (desc)
return desc; return desc;
raw_spin_lock_irqsave(&sparse_irq_lock, flags); raw_spin_lock_irqsave(&sparse_irq_lock, flags);
/* We have to check it to avoid races with another CPU */ /* We have to check it to avoid races with another CPU */
desc = irq_desc_ptrs[irq]; desc = irq_to_desc(irq);
if (desc) if (desc)
goto out_unlock; goto out_unlock;
...@@ -228,7 +229,7 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) ...@@ -228,7 +229,7 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
} }
init_one_irq_desc(irq, desc, node); init_one_irq_desc(irq, desc, node);
irq_desc_ptrs[irq] = desc; set_irq_desc(irq, desc);
out_unlock: out_unlock:
raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); raw_spin_unlock_irqrestore(&sparse_irq_lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment