【转载】Linux查看PCIe版本及速率【方法】PCIE的X4X8X16 查看 数量 怎么看

本文介绍了如何在Linux系统中查看PCI Express(PCIe)的版本和速率,包括PCIe的不同规格、传输速率计算以及如何利用`lspci`命令查询设备的Gen1、Gen2或Gen3状态。同时讲解了PCIe的识别号组成和带宽计算方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux查看PCIe版本及速率

 

PCIE有四种不同的规格,通过下图来了解下PCIE的其中2种规格

 

查看主板上的PCI插槽

# dmidecode | grep --color "PCI"

 

不同PCIe版本对应的传输速率如下:

 

传输速率为每秒传输量GT/s,而不是每秒位数Gbps,因为传输量包括不提供额外吞吐量的开销位; 
比如PCIe 1.x和PCIe 2.x使用8b/10b编码方案,导致占用了20% (= 2/10)的原始信道带宽。

GT/s —— Giga transation per second (千兆传输/秒),即每一秒内传输的次数。重点在于描述物理层通信协议的速率属性,可以不和链路宽度等关联。

Gbps —— Giga Bits Per Second (千兆位/秒)。GT/s 与Gbps 之间不存在成比例的换算关系。


PCIe 吞吐量(可用带宽)计算方法:
吞吐量 = 传输速率 * 编码方案

例如:PCI-e2.0 协议支持 5.0 GT/s,即每一条Lane上支持每秒钟内传输5G个Bit;但这并不意味着 PCIe 2.0协议的每一条Lane支持 5Gbps 的速率。

为什么这么说呢?因为PCIe 2.0 的物理层协议中使用的是8b/10b的编码方案。 即每传输8个Bit,需要发送10个Bit;这多出的2个Bit并不是对上层有意义的信息。
那么,PCIe 2.0协议的每一条Lane支持 5 * 8 / 10 = 4 Gbps = 500 MB/s 的速率。
以一个PCIe 2.0 x8的通道为例,x8的可用带宽为 4 * 8 = 32 Gbps = 4 GB/s。

PCI-e3.0 协议支持 8.0 GT/s, 即每一条Lane 上支持每秒钟内传输 8G个Bit。
而PCIe 3.0 的物理层协议中使用的是 128b/130b 的编码方案。 即每传输128个Bit,需要发送130个Bit。
那么, PCIe 3.0协议的每一条Lane支持 8 * 128 / 130 = 7.877 Gbps = 984.6 MB/s 的速率。
一个PCIe 3.0 x16的通道,x16 的可用带宽为 7.877 * 16 = 126.031 Gbps = 15.754 GB/s。

 

在 Linux 下要如何得知 PCI-E Bus 使用的是 Gen(Generation) 1 還是 Gen2 還是新一代的 Gen 3 雖然使用 
#lspci 只要可以看到目前系統所有的裝置.但是好像看不到 PCI-E Bus 所採用的是哪一代的 PCI-E.

复制代码
root@XXX# lspci 
00:00.0 Host bridge: Intel Corporation Haswell DRAM Controller (rev 06)
00:01.0 PCI bridge: Intel Corporation Haswell PCI Express x16 Controller (rev 06)
00:01.1 PCI bridge: Intel Corporation Haswell PCI Express x8 Controller (rev 06)
00:02.0 VGA compatible controller: Intel Corporation Haswell Integrated Graphics Controller (rev 06)
00:03.0 Audio device: Intel Corporation Haswell HD Audio Controller (rev 06)
00:14.0 USB controller: Intel Corporation Lynx Point USB xHCI Host Controller (rev 05)
00:16.0 Communication controller: Intel Corporation Lynx Point MEI Controller #1 (rev 04)
00:1a.0 USB controller: Intel Corporation Lynx Point USB Enhanced Host Controller #2 (rev 05)
00:1c.0 PCI bridge: Intel Corporation Lynx Point PCI Express Root Port #1 (rev d5)
00:1c.4 PCI bridge: Intel Corporation Lynx Point PCI Express Root Port #5 (rev d5)
00:1c.5 PCI bridge: Intel Corporation Lynx Point PCI Express Root Port #6 (rev d5)
00:1d.0 USB controller: Intel Corporation Lynx Point USB Enhanced Host Controller #1 (rev 05)
00:1f.0 ISA bridge: Intel Corporation Lynx Point LPC Controller (rev 05)
00:1f.2 IDE interface: Intel Corporation Lynx Point 4-port SATA Controller 1 [IDE mode] (rev 05)
00:1f.3 SMBus: Intel Corporation Lynx Point SMBus Controller (rev 05)
00:1f.6 Signal processing controller: Intel Corporation Lynx Point Thermal Management Controller (rev 05)
01:00.0 PCI bridge: PLX Technology, Inc. Unknown device 8724 (rev ca)
02:01.0 PCI bridge: PLX Technology, Inc. Unknown device 8724 (rev ca)
02:02.0 PCI bridge: PLX Technology, Inc. Unknown device 8724 (rev ca)
02:08.0 PCI bridge: PLX Technology, Inc. Unknown device 8724 (rev ca)
02:09.0 PCI bridge: PLX Technology, Inc. Unknown device 8724 (rev ca)
03:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:00.2 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
04:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
04:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
04:00.2 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
04:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
06:00.0 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
06:00.1 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
07:00.0 PCI bridge: PLX Technology, Inc. PEX 8732 32-lane, 8-Port PCI Express Gen 3 (8.0 GT/s) Switch (rev ca)
08:01.0 PCI bridge: PLX Technology, Inc. PEX 8732 32-lane, 8-Port PCI Express Gen 3 (8.0 GT/s) Switch (rev ca)
08:08.0 PCI bridge: PLX Technology, Inc. PEX 8732 32-lane, 8-Port PCI Express Gen 3 (8.0 GT/s) Switch (rev ca)
08:09.0 PCI bridge: PLX Technology, Inc. PEX 8732 32-lane, 8-Port PCI Express Gen 3 (8.0 GT/s) Switch (rev ca)
08:0a.0 PCI bridge: PLX Technology, Inc. PEX 8732 32-lane, 8-Port PCI Express Gen 3 (8.0 GT/s) Switch (rev ca)
09:00.0 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
09:00.1 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
0e:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)
0f:00.0 Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev 03)
root@XXX# 
复制代码

 

复制代码
root@XXX# lspci -tv
-[0000:00]-+-00.0  Intel Corporation Haswell DRAM Controller
           +-01.0-[0000:01-06]----00.0-[0000:02-06]--+-01.0-[0000:03]--+-00.0  Intel Corporation I350 Gigabit Network Connection
           |                                         |                 +-00.1  Intel Corporation I350 Gigabit Network Connection
           |                                         |                 +-00.2  Intel Corporation I350 Gigabit Network Connection
           |                                         |                 \-00.3  Intel Corporation I350 Gigabit Network Connection
           |                                         +-02.0-[0000:04]--+-00.0  Intel Corporation I350 Gigabit Network Connection
           |                                         |                 +-00.1  Intel Corporation I350 Gigabit Network Connection
           |                                         |                 +-00.2  Intel Corporation I350 Gigabit Network Connection
           |                                         |                 \-00.3  Intel Corporation I350 Gigabit Network Connection
           |                                         +-08.0-[0000:05]--
           |                                         \-09.0-[0000:06]--+-00.0  Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection
           |                                                           \-00.1  Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection
           +-01.1-[0000:07-0c]----00.0-[0000:08-0c]--+-01.0-[0000:09]--+-00.0  Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection
           |                                         |                 \-00.1  Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection
           |                                         +-08.0-[0000:0a]--
           |                                         +-09.0-[0000:0b]--
           |                                         \-0a.0-[0000:0c]--
           +-02.0  Intel Corporation Haswell Integrated Graphics Controller
           +-03.0  Intel Corporation Haswell HD Audio Controller
           +-14.0  Intel Corporation Lynx Point USB xHCI Host Controller
           +-16.0  Intel Corporation Lynx Point MEI Controller #1
           +-1a.0  Intel Corporation Lynx Point USB Enhanced Host Controller #2
           +-1c.0-[0000:0d]--
           +-1c.4-[0000:0e]----00.0  Intel Corporation I210 Gigabit Network Connection
           +-1c.5-[0000:0f]----00.0  Intel Corporation I210 Gigabit Network Connection
           +-1d.0  Intel Corporation Lynx Point USB Enhanced Host Controller #1
           +-1f.0  Intel Corporation Lynx Point LPC Controller
           +-1f.2  Intel Corporation Lynx Point 4-port SATA Controller 1 [IDE mode]
           +-1f.3  Intel Corporation Lynx Point SMBus Controller
           \-1f.6  Intel Corporation Lynx Point Thermal Management Controller
root@XXX# 
复制代码

 

如果有裝置是 unknown 的,需要更新 /usr/local/share/pci.ids.gz 請參考更新方式 http://benjr.tw/node/88

 

先查询 Inetl 82599EB 网卡的识别号(bus:device.function)

复制代码
root@XXX# lspci | grep --color 82599  
06:00.0 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
06:00.1 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
09:00.0 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
09:00.1 Ethernet controller: Intel Corporation 82599EB 10-Gigabit SFI/SFP+ Network Connection (rev 01)
root@XXX# 
复制代码

 

在 PCI 的裝置使用三個編號用來當作識別值,個別為 1. "匯流排(bus number)", 2. "裝置(device number) 以及 3. "功能(function number)".
所以剛剛的 06:00.0 就是 bus number = 06 ,device number = 00 function = 0 .

這3個編號會組合成一個 16-bits 的識別碼,

匯流排(bus number) 8bits 2^8 至多可連接 256 個匯流排(0 to ff), 
裝置(device number) 5bits 2^5 至多可接 32 種裝置(0 to 1f) 以及 
功能(function number) 3bits 2^3 至多每種裝置可有 8 項功能(0 to 7).
關於更多 #lspci 的資訊請參考 http://benjr.tw/node/543

 

然后查看vendor id和device id

root@XXX# lspci -n | grep -i 06:00.0
06:00.0 0200: 8086:10fb (rev 01)
root@XXX# 

Linux 使用 Class ID + Vendor ID + Device ID  來代表裝置,如剛剛的  0200: 8086:10fb 所代表裝置名稱為 (Class ID = 0200 , Vendor ID = 8086, Device ID = 10fb)

 

最后查看指定PCI设备的带宽

复制代码
root@XXX# lspci -n -d 8086:10fb -vvv | grep --color  Width
        LnkCap:    Port #9, Speed 5GT/s, Width x8, ASPM L0s, Latency L0 <1us, L1 <8us
        LnkSta:    Speed 5GT/s, Width x8, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
        LnkCap:    Port #9, Speed 5GT/s, Width x8, ASPM L0s, Latency L0 <1us, L1 <8us
        LnkSta:    Speed 5GT/s, Width x8, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
        LnkCap:    Port #1, Speed 5GT/s, Width x8, ASPM L0s, Latency L0 <1us, L1 <8us
        LnkSta:    Speed 5GT/s, Width x8, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
        LnkCap:    Port #1, Speed 5GT/s, Width x8, ASPM L0s, Latency L0 <1us, L1 <8us
        LnkSta:    Speed 5GT/s, Width x8, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
root@XXX# 
复制代码

 

LnkSta : 目前系統所提供的速度 PCI-Express 2.0 ( 5GT/s )
LnkCap : 裝置目前所採用的速度.
LnkSta 和 LnkCap 這兩個速度有可能不一樣 , 典型情况下: 系統所提供的是 PCI Express 是 3.0 但裝置還是使用 2.0 的.

 

转载于:https://www.cnblogs.com/xuanbjut/p/10932389.html

<think>我们想要查看Linux系统中PCIe设备的运行速度(即x1, x4, x8, x16等)以及当前链接速度,可以通过读取sys文件系统中的信息来实现。 具体来说,我们可以使用`lspci`命令来列出PCI设备,然后通过查看每个设备的`/sys`目录下的相关文件来获取当前速度和最大支持的速度。 步骤: 1. 首先,使用`lspci`命令获取PCIe设备的总线号(例如:00:02.0)。 2. 然后,进入该设备在sysfs中的目录(通常在`/sys/bus/pci/devices/`下),查看`max_link_speed`和`current_link_speed`文件,以及`max_link_width`和`current_link_width`文件。 但是,更简单的方法是使用`lspci -vv`命令,它会输出详细的信息,包括设备的链接速度和宽度。 例如,我们可以使用以下命令来查看PCIe设备的链接信息: lspci -vv | grep -i "LnkSta" 或者,更具体地,我们可以使用: lspci -vv | grep -iE "(LnkSta:|LnkCap:)" 这样可以看到每个设备的链路能力(LnkCap)和当前链路状态(LnkSta),包括速度和宽度。 另外,也可以直接查看sys文件系统中的文件,例如: cat /sys/bus/pci/devices/0000:00:02.0/current_link_speed cat /sys/bus/pci/devices/0000:00:02.0/current_link_width 注意:设备路径中的0000:00:02.0需要替换为实际的总线号。 为了更方便,我们可以写一个简单的bash脚本来列出所有PCIe设备的速度和宽度。 以下是一个示例脚本,用于显示每个PCIe设备的当前链接速度和宽度: ```bash #!/bin/bash for dev in /sys/bus/pci/devices/*; do if [ -e "$dev/max_link_speed" ]; then devpath=$(basename "$dev") max_speed=$(cat "$dev/max_link_speed") current_speed=$(cat "$dev/current_link_speed") max_width=$(cat "$dev/max_link_width") current_width=$(cat "$dev/current_link_width") echo "Device: $devpath" echo " Max Link Speed: $max_speed, Current Link Speed: $current_speed" echo " Max Link Width: $max_width, Current Link Width: $current_width" fi done ``` 但是,上面的脚本可能不会显示没有链接的设备(比如没有插入设备的PCIe插槽),而且可能会显示一些非PCIe设备(但通过判断存在max_link_speed文件,我们只处理PCIe设备)。 另外,我们也可以使用`lspci`命令来获取设备名称,以便更友好地显示。 改进的脚本: ```bash #!/bin/bash echo "PCIe Devices:" for dev in /sys/bus/pci/devices/*; do if [ -e "$dev/max_link_speed" ]; then devpath=$(basename "$dev") devname=$(lspci -s "$devpath") max_speed=$(cat "$dev/max_link_speed") current_speed=$(cat "$dev/current_link_speed") max_width=$(cat "$dev/max_link_width") current_width=$(cat "$dev/current_link_width") echo "Device: $devpath - $devname" echo " Max Link: $max_speed x$max_width" echo " Current Link: $current_speed x$current_width" fi done ``` 运行这个脚本,就可以看到每个PCIe设备的最大支持速度和宽度,以及当前运行的速度和宽度。 注意:需要以root权限运行,或者当前用户有权限读取sysfs中的文件。 另外,也可以使用工具如`lshw`来查看,例如: sudo lshw -class bus -class bridge 但这里我们主要关注使用sysfs和lspci的方法。 解释: - `max_link_speed`:设备支持的最大速度(如5 GT/s, 8 GT/s等,对应PCIe版本)。 - `current_link_speed`:当前实际运行的速度。 - `max_link_width`:设备支持的最大通道数(如x1, x4, x8, x16)。 - `current_link_width`:当前实际使用的通道数。 通过比较当前和最大值,我们可以知道设备是否运行在降速模式(比如由于信号问题或电源管理导致降速)。 因此,要查看PCIe是开的x,我们主要关注`current_link_width`,它表示当前使用的通道数。 例如,如果`current_link_width`是8,那么就是x8。 另外,速度(如2.5 GT/s, 5 GT/s, 8 GT/s, 16 GT/s)和宽度(通道数)共同决定了带宽。 所以,我们可以通过上述方法查看。 如果只是临时查看,可以直接使用`lspci -vv`并查找“LnkSta”行。 例如,运行: lspci -vv -s 00:02.0 在输出中查找: LnkSta: Speed 5GT/s, Width x1, ... 这里,Speed表示当前速度(5GT/s对应PCIe 1.0,8GT/s对应PCIe 3.0等),Width x1表示当前是x1。 因此,要快速查看所有设备,可以: lspci -vv | grep -i "LnkSta:" 输出示例: 00:02.0 LnkSta: Speed 5GT/s, Width x1, ... 这样,每一行代表一个设备当前的链接状态。 所以,最简单的方法就是使用`lspci -vv`并过滤出LnkSta。 结论:使用命令`lspci -vv | grep -i "LnkSta"`即可快速查看每个PCIe设备当前运行的速度和宽度(x)。 注意:有些设备可能没有链路状态(比如非PCIe设备),所以只会显示有PCIe链路的设备。 另外,如果设备处于节能状态,可能会显示较低的速度和宽度。 所以,为了准确,最好在设备有负载的情况下查看(或者使用工具强制使其进入全速状态)。 但一般情况下,这样查看是足够的。 如果系统没有安装`lspci`,可以安装`pciutils`包。 在Ubuntu/Debian上: sudo apt install pciutils 在CentOS/RHEL上: sudo yum install pciutils 现在,我们给出一个简单的命令来查看: lspci -vv | grep -i "LnkSta" | grep -v "No" 这样可以过滤掉一些没有链接的设备(如显示“No”的)。 但是,有些设备即使没有链接也可能显示,所以根据实际情况调整。 因此,最直接的方法就是使用`lspci -vv`并查看LnkSta行。 所以,回答你的问题:在Linux查看PCIe是x,可以通过命令`lspci -vv | grep -i "LnkSta"`,然后查看宽度(即x)那一项。 例如,输出“Width x16”就表示运行在x16。</think>在 Linux查看 PCIe 设备的运行速度(如 x1、x4、x8、x16)和当前链接状态,可以通过以下方法实现: ### 方法 1:使用 `lspci` 命令(推荐) ```bash lspci -vv | grep -iE "LnkSta:|LnkCap:" ``` **输出示例:** ``` 00:01.0 PCI bridge: ... LnkCap: Port #0, Speed 8GT/s, Width x16, ... LnkSta: Speed 8GT/s, Width x16 01:00.0 VGA controller: ... LnkCap: Port #0, Speed 16GT/s, Width x16, ... LnkSta: Speed 8GT/s, Width x8 ``` **解释:** - `LnkCap`:设备**支持**的最大速度和宽度(硬件能力) - `LnkSta`:设备**当前运行**的实际速度和宽度 - 示例中显卡硬件支持 x16 (`LnkCap: Width x16`),但当前运行在 x8 (`LnkSta: Width x8`) ### 方法 2:直接查看 sysfs 文件 ```bash # 查看所有 PCIe 设备当前速度 grep -l . /sys/class/pci_bus/*/device/*/current_link_speed 2>/dev/null | xargs -I{} sh -c 'echo -n "{}: "; cat {};' # 查看所有 PCIe 设备当前宽度(x) grep -l . /sys/class/pci_bus/*/device/*/current_link_width 2>/dev/null | xargs -I{} sh -c 'echo -n "{}: "; cat {};' ``` **输出示例:** ``` /sys/class/pci_bus/0000:00/device/0000:00:01.0/current_link_speed: 8.0 GT/s /sys/class/pci_bus/0000:01/device/0000:01:00.0/current_link_width: 8 ``` ### 方法 3:专用工具 `lshw` ```bash sudo lshw -c display -businfo # 查看显卡(其他设备替换 class) ``` **输出示例:** ``` pci@0000:01:00.0 display NVIDIA GP104 [GeForce GTX 1080] ... configuration: ... lanes=16 ... ``` ### 解释说明 1. **关键指标:** - **Width**:物理通道数量(x1、x4、x8、x16) - **Speed**:单通道传输速率(如 2.5GT/s=PCIe 1.0, 5GT/s=PCIe 2.0, 8GT/s=PCIe 3.0, 16GT/s=PCIe 4.0) 2. **常见场景:** - 显卡通常运行在 x16,但可能因主板限制或节能降为 x8 - NVMe SSD 通常运行在 x4 - 网卡/USB 控制器通常运行在 x1 或 x4 3. **性能分析:** - 实际带宽 = 速度 × 宽度 - 例如:PCIe 3.0 x8 = 8 GT/s × 8 = 64 GT/s ≈ 7.88 GB/s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值