PCIe & SR IOV in virtual 
PCIe & SR‐IOV in virtual
     environment
        海老澤 健太郎
       Twitter: @ebiken
     ebiken.g@gmail.com
PCI コンフィグレーション空間
•   デバイス上のFunction毎に存在するメモリ空間
•   ドライバはここにアクセスすることによりデバイスを操作

•   アクセス方法
    – IO Port:起動時 or Legacy
    – MMIO : Memory Mapped IO
                          d

•   フォーマットは3タイプ
    – Type 0 : non‐bridge function
       ype 0 : o b dge u ct o
         •   一般的なデバイスはこちら(NIC, DISK)
    – Type 1 : PCI‐to PCI Bridge
         •   PCIe Switch で Packet Routing するための情報を含む
    – Type 2 : CardBus Bridge
       yp                  g

•   サイズ・配置
    – PCIe = 4KByte (そのうち PCI 共通=256 Byte)
    – 64 B t : コンフィグレ ション空間ヘッダ部分(PCI共通部)
          Byte コンフィグレーション空間ヘッダ部分(PCI共通部)
    – 192 Byte :デバイス固有の領域(PCI共通部)




                                           2
PCI コンフィグレーション空間:配置
           物理メモリ空間     SDRAM    PCIメモリ空間

           メインメモリ     メインメモリ
  4GB
           システムBIOS

           PCI用MMIO             PCIデバイス
  3GB


           メインメモリ     メインメモリ


  1MB
             予約       シャドウRAM
           VGAビデオ                VGAビデオ
0xa0000
      コンベンショナルメモリ
                      メインメモリ
  0MB    (640KB)

                       3
Type 0
             31 - 24               23 - 16               15 - 8                 7-0

1    00h               Device ID                                   Vendor ID

2    04h                 Status                                    Command

3    08h   Class code              Subclass              Prog IF             Revision ID

4    0Ch      BIST            Header type          Latency Timer           Cache Line Size

5    10h                            Base address #0 (BAR0)

6    14h                            Base address #1 (BAR1)

7    18h                            Base address #2 (BAR2)

8    1Ch                            Base address #3 (BAR3)

9    20h                            Base address #4 (BAR4)

10   24h                            Base address #5 (BAR5)

11   28h                              Cardbus CIS Pointer

12   2Ch             Subsystem ID                         Subsystem Vendor ID

13   30h                          Expansion ROM base address
                                                                             Capabilities
14   34h                           Reserved
                                                                              Pointer
15   38h                                      Reserved

16   3Ch   Max latency
           M l t                  Min Grant
                                  Mi G t            Interrupt PIN
                                                    I t     t               Interrupt Line
                                                                            I t     t Li


                                                                       4
コンフィグレーション空間 … PF on Host
[root@dut 0000:03:00.1]# lspci –x
03:00.0 Ethernet controller: Intel Corporation 82599EB 10 Gigabit TN Network Connection (rev 01)
             Vendor ID = 8086 (Intel)
                  Device ID = 151c (82599EB 10 Gigabit TN Network Connection)                  Header Type = 80
                                                                                               bit 7 : Multi function
                                   Command = 0407                                              bit 6‐0 : non‐bridge function
                                       bit 0 : IO enable
                                       bit 1 : Mem enable             Revision ID = 01 Class code = 02 (Network Controller)
                                                     Status = 0010

        00:     86    80     1c    15       07    04        10   00   01   00    00   02    10   00    80   00
        10:     04    00     20    df       00    00        00   00   c1   ec    00   00    00   00    00   00
        20:     04    80     1f    df       00    00        00   00   00   00    00   00    86   80    2c   a0
        30:     00    00     00    00       40    00        00   00   00   00    00   00    0e   02    00   00
  BAR#01 = 0000 0000 df20 0004 (Mem, 64bit)                                     IRQ PIN = INTB#
                                         BAR#23 = 0000 0000 0000 ecc1 IRQ Line = 0e
                                         (IO, 32bit)
     BAR#45 = 0000 0000 df1f 8004 (M
              0000 0000 df1f 8004 (Mem, 64bit)
                                        64bi )
                                                                 Subsystem Vendor ID = 8086 (Intel)

  PCI IDs = Vendor ID + Device ID                                                   Subsystem ID = a02c (***********)
  http://pciids.sourceforge.net/
     p p                 g
  http://pci‐ids.ucw.cz/read/PC/8086                 !!PCIはリトルエンディアン!!
                                                                  5
コンフィグレーション空間 … VF on Host
[root@dut 0000:03:00.1]# lspci –x
03:10.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller Virtual Function (rev 01)
             Vendor ID = ffff (n/a)
                                /
                   Device ID = ffff (n/a)                                                      Header Type = 80
                                                                                               bit 7 : Single function
                                   Command = 0004                                              bit 6‐0 : non‐bridge function
                                       bit 0 : IO disable
                                       bit 1 : Mem disable            Revision ID = 01 Class code = 02 (Network Controller)
                                                      Status = 0010

        00:     ff    ff     ff    ff       04     00    10   00      01   00    00   02    00   00    00   00
        10:     00    00     00    00       00     00    00   00      00   00    00   00    00   00    00   00
        20:     00    00     00    00       00     00    00   00      00   00    00   00    86   80    2c   a0
        30:     00    00     00    00       70     00    00   00      00   00    00   00    00   00    00   00
  BAR#01 = 0000 0000 0000 0000                                                               IRQ PIN = n/a
                                                      BAR#23 = 0000 0000 0000 0000 IRQ Line = 00

      BAR#45 = 0000 0000 0000 0000
               0000 0000 0000 0000
                                                                                  Subsystem Vendor ID = 8086 (Intel)

  PCI IDs = Vendor ID + Device ID                                                   Subsystem ID = a02c (***********)
  http://pciids.sourceforge.net/
     p p                 g
  http://pci‐ids.ucw.cz/read/PC/8086                 !!PCIはリトルエンディアン!!
                                                                 6
コンフィグレーション空間 … VF on Guest
[root@dutvm‐sriov ~]# lspci ‐ x
00:03.0 Ethernet controller: Intel Corporation 82559 Ethernet Controller Virtual Function (rev 01)
            Vendor ID = 8086 (Intel)
                   Device ID = 10ed (82559 Ethernet Controller Virtual Function)               Header Type = 80
                                                                                               bit 7 : Single function
                                   Command = 0407                                              bit 6‐0 : non‐bridge function
                                       bit 0 : IO enable
                                       bit 1 : Mem enable             Revision ID = 01 Class code = 02 (Network Controller)
                                                     Status = 0010

        00:     86    80     ed    10       07    04        10   00   01   00    00   02    00   00    00   00
        10:     00    00     02    f2       00    00        00   00   00   00    00   00    00   40    02   f2
        20:     00    00     00    00       00    00        00   00   00   00    00   00    86   80    2c   a0
        30:     00    00     00    00       a0    00        00   00   00   00    00   00    00   00    00   00
  BAR#0 = f202 0000 (Mem, 32bit)                                                                   IRQ PIN = n/a
                                                  BAR#3 = f202 4000 (Mem, 32bit)         IRQ Line = 00
      BAR#45 = 0000 0000 0000 0000
               0000 0000 0000 0000
                                                                                  Subsystem Vendor ID = 8086 (Intel)

  PCI IDs = Vendor ID + Device ID                                                   Subsystem ID = a02c (***********)
  http://pciids.sourceforge.net/
     p p                 g
  http://pci‐ids.ucw.cz/read/PC/8086                 !!PCIはリトルエンディアン!!
                                                                  7
PF on Host
[root@dut ~]# lspci ‐v ‐s 03:00.0
03:00.0 Ethernet controller: Intel Corporation 82599EB 10 Gigabit TN Network Connection (rev 01)
    Subsystem: Intel Corporation Device a02c
       b             l          i       i
    Flags: bus master, fast devsel, latency 0, IRQ 45
    Memory at df200000 (64‐bit, non‐prefetchable) [size=2M]
    I/O ports at ecc0 [size=32]
    Memory at df1f8000 (64‐bit, non‐prefetchable) [size=16K]
    Capabilities: [40] Power Management version 3
    Capabilities: [50] MSI: Enable‐ Count=1/1 Maskable+ 64bit+
    Capabilities: [70] MSI X: Enable Count=64 Masked‐
    Capabilities: [70] MSI‐X: Enable+ Count 64 Masked
    Capabilities: [a0] Express Endpoint, MSI 00
    Capabilities: [e0] Vital Product Data
    Capabilities: [100] Advanced Error Reporting
    Capabilities: [140] Device Serial Number 00‐1b‐21‐ff‐ff‐ce‐51‐c4
    Capabilities: [140] Device Serial Number 00 1b 21 ff ff ce 51 c4
    Capabilities: [150] Alternative Routing‐ID Interpretation (ARI)
    Capabilities: [160] Single Root I/O Virtualization (SR‐IOV)
    Kernel driver in use: ixgbe
    Kernel modules: ixgbe
          l    d l i b




                                                  8
VF on Host / Guest 比較
[root@dut ~]# lspci ‐v ‐s 03:10.0
03:10.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller Virtual Function (rev 01)
    Subsystem: Intel Corporation Device a02c
    Subsystem: Intel Corporation Device a02c
    Flags: bus master, fast devsel, latency 0
    [virtual] Memory at d0000000 (64‐bit, prefetchable) [size=16K]
    [virtual] Memory at d0100000 (64‐bit, prefetchable) [size=16K]
    Capabilities: [70] MSI‐X: Enable+ Count=3 Masked‐
       p          [ ]
    Capabilities: [a0] Express Endpoint, MSI 00
    Capabilities: [100] Advanced Error Reporting
    Capabilities: [150] Alternative Routing‐ID Interpretation (ARI)
    Kernel driver in use: pci‐stub
    Kernel modules: ixgbevf
          l    d l       b f

[root@dutvm‐sriov ~]# lspci ‐v ‐s 00:03.0
00:03.0 Ethernet controller: Intel Corporation 82559 Ethernet Controller Virtual Function (rev 01)
    Subsystem: Intel Corporation Device a02c
    Subsystem: Intel Corporation Device a02c
    Physical Slot: 3
    Flags: bus master, fast devsel, latency 0
    Memory at f2020000 (32‐bit, non‐prefetchable) [size=16K]
    Memory at f2024000 (32‐bit, non‐prefetchable) [size=16K]
            y               (     ,     p          )[         ]
    Capabilities: [a0] Express Endpoint, MSI 00
    Capabilities: [70] MSI‐x: Enable+ Count=3 Masked‐
    Kernel driver in use: ixgbevf
    Kernel modules: ixgbevf



                                                           9
IO v.s. Memory ‐ Mapped IO
•   IO Mapped IO
     –   IO port (IO空間) を利用
     –   IO空間のアドレス=IOポートアドレス、ポート番号
     –   1,2,4 Byte単位でのRead/Write
     –   IO Port専用のニーモニックがある。asm/io.h

•   MMIO : Memory Mapped IO
     – IO Portの代わりにメモリアクセスをハードウェアレベルでのデバイスへのアクセスに置換
     – デバイスに割当られたアドレス範囲にメモリアクセスをすることにより、ドライバからデバイス
       のレジスタRead/Write可能
     – ドライバが動作する「仮想メモリアドレス」と、MMIO確保された「物理メモリアドレス」の違いに
       注意

•              (PCIe Root Bridge <‐> Device) は共通
    PCIe Layer (PCI R
    PCI L                 B id       D i )
     – Config TLP (Transaction Layer Packet) でアクセス

•   共通の抽象的なインタ フェ ス有り
    共通の抽象的なインターフェース有り
     – asm/iomap.h
     – void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max len);




                                               10
IO v.s. Memory ‐ Mapped IO
•   IO Ports, MMIO割当確認方法
    – [root@hwn01 ~]# ls /proc/ | grep ^io
    – iomem
    – ioports
    [root@hwn01 ~]# cat /proc/ioports
    0000‐0cf7 : PCI Bus 0000:00
     0000‐001f : dma1
     0020‐0021 : pic1
     0040‐0043 : timer0
     0050‐0053 : timer1
     0050‐0053 : timer1
     0060‐0060 : keyboard

    [root@hwn01 ~]# cat /proc/iomem
    00000000‐0000ffff : reserved
    00000000 0000ffff            d
    00010000‐0009f7ff : System RAM
    …
     f4000000‐f7ffffff : PCI MMCONFIG 0000 [bus 00‐3f]
      f4000000‐f7ffffff : reserved
       f4000000‐f7ffffff : pnp 00:0a
     fb400000‐fb7fffff : 0000:00:02.0



                                              11
メモ
• MSI, MSI‐X の Configuration 空間パラメーターと、/proc/interrupt
  で見える割り込み番号の関係
   – ???
• PCIe MSI, MSI‐X の処理方法
   – NICからアドレス0xfeeに対しメモリ書き込み(DWORD Mem Write
                                    Mem Write 
     Transaction)
      • アドレスは初期化時 MSI Capability Registerにソフトウェア(BIOS??)がセット
      • 0xfeeはLocal APIC のレジスタへMemory Mapされている
                    APIC のレジスタ Memory
   – LAPICがCPUへ割り込み通知(INTR)
   – CPU ⇒ LAPICへAck(INTA)
   – LAPIC⇒CPU:Vectorを返す
• VFのBAR
   – VFのメモリ空間にはBARはない
   – PFのSR IOV C bilit R i t に設定
     PFのSR‐IOV Capability Registerに設定
   – Host の lspci ‐v はそちらを表示



                               12
メモ
• 空の PCI スロットのベ ンダ ID とデバイス ID を
  読み取ろうとしたときは、0xFFFFFFFF というエ
  ラ メッセ ジが返る
  ラー メッセージが返る

• BARは起動時にBIOSが割り当て
 – http://www.mnc.co.jp/intime/user/intimedev.php
   ?PCI%A5%B3%A5%F3%A5%D5%A5%A3%A5%B0%
   A5%EC%A1%BC%A5%B7%A5%E7%A5%F3%A5%EC
   %A5%B8%A5%B9%A5%BF

                       13
割り込み一覧(/proc/interrupts)
[root@hwn01 ~]# cat /proc/interrupts
           CPU0       CPU1       CPU2     CPU3
  0:        144          1          0        0   IO-APIC-edge      timer
  1:          3          0          1        2   IO-APIC-edge      i8042
  4:
  4           0          1          1        0   IO-APIC-edge
                                                          d
  8:         33         58         31       57   IO-APIC-edge      rtc0
  9:          0          0          0        0   IO-APIC-fasteoi   acpi
 16:          0          0          0        0   IO-APIC-fasteoi   ahci, uhci_hcd:usb3, uhci_hcd:usb9
 17:        115          3          1        1   IO-APIC-fasteoi   pata_jmicron, firewire_ohci
 18:       2150       3669        117      284   IO-APIC-fasteoi   ehci_hcd:usb1, uhci_hcd:usb5, uhci_hcd:usb8
 19:      51447       1305      39191     1307   IO-APIC-fasteoi   ata_piix, ata_piix, uhci_hcd:usb7
 21:          0          0          0        0   IO-APIC-fasteoi   uhci_hcd:usb4
 23:          0          0          0        0   IO-APIC-fasteoi   ehci_hcd:usb2, uhci_hcd:usb6
 41:      58395        289       3073      269   PCI-MSI-edge      i915@pci:0000:00:02.0
 42:         47         50         47       52   PCI-MSI-edge      hda_intel
 43:       2710       6576       3336     3655   PCI-MSI-edge      eth0
 44:          0          0          0        1   PCI-MSI-edge      xhci_hcd
 45:          0          0          0        0   PCI-MSI-edge      xhci_hcd
 46:          0          0          0        0   PCI-MSI-edge      xhci_hcd
 47:          0          0          0        0   PCI-MSI-edge      xhci_hcd
 48:          0          0          0        0   PCI-MSI-edge      xhci_hcd
 49:       2985          6        648        5   PCI-MSI-edge      eth1
NMI:         13         34         95       28   Non-maskable interrupts
LOC:     332011     170933     296037   190006   Local timer interrupts
SPU:          0          0          0        0   Spurious interrupts
PMI:         13         34         95       28   Performance monitoring interrupts
IWI:          0          0          0        0   IRQ work interrupts
RES:     452195      37148     103501    14434   Rescheduling interrupts
                                                            g        p
CAL:        812       6027       1044     7911   Function call interrupts
TLB:       1077        644       2068      824   TLB shootdowns
TRM:          0          0          0        0   Thermal event interrupts
THR:          0          0          0        0   Threshold APIC interrupts
MCE:          0          0          0        0   Machine check exceptions
MCP:         29         28         28       28   Machine check polls
ERR:          0
MIS:          0


                                                               14

20111015 勉強会 (PCIe / SR-IOV)

  • 1.
    PCIe & SR IOV in virtual  PCIe &SR‐IOV in virtual environment 海老澤 健太郎 Twitter: @ebiken ebiken.g@gmail.com
  • 2.
    PCI コンフィグレーション空間 • デバイス上のFunction毎に存在するメモリ空間 • ドライバはここにアクセスすることによりデバイスを操作 • アクセス方法 – IO Port:起動時 or Legacy – MMIO : Memory Mapped IO d • フォーマットは3タイプ – Type 0 : non‐bridge function ype 0 : o b dge u ct o • 一般的なデバイスはこちら(NIC, DISK) – Type 1 : PCI‐to PCI Bridge • PCIe Switch で Packet Routing するための情報を含む – Type 2 : CardBus Bridge yp g • サイズ・配置 – PCIe = 4KByte (そのうち PCI 共通=256 Byte) – 64 B t : コンフィグレ ション空間ヘッダ部分(PCI共通部) Byte コンフィグレーション空間ヘッダ部分(PCI共通部) – 192 Byte :デバイス固有の領域(PCI共通部) 2
  • 3.
    PCI コンフィグレーション空間:配置 物理メモリ空間 SDRAM PCIメモリ空間 メインメモリ メインメモリ 4GB システムBIOS PCI用MMIO PCIデバイス 3GB メインメモリ メインメモリ 1MB 予約 シャドウRAM VGAビデオ VGAビデオ 0xa0000 コンベンショナルメモリ メインメモリ 0MB (640KB) 3
  • 4.
    Type 0 31 - 24 23 - 16 15 - 8 7-0 1 00h Device ID Vendor ID 2 04h Status Command 3 08h Class code Subclass Prog IF Revision ID 4 0Ch BIST Header type Latency Timer Cache Line Size 5 10h Base address #0 (BAR0) 6 14h Base address #1 (BAR1) 7 18h Base address #2 (BAR2) 8 1Ch Base address #3 (BAR3) 9 20h Base address #4 (BAR4) 10 24h Base address #5 (BAR5) 11 28h Cardbus CIS Pointer 12 2Ch Subsystem ID Subsystem Vendor ID 13 30h Expansion ROM base address Capabilities 14 34h Reserved Pointer 15 38h Reserved 16 3Ch Max latency M l t Min Grant Mi G t Interrupt PIN I t t Interrupt Line I t t Li 4
  • 5.
    コンフィグレーション空間 … PF on Host [root@dut 0000:03:00.1]# lspci–x 03:00.0 Ethernet controller: Intel Corporation 82599EB 10 Gigabit TN Network Connection (rev 01) Vendor ID = 8086 (Intel) Device ID = 151c (82599EB 10 Gigabit TN Network Connection) Header Type = 80 bit 7 : Multi function Command = 0407 bit 6‐0 : non‐bridge function bit 0 : IO enable bit 1 : Mem enable Revision ID = 01 Class code = 02 (Network Controller) Status = 0010 00: 86 80 1c 15 07 04 10 00 01 00 00 02 10 00 80 00 10: 04 00 20 df 00 00 00 00 c1 ec 00 00 00 00 00 00 20: 04 80 1f df 00 00 00 00 00 00 00 00 86 80 2c a0 30: 00 00 00 00 40 00 00 00 00 00 00 00 0e 02 00 00 BAR#01 = 0000 0000 df20 0004 (Mem, 64bit)  IRQ PIN = INTB# BAR#23 = 0000 0000 0000 ecc1 IRQ Line = 0e (IO, 32bit) BAR#45 = 0000 0000 df1f 8004 (M 0000 0000 df1f 8004 (Mem, 64bit) 64bi ) Subsystem Vendor ID = 8086 (Intel) PCI IDs = Vendor ID + Device ID Subsystem ID = a02c (***********) http://pciids.sourceforge.net/ p p g http://pci‐ids.ucw.cz/read/PC/8086 !!PCIはリトルエンディアン!! 5
  • 6.
    コンフィグレーション空間 … VF on Host [root@dut 0000:03:00.1]# lspci–x 03:10.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller Virtual Function (rev 01) Vendor ID = ffff (n/a) / Device ID = ffff (n/a) Header Type = 80 bit 7 : Single function Command = 0004 bit 6‐0 : non‐bridge function bit 0 : IO disable bit 1 : Mem disable Revision ID = 01 Class code = 02 (Network Controller) Status = 0010 00: ff ff ff ff 04 00 10 00 01 00 00 02 00 00 00 00 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20: 00 00 00 00 00 00 00 00 00 00 00 00 86 80 2c a0 30: 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00 BAR#01 = 0000 0000 0000 0000 IRQ PIN = n/a BAR#23 = 0000 0000 0000 0000 IRQ Line = 00 BAR#45 = 0000 0000 0000 0000 0000 0000 0000 0000 Subsystem Vendor ID = 8086 (Intel) PCI IDs = Vendor ID + Device ID Subsystem ID = a02c (***********) http://pciids.sourceforge.net/ p p g http://pci‐ids.ucw.cz/read/PC/8086 !!PCIはリトルエンディアン!! 6
  • 7.
    コンフィグレーション空間 … VF on Guest [root@dutvm‐sriov ~]# lspci‐ x 00:03.0 Ethernet controller: Intel Corporation 82559 Ethernet Controller Virtual Function (rev 01) Vendor ID = 8086 (Intel) Device ID = 10ed (82559 Ethernet Controller Virtual Function) Header Type = 80 bit 7 : Single function Command = 0407  bit 6‐0 : non‐bridge function bit 0 : IO enable bit 1 : Mem enable Revision ID = 01 Class code = 02 (Network Controller) Status = 0010 00: 86 80 ed 10 07 04 10 00 01 00 00 02 00 00 00 00 10: 00 00 02 f2 00 00 00 00 00 00 00 00 00 40 02 f2 20: 00 00 00 00 00 00 00 00 00 00 00 00 86 80 2c a0 30: 00 00 00 00 a0 00 00 00 00 00 00 00 00 00 00 00 BAR#0 = f202 0000 (Mem, 32bit) IRQ PIN = n/a BAR#3 = f202 4000 (Mem, 32bit) IRQ Line = 00 BAR#45 = 0000 0000 0000 0000 0000 0000 0000 0000 Subsystem Vendor ID = 8086 (Intel) PCI IDs = Vendor ID + Device ID Subsystem ID = a02c (***********) http://pciids.sourceforge.net/ p p g http://pci‐ids.ucw.cz/read/PC/8086 !!PCIはリトルエンディアン!! 7
  • 8.
    PF on Host [root@dut ~]# lspci ‐v ‐s 03:00.0 03:00.0 Ethernet controller: Intel Corporation 82599EB 10 Gigabit TN Network Connection (rev 01) Subsystem: Intel Corporation Device a02c b l i i Flags: bus master, fast devsel, latency 0, IRQ 45 Memory at df200000 (64‐bit, non‐prefetchable) [size=2M] I/O ports at ecc0 [size=32] Memory at df1f8000 (64‐bit, non‐prefetchable) [size=16K] Capabilities: [40] Power Management version 3 Capabilities: [50] MSI: Enable‐ Count=1/1 Maskable+ 64bit+ Capabilities: [70] MSI X: Enable Count=64 Masked‐ Capabilities: [70] MSI‐X: Enable+ Count 64 Masked Capabilities: [a0] Express Endpoint, MSI 00 Capabilities: [e0] Vital Product Data Capabilities: [100] Advanced Error Reporting Capabilities: [140] Device Serial Number 00‐1b‐21‐ff‐ff‐ce‐51‐c4 Capabilities: [140] Device Serial Number 00 1b 21 ff ff ce 51 c4 Capabilities: [150] Alternative Routing‐ID Interpretation (ARI) Capabilities: [160] Single Root I/O Virtualization (SR‐IOV) Kernel driver in use: ixgbe Kernel modules: ixgbe l d l i b 8
  • 9.
    VF on Host / Guest 比較 [root@dut ~]# lspci ‐v ‐s 03:10.0 03:10.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller Virtual Function (rev 01) Subsystem: Intel Corporation Device a02c Subsystem: Intel Corporation Device a02c Flags: bus master, fast devsel, latency 0 [virtual] Memory at d0000000 (64‐bit, prefetchable) [size=16K] [virtual] Memory at d0100000 (64‐bit, prefetchable) [size=16K] Capabilities: [70] MSI‐X: Enable+ Count=3 Masked‐ p [ ] Capabilities: [a0] Express Endpoint, MSI 00 Capabilities: [100] Advanced Error Reporting Capabilities: [150] Alternative Routing‐ID Interpretation (ARI) Kernel driver in use: pci‐stub Kernel modules: ixgbevf l d l b f [root@dutvm‐sriov ~]# lspci ‐v ‐s 00:03.0 00:03.0 Ethernet controller: Intel Corporation 82559 Ethernet Controller Virtual Function (rev 01) Subsystem: Intel Corporation Device a02c Subsystem: Intel Corporation Device a02c Physical Slot: 3 Flags: bus master, fast devsel, latency 0 Memory at f2020000 (32‐bit, non‐prefetchable) [size=16K] Memory at f2024000 (32‐bit, non‐prefetchable) [size=16K] y ( , p )[ ] Capabilities: [a0] Express Endpoint, MSI 00 Capabilities: [70] MSI‐x: Enable+ Count=3 Masked‐ Kernel driver in use: ixgbevf Kernel modules: ixgbevf 9
  • 10.
    IO v.s. Memory ‐ MappedIO • IO Mapped IO – IO port (IO空間) を利用 – IO空間のアドレス=IOポートアドレス、ポート番号 – 1,2,4 Byte単位でのRead/Write – IO Port専用のニーモニックがある。asm/io.h • MMIO : Memory Mapped IO – IO Portの代わりにメモリアクセスをハードウェアレベルでのデバイスへのアクセスに置換 – デバイスに割当られたアドレス範囲にメモリアクセスをすることにより、ドライバからデバイス のレジスタRead/Write可能 – ドライバが動作する「仮想メモリアドレス」と、MMIO確保された「物理メモリアドレス」の違いに 注意 • (PCIe Root Bridge <‐> Device) は共通 PCIe Layer (PCI R PCI L B id D i ) – Config TLP (Transaction Layer Packet) でアクセス • 共通の抽象的なインタ フェ ス有り 共通の抽象的なインターフェース有り – asm/iomap.h – void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max len); 10
  • 11.
    IO v.s. Memory ‐ MappedIO • IO Ports, MMIO割当確認方法 – [root@hwn01 ~]# ls /proc/ | grep ^io – iomem – ioports [root@hwn01 ~]# cat /proc/ioports 0000‐0cf7 : PCI Bus 0000:00 0000‐001f : dma1 0020‐0021 : pic1 0040‐0043 : timer0 0050‐0053 : timer1 0050‐0053 : timer1 0060‐0060 : keyboard [root@hwn01 ~]# cat /proc/iomem 00000000‐0000ffff : reserved 00000000 0000ffff d 00010000‐0009f7ff : System RAM … f4000000‐f7ffffff : PCI MMCONFIG 0000 [bus 00‐3f] f4000000‐f7ffffff : reserved f4000000‐f7ffffff : pnp 00:0a fb400000‐fb7fffff : 0000:00:02.0 11
  • 12.
    メモ • MSI, MSI‐X の Configuration空間パラメーターと、/proc/interrupt で見える割り込み番号の関係 – ??? • PCIe MSI, MSI‐X の処理方法 – NICからアドレス0xfeeに対しメモリ書き込み(DWORD Mem Write Mem Write  Transaction) • アドレスは初期化時 MSI Capability Registerにソフトウェア(BIOS??)がセット • 0xfeeはLocal APIC のレジスタへMemory Mapされている APIC のレジスタ Memory – LAPICがCPUへ割り込み通知(INTR) – CPU ⇒ LAPICへAck(INTA) – LAPIC⇒CPU:Vectorを返す • VFのBAR – VFのメモリ空間にはBARはない – PFのSR IOV C bilit R i t に設定 PFのSR‐IOV Capability Registerに設定 – Host の lspci ‐v はそちらを表示 12
  • 13.
    メモ • 空の PCI スロットのベンダ ID とデバイス ID を 読み取ろうとしたときは、0xFFFFFFFF というエ ラ メッセ ジが返る ラー メッセージが返る • BARは起動時にBIOSが割り当て – http://www.mnc.co.jp/intime/user/intimedev.php ?PCI%A5%B3%A5%F3%A5%D5%A5%A3%A5%B0% A5%EC%A1%BC%A5%B7%A5%E7%A5%F3%A5%EC %A5%B8%A5%B9%A5%BF 13
  • 14.
    割り込み一覧(/proc/interrupts) [root@hwn01 ~]# cat/proc/interrupts CPU0 CPU1 CPU2 CPU3 0: 144 1 0 0 IO-APIC-edge timer 1: 3 0 1 2 IO-APIC-edge i8042 4: 4 0 1 1 0 IO-APIC-edge d 8: 33 58 31 57 IO-APIC-edge rtc0 9: 0 0 0 0 IO-APIC-fasteoi acpi 16: 0 0 0 0 IO-APIC-fasteoi ahci, uhci_hcd:usb3, uhci_hcd:usb9 17: 115 3 1 1 IO-APIC-fasteoi pata_jmicron, firewire_ohci 18: 2150 3669 117 284 IO-APIC-fasteoi ehci_hcd:usb1, uhci_hcd:usb5, uhci_hcd:usb8 19: 51447 1305 39191 1307 IO-APIC-fasteoi ata_piix, ata_piix, uhci_hcd:usb7 21: 0 0 0 0 IO-APIC-fasteoi uhci_hcd:usb4 23: 0 0 0 0 IO-APIC-fasteoi ehci_hcd:usb2, uhci_hcd:usb6 41: 58395 289 3073 269 PCI-MSI-edge i915@pci:0000:00:02.0 42: 47 50 47 52 PCI-MSI-edge hda_intel 43: 2710 6576 3336 3655 PCI-MSI-edge eth0 44: 0 0 0 1 PCI-MSI-edge xhci_hcd 45: 0 0 0 0 PCI-MSI-edge xhci_hcd 46: 0 0 0 0 PCI-MSI-edge xhci_hcd 47: 0 0 0 0 PCI-MSI-edge xhci_hcd 48: 0 0 0 0 PCI-MSI-edge xhci_hcd 49: 2985 6 648 5 PCI-MSI-edge eth1 NMI: 13 34 95 28 Non-maskable interrupts LOC: 332011 170933 296037 190006 Local timer interrupts SPU: 0 0 0 0 Spurious interrupts PMI: 13 34 95 28 Performance monitoring interrupts IWI: 0 0 0 0 IRQ work interrupts RES: 452195 37148 103501 14434 Rescheduling interrupts g p CAL: 812 6027 1044 7911 Function call interrupts TLB: 1077 644 2068 824 TLB shootdowns TRM: 0 0 0 0 Thermal event interrupts THR: 0 0 0 0 Threshold APIC interrupts MCE: 0 0 0 0 Machine check exceptions MCP: 29 28 28 28 Machine check polls ERR: 0 MIS: 0 14