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.