mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
GPU: better nvidia GPU temp detection
This commit is contained in:
Vendored
+6849
-2174
File diff suppressed because it is too large
Load Diff
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"home": "https://developer.nvidia.com/gpu-deployment-kit",
|
||||
"home": "https://github.com/NVIDIA/nvidia-settings/blob/main/src/nvml.h",
|
||||
"license": "Embed in source",
|
||||
"version": "v9",
|
||||
"version": "545.23.06",
|
||||
"author": "NVIDIA Corporation"
|
||||
}
|
||||
|
||||
@@ -243,7 +243,11 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
#endif
|
||||
|
||||
if (gpu->temperature != gpu->temperature && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
|
||||
ffDetectNvidiaGpuTemp(&gpu->temperature, device->device_id);
|
||||
{
|
||||
char pciDeviceId[32];
|
||||
snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func);
|
||||
ffDetectNvidiaGpuTemp(&gpu->temperature, pciDeviceId, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
jmp_buf pciInitJmpBuf;
|
||||
|
||||
@@ -75,13 +75,6 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
gpu->dedicated.total = dedicatedVideoMemory + dedicatedSystemMemory;
|
||||
gpu->shared.total = sharedSystemMemory;
|
||||
}
|
||||
|
||||
if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
|
||||
{
|
||||
uint32_t deviceId;
|
||||
if(ffRegReadUint(hDirectxKey, L"DeviceId", &deviceId, NULL))
|
||||
ffDetectNvidiaGpuTemp(&gpu->temperature, deviceId);
|
||||
}
|
||||
}
|
||||
else if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL))
|
||||
{
|
||||
@@ -91,6 +84,15 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
|
||||
}
|
||||
}
|
||||
|
||||
if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
|
||||
{
|
||||
uint32_t vendorId, deviceId, subSystemId;
|
||||
// See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html
|
||||
// displayDevice.DeviceID = MatchingDeviceId "PCI\\VEN_10DE&DEV_2782&SUBSYS_513417AA&REV_A1"
|
||||
if (swscanf(displayDevice.DeviceID, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x", &vendorId, &deviceId, &subSystemId) == 3)
|
||||
ffDetectNvidiaGpuTemp(&gpu->temperature, NULL, (deviceId << 16) | vendorId, subSystemId);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -6,13 +6,17 @@
|
||||
struct FFNvmlData {
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetCount_v2)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByIndex_v2)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByPciBusId_v2)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetPciInfo_v3)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature)
|
||||
|
||||
bool inited;
|
||||
} nvmlData;
|
||||
|
||||
const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId)
|
||||
// Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise
|
||||
// pciBusId = "domain:bus:device.function"
|
||||
// pciDeviceId = (deviceId << 16) | vendorId
|
||||
const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t pciDeviceId, uint32_t pciSubSystemId)
|
||||
{
|
||||
if (!nvmlData.inited)
|
||||
{
|
||||
@@ -29,6 +33,7 @@ const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByIndex_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByPciBusId_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetPciInfo_v3)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature)
|
||||
|
||||
@@ -44,30 +49,40 @@ const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId)
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature == NULL)
|
||||
return "loading nvml library failed";
|
||||
|
||||
uint32_t count;
|
||||
if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetCount_v2() failed";
|
||||
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
nvmlDevice_t device = NULL;
|
||||
if (pciBusId)
|
||||
{
|
||||
nvmlDevice_t device;
|
||||
if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS)
|
||||
continue;
|
||||
nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusId, &device);
|
||||
if (ret != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetHandleByPciBusId_v2() failed";
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t count;
|
||||
if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetCount_v2() failed";
|
||||
|
||||
nvmlPciInfo_t pciInfo;
|
||||
if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS)
|
||||
continue;
|
||||
for (uint32_t i = 0; i < count; i++, device = NULL)
|
||||
{
|
||||
if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS)
|
||||
continue;
|
||||
|
||||
if (pciInfo.pciDeviceId >> 16 != deviceId)
|
||||
continue;
|
||||
nvmlPciInfo_t pciInfo;
|
||||
if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS)
|
||||
continue;
|
||||
|
||||
uint32_t value;
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed";
|
||||
if (pciInfo.pciDeviceId != pciDeviceId || pciInfo.pciSubSystemId != pciSubSystemId)
|
||||
continue;
|
||||
|
||||
*temp = value;
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
if (!device) return "Device not found";
|
||||
}
|
||||
|
||||
return "Device not found";
|
||||
uint32_t value;
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed";
|
||||
|
||||
*temp = value;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId);
|
||||
const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t pciDeviceId, uint32_t pciSubSystemId);
|
||||
|
||||
Reference in New Issue
Block a user