GPU: adds more debug log

This commit is contained in:
Carter Li
2026-09-25 12:27:58 +08:00
parent c3164d15e1
commit a1edf7316c
+43 -2
View File
@@ -1,4 +1,5 @@
#include "gpu.h"
#include "common/debug.h"
#include "common/io.h"
#include "common/path.h"
#include "common/properties.h"
@@ -22,35 +23,45 @@ static const FFstrbuf* loadPciIds() {
#ifdef FF_CUSTOM_PCI_IDS_PATH
FF_DEBUG("Loading PCI IDs from custom path: %s", FF_STR(FF_CUSTOM_PCI_IDS_PATH));
ffReadFileBuffer(FF_STR(FF_CUSTOM_PCI_IDS_PATH), &pciids);
#else // FF_CUSTOM_PCI_IDS_PATH
#if __linux__
FF_DEBUG("Loading PCI IDs from %s", FASTFETCH_TARGET_DIR_USR "/share/hwdata/pci.ids");
ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/hwdata/pci.ids", &pciids);
if (pciids.length == 0) {
FF_DEBUG("PCI IDs not found, trying %s", FASTFETCH_TARGET_DIR_USR "/share/misc/pci.ids");
ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/misc/pci.ids", &pciids); // debian?
if (pciids.length == 0) {
FF_DEBUG("PCI IDs not found, trying %s", FASTFETCH_TARGET_DIR_USR "/local/share/hwdata/pci.ids");
ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/local/share/hwdata/pci.ids", &pciids);
}
}
#elif __OpenBSD__ || __FreeBSD__ || __NetBSD__
FF_DEBUG("Loading PCI IDs from %s", FF_PATH_PKG_BASE "/share/hwdata/pci.ids");
ffReadFileBuffer(FF_PATH_PKG_BASE "/share/hwdata/pci.ids", &pciids);
if (pciids.length == 0) {
FF_DEBUG("PCI IDs not found, trying %s", FF_PATH_PKG_BASE "/share/pciids/pci.ids");
ffReadFileBuffer(FF_PATH_PKG_BASE "/share/pciids/pci.ids", &pciids);
}
#elif __sun
FF_DEBUG("Loading PCI IDs from %s", FASTFETCH_TARGET_DIR_ROOT "/usr/share/hwdata/pci.ids");
ffReadFileBuffer(FASTFETCH_TARGET_DIR_ROOT "/usr/share/hwdata/pci.ids", &pciids);
#elif __HAIKU__
FF_DEBUG("Loading PCI IDs from %s", FASTFETCH_TARGET_DIR_ROOT "/system/data/hwdata/pci.ids");
ffReadFileBuffer(FASTFETCH_TARGET_DIR_ROOT "/system/data/hwdata/pci.ids", &pciids);
#endif
#endif // FF_CUSTOM_PCI_IDS_PATH
FF_DEBUG("PCI IDs data loaded: %u bytes", pciids.length);
return &pciids;
}
static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu) {
FF_DEBUG("Searching pci.ids for vendor=0x%04x device=0x%04x subclass=0x%02x", vendor, device, subclass);
if (content->length) {
char buffer[32];
@@ -59,6 +70,7 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
char* start = (char*) memmem(content->chars, content->length, buffer, len);
char* end = content->chars + content->length;
if (start) {
FF_DEBUG("Found PCI vendor entry for 0x%04x", vendor);
start += len;
end = memchr(start, '\n', (uint32_t) (end - start));
if (!end) {
@@ -85,6 +97,7 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
len = (uint32_t) snprintf(buffer, ARRAY_SIZE(buffer), "\n\t%04x ", device);
start = memmem(start, (size_t) (end - start), buffer, len);
if (start) {
FF_DEBUG("Found PCI device entry for 0x%04x:0x%04x", vendor, device);
start += len;
end = memchr(start, '\n', (uint32_t) (end - start));
if (!end) {
@@ -102,8 +115,14 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
if (!gpu->name.length) {
ffStrbufSetNS(&gpu->name, (uint32_t) (end - start), start);
}
} else {
FF_DEBUG("PCI device entry 0x%04x:0x%04x was not found in pci.ids", vendor, device);
}
} else {
FF_DEBUG("PCI vendor entry 0x%04x was not found in pci.ids", vendor);
}
} else {
FF_DEBUG("PCI IDs data is empty; using a synthesized device name");
}
if (!gpu->name.length) {
@@ -124,6 +143,9 @@ static void parsePciIdsFile(const FFstrbuf* content, uint8_t subclass, uint16_t
}
ffStrbufSetF(&gpu->name, "%s Device %04X%s", gpu->vendor.length ? gpu->vendor.chars : "Unknown", device, subclassStr);
FF_DEBUG("PCI device name not found; synthesized name: %s", gpu->name.chars);
} else {
FF_DEBUG("Resolved PCI device name: vendor='%s', name='%s'", gpu->vendor.chars, gpu->name.chars);
}
}
@@ -133,6 +155,7 @@ static inline int pciDeviceCmp(const uint16_t* key, const FFPciDevice* element)
}
static bool loadPciidsInc(uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu) {
FF_DEBUG("Searching embedded PCI IDs for vendor=0x%04x device=0x%04x", vendor, device);
for (const FFPciVendor* pvendor = ffPciVendors; pvendor->name; pvendor++) {
if (pvendor->id != vendor) {
continue;
@@ -146,6 +169,10 @@ static bool loadPciidsInc(uint8_t subclass, uint16_t vendor, uint16_t device, FF
if (pdevice) {
uint32_t nameLen = (uint32_t) strlen(pdevice->name);
if (nameLen == 0) {
FF_DEBUG("Embedded PCI device entry for 0x%04x:0x%04x has an empty name", vendor, device);
return false;
}
const char* closingBracket = pdevice->name + nameLen - 1;
if (*closingBracket == ']') {
const char* openingBracket = memrchr(pdevice->name, '[', nameLen - 1);
@@ -157,9 +184,11 @@ static bool loadPciidsInc(uint8_t subclass, uint16_t vendor, uint16_t device, FF
if (!gpu->name.length) {
ffStrbufSetNS(&gpu->name, nameLen, pdevice->name);
}
FF_DEBUG("Embedded PCI ID matched: vendor='%s', name='%s'", gpu->vendor.chars, gpu->name.chars);
return true;
}
FF_DEBUG("Embedded PCI vendor matched ('%s'), but device 0x%04x was not found", pvendor->name, device);
if (!gpu->name.length) {
const char* subclassStr;
switch (subclass) {
@@ -179,25 +208,31 @@ static bool loadPciidsInc(uint8_t subclass, uint16_t vendor, uint16_t device, FF
ffStrbufSetF(&gpu->name, "%s Device %04X%s", gpu->vendor.length ? gpu->vendor.chars : "Unknown", device, subclassStr);
}
FF_DEBUG("Using synthesized PCI device name: %s", gpu->name.chars);
return true;
}
FF_DEBUG("Embedded PCI vendor 0x%04x was not found", vendor);
return false;
}
#endif
void ffGPUFillVendorAndName(uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu) {
FF_DEBUG("Resolving PCI GPU name: vendor=0x%04x device=0x%04x subclass=0x%02x", vendor, device, subclass);
if (vendor == 0x1234 && device == 0x1111 && subclass == 0) { // Not exist in pci.ids
ffStrbufSetStatic(&gpu->name, "Virtual Video Controller");
FF_DEBUG("Matched special virtual video controller ID");
return;
}
#if FF_HAVE_EMBEDDED_PCIIDS
bool ok = loadPciidsInc(subclass, vendor, device, gpu);
if (ok) {
FF_DEBUG("Resolved PCI GPU name from embedded IDs: vendor='%s', name='%s'", gpu->vendor.chars, gpu->name.chars);
return;
}
#endif
return parsePciIdsFile(loadPciIds(), subclass, vendor, device, gpu);
parsePciIdsFile(loadPciIds(), subclass, vendor, device, gpu);
FF_DEBUG("Resolved PCI GPU name from pci.ids: vendor='%s', name='%s'", gpu->vendor.chars, gpu->name.chars);
}
#if FF_HAVE_EMBEDDED_AMDGPUIDS
@@ -211,8 +246,10 @@ static bool loadAmdGpuIdsInc(uint16_t deviceId, uint8_t revision, FFGPUResult* g
FFArmGpuProduct* product = bsearch(&key, ffAmdGpuProducts, ARRAY_SIZE(ffAmdGpuProducts), sizeof(*ffAmdGpuProducts), (void*) amdGpuCmp);
if (product) {
ffStrbufSetS(&gpu->name, product->name);
FF_DEBUG("Embedded AMD GPU ID matched: device=0x%04x revision=0x%02x name='%s'", deviceId, revision, gpu->name.chars);
return true;
}
FF_DEBUG("Embedded AMD GPU ID not found: device=0x%04x revision=0x%02x", deviceId, revision);
return false;
}
#endif
@@ -221,18 +258,22 @@ static void parseAmdGpuIdsFile(uint16_t deviceId, uint8_t revision, FFGPUResult*
char query[32];
snprintf(query, ARRAY_SIZE(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
#ifdef FF_CUSTOM_AMDGPU_IDS_PATH
FF_DEBUG("Searching AMD GPU IDs at custom path '%s' for device=0x%04x revision=0x%02x", FF_STR(FF_CUSTOM_AMDGPU_IDS_PATH), deviceId, revision);
ffParsePropFile(FF_STR(FF_CUSTOM_AMDGPU_IDS_PATH), query, &gpu->name);
#else
FF_DEBUG("Searching libdrm/amdgpu.ids for device=0x%04x revision=0x%02x", deviceId, revision);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
#endif
FF_DEBUG("AMD GPU IDs file lookup %s: device=0x%04x revision=0x%02x name='%s'", gpu->name.length ? "matched" : "not matched", deviceId, revision, gpu->name.chars);
}
void ffGPUQueryAmdGpuName(uint16_t deviceId, uint8_t revisionId, FFGPUResult* gpu) {
FF_DEBUG("Resolving AMD GPU name: device=0x%04x revision=0x%02x", deviceId, revisionId);
#if FF_HAVE_EMBEDDED_AMDGPUIDS
bool ok = loadAmdGpuIdsInc(deviceId, revisionId, gpu);
if (ok) {
return;
}
#endif
return parseAmdGpuIdsFile(deviceId, revisionId, gpu);
parseAmdGpuIdsFile(deviceId, revisionId, gpu);
}