Re: [PATCH 2/3] tools/power turbostat: avoid an infinite loop of restarts
From: David Arcari
Date: Tue Nov 25 2025 - 16:51:49 EST
I see. Perhaps this isn't fixable then. I'll take another look.
-DA
On 11/25/25 2:12 PM, Len Brown wrote:
this patch introduces a limit of 10-restarts per turbostat lifetime,
down from infinity.
some turbostat invocations span multiple uses of cpu online/offline --
so this limit will not fly.
On Tue, Nov 18, 2025 at 10:58 AM David Arcari <darcari@xxxxxxxxxx> wrote:
There are some error cases where turbostat will attempt to reinitialize
by calling the re_initialize() function. The code attempts to avoid
an infinite loop by checking the value of 'restarted' in one case, but
not others. It should be checked in all cases of restart. Additonally,
the 'restarted' is reset to zero at the start of the loop which also
needs to be removed.
Signed-off-by: David Arcari <darcari@xxxxxxxxxx>
Cc: Len Brown <lenb@xxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
tools/power/x86/turbostat/turbostat.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 584b0f7f9067..5567b9ecd516 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -6722,7 +6722,11 @@ void turbostat_loop()
set_my_sched_priority(-20);
restart:
- restarted++;
+ if (restarted++ > 10) {
+ if (!retval)
+ retval = -1;
+ exit(retval);
+ }
snapshot_proc_sysfs_files();
retval = for_all_cpus(get_counters, EVEN_COUNTERS);
@@ -6730,13 +6734,9 @@ void turbostat_loop()
if (retval < -1) {
exit(retval);
} else if (retval == -1) {
- if (restarted > 10) {
- exit(retval);
- }
re_initialize();
goto restart;
}
- restarted = 0;
done_iters = 0;
gettimeofday(&tv_even, (struct timezone *)NULL);
--
2.51.0