Ch 15: Tools — lspci·setpci·pcimem·protocol analyzer
#한 줄 요약
“PCIe 트러블슈팅은 lspci로 topology·capability dump → setpci로 register read·write → pcimem으로 BAR 직접 access → dmesg·debugfs로 kernel state → 마지막에 protocol analyzer의 흐름입니다.” — 대부분 문제는 lspci -vv + dmesg로 해결, 드물게 setpci의 raw write가 필요, 진짜 link 문제는 protocol analyzer hardware.
Ch 1~14에서 PCIe의 동작 원리를 봤습니다. 이 장은 그것을 진단·검증할 도구를 본격적으로 분해합니다.
#lspci — 1차 진단 도구
pciutils 패키지에 포함. PCIe device 정보 dump:
| 옵션 | 효과 |
|---|---|
-t | tree topology — switch·port 구조 |
-tv | tree + vendor/device 이름 |
-D | full domain (0000:bb.f) |
-x | 256 byte config space hex dump |
-xxx | 4 KB extended config space hex dump |
-xxxx | 4 KB + capability 분해 |
-vv | 모든 capability 디코딩 (실용 1순위) |
-k | kernel driver·module 정보 |
-nn | numeric ID + name |
-s 01:00.0 | 특정 device |
#lspci -vv 출력 해석
01:00.0 Network controller [0280]: Intel Corp. 82599EB ... Subsystem: Intel Corp. ... Flags: bus master, fast devsel, latency 0, IRQ 50 Memory at f7800000 (64-bit, prefetchable) [size=4M] Capabilities: [40] Power Management ... Capabilities: [50] MSI: Enable+ Count=1/1 ... Capabilities: [60] MSI-X: Enable+ Count=64 ... Capabilities: [a0] Express Endpoint, ... LnkCap: Port #0, Speed 8GT/s, Width x8 ... LnkSta: Speed 8GT/s (ok), Width x8 (ok) DevCtl: ... MaxPayload 256 ... DevCtl2: ... LTR+ ... Capabilities: [100] AER ... Capabilities: [140] SR-IOV ... NumVF 0 Kernel driver in use: ixgbe핵심:
- LnkCap vs LnkSta — 광고와 현재 일치 여부
- MaxPayload·MaxReadRequest — performance tuning
- AER 상태·카운터
#setpci — Raw Register Access
직접 Configuration Space write. 위험!
| 명령 | 효과 |
|---|---|
setpci -s 01:00.0 0x04.W | offset 0x04 W (16-bit) read |
setpci -s 01:00.0 0x04.W=0x0006 | bus master·memory enable |
setpci -s 01:00.0 CAP_EXP+30.W | Capability symbolic name |
# bus master + memory space enablesetpci -s 01:00.0 COMMAND=0x06
# MaxPayload 256 byte set (Device Control)setpci -s 01:00.0 CAP_EXP+8.W=0x2810
# AER capability enablesetpci -s 01:00.0 ECAP_AER+18.L=0x00000007driver가 인지 못 하는 변경 — race 가능. 디버깅·연구용.
#pcimem — BAR Direct R/W
pcimem 도구 (github.com/billfarrow/pcimem):
# BAR0의 offset 0x100 32-bit readpcimem /sys/bus/pci/devices/0000:01:00.0/resource0 0x100 w
# writepcimem /sys/bus/pci/devices/0000:01:00.0/resource0 0x100 w 0xdeadbeefdriver 없이도 BAR access. register layout 검증·하드웨어 brings up.
#/sys/bus/pci/devices//
| Entry | 의미 |
|---|---|
config | 4 KB config dump (binary) |
resource | BAR base·limit·flags |
resource0~resource5 | 각 BAR (mmap 가능) |
vendor·device | ID |
class | Class Code |
numa_node | NUMA locality |
driver | 매칭 driver symlink |
sriov_numvfs | SR-IOV 활성 (PF만) |
reset | FLR·secondary bus reset trigger |
power/control | runtime PM (“auto”·“on”) |
power/wakeup | wake-up 활성 |
# config space dumpxxd /sys/bus/pci/devices/0000:01:00.0/config | head
# FLRecho 1 > /sys/bus/pci/devices/0000:01:00.0/reset
# runtime PMecho auto > /sys/bus/pci/devices/0000:01:00.0/power/control#debugfs
/sys/kernel/debug/pci/에 디버깅 인터페이스:
| Entry | 의미 |
|---|---|
pci/devices | 모든 device 목록 |
pci/<BDF>/config | config space |
pci/<BDF>/aer_dev_correctable | CE counter |
pci/<BDF>/aer_dev_fatal·nonfatal | UE counter |
pci/<BDF>/dpc | DPC trigger·log |
mount -t debugfs none /sys/kernel/debug 필요.
#dmesg — Kernel Log
| 패턴 | 의미 |
|---|---|
pcieport | hot-plug·AER·DPC |
aer | AER report |
ixgbe·nvme·... | driver-specific |
BAR.*can't | resource conflict |
Link is up | LTSSM L0 진입 |
Link is down | LTSSM 떨어짐 |
dmesg | grep -iE "pci|pcie|aer" | tail -50첫 line부터 timing·sequence 추적. boot 직후 init·error 동시 추적.
#aer-inject
drivers/pci/pcie/aer_inject.c로 AER 에러 인위 발생. driver recovery callback 검증용:
# 모듈 로드modprobe aer_inject
# 가짜 CE 발생echo "0000:01:00.0 cor=000001" > /sys/kernel/debug/pci/aer_inject
# driver의 error_detected callback 확인dmesg | grep "error_detected"#dpc-test
drivers/pci/pcie/dpc-test.c로 DPC 동작 검증. Switch port의 DPC trigger test.
#Protocol Analyzer — Hardware
| 분야 | 도구 |
|---|---|
| Commercial | Teledyne LeCroy Summit·Keysight Pulsar |
| TLP/DLLP capture | 모든 link traffic |
| LTSSM 추적 | state transition timeline |
| FPGA-based open-source | pcie-tlp-injector 등 |
Cost 수천만 원. 제조사·card vendor에서 진짜 link 문제 분석에 사용.
#NVMe·NIC 특화 도구
| 도구 | 용도 |
|---|---|
nvme list·smart-log·get-log | NVMe AER·SMART |
ethtool -S | NIC statistics |
mlnx_perf·intel_iommu_dump | vendor-specific |
#트러블슈팅 결정 트리 (간략)
| 증상 | 1단계 |
|---|---|
| Device 안 보임 | lspci -D |
| Link 속도 안 남 | `lspci -vv |
| Driver bind 안 됨 | lspci -k |
| Hot-plug 안 됨 | `dmesg |
| 성능 미달 | `lspci -vv |
| AER 폭주 | `dmesg |
자세한 시나리오북은 Ch 16 Troubleshooting.
#자주 하는 실수
#”setpci로 BAR 변경”
driver가 동작 중이면 driver 입장의 BAR이 invalid. device hang. unbind 후 setpci, 또는 manual driver만.
#”lspci -vv가 항상 동작”
kernel access 필요. VFIO-bound device는 userspace 소유라 상세 정보 제한. unbind 후 다시.
#”AER counter 0이면 정상”
Mask로 가려진 경우도. lspci -vv | grep "AER.*MaskSta" 확인 필요.
#”Protocol Analyzer가 모든 문제 해결”
Hardware 자체의 비결정적 fault는 analyzer로도 reproduction 어려움. 통계적 RAS 누적 → analyzer trigger가 일반 워크플로.
#”debugfs는 production에 안전”
Read는 OK, write·trigger는 production 위험. staging·QA에서만 trigger.
#정리
- lspci -vv가 PCIe 진단의 1순위. topology·capability·LnkCap/LnkSta 모두 dump.
- setpci는 raw register access — driver 무관하게 변경 가능, 위험.
- pcimem이 BAR 직접 R/W. driver brings up·register 검증.
- sysfs (
/sys/bus/pci/)·debugfs가 kernel state·counter·reset trigger. - dmesg에서 boot·link·error timing 추적.
- aer-inject·dpc-test가 driver recovery 검증.
- Protocol analyzer는 진짜 link 문제에. cost 큼.
#다음 편
Ch 16: Troubleshooting — 시나리오북에서 실무 자주 만나는 PCIe 문제 케이스북과 진단 decision tree를 본격적으로 분해합니다.
#관련 항목
- Ch 3: Configuration Space — lspci 출력 영역
- Ch 7: Error Handling — AER counter 의미
- Ch 16: Troubleshooting
- Ch 18: Register Maps — setpci 비트 reference
#시리즈 자료 출처 안내
본 글의 1차 자료·정책은 Ch 1 footer 참고.
PCIe Deep Dive · 15 of 19
- 1Ch 1: PCIe Fundamentals — 계층 구조와 토폴로지
- 2Ch 2: TLP — Transaction Layer Packet
- 3Ch 3: Configuration Space — 4 KB ECAM·Capability Linked List
- 4Ch 4: BAR & MMIO — Device 자원의 호스트 주소 매핑
- 5Ch 5: Interrupts — INTx·MSI·MSI-X·Interrupt Remapping
- 6Ch 6: Power Management — D-state·L-state·ASPM
- 7Ch 7: Error Handling — Correctable·Uncorrectable·AER·DPC
- 8Ch 8: Data Link Layer — DLLP·ACK/NAK·Flow Control·FLIT Mode
- 9Ch 9: Physical Layer — LTSSM·Equalization·SerDes
- 10Ch 10: Linux PCI Basics — Enumeration·Driver Model·sysfs
- 11Ch 11: DMA·IOMMU — Coherent·Streaming·ATS·PRI·PASID·IOMMUFD
- 12Ch 12: Virtualization I — Pass-through·SR-IOV·VFIO·DPDK·SPDK
- 13Ch 13: Virtualization II — vIOMMU·Scalable IOV·VirtIO·IDE·TDISP
- 14Ch 14: Linux Operations — Hot-plug·AER Recovery·DPC·ARI
- 15Ch 15: Tools — lspci·setpci·pcimem·protocol analyzer
- 16Ch 16: Troubleshooting — 실무 시나리오북
- 17Ch 17: Performance — Bandwidth·Latency·Tuning
- 18Ch 18: Register Maps — Config Space·Capability 비트 reference
- 19Ch 19: 고급 기능 — Lane Margining·10-bit Tag·TPH·ACS·L0p
관련 글
Ch 19: 고급 기능 — Lane Margining·10-bit Tag·TPH·ACS·L0p
코어 동작 너머의 PCIe spec 기능들 — Lane Margining(신호 마진 측정)·10-bit Tag(outstanding 확장)·TPH(캐시 주입 힌트)·ACS(격리)·L0p(부분폭 저전력)을 실무 관점에서 정리합니다.
Ch 18: Register Maps — Config Space·Capability 비트 reference
PCIe register reference — Type 0/1 header·PCIe Cap·AER·MSI·MSI-X·SR-IOV·ACS·LTR의 주요 비트 layout.
Ch 17: Performance — Bandwidth·Latency·Tuning
PCIe 성능 — theoretical vs effective BW·MaxPayload·MaxReadReq·latency breakdown·NUMA·P2P·ASPM 영향·tuning.