确定 PCIe 设备 NUMA 节点

确定 PCIe 设备 NUMA 节点

假设是相当新的 Linux 操作系统,有没有一种简单的方法来确定设备插入的 PCIe 插槽属于哪个 NUMA 节点?

答案1

您必须转到相关 PCIe 插槽的目录,例如eth0

 cd /sys/class/net/eth0/device

您将在其中找到numa_nodelocal_cpuslocal_cpulist三个您感兴趣的文件。您可以单击cat它们并查看所需的数据。

答案2

据我所知,可接受的答案仅适用于网卡。根据 GuillermoMA 的回答,hwloc 会为您提供真实的结果,即使它不是那么清晰。lstopo在 hwloc 包中找到(至少在 RHEL 7 上):

# lstopo
Machine (256GB)
  NUMANode L#0 (P#0 128GB)
    Socket L#0 + L3 L#0 (20MB)
      L2 L#0 (256KB) + L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0 + PU L#0 (P#0)
      L2 L#1 (256KB) + L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1 + PU L#1 (P#2)
      L2 L#2 (256KB) + L1d L#2 (32KB) + L1i L#2 (32KB) + Core L#2 + PU L#2 (P#4)
      L2 L#3 (256KB) + L1d L#3 (32KB) + L1i L#3 (32KB) + Core L#3 + PU L#3 (P#6)
      L2 L#4 (256KB) + L1d L#4 (32KB) + L1i L#4 (32KB) + Core L#4 + PU L#4 (P#8)
      L2 L#5 (256KB) + L1d L#5 (32KB) + L1i L#5 (32KB) + Core L#5 + PU L#5 (P#10)
      L2 L#6 (256KB) + L1d L#6 (32KB) + L1i L#6 (32KB) + Core L#6 + PU L#6 (P#12)
      L2 L#7 (256KB) + L1d L#7 (32KB) + L1i L#7 (32KB) + Core L#7 + PU L#7 (P#14)
    HostBridge L#0
      PCIBridge
        PCI 1000:005d
          Block L#0 "sda"
      PCIBridge
        PCI 14e4:16a1
          Net L#1 "eth0"
        PCI 14e4:16a1
          Net L#2 "eth1"
        PCI 14e4:16a1
          Net L#3 "eth2"
        PCI 14e4:16a1
          Net L#4 "eth3"
      PCI 8086:8d62
      PCIBridge
        PCIBridge
          PCIBridge
            PCIBridge
              PCI 102b:0534
      PCI 8086:8d02
        Block L#5 "sr0"
  NUMANode L#1 (P#1 128GB)
    Socket L#1 + L3 L#1 (20MB)
      L2 L#8 (256KB) + L1d L#8 (32KB) + L1i L#8 (32KB) + Core L#8 + PU L#8 (P#1)
      L2 L#9 (256KB) + L1d L#9 (32KB) + L1i L#9 (32KB) + Core L#9 + PU L#9 (P#3)
      L2 L#10 (256KB) + L1d L#10 (32KB) + L1i L#10 (32KB) + Core L#10 + PU L#10 (P#5)
      L2 L#11 (256KB) + L1d L#11 (32KB) + L1i L#11 (32KB) + Core L#11 + PU L#11 (P#7)
      L2 L#12 (256KB) + L1d L#12 (32KB) + L1i L#12 (32KB) + Core L#12 + PU L#12 (P#9)
      L2 L#13 (256KB) + L1d L#13 (32KB) + L1i L#13 (32KB) + Core L#13 + PU L#13 (P#11)
      L2 L#14 (256KB) + L1d L#14 (32KB) + L1i L#14 (32KB) + Core L#14 + PU L#14 (P#13)
      L2 L#15 (256KB) + L1d L#15 (32KB) + L1i L#15 (32KB) + Core L#15 + PU L#15 (P#15)
    HostBridge L#7
      PCIBridge
        PCI 15b3:1003
          Net L#6 "eth4"
          Net L#7 "eth5"

当然,NUMANode L#0 是 CPU0,NUMANode L#1 是 CPU1。然后,您可以从上面获取您最喜欢的 PCI 编号,例如 14e4:16a1,并发现它是什么,以及它的 PCI 地址,以便进一步分析lspci

# lspci -nn | grep 14e4:16a1
01:00.0 Ethernet controller [0200]: Broadcom Corporation BCM57840 NetXtreme II 10 Gigabit Ethernet [14e4:16a1] (rev 11)
01:00.1 Ethernet controller [0200]: Broadcom Corporation BCM57840 NetXtreme II 10 Gigabit Ethernet [14e4:16a1] (rev 11)
01:00.2 Ethernet controller [0200]: Broadcom Corporation BCM57840 NetXtreme II 10 Gigabit Ethernet [14e4:16a1] (rev 11)
01:00.3 Ethernet controller [0200]: Broadcom Corporation BCM57840 NetXtreme II 10 Gigabit Ethernet [14e4:16a1] (rev 11)

在我的其中一台机器上,Emulex 光纤通道卡未显示在输出中lstopo。我lstopo --whole-io通过执行反向查找过程找到了它(如果需要,请向右滚动,以查看我 grep 的 10df 十六进制数字):

# lspci -nn | grep -i emulex
03:00.0 Fibre Channel [0c04]: Emulex Corporation Saturn-X: LightPulse Fibre Channel Host Adapter [10df:f100] (rev 03)
03:00.1 Fibre Channel [0c04]: Emulex Corporation Saturn-X: LightPulse Fibre Channel Host Adapter [10df:f100] (rev 03)
# lstopo --whole-io | grep 10df   
        PCI 10df:f100
        PCI 10df:f100

删除上面的管道 grep 命令,并半手动地浏览输出以在完整lstopo --whole-io显示中找到设备(留给读者练习)。

答案3

您还可以使用 hwloc (http://www.open-mpi.de/projects/hwloc/)(如果您知道设备 ID)。但是,如果您有 2 个相同的设备(例如 GPU),那么了解物理插槽所关联的 NUMA 节点的唯一方法是查看主板手册。

对于华硕 Z9PE-D8 (http://dlcdnet.asus.com/pub/ASUS/mb/LGA2011/Z9PE-D8-WS/Manual/e8726_z9pe-d8_ws.pdf)在第223页。

答案4

有人指出@MariusMatutiae 的答案仅涵盖net,但事实并非如此:他的回答只需进行一点点匹配就可以轻松扩展到所有设备类别:

for i in  /sys/class/*/*/device; do 
    pci=$(basename "$(readlink $i)")
    if [ -e $i/numa_node ]; then
        echo "NUMA Node: `cat $i/numa_node` ($i): `lspci -s $pci`" ;
    fi
done | sort

以下是我的系统的一个示例:

NUMA Node: 0 (/sys/class/drm/card0/device): c3:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 41)
NUMA Node: 0 (/sys/class/net/eth0/device): c1:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
NUMA Node: 0 (/sys/class/pci_bus/0000:c1/device): c0:01.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge
NUMA Node: 0 (/sys/class/pci_bus/0000:c3/device): c2:00.0 PCI bridge: ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge (rev 04)
NUMA Node: 1 (/sys/class/nvme/nvme0/device): 84:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983
NUMA Node: 1 (/sys/class/usbmon/usbmon3/device): 82:00.0 USB controller: ASMedia Technology Inc. ASM1042A USB 3.0 Host Controller
NUMA Node: 2 (/sys/class/iommu/ivhd2/device): 40:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Starship/Matisse IOMMU
NUMA Node: 3 (/sys/class/i2c-adapter/i2c-0/device): 00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller (rev 61)

相关内容