irq: Add CPU mask affinity hint
Subsystems (3)
PATCH v4 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 | 6 ++++++ include/linux/irq.h | 1 + kernel/irq/manage.c | 19 +++++++++++++++++++ kernel/irq/proc.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 0 deletions(-)
include/linux/interrupt.h +6 -0
@@ -209,6 +209,7 @@ 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_set_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 +224,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_set_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_set_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_set_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 +39 -0
@@ -32,6 +32,29 @@ 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; + +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); +else +cpumask_setall (mask); +raw_spin_unlock_irqrestore (&desc->lock, flags); + +seq_cpumask (m, mask); +seq_putc (m,'\n' ); +free_cpumask_var (mask); + +return 0 ; +} +#ifndef is_affinity_mask_valid#define is_affinity_mask_valid (val) 1#endif
@@ -84,6 +107,11 @@ static int irq_affinity_proc_open(struct inode *inode, struct file *file)return single_open (file, irq_affinity_proc_show,PDE (inode)->data); } +static int irq_affinity_hint_proc_open (struct inode *inode,struct file *file) +{ +return single_open (file, irq_affinity_hint_proc_show,PDE (inode)->data); +} +static const struct file_operations irq_affinity_proc_fops = { .open = irq_affinity_proc_open, .read = seq_read,
@@ -92,6 +120,13 @@ static const struct file_operations irq_affinity_proc_fops = { .write = irq_affinity_proc_write, }; +static const struct file_operations irq_affinity_hint_proc_fops = { + .open = irq_affinity_hint_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static int default_affinity_show (struct seq_file *m,void *v) {seq_cpumask (m, irq_default_affinity);
@@ -231,6 +266,10 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)/* create /proc/irq/<irq>/smp_affinity */ proc_create_data ("smp_affinity" ,0600 , desc->dir, &irq_affinity_proc_fops, (void *)(long )irq); + +/* create /proc/irq/<irq>/affinity_hint */ +proc_create_data ("affinity_hint" ,0400 , desc->dir, + &irq_affinity_hint_proc_fops, (void *)(long )irq);#endif proc_create_data("spurious", 0444, desc->dir,
PATCH v4 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 | 20 +++++++++++++++++++- 2 files changed, 21 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 +19 -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 set 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_set_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,14 @@ 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_set_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);
Re: [PATCH linux-next v4 2/2] ixgbe: Example usage of the new IRQ affinity_hint callback
drivers/net/ixgbe/ixgbe_main.c void ixgbe_down(struct ixgbe_adapter *adapter) · line 3269
Quoted 6 lines · Peter P Waskiewicz Jr
drivers/net/ixgbe/ixgbe_main.c +6
-0+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_set_affinity_hint (adapter->msix_entries[i].vector,NULL );
Freeing the mask _AFTER_ clearing the hint might be a worthwhile exercise :)
Thanks,
tglx
Re: [PATCH linux-next v4 2/2] ixgbe: Example usage of the new IRQ affinity_hint callback
Quoted 10 lines · Thomas Gleixner
drivers/net/ixgbe/ixgbe_main.c void ixgbe_down(struct ixgbe_adapter *adapter) · line 3269
Quoted 6 lines · Peter P Waskiewicz Jr
drivers/net/ixgbe/ixgbe_main.c +6
-0+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_set_affinity_hint (adapter->msix_entries[i].vector,NULL );Freeing the mask _AFTER_ clearing the hint might be a worthwhile exercise :)
Crap. I had it reversed before, then when I dropped the unregister call it got swapped. I'll fix it on the official submission for this one.
This patch is just an example patch, not to be merged just now. Once the IRQ side is merged, and DaveM has that pulled into a tree, I'll send an official ixgbe patch using the API. But I'll be sure to have this fixed before sending. :-)
-PJ
[tip:irq/core] genirq: Add CPU mask affinity hint
In reply to Peter P Waskiewicz JrCommit-ID: e7a297b0d7d6049bd4e423ac1e17da31e4c401b8 Gitweb: http://git.kernel.org/tip/e7a297b0d7d6049bd4e423ac1e17da31e4c401b8 Author: Peter P Waskiewicz Jr <[email protected]> AuthorDate: Fri, 30 Apr 2010 14:44:50 -0700 Committer: Thomas Gleixner <[email protected]> CommitDate: Mon, 3 May 2010 11:50:57 +0200
genirq: 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.
[ tglx: Fixed compile warnings, added WARN_ON, made SMP only ]
LKML-Reference: <[email protected]>
--- include/linux/interrupt.h | 6 ++++++ include/linux/irq.h | 1 + kernel/irq/manage.c | 22 ++++++++++++++++++++++ kernel/irq/proc.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 0 deletions(-)
include/linux/interrupt.h +6 -0
@@ -233,6 +233,7 @@ 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_set_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)
@@ -247,6 +248,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_set_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
@@ -195,6 +195,7 @@ struct irq_desc {raw_spinlock_t lock;#ifdef CONFIG_SMP cpumask_var_t affinity; +const struct cpumask *affinity_hint;unsigned int node;#ifdef CONFIG_GENERIC_PENDING_IRQ cpumask_var_t pending_mask;
kernel/irq/manage.c +22 -0
@@ -138,6 +138,22 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)return 0 ; } +int irq_set_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_set_affinity_hint); +#ifndef CONFIG_AUTO_IRQ_AFFINITY /* * Generic version of the affinity autoselector.
@@ -906,6 +922,12 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id) desc->chip->disable (irq); } +#ifdef CONFIG_SMP +/* make sure affinity_hint is cleaned up */ +if (WARN_ON_ONCE (desc->affinity_hint)) + desc->affinity_hint =NULL ; +#endif +raw_spin_unlock_irqrestore (&desc->lock, flags);unregister_handler_proc (irq, action);
kernel/irq/proc.c +39 -0
@@ -32,6 +32,29 @@ 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; + +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); +else +cpumask_setall (mask); +raw_spin_unlock_irqrestore (&desc->lock, flags); + +seq_cpumask (m, mask); +seq_putc (m,'\n' ); +free_cpumask_var (mask); + +return 0 ; +} +#ifndef is_affinity_mask_valid#define is_affinity_mask_valid (val) 1#endif
@@ -84,6 +107,11 @@ static int irq_affinity_proc_open(struct inode *inode, struct file *file)return single_open (file, irq_affinity_proc_show,PDE (inode)->data); } +static int irq_affinity_hint_proc_open (struct inode *inode,struct file *file) +{ +return single_open (file, irq_affinity_hint_proc_show,PDE (inode)->data); +} +static const struct file_operations irq_affinity_proc_fops = { .open = irq_affinity_proc_open, .read = seq_read,
@@ -92,6 +120,13 @@ static const struct file_operations irq_affinity_proc_fops = { .write = irq_affinity_proc_write, }; +static const struct file_operations irq_affinity_hint_proc_fops = { + .open = irq_affinity_hint_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static int default_affinity_show (struct seq_file *m,void *v) {seq_cpumask (m, irq_default_affinity);
@@ -252,6 +287,10 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)proc_create_data ("smp_affinity" ,0600 , desc->dir, &irq_affinity_proc_fops, (void *)(long )irq); +/* create /proc/irq/<irq>/affinity_hint */ +proc_create_data ("affinity_hint" ,0400 , desc->dir, + &irq_affinity_hint_proc_fops, (void *)(long )irq); +proc_create_data ("node" ,0444 , desc->dir, &irq_node_proc_fops, (void *)(long )irq);#endif