]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - tools/power/x86/turbostat/turbostat.c
tools/power turbostat: prevent infinite loop on migration error path
[karo-tx-linux.git] / tools / power / x86 / turbostat / turbostat.c
index 3c063a00f3bf46f214b94fb8e5c30d525cb6dfe7..77e76b11382fed14a18af16e2313a4446d4cf9f4 100644 (file)
@@ -656,8 +656,10 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 {
        int cpu = t->cpu_id;
 
-       if (cpu_migrate(cpu))
+       if (cpu_migrate(cpu)) {
+               fprintf(stderr, "Could not migrate to CPU %d\n", cpu);
                return -1;
+       }
 
        t->tsc = rdtsc();       /* we are running on local CPU of interest */
 
@@ -1088,15 +1090,22 @@ int mark_cpu_present(int cpu)
 void turbostat_loop()
 {
        int retval;
+       int restarted = 0;
 
 restart:
+       restarted++;
+
        retval = for_all_cpus(get_counters, EVEN_COUNTERS);
        if (retval < -1) {
                exit(retval);
        } else if (retval == -1) {
+               if (restarted > 1) {
+                       exit(retval);
+               }
                re_initialize();
                goto restart;
        }
+       restarted = 0;
        gettimeofday(&tv_even, (struct timezone *)NULL);
 
        while (1) {