CPU中断数查看
多核CPU每个核心CPU发生中断的数量查看
# mpstat -I SUM -P ALL 1 3 Linux 5.4.0-40-generic (verify-new-511kernel) 08/28/2021 _x86_64_ (72 CPU) 09:09:30 AM CPU intr/s 09:09:31 AM all 18762.00 09:09:31 AM 0 253.00 09:09:31 AM 1 256.00 09:09:31 AM 2 253.00 09:09:31 AM 3 253.00 09:09:31 AM 4 254.00 09:09:31 AM 5 260.00
说明:
pstat [-I {SUM| CPU | SCPU}][-P {|ALL}] [internal [count]] 参数 解释 -I 查看中断 {SUM 表示汇总每个CPU上的中断数| SCPU 单个软件中断数} -P {|ALL} 表示监控哪个CPU, cpu在[0,cpu个数-1]中取值 internal 相邻的两次采样的间隔时间、 count 采样的次数,count只能和delay一起使用
当中断集中在某个CPU时,会把这个CPU打满,建议将中断平均分配每个CPU处理。
查看中断数高的CPU忙于处理哪些中断
命令:cat /proc/interrupts
cat /proc/interrupts CPU0 CPU1 CPU2 CPU3 0: 245 0 0 7134094 IO-APIC-edge timer 8: 0 0 49 0 IO-APIC-edge rtc 9: 0 0 0 0 IO-APIC-level acpi 66: 67 0 0 0 IO-APIC-level ehci_hcd:usb2 74: 902214 0 0 0 PCI-MSI eth0 169: 0 0 79 0 IO-APIC-level ehci_hcd:usb1 177: 0 0 0 7170885 IO-APIC-level ata_piix, b4xxp 185: 0 0 0 59375 IO-APIC-level ata_piix NMI: 0 0 0 0 LOC: 7104234 7104239 7104243 7104218 ERR: 0 MIS: 0
查看网卡当前中断号绑定的CPU编号
cat /proc/interrupts | head -n1 && cat /proc/interrupts | grep eth CPU0 CPU1 124: 1733966 0 IR-PCI-MSI 49283073-edge eth0-0 125: 0 0 IR-PCI-MSI 49283074-edge eth0-1 126: 0 0 IR-PCI-MSI 49283075-edge eth0-2 127: 0 0 IR-PCI-MSI 49283076-edge eth0-3 128: 0 0 IR-PCI-MSI 49283077-edge eth0-4 129: 0 0 IR-PCI-MSI 49283078-edge eth0-5 130: 0 0 IR-PCI-MSI 49283079-edge eth0-6 131: 0 0 IR-PCI-MSI 49283080-edge eth0-7
如上看每个网卡队列对应一个中断编号,以eth0-0 网卡队列为例,对应中断号为124 查看该队列绑定的CPU
cat /proc/irq/124/smp_affinity_list 查看绑定的CPU列表,(10进制表示)
# cat /proc/irq/124/smp_affinity_list 0
如上表示绑定的为CPU0
cat /proc/irq/124/smp_affinity 查看绑定的CPU列表 (16进制表示)
# cat /proc/irq/124/smp_affinity 00,00000000,00000001
将中断号绑定所有CPU
绑定中断到0、1、2、3核
root@verify-new-511kernel:~# echo 0,1,2,3 > /proc/irq/124/smp_affinity_list root@verify-new-511kernel:~# cat /proc/irq/124/smp_affinity 00,00000000,0000000f root@verify-new-511kernel:~# cat /proc/irq/124/smp_affinity_list 0-3 root@verify-new-511kernel:~#
只绑定到个别核心例如CPU0和CPU1 可以写0-1 代表 连续的核心范围
# echo 0-1 > /proc/irq/124/smp_affinity_list # cat /proc/irq/124/smp_affinity_list 0-1
# cat /proc/irq/124/smp_affinity 00,00000000,00000003
绑定所有的核心(本例72个核心)
root@verify-new-511kernel:~# echo 0-71 > /proc/irq/124/smp_affinity_list root@verify-new-511kernel:~# cat /proc/irq/124/smp_affinity ff,ffffffff,ffffffff