Skip to contentSkip to conversation

cpufreq: amd-pstate: Enable AMD Pstate Preferred Core Supporting.

PATCH Rene Rebe 2 participants 2 messages Aug 29, 2023 – Aug 31, 2023

Subsystems (4)
lore
Share & tools
lore

Rene Rebe

author
#0 lore raw

Dear Meng Li and team,

thank you so much for working on finally bringing AMD preferred core scheduling to mainline Linux!

Quoted 2 lines

The initial core rankings are set up by AMD Pstate when the system boots.

I tested this patch on our Ryzen 7950x and 5950x systems and could unfortunatlely not find any performance differences. I therefore took a closer look and as far as I can tell the conditional for the initial preferred performance priorities appears to be reversed. I marked them down below. I also attached a patch for the fix. With that fixed I can measure a 0.7% improvement compiling Firefox on 7950x. I wonder slightly how this ever past testing before, ...

I think it would be a good idea to always expose the hw perf values in sysfs to help users debugging hardware issues or BIOS settings even with percore not enabled and therefore not using the unused 166 or 255 values anyway.

With that fixed, however, Linux is still not always scheduling to preferred cores, but that appears to be an independant limitation of the current linux scheduler not strictly using the priority for scheduling, yet. With manual taskset guidance I could further improve the Firefox build time by some more seconds to over 1% overall performance improvement, if the linux scheudler would more reliably schedule minute long running rust lto link tasks to the preferred cores and not some mediocre ones.

Review

Quoted 9 lines
(quoted diff) +4 -5
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > AMD_CPPC_HIGHEST_PERF(cap1))
-		highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
-
-	WRITE_ONCE(cpudata->highest_perf, highest_perf);
+	if (prefcore)
+		WRITE_ONCE(cpudata->highest_perf, AMD_PSTATE_PREFCORE_THRESHOLD);
+	else
+		WRITE_ONCE(cpudata->highest_perf, AMD_CPPC_HIGHEST_PERF(cap1));

Conditional reversed, assigns THRESHOLD if enabled!

Quoted 11 lines
(quoted diff) +0 -1
 	WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1));
 	WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1));
@@ -318,17 +322,15 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
 static int cppc_init_perf(struct amd_cpudata *cpudata)
 {
 	struct cppc_perf_caps cppc_perf;
-	u32 highest_perf;
 
 	int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
 	if (ret)
 		return ret;

Review static int pstate_init_perf(struct amd_cpudata *cpudata) · line 333

Quoted 10 lines
(quoted diff) +4 -5
 
-	highest_perf = amd_get_highest_perf();
-	if (highest_perf > cppc_perf.highest_perf)
-		highest_perf = cppc_perf.highest_perf;
-
-	WRITE_ONCE(cpudata->highest_perf, highest_perf);
+	if (prefcore)
+		WRITE_ONCE(cpudata->highest_perf, AMD_PSTATE_PREFCORE_THRESHOLD);
+	else
+		WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf);

Same here. Not using highest_perf if enabled, ...

drivers/cpufreq/amd-pstate.c renamed from drivers/cpufreq/amd-pstate.c.vanilla +4 -4
@@ -282,9 +282,9 @@
 	 * the default max perf.
 	 */
 	if (prefcore)
-		WRITE_ONCE(cpudata->highest_perf, AMD_PSTATE_PREFCORE_THRESHOLD);
-	else
 		WRITE_ONCE(cpudata->highest_perf, AMD_CPPC_HIGHEST_PERF(cap1));
+	else
+		WRITE_ONCE(cpudata->highest_perf, AMD_PSTATE_PREFCORE_THRESHOLD);
 
 	WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1));
 	WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1));
@@ -303,9 +303,9 @@
 		return ret;
 
 	if (prefcore)
-		WRITE_ONCE(cpudata->highest_perf, AMD_PSTATE_PREFCORE_THRESHOLD);
-	else
 		WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf);
+	else
+		WRITE_ONCE(cpudata->highest_perf, AMD_PSTATE_PREFCORE_THRESHOLD);
 
 	WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf);
 	WRITE_ONCE(cpudata->lowest_nonlinear_perf,
Signature · 2 lines
  René Rebe, ExactCODE GmbH, Lietzenburger Str. 42, DE-10789 Berlin
  https://exactcode.com | https://t2sde.org | https://rene.rebe.de
#1 lore raw

[AMD Official Use Only - General]

Hi Rene:

Quoted 38 lines

-----Original Message-----
From: Rene Rebe <[email protected]>
Sent: Tuesday, August 29, 2023 5:35 PM
To: Meng, Li (Jassmine) <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; Shuah Khan <[email protected]>; [email protected]; Fontenot, Nathan <[email protected]>; Sharma, Deepak <[email protected]>; Deucher, Alexander <[email protected]>; Limonciello, Mario <[email protected]>; Huang, Shimmer <[email protected]>; Yuan, Perry <[email protected]>; Du, Xiaojian <[email protected]>; Viresh Kumar <[email protected]>; Borislav Petkov <[email protected]>; Meng, Li (Jassmine) <[email protected]>; Karny, Wyes <[email protected]>
Subject: Re: [PATCH V4 3/7] cpufreq: amd-pstate: Enable AMD Pstate Preferred Core Supporting.

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Dear Meng Li and team,

thank you so much for working on finally bringing AMD preferred core scheduling to mainline Linux!

Quoted 2 lines

The initial core rankings are set up by AMD Pstate when the system boots.

I tested this patch on our Ryzen 7950x and 5950x systems and could unfortunatlely not find any performance differences. I therefore took a closer look and as far as I can tell the conditional for the initial preferred performance priorities appears to be reversed. I marked them down below. I also attached a patch for the fix. With that fixed I can measure a 0.7% improvement compiling Firefox on 7950x. I wonder slightly how this ever past testing before, ...

Quoted 4 lines

I think it would be a good idea to always expose the hw perf values in sysfs to help users debugging hardware issues or BIOS settings even with percore not enabled and therefore not using the unused 166 or 255 values anyway.

[Meng, Li (Jassmine)]
I will add a new sysfs attribute for the highest performance of preferred core.

Quoted 16 lines

With that fixed, however, Linux is still not always scheduling to preferred cores, but that appears to be an independant limitation of the current linux scheduler not strictly using the priority for scheduling, yet. With manual taskset guidance I could further improve the Firefox build time by some more seconds to over 1% overall performance improvement, if the linux scheudler would more reliably schedule minute long running rust lto link tasks to the preferred cores and not some mediocre ones.

Review

Quoted 7 lines
(quoted diff) +2 -5
-     highest_perf = amd_get_highest_perf();
-     if (highest_perf > AMD_CPPC_HIGHEST_PERF(cap1))
-             highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
-
-     WRITE_ONCE(cpudata->highest_perf, highest_perf);
+     if (prefcore)
+             WRITE_ONCE(cpudata->highest_perf,
Quoted 6 lines

AMD_PSTATE_PREFCORE_THRESHOLD);

Review

Quoted 3 lines
(quoted diff) +3 -0
+     else
+             WRITE_ONCE(cpudata->highest_perf,
+ AMD_CPPC_HIGHEST_PERF(cap1));

Conditional reversed, assigns THRESHOLD if enabled!

[Meng, Li (Jassmine)]
The highest_perf is used to calculate the frequency value. The values between 166 and 255 represent priority, not the highest perf.

Quoted 69 lines
Quoted 2 lines
      WRITE_ONCE(cpudata->nominal_perf,

AMD_CPPC_NOMINAL_PERF(cap1));

Quoted 8 lines
      WRITE_ONCE(cpudata->lowest_nonlinear_perf,
AMD_CPPC_LOWNONLIN_PERF(cap1)); @@ -318,17 +322,15 @@ static int
pstate_init_perf(struct amd_cpudata *cpudata)  static int
cppc_init_perf(struct amd_cpudata *cpudata)  {
      struct cppc_perf_caps cppc_perf;
(quoted diff) +0 -1
-     u32 highest_perf;
 
      int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);

Review

Quoted 10 lines
(quoted diff) +2 -5
      if (ret)
              return ret;
 
-     highest_perf = amd_get_highest_perf();
-     if (highest_perf > cppc_perf.highest_perf)
-             highest_perf = cppc_perf.highest_perf;
-
-     WRITE_ONCE(cpudata->highest_perf, highest_perf);
+     if (prefcore)
+             WRITE_ONCE(cpudata->highest_perf,

AMD_PSTATE_PREFCORE_THRESHOLD);

Review

Quoted 3 lines
(quoted diff) +3 -0
+     else
+             WRITE_ONCE(cpudata->highest_perf,
+ cppc_perf.highest_perf);

Same here. Not using highest_perf if enabled, ...

--- linux-6.4/drivers/cpufreq/amd-pstate.c.vanilla 2023-08-25
22:34:25.254995690 +0200
+++ linux-6.4/drivers/cpufreq/amd-pstate.c 2023-08-25
22:35:49.194991446 +0200

(quoted diff) +3 -2
@@ -282,9 +282,9 @@
         * the default max perf.
         */
        if (prefcore)
-               WRITE_ONCE(cpudata->highest_perf,
 AMD_PSTATE_PREFCORE_THRESHOLD);
-       else
                WRITE_ONCE(cpudata->highest_perf,
 AMD_CPPC_HIGHEST_PERF(cap1));
+       else
+               WRITE_ONCE(cpudata->highest_perf,
+ AMD_PSTATE_PREFCORE_THRESHOLD);
 
        WRITE_ONCE(cpudata->nominal_perf,
AMD_CPPC_NOMINAL_PERF(cap1));
        WRITE_ONCE(cpudata->lowest_nonlinear_perf,
AMD_CPPC_LOWNONLIN_PERF(cap1)); @@ -303,9 +303,9 @@
                return ret;

        if (prefcore)

- WRITE_ONCE(cpudata->highest_perf,
AMD_PSTATE_PREFCORE_THRESHOLD);

(quoted diff) +3 -2
-       else
                WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf);
+       else
+               WRITE_ONCE(cpudata->highest_perf,
+ AMD_PSTATE_PREFCORE_THRESHOLD);
 
        WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf);
        WRITE_ONCE(cpudata->lowest_nonlinear_perf,
 
 
--
  René Rebe, ExactCODE GmbH, Lietzenburger Str. 42, DE-10789 Berlin
  https://exactcode.com | https://t2sde.org | https://rene.rebe.de