Correct handling of slow clocks under linux.

Change-Id: I9a1b08d5457caa6739220603bbd37b00febc64d7


[ROCm/ROCR-Runtime commit: 29b5b5c029]
This commit is contained in:
Sean Keely
2017-07-11 18:24:42 -05:00
committed by JamesAdrian Edwards
orang tua 19f96afee1
melakukan 17d0e450cb
2 mengubah file dengan 8 tambahan dan 2 penghapusan
@@ -322,11 +322,14 @@ int ResetOsEvent(EventHandle event) {
return ret_code;
}
static double invPeriod = 0.0;
uint64_t ReadAccurateClock() {
if (invPeriod == 0.0) AccurateClockFrequency();
timespec time;
int err = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
assert(err == 0 && "clock_gettime(CLOCK_MONOTONIC_RAW,...) failed");
return uint64_t(time.tv_sec) * 1000000000ull + uint64_t(time.tv_nsec);
return (uint64_t(time.tv_sec) * 1000000000ull + uint64_t(time.tv_nsec)) * invPeriod;
}
uint64_t AccurateClockFrequency() {
@@ -339,7 +342,8 @@ uint64_t AccurateClockFrequency() {
assert(time.tv_nsec < 0xFFFFFFFF &&
"clock_getres(CLOCK_MONOTONIC_RAW,...) returned very low frequency "
"(<1Hz).");
return uint64_t(time.tv_nsec) * 1000000000ull;
if (invPeriod == 0.0) invPeriod = 1.0 / double(time.tv_nsec);
return 1000000000ull / uint64_t(time.tv_nsec);
}
}
@@ -93,6 +93,8 @@ fast_clock::init::init() {
fast_clock::freq = double(min) / duration_in_seconds(elapsed);
fast_clock::period_ps = 1e12 / fast_clock::freq;
// printf("Timer setup took %f ms\n", duration_in_seconds(elapsed)*1000.0f);
// printf("Fast clock frequency: %f MHz\n", double(fast_clock::freq)/1e6);
}
double accurate_clock::period_ns;