Skip to contentSkip to conversation

cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

RFC PATCH Superseded Nabil S. Alramli 3 participants 9 messages Oct 25, 2024 – Oct 29, 2024 1 message not in the archive Stable branch

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): Zw8Wn5SPqBfRKUhp@LQ3V64L9R2

#1 lore raw

cover cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

Greetings,

This is a RFC for a maintenance patch to an issue in the amd_pstate driver where CPU frequency cannot be boosted in passive or guided modes. Without this patch, AMD machines using stable kernels are unable to get their CPU frequency boosted, which is a significant performance issue.

For example, on a host that has AMD EPYC 7662 64-Core processor without this patch running at full CPU load:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
  do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
  sort | uniq -c
    128 2.0 GHz

And with this patch:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
  do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
  sort | uniq -c
    128 3.3 GHz

I am not sure what the correct process is for submitting patches which affect only stable trees but not the current code base, and do not apply to the current tree. As such, I am submitting this directly to stable@, but please let me know if I should be submitting this elsewhere.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels up until v6.6.51.

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly refactored the code. This commit cannot be ported back on its own, and would require reviewing and cherry picking at least a few dozen of commits in cpufreq, amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant performance issue, and cannot be easily remediated.

Thank you for your attention and I look forward to your response in regards to what the best way to proceed is for getting this important performance fix merged.

Best Regards,

Nabil S. Alramli (1):
cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

 drivers/cpufreq/amd-pstate.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.35.1
#2 lore raw

RFC PATCH 1/1 cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

The CPU frequency cannot be boosted when using the amd_pstate driver in passive or guided mode. This is fixed here.

The CPU frequency is dependent on a setting called highest_perf which is the multiplier used to compute it. The highest_perf value comes from cppc_init_perf when the driver is built-in and from pstate_init_perf when it is a loaded module. Both of these calls have the following condition:

	highest_perf = amd_get_highest_perf();
	if (highest_perf > __cppc_highest_perf_)
		highest_perf = __cppc_highest_perf;

Where again __cppc_highest_perf is either the return from cppc_get_perf_caps in the built-in case or AMD_CPPC_HIGHEST_PERF in the module case. Both of these functions actually return the nominal value, Whereas the call to amd_get_highest_perf returns the correct boost value, so the condition tests true and highest_perf always ends up being the nominal value, therefore never having the ability to boost CPU frequency.

Since amd_get_highest_perf already returns the boost value we should just eliminate this check.

Fixes bedadcfb011f ("cpufreq: amd-pstate: Fix initial highest_perf value")

See-also: 1ec40a175a48 ("cpufreq: amd-pstate: Enable amd-pstate preferred core support")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected] # 6.1 - v6.6.50

---
 drivers/cpufreq/amd-pstate.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/cpufreq/amd-pstate.c +2 -6
index 90dcf26f0973..c66086ae624a 100644
@@ -102,9 +102,7 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
 	 *
 	 * CPPC entry doesn't indicate the highest performance in some ASICs.
 	 */
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > AMD_CPPC_HIGHEST_PERF(cap1))
-		highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
+	highest_perf = max(amd_get_highest_perf(), AMD_CPPC_HIGHEST_PERF(cap1));
 
 	WRITE_ONCE(cpudata->highest_perf, highest_perf);
 
@@ -124,9 +122,7 @@ static int cppc_init_perf(struct amd_cpudata *cpudata)
 	if (ret)
 		return ret;
 
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > cppc_perf.highest_perf)
-		highest_perf = cppc_perf.highest_perf;
+	highest_perf = max(amd_get_highest_perf(), cppc_perf.highest_perf);
 
 	WRITE_ONCE(cpudata->highest_perf, highest_perf);
 
Signature · 1 line
2.35.1
#3 lore raw
In reply to Nabil S. Alramli

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 59 lines

-----Original Message-----
From: Nabil S. Alramli <[email protected]>
Sent: Friday, October 25, 2024 9:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yuan, Perry <[email protected]>; Meng, Li (Jassmine) <[email protected]>; Huang, Ray <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; Nabil S. Alramli <[email protected]>
Subject: [RFC PATCH 6.1.y 0/1] cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

Greetings,

This is a RFC for a maintenance patch to an issue in the amd_pstate driver where CPU frequency cannot be boosted in passive or guided modes. Without this patch, AMD machines using stable kernels are unable to get their CPU frequency boosted, which is a significant performance issue.

For example, on a host that has AMD EPYC 7662 64-Core processor without this patch running at full CPU load:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
  do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
  sort | uniq -c
    128 2.0 GHz

And with this patch:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
  do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
  sort | uniq -c
    128 3.3 GHz

I am not sure what the correct process is for submitting patches which affect only stable trees but not the current code base, and do not apply to the current tree. As such, I am submitting this directly to stable@, but please let me know if I should be submitting this elsewhere.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels up until v6.6.51.

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly refactored the code. This commit cannot be ported back on its own, and would require reviewing and cherry picking at least a few dozen of commits in cpufreq, amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant performance issue, and cannot be easily remediated.

Thank you for your attention and I look forward to your response in regards to what the best way to proceed is for getting this important performance fix merged.

Best Regards,

Quoted 8 lines

Nabil S. Alramli (1):
cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

 drivers/cpufreq/amd-pstate.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

--
2.35.1

Add Mario and Gautham for any help.

Perry.

#4 lore raw
Quoted 67 lines · Perry

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 65 lines

-----Original Message-----
From: Nabil S. Alramli <[email protected]>
Sent: Friday, October 25, 2024 9:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yuan, Perry <[email protected]>; Meng, Li (Jassmine) <[email protected]>; Huang, Ray <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; Nabil S. Alramli <[email protected]>
Subject: [RFC PATCH 6.1.y 0/1] cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

Greetings,

This is a RFC for a maintenance patch to an issue in the amd_pstate driver where CPU frequency cannot be boosted in passive or guided modes. Without this patch, AMD machines using stable kernels are unable to get their CPU frequency boosted, which is a significant performance issue.

For example, on a host that has AMD EPYC 7662 64-Core processor without this patch running at full CPU load:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c
     128 2.0 GHz

And with this patch:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c
     128 3.3 GHz

I am not sure what the correct process is for submitting patches which affect only stable trees but not the current code base, and do not apply to the current tree. As such, I am submitting this directly to stable@, but please let me know if I should be submitting this elsewhere.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels up until v6.6.51.

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly refactored the code. This commit cannot be ported back on its own, and would require reviewing and cherry picking at least a few dozen of commits in cpufreq, amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant performance issue, and cannot be easily remediated.

Thank you for your attention and I look forward to your response in regards to what the best way to proceed is for getting this important performance fix merged.

Best Regards,

Nabil S. Alramli (1):
cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

  drivers/cpufreq/amd-pstate.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 2 lines

--
2.35.1

Add Mario and Gautham for any help.

Perry.

If doing a patch that is only for 6.1.y then I think that some more of this information from the cover letter needs to push into the patch itself.

But looking over the patch and considering how much we've changed this in the newer kernels I think it is a sensible localized change for 6.1.y.

As this is fixed in 6.6.51 via a more complete backport patch please only tag 6.1 in your "Cc: [email protected]" from the patch.

#5 lore raw

Hi Mario,

Thank you for taking a look at my patch.

What do you think about the following for the commit message in the next revision of the PATCH, and omitting the cover letter since most of it is incorporated here?

***********************************************************************

cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

The CPU frequency cannot be boosted when using the amd_pstate driver in passive or guided mode. This is fixed here.

For example, on a host that has AMD EPYC 7662 64-Core processor without this patch running at full CPU load:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
  do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
  sort | uniq -c
    128 2.0 GHz

And with this patch:

$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
  do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
  sort | uniq -c
    128 3.3 GHz

The CPU frequency is dependent on a setting called highest_perf which is the multiplier used to compute it. The highest_perf value comes from cppc_init_perf when the driver is built-in and from pstate_init_perf when it is a loaded module. Both of these calls have the following condition:

        highest_perf = amd_get_highest_perf();
        if (highest_perf > __cppc_highest_perf_)
                highest_perf = __cppc_highest_perf;

Where again __cppc_highest_perf is either the return from cppc_get_perf_caps in the built-in case or AMD_CPPC_HIGHEST_PERF in the module case. Both of these functions actually return the nominal value, Whereas the call to amd_get_highest_perf returns the correct boost value, so the condition tests true and highest_perf always ends up being the nominal value, therefore never having the ability to boost CPU frequency.

Since amd_get_highest_perf already returns the boost value we should just eliminate this check.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly refactored the code. This commit cannot be ported back on its own, and would require reviewing and cherry picking at least a few dozen of commits in cpufreq, amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant performance issue, and cannot be easily remediated. This patch simplifies the fix to a single commit.

***********************************************************************

Quoted 103 lines · Mario Limonciello
Quoted 85 lines · Perry

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 83 lines

-----Original Message-----
From: Nabil S. Alramli <[email protected]>
Sent: Friday, October 25, 2024 9:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yuan, Perry
<[email protected]>; Meng, Li (Jassmine) <[email protected]>; Huang, Ray <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; Nabil S. Alramli <[email protected]>
Subject: [RFC PATCH 6.1.y 0/1] cpufreq: amd-pstate: Enable CPU boost in passive
and guided modes

Greetings,

This is a RFC for a maintenance patch to an issue in the amd_pstate driver where
CPU frequency cannot be boosted in passive or guided modes. Without this patch,
AMD machines using stable kernels are unable to get their CPU frequency boosted,
which is a significant performance issue.

For example, on a host that has AMD EPYC 7662 64-Core processor without this
patch running at full CPU load:

$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c

     128 2.0 GHz

And with this patch:

$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c

     128 3.3 GHz

I am not sure what the correct process is for submitting patches which affect only
stable trees but not the current code base, and do not apply to the current tree. As
such, I am submitting this directly to stable@, but please let me know if I should be
submitting this elsewhere.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels up until
v6.6.51.

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly
refactored the code. This commit cannot be ported back on its own, and would
require reviewing and cherry picking at least a few dozen of commits in cpufreq,
amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant
performance issue, and cannot be easily remediated.

Thank you for your attention and I look forward to your response in regards to what
the best way to proceed is for getting this important performance fix merged.

Best Regards,

Nabil S. Alramli (1):
   cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

  drivers/cpufreq/amd-pstate.c | 8 ++------

  1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 2 lines
Signature · 1 line
2.35.1

Add Mario and Gautham for any help.

Perry.

If doing a patch that is only for 6.1.y then I think that some more of this information from the cover letter needs to push into the patch itself.

But looking over the patch and considering how much we've changed this in the newer kernels I think it is a sensible localized change for 6.1.y.

As this is fixed in 6.6.51 via a more complete backport patch please only tag 6.1 in your "Cc: [email protected]" from the patch.

#6 lore raw
Quoted 8 lines · Nabil S. Alramli

Hi Mario,

Thank you for taking a look at my patch.

What do you think about the following for the commit message in the next revision of the PATCH, and omitting the cover letter since most of it is incorporated here?

Quoted 6 lines

***********************************************************************

cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

The CPU frequency cannot be boosted when using the amd_pstate driver in passive or guided mode. This is fixed here.

No need to say things like "I did this" or "this patch does that". Just drop last sentence.

Quoted 3 lines

For example, on a host that has AMD EPYC 7662 64-Core processor without this patch running at full CPU load:

"On a host that has an AMD EPYC 7662 processor while running with amd-pstate configured for passive mode on full CPU load the processor only reaches 2.0 GHz."

Quoted 8 lines
$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c
     128 2.0 GHz

And with this patch:

On later kernels the CPU can reach 3.3GHz.

Quoted 24 lines
$ for i in $(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c
     128 3.3 GHz

The CPU frequency is dependent on a setting called highest_perf which is the multiplier used to compute it. The highest_perf value comes from cppc_init_perf when the driver is built-in and from pstate_init_perf when it is a loaded module. Both of these calls have the following condition:

         highest_perf = amd_get_highest_perf();
         if (highest_perf > __cppc_highest_perf_)
                 highest_perf = __cppc_highest_perf;

Where again __cppc_highest_perf is either the return from cppc_get_perf_caps in the built-in case or AMD_CPPC_HIGHEST_PERF in the module case. Both of these functions actually return the nominal value, Whereas the call to amd_get_highest_perf returns the correct boost value, so the condition tests true and highest_perf always ends up being the nominal value, therefore never having the ability to boost CPU frequency.

Quoted 5 lines

Since amd_get_highest_perf already returns the boost value we should just eliminate this check.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels

"In stable 6.1" kernels.

Quoted 7 lines

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly refactored the code. This commit cannot be ported back on its own, and would require reviewing and cherry picking at least a few dozen of commits in cpufreq, amd-pstate, ACPI, CPPC.

I'd just say "this has been fixed in 6.6.y and newer but due to refactoring that change isn't feasible to bring back to 6.1.y"

Quoted 3 lines

This means kernels v6.1 up until v6.6.51 are affected by this significant performance issue, and cannot be easily remediated. This patch simplifies the fix to a single commit.

Again no need to say "this patch".

Quoted 107 lines

***********************************************************************

Quoted 103 lines · Mario Limonciello
Quoted 85 lines · Perry

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 83 lines

-----Original Message-----
From: Nabil S. Alramli <[email protected]>
Sent: Friday, October 25, 2024 9:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yuan, Perry
<[email protected]>; Meng, Li (Jassmine) <[email protected]>; Huang, Ray <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; Nabil S. Alramli <[email protected]>
Subject: [RFC PATCH 6.1.y 0/1] cpufreq: amd-pstate: Enable CPU boost in passive
and guided modes

Greetings,

This is a RFC for a maintenance patch to an issue in the amd_pstate driver where
CPU frequency cannot be boosted in passive or guided modes. Without this patch,
AMD machines using stable kernels are unable to get their CPU frequency boosted,
which is a significant performance issue.

For example, on a host that has AMD EPYC 7662 64-Core processor without this
patch running at full CPU load:

$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
    do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
    sort | uniq -c

     128 2.0 GHz

And with this patch:

$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
    do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
    sort | uniq -c

     128 3.3 GHz

I am not sure what the correct process is for submitting patches which affect only
stable trees but not the current code base, and do not apply to the current tree. As
such, I am submitting this directly to stable@, but please let me know if I should be
submitting this elsewhere.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels up until
v6.6.51.

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly
refactored the code. This commit cannot be ported back on its own, and would
require reviewing and cherry picking at least a few dozen of commits in cpufreq,
amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant
performance issue, and cannot be easily remediated.

Thank you for your attention and I look forward to your response in regards to what
the best way to proceed is for getting this important performance fix merged.

Best Regards,

Nabil S. Alramli (1):
   cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

   drivers/cpufreq/amd-pstate.c | 8 ++------
   1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 2 lines
Signature · 1 line
2.35.1

Add Mario and Gautham for any help.

Perry.

If doing a patch that is only for 6.1.y then I think that some more of this information from the cover letter needs to push into the patch itself.

But looking over the patch and considering how much we've changed this in the newer kernels I think it is a sensible localized change for 6.1.y.

As this is fixed in 6.6.51 via a more complete backport patch please only tag 6.1 in your "Cc: [email protected]" from the patch.

#7 lore raw

Mario,

Thank you so much for your valuable feedback. This all makes sense, and I will incorporate it into another revision soon.

Quoted 11 lines · Mario Limonciello
Quoted 10 lines · Nabil S. Alramli

Hi Mario,

Thank you for taking a look at my patch.

What do you think about the following for the commit message in the next revision of the PATCH, and omitting the cover letter since most of it is incorporated here?

***********************************************************************

Quoted 8 lines
Quoted 4 lines

cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

The CPU frequency cannot be boosted when using the amd_pstate driver in passive or guided mode. This is fixed here.

No need to say things like "I did this" or "this patch does that". Just drop last sentence.

My apologies. I was just trying to be clear as to what this patch does. I will drop it.

Quoted 60 lines
Quoted 3 lines

For example, on a host that has AMD EPYC 7662 64-Core processor without this patch running at full CPU load:

"On a host that has an AMD EPYC 7662 processor while running with amd-pstate configured for passive mode on full CPU load the processor only reaches 2.0 GHz."

Quoted 9 lines
$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c

     128 2.0 GHz

And with this patch:

On later kernels the CPU can reach 3.3GHz.

Quoted 25 lines
$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
   do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz"; done | \
   sort | uniq -c

     128 3.3 GHz

The CPU frequency is dependent on a setting called highest_perf which is the multiplier used to compute it. The highest_perf value comes from cppc_init_perf when the driver is built-in and from pstate_init_perf when it is a loaded module. Both of these calls have the following condition:

         highest_perf = amd_get_highest_perf(); if (highest_perf > __cppc_highest_perf_) highest_perf = __cppc_highest_perf;

Where again __cppc_highest_perf is either the return from cppc_get_perf_caps in the built-in case or AMD_CPPC_HIGHEST_PERF in the module case. Both of these functions actually return the nominal value, Whereas the call to amd_get_highest_perf returns the correct boost value, so the condition tests true and highest_perf always ends up being the nominal value, therefore never having the ability to boost CPU frequency.

Quoted 6 lines

Since amd_get_highest_perf already returns the boost value we should just eliminate this check.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels

"In stable 6.1" kernels.

Quoted 7 lines

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly refactored the code. This commit cannot be ported back on its own, and would require reviewing and cherry picking at least a few dozen of commits in cpufreq, amd-pstate, ACPI, CPPC.

Quoted 8 lines

I'd just say "this has been fixed in 6.6.y and newer but due to refactoring that change isn't feasible to bring back to 6.1.y"

Quoted 3 lines

This means kernels v6.1 up until v6.6.51 are affected by this significant performance issue, and cannot be easily remediated. This patch simplifies the fix to a single commit.

Again no need to say "this patch".

Understood. As I stated this was just for clarity as to why the patch may be needed or useful.

Quoted 115 lines
Quoted 114 lines

***********************************************************************

Quoted 109 lines · Mario Limonciello
Quoted 89 lines · Perry

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 87 lines

-----Original Message-----
From: Nabil S. Alramli <[email protected]>
Sent: Friday, October 25, 2024 9:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yuan, Perry
<[email protected]>; Meng, Li (Jassmine) <[email protected]>; Huang, Ray
<[email protected]>; [email protected]; [email protected]; linux-
[email protected]; [email protected]; Nabil S. Alramli <[email protected]>
Subject: [RFC PATCH 6.1.y 0/1] cpufreq: amd-pstate: Enable CPU boost in passive
and guided modes

Greetings,

This is a RFC for a maintenance patch to an issue in the amd_pstate driver where
CPU frequency cannot be boosted in passive or guided modes. Without this patch,
AMD machines using stable kernels are unable to get their CPU frequency boosted,
which is a significant performance issue.

For example, on a host that has AMD EPYC 7662 64-Core processor without this
patch running at full CPU load:

$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
    do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz";
done | \
    sort | uniq -c

      128 2.0 GHz

And with this patch:

$ for i in $(cat
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); \
    do ni=$(echo "scale=1; $i/1000000" | bc -l); echo "$ni GHz";
done | \
    sort | uniq -c

      128 3.3 GHz

I am not sure what the correct process is for submitting patches which affect only
stable trees but not the current code base, and do not apply to the current tree. As
such, I am submitting this directly to stable@, but please let me know if I should be
submitting this elsewhere.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable kernels up until
v6.6.51.

In v6.6.51, a large change, commit 1ec40a175a48 ("cpufreq: amd-pstate:
Enable amd-pstate preferred core support"), was introduced which significantly
refactored the code. This commit cannot be ported back on its own, and would
require reviewing and cherry picking at least a few dozen of commits in cpufreq,
amd-pstate, ACPI, CPPC.

This means kernels v6.1 up until v6.6.51 are affected by this significant
performance issue, and cannot be easily remediated.

Thank you for your attention and I look forward to your response in regards to what
the best way to proceed is for getting this important performance fix merged.

Best Regards,

Nabil S. Alramli (1):
    cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

   drivers/cpufreq/amd-pstate.c | 8 ++------

   1 file changed, 2 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 2 lines

--
2.35.1

Add Mario and Gautham for any help.

Perry.

If doing a patch that is only for 6.1.y then I think that some more of this information from the cover letter needs to push into the patch itself.

But looking over the patch and considering how much we've changed this in the newer kernels I think it is a sensible localized change for 6.1.y.

As this is fixed in 6.6.51 via a more complete backport patch please only tag 6.1 in your "Cc: [email protected]" from the patch.

#8 lore raw

PATCH v2 1/1 cpufreq: amd-pstate: Enable CPU boost in passive and guided modes

In reply to a message not in the archive

CPU frequency cannot be boosted when using the amd_pstate driver in passive or guided mode.

On a host that has an AMD EPYC 7662 processor, while running with amd-pstate configured for passive mode on full CPU load, the processor only reaches 2.0 GHz. On later kernels the CPU can reach 3.3GHz.

The CPU frequency is dependent on a setting called highest_perf which is the multiplier used to compute it. The highest_perf value comes from cppc_init_perf when the driver is built-in and from pstate_init_perf when it is a loaded module. Both of these calls have the following condition:

	highest_perf = amd_get_highest_perf();
	if (highest_perf > __cppc_highest_perf_)
		highest_perf = __cppc_highest_perf;

Where again __cppc_highest_perf is either the return from cppc_get_perf_caps in the built-in case or AMD_CPPC_HIGHEST_PERF in the module case. Both of these functions actually return the nominal value, whereas the call to amd_get_highest_perf returns the correct boost value, so the condition tests true and highest_perf always ends up being the nominal value, therefore never having the ability to boost CPU frequency.

Since amd_get_highest_perf already returns the boost value, we have eliminated this check.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable v6.1 kernels. This has been fixed in v6.6.y and newer but due to refactoring that change isn't feasible to bring back to v6.1.y. Thus, v6.1 kernels are affected by this significant performance issue, and cannot be easily remediated.

Fixes bedadcfb011f ("cpufreq: amd-pstate: Fix initial highest_perf value")

See-also: 1ec40a175a48 ("cpufreq: amd-pstate: Enable amd-pstate preferred core support")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected] # v6.1
---
v2:
- Omit cover letter
- Converted from RFC to PATCH
- Expand commit message based on feedback from Mario Limonciello
- Added Reviewed-by tags
- No functional/code changes

rfc:
https://lore.kernel.org/lkml/[email protected]/

---
 drivers/cpufreq/amd-pstate.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/cpufreq/amd-pstate.c +2 -6
index 90dcf26f0973..c66086ae624a 100644
@@ -102,9 +102,7 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
 	 *
 	 * CPPC entry doesn't indicate the highest performance in some ASICs.
 	 */
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > AMD_CPPC_HIGHEST_PERF(cap1))
-		highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
+	highest_perf = max(amd_get_highest_perf(), AMD_CPPC_HIGHEST_PERF(cap1));
 
 	WRITE_ONCE(cpudata->highest_perf, highest_perf);
 
@@ -124,9 +122,7 @@ static int cppc_init_perf(struct amd_cpudata *cpudata)
 	if (ret)
 		return ret;
 
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > cppc_perf.highest_perf)
-		highest_perf = cppc_perf.highest_perf;
+	highest_perf = max(amd_get_highest_perf(), cppc_perf.highest_perf);
 
 	WRITE_ONCE(cpudata->highest_perf, highest_perf);
 
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#9 lore raw
Quoted 37 lines · Nabil S. Alramli

CPU frequency cannot be boosted when using the amd_pstate driver in passive or guided mode.

On a host that has an AMD EPYC 7662 processor, while running with amd-pstate configured for passive mode on full CPU load, the processor only reaches 2.0 GHz. On later kernels the CPU can reach 3.3GHz.

The CPU frequency is dependent on a setting called highest_perf which is the multiplier used to compute it. The highest_perf value comes from cppc_init_perf when the driver is built-in and from pstate_init_perf when it is a loaded module. Both of these calls have the following condition:

	highest_perf = amd_get_highest_perf();
	if (highest_perf > __cppc_highest_perf_)
		highest_perf = __cppc_highest_perf;

Where again __cppc_highest_perf is either the return from cppc_get_perf_caps in the built-in case or AMD_CPPC_HIGHEST_PERF in the module case. Both of these functions actually return the nominal value, whereas the call to amd_get_highest_perf returns the correct boost value, so the condition tests true and highest_perf always ends up being the nominal value, therefore never having the ability to boost CPU frequency.

Since amd_get_highest_perf already returns the boost value, we have eliminated this check.

The issue was introduced in v6.1 via commit bedadcfb011f ("cpufreq:
amd-pstate: Fix initial highest_perf value"), and exists in stable v6.1 kernels. This has been fixed in v6.6.y and newer but due to refactoring that change isn't feasible to bring back to v6.1.y. Thus, v6.1 kernels are affected by this significant performance issue, and cannot be easily remediated.

Fixes bedadcfb011f ("cpufreq: amd-pstate: Fix initial highest_perf value")
Quoted 5 lines

See-also: 1ec40a175a48 ("cpufreq: amd-pstate: Enable amd-pstate preferred core support")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected] # v6.1

Quoted 40 lines

---
v2:
- Omit cover letter
- Converted from RFC to PATCH
- Expand commit message based on feedback from Mario Limonciello
- Added Reviewed-by tags
- No functional/code changes

rfc:
https://lore.kernel.org/lkml/[email protected]/

---
  drivers/cpufreq/amd-pstate.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/cpufreq/amd-pstate.c +2 -6
index 90dcf26f0973..c66086ae624a 100644
@@ -102,9 +102,7 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
  	 *
  	 * CPPC entry doesn't indicate the highest performance in some ASICs.
  	 */
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > AMD_CPPC_HIGHEST_PERF(cap1))
-		highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
+	highest_perf = max(amd_get_highest_perf(), AMD_CPPC_HIGHEST_PERF(cap1));
 
  	WRITE_ONCE(cpudata->highest_perf, highest_perf);
 
@@ -124,9 +122,7 @@ static int cppc_init_perf(struct amd_cpudata *cpudata)
  	if (ret)
  		return ret;
 
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > cppc_perf.highest_perf)
-		highest_perf = cppc_perf.highest_perf;
+	highest_perf = max(amd_get_highest_perf(), cppc_perf.highest_perf);
 
  	WRITE_ONCE(cpudata->highest_perf, highest_perf);