diff mbox series

tools/power/turbostat: Prevent turbostat early exiting -13 on AMD_F17H

Message ID 20210122145031.754296-1-e.velu@criteo.com
State New
Headers show
Series tools/power/turbostat: Prevent turbostat early exiting -13 on AMD_F17H | expand

Commit Message

Erwan Velu Jan. 22, 2021, 2:50 p.m. UTC
Running turbostat on an AMD_F17H system, exits with a -13 error :
	[root@host] turbostat
	turbostat version 20.09.30 - Len Brown <lenb@kernel.org>
	CPUID(0): AuthenticAMD 0x10 CPUID levels; 0x80000020 xlevels; family:model:stepping 0x17:31:0 (23:49:0)
	CPUID(1): SSE3 MONITOR - - - TSC MSR - HT -
	CPUID(6): APERF, No-TURBO, No-DTS, No-PTM, No-HWP, No-HWPnotify, No-HWPwindow, No-HWPepp, No-HWPpkg, No-EPB
	CPUID(7): No-SGX
	RAPL: 234 sec. Joule Counter Range, at 280 Watts
	/dev/cpu_dma_latency: 2000000000 usec (default)
	current_driver: acpi_idle
	current_governor: menu
	current_governor_ro: menu
	cpu30: POLL: CPUIDLE CORE POLL IDLE
	cpu30: C1: ACPI FFH MWAIT 0x0
	cpu30: C2: ACPI IOPORT 0x414
	cpu30: cpufreq driver: acpi-cpufreq
	cpu30: cpufreq governor: performance
	cpufreq boost: 1
	cpu0: MSR_RAPL_PWR_UNIT: 0x000a1003 (0.125000 Watts, 0.000015 Joules, 0.000977 sec.)

	[root@host]# echo $?
	243

Commit 9972d5d84d76982606806b2ce887f70c2f8ba60a introduced the RAPL display but broke the AMD F17h support with :
	if (do_rapl & RAPL_AMD_F17H) {
-		if (get_msr(cpu, MSR_PKG_ENERGY_STAT, &msr))
+		if (get_msr_sum(cpu, MSR_PKG_ENERGY_STAT, &msr))
 			return -13;

On RAPL_AMD_F17H capable systems, get_msr_sum() is called with MSR_PKG_ENERGY_STAT.

get_msr_sum() was added by commit 87e15da95775a2ffb8c444e84f08ca982b758364 but didn't
added MSR_PKG_ENERGY_STAT as a supported value.
The very close naming between MSR_PKG_ENERGY_STATUS and MSR_PKG_ENERGY_STAT is probably the reason of this miss.

As a result, when get_msr_sum() is called, offset_to_idx() doesn't have
a case statement for this MSR and returns a negative value. turbostat
exits with an error value.

This patch adds the support of MSR_PKG_ENERGY_STAT.
As IDX_PKG_ENERGY was linked to MSR_PKG_ENERGY_STATUS (Intel),
IDX_PKG_ENERGY_AMD is now linked with MSR_PKG_ENERGY_STAT (AMD).

This patch was tested successfully on a AMD 7502P and restore a fully functional turbostat.
model : AMD EPYC 7502P 32-Core Processor
Vendor: 23 (0x17)
Model : 49 (0x31)

Signed-off-by: Erwan Velu <e.velu@criteo.com>
---
 tools/power/x86/turbostat/turbostat.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 389ea5209a83..9ad3447dd439 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -273,6 +273,7 @@  enum {
 	IDX_PP1_ENERGY,
 	IDX_PKG_PERF,
 	IDX_DRAM_PERF,
+	IDX_PKG_ENERGY_AMD,
 	IDX_COUNT,
 };
 
@@ -314,6 +315,9 @@  int idx_to_offset(int idx)
 	case IDX_DRAM_PERF:
 		offset = MSR_DRAM_PERF_STATUS;
 		break;
+	case IDX_PKG_ENERGY_AMD:
+		offset = MSR_PKG_ENERGY_STAT;
+		break;
 	default:
 		offset = -1;
 	}
@@ -343,6 +347,9 @@  int offset_to_idx(int offset)
 	case MSR_DRAM_PERF_STATUS:
 		idx = IDX_DRAM_PERF;
 		break;
+	case MSR_PKG_ENERGY_STAT:
+		idx = IDX_PKG_ENERGY_AMD;
+		break;
 	default:
 		idx = -1;
 	}
@@ -364,6 +371,8 @@  int idx_valid(int idx)
 		return do_rapl & RAPL_PKG_PERF_STATUS;
 	case IDX_DRAM_PERF:
 		return do_rapl & RAPL_DRAM_PERF_STATUS;
+	case IDX_PKG_ENERGY_AMD:
+		return do_rapl & RAPL_AMD_F17H;
 	default:
 		return 0;
 	}