proc/irq//smp_affinity
DESCRIPTION
TRANSCRIPT
/proc/irq/<IRQ>/smp_affinity
@syuu1228
12年9月22日土曜日
cat /proc/interrupts
12年9月22日土曜日
$ cat /proc/interrupts CPU0 CPU1 0: 36843 61973 IO-APIC-edge timer 1: 518 591 IO-APIC-edge i8042 8: 1 0 IO-APIC-edge rtc0 9: 387 321 IO-APIC-fasteoi acpi 12: 11236 79 IO-APIC-edge i8042 16: 0 0 IO-APIC-fasteoi uhci_hcd:usb6 17: 12 11 IO-APIC-fasteoi uhci_hcd:usb7 18: 0 0 IO-APIC-fasteoi uhci_hcd:usb8 19: 6531 235 IO-APIC-fasteoi ehci_hcd:usb2 20: 0 0 IO-APIC-fasteoi uhci_hcd:usb3 21: 85 69 IO-APIC-fasteoi uhci_hcd:usb4 22: 0 0 IO-APIC-fasteoi uhci_hcd:usb5 23: 20 15 IO-APIC-fasteoi ehci_hcd:usb1 40: 0 0 PCI-MSI-edge PCIe PME, pciehp 41: 0 0 PCI-MSI-edge PCIe PME, pciehp 42: 0 0 PCI-MSI-edge PCIe PME, pciehp 43: 33199 31756 PCI-MSI-edge ahci 44: 19 1583 PCI-MSI-edge eth0 45: 10 11 PCI-MSI-edge mei 46: 41104 59303 PCI-MSI-edge i915 47: 170268 708 PCI-MSI-edge iwlwifi 48: 78 77 PCI-MSI-edge snd_hda_intelNMI: 1406 1430 Non-maskable interruptsLOC: 342351 327074 Local timer interruptsSPU: 0 0 Spurious interruptsPMI: 1406 1430 Performance monitoring interruptsIWI: 0 0 IRQ work interruptsRES: 83855 108903 Rescheduling interruptsCAL: 223 195 Function call interruptsTLB: 1486 1665 TLB shootdownsTRM: 0 6 Thermal event interruptsTHR: 0 0 Threshold APIC interruptsMCE: 0 0 Machine check exceptionsMCP: 11 11 Machine check pollsERR: 0MIS: 0 丁度良く複数コアへ分散されてる?
12年9月22日土曜日
smp_affinity
割り込み先CPU群をビットで指定すると、指定されたCPU群にラウンドロビンで割り込まれる
# cat /proc/irq/43/smp_affinity3# echo 1 > /proc/irq/43/smp_affinity
これを書き換えればいいのか!
12年9月22日土曜日
ー 完 ー
12年9月22日土曜日
それでは#kernelvmらしくない
bitの立ってるコアへ割り込み分散
bitが一つならいつもそこへ割り込み
これ、どうなってるんだろう?
# cat /proc/irq/43/smp_affinity3# echo 1 > /proc/irq/43/smp_affinity
12年9月22日土曜日
イマドキなx86の割り込みCPU
Local APIC
CPU
Local APIC
CPU
Local APIC
ICH(South bridge)8259A PIC
Timer
I/O APIC Legacy PCI
Devices
MSI Capable Devices
IPI
MSI
Legacy PCI
8259A Intr
12年9月22日土曜日
Local APIC
CPU毎の割り込みコントローラ 割り込みを許可・マスクしたり、EOIしたり
システム全体で一意なAPIC IDを持つ
他のLAPICへ割り込める(IPI: Inter-processor Interrupt)
CPU
Local APIC
CPU
Local APIC
CPU
Local APIC
ICH(South bridge)8259A PIC
Timer
I/O APIC Legacy PCI
Devices
MSI Capable Devices
IPI
MSI
Legacy PCI
8259A Intr
12年9月22日土曜日
I/O APIC
限られたIRQを複数のPCIデバイスで共有
各IRQをどのLAPICへ転送するかを定義するRedirection Table(I/O APIC上のレジスタ群)を持つ
PCIデバイスはI/O APICを通じてLAPICへ割り込みメッセージを送信
CPU
Local APIC
CPU
Local APIC
CPU
Local APIC
ICH(South bridge)8259A PIC
Timer
I/O APIC Legacy PCI
Devices
MSI Capable Devices
IPI
MSI
Legacy PCI
8259A Intr
12年9月22日土曜日
MSI capable PCI devices
各デバイスが任意の数のIRQを持てる
各IRQの割り込み先LAPICはPCIデバイスのPCI Configuration Spaceに持つ
PCIデバイスは直接LAPICへ割り込みメッセージを送信
CPU
Local APIC
CPU
Local APIC
CPU
Local APIC
ICH(South bridge)8259A PIC
Timer
I/O APIC Legacy PCI
Devices
MSI Capable Devices
IPI
MSI
Legacy PCI
8259A Intr
12年9月22日土曜日
割り込み先の指定方法Physical Destination Mode
Destination FieldにAPIC IDを指定「常に同じCPUへ割り込み」を実現
Logical Destination Mode(Flat Model)Destination Fieldのbitで宛先LAPIC群の範囲を表現
Delivery ModeFixed指定範囲の全てのLAPICへ割り込み
Lowest Priority指定範囲の中で、最もTPR(Task Priority Register)の値が低いCPUへ割り込み
12年9月22日土曜日
Lowest Priority Mode
指定範囲の中で、最もTPR(Task Priority Register)の値が低いLAPICへ割り込み
最小値のTPRを持つLAPICが複数ある場合はラウンドロビンで1つ選択
12年9月22日土曜日
echo 1 > /proc/irq/<IRQ>/smp_affinityした時に何が起きるのかMSIなPCIeデバイスで確かめてみる
Intel Pro/1000(e1000e)PCI Configuration Spaceはrootなら/sys/bus/pciから読める→ユーザランドから読める→もしかして:lspci
12年9月22日土曜日
_人人 人人_
> lspci <
‾Y^Y^Y^Y‾
12年9月22日土曜日
# lspci -vvvv -s 00:19.000:19.0 Ethernet controller: Intel Corporation 82567LM Gigabit Network Connection (rev 03) Subsystem: Lenovo Device 20ee Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx+ Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Interrupt: pin A routed to IRQ 44 Region 0: Memory at f2600000 (32-bit, non-prefetchable) [size=128K] Region 1: Memory at f2625000 (32-bit, non-prefetchable) [size=4K] Region 2: I/O ports at 1840 [size=32] Capabilities: [c8] Power Management version 2 Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+) Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=1 PME- Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ Address: 00000000fee0300c Data: 41b9 Capabilities: [e0] PCI Advanced Features AFCap: TP+ FLR+ AFCtrl: FLR- AFStatus: TP- Kernel driver in use: e1000e Kernel modules: e1000e
赤く塗った所がMSIのフィールドだけれど、これだと良く分からないのでlspciをforkしてMSIフィールドを表示するツールを作成https://gist.github.com/1568777
12年9月22日土曜日
# gcc -lpci msireg.c# ./a.out 00:19.0Message Signalled Interrupts: 64bit+ Queue=0/0 Enable+address_hi=0address_lo=fee0300c dest_mode=logical redirection=lowpri dest_id=3data=41b9 trigger=edge level=assert delivery_mode=lowpri vector=185
Logical modeでLowpri、destid=3、vector=185になってる
# echo 1 > /proc/irq/44/smp_affinity# ./a.out 00:19.0Message Signalled Interrupts: 64bit+ Queue=0/0 Enable+address_hi=0address_lo=fee0100c dest_mode=logical redirection=lowpri dest_id=1data=41b9 trigger=edge level=assert delivery_mode=lowpri vector=185
dest_idが1に書き換わった!
12年9月22日土曜日
余談
調子に乗ってユーザランドからフィールド書き換えたら何かおかしくなりました
カーネルさんと喧嘩してるか、フィールドの書き方間違えたか…
12年9月22日土曜日
Intel® 64 and IA-32 Architectures Software Developer ManualsIntel® I/O Controller Hub 10 (ICH10) Family Datasheetlinux/Documentation/IRQ-affinity.txtUnderstanding the Linux Kernel, 3rd EditionPCI Local Bus Specification Revision 3.0最近のPCアーキテクチャにおける割り込みルーティングの仕組み
/proc/irq/<IRQ>/smp_affinityの書き換えでPCIコンフィグレーション空間はどのように書き換わるか
Interrupts on xv6
参考資料
12年9月22日土曜日