Periodic peaks in frame time when enabling MangoHud that cause periodic stutters in Minecraft (PrismLauncher)
Describe the bug When I enable MangoHud in Minecraft (launched through the PrismLauncher), the frame time graph shows periodic spikes in frame time, these seem to directly relate to frame drops making the game unplayable. When I limit the fps to 60, the spikes are more frequent wrt a fps limit of 144.
List relevant hardware/software information
- Debian 12.9 (KDE, Plasma 5)
- MangoHud v0.8.1
- CPU: AMD FX-8350 (8) @ 3.943GHz
- GPU: AMD ATI Radeon R9 285/380
To Reproduce Steps to reproduce the behavior:
- Go to PrismLauncher
- Click on 'Settings --> Minecraft --> Tweaks -->Performance --> check: Enable MangoHud'
- Click on 'Settings --> Custom Command --> Wrapper Command --> enter: mangohud'
- Launch Minecraft instance
- Enable MangoHud
- Experience error :( Expected behavior MangoHud enabled with nearly constant frame times and no stutters.
Screenshots
Additional context I tried setting
env LD_PRELOAD=""
as a Wrapper command, it doesn't fix the issue. It also persist on all version of Minecraft.
One thing to note: When Rshift+F12 is used to turn off MangoHud, everything returns to normal, no issues, just no MangoHud. I'm also not super experienced with Linux, but the issue seems to be due to the MangoHud as it works fine without it.
It also appears that the functionalities of MangoHud work as the fps can still be limited without the hud turned on etc.
If anyone could help, thank you in advance :D
https://github.com/flightlessmango/MangoHud/commit/7a532bf55ea7ab30cac9ba477a62f5dadd887a1f
It looks like reading power1_average is causing the stutters.
❯ hyperfine -N -L P /sys/class/drm/card0/device/hwmon/hwmon2 'cat {P}/power1_cap' 'cat {P}/power1_average'
Benchmark 1: cat /sys/class/drm/card0/device/hwmon/hwmon2/power1_cap
Time (mean ± σ): 1.4 ms ± 0.2 ms [User: 0.8 ms, System: 0.3 ms]
Range (min … max): 0.8 ms … 2.1 ms 2345 runs
Benchmark 2: cat /sys/class/drm/card0/device/hwmon/hwmon2/power1_average
Time (mean ± σ): 506.6 ms ± 0.2 ms [User: 1.8 ms, System: 0.0 ms]
Range (min … max): 506.2 ms … 507.1 ms 10 runs
Summary
cat /sys/class/drm/card0/device/hwmon/hwmon2/power1_cap ran
370.20 ± 60.64 times faster than cat /sys/class/drm/card0/device/hwmon/hwmon2/power1_average
It looks like reading
power1_averageis causing the stutters.
Sorry if this question is trivial but I'm new to Linux, to my understanding this is not an issue then I cannot resole myself and should instead be solved by the developer of MangoHud?
@otroof
You can use 0.8.0 while the issue is not fixed or compile MangoHud with a patch to revert changes:
diff --git a/src/amdgpu.cpp b/src/amdgpu.cpp
index c566b55..88f7e41 100644
--- a/src/amdgpu.cpp
+++ b/src/amdgpu.cpp
@@ -397,6 +397,8 @@ AMDGPU::AMDGPU(std::string pci_dev, uint32_t device_id, uint32_t vendor_id) {
sysfs_nodes.gpu_voltage_soc = fopen((hwmon_path + dir + "/in0_input").c_str(), "r");
sysfs_nodes.memory_clock = fopen((hwmon_path + dir + "/freq2_input").c_str(), "r");
sysfs_nodes.power_usage = fopen((hwmon_path + dir + "/power1_average").c_str(), "r");
+ // FIXME: reading power1_average causes stutters
+ sysfs_nodes.power_usage = NULL;
sysfs_nodes.fan = fopen((hwmon_path + dir + "/fan1_input").c_str(), "r");
}
}
Can you show the results of these commands on your machine?
time cat /sys/class/drm/card?/device/hwmon/hwmon?/power1_cap
time cat /sys/class/drm/card?/device/hwmon/hwmon?/power1_average
It's not a mangohud issue that accessing the sysfs node stalls the GPU.
This should be reported to the proper place, amdgpu kernel driver?
We don't want to blanket disable it either because it's not happening on every GPU.
We could disable accessing it if gpu_power is not set so the user has some control
@numas13
time cat /sys/class/drm/card?/device/hwmon/hwmon?/power1_cap
returned
165000000
real 0m0.001s
user 0m0.000s
sys 0m0.001s
time cat /sys/class/drm/card?/device/hwmon/hwmon?/power1_average
returned
47008000
real 0m0.530s
user 0m0.001s
sys 0m0.000s
The 500ms i suppose refers to the period of the GPU stall. I installed MangoHud v0.8.0 which "resolved" problem for now. Thanks a lot for your help!