amdgpu: prefer hwmon over gpu_metrics for gpu temp

Co-authored-by: Martin Roukala <martin.roukala@mupuf.org>
pull/758/head
FlightlessMango 2 years ago
parent bcf16a0def
commit b30302c889

@ -194,7 +194,8 @@ void amdgpu_get_metrics(){
gpu_info.CoreClock = amdgpu_common_metrics.current_gfxclk_mhz;
gpu_info.MemClock = amdgpu_common_metrics.current_uclk_mhz;
gpu_info.temp = amdgpu_common_metrics.gpu_temp_c;
// Use hwmon instead, see gpu.cpp
// gpu_info.temp = amdgpu_common_metrics.gpu_temp_c;
gpu_info.apu_cpu_power = amdgpu_common_metrics.average_cpu_power_w;
gpu_info.apu_cpu_temp = amdgpu_common_metrics.apu_cpu_temp_c;

@ -82,15 +82,6 @@ void getAmdGpuInfo(){
gpu_info.load = value;
}
if (amdgpu.temp) {
rewind(amdgpu.temp);
fflush(amdgpu.temp);
int value = 0;
if (fscanf(amdgpu.temp, "%d", &value) != 1)
value = 0;
gpu_info.temp = value / 1000;
}
if (amdgpu.core_clock) {
rewind(amdgpu.core_clock);
fflush(amdgpu.core_clock);
@ -134,4 +125,14 @@ void getAmdGpuInfo(){
value = 0;
gpu_info.memoryUsed = float(value) / (1024 * 1024 * 1024);
}
// On some GPUs SMU can sometimes return the wrong temperature.
// As HWMON is way more visible than the SMU metrics, let's always trust it as it is the most likely to work
if (amdgpu.temp){
rewind(amdgpu.temp);
fflush(amdgpu.temp);
int value = 0;
if (fscanf(amdgpu.temp, "%d", &value) != 1)
value = 0;
gpu_info.temp = value / 1000;
}
}

@ -679,6 +679,12 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
amdgpu.vram_total = fopen((path + "/mem_info_vram_total").c_str(), "r");
if (!amdgpu.vram_used)
amdgpu.vram_used = fopen((path + "/mem_info_vram_used").c_str(), "r");
path += "/hwmon/";
auto dirs = ls(path.c_str(), "hwmon", LS_DIRS);
for (auto& dir : dirs)
if (!amdgpu.temp)
amdgpu.temp = fopen((path + dir + "/temp1_input").c_str(), "r");
if (!metrics_path.empty())
break;
@ -691,15 +697,11 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
SPDLOG_DEBUG("using amdgpu path: {}", path);
path += "/hwmon/";
auto dirs = ls(path.c_str(), "hwmon", LS_DIRS);
for (auto& dir : dirs) {
if (!amdgpu.core_clock)
amdgpu.core_clock = fopen((path + dir + "/freq1_input").c_str(), "r");
if (!amdgpu.memory_clock)
amdgpu.memory_clock = fopen((path + dir + "/freq2_input").c_str(), "r");
if (!amdgpu.temp)
amdgpu.temp = fopen((path + dir + "/temp1_input").c_str(), "r");
if (!amdgpu.power_usage)
amdgpu.power_usage = fopen((path + dir + "/power1_average").c_str(), "r");
}

Loading…
Cancel
Save