All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: Len Brown <lenb@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Zhang Rui <rui.zhang@intel.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chen Yu <yu.c.chen@intel.com>
Subject: [PATCH][RFC] tools/power turbostat: Fix ACPI CState format issue
Date: Mon, 12 Oct 2020 18:02:05 +0800	[thread overview]
Message-ID: <20201012100205.2750-1-yu.c.chen@intel.com> (raw)

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


             reply	other threads:[~2020-10-12 10:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 10:02 Chen Yu [this message]
2021-05-04 22:56 ` [PATCH][RFC] tools/power turbostat: Fix ACPI CState format issue Len Brown
2021-05-05  3:09   ` Chen Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201012100205.2750-1-yu.c.chen@intel.com \
    --to=yu.c.chen@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.