tools/power turbostat: Fix ACPI CState format issue
RFC PATCH 1/1 tools/power turbostat: Fix ACPI CState format issue
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
--- tools/power/x86/turbostat/turbostat.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
tools/power/x86/turbostat/turbostat.c +12 -5
@@ -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); } }
Signature · 1 line
2.25.1
Len Brown
maintainerQuoted 7 lines · Chen Yu
Currently if the system boots with BIOS
_CSTCstate 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
Quoted 7 lines
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
Quoted 11 lines · Len Brown
Quoted 10 lines · Chen Yu
Currently if the system boots with BIOS
_CSTCstate 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.43The C1_ACPI% is of 8 bytes, so extend the format accordingly if the field name equals to/longer than 8 bytes.
Quoted 8 lines
Quoted 4 lines
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.60Let'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 <[email protected]> Date: Mon Aug 10 10:43:30 2020 -0400
tools/power turbostat: Fix output formatting for ACPI CST enumeration
thanks,
Chenyu