PCIe: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Add categories: Hardware, Reference)
(Phase 0.4: Expand PCIe)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:PCIe layer.png|center|frameless|477x477px]]
= PCIe =


{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-15
|review=Pending
}}


{{TOC}}


Unlike the true buses of previous PCI versions, PCI-X included, PCIe is a kind of packet network faking the traditional PCI bus just like a network, with each card connected to a network switch through a dedicated set of wires. Exactly like a local Ethernet network, each card has its own physical connection to the switch fabric. The communication takes the form of packets transmitted over these dedicated lines, with flow control, error detection and retransmissions. There are no MAC addresses, but PCIe have the card’s physical geographic position addressing instead to define MAC. Even though it’s a packet-based network, it’s all about addresses, reads, writes an interrupt.
== Overview ==


PCIe(Peripheral Component Interconnect Express)는 패킷 기반的高速 직렬 확장 버스 표준입니다. 기존 PCI/PCI-X의 병렬 버스 아키텍처를 개선하여, 스위치 기반의 전용 연결로 각 카드가 독립적인 세트를의 와이어로 연결됩니다.


A minimal (1x) PCIe connection merely consists of four wires
=== Summary ===


* two differential pairs in each direction for data transmission
* 무엇인가? — 패킷 기반的高速 직렬 확장 버스 표준 (PCIe)
* another pair of wires to supply the card with a reference clock
* 왜 필요한가? — 높은 대역폭, 낮은 지연, 확장성, 후방 호환성
* 언제 사용하는가? — GPU, NVMe SSD, 네트워크 카드, 확장 카드 등
 
 
== Purpose ==
 
이 문서가 존재하는 이유
 
* Goal: PCIe 아키텍처, 대역폭, 전원, 프로토콜 계층, 흐름 제어 등 핵심 개념 제공
* Scope: PCIe 세대별 대역폭, 전원 공급, TLP/DLLP 계층, 흐름 제어, 가상 채널, 라우팅
* Non-goals: PCIe 커널 드라이버 개발, FPGA PCIe IP 코어 설계는 별도 문서
 
 
== Key Concepts ==


== PCIe bandwidth ==
{| class="wikitable"
{| class="wikitable"
|+PCIe bandwidth by generation<ref>https://en.wikipedia.org/wiki/Peripheral_Component_Interconnect</ref>
! Concept
!PCIe generation
! Description
!PCIe 1.0
! Related
!PCIe 2.0
|-
!PCIe 3.0
| Lane
!PCIe 4.0
| PCIe 기본 전송 채널 (2쌍 데이터 + 1쌍 클록)
![[PCIe 5.0]]
| [[PCIe]]
!PCIe 6.0
|-
!PCIe 7.0
| TLP
| Transaction Layer Packet — 상위 계층 패킷
| [[PCIe]]
|-
| DLLP
| Data Link Layer Packet — 신뢰성 제어 패킷
| [[PCIe]]
|-
|-
|Year of release
| Root Complex
|2003
| PCIe 호스트 브리지 (CPU 내 또는 별도 칩셋)
|2007
| [[PCIe]]
|2010
|2017
|2019
|2022
|2025 (planned)
|-
|-
|Data Transfer Rate
| Flow Control
|2.5 GT/s
| 수신 버퍼 여유 확인 후 전송 제어
|5.0 GT/s
| [[PCIe]]
|8.0 GT/s
|16 GT/s
|32 GT/s
|64 GT/s
|128.0 GT/s
|-
|-
|Total BW x 1 Lane
| Virtual Channel
|250 MB/s
| TC(Traffic Class) 기반 독립 흐름 제어
|500 MB/s
| [[PCIe]]
|1 GB/s
|2 GB/s
|4 GB/s
|8 GB/s
|15 GB/s
|-
|-
|Total BW x 2 Lane
| MSI
|500 MB/s
| Message Signaled Interrupts — 메모리 기반 인터럽트
|1 GB/s
| [[PCIe]]
|2 GB/s
|4 GB/s
|8 GB/s
|16 GB/s
|30 GB/s
|-
|-
|Total BW x 4 Lane
| DMA
|1 GB/s
| Direct Memory Access — 버스 마스터링
|2 GB/s
| [[PCIe]]
|4 GB/s
|}
|8 GB/s
 
|16 GB/s
 
|32 GB/s
== Architecture ==
|60 GB/s
 
PCIe는 3계층 아키텍처로 구성됩니다:
 
<syntaxhighlight lang="mermaid">
graph TD
    A[PCIe Stack] --> B[Transaction Layer]
    A --> C[Data Link Layer]
    A --> D[Physical Layer]
    B --> E[TLP - Transaction Layer Packet]
    C --> F[DLLP - Data Link Layer Packet]
    D --> G[Lane - Differential Pairs]
    B --> H[Root Complex / Switch]
    H --> I[Peripheral Device]
</syntaxhighlight>
 
 
== Workflow ==
 
{| class="wikitable"
! Stage
! Input
! Output
|-
| Write (Posted)
| Memory Write TLP
| Fire-and-forget 전송
|-
| Read (Non-Posted)
| Read Request TLP → Completion TLP
| 데이터 수신
|-
| Flow Control
| Flow Control DLLP
| 전송 크레딧 관리
|-
| Interrupt
| MSI TLP (Posted Write)
| 인터럽트 발생
|}
 
 
== Detailed Explanation ==
 
=== PCIe 아키텍처 ===
 
PCIe는 패킷 네트워크처럼 동작하는 직렬 버스입니다. 각 카드는 스위치 패브릭에 전용 연결로 연결되며, MAC 주소 대신 물리적 위치(버스/디바이스/함수)로 주소 지정됩니다.
 
최소 1x 연결은 4개의 와이어로 구성됩니다:
* 2쌍: 각 방향 데이터 전송용
* 1쌍: 참조 클록 공급용
 
=== PCIe 대역폭 ===
 
{| class="wikitable"
! Generation
! Release Year
! Data Rate
! BW x1 Lane
! BW x4 Lane
! BW x8 Lane
! BW x16 Lane
|-
| PCIe 1.0
| 2003
| 2.5 GT/s
| 250 MB/s
| 1 GB/s
| 2 GB/s
| 4 GB/s
|-
| PCIe 2.0
| 2007
| 5.0 GT/s
| 500 MB/s
| 2 GB/s
| 4 GB/s
| 8 GB/s
|-
| PCIe 3.0
| 2010
| 8.0 GT/s
| 1 GB/s
| 4 GB/s
| 8 GB/s
| 16 GB/s
|-
| PCIe 4.0
| 2017
| 16 GT/s
| 2 GB/s
| 8 GB/s
| 16 GB/s
| 32 GB/s
|-
| PCIe 5.0
| 2019
| 32 GT/s
| 4 GB/s
| 16 GB/s
| 32 GB/s
| 64 GB/s
|-
| PCIe 6.0
| 2022
| 64 GT/s
| 8 GB/s
| 32 GB/s
| 64 GB/s
| 128 GB/s
|-
| PCIe 7.0
| 2025 (예정)
| 128 GT/s
| 15 GB/s
| 60 GB/s
| 121 GB/s
| 242 GB/s
|}
 
예시: GPU가 16 PCIe 레인 사용 시
* PCIe 4.0: 16 × 16 GT/s = 256 GT/s
* PCIe 5.0: 16 × 32 GT/s = 512 GT/s
 
※ PCIe 3.0/4.0 인코딩 오버헤드 약 1.54%
 
=== PCIe 전원 ===
 
{| class="wikitable"
! 카드 타입
! +3.3V
! +12V
! 총합
|-
| 모든 PCIe 카드
| 최대 3A (9.9W)
| —
| —
|-
| x1 카드
| —
| 최대 0.5A (6W)
| 10W 합계
|-
| x4 이상 카드
| —
| 최대 2.1A (25W)
| 25W 합계
|-
| full-size x16 (그래픽)
| —
| 최대 5.5A (66W)
| 75W 합계
|-
| 6-pin 추가 커넥터
| —
| +75W
| 최대 150W
|-
| 8-pin 추가 커넥터
| —
| +150W
| 최대 300W (2×75W + 1×150W)
|-
| 1×75W + 2×150W
| —
| —
| 최대 375W
|}
 
=== 단순 버스 트랜잭션 ===
 
==== PCIe Write (Posted) ====
1. Root Complex가 Memory Write TLP 생성 (헤더 3-4 DW + 데이터 1 DW)
2. TLP를 PCIe 포트에 전송
3. 대상 peripheral이 라우팅, 디코딩, 실행
4. Fire-and-forget — 응답 불필요
 
==== PCIe Read (Non-Posted) ====
1. CPU가 peripheral에 Read Request TLP 전송
2. peripheral이 Completion TLP로 데이터 응답
3. CPU는 Completion 수신까지 대기
 
=== PCIe 통신 계층 ===
 
{| class="wikitable"
! 계층
! 역할
! 패킷
|-
|-
|Total BW x 8 Lane
| Transaction Layer
|2 GB/s
| TX/RX 패킷 정의
|4 GB/s
| TLP (Transaction Layer Packet)
|8 GB/s
|16 GB/s
|32 GB/s
|64 GB/s
|121 GB/s
|-
|-
|Total BW x 16Lane
| Data Link Layer
|4 GB/s
| TLP 무결성 보장, 재전송, 흐름 제어
|8 GB/s
| DLLP (Data Link Layer Packet)
|16 GB/s
|32 GB/s
|64 GB/s
|128 GB/s
|242 GB/s
|-
|-
| colspan="8" |Data transfer rate is measured in <u>Giga'''bits''' (Gb)</u> per second.
| Physical Layer
On the other hand, bandwidth is measured in <u>Giga'''bytes''' (GB)</u> per second: 8 Gigabits = 1 Gigabyte
| 실제 신호 전송 (와이어, 클록)
| Lane (차분 쌍)
|}
 
**DLLP 타입:**
* Ack DLLP — 성공적 TLP 수신 확인
* Nack DLLP — 손상된 TLP 재전송 요청
* Flow Control DLLP — 크레딧 공지 (InitFC1, InitFC2, UpdateFC)
* Power Management DLLP
 
**TLP 크기:** 최대 128, 256, 또는 512 바이트
 
=== 흐름 제어 (Flow Control) ===
 
Data Link Layer의 흐름 제어는 TLP가 link partner의 수신 버퍼 여유 확인 후 전송되도록 합니다.


PCIe gen 3 and 4, the encoding overhead is roughly 1.54%. So, the maximum theoretical bandwidth in Gbps (Gigabits per second) of each PCIe Gen 5.0 looks like : 32GT/s – (32GT/s x 1.54%) =31.5702 Gbps ( or ~3.95GB/s)
**중요:** flow control은 최종 destination이 아닌 link partner에 대해 작동합니다. Switch를 경유할 경우 각 hop마다 독립적인 흐름 제어가 적용됩니다.
 
**6개 독립 계정:**
1. Posted Requests TLP headers
2. Posted Requests TLP data
3. Non-Posted Requests TLP headers
4. Non-Posted Requests TLP data
5. Completion TLP headers
6. Completion TLP data
 
=== 가상 채널 (Virtual Channels) ===
 
TC(Traffic Class)는 TLP에서 가상 채널을 식별하는 데 사용됩니다. 각 가상 채널은 독립적인 흐름 제어 크레딧과 카운터를 가집니다. TC 0 외의 값을 선택하면 다른 채널의 트래픽이 차단되지 않습니다.
 
=== 식별 및 라우팅 ===
 
PCIe 스위치는 각 TLP를 어디로 보낼지 알아야 합니다. 3가지 라우팅 방법:
 
1. **주소 라우팅** — Memory/I/O Read/Write 요청
2. **암시적 라우팅** — Root Complex 브로드캐스트 및 응답 메시지
3. **ID 라우팅** — 나머지 모든 TLP (Bus:Device:Function 16-bit triplet)
 
=== Posted vs Non-Posted 연산 ===
 
{| class="wikitable"
! 타입
! 연산
! 특징
|-
| Posted (Write)
| Memory Write
| Fire-and-forget — 전송 후 대기 불필요
|-
| Non-Posted (Read)
| Memory Read
| Requester가 Completion 수신까지 대기, CPU 버스 홀드 가능
|}
|}


For example, A GPU uses 16 PCIe lanes,
Non-Posted Read는 버스 지연을 유발할 수 있으므로 최신 시스템에서는 최소화됩니다.


* Your peak theoretical bit rate via '''PCIe 4.0''' would be:
=== 32 vs 64 비트 주소 ===
** 16 Lanes x 16 Gigatransfers per lane = '''256 GT/s'''
* Your peak theoretical bit rate via '''PCIe 5.0''' would be:
** 16 Lanes x 32 Gigatransfers per lane = '''512 GT/s'''


== PCIe power<ref>https://en.wikipedia.org/wiki/PCI_Express</ref> ==
* 32비트 주소: 헤더 3 DW
* 64비트 주소: 헤더 4 DW


=== Power from PCIe bus ===
PCIe spec: 4GB 미만 주소는 32비트 형식 사용 필수. 4GB 초과 주소(예: DMA 버퍼)는 64비트 형식 필요.


* All PCI express cards may consume up to 3 A at +3.3 V (9.9 W).
=== I/O 요청 ===


* x1 cards are limited to 0.5 A at +12 V (6 W) and 10 W combined
PCIe는 후방 호환성을 위해 I/O 연산을 지원하지만 새 설계에서는 사용을 권장하지 않습니다. I/O Read/Write 모두 Non-Posted이므로 Write에서도 Completion 대기 필요. 또한 32비트 주소만 지원.
* x4 and wider cards are limited to 2.1 A at +12 V (25 W) and 25 W combined.
* A full-sized x1 card may draw up to the 25 W limits after initialization and software configuration as a high-power device.
* A full-sized x16 graphics card may draw up to 5.5 A at +12 V (66 W) and 75 W combined after initialization and software configuration as a high-power device.


=== Optional connectors ===
=== 인터럽트 ===
add 75 W (6-pin) or 150 W (8-pin) of +12 V power for up to 300 W total (2 × 75 W + 1 × 150 W) through power supply to the device.


* Sense0 pin is connected to ground by the cable or power supply, or float on board if cable is not connected.
{| class="wikitable"
* Sense1 pin is connected to ground by the cable or power supply, or float on board if cable is not connected.
! 타입
! 설명
! 특징
|-
| INTx
| 레거시 레벨 트리거 인터럽트
| 공유 가능, 각 핸들러가 본인 확인 필요
|-
| MSI
| 메모리 기반 메시지 인터럽트
| Posted Write TLP, OS가 직접 핸들러 호출, 클리어 불필요
|}


Some cards use two 8-pin connectors, but this has not been standardized yet as of 2018, therefore such cards must not carry the official PCI Express logo. This configuration allows 375 W total (1 × 75 W + 2 × 150 W) and will likely be standardized by PCI-SIG with the PCI Express 4.0 standard.<sup>[''needs update'']</sup> The 8-pin PCI Express connector could be confused with the EPS12V connector, which is mainly used for powering SMP and multi-core systems. The power connectors are variants of the Molex Mini-Fit Jr. series connectors.
MSI는 PCI 2.2에서 도입되었으며, 현대 OS(리눅스 포함)에서 널리 사용됩니다.


== A simple bus transaction ==
=== 버스 마스터링 (DMA) ===


=== Simple PCIe write operation ===
PCIe에서 모든 디바이스는 Root Complex처럼 Read/Write TLP를 전송할 수 있습니다. 이를 통해 peripheral이 CPU 메모리에 직접 접근(DMA)하거나 peer peripheral과 TLP를 교환할 수 있습니다.
# PCIe chipset (which, in PCIe [[terms]] functions as a '''Root Complex, can be within CPU or PCIe switch or independant''') generates a Memory Write packet for transmission over the bus.  
#* This packet consists of a header, which is either 3 or 4 32-bit words long (depending on if 32 or 64 bit addressing is used) and one 32-bit word containing the word to be written. This packet simply says “write this data to this address”.
# This packet is then transmitted on the chipset’s PCIe port (or one of them, if there are several). The target peripheral may be connected directly to the chipset, or there may be a switch network between them. This way or another, the packet is routed to the peripheral, decoded, and executed by performing the desired write operation.


=== Simple PCIe read operation ===
**DMA 설정:**
1. 표준 구성 레지스터에서 "Bus Master Enable" 비트 설정
2. 드라이버가 BAR 매핑 레지스터에 버퍼 물리 주소 쓰기


# CPU wants to read from a peripheral.  One TLP from the CPU to the peripheral, asking the latter to perform a read operation (PCIe terms, Requester)
=== Reference ===
# Then TLP going back with the data from peripheral (PCIe terms,  '''Completer)'''
# When the peripheral receives a Read Request TLP, it must respond with some sort of Completion TLP, even if it can’t fulfill the action requested


=== PCIe communication Layers ===
* http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-1
The communications mechanism  consists of three layers: The Transaction Layer, the Data Link Layer, and the Physical Layer
* http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-2


# Transaction Layer Packet (TLP) is PCIe’s uppermost layer to define TX/RX packets
# Data Link layer  is responsible for making sure that every TLP arrives to its destination correctly. It wraps TLPs with its own header and with a Link CRC to make sure TLP’s integrity is assured.
#* An acknowledge-retransmit mechanism makes sure no TLPs are lost on the way
#* A flow control mechanism makes sure a packet is sent only when the link partner is ready to receive it.
#* The TLP’s size limits are set at the peripheral’s configuration stage, but typical numbers are a maximum of 128, 256 or 512 bytes per TLP
#* Data Link Layer Packets (DLLPs) packets for maintaining reliable transmission.
#** Ack DLLP for acknowledging successfully received TLPs.
#** Nack DLLP for indicating that a TLP arrived corrupted, and that a retransmit is due. Note that there’s also a timeout mechanism in case nothing that looks like a TLP arrives.
#** Flow Control DLLPs: InitFC1, InitFC2 and UpdateFC, used to announce credits, as described below.
#** Power Management DLLPs
# Physical Layer


== Flow control ==
== Configuration ==
The data link layer has a Flow Control (FC) mechanism, which makes sure that a TLP is transmitted only when the '''link partner''' has enough buffer space to accept it.


The term “'''link partner'''” and not “'''destination'''” deliberately. Becuase when a peripheral is connected to the Root Complex through a switch, it runs its flow control mechanism against the switch and not the final destination. In other words, once the TLP is transmitted from the peripheral, it’s still subject to the flow control mechanism between the switch and the Root Complex. '''If there are more switches on the way, each leg has its own flow control.'''
<syntaxhighlight lang="bash">
# PCIe 디바이스 확인
lspci
lspci -v
lspci -vvv


The flow control mechanism runs independent accounting for six distinct buffer consumers
# PCIe 레인 속도 확인
lspci -vvv | grep -i width
lspci -vvv | grep -i speed


# Posted Requests TLP’s headers
# PCIe 링크 상태
# Posted Requests TLP’s data
lspci -vvv | grep -i LnkSta
# Non-Posted Requests TLP’s headers
</syntaxhighlight>
# Non-Posted Requests TLP’s data
# Completion TLP’s headers
# Completion TLP’s data


== Virtual channels ==
TC (Traffic Class) in the TLPs is an identifier used to create Virtual Channels. These Virtual Channels are merely separate sets of data buffers having a separate flow control credits and counters. So by choosing a TC other than zero (and setting up the bus entities accordingly) one can have TLPs being subject to independent flow control systems, preventing TLPs belonging to one channel block the traffic of TLPs belonging to another.


== Examples ==


=== Example 1: GPU 대역폭 계산 ===


Packet reordering
{| class="wikitable"
! GPU Lanes
| PCIe 3.0
| PCIe 4.0
| PCIe 5.0
|-
| x1
| 1 GB/s
| 2 GB/s
| 4 GB/s
|-
| x4
| 4 GB/s
| 8 GB/s
| 16 GB/s
|-
| x8
| 8 GB/s
| 16 GB/s
| 32 GB/s
|-
| x16
| 16 GB/s
| 32 GB/s
| 64 GB/s
|}


One of the issues that comes to mind in a packet network, is to what extent the TLPs may arrive in an order different from how they were sent. The Internet Protocol (IP, as in TCP/IP) for example, allows any packet reshuffling on the way. PCIe spec defines reordering rules in full detail.
=== Example 2: PCIe 디바이스 정보 확인 ===


== Identification and routing ==
<syntaxhighlight lang="bash">
Since PCIe is essentially a packet network, with the possibility of switches on the way, these switches need to know where to send each TLP. 
# 모든 PCIe 디바이스 목록
[[File:Formation of PCIe ID.png|center|frameless|528x528px]]
$ lspci


There are three routing methods:
# 상세 정보
$ lspci -v


# '''By address  routing''' is applied for Memory and I/O Requests (read and write).
# 매우 상세 정보 (링크 속도, 레인 수 등)
# '''Implicit routing''' is used only for certain message TLPs, such as broadcasts from Root Complex and messages that always go to the Root Complex
$ lspci -vvv
# '''By ID routing''' are all other TLPs are routed by ID.


The ID is a 16-bit word formed in terms of the well known triplet: Bus number, Device number and Function number. Their meaning is exactly like in legacy PCI buses. The ID is formed as follows:
# 특정 디바이스 정보
$ lspci -s 01:00.0 -v
</syntaxhighlight>


== Posted and non-Posted operations ==


=== '''Posted''' operations (Write) ===
== Best Practices ==
such as a Memory Write, A write TLP operation is fire-and-forget method. Once the packet has been formed and handed over to the Data Link Layer, there’s no need to worry about it anymore.


=== '''non-Posted''' operations (Read) ===
* PCIe 4.0 이상 사용 권장 (대역폭 효율성)
like A read operation, consist of a Request and Completion requires the Requester to wait for a Completion. Until the Completion packet arrives, the Requester must retain information about what the Request was, and sometimes even hold the CPU’s bus. If the CPU’s bus started a read cycle, it must be held in wait states until the value of the desired read operation is available at the bus’ data lines. This can be a horrible slowdown of the bus, which is rightfully avoided in recent systems.
* GPU는 x16 레인 사용 (최대 대역폭)
* NVMe SSD는 x4 레인 이상 사용
* DMA 버퍼는 64비트 주소 지원 확인
* MSI 인터럽트 사용 (INTx 대신)
* 흐름 제어 크레딧 모니터링
* TC(Traffic Class)를 활용한 QoS 설정


== 32 vs. 64 bit addressing ==
the address given in read and write requests can be either 32 or 64 bits wide, making the header either 3 or 4 DWs long. However section 2.2.4.1 in the PCIe spec states that the 4 DW header format must be used only when necessary.<blockquote>For Addresses below 4 GB, Requesters must use the 32-bit format. The behavior of the receiver is not specified if a 64-bit format request addressing below 4 GB (i.e., with the upper 32 bits of address all 0) is received.</blockquote>In reality, it's rare that any peripheral's register is mapped over the 4 GB range, however DMA buffers may very well go beyond the 4 GB boundary. As a result, read and write TLPs with 64 bit addressing should be supported when designing a new device.


== I/O Requests ==
== Limitations ==
The PCIe bus supports I/O operations only for the sake of backward compatibility, and strongly recommends not to use I/O TLPs in new designs. One of the reasons is that both read and write requests in I/O space are non-Posted, so the Requester is forced to wait for a completion on write operations as well. Another issue is that I/O operations only take 32-bit addresses, while the PCIe spec endorses 64-bit [[support]] in general.


== Interrupts ==
* PCIe 1.0/2.0: 대역폭 제한 (구형 시스템)
PCIe supports two kinds of interrupts: Legacy INTx and MSI.
* INTx: 인터럽트 공유 문제
* I/O TLP: Non-Posted로 인한 지연
* 32비트 주소: 4GB 초과 주소 사용 불가
* 스위치 추가: 각 hop마다 흐름 제어 오버헤드


# INTx interrupts are supported for the sake of compatibility with legacy software, and also in order to allow bridging between classic PCI buses and PCIe. Since INTx interrupts are level triggered (i.e. the interrupt request is active as long as the physical INTx wire is at low voltage), there’s a TLP packet for saying that the line has been asserted, and another that it has been deasserted. Not only is this a quirky in itself, but the old problems with INTx interrupts retain, such as interrupt sharing and the need for each interrupt handling routine to check who the interrupt is really for.
# To enhance INTx, a new form of interrupt, MSI, was introduced in (conventional) PCI 2.2. The idea was, that since virtually all PCI peripherals have bus master capabilities, MSI uses the peripheral signal an interrupt by writing to a certain address. Signaling an interrupt merely consists of sending a TLP over the bus, which is simply a posted Write Request, with a special address, which the host has written into the peripheral’s configuration space during initialization. Any modern operating system ([[Linux]] included, of course) can then call the correct interrupt routine, without the need to guess who generated the interrupt. Neither is it really necessary to “clear” the interrupt, if the peripheral doesn’t need the acknowledgment.


== Bus Mastering (DMA) ==
== References ==
On PCIe, It boils down to the simple notion, that anyone on the bus can send read and write TLPs on the bus, exactly like the Root Complex. This allows the peripheral to access the CPU’s memory directly (DMA) or exchange TLPs with peer peripherals.


To use DMA, two things that need to be set
* https://en.wikipedia.org/wiki/Peripheral_Component_Interconnect
* http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-1
* http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-2


# First, as with any PCI device: The peripheral needs to be granted bus mastering by setting the “Bus Master Enable” bit in one of the standard configuration registers.
# The second thing is that the driver software needs to inform the peripheral about the relevant buffer’s physical address, most probably by writing to a BAR-mapped register.


== Reference ==
== Related Pages ==
http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-1
 
* [[PCIe 5.0]]
* [[Intel 4th Gen Xeon]]
* [[NVIDIA GPU]]
* [[NVMe]]
* [[DMA]]
 


http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-2
[[Category:Hardware]]
[[Category:Hardware]]
== Knowledge Graph ==
Related
→ [[ACS]]
→ [[Bifurcation]]
→ [[CPU features]]
→ [[Dual vs Single PCIe Root Configuration]]
→ [[AER (Advanced Error Reporting)]]
→ [[ASPM]]
→ [[PCIe 5.0]]


[[Category:Reference]]
[[Category:Reference]]
== PCIe 6.0 ==
PCIe 6.0은 2022년 출시. 32 GT/s, 15 GB/s per lane.
{| class="wikitable"
|+PCIe 6.0 대역폭
! Lane ! x1 ! x4 ! x8 ! x16
|-
| 대역폭 | 15 GB/s | 60 GB/s | 120 GB/s | 240 GB/s
|}
* PAM4 변조 방식 (PCIe 5.0의 NRZ 대비 효율 2x)
* Forward Error Correction (FEC) 추가
* 8b/10b → 128b/132b 인코딩 (PCIe 5.0과 동일)
== PCIe 7.0 (계획) ==
PCIe 7.0은 2025년 계획. 64 GT/s, 30 GB/s per lane.
{| class="wikitable"
|+PCIe 7.0 예상 대역폭
! Lane ! x1 ! x4 ! x8 ! x16
|-
| 예상 대역폭 | 30 GB/s | 120 GB/s | 240 GB/s | 480 GB/s
|}
== CXL (Compute Express Link) ==
CXL은 CPU- 가속기 간 고속 연결. PCIe와 호환. 메모일리티(Memory Interconnect) 지원.
* CXL 2.0: 2021년 출시. 메모일리티 지원
* CXL 3.0: 2023년 출시. 동적 메모리 분할 지원
* CXL over PCIe 물리 레이어 사용
* CPU ↔ GPU, CPU ↔ FPGA, CPU ↔ 스토리지 간 연결
<syntaxhighlight lang="bash">
# CXL 장치 확인
lspci | grep -i cxl
# CXL 메모리 확인
cat /sys/bus/cxl/devices/*/*memory
</syntaxhighlight>

Latest revision as of 13:37, 17 July 2026

PCIe

Template:Status

Template:TOC

Overview

PCIe(Peripheral Component Interconnect Express)는 패킷 기반的高速 직렬 확장 버스 표준입니다. 기존 PCI/PCI-X의 병렬 버스 아키텍처를 개선하여, 스위치 기반의 전용 연결로 각 카드가 독립적인 세트를의 와이어로 연결됩니다.

Summary

  • 무엇인가? — 패킷 기반的高速 직렬 확장 버스 표준 (PCIe)
  • 왜 필요한가? — 높은 대역폭, 낮은 지연, 확장성, 후방 호환성
  • 언제 사용하는가? — GPU, NVMe SSD, 네트워크 카드, 확장 카드 등


Purpose

이 문서가 존재하는 이유

  • Goal: PCIe 아키텍처, 대역폭, 전원, 프로토콜 계층, 흐름 제어 등 핵심 개념 제공
  • Scope: PCIe 세대별 대역폭, 전원 공급, TLP/DLLP 계층, 흐름 제어, 가상 채널, 라우팅
  • Non-goals: PCIe 커널 드라이버 개발, FPGA PCIe IP 코어 설계는 별도 문서


Key Concepts

Concept Description Related
Lane PCIe 기본 전송 채널 (2쌍 데이터 + 1쌍 클록) PCIe
TLP Transaction Layer Packet — 상위 계층 패킷 PCIe
DLLP Data Link Layer Packet — 신뢰성 제어 패킷 PCIe
Root Complex PCIe 호스트 브리지 (CPU 내 또는 별도 칩셋) PCIe
Flow Control 수신 버퍼 여유 확인 후 전송 제어 PCIe
Virtual Channel TC(Traffic Class) 기반 독립 흐름 제어 PCIe
MSI Message Signaled Interrupts — 메모리 기반 인터럽트 PCIe
DMA Direct Memory Access — 버스 마스터링 PCIe


Architecture

PCIe는 3계층 아키텍처로 구성됩니다:

graph TD
    A[PCIe Stack] --> B[Transaction Layer]
    A --> C[Data Link Layer]
    A --> D[Physical Layer]
    B --> E[TLP - Transaction Layer Packet]
    C --> F[DLLP - Data Link Layer Packet]
    D --> G[Lane - Differential Pairs]
    B --> H[Root Complex / Switch]
    H --> I[Peripheral Device]


Workflow

Stage Input Output
Write (Posted) Memory Write TLP Fire-and-forget 전송
Read (Non-Posted) Read Request TLP → Completion TLP 데이터 수신
Flow Control Flow Control DLLP 전송 크레딧 관리
Interrupt MSI TLP (Posted Write) 인터럽트 발생


Detailed Explanation

PCIe 아키텍처

PCIe는 패킷 네트워크처럼 동작하는 직렬 버스입니다. 각 카드는 스위치 패브릭에 전용 연결로 연결되며, MAC 주소 대신 물리적 위치(버스/디바이스/함수)로 주소 지정됩니다.

최소 1x 연결은 4개의 와이어로 구성됩니다:

  • 2쌍: 각 방향 데이터 전송용
  • 1쌍: 참조 클록 공급용

PCIe 대역폭

Generation Release Year Data Rate BW x1 Lane BW x4 Lane BW x8 Lane BW x16 Lane
PCIe 1.0 2003 2.5 GT/s 250 MB/s 1 GB/s 2 GB/s 4 GB/s
PCIe 2.0 2007 5.0 GT/s 500 MB/s 2 GB/s 4 GB/s 8 GB/s
PCIe 3.0 2010 8.0 GT/s 1 GB/s 4 GB/s 8 GB/s 16 GB/s
PCIe 4.0 2017 16 GT/s 2 GB/s 8 GB/s 16 GB/s 32 GB/s
PCIe 5.0 2019 32 GT/s 4 GB/s 16 GB/s 32 GB/s 64 GB/s
PCIe 6.0 2022 64 GT/s 8 GB/s 32 GB/s 64 GB/s 128 GB/s
PCIe 7.0 2025 (예정) 128 GT/s 15 GB/s 60 GB/s 121 GB/s 242 GB/s

예시: GPU가 16 PCIe 레인 사용 시

  • PCIe 4.0: 16 × 16 GT/s = 256 GT/s
  • PCIe 5.0: 16 × 32 GT/s = 512 GT/s

※ PCIe 3.0/4.0 인코딩 오버헤드 약 1.54%

PCIe 전원

카드 타입 +3.3V +12V 총합
모든 PCIe 카드 최대 3A (9.9W)
x1 카드 최대 0.5A (6W) 10W 합계
x4 이상 카드 최대 2.1A (25W) 25W 합계
full-size x16 (그래픽) 최대 5.5A (66W) 75W 합계
6-pin 추가 커넥터 +75W 최대 150W
8-pin 추가 커넥터 +150W 최대 300W (2×75W + 1×150W)
1×75W + 2×150W 최대 375W

단순 버스 트랜잭션

PCIe Write (Posted)

1. Root Complex가 Memory Write TLP 생성 (헤더 3-4 DW + 데이터 1 DW) 2. TLP를 PCIe 포트에 전송 3. 대상 peripheral이 라우팅, 디코딩, 실행 4. Fire-and-forget — 응답 불필요

PCIe Read (Non-Posted)

1. CPU가 peripheral에 Read Request TLP 전송 2. peripheral이 Completion TLP로 데이터 응답 3. CPU는 Completion 수신까지 대기

PCIe 통신 계층

계층 역할 패킷
Transaction Layer TX/RX 패킷 정의 TLP (Transaction Layer Packet)
Data Link Layer TLP 무결성 보장, 재전송, 흐름 제어 DLLP (Data Link Layer Packet)
Physical Layer 실제 신호 전송 (와이어, 클록) Lane (차분 쌍)
    • DLLP 타입:**
  • Ack DLLP — 성공적 TLP 수신 확인
  • Nack DLLP — 손상된 TLP 재전송 요청
  • Flow Control DLLP — 크레딧 공지 (InitFC1, InitFC2, UpdateFC)
  • Power Management DLLP
    • TLP 크기:** 최대 128, 256, 또는 512 바이트

흐름 제어 (Flow Control)

Data Link Layer의 흐름 제어는 TLP가 link partner의 수신 버퍼 여유 확인 후 전송되도록 합니다.

    • 중요:** flow control은 최종 destination이 아닌 link partner에 대해 작동합니다. Switch를 경유할 경우 각 hop마다 독립적인 흐름 제어가 적용됩니다.
    • 6개 독립 계정:**

1. Posted Requests TLP headers 2. Posted Requests TLP data 3. Non-Posted Requests TLP headers 4. Non-Posted Requests TLP data 5. Completion TLP headers 6. Completion TLP data

가상 채널 (Virtual Channels)

TC(Traffic Class)는 TLP에서 가상 채널을 식별하는 데 사용됩니다. 각 가상 채널은 독립적인 흐름 제어 크레딧과 카운터를 가집니다. TC 0 외의 값을 선택하면 다른 채널의 트래픽이 차단되지 않습니다.

식별 및 라우팅

PCIe 스위치는 각 TLP를 어디로 보낼지 알아야 합니다. 3가지 라우팅 방법:

1. **주소 라우팅** — Memory/I/O Read/Write 요청 2. **암시적 라우팅** — Root Complex 브로드캐스트 및 응답 메시지 3. **ID 라우팅** — 나머지 모든 TLP (Bus:Device:Function 16-bit triplet)

Posted vs Non-Posted 연산

타입 연산 특징
Posted (Write) Memory Write Fire-and-forget — 전송 후 대기 불필요
Non-Posted (Read) Memory Read Requester가 Completion 수신까지 대기, CPU 버스 홀드 가능

Non-Posted Read는 버스 지연을 유발할 수 있으므로 최신 시스템에서는 최소화됩니다.

32 vs 64 비트 주소

  • 32비트 주소: 헤더 3 DW
  • 64비트 주소: 헤더 4 DW

PCIe spec: 4GB 미만 주소는 32비트 형식 사용 필수. 4GB 초과 주소(예: DMA 버퍼)는 64비트 형식 필요.

I/O 요청

PCIe는 후방 호환성을 위해 I/O 연산을 지원하지만 새 설계에서는 사용을 권장하지 않습니다. I/O Read/Write 모두 Non-Posted이므로 Write에서도 Completion 대기 필요. 또한 32비트 주소만 지원.

인터럽트

타입 설명 특징
INTx 레거시 레벨 트리거 인터럽트 공유 가능, 각 핸들러가 본인 확인 필요
MSI 메모리 기반 메시지 인터럽트 Posted Write TLP, OS가 직접 핸들러 호출, 클리어 불필요

MSI는 PCI 2.2에서 도입되었으며, 현대 OS(리눅스 포함)에서 널리 사용됩니다.

버스 마스터링 (DMA)

PCIe에서 모든 디바이스는 Root Complex처럼 Read/Write TLP를 전송할 수 있습니다. 이를 통해 peripheral이 CPU 메모리에 직접 접근(DMA)하거나 peer peripheral과 TLP를 교환할 수 있습니다.

    • DMA 설정:**

1. 표준 구성 레지스터에서 "Bus Master Enable" 비트 설정 2. 드라이버가 BAR 매핑 레지스터에 버퍼 물리 주소 쓰기

Reference


Configuration

# PCIe 디바이스 확인
lspci
lspci -v
lspci -vvv

# PCIe 레인 속도 확인
lspci -vvv | grep -i width
lspci -vvv | grep -i speed

# PCIe 링크 상태
lspci -vvv | grep -i LnkSta


Examples

Example 1: GPU 대역폭 계산

GPU Lanes PCIe 3.0 PCIe 4.0 PCIe 5.0
x1 1 GB/s 2 GB/s 4 GB/s
x4 4 GB/s 8 GB/s 16 GB/s
x8 8 GB/s 16 GB/s 32 GB/s
x16 16 GB/s 32 GB/s 64 GB/s

Example 2: PCIe 디바이스 정보 확인

# 모든 PCIe 디바이스 목록
$ lspci

# 상세 정보
$ lspci -v

# 매우 상세 정보 (링크 속도, 레인 수 등)
$ lspci -vvv

# 특정 디바이스 정보
$ lspci -s 01:00.0 -v


Best Practices

  • PCIe 4.0 이상 사용 권장 (대역폭 효율성)
  • GPU는 x16 레인 사용 (최대 대역폭)
  • NVMe SSD는 x4 레인 이상 사용
  • DMA 버퍼는 64비트 주소 지원 확인
  • MSI 인터럽트 사용 (INTx 대신)
  • 흐름 제어 크레딧 모니터링
  • TC(Traffic Class)를 활용한 QoS 설정


Limitations

  • PCIe 1.0/2.0: 대역폭 제한 (구형 시스템)
  • INTx: 인터럽트 공유 문제
  • I/O TLP: Non-Posted로 인한 지연
  • 32비트 주소: 4GB 초과 주소 사용 불가
  • 스위치 추가: 각 hop마다 흐름 제어 오버헤드


References


Related Pages

Knowledge Graph

Related

ACSBifurcationCPU featuresDual vs Single PCIe Root ConfigurationAER (Advanced Error Reporting)ASPMPCIe 5.0

PCIe 6.0

PCIe 6.0은 2022년 출시. 32 GT/s, 15 GB/s per lane.

PCIe 6.0 대역폭
Lane ! x1 ! x4 ! x8 ! x16
15 GB/s | 60 GB/s | 120 GB/s | 240 GB/s
  • PAM4 변조 방식 (PCIe 5.0의 NRZ 대비 효율 2x)
  • Forward Error Correction (FEC) 추가
  • 8b/10b → 128b/132b 인코딩 (PCIe 5.0과 동일)

PCIe 7.0 (계획)

PCIe 7.0은 2025년 계획. 64 GT/s, 30 GB/s per lane.

PCIe 7.0 예상 대역폭
Lane ! x1 ! x4 ! x8 ! x16
30 GB/s | 120 GB/s | 240 GB/s | 480 GB/s

CXL (Compute Express Link)

CXL은 CPU- 가속기 간 고속 연결. PCIe와 호환. 메모일리티(Memory Interconnect) 지원.

  • CXL 2.0: 2021년 출시. 메모일리티 지원
  • CXL 3.0: 2023년 출시. 동적 메모리 분할 지원
  • CXL over PCIe 물리 레이어 사용
  • CPU ↔ GPU, CPU ↔ FPGA, CPU ↔ 스토리지 간 연결
# CXL 장치 확인
lspci | grep -i cxl

# CXL 메모리 확인
cat /sys/bus/cxl/devices/*/*memory