Re: [PATCH] cpufreq: CPPC: Preserve OSPM-set registers across hotplug and unload
From: Rafael J. Wysocki
Date: Wed Jun 24 2026 - 09:21:57 EST
On Wed, Jun 24, 2026 at 2:56 PM Sumit Gupta <sumitg@xxxxxxxxxx> wrote:
>
> Hi Rafael,
>
>
> On 23/06/26 16:30, Rafael J. Wysocki wrote:
> > External email: Use caution opening links or attachments
> >
> >
> > On Tue, Jun 23, 2026 at 11:54 AM Sumit Gupta <sumitg@xxxxxxxxxx> wrote:
> >> Values written to OSPM-set CPPC registers (via sysfs or the autonomous
> >> boot parameter) can be lost in two ways:
> >>
> >> - Across CPU hotplug: the platform may reset a CPU's registers when it
> >> is offlined.
> >> - On driver unload: the value the driver wrote is left in the register
> >> instead of returning to its pre-driver state.
> >>
> >> Add a small table-driven mechanism that handles both:
> >>
> >> - Capture each register's firmware value when a CPU is first seen and
> >> restore it on driver unload.
> >> - Record the last value the driver set and reapply it from ->init()
> >> when the policy is reactivated after CPU hotplug.
> > I'm not sure if this is a good idea TBH.
> >
> > The overall system state when the CPU goes online may be completely
> > different from the system state when the CPU was online last time, so
> > there is no reason to restore its settings from before offline, at
> > least in principle.
>
> These are values userspace deliberately set, more like a frequency QoS
> request that persists until userspace changes it than transient state.
> It's platform dependent though, as the platform I test on preserves them
> across hotplug, but where the platform resets the register on offline
> the value is silently lost. Should the kernel re-apply it on online,
> or is that better left to userspace? If so, I will drop the hotplug reapply
> and keep only the restore on driver unload.
>
> intel_pstate and amd-pstate already re-sync these on CPU online, as they
> keep the policy across hotplug via ->online()/->offline(). So for them
> it's re-syncing the hardware, not restoring state from before offline.
>
> cppc_cpufreq has no ->online()/->offline() today, so it fully tears the
> policy down and rebuilds it, which is why this reads as "restoring
> settings from before offline".
> Would adding ->online()/->offline() be acceptable, with policy preserved
> and ->online() just re-syncing the registers the platform reset?
That would be a better approach IMV.