okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-w' into f-140253623e56f

main
2.0 KiB53 linesraw
1#!/usr/bin/env python3
2"""The PCIe path of every GPU, read from sysfs (no root needed).
3
4Walks from each display card up through its bridges to the root port and prints
5every hop's negotiated and maximum link speed and width. The card's own
6`current_link_*` attributes are printed too; on this PC they claim x16 Gen4 for
7both cards while the upstream ports of one of them are all 8.0 GT/s x4, so the
8bridge chain is the reading that agrees with the engine's own probe.
9
10Also prints the DRM slot, subsystem id and rocm-smi's view of each card.
11"""
12import os
13import subprocess
14import sys
15from pathlib import Path
16
17
18def r(path, name):
19    try:
20        return Path(path, name).read_text().strip()
21    except OSError:
22        return '?'
23
24
25def main():
26    out = sys.stdout
27    smi = subprocess.run(['rocm-smi', '--showbus', '--showid'],
28                         capture_output=True, text=True).stdout
29    for line in smi.splitlines():
30        if 'PCI Bus' in line or 'Subsystem' in line or 'Device ID' in line:
31            print(line, file=out)
32    for dev in sorted(Path('/sys/bus/pci/devices').glob('*')):
33        if not (dev / 'class').exists() or r(dev, 'class') != '0x030000':
34            continue
35        real = os.path.realpath(dev)
36        # which DRM card is this endpoint?
37        card = '?'
38        for c in sorted(Path('/sys/class/drm').glob('card[0-9]*')):
39            if c.name.count('-') == 0 and os.path.realpath(c / 'device') == real:
40                card = c.name
41        print(f'\n=== {dev.name}  drm {card}  subsystem {r(dev, "device")}', file=out)
42        print(f'    realpath {real}', file=out)
43        p = real
44        while p and p != '/sys/devices' and p != '/':
45            name = os.path.basename(p)
46            print(f'    {name:15} class={r(p, "class")} device={r(p, "device"):<7} '
47                  f'current={r(p, "current_link_speed")} x{r(p, "current_link_width")}  '
48                  f'max={r(p, "max_link_speed")} x{r(p, "max_link_width")}', file=out)
49            p = os.path.dirname(p)
50
51
52if __name__ == '__main__':
53    main()