From ae3c6f1e637a3ee8014dbce9934534303370dc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 21 Apr 2024 19:07:42 +0800 Subject: [PATCH] GPU: detect max freq instead of current freq --- src/detection/gpu/gpu_intel.c | 25 ++++++++++++------------- src/detection/gpu/gpu_linux.c | 2 +- src/detection/gpu/gpu_nvidia.c | 6 +++--- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/detection/gpu/gpu_intel.c b/src/detection/gpu/gpu_intel.c index b41d6e8ae..c61992a46 100644 --- a/src/detection/gpu/gpu_intel.c +++ b/src/detection/gpu/gpu_intel.c @@ -14,7 +14,7 @@ struct FFIgclData { FF_LIBRARY_SYMBOL(ctlEnumMemoryModules) FF_LIBRARY_SYMBOL(ctlMemoryGetState) FF_LIBRARY_SYMBOL(ctlEnumFrequencyDomains) - FF_LIBRARY_SYMBOL(ctlFrequencyGetState) + FF_LIBRARY_SYMBOL(ctlFrequencyGetProperties) bool inited; ctl_api_handle_t apiHandle; @@ -44,7 +44,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlEnumMemoryModules) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlMemoryGetState) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlEnumFrequencyDomains) - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlFrequencyGetState) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlFrequencyGetProperties) if (ffctlInit(&(ctl_init_args_t) { .AppVersion = CTL_MAKE_VERSION(CTL_IMPL_MAJOR_VERSION, CTL_IMPL_MINOR_VERSION), @@ -177,22 +177,21 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe if (result.frequency) { - ctl_freq_handle_t freqs[16]; - uint32_t freqCount = sizeof(freqs) / sizeof(freqs[0]); - if (igclData.ffctlEnumFrequencyDomains(device, &freqCount, freqs) == CTL_RESULT_SUCCESS && freqCount > 0) + ctl_freq_handle_t domains[16]; + uint32_t domainCount = sizeof(domains) / sizeof(domains[0]); + if (igclData.ffctlEnumFrequencyDomains(device, &domainCount, domains) == CTL_RESULT_SUCCESS && domainCount > 0) { - double sumValue = 0; - uint32_t availableCount = 0; - for (uint32_t iFreq = 0; iFreq < freqCount; iFreq++) + double maxValue = 0; + ctl_freq_properties_t props = { .Size = sizeof(props), .Version = 0 }; + for (uint32_t iDomain = 0; iDomain < domainCount; iDomain++) { - ctl_freq_state_t state = { .Size = sizeof(state), .Version = 0 }; - if (igclData.ffctlFrequencyGetState(freqs[iFreq], &state) == CTL_RESULT_SUCCESS) + if (igclData.ffctlFrequencyGetProperties(domains[iDomain], &props) == CTL_RESULT_SUCCESS) { - sumValue += state.actual; - availableCount++; + if (props.type == CTL_FREQ_DOMAIN_GPU && props.max > maxValue) + maxValue = props.max; } } - *result.frequency = (sumValue / availableCount) / 1000.; + *result.frequency = maxValue / 1000; } } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 7dba51013..b497a8a5a 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -90,7 +90,7 @@ static void pciDetectVfreq(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) // Works for Intel GPUs // https://patchwork.kernel.org/project/intel-gfx/patch/1422039866-11572-3-git-send-email-ville.syrjala@linux.intel.com/ ffStrbufSetNS(buffer, pciDir->length - (uint32_t) strlen("device"), pciDir->chars); - ffStrbufAppendS(buffer, "gt_cur_freq_mhz"); + ffStrbufAppendS(buffer, "gt_max_freq_mhz"); char str[16]; ssize_t len = ffReadFileData(buffer->chars, sizeof(str) - 1, str); if (len > 1) diff --git a/src/detection/gpu/gpu_nvidia.c b/src/detection/gpu/gpu_nvidia.c index b55cd3258..33fdb527c 100644 --- a/src/detection/gpu/gpu_nvidia.c +++ b/src/detection/gpu/gpu_nvidia.c @@ -11,7 +11,7 @@ struct FFNvmlData { FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature) FF_LIBRARY_SYMBOL(nvmlDeviceGetMemoryInfo_v2) FF_LIBRARY_SYMBOL(nvmlDeviceGetNumGpuCores) - FF_LIBRARY_SYMBOL(nvmlDeviceGetClockInfo) + FF_LIBRARY_SYMBOL(nvmlDeviceGetMaxClockInfo) FF_LIBRARY_SYMBOL(nvmlDeviceGetBrand) bool inited; @@ -32,7 +32,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMemoryInfo_v2) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetNumGpuCores) - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetClockInfo) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMaxClockInfo) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetBrand) if (ffnvmlInit_v2() != NVML_SUCCESS) @@ -122,7 +122,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR if (result.frequency) { uint32_t clockMHz; - if (nvmlData.ffnvmlDeviceGetClockInfo(device, NVML_CLOCK_GRAPHICS, &clockMHz) == NVML_SUCCESS) + if (nvmlData.ffnvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_GRAPHICS, &clockMHz) == NVML_SUCCESS) *result.frequency = clockMHz / 1000.; }