Index: qemu/vl.c @@ -596,8 +596,43 @@ #endif } +uint64_t get_tps_from_proc() +{ + FILE *fp; + char buf[30]; + double cpu_mhz; + + if (!(fp = fopen("/proc/cpuinfo", "r"))) + return 0; + + /* find wanted line */ + while (fgets(buf, 30, fp) != NULL) + if (!strncmp(buf, "cpu MHz", 7)) + break; + + /* line not found? */ + if (feof(fp)) { + fclose(fp); + return 0; + } + fclose(fp); + + /* put 'cpu MHz' value into cpu_mhz */ + if (!sscanf(&buf[9], ": %lf", &cpu_mhz)) + return 0; + + /* return estimated ticks/sec value */ + return (uint64_t)(cpu_mhz * 1000000.0); +} + void cpu_calibrate_ticks(void) { + if (!(ticks_per_sec = get_tps_from_proc())) + fprintf(stderr, "Could not obtain ticks/sec. from /proc/cpuinfo\n \ + resorting to regular method (tsc)\n"); + else /* value obtained, skip below */ + return; + int64_t usec, ticks; usec = get_clock();