mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
GPU: fix clock frequency detection and overall tidy
This commit is contained in:
@@ -13,8 +13,8 @@ typedef struct FFCPUResult
|
||||
uint16_t coresLogical;
|
||||
uint16_t coresOnline;
|
||||
|
||||
double frequencyMin;
|
||||
double frequencyMax;
|
||||
double frequencyMin; // GHz
|
||||
double frequencyMax; // GHz
|
||||
|
||||
double temperature;
|
||||
} FFCPUResult;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define FF_GPU_TEMP_UNSET (0/0.0)
|
||||
#define FF_GPU_CORE_COUNT_UNSET -1
|
||||
#define FF_GPU_VMEM_SIZE_UNSET ((uint64_t)-1)
|
||||
#define FF_GPU_FREQUENCY_UNSET -1u
|
||||
#define FF_GPU_FREQUENCY_UNSET (0/0.0)
|
||||
|
||||
extern const char* FF_GPU_VENDOR_NAME_APPLE;
|
||||
extern const char* FF_GPU_VENDOR_NAME_AMD;
|
||||
@@ -31,7 +31,7 @@ typedef struct FFGPUResult
|
||||
FFstrbuf driver;
|
||||
double temperature;
|
||||
int32_t coreCount;
|
||||
uint32_t frequency;
|
||||
double frequency; // Real time clock frequency in GHz
|
||||
FFGPUMemory dedicated;
|
||||
FFGPUMemory shared;
|
||||
uint64_t deviceId; // Used internally, may be uninitialized
|
||||
|
||||
@@ -41,7 +41,7 @@ typedef struct FFGpuDriverResult
|
||||
FFGPUMemory* memory;
|
||||
uint32_t* coreCount;
|
||||
FFGPUType* type;
|
||||
uint32_t* frequency;
|
||||
double* frequency;
|
||||
} FFGpuDriverResult;
|
||||
|
||||
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "3rdparty/igcl/igcl_api.h"
|
||||
#include "common/library.h"
|
||||
#include "util/mallocHelper.h"
|
||||
|
||||
struct FFIgclData {
|
||||
FF_LIBRARY_SYMBOL(ctlClose)
|
||||
@@ -62,9 +63,10 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
uint32_t deviceCount = 0;
|
||||
if (igclData.ffctlEnumerateDevices(igclData.apiHandle, &deviceCount, NULL))
|
||||
return "ctlEnumerateDevices(NULL) failed";
|
||||
ctl_device_adapter_handle_t devices[16] = {};
|
||||
if (deviceCount == 0 || deviceCount > sizeof(devices) / sizeof(devices[0]))
|
||||
return "Invalid device count";
|
||||
if (deviceCount == 0)
|
||||
return "No Intel graphics adapter found";
|
||||
|
||||
FF_AUTO_FREE ctl_device_adapter_handle_t* devices = malloc(deviceCount * sizeof(*devices));
|
||||
if (igclData.ffctlEnumerateDevices(igclData.apiHandle, &deviceCount, devices))
|
||||
return "ctlEnumerateDevices(devices) failed";
|
||||
|
||||
@@ -127,7 +129,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
{
|
||||
ctl_mem_handle_t memoryModules[16];
|
||||
uint32_t memoryCount = sizeof(memoryModules) / sizeof(memoryModules[0]);
|
||||
if (igclData.ffctlEnumMemoryModules(device, &memoryCount, memoryModules) == CTL_RESULT_SUCCESS)
|
||||
if (igclData.ffctlEnumMemoryModules(device, &memoryCount, memoryModules) == CTL_RESULT_SUCCESS && memoryCount > 0)
|
||||
{
|
||||
result.memory->used = 0;
|
||||
result.memory->total = 0;
|
||||
@@ -156,7 +158,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
{
|
||||
ctl_temp_handle_t sensors[16];
|
||||
uint32_t sensorCount = sizeof(sensors) / sizeof(sensors[0]);
|
||||
if (igclData.ffctlEnumTemperatureSensors(device, &sensorCount, sensors) == CTL_RESULT_SUCCESS)
|
||||
if (igclData.ffctlEnumTemperatureSensors(device, &sensorCount, sensors) == CTL_RESULT_SUCCESS && sensorCount > 0)
|
||||
{
|
||||
double sumValue = 0;
|
||||
uint32_t availableCount = 0;
|
||||
@@ -174,7 +176,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe
|
||||
}
|
||||
|
||||
if (result.frequency)
|
||||
*result.frequency = properties.Frequency;
|
||||
*result.frequency = properties.Frequency / 1000.;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -255,8 +255,8 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
.temp = options->temp ? &gpu->temperature : NULL,
|
||||
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
|
||||
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
|
||||
.type = options->driverSpecific ? &gpu->type : NULL,
|
||||
.frequency = options->driverSpecific ? &gpu->frequency : NULL,
|
||||
.type = &gpu->type,
|
||||
.frequency = &gpu->frequency,
|
||||
}, "libnvidia-ml.so");
|
||||
|
||||
if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
|
||||
|
||||
@@ -100,7 +100,11 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
|
||||
nvmlData.ffnvmlDeviceGetNumGpuCores(device, result.coreCount);
|
||||
|
||||
if (result.frequency)
|
||||
nvmlData.ffnvmlDeviceGetClockInfo(device, NVML_CLOCK_GRAPHICS, result.frequency);
|
||||
{
|
||||
uint32_t clockMHz;
|
||||
if (nvmlData.ffnvmlDeviceGetClockInfo(device, NVML_CLOCK_GRAPHICS, &clockMHz) == NVML_SUCCESS)
|
||||
*result.frequency = clockMHz / 1000.;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -106,12 +106,13 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
.subSystemId = subSystemId,
|
||||
.revId = revId,
|
||||
},
|
||||
.luid = gpu->deviceId,
|
||||
}, (FFGpuDriverResult) {
|
||||
.temp = options->temp ? &gpu->temperature : NULL,
|
||||
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
|
||||
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
|
||||
.type = options->driverSpecific ? &gpu->type : NULL,
|
||||
.frequency = options->driverSpecific ? &gpu->frequency : NULL,
|
||||
.type = &gpu->type,
|
||||
.frequency = &gpu->frequency,
|
||||
}, gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA ? "nvml.dll" :
|
||||
#ifdef _WIN64
|
||||
"ControlLib.dll"
|
||||
|
||||
@@ -113,8 +113,8 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF
|
||||
.temp = options->temp ? &gpu->temperature : NULL,
|
||||
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
|
||||
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
|
||||
.type = options->driverSpecific ? &gpu->type : NULL,
|
||||
.frequency = options->driverSpecific ? &gpu->frequency : NULL,
|
||||
.type = &gpu->type,
|
||||
.frequency = &gpu->frequency,
|
||||
}, "/usr/lib/wsl/lib/libnvidia-ml.so");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
|
||||
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
|
||||
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
|
||||
|
||||
if(gpu->frequency != FF_GPU_FREQUENCY_UNSET)
|
||||
ffStrbufAppendF(&output, " @ %.2f MHz", gpu->frequency / 1e6);
|
||||
if(gpu->frequency == gpu->frequency && gpu->frequency > 0 /* Inactive? */)
|
||||
ffStrbufAppendF(&output, " @ %.2f GHz", gpu->frequency);
|
||||
|
||||
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
|
||||
{
|
||||
@@ -83,7 +83,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
|
||||
{FF_FORMAT_ARG_TYPE_UINT64, &gpu->dedicated.used},
|
||||
{FF_FORMAT_ARG_TYPE_UINT64, &gpu->shared.total},
|
||||
{FF_FORMAT_ARG_TYPE_UINT64, &gpu->shared.used},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &gpu->frequency},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->frequency},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -312,7 +312,7 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
if (gpu->frequency == FF_GPU_FREQUENCY_UNSET)
|
||||
yyjson_mut_obj_add_null(doc, obj, "frequency");
|
||||
else
|
||||
yyjson_mut_obj_add_uint(doc, obj, "frequency", gpu->frequency);
|
||||
yyjson_mut_obj_add_real(doc, obj, "frequency", gpu->frequency);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFGPUResult, gpu, gpus)
|
||||
|
||||
Reference in New Issue
Block a user