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>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
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]
|
|
}
|