Skip to contentSkip to conversation

kernel/irq: allow more precise irq affinity policies

RFC/PATCH Arthur Kepner 2 participants 2 messages Sep 6, 2010 – Sep 9, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

SGI has encountered situations where particular CPUs run out of interrupt vectors on systems with many (several hundred or more) CPUs. This happens because some drivers (particularly the mlx4_core driver) select the number of interrupts they allocate based on the number of CPUS, and because of how the default irq affinity is used.

The following patch allows for a more precise policy about how irq affinities are assigned by the kernel (though it doesn't implement any new policy, except for a practically useless example).

This is a work in progress. I know that it needs several additional things, including:

- redistribute interrupts when the 'current_irq_policy' is updated (for now it only affects irqs allocated after the policy is changed)

- a means to notify drivers about irq_policy changes (so they can adjust network queues, etc.)

Would appreciate comments.

---

 include/linux/irq_policy.h |   21 +++++++++++
 init/Kconfig               |    8 ++++
 kernel/irq/Makefile        |    2 -
 kernel/irq/handle.c        |    5 ++
 kernel/irq/manage.c        |    3 +
 kernel/irq/policy.c        |   84 +++++++++++++++++++++++++++++++++++++++++++++
 kernel/irq/proc.c          |   52 +++++++++++++++++++++++++++
 7 files changed, 173 insertions(+), 2 deletions(-)
include/linux/irq_policy.h new file +21 -0
new file mode 100644
index 0000000..5708088
@@ -0,0 +1,21 @@
+#ifndef _LINUX_IRQ_POLICY_H
+#define _LINUX_IRQ_POLICY_H
+
+struct irq_policy {
+	char *name;
+	void (*apply) (struct cpumask *); /* apply the policy */
+};
+
+extern struct irq_policy *current_irq_policy;
+extern struct mutex irq_policy_mutex; /* protect current_irq_policy */
+
+void __init init_irq_policy(void);
+void irq_policy_select(char *str);
+void irq_policy_apply(struct cpumask *dest);
+
+void apply_default(struct cpumask *dest);
+#ifdef CONFIG_IRQ_POLICY_1
+void apply_policy1(struct cpumask *dest);
+#endif /* CONFIG_IRQ_POLICY_1 */
+
+#endif /* _LINUX_IRQ_POLICY_H */
init/Kconfig +8 -0
index 2de5b1c..d38f18b 100644
@@ -1263,4 +1263,12 @@ config PADATA
 	depends on SMP
 	bool
 
+config IRQ_POLICY_1
+	bool
+	default n
+	depends on SMP
+	help
+	  Silly example - place all interrupts on CPU1. Not intended for
+	  real use. Say N.
+
 source "kernel/Kconfig.locks"
kernel/irq/Makefile +1 -1
index 7d04780..0532082 100644
@@ -1,5 +1,5 @@
 
-obj-y := handle.o manage.o spurious.o resend.o chip.o devres.o
+obj-y := handle.o manage.o spurious.o resend.o chip.o devres.o policy.o
 obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o
 obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o
kernel/irq/handle.c +5 -0
index 27e5c69..a4f1087 100644
@@ -21,6 +21,7 @@
 #include <linux/hash.h>
 #include <linux/radix-tree.h>
 #include <trace/events/irq.h>
+#include <linux/irq_policy.h>
 
 #include "internals.h"
 
@@ -171,6 +172,8 @@ int __init early_irq_init(void)
 
 	init_irq_default_affinity();
 
+	init_irq_policy();
+
 	 /* initialize nr_irqs based on nr_cpu_ids */
 	arch_probe_nr_irqs();
 	printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs);
@@ -258,6 +261,8 @@ int __init early_irq_init(void)
 
 	init_irq_default_affinity();
 
+	init_irq_policy();
+
 	printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
 
 	desc = irq_desc;
kernel/irq/manage.c +2 -1
index c3003e9..06533e3 100644
@@ -14,6 +14,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/irq_policy.h>
 
 #include "internals.h"
 
@@ -175,7 +176,7 @@ static int setup_affinity(unsigned int irq, struct irq_desc *desc)
 			desc->status &= ~IRQ_AFFINITY_SET;
 	}
 
-	cpumask_and(desc->affinity, cpu_online_mask, irq_default_affinity);
+	irq_policy_apply(desc->affinity);
 set_affinity:
 	desc->chip->set_affinity(irq, desc->affinity);
 
kernel/irq/policy.c new file +84 -0

84 lines not on this page · raw message

kernel/irq/proc.c +52 -0

76 lines not on this page · raw message

#1 lore raw
Quoted 10 lines · Arthur Kepner

SGI has encountered situations where particular CPUs run out of interrupt vectors on systems with many (several hundred or more) CPUs. This happens because some drivers (particularly the mlx4_core driver) select the number of interrupts they allocate based on the number of CPUS, and because of how the default irq affinity is used.

The following patch allows for a more precise policy about how irq affinities are assigned by the kernel (though it doesn't implement any new policy, except for a practically useless example).

Quoted 6 lines

This is a work in progress. I know that it needs several additional things, including:

- redistribute interrupts when the 'current_irq_policy' is updated (for now it only affects irqs allocated after the policy is changed)

We implement mechanisms not policies in the kernel. And we already have a mechanism to redistribute interrupts.

Let's look at the problem you're tyring to solve.

Your network driver wants to use one interrupt per cpu, which are now assigned to a single core due to the way the default irq affinity settings work. On a large system this exceeds the number of vectors per cpu. Ok, that's bad.

But now you try to solve that problem with magic policies in the generic irq code. That's wrong.

What you really want is a way to tell the generic code that your driver would like to see a particular interrupt assigned to a particular core, right ?

We already have the affinity_hint mechanism in place, which allows a driver to give a hint to the user space irq balancer, which of course does not help if your device comes up before user space runs.

So the obvious solution is to extend that mechanism and let the kernel use the affinity hint as a first selection criteria as well - user space can still override it.

That's a trivial change and does not impose any policies on the kernel.

Quoted 2 lines

- a means to notify drivers about irq_policy changes (so they can adjust network queues, etc.)

I can understand that, but again it's not about policies. What you want is a callback into the driver which is called _before_ a user space irq affinity setting is applied. That way a driver could even veto such a change if there are hard restrictions on which core or node it can be placed.

OTOH, it's more straight forward to tell the driver to move a specific queue to a specific core and handle it from there. That keeps the magic confined to the driver and does not affect generic code.

Thanks,

tglx