Re: [PATCH v7 0/5] cpufreq: CPPC: Preserve OSPM-set registers across hotplug and unload
From: Christian Loehle
Date: Tue Nov 03 2026 - 09:53:49 EST
On 10/30/26 09:24, Sumit Gupta wrote:
> This series preserves the OSPM-set CPPC registers (Energy Performance
> Preference, Autonomous Activity Window, Autonomous Selection - set via
> sysfs) across CPU hotplug and suspend/resume. On driver unload, it puts
> back the values they had before the driver loaded.
>
> To do this, it keeps the CPPC cpufreq policy alive across CPU hotplug.
> It also orders the performance-control writes in cppc_set_perf(), so
> that restoring them after a platform reset never sends an invalid
> request.
>
> Without online()/offline() callbacks, the core tears a policy down when
> its last CPU goes offline and rebuilds it on the way back, re-reading the
> CPPC capabilities each time. The values written to these registers can
> be lost:
>
> - Across CPU hotplug or suspend/resume: the platform may reset them
> while the CPU is offline or suspended.
> - On driver unload: the driver-written value is left in the register
> instead of returning to its pre-driver state.
>
> Handle these with:
>
> - Patch 1: orders the Desired, MIN and MAX writes in cppc_set_perf(), so
> that the platform never sees an invalid request. Christian proposed
> it in [7], and this version adds fixes found in testing.
> - Patch 2: adds online()/offline() callbacks so the core keeps policy
> alive across CPU hotplug instead of tearing it down and rebuilding it.
> - Patch 3: makes the autonomous selection register helpers take a u64.
> - Patch 4: saves each register's firmware value at init() and each
> successful sysfs write as the requested value. offline() restores the
> firmware values, and online() reapplies the requested values.
> - Patch 5: extends the same restore and reapply to system
> suspend/resume.
>
> v6[6] -> v7:
> - Patch 1:
> - clamp Desired into MIN and MAX instead of rejecting it. (Sashiko)
> - store_auto_select() updates its cache only on success. (Sashiko)
> - Patch 2:
> - exit() only frees the driver data. (Sashiko)
> - online() continues if enabling CPPC fails, as init() does.
> - Patch 4:
> - save the requested value on each successful sysfs write, instead
> of reading it in offline(). (Christian, Rafael [8])
> - init() fails if a firmware value cannot be read. (Christian)
> - split the auto_act_window store from perf_limited.
> - Patch 5:
> - suspend() no longer reads and saves the registers.
>
> Christian Loehle (1):
> ACPI: CPPC: Order performance-control updates
>
> Sumit Gupta (4):
> cpufreq: CPPC: Keep the policy across CPU hotplug
> ACPI: CPPC: Make autonomous selection helpers take a u64
> cpufreq: CPPC: Preserve OSPM-set registers across hotplug and unload
> cpufreq: CPPC: Preserve OSPM-set registers across suspend/resume
>
> drivers/acpi/cppc_acpi.c | 318 +++++++++++++++-----
> drivers/cpufreq/amd-pstate.c | 2 +-
> drivers/cpufreq/cppc_cpufreq.c | 530 ++++++++++++++++++++++++++++++---
> include/acpi/cppc_acpi.h | 9 +-
> 4 files changed, 729 insertions(+), 130 deletions(-)
>
> [1] v1: https://lore.kernel.org/lkml/20260623095403.3407436-1-sumitg@xxxxxxxxxx/
> [2] v2: https://lore.kernel.org/lkml/20260716153820.2007095-1-sumitg@xxxxxxxxxx/
> [3] v3: https://lore.kernel.org/lkml/20260724215937.3368276-1-sumitg@xxxxxxxxxx/
> [4] v4: https://lore.kernel.org/lkml/20260806200857.601152-1-sumitg@xxxxxxxxxx/
> [5] v5: https://lore.kernel.org/lkml/20260916103820.1760297-1-sumitg@xxxxxxxxxx/
> [6] v6: https://lore.kernel.org/lkml/20261020121846.691218-1-sumitg@xxxxxxxxxx/
> [7] https://lore.kernel.org/lkml/1be30b2b-e1e5-41ed-a0dc-0dd5ad3c47cd@xxxxxxx/
> [8] https://lore.kernel.org/linux-pm/CAJZ5v0iXip_5Ywk3EkrGL_u2w_hOcGKA1XvrubLPb3diWHx5Lw@xxxxxxxxxxxxxx/
>
My testing setup is far from perfect, but let's hope good enough:
Tested on Orion O6, AmpereOne and Blackview Ryzen 5 7430U (for ACPI-CPPC only):
- native and emulated CPPC hotplug, both auto-select modes
- S3 on Blackview and s2idle on AmpereOne
- amd-pstate active/passive/guided on Blackview.
Didn't observe any violations in restore order with both native register and
fake support (which silently drops requests before the register write).
Tested-by: Christian Loehle <christian.loehle@xxxxxxx>