Force t1_ update when profiling is enabled

Fixes issue where t1_ counters may not be updated when doing dispatch
profiling, causing a divide by 0.

Change-Id: I91060ac3f9fd2183d277e6e7cd810398a453a87f


[ROCm/ROCR-Runtime commit: 3d1563ee68]
This commit is contained in:
David Yat Sin
2023-11-15 16:14:36 +00:00
parent bc492274e7
commit dc9bce3b9b
4 changed files with 19 additions and 6 deletions
@@ -196,9 +196,12 @@ class AqlQueue : public core::Queue, private core::LocalSignal, public core::Doo
/// @return hsa_status_t
hsa_status_t GetCUMasking(uint32_t num_cu_mask_count, uint32_t* cu_mask) override;
// @brief Submits a block of PM4 and waits until it has been executed.
/// @brief Submits a block of PM4 and waits until it has been executed.
void ExecutePM4(uint32_t* cmd_data, size_t cmd_size_b) override;
/// @brief Enables/Disables profiling overrides SetProfiling from core::Queue
void SetProfiling(bool enabled) override;
/// @brief Update signal value using Relaxed semantics
void StoreRelaxed(hsa_signal_value_t value) override;
@@ -373,6 +373,13 @@ class GpuAgent : public GpuAgentInt {
// @brief returns the libdrm device handle
__forceinline amdgpu_device_handle libDrmDev() const { return ldrm_dev_; }
__forceinline void CheckClockTicks() {
// If we did not update t1 since agent initialization, force a SyncClock. Otherwise computing
// the SystemClockCounter to GPUClockCounter ratio in TranslateTime(tick) results to a division
// by 0.
if (t0_.GPUClockCounter == t1_.GPUClockCounter) SyncClocks();
}
void ReserveScratch();
// @brief If agent supports it, release scratch memory for all AQL queues on this agent.
@@ -1339,6 +1339,13 @@ hsa_status_t AqlQueue::GetCUMasking(uint32_t num_cu_mask_count, uint32_t* cu_mas
return HSA_STATUS_SUCCESS;
}
void AqlQueue::SetProfiling(bool enabled) {
Queue::SetProfiling(enabled);
if (enabled) agent_->CheckClockTicks();
return;
}
void AqlQueue::ExecutePM4(uint32_t* cmd_data, size_t cmd_size_b) {
// pm4_ib_buf_ is a shared resource, so mutually exclude here.
ScopedAcquire<KernelMutex> lock(&pm4_ib_mutex_);
@@ -1191,11 +1191,7 @@ hsa_status_t GpuAgent::EnableDmaProfiling(bool enable) {
}
}
// If we did not update t1 since agent initialization, force a SyncClock. Otherwise computing
// the SystemClockCounter to GPUClockCounter ratio in TranslateTime(tick) results to a division
// by 0. We perform the check here because we do not want to check everytime there is a call to
// TranslateTime(tick)
if (enable && t0_.GPUClockCounter == t1_.GPUClockCounter) SyncClocks();
if (enable) CheckClockTicks();
return HSA_STATUS_SUCCESS;
}