drm/amdgpu: Read clock counter via MMIO to reduce delay (v5)
Subsystems (2)
PATCH 1/1 drm/amdgpu: Read clock counter via MMIO to reduce delay (v5)
[Why]
GPU timing counters are read via KIQ under sriov, which will introduce a delay.
[How]
It could be directly read by MMIO.
v2: Add additional check to prevent carryover issue.
v3: Only check for carryover for once to prevent performance issue.
v4: Add comments of the rough frequency where carryover happens.
v5: Remove mutex and gfxoff ctrl unused with current timing registers.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +12 -7
@@ -7609,10 +7609,8 @@ static int gfx_v10_0_soft_reset(void *handle)static uint64_t gfx_v10_0_get_gpu_clock_counter (struct amdgpu_device *adev) { -uint64_t clock; +uint64_t clock, clock_lo, clock_hi, hi_check; -amdgpu_gfx_off_ctrl (adev, false); -mutex_lock (&adev->gfx.gpu_clock_mutex);switch (adev->asic_type) {case CHIP_VANGOGH :case CHIP_YELLOW_CARP :
@@ -7620,12 +7618,19 @@ static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER_Vangogh) <<32ULL );break ;default : - clock = (uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER) | - ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER) <<32ULL ); + clock_hi =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + hi_check =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); +/* The GFX clock frequency is 100MHz, which sets 32-bit carry over +* roughly every 42 seconds. +*/ +if (hi_check != clock_hi) { + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + clock_hi = hi_check; + } + clock = (uint64_t )clock_lo | ((uint64_t )clock_hi <<32ULL );break ; } -mutex_unlock (&adev->gfx.gpu_clock_mutex); -amdgpu_gfx_off_ctrl (adev, true);return clock; }
Signature · 6 lines
2.25.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 01.07.21 um 11:57 schrieb YuBiao Wang:
Quoted 7 lines
[Why]
GPU timing counters are read via KIQ under sriov, which will introduce a delay.[How]
It could be directly read by MMIO.
Quoted 7 lines
v2: Add additional check to prevent carryover issue.
v3: Only check for carryover for once to prevent performance issue.
v4: Add comments of the rough frequency where carryover happens.
v5: Remove mutex and gfxoff ctrl unused with current timing registers.Signed-off-by YuBiao Wang <[email protected]>Acked-by Horace Chen <[email protected]>
The preemption_disable()/_enable() would still be nice to have I think.
Anyway patch is Reviewed-by: Christian König <[email protected]> either way.
Regards,
Christian.
Quoted 34 lines
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +9
-5@@ -7609,10 +7609,8 @@ static int gfx_v10_0_soft_reset(void *handle)static uint64_t gfx_v10_0_get_gpu_clock_counter (struct amdgpu_device *adev) { -uint64_t clock; +uint64_t clock, clock_lo, clock_hi, hi_check; -amdgpu_gfx_off_ctrl (adev, false); -mutex_lock (&adev->gfx.gpu_clock_mutex);switch (adev->asic_type) {case CHIP_VANGOGH :case CHIP_YELLOW_CARP :@@ -7620,12 +7618,19 @@ static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER_Vangogh) <<32ULL );break ;default : - clock = (uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER) | - ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER) <<32ULL ); + clock_hi =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + hi_check =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); +/* The GFX clock frequency is 100MHz, which sets 32-bit carry over +* roughly every 42 seconds. +*/ +if (hi_check != clock_hi) { + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER);
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) · line 7636
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3
-2+ clock_hi = hi_check; + } + clock = (uint64_t )clock_lo | ((uint64_t )clock_hi <<32ULL );break ; } -mutex_unlock (&adev->gfx.gpu_clock_mutex); -amdgpu_gfx_off_ctrl (adev, true);return clock; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A few comments to take care of before submitting the changes.
Quoted 36 lines · YuBiao Wang
[Why]
GPU timing counters are read via KIQ under sriov, which will introduce a delay.[How]
It could be directly read by MMIO.v2: Add additional check to prevent carryover issue.
v3: Only check for carryover for once to prevent performance issue.
v4: Add comments of the rough frequency where carryover happens.
v5: Remove mutex and gfxoff ctrl unused with current timing registers.Signed-off-by YuBiao Wang <[email protected]>Acked-by Horace Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1
-3@@ -7609,10 +7609,8 @@ static int gfx_v10_0_soft_reset(void *handle)static uint64_t gfx_v10_0_get_gpu_clock_counter (struct amdgpu_device *adev) { -uint64_t clock; +uint64_t clock, clock_lo, clock_hi, hi_check; -amdgpu_gfx_off_ctrl (adev, false); -mutex_lock (&adev->gfx.gpu_clock_mutex);switch (adev->asic_type) {case CHIP_VANGOGH :case CHIP_YELLOW_CARP :@@ -7620,12 +7618,19 @@ static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER_Vangogh) <<32ULL );
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) · line 7626
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6
-2break ;default : - clock = (uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER) | - ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER) <<32ULL ); + clock_hi =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + hi_check =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); +/* The GFX clock frequency is 100MHz, which sets 32-bit carry over +* roughly every 42 seconds. +*/
SMUIO TSC is not ticking based on GFX clock frequency, it's running at a fixed SMUIO TSC Clock frequency which is 100MHz (second part is right).
Replace GFX Clock with SMUIO TSC Clock.
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) · line 7631
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5
-0+if (hi_check != clock_hi) { + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + clock_hi = hi_check; + } + clock = (uint64_t )clock_lo | ((uint64_t )clock_hi <<32ULL );
These types are already uint64_t and looks cleaner without the cast.
Thanks,
Lijo
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) · line 7636
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-2break ; } -mutex_unlock (&adev->gfx.gpu_clock_mutex); -amdgpu_gfx_off_ctrl (adev, true);return clock; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 37 lines · YuBiao Wang
[Why]
GPU timing counters are read via KIQ under sriov, which will introduce a delay.[How]
It could be directly read by MMIO.v2: Add additional check to prevent carryover issue.
v3: Only check for carryover for once to prevent performance issue.
v4: Add comments of the rough frequency where carryover happens.
v5: Remove mutex and gfxoff ctrl unused with current timing registers.Signed-off-by YuBiao Wang <[email protected]>Acked-by Horace Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1
-3@@ -7609,10 +7609,8 @@ static int gfx_v10_0_soft_reset(void *handle)static uint64_t gfx_v10_0_get_gpu_clock_counter (struct amdgpu_device *adev) { -uint64_t clock; +uint64_t clock, clock_lo, clock_hi, hi_check; -amdgpu_gfx_off_ctrl (adev, false); -mutex_lock (&adev->gfx.gpu_clock_mutex);switch (adev->asic_type) {case CHIP_VANGOGH :case CHIP_YELLOW_CARP :@@ -7620,12 +7618,19 @@ static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER_Vangogh) <<32ULL );break ;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) · line 7627
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +7
-2default : - clock = (uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER) | - ((uint64_t )RREG32_SOC15 (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER) <<32ULL ); + clock_hi =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); + clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + hi_check =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_UPPER); +/* The GFX clock frequency is 100MHz, which sets 32-bit carry over +* roughly every 42 seconds. +*/ +if (hi_check != clock_hi) {
Yeah, the comment is so much better now. Good job.
Regards,
Luben
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static uint64_t gfx_v10_0_get_gpu_clock_counter(struct amdgpu_device *adev) · line 7636
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +4
-2+ clock_lo =RREG32_SOC15_NO_KIQ (SMUIO ,0 , mmGOLDEN_TSC_COUNT_LOWER); + clock_hi = hi_check; + } + clock = (uint64_t )clock_lo | ((uint64_t )clock_hi <<32ULL );break ; } -mutex_unlock (&adev->gfx.gpu_clock_mutex); -amdgpu_gfx_off_ctrl (adev, true);return clock; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx