genirq: Expose default irq affinity mask (take 3)
Subsystems (3)
PATCH 1/1 genirq: Expose default irq affinity mask (take 3)
Current IRQ affinity interface does not provide a way to set affinity for the IRQs that will be allocated/activated in the future. This patch creates /proc/irq/default_smp_affinity that lets users set default affinity mask for the newly allocated IRQs. Changing the default does not affect affinity masks for the currently active IRQs, they have to be changed explicitly.
Updated based on Paul J's comments and added some more documentation.
--- Documentation/IRQ-affinity.txt | 37 +++++++++++++++++----- Documentation/filesystems/proc.txt | 29 +++++++++++------- arch/alpha/kernel/irq.c | 5 +-- include/linux/irq.h | 14 +++----- kernel/irq/manage.c | 28 ++++++++++++++++- kernel/irq/proc.c | 59 +++++++++++++++++++++++++++++++++-- 6 files changed, 134 insertions(+), 38 deletions(-)
Documentation/IRQ-affinity.txt +28 -9
@@ -1,17 +1,26 @@ +ChangeLog: + Started by Ingo Molnar <[email protected]> + Update by Max Krasnyansky <[email protected]> -SMP IRQ affinity, started by Ingo Molnar <[email protected]> - +SMP IRQ affinity /proc/irq/IRQ#/smp_affinity specifies which target CPUs are permitted for a given IRQ source. It's a bitmask of allowed CPUs. It's not allowed to turn off all CPUs, and if an IRQ controller does not support IRQ affinity then the value will not change from the default 0xffffffff. +/proc/irq/default_smp_affinity specifies default affinity mask that applies +to all non-active IRQs. Once IRQ is allocated/activated its affinity bitmask +will be set to the default mask. It can then be changed as described above. +Default mask is 0xffffffff. + Here is an example of restricting IRQ44 (eth1) to CPU0-3 then restricting -the IRQ to CPU4-7 (this is an 8-CPU SMP box): +it to CPU4-7 (this is an 8-CPU SMP box): +[root@moon 44]# cd /proc/irq/44 [root@moon 44]# cat smp_affinity ffffffff + [root@moon 44]# echo 0f > smp_affinity [root@moon 44]# cat smp_affinity 0000000f
@@ -21,17 +30,27 @@ PING hell (195.4.7.3): 56 data bytes --- hell ping statistics --- 6029 packets transmitted, 6027 packets received, 0% packet loss round-trip min/avg/max = 0.1/0.1/0.4 ms -[root@moon 44]# cat /proc/interrupts | grep 44: - 44: 0 1785 1785 1783 1783 1 -1 0 IO-APIC-level eth1 +[root@moon 44]# cat /proc/interrupts | grep 'CPU\|44:' + CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 + 44: 1068 1785 1785 1783 0 0 0 0 IO-APIC-level eth1 + +As can be seen from the line above IRQ44 was delivered only to the first four +processors (0-3). +Now lets restrict that IRQ to CPU(4-7). + [root@moon 44]# echo f0 > smp_affinity +[root@moon 44]# cat smp_affinity +000000f0 [root@moon 44]# ping -f h PING hell (195.4.7.3): 56 data bytes .. --- hell ping statistics --- 2779 packets transmitted, 2777 packets received, 0% packet loss round-trip min/avg/max = 0.1/0.5/585.4 ms -[root@moon 44]# cat /proc/interrupts | grep 44: - 44: 1068 1785 1785 1784 1784 1069 1070 1069 IO-APIC-level eth1 -[root@moon 44]# +[root@moon 44]# cat /proc/interrupts | 'CPU\|44:' + CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7 + 44: 1068 1785 1785 1783 1784 1069 1070 1069 IO-APIC-level eth1 + +This time around IRQ44 was delivered only to the last four processors. +i.e counters for the CPU0-3 did not change.
Documentation/filesystems/proc.txt +18 -11
@@ -379,28 +379,35 @@ i386 and x86_64 platforms support the new IRQ vector displays. Of some interest is the introduction of the /proc/irq directory to 2.4. It could be used to set IRQ to CPU affinity, this means that you can "hook" an IRQ to only one CPU, or to exclude a CPU of handling IRQs. The contents of the -irq subdir is one subdir for each IRQ, and one file; prof_cpu_mask +irq subdir is one subdir for each IRQ, and two files; default_smp_affinity and +prof_cpu_mask. For example > ls /proc/irq/ 0 10 12 14 16 18 2 4 6 8 prof_cpu_mask - 1 11 13 15 17 19 3 5 7 9 + 1 11 13 15 17 19 3 5 7 9 default_smp_affinity > ls /proc/irq/0/ smp_affinity -The contents of the prof_cpu_mask file and each smp_affinity file for each IRQ -is the same by default: +smp_affinity is a bitmask, in which you can specify which CPUs can handle the +IRQ, you can set it by doing: - > cat /proc/irq/0/smp_affinity - ffffffff + > echo 1 > /proc/irq/10/smp_affinity + +This means that only the first CPU will handle the IRQ, but you can also echo +5 which means that only the first and fourth CPU can handle the IRQ. -It's a bitmask, in which you can specify which CPUs can handle the IRQ, you can -set it by doing: +The contents of each smp_affinity file is the same by default: + + > cat /proc/irq/0/smp_affinity + ffffffff - > echo 1 > /proc/irq/prof_cpu_mask +The default_smp_affinity mask applies to all non-active IRQs, which are the +IRQs which have not yet been allocated/activated, and hence which lack a +/proc/irq/[0-9]* directory. -This means that only the first CPU will handle the IRQ, but you can also echo 5 -which means that only the first and fourth CPU can handle the IRQ. +prof_cpu_mask specifies which CPUs are to be profiled by the system wide +profiler. Default value is ffffffff (all cpus). The way IRQs are routed is handled by the IO-APIC, and it's Round Robin between all the CPUs which are allowed to handle it. As usual the kernel has
arch/alpha/kernel/irq.c +2 -3
@@ -42,8 +42,7 @@ void ack_bad_irq(unsigned int irq)#ifdef CONFIG_SMP static char irq_user_affinity[NR_IRQS ]; -int -select_smp_affinity (unsigned int irq) +int irq_select_affinity (unsigned int irq) {static int last_cpu;int cpu = last_cpu +1 ;
@@ -51,7 +50,7 @@ select_smp_affinity(unsigned int irq)if (!irq_desc[irq].chip->set_affinity || irq_user_affinity[irq])return 1 ; -while (!cpu_possible (cpu)) +while (!cpu_possible (cpu) || !cpu_isset (cpu, irq_default_affinity)) cpu = (cpu < (NR_CPUS -1 ) ? cpu +1 :0 ); last_cpu = cpu;
include/linux/irq.h +5 -9
@@ -228,8 +228,11 @@ static inline void set_pending_irq(unsigned int irq, cpumask_t mask)#endif /* CONFIG_GENERIC_PENDING_IRQ */ +extern cpumask_t irq_default_affinity; +extern int irq_set_affinity (unsigned int irq,cpumask_t cpumask);extern int irq_can_set_affinity (unsigned int irq); +extern int irq_select_affinity (unsigned int irq);#else /* CONFIG_SMP */
@@ -243,6 +246,8 @@ static inline int irq_set_affinity(unsigned int irq, cpumask_t cpumask)static inline int irq_can_set_affinity (unsigned int irq) {return 0 ; } +static inline int irq_select_affinity (unsigned int irq) {return 0 ; } +#endif /* CONFIG_SMP */ #ifdef CONFIG_IRQBALANCE
@@ -253,15 +258,6 @@ static inline void set_balance_irq_affinity(unsigned int irq, cpumask_t mask) }#endif -#ifdef CONFIG_AUTO_IRQ_AFFINITY -extern int select_smp_affinity (unsigned int irq); -#else -static inline int select_smp_affinity (unsigned int irq) -{ -return 1 ; -} -#endif -extern int no_irq_affinity;static inline int irq_balancing_disabled (unsigned int irq)
kernel/irq/manage.c +26 -2
@@ -16,6 +16,8 @@#ifdef CONFIG_SMP +cpumask_t irq_default_affinity =CPU_MASK_ALL ; +/** * synchronize_irq - wait for pending IRQ handlers (on other CPUs) * @irq: interrupt number to wait for
@@ -94,6 +96,27 @@ int irq_set_affinity(unsigned int irq, cpumask_t cpumask) return 0; } +#ifndef CONFIG_AUTO_IRQ_AFFINITY +/* +* Generic version of the affinity autoselector. +*/ +int irq_select_affinity (unsigned int irq) +{ +cpumask_t mask; + +if (!irq_can_set_affinity (irq)) +return 0 ; + +cpus_and (mask, cpu_online_map, irq_default_affinity); + + irq_desc[irq].affinity = mask; + irq_desc[irq].chip->set_affinity (irq, mask); + +set_balance_irq_affinity (irq, mask); +return 0 ; +} +#endif +#endif /**
@@ -376,6 +399,9 @@ int setup_irq(unsigned int irq, struct irqaction *new) }else /* Undo nested disables: */ desc->depth =1 ; + +/* Set default affinity mask once everything is setup */ +irq_select_affinity (irq); }/* Reset broken irq detection when installing new handler */ desc->irq_count =0 ;
@@ -555,8 +581,6 @@ int request_irq(unsigned int irq, irq_handler_t handler, action->next =NULL ; action->dev_id = dev_id; -select_smp_affinity (irq); -#ifdef CONFIG_DEBUG_SHIRQ if (irqflags &IRQF_SHARED ) {/*
kernel/irq/proc.c +55 -4
91 lines not on this page · raw message
Signature · 1 line
1.5.4.5
Max,
I realized, when reading this again, that the default masks are not ffffffff. That's the default only on systems with no more than 32 CPUs. Rather I suspect that the default is CPU_MASK_ALL. Indeed, your patch has:
cpumask_t irq_default_affinity = CPU_MASK_ALL;
This affects a few mentions of ffffffff in the Docs.
Otherwise looks good - thanks.
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.940.382.4214Quoted 10 lines · Paul Jackson
Max,
I realized, when reading this again, that the default masks are not ffffffff. That's the default only on systems with no more than 32 CPUs. Rather I suspect that the default is
CPU_MASK_ALL. Indeed, your patch has:cpumask_t irq_default_affinity = CPU_MASK_ALL;This affects a few mentions of ffffffff in the Docs.
Good point.
Quoted 3 lines
Otherwise looks good - thanks.
Acked-by Paul Jackson <[email protected]>
Thanx.
btw What's the procedure for including Acked-by ?
cut&paste into the patch description and resend ?
Max
Quoted 1 line · Max
btw What's the procedure for including Acked-by ?
If the acked-by comes fairly shortly after the original patch, and isn't excessively buried in a bunch of discussion, then Andrew will catch it, and add it to the patch in his queue.
If you have to resubmit the patch anyway, then of course, add the acked-by then.
If neither of the above applies, and the acked-by is lost, but your patch is successfully applied anyway, then either of
(1) if you're feeling lazy, don't worry about it, or
(2) reply again to that lkml thread, being sure akpm is on the cc list, asking Andrew to add the acked-by.
Andrew is the expert, of course, in such matters.
If he says something contrary to the above, ignore me.
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.940.382.4214