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." 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;