Better handle memory pressure at suspend
Subsystems (3)
v2 cover Better handle memory pressure at suspend
At suspend time if there is memory pressure then dynamically allocating memory will cause failures that don't clean up properly when trying suspend a second time.
Move the bigger memory allocations into Linux PM prepare() callback and drop allocations that aren't really needed in DC code.
v1: https://patchwork.freedesktop.org/patch/559270/v1->v2:
* Handle DC code too
* Add prepare callback rather than moving symbol calls
Mario Limonciello (3):
drm/amd: Add support for prepare() callback drm/amd: Move evict resources suspend step to prepare() drm/amd/display: Destroy DC context while keeping DML
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 32 +++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 7 ++-- drivers/gpu/drm/amd/display/dc/core/dc.c | 25 --------------- .../gpu/drm/amd/display/dc/core/dc_resource.c | 11 +++++++ 5 files changed, 41 insertions(+), 35 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/3 drm/amd: Add support for prepare() callback
Linux PM core has a prepare() callback run before suspend and complete() callback ran after resume() for devices to use. Add plumbing to bring prepare() to amdgpu.
The idea with the new vfuncs for amdgpu is that all IP blocks that memory allocations during suspend should do the allocation from this call instead of the suspend() callback.
By moving the allocations to prepare() the system suspend will be failed before any IP block has done any suspend code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 20 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 7 ++++--- 3 files changed, 25 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -1415,6 +1415,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,void amdgpu_driver_release_kms (struct drm_device *dev);int amdgpu_device_ip_suspend (struct amdgpu_device *adev); +int amdgpu_device_prepare (struct drm_device *dev);int amdgpu_device_suspend (struct drm_device *dev,bool fbcon);int amdgpu_device_resume (struct drm_device *dev,bool fbcon);u32 amdgpu_get_vblank_counter_kms (struct drm_crtc *crtc);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +20 -0
@@ -4259,6 +4259,26 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_prepare - prepare for device suspend +* +* @dev: drm dev pointer +* +* Prepare to put the hw in the suspend state (all asics). +* Returns 0 for success or an error on failure. +* Called at driver suspend. +*/ +int amdgpu_device_prepare (struct drm_device *dev) +{ +struct amdgpu_device *adev =drm_to_adev (dev); +int r; + +if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF ) +return 0 ; + +return 0 ; +} +/** * amdgpu_device_suspend - initiate device suspend *
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -3
@@ -2425,8 +2425,9 @@ static int amdgpu_pmops_prepare(struct device *dev)/* Return a positive number here so * DPM_FLAG_SMART_SUSPEND works properly */ -if (amdgpu_device_supports_boco (drm_dev)) -return pm_runtime_suspended (dev); +if (amdgpu_device_supports_boco (drm_dev) && +pm_runtime_suspended (dev)) +return 1 ;/* if we will not support s3 or s2i for the device * then skip suspend
@@ -2435,7 +2436,7 @@ static int amdgpu_pmops_prepare(struct device *dev) !amdgpu_acpi_is_s3_active(adev))return 1 ; -return 0 ; +return amdgpu_device_prepare (drm_dev); }static void amdgpu_pmops_complete (struct device *dev)
Signature · 1 line
2.34.1
PATCH v2 2/3 drm/amd: Move evict resources suspend step to prepare()
In reply to Mario LimoncielloIf the system is under high memory pressure, the resources may need to be evicted into swap instead. If the storage backing for swap is offlined during the suspend() step then such a call may fail.
So instead move this step into prepare(), while leaving all other steps that put the GPU into a low power state in suspend().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -7
@@ -4276,6 +4276,11 @@ int amdgpu_device_prepare(struct drm_device *dev)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ; +/* Evict the majority of BOs before grabbing the full access */ + r =amdgpu_device_evict_resources (adev); +if (r) +return r; +return 0 ; }
@@ -4297,13 +4302,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ; - adev->in_suspend = true; - -/* Evict the majority of BOs before grabbing the full access */ - r =amdgpu_device_evict_resources (adev); -if (r) -return r; -if (amdgpu_sriov_vf (adev)) {amdgpu_virt_fini_data_exchange (adev); r =amdgpu_virt_request_full_gpu (adev, false);
Signature · 1 line
2.34.1
Deucher, Alexander
maintainerRE: [PATCH v2 2/3] drm/amd: Move evict resources suspend step to prepare()
[AMD Official Use Only - General]
Quoted 42 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Monday, October 2, 2023 6:45 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v2 2/3] drm/amd: Move evict resources suspend step toprepare()If the system is under high memory pressure, the resources may need to be evicted into swap instead. If the storage backing for swap is offlined during the
suspend()step then such a call may fail.So instead move this step into
prepare(), while leaving all other steps that put the GPU into a low power state insuspend().Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0@@ -4276,6 +4276,11 @@ int amdgpu_device_prepare(struct drm_device *dev)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ; +/* Evict the majority of BOs before grabbing the full access */ + r =amdgpu_device_evict_resources (adev); +if (r) +return r; +return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device · line 4301
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-1@@ -4297,13 +4302,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ; - adev->in_suspend = true;
This shouldn't be dropped.
Alex
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-6- -/* Evict the majority of BOs before grabbing the full access */ - r =amdgpu_device_evict_resources (adev); -if (r) -return r; -if (amdgpu_sriov_vf (adev)) {amdgpu_virt_fini_data_exchange (adev);r = amdgpu_virt_request_full_gpu(adev, false);--
2.34.1
Re: [PATCH v2 2/3] drm/amd: Move evict resources suspend step to prepare()
Quoted 43 lines · Alexander
[AMD Official Use Only - General]
Quoted 41 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Monday, October 2, 2023 6:45 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v2 2/3] drm/amd: Move evict resources suspend step toprepare()If the system is under high memory pressure, the resources may need to be evicted into swap instead. If the storage backing for swap is offlined during the
suspend()step then such a call may fail.So instead move this step into
prepare(), while leaving all other steps that put the GPU into a low power state insuspend().Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0@@ -4276,6 +4276,11 @@ int amdgpu_device_prepare(struct drm_device *dev)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ; +/* Evict the majority of BOs before grabbing the full access */ + r =amdgpu_device_evict_resources (adev); +if (r) +return r; +return 0 ; }
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device · line 4301
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-1@@ -4297,13 +4302,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ; - adev->in_suspend = true;This shouldn't be dropped.
Thanks - that was a mistake when I was rebasing it. I'll respin with a fix.
Quoted 14 lines
Alex
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-6- -/* Evict the majority of BOs before grabbing the full access */ - r =amdgpu_device_evict_resources (adev); -if (r) -return r; -if (amdgpu_sriov_vf (adev)) {amdgpu_virt_fini_data_exchange (adev);r = amdgpu_virt_request_full_gpu(adev, false);--
2.34.1
PATCH v2 3/3 drm/amd/display: Destroy DC context while keeping DML
In reply to Mario LimoncielloIf there is memory pressure at suspend time then dynamically allocating a large structure as part of DC suspend code will fail.
Instead re-use the same structure and clear all members except those that should be maintained.
---
Cc: [email protected]
--- drivers/gpu/drm/amd/display/dc/core/dc.c | 25 ------------------- .../gpu/drm/amd/display/dc/core/dc_resource.c | 11 ++++++++ 2 files changed, 11 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc.c +0 -25
@@ -4728,9 +4728,6 @@ bool dc_set_power_state( struct dc *dc, enum dc_acpi_cm_power_state power_state) { - struct kref refcount; -struct display_mode_lib *dml; -if (!dc->current_state)return true;
@@ -4750,30 +4747,8 @@ bool dc_set_power_state(break ;default :ASSERT (dc->current_state->stream_count ==0 ); -/* Zero out the current context so that on resume we start with -* clean state, and dc hw programming optimizations will not -* cause any trouble. -*/ - dml =kzalloc (sizeof (struct display_mode_lib ), -GFP_KERNEL ); - -ASSERT (dml); -if (!dml) -return false; - -/* Preserve refcount */ - refcount = dc->current_state->refcount; -/* Preserve display mode lib */ -memcpy (dml, &dc->current_state->bw_ctx.dml,sizeof (struct display_mode_lib ));dc_resource_state_destruct (dc->current_state); -memset (dc->current_state,0 , -sizeof (*dc->current_state)); - - dc->current_state->refcount = refcount; - dc->current_state->bw_ctx.dml = *dml; - -kfree (dml);break ; }
drivers/gpu/drm/amd/display/dc/core/dc_resource.c +11 -0
@@ -4350,6 +4350,17 @@ void dc_resource_state_destruct(struct dc_state *context) context->streams[i] =NULL ; } context->stream_count =0 ; + context->stream_mask =0 ; +memset (&context->res_ctx,0 ,sizeof (context->res_ctx)); +memset (&context->pp_display_cfg,0 ,sizeof (context->pp_display_cfg)); +memset (&context->dcn_bw_vars,0 ,sizeof (context->dcn_bw_vars)); + context->clk_mgr =NULL ; +memset (&context->bw_ctx.bw,0 ,sizeof (context->bw_ctx.bw)); +memset (context->block_sequence,0 ,sizeof (context->block_sequence)); + context->block_sequence_steps =0 ; +memset (context->dc_dmub_cmd,0 ,sizeof (context->dc_dmub_cmd)); + context->dmub_cmd_count =0 ; +memset (&context->perf_params,0 ,sizeof (context->perf_params)); } void dc_resource_state_copy_construct(
Signature · 1 line
2.34.1