Skip to content

Commit e52966c

Browse files
committed
tools/power turbostat: prevent infinite loop on migration error path
Turbostat assumed if it can't migrate to a CPU, then the CPU must have gone off-line and turbostat should re-initialize with the new topology. But if turbostat can not migrate because it is restricted by a cpuset, then it will fail to migrate even after re-initialization, resulting in an infinite loop. Spit out a warning when we can't migrate and endure only 2 re-initialize cycles in a row before giving up and exiting. Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 3fc808a commit e52966c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,10 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
656656
{
657657
int cpu = t->cpu_id;
658658

659-
if (cpu_migrate(cpu))
659+
if (cpu_migrate(cpu)) {
660+
fprintf(stderr, "Could not migrate to CPU %d\n", cpu);
660661
return -1;
662+
}
661663

662664
t->tsc = rdtsc(); /* we are running on local CPU of interest */
663665

@@ -1088,15 +1090,22 @@ int mark_cpu_present(int cpu)
10881090
void turbostat_loop()
10891091
{
10901092
int retval;
1093+
int restarted = 0;
10911094

10921095
restart:
1096+
restarted++;
1097+
10931098
retval = for_all_cpus(get_counters, EVEN_COUNTERS);
10941099
if (retval < -1) {
10951100
exit(retval);
10961101
} else if (retval == -1) {
1102+
if (restarted > 1) {
1103+
exit(retval);
1104+
}
10971105
re_initialize();
10981106
goto restart;
10991107
}
1108+
restarted = 0;
11001109
gettimeofday(&tv_even, (struct timezone *)NULL);
11011110

11021111
while (1) {

0 commit comments

Comments
 (0)