项目需求
项目需要将wlan1的中断绑定到CPU0
查看当前CPU的中断情况
~ # cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
17: 15361 15338 15372 15366 MIPS GIC Local 1 timer
38: 2 0 0 0 MIPS GIC 22 apl_sw
46: 2767 0 0 0 MIPS GIC 30 serial
59: 0 888 0 0 MIPS GIC 43 eth0
61: 26 0 0 0 MIPS GIC 45 eth0
63: 0 0 0 0 MIPS GIC 47 eth0
72: 0 0 0 34648 MIPS GIC 56 wlan0
73: 0 0 27840 0 MIPS GIC 57 wlan1
74: 65219 0 0 0 MIPS GIC 58 ehci_hcd:usb1, ohci_hcd:usb2
75: 0 0 0 0 MIPS GIC 59 xhci-hcd:usb3
79: 4820 0 0 0 MIPS GIC 63 IPI call
80: 0 3056 0 0 MIPS GIC 64 IPI call
81: 0 0 5743 0 MIPS GIC 65 IPI call
82: 0 0 0 3135 MIPS GIC 66 IPI call
83: 10642 0 0 0 MIPS GIC 67 IPI resched
84: 0 17563 0 0 MIPS GIC 68 IPI resched
85: 0 0 22547 0 MIPS GIC 69 IPI resched
86: 0 0 0 17056 MIPS GIC 70 IPI resched
ERR: 0
从以上可以看出,wlan1默认绑定到CPU2,中断号73,使用以下指令查看
~ # cat /proc/irq/73/smp_affinity
4
说明:
smp_affinity的值表示绑定的是那个CPU
CPU0 1
CPU1 2
CPU2 4
CPU3 8
如果需要绑定CPU0 CPU1则修改为3即可
绑定指令
echo 1 >/proc/irq/73/smp_affinity
查看是否生效
绑定之前
~ # cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
17: 65294 65271 65305 65299 MIPS GIC Local 1 timer
38: 2 0 0 0 MIPS GIC 22 apl_sw
46: 2991 0 0 0 MIPS GIC 30 serial
59: 0 2321 0 0 MIPS GIC 43 eth0
61: 26 0 0 0 MIPS GIC 45 eth0
63: 0 0 0 0 MIPS GIC 47 eth0
72: 0 0 0 159808 MIPS GIC 56 wlan0
73: 0 0 127546 0 MIPS GIC 57 wlan1
74: 229891 0 0 0 MIPS GIC 58 ehci_hcd:usb1, ohci_hcd:usb2
75: 0 0 0 0 MIPS GIC 59 xhci-hcd:usb3
79: 8349 0 0 0 MIPS GIC 63 IPI call
80: 0 4747 0 0 MIPS GIC 64 IPI call
81: 0 0 9752 0 MIPS GIC 65 IPI call
82: 0 0 0 4727 MIPS GIC 66 IPI call
83: 29554 0 0 0 MIPS GIC 67 IPI resched
84: 0 94457 0 0 MIPS GIC 68 IPI resched
85: 0 0 44024 0 MIPS GIC 69 IPI resched
86: 0 0 0 40250 MIPS GIC 70 IPI resched
ERR: 0
绑定之后
发现73的irq中断到CPU0,CPU2的中断数量没有增加,表示绑定成功
~ # cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
17: 69278 69255 69289 69283 MIPS GIC Local 1 timer
38: 2 0 0 0 MIPS GIC 22 apl_sw
46: 3179 0 0 0 MIPS GIC 30 serial
59: 0 2428 0 0 MIPS GIC 43 eth0
61: 26 0 0 0 MIPS GIC 45 eth0
63: 0 0 0 0 MIPS GIC 47 eth0
72: 0 0 0 169368 MIPS GIC 56 wlan0
73: 437 0 127546 0 MIPS GIC 57 wlan1
74: 242508 0 0 0 MIPS GIC 58 ehci_hcd:usb1, ohci_hcd:usb2
75: 0 0 0 0 MIPS GIC 59 xhci-hcd:usb3
79: 8622 0 0 0 MIPS GIC 63 IPI call
80: 0 4882 0 0 MIPS GIC 64 IPI call
81: 0 0 10055 0 MIPS GIC 65 IPI call
82: 0 0 0 4838 MIPS GIC 66 IPI call
83: 30245 0 0 0 MIPS GIC 67 IPI resched
84: 0 101884 0 0 MIPS GIC 68 IPI resched
85: 0 0 46547 0 MIPS GIC 69 IPI resched
86: 0 0 0 42320 MIPS GIC 70 IPI resched
ERR: 0
注意事项
现在的多数Linux系统中已经有了IRQ Balance这个服务(服务程序一般是 /usr/sbin/irqbalance
),它可以自动调节分配各个中断与CPU的绑定关系,以避免所有中断的处理都集中在少数几个CPU上
参考
https://www.cnblogs.com/bamanzi/p/linux-irq-and-cpu-affinity.html
https://blog.51cto.com/noican/1355357
https://segmentfault.com/a/1190000006178824
https://www.vpsee.com/2010/07/load-balancing-with-irq-smp-affinity/
https://www.jianshu.com/p/6beacca6fdcd