Switch to CLOCK_BOOTTIME for HSA system clock.

This is consistent with KFD and has significantly better latency.
KFD is taking this as the definition of the SystemClockCounter.

Change-Id: I4c1b3bc58c738206265c55ebefd41356c013bfe5


[ROCm/ROCR-Runtime commit: 0ee82742a7]
This commit is contained in:
Sean Keely
2022-04-27 20:16:54 -05:00
parent be1d3bef2d
commit 2b8c129efb
4 changed files with 40 additions and 7 deletions
@@ -580,9 +580,7 @@ hsa_status_t Runtime::GetSystemInfo(hsa_system_info_t attribute, void* value) {
*((uint16_t*)value) = HSA_VERSION_MINOR;
break;
case HSA_SYSTEM_INFO_TIMESTAMP: {
HsaClockCounters clocks;
hsaKmtGetClockCounters(0, &clocks);
*((uint64_t*)value) = clocks.SystemClockCounter;
*((uint64_t*)value) = os::ReadSystemClock();
break;
}
case HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY: {
@@ -1349,10 +1347,8 @@ hsa_status_t Runtime::Load() {
// Setup system clock frequency for the first time.
if (sys_clock_freq_ == 0) {
// Cache system clock frequency
HsaClockCounters clocks;
hsaKmtGetClockCounters(0, &clocks);
sys_clock_freq_ = clocks.SystemClockFrequencyHz;
sys_clock_freq_ = os::SystemClockFrequency();
if (sys_clock_freq_ < 100000) debug_warning("System clock resolution is low.");
}
BindVmFaultHandler();
@@ -515,6 +515,25 @@ void DestroySharedMutex(SharedMutex lock) {
delete *(pthread_rwlock_t**)&lock;
}
static uint64_t sys_clock_period_ = 0;
uint64_t ReadSystemClock() {
struct timespec ts;
clock_gettime(CLOCK_BOOTTIME, &ts);
uint64_t time = (uint64_t(ts.tv_sec) * 1000000000 + uint64_t(ts.tv_nsec));
if (sys_clock_period_ != 1)
return time / sys_clock_period_;
else
return time;
}
uint64_t SystemClockFrequency() {
struct timespec ts;
clock_getres(CLOCK_BOOTTIME, &ts);
sys_clock_period_ = (uint64_t(ts.tv_sec) * 1000000000 + uint64_t(ts.tv_nsec));
return 1000000000 / sys_clock_period_;
}
} // namespace os
} // namespace rocr
@@ -266,6 +266,14 @@ uint64_t ReadAccurateClock();
/// seconds. This frequency does not change at runtime.
/// @return returns the frequency
uint64_t AccurateClockFrequency();
/// @brief read the system clock which serves as the HSA system clock
/// counter in KFD.
uint64_t ReadSystemClock();
/// @brief read the system clock frequency
uint64_t SystemClockFrequency();
} // namespace os
} // namespace rocr
@@ -270,6 +270,16 @@ void DestroySharedMutex(SharedMutex lock) {
abort();
}
uint64_t ReadSystemClock() {
assert(false && "Not implemented.");
abort();
}
uint64_t SystemClockFrequency() {
assert(false && "Not implemented.");
abort();
}
} // namespace os
} // namespace rocr