/proc/irq/{number}/smp_affinity
/proc/irq/{number}/smp_affinity
在多 CPU 的环境中,还有一个中断平衡的问题,比如,网卡中断会教给哪个 CPU 处理,这个参数控制哪些 CPU 可以绑定 IRQ 中断。其中的 {number} 是对应设备的中断编号,可以用下面的命令找出:
cat /proc/interrupt比如,一般 eth0 的 IRQ 编号是 16,所以控制 eth0 中断绑定的 /proc 文件名是 /proc/irq/16/smp_affinity。上面这个命令还可以看到某些中断对应的CPU处理的次数,缺省的时候肯定是不平衡的。
设置其值的方法很简单,smp_affinity 自身是一个位掩码(bitmask),特定的位对应特定的 CPU,这样,01 就意味着只有第一个 CPU 可以处理对应的中断,而 0f(0x1111)意味着四个 CPU 都会参与中断处理。
几乎所有外设都有这个参数设置,可以关注一下。
这个数值的推荐设置,其实在很大程度上,让专门的CPU处理专门的中断是效率最高的,比如,给磁盘IO一个CPU,给网卡一个CPU,这样是比较合理的。
现在的服务器一般都是多核了,但是中断很多时候都是只用一个核,如果有些中断要求比较高,可以把它独立分配给一个cpu使用。
查看irq资源
cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3 0: 131 0 0 1914 IO-APIC-edge timer 1: 0 0 0 2 IO-APIC-edge i8042 6: 0 0 0 3 IO-APIC-edge floppy 8: 0 0 0 0 IO-APIC-edge rtc 9: 0 0 0 1 IO-APIC-fasteoi acpi 12: 0 0 0 4 IO-APIC-edge i8042 16: 0 0 0 88 IO-APIC-fasteoi uhci_hcd:usb1 18: 0 0 0 0 IO-APIC-fasteoi uhci_hcd:usb2 19: 0 0 0 0 IO-APIC-fasteoi uhci_hcd:usb3 20: 0 0 0 3632390 IO-APIC-fasteoi eth0 21: 0 0 0 286964 IO-APIC-fasteoi eth1 22: 0 0 0 122 IO-APIC-fasteoi ehci_hcd:usb4, ide0 23: 0 0 0 71154 IO-APIC-fasteoi megaraid 24: 22742 71684193 0 501949119 IO-APIC-fasteoi wct4xxp NMI: 0 0 0 0 Non-maskable interrupts LOC: 2928977 1633788 6945258 8115638 Local timer interrupts RES: 1507 2361 3804 3442 Rescheduling interrupts CAL: 263 226 288 168 function call interrupts TLB: 5488 4201 5293 3658 TLB shootdowns TRM: 0 0 0 0 Thermal event interrupts SPU: 0 0 0 0 Spurious interrupts ERR: 0 MIS: 0
wct4xxp 就是E1卡TE410P,这个对中端要求比较高,所以分配到独立的cpu来处理,irq号是24
cat /proc/irq/24/smp_affinity
00000003
smp_affinity 文件默认是全部ffffffff,8个f就是16的8次方位,一般一台机就几只cpu,所以够了,echo 3 > /proc/irq/24/smp_affinity 就是分配第一第二只cpu给该irq。
先通过 /proc/interrupts 查看设备中断号
smp_affinity 具体定义:
IRQ Affinity
Binding IRQ’s to a group of CPU’s is a new feature of the 2.4 kernel. While it was originally developed as part of Red Hat Content Accelerator, it is now a generic and independent kernel feature. Every IRQ source in Linux has an entry in /proc/irq directory. For example, the settings for IRQ 40 is stored in /proc/irq/40. IRQ affinity, or IRQ bindings, is configured though the smp_affinity setting in that directory. For example, the smp_affinity for IRQ 40 is in /proc/irq/40/smp_affinity. The value of the smp_affinity setting is a bitmask of all CPU’s that are permitted as a resource for the given IRQ. The default value for smp_affinity is the HEX value 0xffffffff. This means the processes for the IRQ are sent to all CPU’s. You are not allowed to turn off all CPU’s for an IRQ. If the IRQ controller does not support IRQ affinity, the value can not be changed from the default. If multiple CPU’s are defined, then the IRQ source uses the least busy CPU. This is called ‘lowest priority APIC routing.’ IRQ affinity is achieved by binding an IRQ to a specific CPU or group of CPU’s by echoing a HEX value to smp_affinity for the IRQ.