Skip to contentSkip to conversation

irqdomain: Simple NUMA awareness.

PATCH Applied Paul Mundt 2 participants 7 messages May 21, 2012 – Jun 13, 2012

Subsystems (4)
lore
Share & tools
lore

Paul Mundt

author
#0 lore raw

PATCH 1/2 irqdomain: Simple NUMA awareness.

While common irqdesc allocation is node aware, the irqdomain code is not.

Presently we observe a number of regressions/inconsistencies on NUMA-capable platforms:

- Platforms using irqdomains with legacy mappings, where the irq_descs are allocated node-local and the irqdomain data structure is not.

- Drivers implementing irqdomains will lose node locality regardless of the underlying struct device's node id.

This plugs in NUMA node id proliferation across the various allocation callsites by way of_node_to_nid() node lookup. While of_node_to_nid() does the right thing for OF-capable platforms it doesn't presently handle the non-DT case. This is trivially dealt with by simply wraping in to numa_node_id() unconditionally.

---
 include/linux/of.h     |   16 ++++++++++------
 kernel/irq/irqdomain.c |   13 ++++++++-----
 2 files changed, 18 insertions(+), 11 deletions(-)
include/linux/of.h +10 -6
index fa7fb1d..8650544 100644
@@ -21,7 +21,7 @@
 #include <linux/kref.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spinlock.h>
-
+#include <linux/topology.h>
 #include <asm/byteorder.h>
 #include <asm/errno.h>
 
@@ -158,11 +158,6 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
 
 #define OF_BAD_ADDR	((u64)-1)
 
-#ifndef of_node_to_nid
-static inline int of_node_to_nid(struct device_node *np) { return -1; }
-#define of_node_to_nid of_node_to_nid
-#endif
-
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
 #define for_each_node_by_name(dn, name) \
@@ -351,6 +346,15 @@ static inline int of_machine_is_compatible(const char *compat)
 #define of_match_node(_matches, _node)	NULL
 #endif /* CONFIG_OF */
 
+#ifndef of_node_to_nid
+static inline int of_node_to_nid(struct device_node *np)
+{
+	return numa_node_id();
+}
+
+#define of_node_to_nid of_node_to_nid
+#endif
+
 /**
  * of_property_read_bool - Findfrom a property
  * @np:		device node from which the property value is to be read.
kernel/irq/irqdomain.c +8 -5
index 41c1564..9e99054 100644
@@ -10,6 +10,7 @@
 #include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/topology.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/smp.h>
@@ -45,7 +46,8 @@ static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
 {
 	struct irq_domain *domain;
 
-	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
+	domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
+			      of_node_to_nid(of_node));
 	if (WARN_ON(!domain))
 		return NULL;
 
@@ -229,7 +231,8 @@ struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
 	struct irq_domain *domain;
 	unsigned int *revmap;
 
-	revmap = kzalloc(sizeof(*revmap) * size, GFP_KERNEL);
+	revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
+			      of_node_to_nid(of_node));
 	if (WARN_ON(!revmap))
 		return NULL;
 
@@ -367,7 +370,7 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
 	BUG_ON(domain = NULL);
 	WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP);
 
-	virq = irq_alloc_desc_from(1, 0);
+	virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
 	if (!virq) {
 		pr_debug("create_direct virq allocation failed\n");
 		return 0;
@@ -433,9 +436,9 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
 	hint = hwirq % nr_irqs;
 	if (hint = 0)
 		hint++;
-	virq = irq_alloc_desc_from(hint, 0);
+	virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
 	if (virq <= 0)
-		virq = irq_alloc_desc_from(1, 0);
+		virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
 	if (virq <= 0) {
 		pr_debug("-> virq allocation failed\n");
 		return 0;
Signature · 1 line
1.7.9.rc0.28.g0e1cf
author
#1 lore raw

PATCH 2/2 irqdomain: Support for static IRQ mapping and association.

This adds a new strict mapping API for supporting creation of linux IRQs at existing positions within the domain. The new routines are as follows:

For dynamic allocation and insertion to specified ranges:

- irq_create_identity_mapping()
- irq_create_strict_mappings()

These will allocate and associate a range of linux IRQs at the specified location. This can be used by controllers that have their own static linux IRQ definitions to map a hwirq range to, as well as for platforms that wish to establish 1:1 identity mapping between linux and hwirq space.

For insertion to specified ranges by platforms that do their own irq_desc management:

- irq_domain_associate()
- irq_domain_associate_many()

These in turn call back in to the domain's ->map() routine, for further processing by the platform. Disassociation of IRQs get handled through irq_dispose_mapping() as normal.

With these in place it should be possible to begin migration of legacy IRQ domains to linear ones, without requiring special handling for static vs dynamic IRQ definitions in DT vs non-DT paths. This also makes it possible for domains with static mappings to adopt whichever tree model best fits their needs, rather than simply restricting them to linear revmaps.

---
 include/linux/irqdomain.h |   15 +++++++
 kernel/irq/irqdomain.c    |   95 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 106 insertions(+), 4 deletions(-)
include/linux/irqdomain.h +15 -0
index 5abb533..7f8085c 100644
@@ -144,12 +144,27 @@ static inline struct irq_domain *irq_domain_add_legacy_isa(
 
 extern void irq_domain_remove(struct irq_domain *host);
 
+extern int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
+				irq_hw_number_t hwirq);
+extern int irq_domain_associate_many(struct irq_domain *domain,
+				     unsigned int irq_base,
+				     irq_hw_number_t hwirq_base, int count);
 extern unsigned int irq_create_mapping(struct irq_domain *host,
 				       irq_hw_number_t hwirq);
 extern void irq_dispose_mapping(unsigned int virq);
 extern unsigned int irq_find_mapping(struct irq_domain *host,
 				     irq_hw_number_t hwirq);
 extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
+extern int irq_create_strict_mappings(struct irq_domain *domain,
+				      unsigned int irq_base,
+				      irq_hw_number_t hwirq_base, int count);
+
+static inline int irq_create_identity_mapping(struct irq_domain *host,
+					      irq_hw_number_t hwirq)
+{
+	return irq_create_strict_mappings(host, hwirq, hwirq, 1);
+}
+
 extern void irq_radix_revmap_insert(struct irq_domain *host, unsigned int virq,
 				    irq_hw_number_t hwirq);
 extern unsigned int irq_radix_revmap_lookup(struct irq_domain *host,
kernel/irq/irqdomain.c +91 -4

125 lines not on this page · raw message

Signature · 1 line
1.7.9.rc0.28.g0e1cf
#2 lore raw

Re: [PATCH 2/2] irqdomain: Support for static IRQ mapping and association.

Quoted 26 lines · Paul Mundt
kernel/irq/irqdomain.c +26 -0
+/**
+ * irq_domain_associate_many() - Associate a range of hw irqs with linux irqs
+ * @domain: domain owning the interrupt range
+ * @irq_base: beginning of linux IRQ range
+ * @hwirq_base: beginning of hardware IRQ range
+ * @count: Number of interrupts to associate
+ *
+ * This routine takes care of creating an association between a range of
+ * hardware and linux IRQs using pre-existing IRQ allocations. For use by
+ * controllers that do their own irq_desc management.
+ */
+int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
+			      irq_hw_number_t hwirq_base, int count)
+{
+	int i, ret;
+
+	for (i = 0; i < count; i++) {
+		ret = irq_domain_associate(domain, irq_base + i,
+					   hwirq_base + i);
+		if (unlikely(ret))
+			goto unmap;
+	}
+
+	return 0;
+
+unmap:

kernel/irq/irqdomain.c static int irq_setup_virq(struct irq_domain *domain, unsigned int virq, · line 402

Quoted 10 lines
kernel/irq/irqdomain.c +10 -0
+	while (--i >= 0) {
+		if (domain->ops->unmap)
+			domain->ops->unmap(domain, irq_base + i);
+
+		irq_set_status_flags(irq_base + i, IRQ_NOREQUEST);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(irq_domain_associate_many);

Looks good, but I've flipped around the patch to make irq_domain_associate() a simple wrapper around irq_domain_associate_many() instead of the other way around. It makes for a bigger change to the existing irq_setup_virq() code, but in the end I think it makes more to keep all the logic in one place. I'll post my revised version.

I've also added sanity checks to make sure only allocated irq_descs can get associated. Otherwise the kernel will oops.

Quoted 23 lines
kernel/irq/irqdomain.c +23 -0
+/**
+ * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
+ * @domain: domain owning the interrupt range
+ * @irq_base: beginning of linux IRQ range
+ * @hwirq_base: beginning of hardware IRQ range
+ * @count: Number of interrupts to map
+ *
+ * This routine is used for allocating and mapping a range of hardware
+ * irqs to linux irqs where the linux irq numbers are at pre-defined
+ * locations. For use by controllers that already have static mappings
+ * to insert in to the domain.
+ *
+ * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
+ * domain insertion.
+ *
+ * 0 is returned upon success, while any failure to establish a static
+ * mapping is treated as an error.
+ */
+int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
+			       irq_hw_number_t hwirq_base, int count)
+{
+	int ret;
+

kernel/irq/irqdomain.c unsigned int irq_create_mapping(struct irq_domain *domain, · line 541

Quoted 10 lines
kernel/irq/irqdomain.c +10 -0
+	ret = irq_alloc_descs(irq_base, irq_base, count,
+			      of_node_to_nid(domain->of_node));
+	if (unlikely(ret < 0))
+		return ret;
+
+	ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
+	if (unlikely(ret < 0)) {
+		irq_free_descs(irq_base, count);
+		return ret;
+	}

It would be really good to make sure the hwirqs aren't already associated before trying to associate them again. Unfortunately that can't be done (nicely) until I get rid of the slow path lookup. I've got a patch for that which I'll rebase on top of this one and post soon.

g.

Quoted 11 lines
kernel/irq/irqdomain.c +5 -0
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
+
 unsigned int irq_create_of_mapping(struct device_node *controller,
 				   const u32 *intspec, unsigned int intsize)
 {
Signature · 1 line
1.7.9.rc0.28.g0e1cf
Signature · 2 lines
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
author
#3 lore raw

Re: [PATCH 2/2] irqdomain: Support for static IRQ mapping and association.

Quoted 13 lines · Grant Likely
Quoted 12 lines · Paul Mundt
kernel/irq/irqdomain.c +12 -0
+int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
+			       irq_hw_number_t hwirq_base, int count)
+{
+	int ret;
+
+	ret = irq_alloc_descs(irq_base, irq_base, count,
+			      of_node_to_nid(domain->of_node));
+	if (unlikely(ret < 0))
+		return ret;
+
+	ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
+	if (unlikely(ret < 0)) {
Quoted 9 lines

kernel/irq/irqdomain.c unsigned int irq_create_mapping(struct irq_domain *domain, · line 541

Quoted 3 lines
kernel/irq/irqdomain.c +3 -0
+		irq_free_descs(irq_base, count);
+		return ret;
+	}

It would be really good to make sure the hwirqs aren't already associated before trying to associate them again. Unfortunately that can't be done (nicely) until I get rid of the slow path lookup. I've got a patch for that which I'll rebase on top of this one and post soon.

Any updates on this? I have quite a few more changes I intend on making, but there's no point in starting in on that until these existing patches are sorted out.

#4 lore raw

Re: [PATCH 2/2] irqdomain: Support for static IRQ mapping and association.

Quoted 23 lines · Paul Mundt
Quoted 13 lines · Grant Likely
Quoted 12 lines · Paul Mundt
kernel/irq/irqdomain.c +12 -0
+int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
+                          irq_hw_number_t hwirq_base, int count)
+{
+   int ret;
+
+   ret = irq_alloc_descs(irq_base, irq_base, count,
+                         of_node_to_nid(domain->of_node));
+   if (unlikely(ret < 0))
+           return ret;
+
+   ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
+   if (unlikely(ret < 0)) {
Quoted 9 lines
Quoted 3 lines

+           irq_free_descs(irq_base, count);
+           return ret;
+   }

It would be really good to make sure the hwirqs aren't already associated before trying to associate them again.  Unfortunately that can't be done (nicely) until I get rid of the slow path lookup.  I've got a patch for that which I'll rebase on top of this one and post soon.

Quoted 3 lines

Any updates on this? I have quite a few more changes I intend on making, but there's no point in starting in on that until these existing patches are sorted out.

Yeah, I made some progress and have a whole bunch of patches to post which I had hoped to do last week. Unfortunately the move to the UK has meant that the last 7 days have been non-stop cleaning, packing and throwing out stuff. I've not been able to do a final cleanup. The house gets cleaned on Tuesday so it can go on the market on Wednesday which means all the house stuff must be done by Monday evening. Hopefully I'll get some time on Tuesday to do some hacking.

If you want to look at them I've pushed them out to the irqdomain/test branch on git.secretlab.ca.

g.

author
#5 lore raw

Re: [PATCH 2/2] irqdomain: Support for static IRQ mapping and association.

Quoted 11 lines · Grant Likely
Quoted 9 lines · Paul Mundt
Quoted 5 lines · Grant Likely

It would be really good to make sure the hwirqs aren't already associated before trying to associate them again. ?Unfortunately that can't be done (nicely) until I get rid of the slow path lookup. ?I've got a patch for that which I'll rebase on top of this one and post soon.

Any updates on this? I have quite a few more changes I intend on making, but there's no point in starting in on that until these existing patches are sorted out.

Quoted 8 lines

Yeah, I made some progress and have a whole bunch of patches to post which I had hoped to do last week. Unfortunately the move to the UK has meant that the last 7 days have been non-stop cleaning, packing and throwing out stuff. I've not been able to do a final cleanup. The house gets cleaned on Tuesday so it can go on the market on Wednesday which means all the house stuff must be done by Monday evening. Hopefully I'll get some time on Tuesday to do some hacking.

No worries, life happens. Just wanted to make sure you hadn't forgotten about them!

Quoted 3 lines

If you want to look at them I've pushed them out to the irqdomain/test branch on git.secretlab.ca.

Thanks, I've fetched them and been hacking on them a bit. Fortunately you already did some the work I had intended on doing, particularly in relation to slow vs fast-path lookups, so there hasn't been much more for me to do.

That being said, you forgot about legacy domains with non-zero hwirq bases in your legacy -> linear revmap conversion, so some (or all) of those IRQs will now find themselves stuffed in the radix tree instead..

I already got bitten by this trying to figure out why my batched disposal helper wasn't doing its job and my linear domain was tripping over the non-zero radix root height warn at domain removal time, so that's fixed now.

Patches to follow (also in the common/irqdomain topic branch in my github tree).

Applied
#6 lore raw
In reply to Paul Mundt
Quoted 12 lines · Paul Mundt

While common irqdesc allocation is node aware, the irqdomain code is not.

Presently we observe a number of regressions/inconsistencies on NUMA-capable platforms:

- Platforms using irqdomains with legacy mappings, where the irq_descs are allocated node-local and the irqdomain data structure is not.

- Drivers implementing irqdomains will lose node locality regardless of the underlying struct device's node id.

Quoted 7 lines

This plugs in NUMA node id proliferation across the various allocation callsites by way of_node_to_nid() node lookup. While of_node_to_nid() does the right thing for OF-capable platforms it doesn't presently handle the non-DT case. This is trivially dealt with by simply wraping in to numa_node_id() unconditionally.

Queued for v3.6, Thanks.

g.

Quoted 102 lines
---
 include/linux/of.h     |   16 ++++++++++------
 kernel/irq/irqdomain.c |   13 ++++++++-----
 2 files changed, 18 insertions(+), 11 deletions(-)
include/linux/of.h +10 -6
index fa7fb1d..8650544 100644
@@ -21,7 +21,7 @@
 #include <linux/kref.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spinlock.h>
-
+#include <linux/topology.h>
 #include <asm/byteorder.h>
 #include <asm/errno.h>
 
@@ -158,11 +158,6 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
 
 #define OF_BAD_ADDR	((u64)-1)
 
-#ifndef of_node_to_nid
-static inline int of_node_to_nid(struct device_node *np) { return -1; }
-#define of_node_to_nid of_node_to_nid
-#endif
-
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
 #define for_each_node_by_name(dn, name) \
@@ -351,6 +346,15 @@ static inline int of_machine_is_compatible(const char *compat)
 #define of_match_node(_matches, _node)	NULL
 #endif /* CONFIG_OF */
 
+#ifndef of_node_to_nid
+static inline int of_node_to_nid(struct device_node *np)
+{
+	return numa_node_id();
+}
+
+#define of_node_to_nid of_node_to_nid
+#endif
+
 /**
  * of_property_read_bool - Findfrom a property
  * @np:		device node from which the property value is to be read.
kernel/irq/irqdomain.c +8 -5
index 41c1564..9e99054 100644
@@ -10,6 +10,7 @@
 #include <linux/mutex.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/topology.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/smp.h>
@@ -45,7 +46,8 @@ static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
 {
 	struct irq_domain *domain;
 
-	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
+	domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
+			      of_node_to_nid(of_node));
 	if (WARN_ON(!domain))
 		return NULL;
 
@@ -229,7 +231,8 @@ struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
 	struct irq_domain *domain;
 	unsigned int *revmap;
 
-	revmap = kzalloc(sizeof(*revmap) * size, GFP_KERNEL);
+	revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
+			      of_node_to_nid(of_node));
 	if (WARN_ON(!revmap))
 		return NULL;
 
@@ -367,7 +370,7 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
 	BUG_ON(domain = NULL);
 	WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP);
 
-	virq = irq_alloc_desc_from(1, 0);
+	virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
 	if (!virq) {
 		pr_debug("create_direct virq allocation failed\n");
 		return 0;
@@ -433,9 +436,9 @@ unsigned int irq_create_mapping(struct irq_domain *domain,
 	hint = hwirq % nr_irqs;
 	if (hint = 0)
 		hint++;
-	virq = irq_alloc_desc_from(hint, 0);
+	virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
 	if (virq <= 0)
-		virq = irq_alloc_desc_from(1, 0);
+		virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
 	if (virq <= 0) {
 		pr_debug("-> virq allocation failed\n");
 		return 0;
Signature · 1 line
1.7.9.rc0.28.g0e1cf
Signature · 2 lines
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.