Bug 216189 - amd-pstate stops working after S3 suspend
Summary: amd-pstate stops working after S3 suspend
Status: RESOLVED DUPLICATE of bug 215938
Alias: None
Product: Power Management
Classification: Unclassified
Component: cpufreq (show other bugs)
Hardware: AMD Linux
: P1 normal
Assignee: linux-pm@vger.kernel.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-29 15:21 UTC by a
Modified: 2022-07-04 15:09 UTC (History)
2 users (show)

See Also:
Kernel Version: 5.18.8
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description a 2022-06-29 15:21:36 UTC
Hardware: Lenovo Thinkpad T14 Gen2 AMD  
CPU: AMD Ryzen 7 PRO 5850U  
Kernel: 5.18.8  (tried linux-next too)  
  
  
I've managed to get new `amd-pstate` driver working on my system, but after suspend (S3) it stops working and CPU frequency and Boost state control is not working. 

Falling back to `acpi-cpufreq` driver solves the issue — suspend no longer breaks CPU frequency and Boost controls. 


```
    ~ sudo cpupower frequency-info                                                                                                                              
    analyzing CPU 0:
      driver: amd-pstate
      CPUs which run at the same hardware frequency: 0
      CPUs which need to have their frequency coordinated by software: 0
      maximum transition latency: 131 us
      hardware limits: 400 MHz - 1.90 GHz
      available cpufreq governors: ondemand performance schedutil
      current policy: frequency should be within 800 MHz and 1.50 GHz.
                      The governor "ondemand" may decide which speed to use
                      within this range.
      current CPU frequency: Unable to call hardware
      current CPU frequency: 3.41 GHz (asserted by call to kernel)

     boost state support:
        Supported: yes
        Active: no
        AMD PSTATE Highest Performance: 166. Maximum Frequency: 4.51 GHz.
        AMD PSTATE Nominal Performance: 70. Nominal Frequency: 1.90 GHz.
        AMD PSTATE Lowest Non-linear Performance: 41. Lowest Non-linear Frequency: 1.11 GHz.
        AMD PSTATE Lowest Performance: 15. Lowest Frequency: 400 MHz.
```

As we see here, frequency limits are set to 800 MHz - 1.50 GHz and boost stats is inactive, but actual CPU frequency 3.41 GHz (that means boost is on and limits are ignored)  
  
The things starts working again only after reboot.  
  
Any commands such as 
```
echo 1 > /sys/devices/system/cpu/cpufreq/boost
echo 0 > /sys/devices/system/cpu/cpufreq/boost
cpupower frequency-set -g ondemand -d 400MHz -u 800MHz
cpupower frequency-set -g performance -d 1.9GHz -u 1.9GHz

```

just does nothing. (after reboot they start working again of course)  
  

There are no mentions of pstate module in dmesg, but maybe I have to enable some debug (how to do it?)  
  
Simillar bug for intel_pstate: https://bugzilla.kernel.org/show_bug.cgi?id=90421  
Maybe it is related some way.
Comment 1 a 2022-06-29 15:34:02 UTC
May be duplicate of https://bugzilla.kernel.org/show_bug.cgi?id=215938
Comment 2 a 2022-06-29 15:35:35 UTC

*** This bug has been marked as a duplicate of bug 215938 ***
Comment 3 Joe 2022-06-30 08:26:21 UTC
Hello, 

The fixed patch has been accepted. It will be updated in 5.19.

Here is the detail

On Thu, Jun 23, 2022 at 9:53 AM Huang Rui <ray.huang@amd.com> wrote:
>
> On Thu, Jun 23, 2022 at 11:15:09AM +0800, Su, Jinzhou (Joe) wrote:
> > When system resumes from S3, the CPPC enable register will be 
> > cleared and reset to 0. So sets this bit to enable CPPC interface by 
> > writing 1 to this register.
> >
> > Signed-off-by: Jinzhou Su <Jinzhou.Su@amd.com>
>
> Signed-off-by: Jinzhou Su <Jinzhou.Su@amd.com>
> Cc: stable@vger.kernel.org
>
> You can add one line below your commit description to Cc stable 
> mailing list. And next time in V2, it's better to use subject-prefix 
> optional to mark it as v2 like below:
>
> git format-patch --subject-prefix="PATCH v2" HEAD~
>
> Other looks good for me, patch is
>
> Acked-by: Huang Rui <ray.huang@amd.com>
>
> > ---
> >  drivers/cpufreq/amd-pstate.c | 24 ++++++++++++++++++++++++
> >  1 file changed, 24 insertions(+)
> >
> > diff --git a/drivers/cpufreq/amd-pstate.c 
> > b/drivers/cpufreq/amd-pstate.c index 7be38bc6a673..9ac75c1cde9c 
> > 100644
> > --- a/drivers/cpufreq/amd-pstate.c
> > +++ b/drivers/cpufreq/amd-pstate.c
> > @@ -566,6 +566,28 @@ static int amd_pstate_cpu_exit(struct cpufreq_policy
> *policy)
> >       return 0;
> >  }
> >
> > +static int amd_pstate_cpu_resume(struct cpufreq_policy *policy) {
> > +     int ret;
> > +
> > +     ret = amd_pstate_enable(true);
> > +     if (ret)
> > +             pr_err("failed to enable amd-pstate during resume, 
> > + return %d\n", ret);
> > +
> > +     return ret;
> > +}
> > +
> > +static int amd_pstate_cpu_suspend(struct cpufreq_policy *policy) {
> > +     int ret;
> > +
> > +     ret = amd_pstate_enable(false);
> > +     if (ret)
> > +             pr_err("failed to disable amd-pstate during suspend, 
> > + return %d\n", ret);
> > +
> > +     return ret;
> > +}
> > +
> >  /* Sysfs attributes */
> >
> >  /*
> > @@ -636,6 +658,8 @@ static struct cpufreq_driver amd_pstate_driver = {
> >       .target         = amd_pstate_target,
> >       .init           = amd_pstate_cpu_init,
> >       .exit           = amd_pstate_cpu_exit,
> > +     .suspend        = amd_pstate_cpu_suspend,
> > +     .resume         = amd_pstate_cpu_resume,
> >       .set_boost      = amd_pstate_set_boost,
> >       .name           = "amd-pstate",
> >       .attr           = amd_pstate_attr,
> > --

Applied with some edits in the subject and changelog, and a CC:stable tag added, as 5.19-rc material.

Thanks!
Comment 4 Joe 2022-06-30 08:33:24 UTC
Hello, 

It works on my local. Please try the update and close the issue. 

Thanks!
Joe

Note You need to log in before you can comment on or make changes to this bug.