linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tools/power turbostat: Fix RAPL summary collection on AMD processors
@ 2021-04-19 19:58 Terry Bowman
  2021-04-19 23:52 ` calvin.walton
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Terry Bowman @ 2021-04-19 19:58 UTC (permalink / raw)
  To: lenb, yu.c.chen, linux-pm, linux-kernel, bp, calvin.walton
  Cc: terry.bowman, wei.huang2

Turbostat fails to correctly collect and display RAPL summary information
on Family 17h and 19h AMD processors. Running turbostat on these processors
returns immediately. If turbostat is working correctly then RAPL summary
data is displayed until the user provided command completes. If a command
is not provided by the user then turbostat is designed to continuously
display RAPL information until interrupted.

The issue is due to offset_to_idx() and idx_to_offset() missing support for
AMD MSR addresses/offsets. offset_to_idx()'s switch statement is missing
cases for AMD MSRs and idx_to_offset() does not include a path to return
AMD MSR(s) for any idx.

The solution is add AMD MSR support to offset_to_idx() and idx_to_offset().
These functions are split-out and renamed along architecture vendor lines
for supporting both AMD and Intel MSRs.

Fixes: 9972d5d84d76 ("tools/power turbostat: Enable accumulate RAPL display")
Signed-off-by: Terry Bowman <terry.bowman@amd.com>
---
Changes in V2:
  - Set patch title to v2. The first patch submission was mistakenly titled as
  v4 when it should have been v1.
  - Change offset variables from 'int' to 'off_t' type. Change is needed
  to prevent sign extension in code casting int->off_t. This is currently a
  problem with AMD MSRs using base of 0xC000_0000
  - Update idx_valid_amd() capability masking to use RAPL_AMD_F17H

 tools/power/x86/turbostat/turbostat.c | 63 ++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 6 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index a7c4f0772e53..5aacdbd28fa8 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -291,9 +291,9 @@ struct msr_sum_array {
 /* The percpu MSR sum array.*/
 struct msr_sum_array *per_cpu_msr_sum;
 
-int idx_to_offset(int idx)
+off_t idx_to_offset_intel(int idx)
 {
-	int offset;
+	off_t offset;
 
 	switch (idx) {
 	case IDX_PKG_ENERGY:
@@ -320,7 +320,7 @@ int idx_to_offset(int idx)
 	return offset;
 }
 
-int offset_to_idx(int offset)
+int offset_to_idx_intel(off_t offset)
 {
 	int idx;
 
@@ -349,7 +349,7 @@ int offset_to_idx(int offset)
 	return idx;
 }
 
-int idx_valid(int idx)
+int idx_valid_intel(int idx)
 {
 	switch (idx) {
 	case IDX_PKG_ENERGY:
@@ -368,6 +368,51 @@ int idx_valid(int idx)
 		return 0;
 	}
 }
+
+off_t (*idx_to_offset)(int idx) = idx_to_offset_intel;
+int (*offset_to_idx)(off_t offset) = offset_to_idx_intel;
+int (*idx_valid)(int idx) = idx_valid_intel;
+
+off_t idx_to_offset_amd(int idx)
+{
+	off_t offset;
+
+	switch (idx) {
+	case IDX_PKG_ENERGY:
+		offset = MSR_PKG_ENERGY_STAT;
+		break;
+	default:
+		offset = -1;
+	}
+
+	return offset;
+}
+
+int offset_to_idx_amd(off_t offset)
+{
+	int idx;
+
+	switch (offset) {
+	case MSR_PKG_ENERGY_STAT:
+		idx = IDX_PKG_ENERGY;
+		break;
+	default:
+		idx = -1;
+	}
+
+	return idx;
+}
+
+int idx_valid_amd(int idx)
+{
+	switch (idx) {
+	case IDX_PKG_ENERGY:
+		return do_rapl & RAPL_AMD_F17H;
+	default:
+		return 0;
+	}
+}
+
 struct sys_counters {
 	unsigned int added_thread_counters;
 	unsigned int added_core_counters;
@@ -3272,7 +3317,7 @@ static int update_msr_sum(struct thread_data *t, struct core_data *c, struct pkg
 
 	for (i = IDX_PKG_ENERGY; i < IDX_COUNT; i++) {
 		unsigned long long msr_cur, msr_last;
-		int offset;
+		off_t offset;
 
 		if (!idx_valid(i))
 			continue;
@@ -3281,7 +3326,7 @@ static int update_msr_sum(struct thread_data *t, struct core_data *c, struct pkg
 			continue;
 		ret = get_msr(cpu, offset, &msr_cur);
 		if (ret) {
-			fprintf(outf, "Can not update msr(0x%x)\n", offset);
+			fprintf(outf, "Can not update msr(0x%lx)\n", offset);
 			continue;
 		}
 
@@ -5348,6 +5393,12 @@ void process_cpuid()
 	if (!quiet)
 		decode_misc_feature_control();
 
+	if (authentic_amd || hygon_genuine) {
+		idx_to_offset = idx_to_offset_amd;
+		offset_to_idx = offset_to_idx_amd;
+		idx_valid = idx_valid_amd;
+	}
+
 	return;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-04-24  1:30 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 19:58 [PATCH v2] tools/power turbostat: Fix RAPL summary collection on AMD processors Terry Bowman
2021-04-19 23:52 ` calvin.walton
2021-04-20  2:03 ` Chen Yu
2021-04-20  8:07   ` Borislav Petkov
2021-04-20 13:15     ` Chen Yu
2021-04-20 13:28       ` Calvin Walton
2021-04-20 14:37         ` Chen Yu
2021-04-20 14:42           ` Calvin Walton
2021-04-23 12:16             ` Chen Yu
2021-04-23 12:19               ` Borislav Petkov
2021-04-23 13:34                 ` Chen Yu
2021-04-23 14:32                   ` Borislav Petkov
2021-04-24  1:14                     ` Chen Yu
2021-04-23 14:00                 ` Calvin Walton
2021-04-23 14:29                   ` Borislav Petkov
2021-04-24  1:34                   ` Chen Yu
2021-04-23 14:04               ` Calvin Walton
2021-04-23 14:27                 ` Chen Yu
2021-04-23 15:17                   ` Calvin Walton
2021-04-20 14:06       ` Artem S. Tashkinov
2021-04-20 15:25       ` Borislav Petkov
2021-04-23 12:18         ` Chen Yu
2021-04-20 13:32 ` Calvin Walton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).