irq: Add CPU mask affinity hint
Subsystems (3)
PATCH v3 1/2 irq: Add CPU mask affinity hint
This patch adds a cpumask affinity hint to the irq_desc structure, along with a registration function and a read-only proc entry for each interrupt.
This affinity_hint handle for each interrupt can be used by underlying drivers that need a better mechanism to control interrupt affinity. The underlying driver can register a cpumask for the interrupt, which will allow the driver to provide the CPU mask for the interrupt to anything that requests it. The intent is to extend the userspace daemon, irqbalance, to help hint to it a preferred CPU mask to balance the interrupt into.
---
include/linux/interrupt.h | 7 +++++++ include/linux/irq.h | 1 + kernel/irq/manage.c | 19 +++++++++++++++++++ kernel/irq/proc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 0 deletions(-)
include/linux/interrupt.h +7 -0
@@ -209,6 +209,8 @@ extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);extern int irq_can_set_affinity (unsigned int irq);extern int irq_select_affinity (unsigned int irq); +extern int irq_register_affinity_hint (unsigned int irq, +const struct cpumask *m);#else /* CONFIG_SMP */ static inline int irq_set_affinity (unsigned int irq,const struct cpumask *m)
@@ -223,6 +225,11 @@ static inline int irq_can_set_affinity(unsigned int irq)static inline int irq_select_affinity (unsigned int irq) {return 0 ; } +static inline int irq_register_affinity_hint (unsigned int irq, +const struct cpumask *m) +{ +return -EINVAL ; +}#endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */ #ifdef CONFIG_GENERIC_HARDIRQS
include/linux/irq.h +1 -0
@@ -206,6 +206,7 @@ struct irq_desc {struct proc_dir_entry *dir;#endif const char *name; +struct cpumask *affinity_hint; }____cacheline_internodealigned_in_smp ; extern void arch_init_copy_chip_data(struct irq_desc *old_desc,
kernel/irq/manage.c +19 -0
@@ -138,6 +138,22 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)return 0 ; } +int irq_register_affinity_hint (unsigned int irq,const struct cpumask *m) +{ +struct irq_desc *desc =irq_to_desc (irq); +unsigned long flags; + +if (!desc) +return -EINVAL ; + +raw_spin_lock_irqsave (&desc->lock, flags); + desc->affinity_hint = m; +raw_spin_unlock_irqrestore (&desc->lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (irq_register_affinity_hint); +#ifndef CONFIG_AUTO_IRQ_AFFINITY /* * Generic version of the affinity autoselector.
@@ -916,6 +932,9 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id) desc->chip->disable (irq); } +/* make sure affinity_hint is cleaned up */ + desc->affinity_hint =NULL ; +raw_spin_unlock_irqrestore (&desc->lock, flags);unregister_handler_proc (irq, action);
kernel/irq/proc.c +42 -0
66 lines not on this page · raw message
PATCH v3 2/2 ixgbe: Example usage of the new IRQ affinity_hint callback
This patch uses the new IRQ affinity_hint callback mechanism. It serves purely as an example of how a low-level driver can utilize this new interface.
An official ixgbe patch will be pushed through netdev once the IRQ patches have been accepted and merged.
---
drivers/net/ixgbe/ixgbe.h | 2 ++ drivers/net/ixgbe/ixgbe_main.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletions(-)
drivers/net/ixgbe/ixgbe.h +2 -0
@@ -32,6 +32,7 @@#include <linux/pci.h> #include <linux/netdevice.h> #include <linux/aer.h> +#include <linux/cpumask.h> #include "ixgbe_type.h" #include "ixgbe_common.h"
@@ -236,6 +237,7 @@ struct ixgbe_q_vector {u8 tx_itr;u8 rx_itr;u32 eitr; +cpumask_var_t affinity_mask; };/* Helper macros to switch between ints/sec and what the register uses.
drivers/net/ixgbe/ixgbe_main.c +20 -1
@@ -1083,6 +1083,16 @@ static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) q_vector->eitr = adapter->rx_eitr_param;ixgbe_write_eitr (q_vector); + +/* +* Allocate the affinity_hint cpumask, assign the mask for +* this vector, and register our affinity_hint for this irq. +*/ +if (!alloc_cpumask_var (&q_vector->affinity_mask,GFP_KERNEL )) +return ; +cpumask_set_cpu (v_idx, q_vector->affinity_mask); +irq_register_affinity_hint (adapter->msix_entries[v_idx].vector, + q_vector->affinity_mask); }if (adapter->hw.mac.type == ixgbe_mac_82598EB)
@@ -3218,7 +3228,7 @@ void ixgbe_down(struct ixgbe_adapter *adapter)struct ixgbe_hw *hw = &adapter->hw;u32 rxctrl;u32 txdctl; -int i, j; +int i, j, num_q_vectors = adapter->num_msix_vectors -NON_Q_VECTORS ;/* signal that we are down to the interrupt handler */ set_bit (__IXGBE_DOWN, &adapter->state);
@@ -3251,6 +3261,15 @@ void ixgbe_down(struct ixgbe_adapter *adapter)ixgbe_napi_disable_all (adapter); +for (i =0 ; i < num_q_vectors; i++) { +struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; +/* release the CPU mask memory */ +free_cpumask_var (q_vector->affinity_mask); +/* clear the affinity_mask in the IRQ descriptor */ +irq_register_affinity_hint (adapter->msix_entries[i].vector, +NULL ); + } +clear_bit (__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);del_timer_sync (&adapter->sfp_timer);del_timer_sync (&adapter->watchdog_timer);
Peter,
include/linux/interrupt.h extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask); · line 213
Quoted 3 lines · Peter P Waskiewicz Jr
include/linux/interrupt.h +2
-0+extern int irq_register_affinity_hint (unsigned int irq, +const struct cpumask *m);
One last nitpick.
Can you please rename to irq_set_affinity_hint() ?
Otherwise, I'm happy with the outcome. Thanks for your patience!
Thanks,
tglx
Quoted 10 lines · Thomas Gleixner
Peter,
include/linux/interrupt.h extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask); · line 213
Quoted 3 lines · Peter P Waskiewicz Jr
include/linux/interrupt.h +2
-0+extern int irq_register_affinity_hint (unsigned int irq, +const struct cpumask *m);One last nitpick.
Can you please rename to
irq_set_affinity_hint()?
Not a problem. It's a better name anyways now that we've dropped the callback function. Patch update incoming.
Quoted 2 lines
Otherwise, I'm happy with the outcome. Thanks for your patience!
Thanks for your help getting this pulled together. This is a big step for our performance tuning goals.
Cheers,
-PJ
Quoted 14 lines · Peter P Waskiewicz Jr
This patch adds a cpumask affinity hint to the
irq_descstructure, along with a registration function and a read-only proc entry for each interrupt.This
affinity_hinthandle for each interrupt can be used by underlying drivers that need a better mechanism to control interrupt affinity. The underlying driver can register a cpumask for the interrupt, which will allow the driver to provide the CPU mask for the interrupt to anything that requests it. The intent is to extend the userspace daemon, irqbalance, to help hint to it a preferred CPU mask to balance the interrupt into.Signed-off-by Peter P Waskiewicz Jr <[email protected]>
[...]
Quoted 5 lines
kernel/irq/manage.c +0
-0
kernel/irq/manage.c int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask) · line 147
Quoted 10 lines
kernel/irq/manage.c +7
-0@@ -138,6 +138,22 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)return 0 ; } +int irq_register_affinity_hint (unsigned int irq,const struct cpumask *m) +{ +struct irq_desc *desc =irq_to_desc (irq); +unsigned long flags; + +if (!desc) +return -EINVAL ;
Is it possible for irq_to_desc(irq) to be NULL? This function already assumes that the caller 'owns' the IRQ.
Quoted 6 lines
kernel/irq/manage.c +6
-0+raw_spin_lock_irqsave (&desc->lock, flags); + desc->affinity_hint = m; +raw_spin_unlock_irqrestore (&desc->lock, flags); + +return 0 ; +}
[...]
Quoted 23 lines
kernel/irq/proc.c +15
-0@@ -32,6 +32,32 @@ static int irq_affinity_proc_show(struct seq_file *m, void *v)return 0 ; } +static int irq_affinity_hint_proc_show (struct seq_file *m,void *v) +{ +struct irq_desc *desc =irq_to_desc ((long )m->private); +unsigned long flags; +cpumask_var_t mask; +int ret = -EINVAL ; + +if (!alloc_cpumask_var (&mask,GFP_KERNEL )) +return -ENOMEM ; + +raw_spin_lock_irqsave (&desc->lock, flags); +if (desc->affinity_hint) { +cpumask_copy (mask, desc->affinity_hint); + ret =0 ; + }
kernel/irq/proc.c static int irq_affinity_proc_show(struct seq_file *m, void *v) · line 59
Quoted 10 lines
kernel/irq/proc.c +10
-0+raw_spin_unlock_irqrestore (&desc->lock, flags); + +if (!ret) { +seq_cpumask (m, mask); +seq_putc (m,'\n' ); + } +free_cpumask_var (mask); + +return ret; +}
[...]
I don't think this should be returning -EINVAL if the affinity hint is missing. That means 'invalid argument', but there is nothing invalid about trying to read() the corresponding file. The file should simply be empty if there is no hint. (Actually it might be better if it didn't appear at all, but that would be a pain to implement.)
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 11 lines · Ben Hutchings
kernel/irq/manage.c int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask) · line 147
Quoted 7 lines · Peter P Waskiewicz Jr
kernel/irq/manage.c +7
-0+int irq_register_affinity_hint (unsigned int irq,const struct cpumask *m) +{ +struct irq_desc *desc =irq_to_desc (irq); +unsigned long flags; + +if (!desc) +return -EINVAL ;Is it possible for
irq_to_desc(irq)to be NULL? This function already assumes that the caller 'owns' the IRQ.
Oh come on. Driver writers get everything wrong and not checking on an invalid irq number is better than crashing :)
Quoted 4 lines
Quoted 4 lines
kernel/irq/proc.c +4
-0+static int irq_affinity_hint_proc_show (struct seq_file *m,void *v) +{ +struct irq_desc *desc =irq_to_desc ((long )m->private); +unsigned long flags;
Quoted 8 lines
kernel/irq/proc.c static int irq_affinity_proc_show(struct seq_file *m, void *v) · line 40
Quoted 2 lines
kernel/irq/proc.c +2
-0+cpumask_var_t mask; +int ret = -EINVAL ;I don't think this should be returning
-EINVALif the affinity hint is missing. That means 'invalid argument', but there is nothing invalid about trying toread()the corresponding file. The file should simply be empty if there is no hint. (Actually it might be better if it didn't appear at all, but that would be a pain to implement.)
I agree that -EINVAL is not really a good match.
How about just returning CPU_MASK_ALL if desc->affinity_hint is not set ?
Thanks,
tglx
Quoted 29 lines · Thomas Gleixner
Quoted 11 lines · Ben Hutchings
kernel/irq/manage.c int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask) · line 147
Quoted 7 lines · Peter P Waskiewicz Jr
kernel/irq/manage.c +7
-0+int irq_register_affinity_hint (unsigned int irq,const struct cpumask *m) +{ +struct irq_desc *desc =irq_to_desc (irq); +unsigned long flags; + +if (!desc) +return -EINVAL ;Is it possible for
irq_to_desc(irq)to be NULL? This function already assumes that the caller 'owns' the IRQ.Oh come on. Driver writers get everything wrong and not checking on an invalid irq number is better than crashing :)
Quoted 4 lines
Quoted 4 lines
kernel/irq/proc.c +4
-0+static int irq_affinity_hint_proc_show (struct seq_file *m,void *v) +{ +struct irq_desc *desc =irq_to_desc ((long )m->private); +unsigned long flags;Quoted 8 lines
kernel/irq/proc.c static int irq_affinity_proc_show(struct seq_file *m, void *v) · line 40
Quoted 2 lines
kernel/irq/proc.c +2
-0+cpumask_var_t mask; +int ret = -EINVAL ;I don't think this should be returning
-EINVALif the affinity hint is missing. That means 'invalid argument', but there is nothing invalid about trying toread()the corresponding file. The file should simply be empty if there is no hint. (Actually it might be better if it didn't appear at all, but that would be a pain to implement.)
Quoted 4 lines
I agree that
-EINVALis not really a good match.How about just returning
CPU_MASK_ALLifdesc->affinity_hintis not set ?
That seems reasonable to me.
cheers,
-PJ