drm/panthor: Be robust against failures in the resume path
Subsystems (3)
Boris Brezillon
maintainercover drm/panthor: Be robust against failures in the resume path
Hello,
Here's a collection of patches improving robustness to failures in the device resume/suspend path. Those failures are pretty hard to reproduce (happens once in a while on a deqp-vk run), so I used a mechanism to fake them.
Faking a FW boot failure is kinda tricky though, which means the last patch has only been partially tested:
- the fast reset path is well tested because that's the default on a device suspend
- the slow reset has been tested with a hack replacing fast resets by slow resets
- the fast -> slow reset fallback has been tested by faking boot failures after a fast reset, but these are not real, which means we can't really validate if the MCU recovers fine after a slow reset
On the other hand, this implementation doesn't look like it could do more harm than the current one (the only difference is the extra GPU soft-reset that happens between the fast and slow FW boot).
Regards,
Boris
Boris Brezillon (5):
drm/panthor: Preserve the result returned by panthor_fw_resume() drm/panthor: Be robust against runtime PM resume failures in the
suspend path
drm/panthor: Ignore devfreq_{suspend,resume}_device() failures drm/panthor: Be robust against resume failures drm/panthor: Fix the fast-reset logic
drivers/gpu/drm/panthor/panthor_devfreq.c | 12 ++-- drivers/gpu/drm/panthor/panthor_devfreq.h | 4 +- drivers/gpu/drm/panthor/panthor_device.c | 78 +++++++++++------------ drivers/gpu/drm/panthor/panthor_device.h | 28 ++++++++ drivers/gpu/drm/panthor/panthor_drv.c | 2 +- drivers/gpu/drm/panthor/panthor_fw.c | 62 +++++------------- drivers/gpu/drm/panthor/panthor_gpu.c | 14 ++-- drivers/gpu/drm/panthor/panthor_mmu.c | 3 +- drivers/gpu/drm/panthor/panthor_sched.c | 4 +- 9 files changed, 102 insertions(+), 105 deletions(-)
Signature · 1 line
2.46.2
Boris Brezillon
maintainerPATCH 1/5 drm/panthor: Preserve the result returned by panthor_fw_resume()
WARN() will return true if the condition is true, false otherwise. If we store the return of drm_WARN_ON() in ret, we lose the actual error code.
--- drivers/gpu/drm/panthor/panthor_device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/panthor/panthor_device.c +2 -2
@@ -441,8 +441,8 @@ int panthor_device_resume(struct device *dev) drm_dev_enter(&ptdev->base, &cookie)) {panthor_gpu_resume (ptdev);panthor_mmu_resume (ptdev); - ret =drm_WARN_ON (&ptdev->base,panthor_fw_resume (ptdev)); -if (!ret) { + ret =panthor_fw_resume (ptdev); +if (!drm_WARN_ON (&ptdev->base, ret)) {panthor_sched_resume (ptdev); }else {panthor_mmu_suspend (ptdev);
Signature · 1 line
2.46.2
Re: [PATCH 1/5] drm/panthor: Preserve the result returned by panthor_fw_resume()
Quoted 6 lines · Boris Brezillon
WARN()will return true if the condition is true, false otherwise. If we store the return ofdrm_WARN_ON()in ret, we lose the actual error code.Fixes 5fe909cae118 ("drm/panthor: Add the device logical block")Signed-off-by Boris Brezillon <[email protected]>
Quoted 19 lines
--- drivers/gpu/drm/panthor/panthor_device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +2
-2@@ -441,8 +441,8 @@ int panthor_device_resume(struct device *dev) drm_dev_enter(&ptdev->base, &cookie)) {panthor_gpu_resume (ptdev);panthor_mmu_resume (ptdev); - ret =drm_WARN_ON (&ptdev->base,panthor_fw_resume (ptdev)); -if (!ret) { + ret =panthor_fw_resume (ptdev); +if (!drm_WARN_ON (&ptdev->base, ret)) {panthor_sched_resume (ptdev); }else {panthor_mmu_suspend (ptdev);
Boris Brezillon
maintainerPATCH 2/5 drm/panthor: Be robust against runtime PM resume failures in the suspend path
In reply to Boris BrezillonThe runtime PM resume operation is not guaranteed to succeed, but if it fails, the device should be in a suspended state. Make sure we're robust to resume failures in the unplug path.
--- drivers/gpu/drm/panthor/panthor_device.c | 23 ++++++++--------------- drivers/gpu/drm/panthor/panthor_fw.c | 14 +++++++++----- drivers/gpu/drm/panthor/panthor_gpu.c | 3 ++- drivers/gpu/drm/panthor/panthor_mmu.c | 3 ++- 4 files changed, 21 insertions(+), 22 deletions(-)
drivers/gpu/drm/panthor/panthor_device.c +8 -15
@@ -48,6 +48,8 @@ static int panthor_clk_init(struct panthor_device *ptdev)void panthor_device_unplug (struct panthor_device *ptdev) { +int ret; +/* This function can be called from two different path: the reset work * and the platform device remove callback. drm_dev_unplug() doesn't * deal with concurrent callers, so we have to protect drm_dev_unplug()
@@ -74,7 +76,8 @@ void panthor_device_unplug(struct panthor_device *ptdev)*/ mutex_unlock (&ptdev->unplug.lock); -drm_WARN_ON (&ptdev->base,pm_runtime_get_sync (ptdev->base.dev) <0 ); + ret =pm_runtime_get_sync (ptdev->base.dev); +drm_WARN_ON (&ptdev->base, ret <0 );/* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed.
@@ -85,7 +88,10 @@ void panthor_device_unplug(struct panthor_device *ptdev)panthor_gpu_unplug (ptdev);pm_runtime_dont_use_autosuspend (ptdev->base.dev); -pm_runtime_put_sync_suspend (ptdev->base.dev); + +/* If the resume failed, we don't need to suspend here. */ +if (!ret) +pm_runtime_put_sync_suspend (ptdev->base.dev);/* If PM is disabled, we need to call the suspend handler manually. */ if (!IS_ENABLED (CONFIG_PM ))
@@ -541,17 +547,4 @@ int panthor_device_suspend(struct device *dev)clk_disable_unprepare (ptdev->clks.core);atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED );return 0 ; - -err_set_active: -/* If something failed and we have to revert back to an -* active state, we also need to clear the MMIO userspace -* mappings, so any dumb pages that were mapped while we -* were trying to suspend gets invalidated. -*/ -mutex_lock (&ptdev->pm.mmio_lock); -atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_ACTIVE ); -unmap_mapping_range (ptdev->base.anon_inode->i_mapping, -DRM_PANTHOR_USER_MMIO_OFFSET ,0 ,1 ); -mutex_unlock (&ptdev->pm.mmio_lock); -return ret; }
drivers/gpu/drm/panthor/panthor_fw.c +9 -5
@@ -12,6 +12,7 @@#include <linux/iosys-map.h> #include <linux/mutex.h> #include <linux/platform_device.h> +#include <linux/pm_runtime.h> #include <drm/drm_drv.h> #include <drm/drm_managed.h>
@@ -1188,11 +1189,13 @@ void panthor_fw_unplug(struct panthor_device *ptdev)cancel_delayed_work_sync (&ptdev->fw->watchdog.ping_work); -/* Make sure the IRQ handler can be called after that point. */ -if (ptdev->fw->irq.irq) -panthor_job_irq_suspend (&ptdev->fw->irq); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) { +/* Make sure the IRQ handler can be called after that point. */ +if (ptdev->fw->irq.irq) +panthor_job_irq_suspend (&ptdev->fw->irq); -panthor_fw_stop (ptdev); +panthor_fw_stop (ptdev); + }list_for_each_entry (section, &ptdev->fw->sections, node)panthor_kernel_bo_destroy (section->mem);
@@ -1205,7 +1208,8 @@ void panthor_fw_unplug(struct panthor_device *ptdev)panthor_vm_put (ptdev->fw->vm); ptdev->fw->vm =NULL ; -panthor_gpu_power_off (ptdev,L2 , ptdev->gpu_info.l2_present,20000 ); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) +panthor_gpu_power_off (ptdev,L2 , ptdev->gpu_info.l2_present,20000 ); }/**
drivers/gpu/drm/panthor/panthor_gpu.c +2 -1
@@ -174,7 +174,8 @@ void panthor_gpu_unplug(struct panthor_device *ptdev)unsigned long flags;/* Make sure the IRQ handler is not running after that point. */ -panthor_gpu_irq_suspend (&ptdev->gpu->irq); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) +panthor_gpu_irq_suspend (&ptdev->gpu->irq);/* Wake-up all waiters. */ spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags);
drivers/gpu/drm/panthor/panthor_mmu.c +2 -1
@@ -2674,7 +2674,8 @@ int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec, struct panthor_vm*/ void panthor_mmu_unplug (struct panthor_device *ptdev) { -panthor_mmu_irq_suspend (&ptdev->mmu->irq); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) +panthor_mmu_irq_suspend (&ptdev->mmu->irq);mutex_lock (&ptdev->mmu->as.slots_lock);for (u32 i =0 ; i <ARRAY_SIZE (ptdev->mmu->as.slots); i++) {
Signature · 1 line
2.46.2
Boris Brezillon
maintainerRe: [PATCH 2/5] drm/panthor: Be robust against runtime PM resume failures in the suspend path
Quoted 11 lines · On Wed, 13 Nov 2024 16:42:54 +0100 Boris Brezillon…
drivers/gpu/drm/panthor/panthor_device.c +2
-1@@ -74,7 +76,8 @@ void panthor_device_unplug(struct panthor_device *ptdev)*/ mutex_unlock (&ptdev->unplug.lock); -drm_WARN_ON (&ptdev->base,pm_runtime_get_sync (ptdev->base.dev) <0 ); + ret =pm_runtime_get_sync (ptdev->base.dev); +drm_WARN_ON (&ptdev->base, ret <0 );/* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed.
drivers/gpu/drm/panthor/panthor_device.c void panthor_device_unplug(struct panthor_device *ptdev) · line 94
Quoted 8 lines
drivers/gpu/drm/panthor/panthor_device.c +4
-1@@ -85,7 +88,10 @@ void panthor_device_unplug(struct panthor_device *ptdev)panthor_gpu_unplug (ptdev);pm_runtime_dont_use_autosuspend (ptdev->base.dev); -pm_runtime_put_sync_suspend (ptdev->base.dev); + +/* If the resume failed, we don't need to suspend here. */ +if (!ret) +pm_runtime_put_sync_suspend (ptdev->base.dev);
Okay, I always get confused by pm_runtime_get_sync(). Turns out the refcount is incremented even if pm_runtime_get_sync() fails, so we should call pm_runtime_put_sync_suspend() unconditionally here.
Boris Brezillon
maintainerRe: [PATCH 2/5] drm/panthor: Be robust against runtime PM resume failures in the suspend path
In reply to Boris BrezillonQuoted 8 lines · On Wed, 13 Nov 2024 16:42:54 +0100 Boris Brezillon…
drivers/gpu/drm/panthor/panthor_device.c +0
-4@@ -541,17 +547,4 @@ int panthor_device_suspend(struct device *dev)clk_disable_unprepare (ptdev->clks.core);atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED );return 0 ; - -err_set_active: -/* If something failed and we have to revert back to an -* active state, we also need to clear the MMIO userspace
drivers/gpu/drm/panthor/panthor_device.c int panthor_device_suspend(struct device *dev) · line 550
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.c +0
-9-* mappings, so any dumb pages that were mapped while we -* were trying to suspend gets invalidated. -*/ -mutex_lock (&ptdev->pm.mmio_lock); -atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_ACTIVE ); -unmap_mapping_range (ptdev->base.anon_inode->i_mapping, -DRM_PANTHOR_USER_MMIO_OFFSET ,0 ,1 ); -mutex_unlock (&ptdev->pm.mmio_lock); -return ret; }
This chunk should be in patch 3.
Liviu Dudau
maintainerRe: [PATCH 2/5] drm/panthor: Be robust against runtime PM resume failures in the suspend path
In reply to Boris BrezillonQuoted 48 lines · Boris Brezillon
The runtime PM resume operation is not guaranteed to succeed, but if it fails, the device should be in a suspended state. Make sure we're robust to resume failures in the unplug path.
Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.c | 23 ++++++++--------------- drivers/gpu/drm/panthor/panthor_fw.c | 14 +++++++++----- drivers/gpu/drm/panthor/panthor_gpu.c | 3 ++- drivers/gpu/drm/panthor/panthor_mmu.c | 3 ++- 4 files changed, 21 insertions(+), 22 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +8
-2@@ -48,6 +48,8 @@ static int panthor_clk_init(struct panthor_device *ptdev)void panthor_device_unplug (struct panthor_device *ptdev) { +int ret; +/* This function can be called from two different path: the reset work * and the platform device remove callback. drm_dev_unplug() doesn't * deal with concurrent callers, so we have to protect drm_dev_unplug() @@ -74,7 +76,8 @@ void panthor_device_unplug(struct panthor_device *ptdev)*/ mutex_unlock (&ptdev->unplug.lock); -drm_WARN_ON (&ptdev->base,pm_runtime_get_sync (ptdev->base.dev) <0 ); + ret =pm_runtime_get_sync (ptdev->base.dev); +drm_WARN_ON (&ptdev->base, ret <0 );/* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed. @@ -85,7 +88,10 @@ void panthor_device_unplug(struct panthor_device *ptdev)panthor_gpu_unplug (ptdev);pm_runtime_dont_use_autosuspend (ptdev->base.dev); -pm_runtime_put_sync_suspend (ptdev->base.dev); + +/* If the resume failed, we don't need to suspend here. */ +if (!ret) +pm_runtime_put_sync_suspend (ptdev->base.dev);/* If PM is disabled, we need to call the suspend handler manually. */ if (!IS_ENABLED (CONFIG_PM ))
drivers/gpu/drm/panthor/panthor_device.c int panthor_device_suspend(struct device *dev) · line 545
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_device.c +0
-2@@ -541,17 +547,4 @@ int panthor_device_suspend(struct device *dev)clk_disable_unprepare (ptdev->clks.core);atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED );return 0 ; - -err_set_active:
Label is being deleted here, but I don't see where the goto err_set_active is being removed.
Best regards,
Liviu
Quoted 83 lines
drivers/gpu/drm/panthor/panthor_device.c +0
-11-/* If something failed and we have to revert back to an -* active state, we also need to clear the MMIO userspace -* mappings, so any dumb pages that were mapped while we -* were trying to suspend gets invalidated. -*/ -mutex_lock (&ptdev->pm.mmio_lock); -atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_ACTIVE ); -unmap_mapping_range (ptdev->base.anon_inode->i_mapping, -DRM_PANTHOR_USER_MMIO_OFFSET ,0 ,1 ); -mutex_unlock (&ptdev->pm.mmio_lock); -return ret; }drivers/gpu/drm/panthor/panthor_fw.c +9
-5@@ -12,6 +12,7 @@#include <linux/iosys-map.h> #include <linux/mutex.h> #include <linux/platform_device.h> +#include <linux/pm_runtime.h> #include <drm/drm_drv.h> #include <drm/drm_managed.h> @@ -1188,11 +1189,13 @@ void panthor_fw_unplug(struct panthor_device *ptdev)cancel_delayed_work_sync (&ptdev->fw->watchdog.ping_work); -/* Make sure the IRQ handler can be called after that point. */ -if (ptdev->fw->irq.irq) -panthor_job_irq_suspend (&ptdev->fw->irq); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) { +/* Make sure the IRQ handler can be called after that point. */ +if (ptdev->fw->irq.irq) +panthor_job_irq_suspend (&ptdev->fw->irq); -panthor_fw_stop (ptdev); +panthor_fw_stop (ptdev); + }list_for_each_entry (section, &ptdev->fw->sections, node)panthor_kernel_bo_destroy (section->mem);@@ -1205,7 +1208,8 @@ void panthor_fw_unplug(struct panthor_device *ptdev)panthor_vm_put (ptdev->fw->vm); ptdev->fw->vm =NULL ; -panthor_gpu_power_off (ptdev,L2 , ptdev->gpu_info.l2_present,20000 ); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) +panthor_gpu_power_off (ptdev,L2 , ptdev->gpu_info.l2_present,20000 ); }/** drivers/gpu/drm/panthor/panthor_gpu.c +2
-1@@ -174,7 +174,8 @@ void panthor_gpu_unplug(struct panthor_device *ptdev)unsigned long flags;/* Make sure the IRQ handler is not running after that point. */ -panthor_gpu_irq_suspend (&ptdev->gpu->irq); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) +panthor_gpu_irq_suspend (&ptdev->gpu->irq);/* Wake-up all waiters. */ spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags);drivers/gpu/drm/panthor/panthor_mmu.c +2
-1@@ -2674,7 +2674,8 @@ int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec, struct panthor_vm*/ void panthor_mmu_unplug (struct panthor_device *ptdev) { -panthor_mmu_irq_suspend (&ptdev->mmu->irq); +if (!IS_ENABLED (CONFIG_PM ) ||pm_runtime_active (ptdev->base.dev)) +panthor_mmu_irq_suspend (&ptdev->mmu->irq);mutex_lock (&ptdev->mmu->as.slots_lock);for (u32 i =0 ; i <ARRAY_SIZE (ptdev->mmu->as.slots); i++) {Signature · 1 line
2.46.2
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Boris Brezillon
maintainerRe: [PATCH 2/5] drm/panthor: Be robust against runtime PM resume failures in the suspend path
Quoted 46 lines · On Thu, 14 Nov 2024 11:13:29 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 45 lines · Boris Brezillon
The runtime PM resume operation is not guaranteed to succeed, but if it fails, the device should be in a suspended state. Make sure we're robust to resume failures in the unplug path.
Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.c | 23 ++++++++--------------- drivers/gpu/drm/panthor/panthor_fw.c | 14 +++++++++----- drivers/gpu/drm/panthor/panthor_gpu.c | 3 ++- drivers/gpu/drm/panthor/panthor_mmu.c | 3 ++- 4 files changed, 21 insertions(+), 22 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +8
-2@@ -48,6 +48,8 @@ static int panthor_clk_init(struct panthor_device *ptdev)void panthor_device_unplug (struct panthor_device *ptdev) { +int ret; +/* This function can be called from two different path: the reset work * and the platform device remove callback. drm_dev_unplug() doesn't * deal with concurrent callers, so we have to protect drm_dev_unplug() @@ -74,7 +76,8 @@ void panthor_device_unplug(struct panthor_device *ptdev)*/ mutex_unlock (&ptdev->unplug.lock); -drm_WARN_ON (&ptdev->base,pm_runtime_get_sync (ptdev->base.dev) <0 ); + ret =pm_runtime_get_sync (ptdev->base.dev); +drm_WARN_ON (&ptdev->base, ret <0 );/* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed. @@ -85,7 +88,10 @@ void panthor_device_unplug(struct panthor_device *ptdev)panthor_gpu_unplug (ptdev);pm_runtime_dont_use_autosuspend (ptdev->base.dev); -pm_runtime_put_sync_suspend (ptdev->base.dev); + +/* If the resume failed, we don't need to suspend here. */ +if (!ret) +pm_runtime_put_sync_suspend (ptdev->base.dev);
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.c int panthor_device_suspend(struct device *dev) · line 545
Quoted 8 lines
drivers/gpu/drm/panthor/panthor_device.c +0
-2/* If PM is disabled, we need to call the suspend handler manually. */ if (!IS_ENABLED (CONFIG_PM ))@@ -541,17 +547,4 @@ int panthor_device_suspend(struct device *dev)clk_disable_unprepare (ptdev->clks.core);atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED );return 0 ; - -err_set_active:Label is being deleted here, but I don't see where the
goto err_set_activeis being removed.
Yes, as mentioned in my own reply, this chunk should be in patch 3.
Re: [PATCH 2/5] drm/panthor: Be robust against runtime PM resume failures in the suspend path
Quoted 60 lines · Boris Brezillon
Quoted 46 lines · On Thu, 14 Nov 2024 11:13:29 +0000 Liviu Dudau <[email protected]> wrote:
Quoted 45 lines · Boris Brezillon
The runtime PM resume operation is not guaranteed to succeed, but if it fails, the device should be in a suspended state. Make sure we're robust to resume failures in the unplug path.
Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.c | 23 ++++++++--------------- drivers/gpu/drm/panthor/panthor_fw.c | 14 +++++++++----- drivers/gpu/drm/panthor/panthor_gpu.c | 3 ++- drivers/gpu/drm/panthor/panthor_mmu.c | 3 ++- 4 files changed, 21 insertions(+), 22 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +8
-2@@ -48,6 +48,8 @@ static int panthor_clk_init(struct panthor_device *ptdev)void panthor_device_unplug (struct panthor_device *ptdev) { +int ret; +/* This function can be called from two different path: the reset work * and the platform device remove callback. drm_dev_unplug() doesn't * deal with concurrent callers, so we have to protect drm_dev_unplug() @@ -74,7 +76,8 @@ void panthor_device_unplug(struct panthor_device *ptdev)*/ mutex_unlock (&ptdev->unplug.lock); -drm_WARN_ON (&ptdev->base,pm_runtime_get_sync (ptdev->base.dev) <0 ); + ret =pm_runtime_get_sync (ptdev->base.dev); +drm_WARN_ON (&ptdev->base, ret <0 );/* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed. @@ -85,7 +88,10 @@ void panthor_device_unplug(struct panthor_device *ptdev)panthor_gpu_unplug (ptdev);pm_runtime_dont_use_autosuspend (ptdev->base.dev); -pm_runtime_put_sync_suspend (ptdev->base.dev); + +/* If the resume failed, we don't need to suspend here. */ +if (!ret) +pm_runtime_put_sync_suspend (ptdev->base.dev);Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.c int panthor_device_suspend(struct device *dev) · line 545
Quoted 8 lines
drivers/gpu/drm/panthor/panthor_device.c +0
-2/* If PM is disabled, we need to call the suspend handler manually. */ if (!IS_ENABLED (CONFIG_PM ))@@ -541,17 +547,4 @@ int panthor_device_suspend(struct device *dev)clk_disable_unprepare (ptdev->clks.core);atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED );return 0 ; - -err_set_active:Label is being deleted here, but I don't see where the
goto err_set_activeis being removed.
Quoted 1 line
Yes, as mentioned in my own reply, this chunk should be in patch 3.
Sorry, I did look at patch 3 before sending the email but somehow missed the line with the goto being deleted.
With the change:
Best regards,
Liviu
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Boris Brezillon
maintainerPATCH 3/5 drm/panthor: Ignore devfreq_{suspend, resume}_device() failures
In reply to Boris Brezillondevfreq_{resume,suspend}_device() don't bother undoing the suspend_count modifications if something fails, so either it assumes failures are harmless, or it's super fragile/buggy. In either case it's not something we can address at the driver level, so let's just assume failures are harmless for now, like is done in panfrost.
--- drivers/gpu/drm/panthor/panthor_devfreq.c | 12 ++++++------ drivers/gpu/drm/panthor/panthor_devfreq.h | 4 ++-- drivers/gpu/drm/panthor/panthor_device.c | 22 +++------------------- 3 files changed, 11 insertions(+), 27 deletions(-)
drivers/gpu/drm/panthor/panthor_devfreq.c +6 -6
@@ -244,26 +244,26 @@ int panthor_devfreq_init(struct panthor_device *ptdev)return 0 ; } -int panthor_devfreq_resume (struct panthor_device *ptdev) +void panthor_devfreq_resume (struct panthor_device *ptdev) {struct panthor_devfreq *pdevfreq = ptdev->devfreq;if (!pdevfreq->devfreq) -return 0 ; +return ;panthor_devfreq_reset (pdevfreq); -return devfreq_resume_device (pdevfreq->devfreq); +drm_WARN_ON (&ptdev->base,devfreq_resume_device (pdevfreq->devfreq)); } -int panthor_devfreq_suspend (struct panthor_device *ptdev) +void panthor_devfreq_suspend (struct panthor_device *ptdev) {struct panthor_devfreq *pdevfreq = ptdev->devfreq;if (!pdevfreq->devfreq) -return 0 ; +return ; -return devfreq_suspend_device (pdevfreq->devfreq); +drm_WARN_ON (&ptdev->base,devfreq_suspend_device (pdevfreq->devfreq)); }void panthor_devfreq_record_busy (struct panthor_device *ptdev)
drivers/gpu/drm/panthor/panthor_devfreq.h +2 -2
@@ -12,8 +12,8 @@ struct panthor_devfreq;int panthor_devfreq_init (struct panthor_device *ptdev); -int panthor_devfreq_resume (struct panthor_device *ptdev); -int panthor_devfreq_suspend (struct panthor_device *ptdev); +void panthor_devfreq_resume (struct panthor_device *ptdev); +void panthor_devfreq_suspend (struct panthor_device *ptdev);void panthor_devfreq_record_busy (struct panthor_device *ptdev);void panthor_devfreq_record_idle (struct panthor_device *ptdev);
drivers/gpu/drm/panthor/panthor_device.c +3 -19
@@ -439,9 +439,7 @@ int panthor_device_resume(struct device *dev)if (ret) goto err_disable_stacks_clk; - ret =panthor_devfreq_resume (ptdev); -if (ret) - goto err_disable_coregroup_clk; +panthor_devfreq_resume (ptdev);if (panthor_device_is_initialized (ptdev) &&drm_dev_enter (&ptdev->base, &cookie)) {
@@ -478,8 +476,6 @@ int panthor_device_resume(struct device *dev) err_suspend_devfreq:panthor_devfreq_suspend (ptdev); - -err_disable_coregroup_clk:clk_disable_unprepare (ptdev->clks.coregroup); err_disable_stacks_clk:
@@ -496,7 +492,7 @@ int panthor_device_resume(struct device *dev)int panthor_device_suspend (struct device *dev) {struct panthor_device *ptdev =dev_get_drvdata (dev); -int ret, cookie; +int cookie;if (atomic_read (&ptdev->pm.state) !=PANTHOR_DEVICE_PM_STATE_ACTIVE )return -EINVAL ;
@@ -528,19 +524,7 @@ int panthor_device_suspend(struct device *dev)drm_dev_exit (cookie); } - ret =panthor_devfreq_suspend (ptdev); -if (ret) { -if (panthor_device_is_initialized (ptdev) && -drm_dev_enter (&ptdev->base, &cookie)) { -panthor_gpu_resume (ptdev); -panthor_mmu_resume (ptdev); -drm_WARN_ON (&ptdev->base,panthor_fw_resume (ptdev)); -panthor_sched_resume (ptdev); -drm_dev_exit (cookie); - } - - goto err_set_active; - } +panthor_devfreq_suspend (ptdev);clk_disable_unprepare (ptdev->clks.coregroup);clk_disable_unprepare (ptdev->clks.stacks);
Signature · 1 line
2.46.2
Re: [PATCH 3/5] drm/panthor: Ignore devfreq_{suspend, resume}_device() failures
Quoted 7 lines · Boris Brezillon
devfreq_{resume,suspend}_device() don't bother undoing the
suspend_countmodifications if something fails, so either it assumes failures are harmless, or it's super fragile/buggy. In either case it's not something we can address at the driver level, so let's just assume failures are harmless for now, like is done in panfrost.Signed-off-by Boris Brezillon <[email protected]>
With the missing chunk from patch 2:
Quoted 112 lines
--- drivers/gpu/drm/panthor/panthor_devfreq.c | 12 ++++++------ drivers/gpu/drm/panthor/panthor_devfreq.h | 4 ++-- drivers/gpu/drm/panthor/panthor_device.c | 22 +++------------------- 3 files changed, 11 insertions(+), 27 deletions(-)drivers/gpu/drm/panthor/panthor_devfreq.c +6
-6@@ -244,26 +244,26 @@ int panthor_devfreq_init(struct panthor_device *ptdev)return 0 ; } -int panthor_devfreq_resume (struct panthor_device *ptdev) +void panthor_devfreq_resume (struct panthor_device *ptdev) {struct panthor_devfreq *pdevfreq = ptdev->devfreq;if (!pdevfreq->devfreq) -return 0 ; +return ;panthor_devfreq_reset (pdevfreq); -return devfreq_resume_device (pdevfreq->devfreq); +drm_WARN_ON (&ptdev->base,devfreq_resume_device (pdevfreq->devfreq)); } -int panthor_devfreq_suspend (struct panthor_device *ptdev) +void panthor_devfreq_suspend (struct panthor_device *ptdev) {struct panthor_devfreq *pdevfreq = ptdev->devfreq;if (!pdevfreq->devfreq) -return 0 ; +return ; -return devfreq_suspend_device (pdevfreq->devfreq); +drm_WARN_ON (&ptdev->base,devfreq_suspend_device (pdevfreq->devfreq)); }void panthor_devfreq_record_busy (struct panthor_device *ptdev)drivers/gpu/drm/panthor/panthor_devfreq.h +2
-2@@ -12,8 +12,8 @@ struct panthor_devfreq;int panthor_devfreq_init (struct panthor_device *ptdev); -int panthor_devfreq_resume (struct panthor_device *ptdev); -int panthor_devfreq_suspend (struct panthor_device *ptdev); +void panthor_devfreq_resume (struct panthor_device *ptdev); +void panthor_devfreq_suspend (struct panthor_device *ptdev);void panthor_devfreq_record_busy (struct panthor_device *ptdev);void panthor_devfreq_record_idle (struct panthor_device *ptdev);drivers/gpu/drm/panthor/panthor_device.c +3
-19@@ -439,9 +439,7 @@ int panthor_device_resume(struct device *dev)if (ret) goto err_disable_stacks_clk; - ret =panthor_devfreq_resume (ptdev); -if (ret) - goto err_disable_coregroup_clk; +panthor_devfreq_resume (ptdev);if (panthor_device_is_initialized (ptdev) &&drm_dev_enter (&ptdev->base, &cookie)) {@@ -478,8 +476,6 @@ int panthor_device_resume(struct device *dev) err_suspend_devfreq:panthor_devfreq_suspend (ptdev); - -err_disable_coregroup_clk:clk_disable_unprepare (ptdev->clks.coregroup); err_disable_stacks_clk:@@ -496,7 +492,7 @@ int panthor_device_resume(struct device *dev)int panthor_device_suspend (struct device *dev) {struct panthor_device *ptdev =dev_get_drvdata (dev); -int ret, cookie; +int cookie;if (atomic_read (&ptdev->pm.state) !=PANTHOR_DEVICE_PM_STATE_ACTIVE )return -EINVAL ;@@ -528,19 +524,7 @@ int panthor_device_suspend(struct device *dev)drm_dev_exit (cookie); } - ret =panthor_devfreq_suspend (ptdev); -if (ret) { -if (panthor_device_is_initialized (ptdev) && -drm_dev_enter (&ptdev->base, &cookie)) { -panthor_gpu_resume (ptdev); -panthor_mmu_resume (ptdev); -drm_WARN_ON (&ptdev->base,panthor_fw_resume (ptdev)); -panthor_sched_resume (ptdev); -drm_dev_exit (cookie); - } - - goto err_set_active; - } +panthor_devfreq_suspend (ptdev);clk_disable_unprepare (ptdev->clks.coregroup);clk_disable_unprepare (ptdev->clks.stacks);
Boris Brezillon
maintainerPATCH 4/5 drm/panthor: Be robust against resume failures
In reply to Boris BrezillonWhen the runtime PM resume callback returns an error, it puts the device in a state where it can't be resumed anymore. Make sure we can recover from such transient failures by calling pm_runtime_set_suspended() explicitly after a pm_runtime_resume_and_get() failure.
--- drivers/gpu/drm/panthor/panthor_device.c | 1 + drivers/gpu/drm/panthor/panthor_device.h | 17 +++++++++++++++++ drivers/gpu/drm/panthor/panthor_drv.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/panthor/panthor_device.c +1 -0
@@ -486,6 +486,7 @@ int panthor_device_resume(struct device *dev) err_set_suspended:atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED ); +atomic_set (&ptdev->pm.recovery_needed,1 );return ret; }
drivers/gpu/drm/panthor/panthor_device.h +17 -0
@@ -9,6 +9,7 @@#include <linux/atomic.h> #include <linux/io-pgtable.h> #include <linux/regulator/consumer.h> +#include <linux/pm_runtime.h> #include <linux/sched.h> #include <linux/spinlock.h>
@@ -180,6 +181,9 @@ struct panthor_device {* is suspended. */ struct page *dummy_latest_flush; + +/** @recovery_needed: True when a resume attempt failed. */ +atomic_t recovery_needed; } pm;/** @profile_mask: User-set profiling flags for job accounting. */
@@ -243,6 +247,19 @@ int panthor_device_mmap_io(struct panthor_device *ptdev,int panthor_device_resume (struct device *dev);int panthor_device_suspend (struct device *dev); +static inline int panthor_device_resume_and_get (struct panthor_device *ptdev) +{ +int ret =pm_runtime_resume_and_get (ptdev->base.dev); + +/* If the resume failed, we need to clear the runtime_error, which we +* can done by forcing the RPM state to suspended. +*/ +if (ret &&atomic_cmpxchg (&ptdev->pm.recovery_needed,1 ,0 ) ==1 ) +pm_runtime_set_suspended (ptdev->base.dev); + +return ret; +} +enum drm_panthor_exception_type {DRM_PANTHOR_EXCEPTION_OK =0x00 ,DRM_PANTHOR_EXCEPTION_TERMINATED =0x04 ,
drivers/gpu/drm/panthor/panthor_drv.c +1 -1
@@ -763,7 +763,7 @@ static int panthor_query_timestamp_info(struct panthor_device *ptdev, {int ret; - ret =pm_runtime_resume_and_get (ptdev->base.dev); + ret =panthor_device_resume_and_get (ptdev);if (ret)return ret;
drivers/gpu/drm/panthor/panthor_sched.c +2 -2
@@ -2364,7 +2364,7 @@ static void tick_work(struct work_struct *work)if (!drm_dev_enter (&ptdev->base, &cookie))return ; - ret =pm_runtime_resume_and_get (ptdev->base.dev); + ret =panthor_device_resume_and_get (ptdev);if (drm_WARN_ON (&ptdev->base, ret)) goto out_dev_exit;
@@ -3131,7 +3131,7 @@ queue_run_job(struct drm_sched_job *sched_job)return dma_fence_get (job->done_fence); } - ret =pm_runtime_resume_and_get (ptdev->base.dev); + ret =panthor_device_resume_and_get (ptdev);if (drm_WARN_ON (&ptdev->base, ret))return ERR_PTR (ret);
Signature · 1 line
2.46.2
Steven Price
maintainerRe: [PATCH 4/5] drm/panthor: Be robust against resume failures
Quoted 49 lines · Boris Brezillon
When the runtime PM resume callback returns an error, it puts the device in a state where it can't be resumed anymore. Make sure we can recover from such transient failures by calling
pm_runtime_set_suspended()explicitly after apm_runtime_resume_and_get()failure.Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.c | 1 + drivers/gpu/drm/panthor/panthor_device.h | 17 +++++++++++++++++ drivers/gpu/drm/panthor/panthor_drv.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +1
-0@@ -486,6 +486,7 @@ int panthor_device_resume(struct device *dev) err_set_suspended:atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED ); +atomic_set (&ptdev->pm.recovery_needed,1 );return ret; }drivers/gpu/drm/panthor/panthor_device.h +4
-0@@ -9,6 +9,7 @@#include <linux/atomic.h> #include <linux/io-pgtable.h> #include <linux/regulator/consumer.h> +#include <linux/pm_runtime.h> #include <linux/sched.h> #include <linux/spinlock.h> @@ -180,6 +181,9 @@ struct panthor_device {* is suspended. */ struct page *dummy_latest_flush; + +/** @recovery_needed: True when a resume attempt failed. */ +atomic_t recovery_needed; } pm;/** @profile_mask: User-set profiling flags for job accounting. */ @@ -243,6 +247,19 @@ int panthor_device_mmap_io(struct panthor_device *ptdev,int panthor_device_resume (struct device *dev);
drivers/gpu/drm/panthor/panthor_device.h int panthor_device_mmap_io(struct panthor_device *ptdev, · line 257
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.h +8
-0int panthor_device_suspend (struct device *dev); +static inline int panthor_device_resume_and_get (struct panthor_device *ptdev) +{ +int ret =pm_runtime_resume_and_get (ptdev->base.dev); + +/* If the resume failed, we need to clear the runtime_error, which we +* can done by forcing the RPM state to suspended. +*/ +if (ret &&atomic_cmpxchg (&ptdev->pm.recovery_needed,1 ,0 ) ==1 )
I'm unclear what this atomic achieves. At first glance it appears
pointless: with this change if panthor_device_resume() fails then recovery_needed is set to 1. So logically if ret != 0 then also recovery_needed == 1.
My second thought was is this to avoid races? If multiple threads are calling this then only one will win the cmpxchg and call pm_runtime_set_suspended. But it's not safe - it's quite possible for the first thread to get past the cmpxchg and be suspended before the second thread comes along and reaches the same point - leading to multiple calls to pm_runtime_set_suspended().
So I'm afraid I don't understand this atomic - what am I missing?
Thanks,
Steve
Quoted 43 lines
drivers/gpu/drm/panthor/panthor_device.h +5
-0+pm_runtime_set_suspended (ptdev->base.dev); + +return ret; +} +enum drm_panthor_exception_type {DRM_PANTHOR_EXCEPTION_OK =0x00 ,DRM_PANTHOR_EXCEPTION_TERMINATED =0x04 ,drivers/gpu/drm/panthor/panthor_drv.c +1
-1@@ -763,7 +763,7 @@ static int panthor_query_timestamp_info(struct panthor_device *ptdev, {int ret; - ret =pm_runtime_resume_and_get (ptdev->base.dev); + ret =panthor_device_resume_and_get (ptdev);if (ret)return ret;drivers/gpu/drm/panthor/panthor_sched.c +2
-2@@ -2364,7 +2364,7 @@ static void tick_work(struct work_struct *work)if (!drm_dev_enter (&ptdev->base, &cookie))return ; - ret =pm_runtime_resume_and_get (ptdev->base.dev); + ret =panthor_device_resume_and_get (ptdev);if (drm_WARN_ON (&ptdev->base, ret)) goto out_dev_exit;@@ -3131,7 +3131,7 @@ queue_run_job(struct drm_sched_job *sched_job)return dma_fence_get (job->done_fence); } - ret =pm_runtime_resume_and_get (ptdev->base.dev); + ret =panthor_device_resume_and_get (ptdev);if (drm_WARN_ON (&ptdev->base, ret))return ERR_PTR (ret);
Boris Brezillon
maintainerRe: [PATCH 4/5] drm/panthor: Be robust against resume failures
Quoted 66 lines · On Thu, 14 Nov 2024 10:51:01 +0000 Steven Price <[email protected]> wrote:
Quoted 49 lines · Boris Brezillon
When the runtime PM resume callback returns an error, it puts the device in a state where it can't be resumed anymore. Make sure we can recover from such transient failures by calling
pm_runtime_set_suspended()explicitly after apm_runtime_resume_and_get()failure.Signed-off-by Boris Brezillon <[email protected]>--- drivers/gpu/drm/panthor/panthor_device.c | 1 + drivers/gpu/drm/panthor/panthor_device.h | 17 +++++++++++++++++ drivers/gpu/drm/panthor/panthor_drv.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +1
-0@@ -486,6 +486,7 @@ int panthor_device_resume(struct device *dev) err_set_suspended:atomic_set (&ptdev->pm.state,PANTHOR_DEVICE_PM_STATE_SUSPENDED ); +atomic_set (&ptdev->pm.recovery_needed,1 );return ret; }drivers/gpu/drm/panthor/panthor_device.h +4
-0@@ -9,6 +9,7 @@#include <linux/atomic.h> #include <linux/io-pgtable.h> #include <linux/regulator/consumer.h> +#include <linux/pm_runtime.h> #include <linux/sched.h> #include <linux/spinlock.h> @@ -180,6 +181,9 @@ struct panthor_device {* is suspended. */ struct page *dummy_latest_flush; + +/** @recovery_needed: True when a resume attempt failed. */ +atomic_t recovery_needed; } pm;/** @profile_mask: User-set profiling flags for job accounting. */ @@ -243,6 +247,19 @@ int panthor_device_mmap_io(struct panthor_device *ptdev,int panthor_device_resume (struct device *dev);drivers/gpu/drm/panthor/panthor_device.h int panthor_device_mmap_io(struct panthor_device *ptdev, · line 257
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.h +8
-0int panthor_device_suspend (struct device *dev); +static inline int panthor_device_resume_and_get (struct panthor_device *ptdev) +{ +int ret =pm_runtime_resume_and_get (ptdev->base.dev); + +/* If the resume failed, we need to clear the runtime_error, which we +* can done by forcing the RPM state to suspended. +*/ +if (ret &&atomic_cmpxchg (&ptdev->pm.recovery_needed,1 ,0 ) ==1 )I'm unclear what this atomic achieves. At first glance it appears
pointless: with this change ifpanthor_device_resume()fails thenrecovery_neededis set to 1. So logically if ret != 0 then alsorecovery_needed== 1.
Quoted 6 lines
My second thought was is this to avoid races? If multiple threads are calling this then only one will win the cmpxchg and call
pm_runtime_set_suspended. But it's not safe - it's quite possible for the first thread to get past the cmpxchg and be suspended before the second thread comes along and reaches the same point - leading to multiple calls topm_runtime_set_suspended().
Yes, it was here to avoid the race. I don't think there's a risk of multiple threads calling pm_runtime_set_suspended() without actually needing such a call, because we won't reach panthor_device_resume() until the runtime_error has been cleared (runtime PM bails out early with a -EINVAL). So, in practice, there's no way two threads can see a recovery_needed=1 unless the error has already been cleared by the other thread and the second thread triggered another resume error, in which case the second pm_runtime_set_suspended() call is legit.
But now that you mention it, it indeed doesn't prevent the second thread to call pm_runtime_resume_and_get() before the PM runtime_error has been cleared, leading to potential spurious errors, so that's annoying.
Boris Brezillon
maintainerPATCH 5/5 drm/panthor: Fix the fast-reset logic
In reply to Boris BrezillonIf we do a GPU soft-reset, that's no longer fast reset. This also means the slow reset fallback doesn't work because the MCU state is only reset after a GPU soft-reset.
Let's move the retry logic to panthor_device_resume() to issue a soft-reset between the fast and slow attempts, and patch panthor_gpu_suspend() to only power-off the L2 when a fast reset is requested.
--- drivers/gpu/drm/panthor/panthor_device.c | 32 ++++++++++++---- drivers/gpu/drm/panthor/panthor_device.h | 11 ++++++ drivers/gpu/drm/panthor/panthor_fw.c | 48 ++++-------------------- drivers/gpu/drm/panthor/panthor_gpu.c | 11 +++--- 4 files changed, 49 insertions(+), 53 deletions(-)
drivers/gpu/drm/panthor/panthor_device.c +24 -8
@@ -417,6 +417,22 @@ int panthor_device_mmap_io(struct panthor_device *ptdev, struct vm_area_struct *return 0 ; } +static int panthor_device_resume_hw_components (struct panthor_device *ptdev) +{ +int ret; + +panthor_gpu_resume (ptdev); +panthor_mmu_resume (ptdev); + + ret =panthor_fw_resume (ptdev); +if (!ret) +return 0 ; + +panthor_mmu_suspend (ptdev); +panthor_gpu_suspend (ptdev); +return ret; +} +int panthor_device_resume (struct device *dev) {struct panthor_device *ptdev =dev_get_drvdata (dev);
@@ -443,16 +459,16 @@ int panthor_device_resume(struct device *dev)if (panthor_device_is_initialized (ptdev) &&drm_dev_enter (&ptdev->base, &cookie)) { -panthor_gpu_resume (ptdev); -panthor_mmu_resume (ptdev); - ret =panthor_fw_resume (ptdev); -if (!drm_WARN_ON (&ptdev->base, ret)) { -panthor_sched_resume (ptdev); - }else { -panthor_mmu_suspend (ptdev); -panthor_gpu_suspend (ptdev); + ret =panthor_device_resume_hw_components (ptdev); +if (ret && ptdev->reset.fast) { +drm_err (&ptdev->base,"Fast reset failed, trying a slow reset" ); + ptdev->reset.fast = false; + ret =panthor_device_resume_hw_components (ptdev); } +if (!ret) +panthor_sched_resume (ptdev); +drm_dev_exit (cookie);if (ret)
drivers/gpu/drm/panthor/panthor_device.h +11 -0
@@ -157,6 +157,17 @@ struct panthor_device {/** @pending: Set to true if a reset is pending. */ atomic_t pending; + +/** +* @fast: True if the post_reset logic can proceed with a fast reset. +* +* A fast reset is just a reset where the driver doesn't reload the FW sections. +* +* Any time the firmware is properly suspended, a fast reset can take place. +* On the other hand, if the halt operation failed, the driver will reload +* all FW sections to make sure we start from a fresh state. +*/ +bool fast; } reset;/** @pm: Power management related data. */
drivers/gpu/drm/panthor/panthor_fw.c +8 -40
80 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_gpu.c +6 -5
@@ -461,11 +461,12 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)*/ void panthor_gpu_suspend (struct panthor_device *ptdev) { -/* -* It may be preferable to simply power down the L2, but for now just -* soft-reset which will leave the L2 powered down. -*/ -panthor_gpu_soft_reset (ptdev); +/* On a fast reset, simply power down the L2. */ +if (!ptdev->reset.fast) +panthor_gpu_soft_reset (ptdev); +else +panthor_gpu_power_off (ptdev,L2 ,1 ,20000 ); +panthor_gpu_irq_suspend (&ptdev->gpu->irq); }
Signature · 1 line
2.46.2
Re: [PATCH 5/5] drm/panthor: Fix the fast-reset logic
Quoted 10 lines · Boris Brezillon
If we do a GPU soft-reset, that's no longer fast reset. This also means the slow reset fallback doesn't work because the MCU state is only reset after a GPU soft-reset.
Let's move the retry logic to
panthor_device_resume()to issue a soft-reset between the fast and slow attempts, and patchpanthor_gpu_suspend()to only power-off the L2 when a fast reset is requested.Signed-off-by Boris Brezillon <[email protected]>
I also don't have a good way of testing this, but it looks right and it doesn't blow up in the "normal" case, so:
Quoted 191 lines
--- drivers/gpu/drm/panthor/panthor_device.c | 32 ++++++++++++---- drivers/gpu/drm/panthor/panthor_device.h | 11 ++++++ drivers/gpu/drm/panthor/panthor_fw.c | 48 ++++-------------------- drivers/gpu/drm/panthor/panthor_gpu.c | 11 +++--- 4 files changed, 49 insertions(+), 53 deletions(-)drivers/gpu/drm/panthor/panthor_device.c +24
-8@@ -417,6 +417,22 @@ int panthor_device_mmap_io(struct panthor_device *ptdev, struct vm_area_struct *return 0 ; } +static int panthor_device_resume_hw_components (struct panthor_device *ptdev) +{ +int ret; + +panthor_gpu_resume (ptdev); +panthor_mmu_resume (ptdev); + + ret =panthor_fw_resume (ptdev); +if (!ret) +return 0 ; + +panthor_mmu_suspend (ptdev); +panthor_gpu_suspend (ptdev); +return ret; +} +int panthor_device_resume (struct device *dev) {struct panthor_device *ptdev =dev_get_drvdata (dev);@@ -443,16 +459,16 @@ int panthor_device_resume(struct device *dev)if (panthor_device_is_initialized (ptdev) &&drm_dev_enter (&ptdev->base, &cookie)) { -panthor_gpu_resume (ptdev); -panthor_mmu_resume (ptdev); - ret =panthor_fw_resume (ptdev); -if (!drm_WARN_ON (&ptdev->base, ret)) { -panthor_sched_resume (ptdev); - }else { -panthor_mmu_suspend (ptdev); -panthor_gpu_suspend (ptdev); + ret =panthor_device_resume_hw_components (ptdev); +if (ret && ptdev->reset.fast) { +drm_err (&ptdev->base,"Fast reset failed, trying a slow reset" ); + ptdev->reset.fast = false; + ret =panthor_device_resume_hw_components (ptdev); } +if (!ret) +panthor_sched_resume (ptdev); +drm_dev_exit (cookie);if (ret)drivers/gpu/drm/panthor/panthor_device.h +11
-0@@ -157,6 +157,17 @@ struct panthor_device {/** @pending: Set to true if a reset is pending. */ atomic_t pending; + +/** +* @fast: True if the post_reset logic can proceed with a fast reset. +* +* A fast reset is just a reset where the driver doesn't reload the FW sections. +* +* Any time the firmware is properly suspended, a fast reset can take place. +* On the other hand, if the halt operation failed, the driver will reload +* all FW sections to make sure we start from a fresh state. +*/ +bool fast; } reset;/** @pm: Power management related data. */ drivers/gpu/drm/panthor/panthor_fw.c +8
-40@@ -263,17 +263,6 @@ struct panthor_fw {/** @booted: True is the FW is booted */ bool booted; -/** -* @fast_reset: True if the post_reset logic can proceed with a fast reset. -* -* A fast reset is just a reset where the driver doesn't reload the FW sections. -* -* Any time the firmware is properly suspended, a fast reset can take place. -* On the other hand, if the halt operation failed, the driver will reload -* all sections to make sure we start from a fresh state. -*/ -bool fast_reset; -/** @irq: Job irq data. */ struct panthor_irq irq; };@@ -1090,7 +1079,7 @@ void panthor_fw_pre_reset(struct panthor_device *ptdev, bool on_hang)/* Make sure we won't be woken up by a ping. */ cancel_delayed_work_sync (&ptdev->fw->watchdog.ping_work); - ptdev->fw->fast_reset = false; + ptdev->reset.fast = false;if (!on_hang) {struct panthor_fw_global_iface *glb_iface =panthor_fw_get_glb_iface (ptdev);@@ -1101,7 +1090,7 @@ void panthor_fw_pre_reset(struct panthor_device *ptdev, bool on_hang)if (!readl_poll_timeout (ptdev->iomem +MCU_STATUS , status, status ==MCU_STATUS_HALT ,10 ,100000 ) && glb_iface->output->halt_status ==PANTHOR_FW_HALT_OK ) { - ptdev->fw->fast_reset = true; + ptdev->reset.fast = true; }else {drm_warn (&ptdev->base,"Failed to cleanly suspend MCU" ); }@@ -1131,41 +1120,20 @@ int panthor_fw_post_reset(struct panthor_device *ptdev)if (ret)return ret; -/* If this is a fast reset, try to start the MCU without reloading -* the FW sections. If it fails, go for a full reset. -*/ -if (ptdev->fw->fast_reset) { - ret =panthor_fw_start (ptdev); -if (!ret) - goto out; - -/* Forcibly reset the MCU and force a slow reset, so we get a -* fresh boot on the next panthor_fw_start() call. -*/ -panthor_fw_stop (ptdev); - ptdev->fw->fast_reset = false; -drm_err (&ptdev->base,"FW fast reset failed, trying a slow reset" ); - - ret =panthor_vm_flush_all (ptdev->fw->vm); -if (ret) { -drm_err (&ptdev->base,"FW slow reset failed (couldn't flush FW's AS l2cache)" ); -return ret; - } - } - -/* Reload all sections, including RO ones. We're not supposed -* to end up here anyway, let's just assume the overhead of +/* On a slow reset, reload all sections, including RO ones. We're not +* supposed to end up here anyway, let's just assume the overhead of * reloading everything is acceptable. */ -panthor_reload_fw_sections (ptdev, true); +if (!ptdev->reset.fast) +panthor_reload_fw_sections (ptdev, true); ret =panthor_fw_start (ptdev);if (ret) { -drm_err (&ptdev->base,"FW slow reset failed (couldn't start the FW )" ); +drm_err (&ptdev->base,"FW %s reset failed" , + ptdev->reset.fast ?"fast" :"slow" );return ret; } -out:/* We must re-initialize the global interface even on fast-reset. */ panthor_fw_init_global_iface (ptdev);return 0 ;drivers/gpu/drm/panthor/panthor_gpu.c +6
-5@@ -461,11 +461,12 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)*/ void panthor_gpu_suspend (struct panthor_device *ptdev) { -/* -* It may be preferable to simply power down the L2, but for now just -* soft-reset which will leave the L2 powered down. -*/ -panthor_gpu_soft_reset (ptdev); +/* On a fast reset, simply power down the L2. */ +if (!ptdev->reset.fast) +panthor_gpu_soft_reset (ptdev); +else +panthor_gpu_power_off (ptdev,L2 ,1 ,20000 ); +panthor_gpu_irq_suspend (&ptdev->gpu->irq); }