Linux IPI核间中断及亲和性

IPI核间中断概念及亲和性

IPI 全称为Inter-Processor Interrupt,即处理中间的中断,需要可编程中断控制器PIC or APIC的支持!XLR 732 多核多线程处理器的中断由 PIC(Programmable Interrupt Controller)统一控制。PIC 允许一个硬件线程中断其他的硬件线程,这种方式被称为核间中断
(Inter-Processor Interrupts,IPI)。使用 IPI 进行
核间通信的关键在于要利用中断服务例程 ISR 去读取一个事先约好的共享内存区域。发起方首先将消息写到一块共享内存中,然后发起核间中断。被中断的硬件
线程在中断服务例程中读取该内存,以获得发起方通知的消息。为防止多核间的竞争导致消息被改写,使用这种方式必须利用锁机制来确保消息的完整性
————————————————
IPI中断作用:多核处理器间通信,提升并行运算,多核处理能力,多核消息同步,多核负载均衡,发挥发挥多核处理器高性能的优势!

核间通信是多核处理器系统所面临的主要难点,通信机制的优劣直接影响多核处理器的性能,高效的通信机制是的重要保障。而KeyStone 架构的通信研究才刚刚起步,因多核通信复杂,拓扑结构的选取会直接影响通信代价和并行计算的效率。采用基于KeyStone架构的中断控制器、核间通信寄存器以及合适的通信拓扑结构实现多核间的通信。通过中断系统激活处理器,触发具有通信功能的中断服务程序,调用寄存器完成相应的功能,并通过合适拓扑结构完成通信。

核间通信的关键在于要利用中断服务例程 ISR 去读取一个事先约好的共享内存区域。发起方首先将消息写到一块共享内存中,然后发起核间中断。被中断的硬件

Linux中断亲和性

/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。

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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章