diff mbox series

[RFC] tools/power turbostat: Fix ACPI CState format issue

Message ID 20201012100205.2750-1-yu.c.chen@intel.com (mailing list archive)
State New, archived
Delegated to: Len Brown
Headers show
Series [RFC] tools/power turbostat: Fix ACPI CState format issue | expand

Commit Message

Chen Yu Oct. 12, 2020, 10:02 a.m. UTC
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(-)

Comments

Len Brown May 4, 2021, 10:56 p.m. UTC | #1
On Mon, Oct 12, 2020 at 6:00 AM Chen Yu <yu.c.chen@intel.com> wrote:
>
> 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

Let's shorten the header fields so that a single tab continues to work.
this is helpful for processing turbostat output in .TSV format.

thx
Chen Yu May 5, 2021, 3:09 a.m. UTC | #2
On Tue, May 04, 2021 at 06:56:00PM -0400, Len Brown wrote:
> On Mon, Oct 12, 2020 at 6:00 AM Chen Yu <yu.c.chen@intel.com> wrote:
> >
> > 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
> 
> Let's shorten the header fields so that a single tab continues to work.
> this is helpful for processing turbostat output in .TSV format.
>
Okay. BTW it looks like the following patch has already fixed the _CST format issue
and single tab still works:
commit fecb3bc839df64761cc63c9ee9b45c1cad36aee8
Author: David Arcari <darcari@redhat.com>
Date:   Mon Aug 10 10:43:30 2020 -0400

    tools/power turbostat: Fix output formatting for ACPI CST enumeration

thanks,
Chenyu
diff mbox series

Patch

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);
 		}
 	}