Fix DCN 3.1.4 hangs on s2idle entry
Subsystems (3)
v3 cover Fix DCN 3.1.4 hangs on s2idle entry
DCN 3.1.4 s2idle entry will hang
occasionally on s2idle entry, but only if running Wayland and only when using systemctl suspend, not echo mem | tee /sys/power/state.
This happens because using systemctl suspend will cause the screen to lock right before writing mem into /sys/power/state. Userspace calls an IOCTL that leads to gpu_clock_counter().
This causes a delayed GFXOFF entry to be scheduled right before s2idle entry. If the workqueue doesn't get processed before the RLC is turned off the system is hung. Even if the workqueue *does* get processed, there is a race between the APU microcontrollers and driver for whether GFX is actually powered off when RLC is turned off.
To avoid this issue, flush the workqueue on s2idle entry and ensure that GFX is really in GFXOFF before any sensitive register accesses occur.
NOTE: This main trigger for this issue (IOCTL reading GPU clocks at suspend) is solved in amd-staging-drm-next via these commits:5591a051b86b ("drm/amdgpu: refine get gpu clock counter method") ea27ee2bea6b ("drm/amdgpu/gfx11: update gpu_clock_counter logic")
As GFXOFF can still be triggered in other ways, this series helps to improve the robustness. It was tested both with and without those commits present.
v2->v3:
* Remove dead code
* Apply the logic to wait for matching GFXOFF state to more ASICs
* Move code for IMU enabled ASICs to other files
Mario Limonciello (4):
drm/amd: Flush any delayed gfxoff on suspend entry drm/amd: Validate gfxoff state for smu10 drm/amd: Validate gfxoff state for smu12 drm/amd: Validate gfxoff state for smu13
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 9 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_imu.h | 1 + drivers/gpu/drm/amd/amdgpu/imu_v11_0.c | 10 ++++ .../drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.c | 57 +++++++++---------- .../gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c | 26 +++++---- .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 42 ++++++++++---- 7 files changed, 88 insertions(+), 58 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/4 drm/amd: Flush any delayed gfxoff on suspend entry
DCN 3.1.4 is reported to hang on s2idle entry if graphics activity is happening during entry. This is because GFXOFF was scheduled as delayed but RLC gets disabled in s2idle entry sequence which will hang GFX IP if not already in GFXOFF.
To help this problem, flush any delayed work for GFXOFF early in s2idle entry sequence to ensure that it's off when RLC is changed.
commit 3964b0c2e843 ("drm/amdgpu: complete gfxoff allow signal during suspend without delay") modified power gating flow so that if called in s0ix that it ensured that GFXOFF wasn't put in work queue but instead processed immediately.
This is dead code due to commit 5d70a549d00d ("drm/amdgpu: skip CG/PG for gfx during S0ix") because GFXOFF will now not be explicitly called as part of the suspend entry code. Remove that dead code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 9 +-------- 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -4316,6 +4316,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)drm_fb_helper_set_suspend_unlocked (adev_to_drm (adev)->fb_helper, true);cancel_delayed_work_sync (&adev->delayed_init_work); +flush_delayed_work (&adev->gfx.gfx_off_delay_work);amdgpu_ras_suspend (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -8
@@ -688,15 +688,8 @@ void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, bool enable)if (adev->gfx.gfx_off_req_count ==0 && !adev->gfx.gfx_off_state) { -/* If going to s2idle, no need to wait */ -if (adev->in_s0ix) { -if (!amdgpu_dpm_set_powergating_by_smu (adev, -AMD_IP_BLOCK_TYPE_GFX , true)) - adev->gfx.gfx_off_state = true; - }else { -schedule_delayed_work (&adev->gfx.gfx_off_delay_work, +schedule_delayed_work (&adev->gfx.gfx_off_delay_work, delay); - } } }else {if (adev->gfx.gfx_off_req_count ==0 ) {
Signature · 1 line
2.34.1
PATCH v3 2/4 drm/amd: Validate gfxoff state for smu10
In reply to Mario LimoncielloGFXOFF may be flushed at suspend entry and it may be important to ensure it reaches desired target state.
--- .../drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.c | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.c +28 -29
@@ -345,36 +345,11 @@ static bool smu10_is_gfx_on(struct pp_hwmgr *hwmgr)return false; } -static int smu10_disable_gfx_off (struct pp_hwmgr *hwmgr) -{ -struct amdgpu_device *adev = hwmgr->adev; - -if (adev->pm.pp_feature &PP_GFXOFF_MASK ) { -smum_send_msg_to_smc (hwmgr, PPSMC_MSG_DisableGfxOff,NULL ); - -/* confirm gfx is back to "on" state */ -while (!smu10_is_gfx_on (hwmgr)) -msleep (1 ); - } - -return 0 ; -} -static int smu10_disable_dpm_tasks (struct pp_hwmgr *hwmgr) {return 0 ; } -static int smu10_enable_gfx_off (struct pp_hwmgr *hwmgr) -{ -struct amdgpu_device *adev = hwmgr->adev; - -if (adev->pm.pp_feature &PP_GFXOFF_MASK ) -smum_send_msg_to_smc (hwmgr, PPSMC_MSG_EnableGfxOff,NULL ); - -return 0 ; -} -static void smu10_populate_umdpstate_clocks (struct pp_hwmgr *hwmgr) { hwmgr->pstate_sclk =SMU10_UMD_PSTATE_GFXCLK ;
@@ -416,10 +391,34 @@ static int smu10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)static int smu10_gfx_off_control (struct pp_hwmgr *hwmgr,bool enable) { -if (enable) -return smu10_enable_gfx_off (hwmgr); -else -return smu10_disable_gfx_off (hwmgr); +struct amdgpu_device *adev = hwmgr->adev; +int r, timeout =500 ; +bool target; + +if (!(adev->pm.pp_feature &PP_GFXOFF_MASK )) +return 0 ; + +if (enable) { + r =smum_send_msg_to_smc (hwmgr, PPSMC_MSG_EnableGfxOff,NULL ); + target = false; + }else { + r =smum_send_msg_to_smc (hwmgr, PPSMC_MSG_DisableGfxOff,NULL ); + target = true; + } +if (r) +return r; + +/* confirm gfx is back to intended state, timeout is 0.5 second */ +while (smu10_is_gfx_on (hwmgr) != target) { +msleep (1 ); + timeout--; +if (timeout ==0 ) { +DRM_ERROR ("%s gfxoff timeout and failed!\n" , enable ?"enable" :"disable" ); +return -ETIMEDOUT ; + } + } + +return 0 ; } static int smu10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
Signature · 1 line
2.34.1
PATCH v3 3/4 drm/amd: Validate gfxoff state for smu12
In reply to Mario LimoncielloGFXOFF may be flushed at suspend entry and it may be important to ensure it reaches desired target state.
--- .../gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c +15 -11
@@ -157,26 +157,30 @@ uint32_t smu_v12_0_get_gfxoff_status(struct smu_context *smu)int smu_v12_0_gfx_off_control (struct smu_context *smu,bool enable) { -int ret =0 , timeout =500 ; +int ret, timeout =500 ; +int target;if (enable) { ret =smu_cmn_send_smc_msg (smu, SMU_MSG_AllowGfxOff,NULL ); - + target =0 ; }else { ret =smu_cmn_send_smc_msg (smu, SMU_MSG_DisallowGfxOff,NULL ); + target =2 ; + } +if (ret) +return ret; -/* confirm gfx is back to "on" state, timeout is 0.5 second */ -while (!(smu_v12_0_get_gfxoff_status (smu) ==2 )) { -msleep (1 ); - timeout--; -if (timeout ==0 ) { -DRM_ERROR ("disable gfxoff timeout and failed!\n" ); -break ; - } +/* confirm gfx is back to intended state, timeout is 0.5 second */ +while ((smu_v12_0_get_gfxoff_status (smu) != target)) { +msleep (1 ); + timeout--; +if (timeout ==0 ) { +DRM_ERROR ("%s gfxoff timeout and failed!\n" , enable ?"enable" :"disable" ); +return -ETIMEDOUT ; } } -return ret; +return 0 ; }int smu_v12_0_fini_smc_tables (struct smu_context *smu)
Signature · 1 line
2.34.1
PATCH v3 4/4 drm/amd: Validate gfxoff state for smu13
In reply to Mario LimoncielloGFXOFF may be flushed at suspend entry and it may be important to ensure it reaches desired target state. In SMU13 designs that use IMU, validate the state is reached.
This mirrors the implementation done for SMU10 and SMU12.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_imu.h | 1 + drivers/gpu/drm/amd/amdgpu/imu_v11_0.c | 10 +++++ .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 42 ++++++++++++++----- 3 files changed, 43 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_imu.h +1 -0
@@ -36,6 +36,7 @@ struct amdgpu_imu_funcs {int (*start_imu)(struct amdgpu_device *adev);void (*program_rlc_ram)(struct amdgpu_device *adev);int (*wait_for_reset_status)(struct amdgpu_device *adev); +int (*get_gfxoff_status)(struct amdgpu_device *adev); };struct imu_rlc_ram_golden {
drivers/gpu/drm/amd/amdgpu/imu_v11_0.c +10 -0
@@ -375,6 +375,15 @@ static void imu_v11_0_program_rlc_ram(struct amdgpu_device *adev)WREG32_SOC15 (GC ,0 , regGFX_IMU_RLC_RAM_INDEX, reg_data); } +#define GFX_OFF_STATUS_SHIFT 1 +#define GFX_OFF_STATUS_MASK 0x6 +int imu_v11_0_get_gfxoff_status (struct amdgpu_device *adev) +{ +uint32_t reg =RREG32_SOC15 (GC ,0 , regGFX_IMU_MSG_FLAGS); + +return (reg &GFX_OFF_STATUS_MASK ) >>GFX_OFF_STATUS_SHIFT ; +} +const struct amdgpu_imu_funcs gfx_v11_0_imu_funcs = { .init_microcode = imu_v11_0_init_microcode, .load_microcode = imu_v11_0_load_microcode,
@@ -382,4 +391,5 @@ const struct amdgpu_imu_funcs gfx_v11_0_imu_funcs = { .start_imu = imu_v11_0_start, .program_rlc_ram = imu_v11_0_program_rlc_ram, .wait_for_reset_status = imu_v11_0_wait_for_reset_status, + .get_gfxoff_status = imu_v11_0_get_gfxoff_status, };
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +32 -10
60 lines not on this page · raw message
Signature · 1 line
2.34.1