Skip to contentSkip to conversation

drm/amdgpu/gfx11: update gpu_clock_counter logic

PATCH Superseded Alex Deucher 1 participant 1 message Apr 10, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu/gfx11: update gpu_clock_counter logic

This code was written prior to previous updates to this logic for other chips. The RSC registers are part of SMUIO which is an always on block so there is no need to disable gfxoff. Additionally add the carryover and preemption checks.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +15 -7
index ecf8ceb53311..c222b943eb65 100644
@@ -4670,14 +4670,22 @@ static int gfx_v11_0_post_soft_reset(void *handle)
 
 static uint64_t gfx_v11_0_get_gpu_clock_counter(struct amdgpu_device *adev)
 {
-	uint64_t clock;
+	uint64_t clock, clock_lo, clock_hi, hi_check;
+
+	preempt_disable();
+	clock_hi = RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_UPPER);
+	clock_lo = RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_LOWER);
+	hi_check = RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_UPPER);
+	/* The SMUIO TSC clock frequency is 100MHz, which sets 32-bit carry over
+	 * roughly every 42 seconds.
+	 */
+	if (hi_check != clock_hi) {
+		clock_lo = RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_LOWER);
+		clock_hi = hi_check;
+	}
+	preempt_enable();
+	clock = clock_lo | (clock_hi << 32ULL);
 
-	amdgpu_gfx_off_ctrl(adev, false);
-	mutex_lock(&adev->gfx.gpu_clock_mutex);
-	clock = (uint64_t)RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_LOWER) |
-		((uint64_t)RREG32_SOC15(SMUIO, 0, regGOLDEN_TSC_COUNT_UPPER) << 32ULL);
-	mutex_unlock(&adev->gfx.gpu_clock_mutex);
-	amdgpu_gfx_off_ctrl(adev, true);
 	return clock;
 }
 
Signature · 1 line
2.39.2