Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 64165: Fix RDTSC calibration #65

Merged
merged 1 commit into from Dec 24, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions extension/xhprof.c
Expand Up @@ -1360,23 +1360,24 @@ static double get_cpu_frequency() {
struct timeval end;
uint64 tsc_start;
uint64 tsc_end;
volatile int i;

if (gettimeofday(&start, 0)) {
perror("gettimeofday");
return 0.0;
}

tsc_start = cycle_timer();

/* Sleep for 5 miliseconds. Comparaing with gettimeofday's few microseconds
* execution time, this should be enough. */
usleep(5000);
if (gettimeofday(&end, 0)) {
perror("gettimeofday");
return 0.0;
}
tsc_start = cycle_timer();

tsc_end = cycle_timer();
/* Busy loop for 5 miliseconds. */
do {
for (i = 0; i < 1000000; i++);
if (gettimeofday(&end, 0)) {
perror("gettimeofday");
return 0.0;
}
tsc_end = cycle_timer();
} while (get_us_interval(&start, &end) < 5000);

return (tsc_end - tsc_start) * 1.0 / (get_us_interval(&start, &end));
}
Expand Down