Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug 64165: Fix RDTSC calibration #65

Merged
merged 1 commit into from

2 participants

@tstarling

Do a busy loop instead of usleep(5000), since usleep(5000) causes the
CPU to halt, giving meaningless results.

@tstarling tstarling Bug 64165: Fix RDTSC calibration
Do a busy loop instead of usleep(5000), since usleep(5000) causes the
CPU to halt, giving meaningless results.
ec7631b
@preinheimer preinheimer merged commit 29a77c3 into preinheimer:master
@preinheimer
Owner

thanks, sorry for the stupid delay.

@atdt atdt referenced this pull request in facebook/hhvm
Closed

Fix RDTSC calibration in ext_hotprofiler #1488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @tstarling

    Bug 64165: Fix RDTSC calibration

    tstarling authored
    Do a busy loop instead of usleep(5000), since usleep(5000) causes the
    CPU to halt, giving meaningless results.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 10 deletions.
  1. +11 −10 extension/xhprof.c
View
21 extension/xhprof.c
@@ -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));
}
Something went wrong with that request. Please try again.