cpu: fix cpu_power=0W on Zen 5 when cpu_temp is also enabled#2042
Open
Motaphe wants to merge 1 commit into
Open
cpu: fix cpu_power=0W on Zen 5 when cpu_temp is also enabled#2042Motaphe wants to merge 1 commit into
Motaphe wants to merge 1 commit into
Conversation
zenpower5-dkms-git (Zen 5/9800X3D) exposes package power as RAPL_P_Package on power1_input, not the SVI2 labels (SVI2_P_Core / SVI2_P_SoC) that init_cpu_power_data_zenpower() was searching for. This caused the function to return nullptr on Zen 5 hardware. A second bug: InitCpuPowerData() unconditionally breaks out of the hwmon enumeration loop after visiting a "zenpower" device, even when init returned nullptr. This prevented the zenergy fallback from ever being reached. The correlation with cpu_temp: GetCpuFile() (called during cpu_temp init) opens files on the zenpower hwmon node, altering the sysfs readdir() bucket ordering so zenpower is enumerated first in the subsequent power init scan, triggering the unconditional break before zenergy is reached. Fix: - init_cpu_power_data_zenpower: try SVI2 labels first (Zen 4-); fall through to RAPL_P_Package if not found (Zen 5 / zenpower5) - get_cpu_power_zenpower: make socPowerFile optional; when null (single RAPL reading), socPower stays 0 - InitCpuPowerData loop: change unconditional break to "if (cpuPowerData) break;" so zenergy is tried on zenpower failure Fixes: flightlessmango#1794
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1794.
Problem
On Zen 5 hardware (Ryzen 7 9800X3D, kernel 7.0.3, zenpower5-dkms-git),
cpu_powerreports 0W whenevercpu_tempis also present in the config. Removingcpu_tempmakes power display correctly. The data is readable in sysfs — the bug is entirely in MangoHud's sensor scan logic.Root Cause
Three bugs interact:
1. zenpower5 power label not recognised
init_cpu_power_data_zenpower()searches only for SVI2 labels (SVI2_P_Core,SVI2_P_SoC) — the interface exposed by zenpower on Zen 2/3/4. zenpower5-dkms-git (Zen 5) exposes package power as a single RAPL reading instead:Neither SVI2 label is present, so
find_inputfails and the function returnsnullptr.2. Unconditional
breakblocks the zenergy fallbackWhen zenpower is enumerated before zenergy, the loop exits with
cpuPowerData == nullptr. zenergy exportsEsocket0cumulative energy and would succeed as a fallback, but is never reached.3. Why it correlates with
cpu_tempGetCpuFile(), called duringcpu_tempinit, opens files on the zenpower hwmon node. This warms the sysfs dcache entries for that device, alteringreaddir()bucket order on the subsequentInitCpuPowerData()call — zenpower now appears before zenergy. Withoutcpu_temp, zenergy appears first and succeeds immediately. Withcpu_temp, zenpower comes first, returnsnullptr, the unconditional break fires, and power stays 0W for the process lifetime.Fix
init_cpu_power_data_zenpower— try SVI2 labels first (Zen 4 and older, code path unchanged). If not found, tryRAPL_P_Package. Returnnullptronly if neither is present.get_cpu_power_zenpower— drop the early-return that required bothcorePowerFileandsocPowerFile. WhensocPowerFileis null (Zen 5 single-RAPL case),socPowerstays 0. The destructor already null-checkssocPowerFile, so teardown is unaffected.InitCpuPowerDataloop —break→if (cpuPowerData) break;so a failed zenpower init lets the loop continue to zenergy.Backward compatibility: Zen 4 and older zenpower (SVI2 labels present) takes the original code path unchanged — the
RAPL_P_Packagebranch is only entered when SVI2 labels are absent.Test