Skip to contentSkip to conversation

tools/power/cpupower: Fix Pstate frequency reporting on AMD Family 1Ah CPUs

PATCH In review Dhananjay Ugwekar 3 participants 3 messages Apr 30, 2024 – May 2, 2024 CPU power monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/power/cpupower: Fix Pstate frequency reporting on AMD Family 1Ah CPUs

Update cpupower's P-State frequency calculation and reporting with AMD Family 1Ah+ processors, when using the acpi-cpufreq driver. This is due to a change in the PStateDef MSR layout in AMD Family 1Ah+.

[ dhananjay: commit log, tested on 4th and 5th Gen AMD EPYC system ]

---
 tools/power/cpupower/utils/helpers/amd.c | 26 +++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
tools/power/cpupower/utils/helpers/amd.c +23 -3
index c519cc89c97f..0a56e22240fc 100644
@@ -41,6 +41,16 @@ union core_pstate {
 		unsigned res1:31;
 		unsigned en:1;
 	} pstatedef;
+	/* since fam 1Ah: */
+	struct {
+		unsigned fid:12;
+		unsigned res1:2;
+		unsigned vid:8;
+		unsigned iddval:8;
+		unsigned idddiv:2;
+		unsigned res2:31;
+		unsigned en:1;
+	} pstatedef2;
 	unsigned long long val;
 };
 
@@ -48,6 +58,10 @@ static int get_did(union core_pstate pstate)
 {
 	int t;
 
+	/* Fam 1Ah onward do not use did */
+	if (cpupower_cpu_info.family >= 0x1A)
+		return 0;
+
 	if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATEDEF)
 		t = pstate.pstatedef.did;
 	else if (cpupower_cpu_info.family == 0x12)
@@ -61,12 +75,18 @@ static int get_did(union core_pstate pstate)
 static int get_cof(union core_pstate pstate)
 {
 	int t;
-	int fid, did, cof;
+	int fid, did, cof = 0;
 
 	did = get_did(pstate);
 	if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATEDEF) {
-		fid = pstate.pstatedef.fid;
-		cof = 200 * fid / did;
+		if (cpupower_cpu_info.family >= 0x1A) {
+			fid = pstate.pstatedef2.fid;
+			if (fid > 0x0f)
+				cof = (fid * 5);
+		} else {
+			fid = pstate.pstatedef.fid;
+			cof = 200 * fid / did;
+		}
 	} else {
 		t = 0x10;
 		fid = pstate.pstate.fid;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dhananjay Ugwekar

Update cpupower's P-State frequency calculation and reporting with AMD Family 1Ah+ processors, when using the acpi-cpufreq driver. This is due to a change in the PStateDef MSR layout in AMD Family 1Ah+.

[ dhananjay: commit log, tested on 4th and 5th Gen AMD EPYC system ]

Quoted 58 lines
---
  tools/power/cpupower/utils/helpers/amd.c | 26 +++++++++++++++++++++---
  1 file changed, 23 insertions(+), 3 deletions(-)
tools/power/cpupower/utils/helpers/amd.c +23 -3
index c519cc89c97f..0a56e22240fc 100644
@@ -41,6 +41,16 @@ union core_pstate {
  		unsigned res1:31;
  		unsigned en:1;
  	} pstatedef;
+	/* since fam 1Ah: */
+	struct {
+		unsigned fid:12;
+		unsigned res1:2;
+		unsigned vid:8;
+		unsigned iddval:8;
+		unsigned idddiv:2;
+		unsigned res2:31;
+		unsigned en:1;
+	} pstatedef2;
  	unsigned long long val;
  };
 
@@ -48,6 +58,10 @@ static int get_did(union core_pstate pstate)
  {
  	int t;
 
+	/* Fam 1Ah onward do not use did */
+	if (cpupower_cpu_info.family >= 0x1A)
+		return 0;
+
  	if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATEDEF)
  		t = pstate.pstatedef.did;
  	else if (cpupower_cpu_info.family == 0x12)
@@ -61,12 +75,18 @@ static int get_did(union core_pstate pstate)
  static int get_cof(union core_pstate pstate)
  {
  	int t;
-	int fid, did, cof;
+	int fid, did, cof = 0;
 
  	did = get_did(pstate);
  	if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATEDEF) {
-		fid = pstate.pstatedef.fid;
-		cof = 200 * fid / did;
+		if (cpupower_cpu_info.family >= 0x1A) {
+			fid = pstate.pstatedef2.fid;
+			if (fid > 0x0f)
+				cof = (fid * 5);
+		} else {
+			fid = pstate.pstatedef.fid;
+			cof = 200 * fid / did;
+		}
  	} else {
  		t = 0x10;
  		fid = pstate.pstate.fid;
maintainer
#2 lore raw
Quoted 10 lines · Mario Limonciello
Quoted 8 lines · Dhananjay Ugwekar

Update cpupower's P-State frequency calculation and reporting with AMD Family 1Ah+ processors, when using the acpi-cpufreq driver. This is due to a change in the PStateDef MSR layout in AMD Family 1Ah+.

[ dhananjay: commit log, tested on 4th and 5th Gen AMD EPYC system ]

Thank you. Applied to

git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git/log/ cpupower branch for Linux 6.10-rc1.

I will include it in my pull request to Rafael.

thanks
-- Shuah