From ca44cbb3d90585253c795e756bd29ada9c5641bc Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Mon, 20 May 2019 12:41:48 -0500 Subject: [PATCH] Revert to SystemClockCounter for HSA system time. CPUClockCounter is not NTP adjusted (CLOCK_MONOTONIC_RAW) so should be better for measurements. However, it is implemented with syscall while CLOCK_MONOTONIC is implemented via vDSO. The latency increase becomes significant when language layers make corresponding clock measurements. Reverting to CLOCK_MONOTONIC will reduce latency and allow small duration events to be measured at the cost of incorporating NTP frequency skew errors. NTP may adjust frequency by 500ppm so limits us to ~3 decimals in elapsed time. Change-Id: I920b9f707f47109d80d6c256c475638c03fb8d76 [ROCm/ROCR-Runtime commit: 4b22d243461efe4e77dbe86743984a4163e20902] --- .../runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 10 +++++----- .../runtime/hsa-runtime/core/runtime/runtime.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 83bdd71341..9706ca07b7 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -1095,25 +1095,25 @@ uint64_t GpuAgent::TranslateTime(uint64_t tick) { if ((t1_.GPUClockCounter < tick) || (t1_.GPUClockCounter == t0_.GPUClockCounter)) SyncClocks(); // Good for ~300 yrs - // uint64_t sysdelta = t1_.CPUClockCounter - t0_.CPUClockCounter; + // uint64_t sysdelta = t1_.SystemClockCounter - t0_.SystemClockCounter; // uint64_t gpudelta = t1_.GPUClockCounter - t0_.GPUClockCounter; // int64_t offtick = int64_t(tick - t1_.GPUClockCounter); //__int128 num = __int128(sysdelta)*__int128(offtick) + - //__int128(gpudelta)*__int128(t1_.CPUClockCounter); + //__int128(gpudelta)*__int128(t1_.SystemClockCounter); //__int128 sysLarge = num / __int128(gpudelta); // return sysLarge; // Good for ~3.5 months. uint64_t system_tick = 0; - double ratio = double(t1_.CPUClockCounter - t0_.CPUClockCounter) / + double ratio = double(t1_.SystemClockCounter - t0_.SystemClockCounter) / double(t1_.GPUClockCounter - t0_.GPUClockCounter); - system_tick = uint64_t(ratio * double(int64_t(tick - t1_.GPUClockCounter))) + t1_.CPUClockCounter; + system_tick = uint64_t(ratio * double(int64_t(tick - t1_.GPUClockCounter))) + t1_.SystemClockCounter; // tick predates HSA startup - extrapolate with fixed clock ratio if (tick < t0_.GPUClockCounter) { if (historical_clock_ratio_ == 0.0) historical_clock_ratio_ = ratio; system_tick = uint64_t(historical_clock_ratio_ * double(int64_t(tick - t0_.GPUClockCounter))) + - t0_.CPUClockCounter; + t0_.SystemClockCounter; } return system_tick; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index 0448a28439..d48964245c 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -509,7 +509,7 @@ hsa_status_t Runtime::GetSystemInfo(hsa_system_info_t attribute, void* value) { case HSA_SYSTEM_INFO_TIMESTAMP: { HsaClockCounters clocks; hsaKmtGetClockCounters(0, &clocks); - *((uint64_t*)value) = clocks.CPUClockCounter; + *((uint64_t*)value) = clocks.SystemClockCounter; break; } case HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY: {