Better handle memory pressure at suspend
Subsystems (3)
v3 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://lore.kernel.org/amd-gfx/[email protected]/
v2: https://lore.kernel.org/amd-gfx/[email protected]/T/#mc800319a05df821cd1875234b09bf212e2e3282b
v2->v3:
* Handle adev->in_suspend in prepare() and complete()
* Add missing scratch variable in dc_resource_state_destruct()
* Revert error code propagation in same seriesv1->v2:
* Handle DC code too
* Add prepare callback rather than moving symbol calls
Mario Limonciello (4):
drm/amd: Add support for prepare() and complete() callbacks drm/amd: Move evict resources suspend step to prepare() drm/amd/display: Destroy DC context while keeping DML drm/amd/display: make dc_set_power_state() return type void again
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 46 ++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++-- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 17 ++----- drivers/gpu/drm/amd/display/dc/core/dc.c | 31 +------------ .../gpu/drm/amd/display/dc/core/dc_resource.c | 12 +++++ drivers/gpu/drm/amd/display/dc/dc.h | 2 +- 7 files changed, 69 insertions(+), 52 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/4 drm/amd: Add support for prepare() and complete() callbacks
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.
If the suspend fails, then do any cleanups in the complete() callback.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 ++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -1415,6 +1415,8 @@ 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); +void amdgpu_device_complete (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 +37 -2
@@ -4259,6 +4259,43 @@ 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 ; + + adev->in_suspend = true; + +return 0 ; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) +{ +struct amdgpu_device *adev =drm_to_adev (dev); + + adev->in_suspend = false; +} +/** * amdgpu_device_suspend - initiate device suspend *
@@ -4277,8 +4314,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)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +7 -4
@@ -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,12 +2436,14 @@ 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) { -/* nothing to do */ +struct drm_device *drm_dev =dev_get_drvdata (dev); + +amdgpu_device_complete (drm_dev); }static int amdgpu_pmops_suspend (struct device *dev)
Signature · 1 line
2.34.1
Deucher, Alexander
maintainerRE: [PATCH v3 1/4] drm/amd: Add support for prepare() and complete() callbacks
[Public]
Quoted 94 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Tuesday, October 3, 2023 4:55 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksLinux PM core has a
prepare()callback run before suspend andcomplete()callback ran afterresume()for devices to use. Add plumbing to bringprepare()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.If the suspend fails, then do any cleanups in the
complete()callback.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 ++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1415,6 +1415,8 @@ 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);void +amdgpu_device_complete (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); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexbad2b5577e96..f53cf675c3ce100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35
-0@@ -4259,6 +4259,43 @@ 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 ; + + adev->in_suspend = true; + +return 0 ; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) { +struct amdgpu_device *adev =drm_to_adev (dev); + + adev->in_suspend = false; +} +/** * amdgpu_device_suspend - initiate device suspend *
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device · line 4282
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2@@ -4277,8 +4314,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; -
We also set this to false in amdgpu_device_resume() so that should be fixed up as well. But, I'm not sure we want to move this out of amdgpu_device_suspend(). There are places we use amdgpu_device_suspend/resume() outside of pmops that also rely on these being set. Those places may need to be fixed up if we do. IIRC, the switcheroo code uses this.
Alex
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* Evict the majority of BOs before grabbing the full access */ r =amdgpu_device_evict_resources (adev);if (r)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3
-2@@ -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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-3@@ -2435,12 +2436,14 @@ 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) { -/* nothing to do */ +struct drm_device *drm_dev =dev_get_drvdata (dev); + +amdgpu_device_complete (drm_dev); }static int amdgpu_pmops_suspend (struct device *dev) --2.34.1
Re: [PATCH v3 1/4] drm/amd: Add support for prepare() and complete() callbacks
Quoted 100 lines · Alexander
[Public]
Quoted 98 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Tuesday, October 3, 2023 4:55 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksLinux PM core has a
prepare()callback run before suspend andcomplete()callback ran afterresume()for devices to use. Add plumbing to bringprepare()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.If the suspend fails, then do any cleanups in the
complete()callback.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 ++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1415,6 +1415,8 @@ 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);void +amdgpu_device_complete (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); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexbad2b5577e96..f53cf675c3ce100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35
-0@@ -4259,6 +4259,43 @@ 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 ; + + adev->in_suspend = true; + +return 0 ; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) { +struct amdgpu_device *adev =drm_to_adev (dev); + + adev->in_suspend = false; +} +/** * amdgpu_device_suspend - initiate device suspend * @@ -4277,8 +4314,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ;
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) · line 4281
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2- adev->in_suspend = true; -We also set this to false in
amdgpu_device_resume()so that should be fixed up as well. But, I'm not sure we want to move this out ofamdgpu_device_suspend(). There are places we use amdgpu_device_suspend/resume() outside of pmops that also rely on these being set. Those places may need to be fixed up if we do. IIRC, the switcheroo code uses this.
The big reason that I moved it from suspend() to prepare() was so that amdgpu_device_evict_resources() was called with the context of it being set.
My thought process:
0) prepare() sets all the time
1) If prepare() fails complete() clears it.
2) If prepare() succeeds it remains set for suspend()
3) If suspend() succeeds it gets cleared at resume()
4) If resume() failed for some reason, it's cleared by complete().
Does it actually matter that it's set while evicting resources?
If so, maybe I'll just have both prepare() and suspend() set it universally and both resume() and complete() clear it universally.
Quoted 44 lines
Alex
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* Evict the majority of BOs before grabbing the full access */ r =amdgpu_device_evict_resources (adev);if (r)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3
-2@@ -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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-3@@ -2435,12 +2436,14 @@ 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) { -/* nothing to do */ +struct drm_device *drm_dev =dev_get_drvdata (dev); + +amdgpu_device_complete (drm_dev); }static int amdgpu_pmops_suspend (struct device *dev) --2.34.1
Deucher, Alexander
maintainerRE: [PATCH v3 1/4] drm/amd: Add support for prepare() and complete() callbacks
[Public]
Quoted 126 lines
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, October 3, 2023 5:17 PM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Cc: Wentland, Harry <[email protected]>
Subject: Re: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksQuoted 103 lines · Alexander
[Public]
Quoted 101 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Tuesday, October 3, 2023 4:55 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksLinux PM core has a
prepare()callback run before suspend andcomplete()callback ran afterresume()for devices to use. Add plumbing to bringprepare()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.If the suspend fails, then do any cleanups in the
complete()callback.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 ++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -1415,6 +1415,8 @@ void amdgpu_driver_postclose_kms(struct
drm_device*dev, voidamdgpu_driver_release_kms(struct drm_device *dev);int amdgpu_device_ip_suspend(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+int amdgpu_device_prepare (struct drm_device *dev);void +amdgpu_device_complete (struct drm_device *dev);int amdgpu_device_suspend (struct drm_device *dev,bool fbcon);int
amdgpu_device_resume(struct drm_device *dev, bool fbcon);
u32amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc); diff
--gita/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexbad2b5577e96..f53cf675c3ce100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4259,6 +4259,43 @@ static intamdgpu_device_evict_resources(struct
amdgpu_device*adev)
/*
* Suspend & resume.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35
-0+/** +* 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 ; + + adev->in_suspend = true; + +return 0 ; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) { +struct amdgpu_device *adev =drm_to_adev (dev); + + adev->in_suspend = false; +} +/** * amdgpu_device_suspend - initiate device suspend * @@ -4277,8 +4314,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ;Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) · line 4281
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2- adev->in_suspend = true; -We also set this to false in
amdgpu_device_resume()so that should be fixedup as well. But, I'm not sure we want to move this out of
amdgpu_device_suspend(). There are places we use amdgpu_device_suspend/resume() outside of pmops that also rely on these being set. Those places may need to be fixed up if we do. IIRC, the switcheroo code uses this.The big reason that I moved it from
suspend()toprepare()was so thatamdgpu_device_evict_resources()was called with the context of it being set.
Quoted 8 lines
My thought process:
0)prepare()sets all the time
1) Ifprepare()failscomplete()clears it.
2) Ifprepare()succeeds it remains set forsuspend()
3) Ifsuspend()succeeds it gets cleared atresume()
4) Ifresume()failed for some reason, it's cleared bycomplete().Does it actually matter that it's set while evicting resources?
Shouldn't matter for evicting resources. We even have debugfs nodes you can access to forcibly evict resources at runtime for testing memory pressure.
Alex
Quoted 49 lines
If so, maybe I'll just have both
prepare()andsuspend()set it universally and bothresume()andcomplete()clear it universally.Quoted 22 lines
Alex
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* Evict the majority of BOs before grabbing the full access */ r =amdgpu_device_evict_resources (adev);if (r)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3
-2@@ -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 ;Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_prepare(struct
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0/* if we will not support s3 or s2i for the device * then skip suspend
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -2435,12 +2436,14 @@ static int amdgpu_pmops_prepare(structdevice
Quoted 19 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-3*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) { -/* nothing to do */ +struct drm_device *drm_dev =dev_get_drvdata (dev); + +amdgpu_device_complete (drm_dev); }static int amdgpu_pmops_suspend (struct device *dev) --2.34.1
Re: [PATCH v3 1/4] drm/amd: Add support for prepare() and complete() callbacks
Quoted 135 lines · Alexander
[Public]
Quoted 133 lines
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, October 3, 2023 5:17 PM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Cc: Wentland, Harry <[email protected]>
Subject: Re: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksQuoted 103 lines · Alexander
[Public]
Quoted 101 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Tuesday, October 3, 2023 4:55 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksLinux PM core has a
prepare()callback run before suspend andcomplete()callback ran afterresume()for devices to use. Add plumbing to bringprepare()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.If the suspend fails, then do any cleanups in the
complete()callback.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 ++++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -1415,6 +1415,8 @@ void amdgpu_driver_postclose_kms(struct
drm_device*dev, voidamdgpu_driver_release_kms(struct drm_device *dev);int amdgpu_device_ip_suspend(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+int amdgpu_device_prepare (struct drm_device *dev);void +amdgpu_device_complete (struct drm_device *dev);int amdgpu_device_suspend (struct drm_device *dev,bool fbcon);int
amdgpu_device_resume(struct drm_device *dev, bool fbcon);
u32amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc); diff
--gita/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexbad2b5577e96..f53cf675c3ce100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4259,6 +4259,43 @@ static intamdgpu_device_evict_resources(struct
amdgpu_device*adev)
/*
* Suspend & resume.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35
-0+/** +* 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 ; + + adev->in_suspend = true; + +return 0 ; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) { +struct amdgpu_device *adev =drm_to_adev (dev); + + adev->in_suspend = false; +} +/** * amdgpu_device_suspend - initiate device suspend * @@ -4277,8 +4314,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)if (dev->switch_power_state ==DRM_SWITCH_POWER_OFF )return 0 ;Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) · line 4281
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2- adev->in_suspend = true; -We also set this to false in
amdgpu_device_resume()so that should be fixedup as well. But, I'm not sure we want to move this out of
amdgpu_device_suspend(). There are places we use amdgpu_device_suspend/resume() outside of pmops that also rely on these being set. Those places may need to be fixed up if we do. IIRC, the switcheroo code uses this.The big reason that I moved it from
suspend()toprepare()was so thatamdgpu_device_evict_resources()was called with the context of it being set.My thought process:
0)prepare()sets all the time
1) Ifprepare()failscomplete()clears it.
2) Ifprepare()succeeds it remains set forsuspend()
3) Ifsuspend()succeeds it gets cleared atresume()
4) Ifresume()failed for some reason, it's cleared bycomplete().
Quoted 3 lines
Quoted 1 line
Does it actually matter that it's set while evicting resources?
Shouldn't matter for evicting resources. We even have debugfs nodes you can access to forcibly evict resources at runtime for testing memory pressure.
Then in that case I think what I'll do is put an extra call for amdgpu_device_evict_resources() in the prepare callback.
It shouldn't do any harm to call three times in the suspend sequence instead of two.
Quoted 53 lines
Alex
Quoted 49 lines
If so, maybe I'll just have both
prepare()andsuspend()set it universally and bothresume()andcomplete()clear it universally.Quoted 22 lines
Alex
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* Evict the majority of BOs before grabbing the full access */ r =amdgpu_device_evict_resources (adev);if (r)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3
-2@@ -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 ;Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_prepare(struct
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0/* if we will not support s3 or s2i for the device * then skip suspend
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -2435,12 +2436,14 @@ static int amdgpu_pmops_prepare(structdevice
Quoted 19 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-3*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) { -/* nothing to do */ +struct drm_device *drm_dev =dev_get_drvdata (dev); + +amdgpu_device_complete (drm_dev); }static int amdgpu_pmops_suspend (struct device *dev) --2.34.1
Re: [PATCH v3 1/4] drm/amd: Add support for prepare() and complete() callbacks
Am 04.10.23 um 05:39 schrieb Mario Limonciello:
Quoted 136 lines · Alexander
Quoted 135 lines
[Public]
Quoted 133 lines
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, October 3, 2023 5:17 PM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Cc: Wentland, Harry <[email protected]>
Subject: Re: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksQuoted 103 lines · Alexander
[Public]
Quoted 101 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Tuesday, October 3, 2023 4:55 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksLinux PM core has a
prepare()callback run before suspend andcomplete()callback ran afterresume()for devices to use. Add plumbing to bringprepare()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.If the suspend fails, then do any cleanups in the
complete()callback.Signed-off-by Mario Limonciello <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 39
++++++++++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++---3 files changed, 46 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -1415,6 +1415,8 @@ void amdgpu_driver_postclose_kms(struct
drm_device*dev, voidamdgpu_driver_release_kms(struct drm_device *dev);int
amdgpu_device_ip_suspend(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+int amdgpu_device_prepare (struct drm_device *dev);void +amdgpu_device_complete (struct drm_device *dev);int
amdgpu_device_suspend(struct drm_device *dev, bool fbcon); intamdgpu_device_resume(struct drm_device *dev, bool fbcon); u32amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexbad2b5577e96..f53cf675c3ce100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4259,6 +4259,43 @@ static intamdgpu_device_evict_resources(struct
amdgpu_device*adev)
/*
* Suspend & resume.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35
-0+/** +* 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; + + adev->in_suspend = true; + + return 0; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) { + struct amdgpu_device *adev = drm_to_adev(dev); + + adev->in_suspend = false; +} +/**
*amdgpu_device_suspend- initiate device suspend *drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4277,8 +4314,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) return 0;Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) · line 4281
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2- adev->in_suspend = true; -We also set this to false in
amdgpu_device_resume()so that should be fixedup as well. But, I'm not sure we want to move this out of amdgpu_device_suspend(). There are places we use amdgpu_device_suspend/resume() outside of pmops that also rely on these being set. Those places may need to be fixed up if we do. IIRC, the switcheroo code uses this.
The big reason that I moved it from
suspend()toprepare()was so thatamdgpu_device_evict_resources()was called with the context of it being set.My thought process:
0)prepare()sets all the time
1) Ifprepare()failscomplete()clears it.
2) Ifprepare()succeeds it remains set forsuspend()
3) Ifsuspend()succeeds it gets cleared atresume()
4) Ifresume()failed for some reason, it's cleared bycomplete().
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Does it actually matter that it's set while evicting resources?
Shouldn't matter for evicting resources. We even have debugfs nodes you can access to forcibly evict resources at runtime for testing memory pressure.
Then in that case I think what I'll do is put an extra call for
amdgpu_device_evict_resources()in the prepare callback.It shouldn't do any harm to call three times in the suspend sequence instead of two.
Yeah, I think you should move the first call from suspend to prepare.
Evacuating VRAM doesn't rely at all on the suspend flag, but the second evacuation only works after we turned of the hardware.
Regards,
Christian.
Quoted 55 lines
Quoted 54 lines
Alex
Quoted 49 lines
If so, maybe I'll just have both
prepare()andsuspend()set it universally and bothresume()andcomplete()clear it universally.Quoted 22 lines
Alex
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* Evict the majority of BOs before grabbing the full access */ r = amdgpu_device_evict_resources(adev);if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3
-2@@ -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;Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_prepare(struct
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0/* if we will not support s3 or s2i for the device* then skip suspend
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -2435,12 +2436,14 @@ static int amdgpu_pmops_prepare(structdevice
Quoted 19 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-2*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) { - /* nothing to do */ + struct drm_device *drm_dev = dev_get_drvdata(dev); + + amdgpu_device_complete(drm_dev); } static int amdgpu_pmops_suspend(struct device *dev)Signature · 1 line
2.34.1
Re: [PATCH v3 1/4] drm/amd: Add support for prepare() and complete() callbacks
Quoted 141 lines · Christian König
Am 04.10.23 um 05:39 schrieb Mario Limonciello:
Quoted 140 lines · Alexander
Quoted 138 lines
[Public]
Quoted 126 lines
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, October 3, 2023 5:17 PM
To: Deucher, Alexander <[email protected]>; amd- [email protected]
Cc: Wentland, Harry <[email protected]>
Subject: Re: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksQuoted 103 lines · Alexander
[Public]
Quoted 101 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello
Sent: Tuesday, October 3, 2023 4:55 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Limonciello, Mario <[email protected]>
Subject: [PATCH v3 1/4] drm/amd: Add support forprepare()andcomplete()callbacksLinux PM core has a
prepare()callback run before suspend andcomplete()callback ran afterresume()for devices to use. Add plumbing to bringprepare()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.If the suspend fails, then do any cleanups in the
complete()callback.Signed-off-by Mario Limonciello <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 39
++++++++++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++---3 files changed, 46 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -1415,6 +1415,8 @@ void amdgpu_driver_postclose_kms(struct
drm_device*dev, voidamdgpu_driver_release_kms(struct drm_device *dev);int
amdgpu_device_ip_suspend(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+int amdgpu_device_prepare (struct drm_device *dev);void +amdgpu_device_complete (struct drm_device *dev);int
amdgpu_device_suspend(struct drm_device *dev, bool fbcon); intamdgpu_device_resume(struct drm_device *dev, bool fbcon); u32amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
indexbad2b5577e96..f53cf675c3ce100644drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4259,6 +4259,43 @@ static intamdgpu_device_evict_resources(struct
amdgpu_device*adev)
/*
* Suspend & resume.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35
-0+/** +* 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; + + adev->in_suspend = true; + + return 0; +} + +/** +* amdgpu_device_complete - complete the device after resume +* +* @dev: drm dev pointer +* +* Clean up any actions that the prepare step did. +* Called after driver resume. +*/ +void amdgpu_device_complete (struct drm_device *dev) { + struct amdgpu_device *adev = drm_to_adev(dev); + + adev->in_suspend = false; +} +/**
*amdgpu_device_suspend- initiate device suspend *drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4277,8 +4314,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) return 0;Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_suspend(struct drm_device *dev, bool fbcon) · line 4281
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2- adev->in_suspend = true; -We also set this to false in
amdgpu_device_resume()so that should be fixedup as well. But, I'm not sure we want to move this out of amdgpu_device_suspend(). There are places we use amdgpu_device_suspend/resume() outside of pmops that also rely on these being set. Those places may need to be fixed up if we do. IIRC, the switcheroo code uses this.
The big reason that I moved it from
suspend()toprepare()was so thatamdgpu_device_evict_resources()was called with the context of it being set.Quoted 8 lines
My thought process:
0)prepare()sets all the time
1) Ifprepare()failscomplete()clears it.
2) Ifprepare()succeeds it remains set forsuspend()
3) Ifsuspend()succeeds it gets cleared atresume()
4) Ifresume()failed for some reason, it's cleared bycomplete().Does it actually matter that it's set while evicting resources?
Shouldn't matter for evicting resources. We even have debugfs nodes you can access to forcibly evict resources at runtime for testing memory pressure.
Quoted 7 lines
Quoted 3 lines
Then in that case I think what I'll do is put an extra call for
amdgpu_device_evict_resources()in the prepare callback.It shouldn't do any harm to call three times in the suspend sequence instead of two.
Yeah, I think you should move the first call from suspend to prepare.
Evacuating VRAM doesn't rely at all on the suspend flag, but the second evacuation only works after we turned of the hardware.
In the v4 of the series I've instead added an extra call to evict in prepare(). So it's 1x call in prepare() and then 2x call in suspend().
Quoted 60 lines
Regards,
Christian.Quoted 55 lines
Quoted 54 lines
Alex
Quoted 49 lines
If so, maybe I'll just have both
prepare()andsuspend()set it universally and bothresume()andcomplete()clear it universally.Quoted 22 lines
Alex
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* Evict the majority of BOs before grabbing the full access */ r = amdgpu_device_evict_resources(adev);if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3
-2@@ -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;Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_prepare(struct
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0/* if we will not support s3 or s2i for the device* then skip suspend
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -2435,12 +2436,14 @@ static int amdgpu_pmops_prepare(structdevice
Quoted 19 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-2*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) { - /* nothing to do */ + struct drm_device *drm_dev = dev_get_drvdata(dev); + + amdgpu_device_complete(drm_dev); } static int amdgpu_pmops_suspend(struct device *dev)Signature · 1 line
2.34.1
PATCH v3 2/4 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -5
@@ -4278,6 +4278,10 @@ int amdgpu_device_prepare(struct drm_device *dev) adev->in_suspend = true; + r =amdgpu_device_evict_resources (adev); +if (r) +return r; +return 0 ; }
@@ -4314,11 +4318,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)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; -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
PATCH v3 3/4 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 | 12 +++++++++ 2 files changed, 12 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 +12 -0
@@ -4350,6 +4350,18 @@ 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)); +memset (&context->scratch,0 ,sizeof (context->scratch)); } void dc_resource_state_copy_construct(
Signature · 1 line
2.34.1
PATCH v3 4/4 drm/amd/display: make dc_set_power_state() return type `void` again
In reply to Mario LimoncielloAs dc_set_power_state() no longer allocates memory, it's not necessary to have return types and check return code as it can't fail anymore.
Change it back to void.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 17 +++++------------ drivers/gpu/drm/amd/display/dc/core/dc.c | 6 ++---- drivers/gpu/drm/amd/display/dc/dc.h | 2 +- 3 files changed, 8 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -12
@@ -2686,11 +2686,6 @@ static void hpd_rx_irq_work_suspend(struct amdgpu_display_manager *dm) } } -static int dm_set_power_state (struct dc *dc,enum dc_acpi_cm_power_state power_state) -{ -return dc_set_power_state (dc, power_state) ?0 : -ENOMEM ; -} -static int dm_suspend (void *handle) {struct amdgpu_device *adev = handle;
@@ -2724,7 +2719,9 @@ static int dm_suspend(void *handle)hpd_rx_irq_work_suspend (dm); -return dm_set_power_state (dm->dc,DC_ACPI_CM_POWER_STATE_D3 ); +dc_set_power_state (dm->dc,DC_ACPI_CM_POWER_STATE_D3 ); + +return 0 ; } struct drm_connector *
@@ -2918,9 +2915,7 @@ static int dm_resume(void *handle)if (r)DRM_ERROR ("DMUB interface failed to initialize: status=%d\n" , r); - r =dm_set_power_state (dm->dc,DC_ACPI_CM_POWER_STATE_D0 ); -if (r) -return r; +dc_set_power_state (dm->dc,DC_ACPI_CM_POWER_STATE_D0 );dc_resume (dm->dc);
@@ -2970,9 +2965,7 @@ static int dm_resume(void *handle) }/* power on hardware */ - r =dm_set_power_state (dm->dc,DC_ACPI_CM_POWER_STATE_D0 ); -if (r) -return r; +dc_set_power_state (dm->dc,DC_ACPI_CM_POWER_STATE_D0 );/* program HPD filter */ dc_resume (dm->dc);
drivers/gpu/drm/amd/display/dc/core/dc.c +2 -4
@@ -4724,12 +4724,12 @@ void dc_power_down_on_boot(struct dc *dc) dc->hwss.power_down_on_boot (dc); } -bool dc_set_power_state ( +void dc_set_power_state (struct dc *dc,enum dc_acpi_cm_power_state power_state) {if (!dc->current_state) -return true; +return ;switch (power_state) {case DC_ACPI_CM_POWER_STATE_D0 :
@@ -4752,8 +4752,6 @@ bool dc_set_power_state(break ; } - -return true; }void dc_resume (struct dc *dc)
drivers/gpu/drm/amd/display/dc/dc.h +1 -1
@@ -2330,7 +2330,7 @@ void dc_notify_vsync_int_state(struct dc *dc, struct dc_stream_state *stream, bo/* Power Interfaces */ -bool dc_set_power_state ( +void dc_set_power_state (struct dc *dc,enum dc_acpi_cm_power_state power_state);void dc_resume (struct dc *dc);
Signature · 1 line
2.34.1