Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions contrib/99-powercap-rapl.rules
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 17 additions & 0 deletions contrib/install-rapl-fix.sh
Original file line number Diff line number Diff line change
@@ -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."
12 changes: 4 additions & 8 deletions src/amdgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,10 @@ static bool get_cpu_power_rapl(CPUPowerData* cpuPowerData, float& power) {
int64_t timeDiffMicro = std::chrono::duration_cast<std::chrono::microseconds>(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;
Expand Down