A GPU is named from an embedded PCI ID table, the same on every machine

The router has no lspci, so its GeminiLake chip came up as 'Intel GPU
3185' beside the identical chip's 'Intel UHD Graphics 600' on hamtv.
A trimmed pci.ids — the graphics devices of Intel, AMD and NVIDIA, and the
virtual GPUs, 115 KB — rides in the binary and is consulted first; lspci
is the fallback for a card newer than the table. scripts/pci-ids-gpu.sh
regenerates it from the hub's copy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Mitchell-Johnson
2026-10-02 23:48:05 -07:00
co-authored by Claude Fable 5.1
parent b5cecce435
commit 3a58e265c6
6 changed files with 3085 additions and 2 deletions
+8 -1
View File
@@ -257,9 +257,16 @@ var (
bracketRe = regexp.MustCompile(`\[([^\]]+)\]`)
)
// gpuName is "Intel Arc A380", from lspci's bracketed marketing name when it has one.
// gpuName is "Intel Arc A380": from the embedded PCI ID table first, so the name is the
// same on every machine; from lspci for a card newer than the table; and failing both,
// the vendor and the raw device ID.
func gpuName(dev, bus, driver string) string {
if bus != "" {
vid := strings.TrimPrefix(strings.TrimSpace(readStr(dev+"/vendor")), "0x")
did := strings.TrimPrefix(strings.TrimSpace(readStr(dev+"/device")), "0x")
if vn, dn := pciName(vid, did); dn != "" {
return lspciName(vn + " " + dn)
}
if out, ok := runOut("lspci", "-s", bus); ok {
if _, desc, found := strings.Cut(out, ": "); found {
return lspciName(desc)
+18
View File
@@ -152,3 +152,21 @@ func TestLiveARC(t *testing.T) {
t.Logf("%s = %v %s", x.ID, x.Value, x.Unit)
}
}
// The embedded table names the lab's four GPUs the way lspci would, so a machine without
// pciutils (the router) agrees with one that has it.
func TestPCIName(t *testing.T) {
for id, want := range map[string]string{"8086:3185": "Intel UHD Graphics 600", "8086:56a5": "Intel Arc A380", "8086:46d1": "Intel UHD Graphics", "8086:4c8a": "Intel UHD Graphics 750", "10de:2684": "NVIDIA GeForce RTX 4090"} {
v, d := pciName(id[:4], id[5:])
if d == "" {
t.Errorf("%s: not in the table", id)
continue
}
if got := lspciName(v + " " + d); got != want {
t.Errorf("%s → %q, want %q", id, got, want)
}
}
if _, d := pciName("8086", "ffff"); d != "" {
t.Errorf("an unknown device should be empty, got %q", d)
}
}
+47
View File
@@ -0,0 +1,47 @@
package metrics
// A trimmed PCI ID database, embedded, so a GPU is named the same on every machine —
// "Intel UHD Graphics 600" — whether or not that machine has pciutils. OpenWrt has neither
// lspci nor pci.ids, and the router's GPU came up as "Intel GPU 3185" beside its twin's
// "Intel UHD Graphics 600" until this. scripts/pci-ids-gpu.sh regenerates the file.
import (
_ "embed"
"strings"
"sync"
)
//go:embed pciids_gpu.txt
var pciIDsGPU string
var pciTable struct {
once sync.Once
vendors map[string]string // "8086" → "Intel Corporation"
devices map[string]string // "8086:3185" → "GeminiLake [UHD Graphics 600]"
}
// pciName looks a vendor and device ID up (hex, lower case, no 0x): the vendor's name and
// the device's; empty where unknown.
func pciName(vendor, device string) (string, string) {
pciTable.once.Do(func() {
pciTable.vendors, pciTable.devices = map[string]string{}, map[string]string{}
cur := ""
for _, line := range strings.Split(pciIDsGPU, "\n") {
switch {
case line == "" || line[0] == '#':
case line[0] == '\t':
if cur == "" || len(line) < 7 || line[1] == '\t' {
continue // a subsystem, or a device before any vendor
}
pciTable.devices[cur+":"+line[1:5]] = strings.TrimSpace(line[5:])
default:
if len(line) >= 6 {
cur = line[:4]
pciTable.vendors[cur] = strings.TrimSpace(line[4:])
}
}
}
})
vendor, device = strings.ToLower(vendor), strings.ToLower(device)
return pciTable.vendors[vendor], pciTable.devices[vendor+":"+device]
}
File diff suppressed because it is too large Load Diff