英语

SMP IRQ 亲和性

更新日志

/proc/irq/IRQ#/smp_affinity 和 /proc/irq/IRQ#/smp_affinity_list 指定允许给定 IRQ 源使用的目标 CPU。它是一个位掩码 (smp_affinity) 或允许的 CPU 列表 (smp_affinity_list)。不允许关闭所有 CPU,如果 IRQ 控制器不支持 IRQ 亲和性,则该值不会从所有 CPU 的默认值更改。

/proc/irq/default_smp_affinity 指定适用于所有非活动 IRQ 的默认亲和性掩码。一旦 IRQ 被分配/激活,它的亲和性位掩码将被设置为默认掩码。然后可以如上所述更改它。默认掩码是 0xffffffff。

以下是将 IRQ44 (eth1) 限制为 CPU0-3,然后限制为 CPU4-7 的示例(这是一个 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
[root@moon 44]# ping -f h
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 'CPU\|44:'
        CPU0       CPU1       CPU2       CPU3      CPU4       CPU5        CPU6       CPU7
44:       1068       1785       1785       1783         0          0           0         0    IO-APIC-level  eth1

从上面的行可以看出,IRQ44 仅被传递到前四个处理器 (0-3)。现在让我们将 IRQ 限制为 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 |  'CPU\|44:'
        CPU0       CPU1       CPU2       CPU3      CPU4       CPU5        CPU6       CPU7
44:       1068       1785       1785       1783      1784       1069        1070       1069   IO-APIC-level  eth1

这一次 IRQ44 仅被传递到最后四个处理器。即 CPU0-3 的计数器没有改变。

以下是将相同 irq (44) 限制为 cpus 1024 到 1031 的示例

[root@moon 44]# echo 1024-1031 > smp_affinity_list
[root@moon 44]# cat smp_affinity_list
1024-1031

请注意,要使用位掩码执行此操作,需要 32 个零的位掩码才能遵循相关的位掩码。