* [PATCH 0/3] tools/power turbostat: Fix counter formats and CPU selection docs
@ 2026-11-24 3:27 Qinyun Tan
2026-11-24 3:27 ` [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters Qinyun Tan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Qinyun Tan @ 2026-11-24 3:27 UTC (permalink / raw)
To: lenb; +Cc: michael.hebenstreit, linux-pm, linux-kernel, xlpang, Qinyun Tan
Hi all,
This series fixes three turbostat issues:
1. Preserve current CPU/core perf counter values for the average format.
2. Restore low-32-bit truncation for u32 raw counters.
3. Correct the --cpu documentation: numeric selections restrict
collection and the summary; core and package only filter displayed rows.
Thanks,
Qinyun Tan
Qinyun Tan (3):
tools/power turbostat: Fix average format for CPU/core perf counters
tools/power turbostat: Restore u32 truncation for raw counters
tools/power turbostat: Fix --cpu summary description
tools/power/x86/turbostat/turbostat.8 | 4 ++--
tools/power/x86/turbostat/turbostat.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters 2026-11-24 3:27 [PATCH 0/3] tools/power turbostat: Fix counter formats and CPU selection docs Qinyun Tan @ 2026-11-24 3:27 ` Qinyun Tan 2026-11-27 5:53 ` Zhang, Rui 2026-11-24 3:27 ` [PATCH 2/3] tools/power turbostat: Restore u32 truncation for raw counters Qinyun Tan 2026-11-24 3:27 ` [PATCH 3/3] tools/power turbostat: Fix --cpu summary description Qinyun Tan 2 siblings, 1 reply; 7+ messages in thread From: Qinyun Tan @ 2026-11-24 3:27 UTC (permalink / raw) To: lenb; +Cc: michael.hebenstreit, linux-pm, linux-kernel, xlpang, Qinyun Tan Perf counters added with the average format report interval deltas at CPU and core scope instead of the latest counter values. Their summary rows consequently average the deltas rather than the counter values. delta_thread() and delta_core() only preserve FORMAT_RAW perf counters. FORMAT_AVERAGE falls through to subtraction before the summary is calculated. Preserve FORMAT_AVERAGE values in both perf counter loops, matching the existing handling in delta_package() and the MSR counter loops. Fixes: dcd1c379b0f1 ("tools/power turbostat: add format "average" for external attributes") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> --- tools/power/x86/turbostat/turbostat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 123078926131..4e7eba8d8752 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -3956,7 +3956,7 @@ void delta_core(struct core_data *new, struct core_data *old) } for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { - if (pp->format == FORMAT_RAW) + if (pp->format == FORMAT_RAW || pp->format == FORMAT_AVERAGE) old->perf_counter[i] = new->perf_counter[i]; else old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; @@ -4079,7 +4079,7 @@ int delta_thread(struct thread_data *new, struct thread_data *old, struct core_d } for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { - if (pp->format == FORMAT_RAW) + if (pp->format == FORMAT_RAW || pp->format == FORMAT_AVERAGE) old->perf_counter[i] = new->perf_counter[i]; else old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; -- 2.55.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters 2026-11-24 3:27 ` [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters Qinyun Tan @ 2026-11-27 5:53 ` Zhang, Rui 0 siblings, 0 replies; 7+ messages in thread From: Zhang, Rui @ 2026-11-27 5:53 UTC (permalink / raw) To: qinyuntan, lenb; +Cc: michael.hebenstreit, linux-pm, xlpang, linux-kernel On Tue, 2026-11-24 at 11:27 +0800, Qinyun Tan wrote: > Perf counters added with the average format report interval deltas at > CPU and core scope instead of the latest counter values. Their > summary > rows consequently average the deltas rather than the counter values. > > delta_thread() and delta_core() only preserve FORMAT_RAW perf > counters. > FORMAT_AVERAGE falls through to subtraction before the summary is > calculated. > > Preserve FORMAT_AVERAGE values in both perf counter loops, matching > the > existing handling in delta_package() and the MSR counter loops. > > Fixes: dcd1c379b0f1 ("tools/power turbostat: add format "average" for > external attributes") > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Then what about the PMT counters? This is an interesting finding. It appears to reveal a broader inconsistency in RAW/AVERAGE handling across the regular, perf and PMT counter loops in delta_package(), delta_core() and delta_thread(). Len, is there any intentional reason for FORMAT_AVERAGE perf or PMT counters to undergo subtraction? or we didnt assume they exist? If no source-specific handling is needed here, could we use a common macro for the preserve-versus-subtract operation? That would simplify these loops and keep their format handling consistent: #define UPDATE_COUNTER(ptr, i, member) \ do { \ if ((ptr)->format == FORMAT_RAW || \ (ptr)->format == FORMAT_AVERAGE) \ old->member[i] = new->member[i]; \ else \ old->member[i] = new->member[i] - old->member[i]; \ } while (0) The callers would use UPDATE_COUNTER(mp, i, counter), UPDATE_COUNTER(pp, i, perf_counter) and UPDATE_COUNTER(ppmt, i, pmt_counter), retaining any counter-specific processing around them. thanks, rui > --- > tools/power/x86/turbostat/turbostat.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/power/x86/turbostat/turbostat.c > b/tools/power/x86/turbostat/turbostat.c > index 123078926131..4e7eba8d8752 100644 > --- a/tools/power/x86/turbostat/turbostat.c > +++ b/tools/power/x86/turbostat/turbostat.c > @@ -3956,7 +3956,7 @@ void delta_core(struct core_data *new, struct > core_data *old) > } > > for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { > - if (pp->format == FORMAT_RAW) > + if (pp->format == FORMAT_RAW || pp->format == > FORMAT_AVERAGE) > old->perf_counter[i] = new->perf_counter[i]; > else > old->perf_counter[i] = new->perf_counter[i] > - old->perf_counter[i]; > @@ -4079,7 +4079,7 @@ int delta_thread(struct thread_data *new, > struct thread_data *old, struct core_d > } > > for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { > - if (pp->format == FORMAT_RAW) > + if (pp->format == FORMAT_RAW || pp->format == > FORMAT_AVERAGE) > old->perf_counter[i] = new->perf_counter[i]; > else > old->perf_counter[i] = new->perf_counter[i] > - old->perf_counter[i]; ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] tools/power turbostat: Restore u32 truncation for raw counters 2026-11-24 3:27 [PATCH 0/3] tools/power turbostat: Fix counter formats and CPU selection docs Qinyun Tan 2026-11-24 3:27 ` [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters Qinyun Tan @ 2026-11-24 3:27 ` Qinyun Tan 2026-11-27 5:54 ` Zhang, Rui 2026-11-24 3:27 ` [PATCH 3/3] tools/power turbostat: Fix --cpu summary description Qinyun Tan 2 siblings, 1 reply; 7+ messages in thread From: Qinyun Tan @ 2026-11-24 3:27 UTC (permalink / raw) To: lenb; +Cc: michael.hebenstreit, linux-pm, linux-kernel, xlpang, Qinyun Tan The u32 size option truncates raw counter values to 32 bits for display. However, print_hex_value() now prints the full value even when the width is 32 bits. For example, 0x000000edc994ba0d is printed as edc994ba0d instead of c994ba0d. The print helper cleanup replaced %08x and the unsigned int cast with %08llx. The field width is a minimum, so it does not truncate values that need more than eight hexadecimal digits. The cast was needed to discard the upper 32 bits. Restore the cast and %08x for raw counters up to 32 bits wide. Leave 64-bit raw values and decimal counter formatting unchanged. Fixes: 092b76a3253f ("tools/power turbostat: Cleanup print helper functions") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> --- tools/power/x86/turbostat/turbostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 4e7eba8d8752..d0f0b4af6094 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -2906,7 +2906,7 @@ static inline int print_hex_value(int width, int *printed, char *delim, unsigned char *sep = (*printed)++ ? delim : ""; if (width <= 32) - return sprintf(outp, "%s%08llx", sep, value); + return sprintf(outp, "%s%08x", sep, (unsigned int)value); else return sprintf(outp, "%s%016llx", sep, value); } -- 2.55.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] tools/power turbostat: Restore u32 truncation for raw counters 2026-11-24 3:27 ` [PATCH 2/3] tools/power turbostat: Restore u32 truncation for raw counters Qinyun Tan @ 2026-11-27 5:54 ` Zhang, Rui 0 siblings, 0 replies; 7+ messages in thread From: Zhang, Rui @ 2026-11-27 5:54 UTC (permalink / raw) To: qinyuntan, lenb; +Cc: michael.hebenstreit, linux-pm, xlpang, linux-kernel On Tue, 2026-11-24 at 11:27 +0800, Qinyun Tan wrote: > The u32 size option truncates raw counter values to 32 bits for > display. > However, print_hex_value() now prints the full value even when the > width > is 32 bits. For example, 0x000000edc994ba0d is printed as edc994ba0d > instead of c994ba0d. > > The print helper cleanup replaced %08x and the unsigned int cast with > %08llx. The field width is a minimum, so it does not truncate values > that need more than eight hexadecimal digits. The cast was needed to > discard the upper 32 bits. > > Restore the cast and %08x for raw counters up to 32 bits wide. Leave > 64-bit raw values and decimal counter formatting unchanged. > > Fixes: 092b76a3253f ("tools/power turbostat: Cleanup print helper > functions") > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Acked-by: Zhang Rui <rui.zhang@intel.com> -rui > --- > tools/power/x86/turbostat/turbostat.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/power/x86/turbostat/turbostat.c > b/tools/power/x86/turbostat/turbostat.c > index 4e7eba8d8752..d0f0b4af6094 100644 > --- a/tools/power/x86/turbostat/turbostat.c > +++ b/tools/power/x86/turbostat/turbostat.c > @@ -2906,7 +2906,7 @@ static inline int print_hex_value(int width, > int *printed, char *delim, unsigned > char *sep = (*printed)++ ? delim : ""; > > if (width <= 32) > - return sprintf(outp, "%s%08llx", sep, value); > + return sprintf(outp, "%s%08x", sep, (unsigned > int)value); > else > return sprintf(outp, "%s%016llx", sep, value); > } ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] tools/power turbostat: Fix --cpu summary description 2026-11-24 3:27 [PATCH 0/3] tools/power turbostat: Fix counter formats and CPU selection docs Qinyun Tan 2026-11-24 3:27 ` [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters Qinyun Tan 2026-11-24 3:27 ` [PATCH 2/3] tools/power turbostat: Restore u32 truncation for raw counters Qinyun Tan @ 2026-11-24 3:27 ` Qinyun Tan 2026-11-27 5:55 ` Zhang, Rui 2 siblings, 1 reply; 7+ messages in thread From: Qinyun Tan @ 2026-11-24 3:27 UTC (permalink / raw) To: lenb; +Cc: michael.hebenstreit, linux-pm, linux-kernel, xlpang, Qinyun Tan The man page states that --cpu only filters output and that the summary always includes all CPUs. Numeric CPU selections also restrict counter collection and the summary, while core and package only filter displayed rows. Correct the option and row descriptions to match this behavior. Fixes: 0fe375290137 ("tools/power/turbostat: Obey allowed CPUs for system summary") Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> --- tools/power/x86/turbostat/turbostat.8 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8 index c905198d0501..c2b86d20db95 100644 --- a/tools/power/x86/turbostat/turbostat.8 +++ b/tools/power/x86/turbostat/turbostat.8 @@ -92,7 +92,7 @@ name as necessary to disambiguate it from others is necessary. Note that option '%x' hex identifier of the PMT MMIO region. .fi .PP -\fB--cpu cpu-set\fP limit output to system summary plus the specified cpu-set. If cpu-set is the string "core", then the system summary plus the first CPU in each core are printed -- eg. subsequent HT siblings are not printed. Or if cpu-set is the string "package", then the system summary plus the first CPU in each package is printed. Otherwise, the system summary plus the specified set of CPUs are printed. The cpu-set is ordered from low to high, comma delimited with ".." and "-" permitted to denote a range. eg. 1,2,8,14..17,21-44 Multiple invocations of --cpu are OR'd together. +\fB--cpu cpu-set\fP select CPUs to monitor or limit the rows displayed. If cpu-set is the string "core", then the system summary plus the first CPU in each core are printed -- eg. subsequent HT siblings are not printed. Or if cpu-set is the string "package", then the system summary plus the first CPU in each package is printed. Otherwise, counter collection, output and the system summary are restricted to the specified set of CPUs. The cpu-set is ordered from low to high, comma delimited with ".." and "-" permitted to denote a range. eg. 1,2,8,14..17,21-44 Multiple invocations of --cpu are OR'd together. .PP \fB--hide column\fP do not show the specified built-in columns. May be invoked multiple times, or with a comma-separated list of column names. .PP @@ -138,7 +138,7 @@ The \fBcommand\fP parameter forks \fBcommand\fP, and upon its exit, displays the statistics gathered since it was forked. .PP .SH ROW DESCRIPTIONS -The system configuration dump (if --quiet is not used) is followed by statistics. The first row of the statistics labels the content of each column (below). The second row of statistics is the system summary line. The system summary line has a '-' in the columns for the Package, Core, and CPU. The contents of the system summary line depends on the type of column. Columns that count items (eg. IRQ) show the sum across all CPUs in the system. Columns that show a percentage show the average across all CPUs in the system. Columns that dump raw MSR values simply show 0 in the summary. After the system summary row, each row describes a specific Package/Core/CPU. Note that if the --cpu parameter is used to limit which specific CPUs are displayed, turbostat will still collect statistics for all CPUs in the system and will still show the system summary for all CPUs in the system. +The system configuration dump (if --quiet is not used) is followed by statistics. The first row of the statistics labels the content of each column (below). The second row of statistics is the system summary line. The system summary line has a '-' in the columns for the Package, Core, and CPU. The contents of the system summary line depends on the type of column. Columns that count items (eg. IRQ) show the sum across the monitored CPUs. Columns that show a percentage show the average across the monitored CPUs. Columns that dump raw MSR values simply show 0 in the summary. After the system summary row, each row describes a specific Package/Core/CPU. The system summary covers the CPUs being monitored; see --cpu for CPU selection. .SH COLUMN DESCRIPTIONS .PP \fBusec\fP For each CPU, the number of microseconds elapsed during counter collection, including thread migration -- if any. This counter is disabled by default, and is enabled with "--enable usec", or --debug. On the summary row, usec refers to the total elapsed time to snapshot the procfs/sysfs and collect the counters on all cpus. -- 2.55.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] tools/power turbostat: Fix --cpu summary description 2026-11-24 3:27 ` [PATCH 3/3] tools/power turbostat: Fix --cpu summary description Qinyun Tan @ 2026-11-27 5:55 ` Zhang, Rui 0 siblings, 0 replies; 7+ messages in thread From: Zhang, Rui @ 2026-11-27 5:55 UTC (permalink / raw) To: qinyuntan, lenb; +Cc: michael.hebenstreit, linux-pm, xlpang, linux-kernel On Tue, 2026-11-24 at 11:27 +0800, Qinyun Tan wrote: > The man page states that --cpu only filters output and that the > summary > always includes all CPUs. Numeric CPU selections also restrict > counter > collection and the summary, while core and package only filter > displayed > rows. > > Correct the option and row descriptions to match this behavior. > > Fixes: 0fe375290137 ("tools/power/turbostat: Obey allowed CPUs for > system summary") > Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com> Acked-by: Zhang Rui <rui.zhang@intel.com> -rui > --- > tools/power/x86/turbostat/turbostat.8 | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/power/x86/turbostat/turbostat.8 > b/tools/power/x86/turbostat/turbostat.8 > index c905198d0501..c2b86d20db95 100644 > --- a/tools/power/x86/turbostat/turbostat.8 > +++ b/tools/power/x86/turbostat/turbostat.8 > @@ -92,7 +92,7 @@ name as necessary to disambiguate it from others is > necessary. Note that option > '%x' hex identifier of the PMT MMIO region. > .fi > .PP > -\fB--cpu cpu-set\fP limit output to system summary plus the > specified cpu-set. If cpu-set is the string "core", then the system > summary plus the first CPU in each core are printed -- eg. subsequent > HT siblings are not printed. Or if cpu-set is the string "package", > then the system summary plus the first CPU in each package is > printed. Otherwise, the system summary plus the specified set of > CPUs are printed. The cpu-set is ordered from low to high, comma > delimited with ".." and "-" permitted to denote a range. eg. > 1,2,8,14..17,21-44 Multiple invocations of --cpu are OR'd together. > +\fB--cpu cpu-set\fP select CPUs to monitor or limit the rows > displayed. If cpu-set is the string "core", then the system summary > plus the first CPU in each core are printed -- eg. subsequent HT > siblings are not printed. Or if cpu-set is the string "package", > then the system summary plus the first CPU in each package is > printed. Otherwise, counter collection, output and the system > summary are restricted to the specified set of CPUs. The cpu-set is > ordered from low to high, comma delimited with ".." and "-" permitted > to denote a range. eg. 1,2,8,14..17,21-44 Multiple invocations of -- > cpu are OR'd together. > .PP > \fB--hide column\fP do not show the specified built-in columns. May > be invoked multiple times, or with a comma-separated list of column > names. > .PP > @@ -138,7 +138,7 @@ The \fBcommand\fP parameter forks \fBcommand\fP, > and upon its exit, > displays the statistics gathered since it was forked. > .PP > .SH ROW DESCRIPTIONS > -The system configuration dump (if --quiet is not used) is followed > by statistics. The first row of the statistics labels the content of > each column (below). The second row of statistics is the system > summary line. The system summary line has a '-' in the columns for > the Package, Core, and CPU. The contents of the system summary line > depends on the type of column. Columns that count items (eg. IRQ) > show the sum across all CPUs in the system. Columns that show a > percentage show the average across all CPUs in the system. Columns > that dump raw MSR values simply show 0 in the summary. After the > system summary row, each row describes a specific Package/Core/CPU. > Note that if the --cpu parameter is used to limit which specific CPUs > are displayed, turbostat will still collect statistics for all CPUs > in the system and will still show the system summary for all CPUs in > the system. > +The system configuration dump (if --quiet is not used) is followed > by statistics. The first row of the statistics labels the content of > each column (below). The second row of statistics is the system > summary line. The system summary line has a '-' in the columns for > the Package, Core, and CPU. The contents of the system summary line > depends on the type of column. Columns that count items (eg. IRQ) > show the sum across the monitored CPUs. Columns that show a > percentage show the average across the monitored CPUs. Columns that > dump raw MSR values simply show 0 in the summary. After the system > summary row, each row describes a specific Package/Core/CPU. The > system summary covers the CPUs being monitored; see --cpu for CPU > selection. > .SH COLUMN DESCRIPTIONS > .PP > \fBusec\fP For each CPU, the number of microseconds elapsed during > counter collection, including thread migration -- if any. This > counter is disabled by default, and is enabled with "--enable usec", > or --debug. On the summary row, usec refers to the total elapsed > time to snapshot the procfs/sysfs and collect the counters on all > cpus. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-27 5:55 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-24 3:27 [PATCH 0/3] tools/power turbostat: Fix counter formats and CPU selection docs Qinyun Tan 2026-11-24 3:27 ` [PATCH 1/3] tools/power turbostat: Fix average format for CPU/core perf counters Qinyun Tan 2026-11-27 5:53 ` Zhang, Rui 2026-11-24 3:27 ` [PATCH 2/3] tools/power turbostat: Restore u32 truncation for raw counters Qinyun Tan 2026-11-27 5:54 ` Zhang, Rui 2026-11-24 3:27 ` [PATCH 3/3] tools/power turbostat: Fix --cpu summary description Qinyun Tan 2026-11-27 5:55 ` Zhang, Rui
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®