drm/amd: Add Suspend/Hibernate notification callback support
Subsystems (2)
PATCH 1/1 drm/amd: Add Suspend/Hibernate notification callback support
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops prepare() callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.
Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +36 -0
@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count
@@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:
@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */
@@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* +*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb); + +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev)) +return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Signature · 1 line
2.43.0
Quoted 8 lines · Mario Limonciello
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Quoted 7 lines
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
This patch has some very good feedback on helping this memory pressure issue.
Quoted 85 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +36
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* +*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb); + +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev)) +return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Am 18.11.24 um 21:03 schrieb Mario Limonciello:
Quoted 8 lines
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Quoted 7 lines
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
I'm absolutely not an expert on that stuff but it looks rather reasonable to me.
Alex what do you think?
Regards,
Christian.
Quoted 85 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +36
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* +*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb); + +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev)) +return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Alex Deucher
Acked-byQuoted 14 lines · Christian König
Am 18.11.24 um 21:03 schrieb Mario Limonciello:
Quoted 12 lines
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
Quoted 8 lines
Quoted 3 lines
I'm absolutely not an expert on that stuff but it looks rather reasonable to me.
Alex what do you think?
Yeah, same. Seems reasonable to me.
Quoted 90 lines
Regards,
Christian.Quoted 85 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +36
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* +*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb); + +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev)) +return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Quoted 80 lines · Mario Limonciello
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +*
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4808
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-0+*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb); + +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev))
This will result in an eviction call on APUs since the flags won't be set by this time. Is that intended?
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L4739
Thanks,
Lijo
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Quoted 88 lines · Lijo
Quoted 85 lines · Mario Limonciello
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +24
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* +*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb);
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4808
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0+ +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev))This will result in an eviction call on APUs since the flags won't be set by this time. Is that intended?
Very good catch! I will bump it and modify amdgpu_device_evict_resources() to just skip APUs entirely.
Quoted 17 lines
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L4739
Thanks,
LijoQuoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Quoted 99 lines · Mario Limonciello
Quoted 88 lines · Lijo
Quoted 85 lines · Mario Limonciello
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +24
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* +*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb);Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4808
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0+ +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev))This will result in an eviction call on APUs since the flags won't be set by this time. Is that intended?
Quoted 2 lines
Very good catch! I will bump it and modify
amdgpu_device_evict_resources()to just skip APUs entirely.
We can skip for suspend on APUs, but we need to keep it for hibernation.
Alex
Quoted 19 lines
Quoted 18 lines
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L4739
Thanks,
LijoQuoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *
Quoted 101 lines · Alex Deucher
Quoted 99 lines · Mario Limonciello
Quoted 96 lines · Lijo
Quoted 80 lines · Mario Limonciello
As part of the suspend sequence VRAM needs to be evicted on dGPUs. In order to make suspend/resume more reliable we moved this into the pmops
prepare()callback so that the suspend sequence would fail but the system could remain operational under high memory usage suspend.Another class of issues exist though where due to memory fragementation there isn't a large enough contiguous space and swap isn't accessible.
Add support for a suspend/hibernate notification callback that could evict VRAM before tasks are frozen. This should allow paging out to swap if necessary.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -885,6 +885,7 @@ struct amdgpu_device {bool need_swiotlb;bool accel_working;struct notifier_block acpi_nb; +struct notifier_block pm_nb;struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS ];struct debugfs_blob_wrapper debugfs_vbios_blob;struct debugfs_blob_wrapper debugfs_discovery_blob;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19
-0@@ -190,6 +190,8 @@ void amdgpu_set_init_level(struct amdgpu_device *adev, }static inline void amdgpu_device_stop_pending_resets (struct amdgpu_device *adev); +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data);/** * DOC: pcie_replay_count @@ -4582,6 +4584,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_device_check_iommu_direct_map (adev); + adev->pm_nb.notifier_call = amdgpu_device_pm_notifier; + r =register_pm_notifier (&adev->pm_nb); +if (r) + goto failed; +return 0 ; release_ras_con:@@ -4646,6 +4653,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)drain_workqueue (adev->mman.bdev.wq); adev->shutdown = true; +unregister_pm_notifier (&adev->pm_nb); +/* make sure IB test finished before entering exclusive mode * to avoid preemption on IB test */ @@ -4777,6 +4786,33 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)/* * Suspend & resume. */ +/** +* amdgpu_device_pm_notifier - Notification block for Suspend/Hibernate events +* @nb: notifier block +* @mode: suspend mode +* @data: data +* +* This function is called when the system is about to suspend or hibernate. +* It is used to evict resources from the device before the system goes to +* sleep while there is still access to swap. +* drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4808
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-0+*/ +static int amdgpu_device_pm_notifier (struct notifier_block *nb,unsigned long mode, +void *data) +{ + struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb); + +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +if (amdgpu_device_evict_resources (adev))This will result in an eviction call on APUs since the flags won't be set by this time. Is that intended?
Quoted 4 lines
Quoted 2 lines
Very good catch! I will bump it and modify
amdgpu_device_evict_resources()to just skip APUs entirely.We can skip for suspend on APUs, but we need to keep it for hibernation.
Right; I realized that when I looked at the code, and that's what I ended up doing for v2.
Quoted 22 lines
Alex
Quoted 19 lines
Quoted 18 lines
https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L4739
Thanks,
LijoQuoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+return NOTIFY_BAD ; +break ; + } + +return NOTIFY_DONE ; +} +/** * amdgpu_device_prepare - prepare for device suspend *