Skip to content

Fallback package governor driven by per-core instruction rates - #196

Closed
totemofwolf wants to merge 1 commit into
trulyspinach:masterfrom
totemofwolf:fallback-instruction-governor
Closed

totemofwolf wants to merge 1 commit into
trulyspinach:masterfrom
totemofwolf:fallback-instruction-governor

Conversation

@totemofwolf

Copy link
Copy Markdown

Problem

The per-core idle accounting lives in pmRyzen_machine_idle(), which only runs when the kernel's idle path routes through our pmDispatch registration. On some systems that never happens — on a Cezanne laptop (Lenovo Legion R7000P 2021, Ryzen 7 5800H) another kext owning the dispatch slot (CpuTscSync) leaves the machine-idle hook dead even when our kext registers last; changing kext load order does not help.

When the accounting never runs, set_PState() is never called and every core stays pinned at P0 (~24 W, ~90 °C at desktop idle), regardless of PSTATE_LIMIT.

Fix

Drive the package P-state from the main workloop timer instead, using the per-core retired-instruction rates that are already collected every tick (MSR PERF_IRPC via updateInstructionDelta). The rate is frequency-independent — an idle core retires <0.1 G inst/s, a busy core >1 G inst/s — so governing works correctly even while cores are parked in a low P-state:

  • any core > 0.3 G inst/s → request P0 (instant)
  • all cores < 0.1 G inst/s for ~4 ticks → request P2 (clamped by getPMPStateLimit())
  • otherwise → P1

Respects the existing pstatelimit (LPM/PPM toggles) and reuses applyPowerControl().

Result (Ryzen 7 5800H, Legion R7000P 2021, Ventura 13.7.8, with CpuTscSync installed)

Desktop idle now drops to the firmware P2 state (1.2 GHz, ~9 W package power) and returns to P0 + boost instantly under load. Before this change the CPU was pinned at ~3.4 GHz / 24 W / 85–90 °C whenever the machine was on.

Note

Independent of the P-state-limit change in my other PR — this one makes down-clocking happen at all on systems where the idle hook is unavailable; both together give the full idle→boost range on Cezanne mobile.

On systems where the idle path does not route through our pmDispatch
(Cezanne laptops with another dispatch owner present), the idle-hook
accounting in pmRyzen_machine_idle never runs and every core stays
pinned at P0 forever (24W / 90C at desktop idle on a 5800H).

Drive the package P-state from the main workloop timer instead, using
per-core retired-instruction rates (MSR PERF_IRPC, already collected
every tick). The rate is frequency-independent, so governing works even
while cores sit in a low P-state:

  any core > 0.3G inst/s            -> P0 (instant)
  all cores < 0.1G inst/s for ~4s   -> P2 (clamped by pstatelimit)
  otherwise                         -> P1

Respects the UserClient pstatelimit (LPM/PPM) and reuses
applyPowerControl().
@trulyspinach

Copy link
Copy Markdown
Owner

I need to hear your reasoning and review of the code. Not from AIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants