net: Automatic IRQ siloing for network devices
Subsystems (3)
Automatic IRQ siloing for network devices
At last years netconf:
http://vger.kernel.org/netconf2010.html
Tom Herbert gave a talk in which he outlined some of the things we can do to improve scalability and througput in our network stack
One of the big items on the slides was the notion of siloing irqs, which is the practice of setting irq affinity to a cpu or cpu set that was 'close' to the process that would be consuming data. The idea was to ensure that a hard irq for a nic (and its subsequent softirq) would execute on the same cpu as the process consuming the data, increasing cache hit rates and speeding up overall throughput.
I had taken an idea away from that talk, and have finally gotten around to implementing it. One of the problems with the above approach is that its all quite manual. I.e. to properly enact this siloiong, you have to do a few things by hand:
1) decide which process is the heaviest user of a given rx queue
2) restrict the cpus which that task will run on
3) identify the irq which the rx queue in (1) maps to
4) manually set the affinity for the irq in (3) to cpus which match the cpus in
(2)
That configuration of course has to change in response to workload changed (what if your consumer process gets reworked so that its no longer the largest network user, etc).
I thought it would be good if we could automate some amount of this, and I think I've found a way to do that. With this patch set I introduce the ability to:
A) Register common affinity monitoring routines against a given irq which can implement various algorithms to determine a suggested placement of said irq's affinity
B) Add an algorithm to the network subsystem to track the amount of data that flows through each entry in a given rx_queues rps_flow_table, and uses that data to suggest an affinity for the irq associated with that rx queue.
This patchset lets these affinity suggestions get exported via the /proc/irq/<n>/affinity_hint interface (which is unused in the kernel with the exception of ixgbe). It also exports a new proc file affinity_alg which informs anyone interested in the affinity_hint how the hint is being computed.
Testing:
I've been running this patchset on my dual core system here with a cxgb4
as my network interface. I've been running a TCP STREAMS test from netperf in 2 minute increments under various conditions. I've found experimentally that (as you might expect) optimal performance is reached when irq affinity is bound to a core that is not the cpu core identified by the largest RFS flow, but is as close to it as possible (ideally sharing an L2 cache). In that way with we avoid the cpu contention between the softirq and the application, while still maximizing cache hits. In congunction with the irqbalance patch I hacked up here:
http://people.redhat.com/nhorman/irqbalance.patch
To steer irqs that have affinity using the rfs max weight algorithm to cpus that are as close as possible to the hinted cpu, I'm able to get approximately a 3% speedup in receive rates over the pessimal case, and about a 1% speedup over the nominal case (statically setting irq affinity to a single cpu).
Note: Currently this patch set only updates cxgb4 to use the new hinting mechanism. If this gets accepted, I have more cards to test with and plan to update them, but I thought for a first pass it would be better to simply update what I tested with.
Thoughts/Opinions appreciated
Thanks & Regards
Neil
PATCH 1/3 irq: Add registered affinity guidance infrastructure
From: nhorman <[email protected]>
This patch adds the needed data to the irq_desc struct, as well as the needed API calls to allow the requester of an irq to register a handler function to determine the affinity_hint of that irq when queried from user space.
--- include/linux/interrupt.h | 38 +++++++++++++++++++++++++++++++++++++- include/linux/irq.h | 9 +++++++++ include/linux/irqdesc.h | 4 ++++ kernel/irq/Kconfig | 12 +++++++++++- kernel/irq/manage.c | 39 +++++++++++++++++++++++++++++++++++++++ kernel/irq/proc.c | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 2 deletions(-)
include/linux/interrupt.h +37 -1
@@ -118,6 +118,17 @@ struct irqaction { }____cacheline_internodealigned_in_smp ;extern irqreturn_t no_action (int cpl,void *dev_id); +#ifdef CONFIG_AFFINITY_UPDATE +extern int setup_affinity_data (int irq,irq_affinity_init_t ,void *); +#else +static inline int setup_affinity_data (int irq, +irq_affinity_init_t init,void *d) +{ +return 0 ; +} +#endif + +extern void free_irq (unsigned int ,void *);#ifdef CONFIG_GENERIC_HARDIRQS extern int __must_check
@@ -125,6 +136,32 @@ request_threaded_irq(unsigned int irq, irq_handler_t handler,irq_handler_t thread_fn, unsigned long flags, const char *name, void *dev); +#ifdef CONFIG_AFFINITY_UPDATE +static inline int __must_check +request_affinity_irq (unsigned int irq,irq_handler_t handler, +irq_handler_t thread_fn, +unsigned long flags,const char *name,void *dev, +irq_affinity_init_t af_init,void *af_priv) +{ +int rc; + + rc =request_threaded_irq (irq, handler, thread_fn, flags, name, dev); +if (rc) + goto out; + +if (af_init) + rc =setup_affinity_data (irq, af_init, af_priv); +if (rc) +free_irq (irq, dev); + +out: +return rc; +} +#else +#define request_affinity_irq (irq, hnd, tfn, flg, nm, dev, init, priv) \ + request_threaded_irq(irq, hnd, NULL, flg, nm, dev) +#endif +static inline int __must_check request_irq (unsigned int irq,irq_handler_t handler,unsigned long flags,const char *name,void *dev)
@@ -167,7 +204,6 @@ request_any_context_irq(unsigned int irq, irq_handler_t handler,static inline void exit_irq_thread (void ) { }#endif -extern void free_irq (unsigned int ,void *);struct device ;
include/linux/irq.h +9 -0
@@ -30,6 +30,15 @@struct irq_desc ;struct irq_data ; +struct affin_data { +void *priv; +char *affinity_alg; +void (*affin_update)(int irq,struct affin_data *ad); +void (*affin_cleanup)(int irq,struct affin_data *ad); +}; + +typedef int (*irq_affinity_init_t )(int ,struct affin_data *,void *); +typedef void (*irq_flow_handler_t )(unsigned int irq,struct irq_desc *desc);typedef void (*irq_preflow_handler_t )(struct irq_data *data);
include/linux/irqdesc.h +4 -0
@@ -64,6 +64,10 @@ struct irq_desc {struct timer_rand_state *timer_rand_state;unsigned int __percpu *kstat_irqs;irq_flow_handler_t handle_irq; +#ifdef CONFIG_AFFINITY_UPDATE +struct affin_data *af_data; +#endif +#ifdef CONFIG_IRQ_PREFLOW_FASTEOI irq_preflow_handler_t preflow_handler;#endif
kernel/irq/Kconfig +11 -1
@@ -51,6 +51,17 @@ config IRQ_PREFLOW_FASTEOI config IRQ_FORCED_THREADING bool +config AFFINITY_UPDATE + bool "Support irq affinity direction" + depends on GENERIC_HARDIRQS + ---help--- + + Affinity updating adds the ability for requestors of irqs to + register affinity update methods against the irq in question + in so doing the requestor can be informed every time user space + queries an irq for its optimal affinity, giving the requstor the + chance to tell user space where the irq can be optimally handled + config SPARSE_IRQ bool "Support sparse irq numbering" depends on HAVE_SPARSE_IRQ
@@ -64,6 +75,5 @@ config SPARSE_IRQ out the interrupt descriptors in a more NUMA-friendly way. ) If you don't know what to do here, say N. - endmenu endif
kernel/irq/manage.c +39 -0
@@ -1159,6 +1159,17 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)unregister_handler_proc (irq, action); +#ifdef CONFIG_AFFINITY_UPDATE +/* +* Have to do this after we unregister proc accessors +*/ +if (desc->af_data) { +if (desc->af_data->affin_cleanup) + desc->af_data->affin_cleanup (irq, desc->af_data); +kfree (desc->af_data); + desc->af_data =NULL ; + } +#endif /* Make sure it's not being used on another CPU: */ synchronize_irq (irq);
@@ -1345,6 +1356,34 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler, }EXPORT_SYMBOL (request_threaded_irq); +#ifdef CONFIG_AFFINITY_UPDATE +int setup_affinity_data (int irq,irq_affinity_init_t af_init,void *af_priv) +{ +struct affin_data *data; +struct irq_desc *desc; +int rc; + + desc =irq_to_desc (irq); +if (!desc) +return -ENOENT ; + + data =kzalloc (sizeof (struct affin_data ),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + rc =af_init (irq, data, af_priv); +if (rc) { +kfree (data); +return rc; + } + + desc->af_data = data; + +return 0 ; +} +EXPORT_SYMBOL (setup_affinity_data); +#endif +/** * request_any_context_irq - allocate an interrupt line * @irq: Interrupt line to allocate
kernel/irq/proc.c +35 -0
@@ -42,6 +42,11 @@ static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)if (!zalloc_cpumask_var (&mask,GFP_KERNEL ))return -ENOMEM ; +#ifdef CONFIG_AFFINITY_UPDATE +if (desc->af_data && desc->af_data->affin_update) + desc->af_data->affin_update ((long )m->private, desc->af_data); +#endif +raw_spin_lock_irqsave (&desc->lock, flags);if (desc->affinity_hint)cpumask_copy (mask, desc->affinity_hint);
@@ -54,6 +59,19 @@ static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)return 0 ; } +static int irq_affinity_alg_proc_show (struct seq_file *m,void *v) +{ +char *alg ="none" ; +#ifdef CONFIG_AFFINITY_UPDATE +struct irq_desc *desc =irq_to_desc ((long )m->private); + +if (desc->af_data->affinity_alg) + alg = desc->af_data->affinity_alg; +#endif +seq_printf (m,"%s\n" , alg); +return 0 ; +} +#ifndef is_affinity_mask_valid#define is_affinity_mask_valid (val) 1#endif
@@ -110,6 +128,11 @@ 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 int irq_affinity_alg_proc_open (struct inode *inode,struct file *file) +{ +return single_open (file, irq_affinity_alg_proc_show,PDE (inode)->data); +} +static const struct file_operations irq_affinity_proc_fops = { .open = irq_affinity_proc_open, .read = seq_read,
@@ -125,6 +148,13 @@ static const struct file_operations irq_affinity_hint_proc_fops = { .release = single_release, }; +static const struct file_operations irq_affinity_alg_proc_fops = { + .open = irq_affinity_alg_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);
@@ -288,6 +318,11 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)/* create /proc/irq/<irq>/affinity_hint */ proc_create_data ("affinity_hint" ,0400 , desc->dir, &irq_affinity_hint_proc_fops, (void *)(long )irq); +#ifdef CONFIG_AFFINITY_UPDATE +/* Create /proc/irq/<irq>/affinity_alg */ +proc_create_data ("affinity_alg" ,0400 , desc->dir, + &irq_affinity_alg_proc_fops, (void *)(long )irq); +#endif proc_create_data ("node" ,0444 , desc->dir, &irq_node_proc_fops, (void *)(long )irq);
Signature · 1 line
1.7.4.2
Re: [PATCH 1/3] irq: Add registered affinity guidance infrastructure
Quoted 5 lines · Neil Horman
From: nhorman <[email protected]>
This patch adds the needed data to the
irq_descstruct, as well as the needed API calls to allow the requester of an irq to register a handler function to determine theaffinity_hintof that irq when queried from user space.
This changelog simply sucks. It does not explain the rationale for this churn at all.
Which problem is it solving?
Why are the current interfaces not sufficient?
....
include/linux/interrupt.h struct irqaction { · line 122
Quoted 2 lines
include/linux/interrupt.h +2
-0+#ifdef CONFIG_AFFINITY_UPDATE +extern int setup_affinity_data (int irq,irq_affinity_init_t ,void *);
yuck, irq_affinity_init_t ???
include/linux/interrupt.h request_threaded_irq(unsigned int irq, irq_handler_t handler, · line 144
Quoted 6 lines
include/linux/interrupt.h +6
-0+#ifdef CONFIG_AFFINITY_UPDATE +static inline int __must_check +request_affinity_irq (unsigned int irq,irq_handler_t handler, +irq_handler_t thread_fn, +unsigned long flags,const char *name,void *dev, +irq_affinity_init_t af_init,void *af_priv)
So next time we make a wrapper around request_affinity_irq() which takes another 3 arguments?
include/linux/interrupt.h request_threaded_irq(unsigned int irq, irq_handler_t handler, · line 150
Quoted 6 lines
include/linux/interrupt.h +6
-0+{ +int rc; + + rc =request_threaded_irq (irq, handler, thread_fn, flags, name, dev); +if (rc) + goto out;
Brilliant use case for a goto. _NOT_
include/linux/interrupt.h request_threaded_irq(unsigned int irq, irq_handler_t handler, · line 162
Quoted 11 lines
include/linux/interrupt.h +11
-0+if (af_init) + rc =setup_affinity_data (irq, af_init, af_priv); +if (rc) +free_irq (irq, dev); + +out: + return rc; +} +#else +#define request_affinity_irq (irq, hnd, tfn, flg, nm, dev, init, priv) \ + request_threaded_irq(irq, hnd, NULL, flg, nm, dev)
Oh nice. tfn becomes magically NULL if that magic CONFIG switch is not set.
Quoted 3 lines
struct
irq_desc;
structirq_data;
+structaffin_data{
Gah. Do you think that I went to major pain to consolidate the irq namespace just to accecpt another random one?
Also that's completely undocumented. Hint:
# grep -C1 "/\*\*" $this_file
include/linux/irq.h line 35
Quoted 2 lines
include/linux/irq.h +2
-0+void *priv; +char *affinity_alg;
const perhaps ?
include/linux/irq.h line 40
Quoted 5 lines
include/linux/irq.h +5
-0+void (*affin_update)(int irq,struct affin_data *ad); +void (*affin_cleanup)(int irq,struct affin_data *ad); +}; + +typedef int (*irq_affinity_init_t )(int ,struct affin_data *,void *);
Whee. Why do you want a typedef for that ?
kernel/irq/Kconfig config IRQ_PREFLOW_FASTEOI · line 56
Quoted 9 lines
kernel/irq/Kconfig +3
-0@@ -51,6 +51,17 @@ config IRQ_PREFLOW_FASTEOI config IRQ_FORCED_THREADING bool +config AFFINITY_UPDATE + bool "Support irq affinity direction" + depends on GENERIC_HARDIRQS
Right. We need a dependency for somthing which is inside of a guarded section which selects GENERIC_HARDIRQS.
kernel/irq/Kconfig config IRQ_PREFLOW_FASTEOI · line 63
Quoted 7 lines
kernel/irq/Kconfig +7
-0+ ---help--- + + Affinity updating adds the ability for requestors of irqs to + register affinity update methods against the irq in question + in so doing the requestor can be informed every time user space + queries an irq for its optimal affinity, giving the requstor the + chance to tell user space where the irq can be optimally handled
-ENOPARSE. I still do not understand what you are trying to solve.
kernel/irq/Kconfig config SPARSE_IRQ · line 67
Quoted 5 lines
kernel/irq/Kconfig +0
-1@@ -64,6 +75,5 @@ config SPARSE_IRQ out the interrupt descriptors in a more NUMA-friendly way. ) If you don't know what to do here, say N. -
Unrelated
Quoted 11 lines
kernel/irq/Kconfig +0
-0endmenu endifkernel/irq/manage.c +1
-0@@ -1159,6 +1159,17 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)unregister_handler_proc (irq, action); +#ifdef CONFIG_AFFINITY_UPDATE
kernel/irq/manage.c static struct irqaction *__free_irq(unsigned int irq, void *dev_id) · line 1172
Quoted 10 lines
kernel/irq/manage.c +10
-0+/* +* Have to do this after we unregister proc accessors +*/ +if (desc->af_data) { +if (desc->af_data->affin_cleanup) + desc->af_data->affin_cleanup (irq, desc->af_data); +kfree (desc->af_data); + desc->af_data =NULL ; + } +#endif
Grr. Aside of the fact, that I think that whole thing is silly and overengineered, please move this out of line and keep your fricking #ifdef mess out of the main code.
kernel/irq/manage.c int request_threaded_irq(unsigned int irq, irq_handler_t handler, · line 1360
Quoted 9 lines
kernel/irq/manage.c +2
-0/* Make sure it's not being used on another CPU: */ synchronize_irq (irq);@@ -1345,6 +1356,34 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler, }EXPORT_SYMBOL (request_threaded_irq); +#ifdef CONFIG_AFFINITY_UPDATE +int setup_affinity_data (int irq,irq_affinity_init_t af_init,void *af_priv)
That interface is completely wrong for various reasons:
1) Namespace violation: irq_....
2) This want's to be separated into a allocation and a setter function
Quoted 10 lines
kernel/irq/manage.c +10
-0+{ +struct affin_data *data; +struct irq_desc *desc; +int rc; + + desc =irq_to_desc (irq); +if (!desc) +return -ENOENT ; + + data =kzalloc (sizeof (struct affin_data ),GFP_KERNEL );
kernel/irq/manage.c int request_threaded_irq(unsigned int irq, irq_handler_t handler, · line 1380
Quoted 10 lines
kernel/irq/manage.c +10
-0+if (!data) +return -ENOMEM ; + + rc =af_init (irq, data, af_priv); +if (rc) { +kfree (data); +return rc; + } + + desc->af_data = data;
Right, we do this unlocked of course.
kernel/irq/manage.c int request_threaded_irq(unsigned int irq, irq_handler_t handler, · line 1384
Quoted 3 lines
kernel/irq/manage.c +3
-0+return 0 ; +} +EXPORT_SYMBOL (setup_affinity_data);
No. That want's to be EXPORT_SYMBOL_GPL if at all.
kernel/irq/proc.c static int irq_affinity_hint_proc_show(struct seq_file *m, void *v) · line 49
Quoted 11 lines
kernel/irq/proc.c +5
-0@@ -42,6 +42,11 @@ static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)if (!zalloc_cpumask_var (&mask,GFP_KERNEL ))return -ENOMEM ; +#ifdef CONFIG_AFFINITY_UPDATE +if (desc->af_data && desc->af_data->affin_update) + desc->af_data->affin_update ((long )m->private, desc->af_data); +#endif +
Yikes. How the hell is this related to the changelog and to the scope of this function?
This function shows the hint we agreed on and nothing else. We do not call magic crap via proc.
Locking is not your favourite topic, right ?
Quoted 6 lines
kernel/irq/proc.c +0
-0raw_spin_lock_irqsave (&desc->lock, flags);if (desc->affinity_hint)cpumask_copy (mask, desc->affinity_hint);@@ -54,6 +59,19 @@ static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)return 0 ; }
kernel/irq/proc.c static int irq_affinity_hint_proc_show(struct seq_file *m, void *v) · line 70
Quoted 10 lines
kernel/irq/proc.c +9
-0+static int irq_affinity_alg_proc_show (struct seq_file *m,void *v) +{ +char *alg ="none" ; +#ifdef CONFIG_AFFINITY_UPDATE +struct irq_desc *desc =irq_to_desc ((long )m->private); + +if (desc->af_data->affinity_alg) + alg = desc->af_data->affinity_alg; +#endif
Nice, we add the policy concept to the kernel another time. No, we don't want policies in the kernel except there is some reasonable explanation.
Thanks,
tglx
Re: [PATCH 1/3] irq: Add registered affinity guidance infrastructure
Quoted 11 lines · Thomas Gleixner
Quoted 5 lines · Neil Horman
From: nhorman <[email protected]>
This patch adds the needed data to the
irq_descstruct, as well as the needed API calls to allow the requester of an irq to register a handler function to determine theaffinity_hintof that irq when queried from user space.This changelog simply sucks. It does not explain the rationale for this churn at all.
It seems pretty clear to me. It allows a common function to update the value of affinity_hint when its queried.
Quoted 2 lines
Which problem is it solving?
Why are the current interfaces not sufficient?
Did you read the initial post that I sent with it? Apparently not. Apologies, its seems my git-send-email didn't cc everyone I expected it to:
http://marc.info/?l=linux-netdev&m=130291921026187&w=2
I'll skip the rest of your your email, and just try to turn some of your rant into something more acceptible to you.
Neil
PATCH 2/3 net: Add net device irq siloing feature
In reply to Neil HormanUsing the irq affinity infrastrucuture, we can now allow net devices to call request_irq using a new wrapper function (request_net_irq), which will attach a common affinty_update handler to each requested irq. This affinty update mechanism correlates each tracked irq to the flow(s) that said irq processes most frequently. The highest traffic flow is noted, marked and exported to user space via the affinity_hint proc file for each irq. In this way, utilities like irqbalance are able to determine which cpu is recieving the most data from each rx queue on a given NIC, and set irq affinity accordingly.
--- include/linux/netdevice.h | 18 +++++++ kernel/irq/proc.c | 2 +- net/Kconfig | 12 +++++ net/core/dev.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ net/core/sysctl_net_core.c | 9 ++++ 5 files changed, 147 insertions(+), 1 deletions(-)
include/linux/netdevice.h +18 -0
@@ -609,6 +609,9 @@ struct rps_map {struct rps_dev_flow {u16 cpu;u16 filter; +#ifdef CONFIG_RFS_SILOING +u32 weight; +#endif unsigned int last_qtail; };#define RPS_NO_FILTER 0xffff
@@ -1631,6 +1634,21 @@ static inline void unregister_netdevice(struct net_device *dev)unregister_netdevice_queue (dev,NULL ); } +#ifdef CONFIG_RFS_SILOING +extern int netdev_rxq_silo_init (int irq,struct affin_data *afd,void *priv); +extern int sysctl_irq_siloing_period; + +static inline int __must_check +request_net_irq (unsigned int irq,irq_handler_t handler,unsigned long flags, +const char *name,void *dev,struct net_device *ndev,int rxq) +{ +return request_affinity_irq (irq, handler,NULL , flags, name, dev, + netdev_rxq_silo_init, &ndev->_rx[rxq]); +} +#else +#define request_net_irq (i, h, f, n, d, nd, r) request_irq(i, h, NULL, f, n, d) +#endif +extern int netdev_refcnt_read (const struct net_device *dev);extern void free_netdev (struct net_device *dev);extern void synchronize_net (void );
kernel/irq/proc.c +1 -1
@@ -65,7 +65,7 @@ static int irq_affinity_alg_proc_show(struct seq_file *m, void *v)#ifdef CONFIG_AFFINITY_UPDATE struct irq_desc *desc =irq_to_desc ((long )m->private); -if (desc->af_data->affinity_alg) +if (desc->af_data && desc->af_data->affinity_alg) alg = desc->af_data->affinity_alg;#endif seq_printf (m,"%s\n" , alg);
net/Kconfig +12 -0
@@ -232,6 +232,18 @@ config XPS depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS default y +config RFS_SILOING + boolean + depends on RFS_ACCEL && AFFINITY_UPDATE + default y + ---help--- + This feature allows appropriately enabled network drivers to + export affinity_hint data to user space based on the RFS flow hash + table for the rx queue associated with a given interrupt. This allows + userspace to optimize irq affinity such that a given rx queue has its + interrupt serviced on the same cpu/l2 cache/numa node running the process + that consumes most of its data. + menu "Network testing" config NET_PKTGEN
net/core/dev.c +107 -0
131 lines not on this page · raw message
net/core/sysctl_net_core.c +9 -0
@@ -158,6 +158,15 @@ static struct ctl_table net_core_table[] = { .proc_handler = rps_sock_flow_sysctl }, #endif +#ifdef CONFIG_RFS_SILOING + { + .procname = "irq_siloing_period", + .data = &sysctl_irq_siloing_period, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, +#endif #endif /* CONFIG_NET */ { .procname = "netdev_budget",
Signature · 1 line
1.7.4.2
Re: [PATCH 2/3] net: Add net device irq siloing feature
Quoted 8 lines · Neil Horman
Using the irq affinity infrastrucuture, we can now allow net devices to call
request_irqusing a new wrapper function (request_net_irq), which will attach a commonaffinty_updatehandler to each requested irq. This affinty update mechanism correlates each tracked irq to the flow(s) that said irq processes most frequently. The highest traffic flow is noted, marked and exported to user space via theaffinity_hintproc file for each irq. In this way, utilities like irqbalance are able to determine which cpu is recieving the most data from each rx queue on a given NIC, and set irq affinity accordingly.
[...]
Is irqbalance expected to poll the affinity hints? How often?
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH 2/3] net: Add net device irq siloing feature
Quoted 9 lines · Ben Hutchings
Quoted 8 lines · Neil Horman
Using the irq affinity infrastrucuture, we can now allow net devices to call
request_irqusing a new wrapper function (request_net_irq), which will attach a commonaffinty_updatehandler to each requested irq. This affinty update mechanism correlates each tracked irq to the flow(s) that said irq processes most frequently. The highest traffic flow is noted, marked and exported to user space via theaffinity_hintproc file for each irq. In this way, utilities like irqbalance are able to determine which cpu is recieving the most data from each rx queue on a given NIC, and set irq affinity accordingly.
Quoted 4 lines
[...]
Is irqbalance expected to poll the affinity hints? How often?
Yes, its done just that for quite some time. Intel added that ability at the same time they added the affinity_hint proc file. Irqbalance polls the affinity_hint file at the same time it rebalances all irqs (every 10 seconds). If the affinity_hint is non-zero, irqbalance just copies it to smp_affinity for the same irq. Up until now thats been just about dead code because only ixgbe sets affinity_hint. Thats why I added the affinity_alg file, so irqbalance could do something more intellegent than just a blind copy. With the patch that I referenced I added code to irqbalance to allow it to preform different balancing methods based on the output of affinity_alg.
Neil
Quoted 8 lines
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH 2/3] net: Add net device irq siloing feature
Quoted 21 lines · Ben Hutchings
Quoted 15 lines · Neil Horman
Quoted 6 lines
Using the irq affinity infrastrucuture, we can now allow net devices to call
request_irqusing a new wrapper function (request_net_irq), which will attach a
commonaffinty_updatehandler to each requested irq. This affinty update mechanism correlates each tracked irq to the flow(s) thatQuoted 8 lines
said irq processes
most frequently. The highest traffic flow is noted, marked and exported to user
space via theaffinity_hintproc file for each irq. In this way, utilities like
irqbalance are able to determine which cpu is recieving the most data from each
rx queue on a given NIC, and set irq affinity accordingly.Quoted 4 lines
[...]
Is irqbalance expected to poll the affinity hints? How often?
Quoted 14 lines
Yes, its done just that for quite some time. Intel added that ability at the
same time they added theaffinity_hintproc file. Irqbalance polls theaffinity_hintfile at the same time it rebalances all irqs (every 10 seconds). If theaffinity_hintis non-zero, irqbalance just copies it tosmp_affinityfor
the same irq. Up until now thats been just about dead code because only ixgbe
setsaffinity_hint. Thats why I added theaffinity_algfile, so irqbalance could do something more intellegent than just a blind copy. With the patch that
I referenced I added code to irqbalance to allow it to preform different balancing methods based on the output ofaffinity_alg. Neil
I hate the way more and more interfaces are becoming device driver specific. It makes it impossible to build sane management infrastructure and causes lots of customer and service complaints.
Re: [PATCH 2/3] net: Add net device irq siloing feature
Quoted 35 lines · Stephen Hemminger
Quoted 20 lines · Ben Hutchings
Quoted 15 lines · Neil Horman
Quoted 6 lines
Using the irq affinity infrastrucuture, we can now allow net devices to call
request_irqusing a new wrapper function (request_net_irq), which will attach a
commonaffinty_updatehandler to each requested irq. This affinty update mechanism correlates each tracked irq to the flow(s) thatQuoted 8 lines
said irq processes
most frequently. The highest traffic flow is noted, marked and exported to user
space via theaffinity_hintproc file for each irq. In this way, utilities like
irqbalance are able to determine which cpu is recieving the most data from each
rx queue on a given NIC, and set irq affinity accordingly.Quoted 4 lines
[...]
Is irqbalance expected to poll the affinity hints? How often?
Quoted 14 lines
Yes, its done just that for quite some time. Intel added that ability at the
same time they added theaffinity_hintproc file. Irqbalance polls theaffinity_hintfile at the same time it rebalances all irqs (every 10 seconds). If theaffinity_hintis non-zero, irqbalance just copies it tosmp_affinityfor
the same irq. Up until now thats been just about dead code because only ixgbe
setsaffinity_hint. Thats why I added theaffinity_algfile, so irqbalance could do something more intellegent than just a blind copy. With the patch that
I referenced I added code to irqbalance to allow it to preform different balancing methods based on the output ofaffinity_alg. Neil
Quoted 4 lines
I hate the way more and more interfaces are becoming device driver specific. It makes it impossible to build sane management infrastructure and causes lots of customer and service complaints.
For me, the whole problem is the paradigm that we adapt IRQ to CPU were applications _were_ running in last seconds, while process scheduler might perform other choices, ie migrate task to cpu where IRQ was happening (the cpu calling wakeups)
We can add logic to each layer, and yet not gain perfect behavior.
Some kind of cooperation is neeed.
Irqbalance for example is of no use in the case of a network flood happening on your machine, because we enter NAPI mode for several minutes on a single cpu. We'll need to add special logic in NAPI loop to force an exit to reschedule an IRQ (so that another cpu can take it)
Re: [PATCH 2/3] net: Add net device irq siloing feature
Quoted 46 lines · Eric Dumazet
Quoted 35 lines · Stephen Hemminger
Quoted 20 lines · Ben Hutchings
Quoted 15 lines · Neil Horman
Quoted 6 lines
Using the irq affinity infrastrucuture, we can now allow net devices to call
request_irqusing a new wrapper function (request_net_irq), which will attach a
commonaffinty_updatehandler to each requested irq. This affinty update mechanism correlates each tracked irq to the flow(s) thatQuoted 8 lines
said irq processes
most frequently. The highest traffic flow is noted, marked and exported to user
space via theaffinity_hintproc file for each irq. In this way, utilities like
irqbalance are able to determine which cpu is recieving the most data from each
rx queue on a given NIC, and set irq affinity accordingly.Quoted 4 lines
[...]
Is irqbalance expected to poll the affinity hints? How often?
Quoted 14 lines
Yes, its done just that for quite some time. Intel added that ability at the
same time they added theaffinity_hintproc file. Irqbalance polls theaffinity_hintfile at the same time it rebalances all irqs (every 10 seconds). If theaffinity_hintis non-zero, irqbalance just copies it tosmp_affinityfor
the same irq. Up until now thats been just about dead code because only ixgbe
setsaffinity_hint. Thats why I added theaffinity_algfile, so irqbalance could do something more intellegent than just a blind copy. With the patch that
I referenced I added code to irqbalance to allow it to preform different balancing methods based on the output ofaffinity_alg. NeilQuoted 4 lines
I hate the way more and more interfaces are becoming device driver specific. It makes it impossible to build sane management infrastructure and causes lots of customer and service complaints.
For me, the whole problem is the paradigm that we adapt IRQ to CPU were applications _were_ running in last seconds, while process scheduler might perform other choices, ie migrate task to cpu where IRQ was happening (the cpu calling wakeups)
Quoted 9 lines
We can add logic to each layer, and yet not gain perfect behavior.
Some kind of cooperation is neeed.
Irqbalance for example is of no use in the case of a network flood happening on your machine, because we enter NAPI mode for several minutes on a single cpu. We'll need to add special logic in NAPI loop to force an exit to reschedule an IRQ (so that another cpu can take it)
Would you consider an approach whereby we, instead of updating irq affinity to match the process that consumes data from a given irq, bias the scheduler such that process which consume data from a given irq not be moved away from the same core/l2 cache being fed by that flow? Do you have a suggestion for how best to communicate that to the scheduler? It would seem that interrogating the RFS table from the scheduler might not be well received.
Best
Neil
Quoted 3 lines
PATCH 3/3 net: Adding siloing irqs to cxgb4 driver
In reply to Neil Hormancxgb4 hardware has been tested here and shows correct functionality with affinity hinting infrastructure
--- drivers/net/cxgb4/cxgb4_main.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/cxgb4/cxgb4_main.c +4 -2
@@ -562,9 +562,11 @@ static int request_msix_queue_irqs(struct adapter *adap)return err;for_each_ethrxq (s, ethqidx) { - err =request_irq (adap->msix_info[msi].vec, t4_sge_intr_msix,0 , + err =request_net_irq (adap->msix_info[msi].vec, t4_sge_intr_msix,0 , adap->msix_info[msi].desc, - &s->ethrxq[ethqidx].rspq); + &s->ethrxq[ethqidx].rspq, + adap->port[ethqidx/MAX_NPORTS ], + ethqidx %MAX_NPORTS );if (err) goto unwind; msi++;
Signature · 1 line
1.7.4.2
Quoted 20 lines · Neil Horman
Automatic IRQ siloing for network devices
At last years netconf:
http://vger.kernel.org/netconf2010.htmlTom Herbert gave a talk in which he outlined some of the things we can do to improve scalability and througput in our network stack
One of the big items on the slides was the notion of siloing irqs, which is the practice of setting irq affinity to a cpu or cpu set that was 'close' to the process that would be consuming data. The idea was to ensure that a hard irq for a nic (and its subsequent softirq) would execute on the same cpu as the process consuming the data, increasing cache hit rates and speeding up overall throughput.
I had taken an idea away from that talk, and have finally gotten around to implementing it. One of the problems with the above approach is that its all quite manual. I.e. to properly enact this siloiong, you have to do a few things by hand:
Quoted 5 lines
1) decide which process is the heaviest user of a given rx queue
2) restrict the cpus which that task will run on
3) identify the irq which the rx queue in (1) maps to
4) manually set the affinity for the irq in (3) to cpus which match the cpus in
(2)
[...]
This presumably works well with small numbers of flows and/or large numbers of queues. You could scale it up somewhat by manipulating the device's flow hash indirection table, but that usually only has 128 entries. (Changing the indirection table is currently quite expensive, though that could be changed.)
I see RFS and accelerated RFS as the only reasonable way to scale to large numbers of flows. And as part of accelerated RFS, I already did the work for mapping CPUs to IRQs (note, not the other way round). If IRQ affinity keeps changing then it will significantly undermine the usefulness of hardware flow steering.
Now I'm not saying that your approach is useless. There is more hardware out there with flow hashing than with flow steering, and there are presumably many systems with small numbers of active flows. But I think we need to avoid having two features that conflict and a requirement for administrators to make a careful selection between them.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 26 lines · Ben Hutchings
Quoted 20 lines · Neil Horman
Automatic IRQ siloing for network devices
At last years netconf:
http://vger.kernel.org/netconf2010.htmlTom Herbert gave a talk in which he outlined some of the things we can do to improve scalability and througput in our network stack
One of the big items on the slides was the notion of siloing irqs, which is the practice of setting irq affinity to a cpu or cpu set that was 'close' to the process that would be consuming data. The idea was to ensure that a hard irq for a nic (and its subsequent softirq) would execute on the same cpu as the process consuming the data, increasing cache hit rates and speeding up overall throughput.
I had taken an idea away from that talk, and have finally gotten around to implementing it. One of the problems with the above approach is that its all quite manual. I.e. to properly enact this siloiong, you have to do a few things by hand:
Quoted 5 lines
1) decide which process is the heaviest user of a given rx queue
2) restrict the cpus which that task will run on
3) identify the irq which the rx queue in (1) maps to
4) manually set the affinity for the irq in (3) to cpus which match the cpus in
(2)
Quoted 7 lines
[...]
This presumably works well with small numbers of flows and/or large numbers of queues. You could scale it up somewhat by manipulating the device's flow hash indirection table, but that usually only has 128 entries. (Changing the indirection table is currently quite expensive, though that could be changed.)
[...]
Actually, I reckon you could do a more or less generic implementation of accelerated RFS on top of a flow hash indirection table. It would require the drivers to provide a new function to update single table entries, and some way to switch between automatic configuration by RFS and manual configuration with ethtool.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 40 lines · Ben Hutchings
Quoted 20 lines · Neil Horman
Automatic IRQ siloing for network devices
At last years netconf:
http://vger.kernel.org/netconf2010.htmlTom Herbert gave a talk in which he outlined some of the things we can do to improve scalability and througput in our network stack
One of the big items on the slides was the notion of siloing irqs, which is the practice of setting irq affinity to a cpu or cpu set that was 'close' to the process that would be consuming data. The idea was to ensure that a hard irq for a nic (and its subsequent softirq) would execute on the same cpu as the process consuming the data, increasing cache hit rates and speeding up overall throughput.
I had taken an idea away from that talk, and have finally gotten around to implementing it. One of the problems with the above approach is that its all quite manual. I.e. to properly enact this siloiong, you have to do a few things by hand:
Quoted 5 lines
1) decide which process is the heaviest user of a given rx queue
2) restrict the cpus which that task will run on
3) identify the irq which the rx queue in (1) maps to
4) manually set the affinity for the irq in (3) to cpus which match the cpus in
(2)[...]
This presumably works well with small numbers of flows and/or large numbers of queues. You could scale it up somewhat by manipulating the device's flow hash indirection table, but that usually only has 128 entries. (Changing the indirection table is currently quite expensive, though that could be changed.)
I see RFS and accelerated RFS as the only reasonable way to scale to large numbers of flows. And as part of accelerated RFS, I already did the work for mapping CPUs to IRQs (note, not the other way round). If IRQ affinity keeps changing then it will significantly undermine the usefulness of hardware flow steering.
Quoted 8 lines
Now I'm not saying that your approach is useless. There is more hardware out there with flow hashing than with flow steering, and there are presumably many systems with small numbers of active flows. But I think we need to avoid having two features that conflict and a requirement for administrators to make a careful selection between them.
Ben.
I hear what your saying and I agree, theres no point in having features work against each other. That said, I'm not sure I agree that these features have to work against one another, nor does a sysadmin need to make a choice between the two. Note the third patch in this series. Making this work requires that network drivers wanting to participate in this affinity algorithm opt in by using the request_net_irq macro to attach the interrupt to the rfs affinity code that I added. Theres no reason that a driver which supports hardware that still uses flow steering can't opt out of this algorithm, and as a result irqbalance will still treat those interrupts as it normally does. And for those drivers which do opt in, irqbalance can take care of affinity assignment, using the provided hint. No need for sysadmin intervention.
I'm sure there can be improvements made to this code, but I think theres less conflict between the work you've done and this code than there appears to be at first blush.
Best
Neil
Quoted 6 lines
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 61 lines · On Fri, 15 Apr 2011 21:59:38 -0400 Neil Horman <[email protected]> wrote:
Quoted 40 lines · Ben Hutchings
Quoted 20 lines · Neil Horman
Automatic IRQ siloing for network devices
At last years netconf:
http://vger.kernel.org/netconf2010.htmlTom Herbert gave a talk in which he outlined some of the things we can do to improve scalability and througput in our network stack
One of the big items on the slides was the notion of siloing irqs, which is the practice of setting irq affinity to a cpu or cpu set that was 'close' to the process that would be consuming data. The idea was to ensure that a hard irq for a nic (and its subsequent softirq) would execute on the same cpu as the process consuming the data, increasing cache hit rates and speeding up overall throughput.
I had taken an idea away from that talk, and have finally gotten around to implementing it. One of the problems with the above approach is that its all quite manual. I.e. to properly enact this siloiong, you have to do a few things by hand:
Quoted 5 lines
1) decide which process is the heaviest user of a given rx queue
2) restrict the cpus which that task will run on
3) identify the irq which the rx queue in (1) maps to
4) manually set the affinity for the irq in (3) to cpus which match the cpus in
(2)[...]
This presumably works well with small numbers of flows and/or large numbers of queues. You could scale it up somewhat by manipulating the device's flow hash indirection table, but that usually only has 128 entries. (Changing the indirection table is currently quite expensive, though that could be changed.)
I see RFS and accelerated RFS as the only reasonable way to scale to large numbers of flows. And as part of accelerated RFS, I already did the work for mapping CPUs to IRQs (note, not the other way round). If IRQ affinity keeps changing then it will significantly undermine the usefulness of hardware flow steering.
Quoted 8 lines
Now I'm not saying that your approach is useless. There is more hardware out there with flow hashing than with flow steering, and there are presumably many systems with small numbers of active flows. But I think we need to avoid having two features that conflict and a requirement for administrators to make a careful selection between them.
Ben.
I hear what your saying and I agree, theres no point in having features work against each other. That said, I'm not sure I agree that these features have to work against one another, nor does a sysadmin need to make a choice between the two. Note the third patch in this series. Making this work requires that network drivers wanting to participate in this affinity algorithm opt in by using the
request_net_irqmacro to attach the interrupt to the rfs affinity code that I added. Theres no reason that a driver which supports hardware that still uses flow steering can't opt out of this algorithm, and as a result irqbalance will still treat those interrupts as it normally does. And for those drivers which do opt in, irqbalance can take care of affinity assignment, using the provided hint. No need for sysadmin intervention.
Quoted 4 lines
I'm sure there can be improvements made to this code, but I think theres less conflict between the work you've done and this code than there appears to be at first blush.
My gut feeling is that:
* kernel should default to a simple static sane irq policy without user space. This is especially true for multi-queue devices where the default puts all IRQ's on one cpu.
* irqbalance should do a one-shot rearrangement at boot up. It should rearrange when new IRQ's are requested. The kernel should have capablity to notify userspace (uevent?) when IRQ's are added or removed.
* Let scheduler make decisions about migrating processes (rather than let irqbalance migrate IRQ's).
* irqbalance should not do the hacks it does to try and guess at network traffic.
Quoted 69 lines · Stephen Hemminger
Quoted 61 lines · On Fri, 15 Apr 2011 21:59:38 -0400 Neil Horman <[email protected]> wrote:
Quoted 40 lines · Ben Hutchings
Quoted 20 lines · Neil Horman
Automatic IRQ siloing for network devices
At last years netconf:
http://vger.kernel.org/netconf2010.htmlTom Herbert gave a talk in which he outlined some of the things we can do to improve scalability and througput in our network stack
One of the big items on the slides was the notion of siloing irqs, which is the practice of setting irq affinity to a cpu or cpu set that was 'close' to the process that would be consuming data. The idea was to ensure that a hard irq for a nic (and its subsequent softirq) would execute on the same cpu as the process consuming the data, increasing cache hit rates and speeding up overall throughput.
I had taken an idea away from that talk, and have finally gotten around to implementing it. One of the problems with the above approach is that its all quite manual. I.e. to properly enact this siloiong, you have to do a few things by hand:
Quoted 5 lines
1) decide which process is the heaviest user of a given rx queue
2) restrict the cpus which that task will run on
3) identify the irq which the rx queue in (1) maps to
4) manually set the affinity for the irq in (3) to cpus which match the cpus in
(2)[...]
This presumably works well with small numbers of flows and/or large numbers of queues. You could scale it up somewhat by manipulating the device's flow hash indirection table, but that usually only has 128 entries. (Changing the indirection table is currently quite expensive, though that could be changed.)
I see RFS and accelerated RFS as the only reasonable way to scale to large numbers of flows. And as part of accelerated RFS, I already did the work for mapping CPUs to IRQs (note, not the other way round). If IRQ affinity keeps changing then it will significantly undermine the usefulness of hardware flow steering.
Quoted 8 lines
Now I'm not saying that your approach is useless. There is more hardware out there with flow hashing than with flow steering, and there are presumably many systems with small numbers of active flows. But I think we need to avoid having two features that conflict and a requirement for administrators to make a careful selection between them.
Ben.
I hear what your saying and I agree, theres no point in having features work against each other. That said, I'm not sure I agree that these features have to work against one another, nor does a sysadmin need to make a choice between the two. Note the third patch in this series. Making this work requires that network drivers wanting to participate in this affinity algorithm opt in by using the
request_net_irqmacro to attach the interrupt to the rfs affinity code that I added. Theres no reason that a driver which supports hardware that still uses flow steering can't opt out of this algorithm, and as a result irqbalance will still treat those interrupts as it normally does. And for those drivers which do opt in, irqbalance can take care of affinity assignment, using the provided hint. No need for sysadmin intervention.Quoted 4 lines
I'm sure there can be improvements made to this code, but I think theres less conflict between the work you've done and this code than there appears to be at first blush.
Quoted 5 lines
My gut feeling is that:
* kernel should default to a simple static sane irq policy without user space. This is especially true for multi-queue devices where the default puts all IRQ's on one cpu.
Thats not how it currently works, AFAICS. The default kernel policy is currently that cpu affinity for any newly requested irq is all cpus. Any restriction beyond that is the purview and doing of userspace (irqbalance or manual affinity setting).
Quoted 4 lines
* irqbalance should do a one-shot rearrangement at boot up. It should rearrange when new IRQ's are requested. The kernel should have capablity to notify userspace (uevent?) when IRQ's are added or removed.
I can see that, and it would be easy to implement. That said, I'm not sure what criteria should be used when doing said re-arrangement. Currently irqbalance uses interrupt counts and names to determine how interrupts should be placed. That is of course a hack, but its done because its currently the best information available to user space. Thats what this patch series was hoping to address. By exporting RFS flow data we give the opportunity to irqbalance to do some modicum of better irq placement.
Quoted 3 lines
* Let scheduler make decisions about migrating processes (rather than let irqbalance migrate IRQ's).
I can certainly get behind this idea, I've been having trouble however comming up with a good algorithm that lets the scheduler make a rational decision about which cpu to run a process on. I.e. how to do you weigh moving a process to a cpu thats more local to the rx queue its reciving data on against the fact that its also sharing a memory segment with another process on its current cpu. I'd like to be able to normalize these comparisons, but I'm not at all sure (yet) how to do so.
Quoted 2 lines
* irqbalance should not do the hacks it does to try and guess at network traffic.
Well, I can certainly agree with that, but I'm not sure what that looks like.
I could envision something like:
1) Use irqbalance to do a one time placement of interrupts, keeping a simple (possibly sub-optimal) policy, perhaps something like new irqs get assigned to the least loaded cpu within the numa node of the device the irq is originating from.
2) Add a udev event on the addition of new interrupts, to rerun irqbalance
3) Add some exported information to identify processes that are high users of network traffic, and correlate that usage to a rxq/irq that produces that information (possibly some per-task proc file)
4) Create/expand an additional user space daemon to monitor the highest users of network traffic on various rxq/irqs (as identified in (3)) and restrict those processes execution to those cpus which are on the same L2 cache as the irq itself. The cpuset cgroup could be usefull in doing this perhaps.
Actually, as I read back to myself, that acutally sounds kind of good to me. It keeps all the policy for this in user space, and minimizes what we have to add to the kernel to make it happen (some process information in /proc and another udev event). I'd like to get some feedback before I start implementing this, but I think this could be done. What do you think?
Thanks & Regards
Neil
Quoted 1 line · Neil Horman
On Sat, Apr 16, 2011 at 09:17:04AM -0700, Stephen Hemminger wrote:
[...]
Quoted 9 lines
Quoted 5 lines
My gut feeling is that:
* kernel should default to a simple static sane irq policy without user space. This is especially true for multi-queue devices where the default puts all IRQ's on one cpu.Thats not how it currently works, AFAICS. The default kernel policy is currently that cpu affinity for any newly requested irq is all cpus. Any restriction beyond that is the purview and doing of userspace (irqbalance or manual affinity setting).
Right. Though it may be reasonable for the kernel to use the hint as the initial affinity for a newly allocated IRQ (not sure quite how we determine that).
[...]
Quoted 4 lines
Quoted 2 lines
* irqbalance should not do the hacks it does to try and guess at network traffic.
Well, I can certainly agree with that, but I'm not sure what that looks like.
Quoted 8 lines
I could envision something like:
1) Use irqbalance to do a one time placement of interrupts, keeping a simple (possibly sub-optimal) policy, perhaps something like new irqs get assigned to the least loaded cpu within the numa node of the device the irq is originating from.
2) Add a udev event on the addition of new interrupts, to rerun irqbalance
Yes, making irqbalance more (or entirely) event-driven seems like a good thing.
Quoted 8 lines
3) Add some exported information to identify processes that are high users of network traffic, and correlate that usage to a rxq/irq that produces that information (possibly some per-task proc file)
4) Create/expand an additional user space daemon to monitor the highest users of network traffic on various rxq/irqs (as identified in (3)) and restrict those processes execution to those cpus which are on the same L2 cache as the irq itself. The cpuset cgroup could be usefull in doing this perhaps.
I just don't see that you're going to get processes associated with specific RX queues unless you make use of flow steering.
The 128-entry flow hash indirection table is part of Microsoft's requirements for RSS so most multiqueue hardware is going to let you do limited flow steering that way.
Quoted 5 lines
Actually, as I read back to myself, that acutally sounds kind of good to me. It keeps all the policy for this in user space, and minimizes what we have to add to the kernel to make it happen (some process information in /proc and another udev event). I'd like to get some feedback before I start implementing this, but I think this could be done. What do you think?
I don't think it's a good idea to override the scheduler dynamically like this.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 8 lines · Ben Hutchings
Quoted 1 line · Neil Horman
On Sat, Apr 16, 2011 at 09:17:04AM -0700, Stephen Hemminger wrote:
[...]
Quoted 5 lines
Quoted 5 lines
My gut feeling is that:
* kernel should default to a simple static sane irq policy without user space. This is especially true for multi-queue devices where the default puts all IRQ's on one cpu.
Quoted 9 lines
Quoted 4 lines
Thats not how it currently works, AFAICS. The default kernel policy is currently that cpu affinity for any newly requested irq is all cpus. Any restriction beyond that is the purview and doing of userspace (irqbalance or manual affinity setting).
Right. Though it may be reasonable for the kernel to use the hint as the initial affinity for a newly allocated IRQ (not sure quite how we determine that).
So I understand what your saying here, but I'm having a hard time reconciling the two notions. Currently as it stands, affinity_hint gets set by a single function call in the kernel (irq_set_affinity_hint), and is called by drivers wishing to guide irqbalances behavior (currently only ixgbe does this). The behavior a driver is capable of guiding however are either overly simple (ixgbe just tells irqbalance to place each irq on a separate cpu, which irqbalance would do anyway) or overly complex (forcing policy into the kernel, which I tried to do with this patch series, but based on the responses I've gotten here, that seems non-desireable).
I personally like the idea of using affinity_hint to export various guidelines to drive irqbalances behavior, but I think I'm in the minority on that. Given the responses here, It almost seems to me like we should do away with affinity_hint alltogether (or perhaps just continue to ignore it), and rather export data relevent to balancing in various other locations, and just have irqbalance use that info directly.
Quoted 12 lines
[...]
Quoted 11 lines
Quoted 2 lines
* irqbalance should not do the hacks it does to try and guess at network traffic.
Well, I can certainly agree with that, but I'm not sure what that looks like.
I could envision something like:
1) Use irqbalance to do a one time placement of interrupts, keeping a simple (possibly sub-optimal) policy, perhaps something like new irqs get assigned to the least loaded cpu within the numa node of the device the irq is originating from.
Quoted 5 lines
Quoted 1 line
2) Add a udev event on the addition of new interrupts, to rerun irqbalance
Yes, making irqbalance more (or entirely) event-driven seems like a good thing.
Yeah, I can do that, it shouldn't be hard. Do we need to worry about bursty interfaces (i.e. irqs that have high volume counts for periods of time followed by periods of low activity). A periodic irqbalance can reblance behavior like that wheras a one-shot cannot. Can we just assume that the one-shot rebalance would give a 'good enough' placement in that situation?
Quoted 9 lines
Quoted 8 lines
3) Add some exported information to identify processes that are high users of network traffic, and correlate that usage to a rxq/irq that produces that information (possibly some per-task proc file)
4) Create/expand an additional user space daemon to monitor the highest users of network traffic on various rxq/irqs (as identified in (3)) and restrict those processes execution to those cpus which are on the same L2 cache as the irq itself. The cpuset cgroup could be usefull in doing this perhaps.
Quoted 7 lines
I just don't see that you're going to get processes associated with specific RX queues unless you make use of flow steering.
The 128-entry flow hash indirection table is part of Microsoft's requirements for RSS so most multiqueue hardware is going to let you do limited flow steering that way.
Yes, Agreed. I had presumed that any feature like this would assume RFS was available and enabled. If it wasn't, we'd have to re-implement some metric gathering code along with code to correlate sockets to rx queues and irqs. That would be 90% of the RFS code and this patch series :)
Quoted 9 lines
Quoted 5 lines
Actually, as I read back to myself, that acutally sounds kind of good to me. It keeps all the policy for this in user space, and minimizes what we have to add to the kernel to make it happen (some process information in /proc and another udev event). I'd like to get some feedback before I start implementing this, but I think this could be done. What do you think?
I don't think it's a good idea to override the scheduler dynamically like this.
Why not? Not disagreeing here, but I'm curious as to why you think this is bad. We already have several interfaces for doing this in user space (cgroups and taskset come to mind). Nominally they are used directly by sysadmins, and used sparingly for specific configurations. All I'm suggesting is that we create a daemon to identify processes that would benefit from running closer to the nics they are getting data from, and restricting them to cpus that fit that benefit. If a sysadmin doesn't want that behavior, they can stop the daemon, or change its configuration to avoid including processes they don't want to move/restrict.
Thanks & Regards
Neil
Quoted 8 lines
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 18 lines · Neil Horman
Quoted 8 lines · Ben Hutchings
Quoted 1 line · Neil Horman
On Sat, Apr 16, 2011 at 09:17:04AM -0700, Stephen Hemminger wrote:
[...]
Quoted 5 lines
Quoted 5 lines
My gut feeling is that:
* kernel should default to a simple static sane irq policy without user space. This is especially true for multi-queue devices where the default puts all IRQ's on one cpu.Quoted 9 lines
Quoted 4 lines
Thats not how it currently works, AFAICS. The default kernel policy is currently that cpu affinity for any newly requested irq is all cpus. Any restriction beyond that is the purview and doing of userspace (irqbalance or manual affinity setting).
Right. Though it may be reasonable for the kernel to use the hint as the initial affinity for a newly allocated IRQ (not sure quite how we determine that).
Quoted 7 lines
So I understand what your saying here, but I'm having a hard time reconciling the two notions. Currently as it stands,
affinity_hintgets set by a single function call in the kernel (irq_set_affinity_hint), and is called by drivers wishing to guide irqbalances behavior (currently only ixgbe does this). The behavior a driver is capable of guiding however are either overly simple (ixgbe just tells irqbalance to place each irq on a separate cpu, which irqbalance would do anyway)
It's a bit more subtle than that.
ixgbe is trying to set up hardware flow steering. Some versions of the hardware can steer packets to RX queues based on the TX queue that was last used for the same flow. The TX queue selection based on CPU in ixgbe_select_queue() should be the inverse of the IRQ affinity mapping of RX queues, and the affinity hints are supposed to ensure that this is true.
I think it should be possible to replace those hints with use of irq_cpu_rmap for TX queue selection.
Quoted 3 lines
or overly complex (forcing policy into the kernel, which I
tried to do with this patch series, but based on the responses I've gotten here, that seems non-desireable).
The trouble is that irqbalance has been so bad for multiqueue net devices in the past that many vendors (including Solarflare) recommended that it be disabled. I think irqbalance does sensible things now but many systems will be running without it for some time to come.
I was thinking that if the drivers could set sane hints to start with then it would improve matters for those systems without irqbalance. But maybe it would be better still for some part of the networking core or IRQ core to set up a default spreading of multiqueue IRQs.
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Actually, as I read back to myself, that acutally sounds kind of good to me. It keeps all the policy for this in user space, and minimizes what we have to add to the kernel to make it happen (some process information in /proc and another udev event). I'd like to get some feedback before I start implementing this, but I think this could be done. What do you think?
Quoted 7 lines
Quoted 3 lines
I don't think it's a good idea to override the scheduler dynamically like this.
Why not? Not disagreeing here, but I'm curious as to why you think this is bad. We already have several interfaces for doing this in user space (cgroups and taskset come to mind). Nominally they are used directly by sysadmins, and used sparingly for specific configurations.
Yes, that is why I think this is different.
Quoted 5 lines
All I'm suggesting is that we create a
daemon to identify processes that would benefit from running closer to the nics they are getting data from, and restricting them to cpus that fit that benefit. If a sysadmin doesn't want that behavior, they can stop the daemon, or change its configuration to avoid including processes they don't want to move/restrict.
I think this could improve latency under low CPU load and throughput under high CPU load for small numbers of relatively long-lived flows. But for large numbers of flows or high turnover of flows the affinity will just be noise.
You're welcome to do your own experiments, obviously!
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Quoted 27 lines · Ben Hutchings
Quoted 18 lines · Neil Horman
Quoted 8 lines · Ben Hutchings
Quoted 1 line · Neil Horman
On Sat, Apr 16, 2011 at 09:17:04AM -0700, Stephen Hemminger wrote:
[...]
Quoted 5 lines
Quoted 5 lines
My gut feeling is that:
* kernel should default to a simple static sane irq policy without user space. This is especially true for multi-queue devices where the default puts all IRQ's on one cpu.Quoted 9 lines
Quoted 4 lines
Thats not how it currently works, AFAICS. The default kernel policy is currently that cpu affinity for any newly requested irq is all cpus. Any restriction beyond that is the purview and doing of userspace (irqbalance or manual affinity setting).
Right. Though it may be reasonable for the kernel to use the hint as the initial affinity for a newly allocated IRQ (not sure quite how we determine that).
Quoted 7 lines
So I understand what your saying here, but I'm having a hard time reconciling the two notions. Currently as it stands,
affinity_hintgets set by a single function call in the kernel (irq_set_affinity_hint), and is called by drivers wishing to guide irqbalances behavior (currently only ixgbe does this). The behavior a driver is capable of guiding however are either overly simple (ixgbe just tells irqbalance to place each irq on a separate cpu, which irqbalance would do anyway)
Quoted 9 lines
It's a bit more subtle than that.
ixgbe is trying to set up hardware flow steering. Some versions of the hardware can steer packets to RX queues based on the TX queue that was last used for the same flow. The TX queue selection based on CPU in
ixgbe_select_queue()should be the inverse of the IRQ affinity mapping of RX queues, and the affinity hints are supposed to ensure that this is true.
Ah, ok, that makes a bit more sense then. Thank you for that.
Quoted 12 lines
I think it should be possible to replace those hints with use of
irq_cpu_rmapfor TX queue selection.Quoted 3 lines
or overly complex (forcing policy into the kernel, which I
tried to do with this patch series, but based on the responses I've gotten here, that seems non-desireable).The trouble is that irqbalance has been so bad for multiqueue net devices in the past that many vendors (including Solarflare) recommended that it be disabled. I think irqbalance does sensible things now but many systems will be running without it for some time to come.
Quoted 5 lines
I was thinking that if the drivers could set sane hints to start with then it would improve matters for those systems without irqbalance. But maybe it would be better still for some part of the networking core or IRQ core to set up a default spreading of multiqueue IRQs.
But doesn't this force policy for irqbalancing into the kernel, as Thomas and Eric alluded to? It seems to me that, if we can export just a bit more information regarding irqs and their associations to devices (which has been a major achilles heel of irqblance in the past), then I think we can create a sane default balancing policy with some simple udev rules. I've been messing with this a bit today.
Quoted 10 lines
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Actually, as I read back to myself, that acutally sounds kind of good to me. It keeps all the policy for this in user space, and minimizes what we have to add to the kernel to make it happen (some process information in /proc and another udev event). I'd like to get some feedback before I start implementing this, but I think this could be done. What do you think?
I don't think it's a good idea to override the scheduler dynamically like this.
Quoted 7 lines
Quoted 4 lines
Why not? Not disagreeing here, but I'm curious as to why you think this is bad. We already have several interfaces for doing this in user space (cgroups and taskset come to mind). Nominally they are used directly by sysadmins, and used sparingly for specific configurations.
Yes, that is why I think this is different.
Ok, fair enough.
Quoted 6 lines
Quoted 5 lines
All I'm suggesting is that we create a
daemon to identify processes that would benefit from running closer to the nics they are getting data from, and restricting them to cpus that fit that benefit. If a sysadmin doesn't want that behavior, they can stop the daemon, or change its configuration to avoid including processes they don't want to move/restrict.
Quoted 7 lines
I think this could improve latency under low CPU load and throughput under high CPU load for small numbers of relatively long-lived flows. But for large numbers of flows or high turnover of flows the affinity will just be noise.
You're welcome to do your own experiments, obviously!
I will, but I'll start with the low hanging fruit. I'm going to try exporting the msi table for a device. With that I can use the netdev_registration uevent to properly identify network based irqs without the need for 1/2 assed regex searches and volume counts and do one shot rebalancing of them.
Thanks for your time & thoughts!
Neil
Quoted 8 lines
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.