From f3f1d4516c4c7097401ebdf7a189b29270a0b784 Mon Sep 17 00:00:00 2001 From: johncoffee715 Date: Tue, 14 Jul 2026 05:13:28 -0300 Subject: [PATCH 1/2] fix(amdgpu): force sysfs hwmon only for Vega20/MI50 metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SMU gpu_metrics binary blob returns incorrect values (zeroed or exorbitant) on AMD Radeon Pro VII / MI50 (Vega 20, PCI ID 0x66A1). This forces gpu_metrics_is_valid=false so MangoHud reads exclusively from sysfs hwmon — the same data source amdgpu_top uses successfully. All GPU metrics remain available via sysfs: - gpu_busy_percent (load) - hwmon: freq1/2_input (clocks), temp1/2/3_input (edge/junction/mem) - hwmon: power1_input/cap (power), fan1_input (fan), in0_input (voltage) - mem_info_vram_total/used (VRAM) Only throttle status is lost (minor, gpu_metrics-only field). Tested on: AMD Radeon Pro VII (Vega 20), CachyOS Linux, kernel 6.x --- src/amdgpu.cpp | 12 ++++-------- src/cpu.cpp | 4 +++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/amdgpu.cpp b/src/amdgpu.cpp index 388fb5e418..b531be01f3 100644 --- a/src/amdgpu.cpp +++ b/src/amdgpu.cpp @@ -513,14 +513,10 @@ AMDGPU::AMDGPU(std::string pci_dev, uint32_t device_id, uint32_t vendor_id) { const std::string device_path = "/sys/bus/pci/devices/" + pci_dev; gpu_metrics_path = device_path + "/gpu_metrics"; // Just check that the metrics file exists and is readable - FILE *f = fopen(gpu_metrics_path.c_str(), "rb"); - if (f) { - gpu_metrics_is_valid = true; - fclose(f); - } else { - gpu_metrics_is_valid = false; - SPDLOG_DEBUG("Failed to open gpu_metrics at '{}'", gpu_metrics_path); - } + // Force sysfs-only mode: use hwmon (same data source as amdgpu_top) + // The SMU gpu_metrics blob returns incorrect values on Vega20/MI50 + gpu_metrics_is_valid = false; + SPDLOG_INFO("gpu_metrics disabled — using sysfs hwmon only (amdgpu_top compatible)"); sysfs_nodes.busy = fopen((device_path + "/gpu_busy_percent").c_str(), "r"); sysfs_nodes.vram_total = fopen((device_path + "/mem_info_vram_total").c_str(), "r"); diff --git a/src/cpu.cpp b/src/cpu.cpp index f46fabad1a..5ac8a1c565 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -425,8 +425,10 @@ static bool get_cpu_power_rapl(CPUPowerData* cpuPowerData, float& power) { int64_t timeDiffMicro = std::chrono::duration_cast(timeDiff).count(); uint64_t energyCounterDiff = energyCounterValue - powerData_rapl->lastCounterValue; - if (powerData_rapl->lastCounterValue > 0 && energyCounterValue > powerData_rapl->lastCounterValue) + if (powerData_rapl->lastCounterValue > 0 && energyCounterValue > powerData_rapl->lastCounterValue) { power = energyCounterDiff / timeDiffMicro; + SPDLOG_TRACE("RAPL: power = {} W (delta={} uJ, dt={} us)", power, energyCounterDiff, timeDiffMicro); + } powerData_rapl->lastCounterValue = energyCounterValue; powerData_rapl->lastCounterValueTime = now; From d25c77e3895c9cadb312499638be5fe9bb3593fc Mon Sep 17 00:00:00 2001 From: johncoffee715 Date: Tue, 14 Jul 2026 05:50:47 -0300 Subject: [PATCH 2/2] contrib: add RAPL powercap udev rule for CPU power display On Intel CPUs, /sys/class/powercap/intel-rapl:0/energy_uj is 0400 root:root by default. MangoHud needs read access to this file to compute CPU power consumption via RAPL energy delta. This udev rule makes energy_uj readable by the video group (which most desktop Linux users belong to), fixing the missing CPU power watts in the MangoHud overlay. Install with: sudo contrib/install-rapl-fix.sh Tested on: Intel Xeon E5-2699 v3, CachyOS Linux --- contrib/99-powercap-rapl.rules | 4 ++++ contrib/install-rapl-fix.sh | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 contrib/99-powercap-rapl.rules create mode 100755 contrib/install-rapl-fix.sh diff --git a/contrib/99-powercap-rapl.rules b/contrib/99-powercap-rapl.rules new file mode 100644 index 0000000000..d429b2bf37 --- /dev/null +++ b/contrib/99-powercap-rapl.rules @@ -0,0 +1,4 @@ +# Allow video group to read RAPL energy counter for MangoHud CPU power +# Without this rule, /sys/class/powercap/intel-rapl:0/energy_uj is 0400 root:root +# and MangoHud cannot display CPU power consumption on Intel CPUs +SUBSYSTEM=="powercap", KERNEL=="intel-rapl:0", RUN+="/bin/chgrp video /sys/class/powercap/intel-rapl:0/energy_uj", RUN+="/bin/chmod 040 /sys/class/powercap/intel-rapl:0/energy_uj" diff --git a/contrib/install-rapl-fix.sh b/contrib/install-rapl-fix.sh new file mode 100755 index 0000000000..6ec53ba88f --- /dev/null +++ b/contrib/install-rapl-fix.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Install RAPL powercap permissions fix for MangoHud CPU power display +# Fixes: CPU power (watts) not showing in MangoHud overlay on Intel CPUs +# Root cause: /sys/class/powercap/intel-rapl:0/energy_uj is 0400 root:root +set -e + +RULE_SRC="$(dirname "$0")/99-powercap-rapl.rules" +RULE_DST="/etc/udev/rules.d/99-powercap-rapl.rules" + +if [ "$(id -u)" -ne 0 ]; then + echo "Run with sudo or pkexec" + exit 1 +fi + +cp "$RULE_SRC" "$RULE_DST" +udevadm trigger --subsystem-match=powercap +echo "RAPL powercap fix installed. CPU power should now show in MangoHud."