linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RFC] tools/power turbostat: Fix ACPI CState format issue
@ 2020-10-12 10:02 Chen Yu
  2021-05-04 22:56 ` Len Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Yu @ 2020-10-12 10:02 UTC (permalink / raw)
  To: Len Brown; +Cc: Rafael J. Wysocki, Zhang Rui, linux-pm, linux-kernel, Chen Yu

Currently if the system boots with BIOS _CST Cstate information
enabled, the turbostat output would have unaligned problems:

C1_ACPI C2_ACPI C3_ACPI POLL%   C1_ACPI%        C2_ACPI%        C3_ACPI%        CPU%c1
5       37      138     0.00    0.02    1.30    98.51   0.38    0.00    0.00    99.43

The C1_ACPI% is of 8 bytes, so extend the format accordingly if the field name
equals to/longer than 8 bytes.

After the patch applied:

C1_ACPI C2_ACPI C3_ACPI POLL%   C1_ACPI%        C2_ACPI%        C3_ACPI%        CPU%c1
2       42      96      0.00    0.12            2.60            97.09           0.60

Reported-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
 tools/power/x86/turbostat/turbostat.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 33b370865d16..73aa8738ae36 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -664,14 +664,16 @@ void print_header(char *delim)
 		outp += sprintf(outp, "%sSMI", (printed++ ? delim : ""));
 
 	for (mp = sys.tp; mp; mp = mp->next) {
-
+		int name_len = strlen(mp->name);
 		if (mp->format == FORMAT_RAW) {
 			if (mp->width == 64)
 				outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name);
 			else
 				outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name);
 		} else {
-			if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns)
+			if (((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) ||
+				/* Deal with corner case: Cx_ACPI% is of 8 bytes. */
+				((mp->type == COUNTER_USEC) && name_len >= 8))
 				outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name);
 			else
 				outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name);
@@ -1005,6 +1007,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
 
 	/* Added counters */
 	for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) {
+		int name_len = strlen(mp->name);
 		if (mp->format == FORMAT_RAW) {
 			if (mp->width == 32)
 				outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]);
@@ -1016,9 +1019,13 @@ int format_counters(struct thread_data *t, struct core_data *c,
 			else
 				outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]);
 		} else if (mp->format == FORMAT_PERCENT) {
-			if (mp->type == COUNTER_USEC)
-				outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000);
-			else
+			if (mp->type == COUNTER_USEC) {
+				/* Deal with corner case: Cx_ACPI% is of 8 bytes. */
+				if (name_len >= 8)
+					outp += sprintf(outp, "%s%-8.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000);
+				else
+					outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000);
+			} else
 				outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i]/tsc);
 		}
 	}
-- 
2.25.1


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

end of thread, other threads:[~2021-05-05  3:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-12 10:02 [PATCH][RFC] tools/power turbostat: Fix ACPI CState format issue Chen Yu
2021-05-04 22:56 ` Len Brown
2021-05-05  3:09   ` Chen Yu

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).