All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/imagination: retry runtime idle when firmware is not yet idle
@ 2026-10-29  8:38 ` Baihui Liang
  0 siblings, 0 replies; 3+ messages in thread
From: Baihui Liang @ 2026-10-29  8:38 UTC (permalink / raw)
  To: Alessio Belle, Luigi Santivetti, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Yixun Lan,
	Troy Mitchell
  Cc: imagination, dri-devel, linux-kernel, linux-riscv, spacemit,
	Baihui Liang

Returning -EBUSY from ->runtime_idle() prevents the PM core from
retrying the idle check. Schedule an autosuspend so the idle state
can be re-evaluated once the firmware reaches ROGUE_FWIF_POW_IDLE.

Signed-off-by: Baihui Liang <liangbaihui@linux.spacemit.com>
---
Tested on SpacemiT K3 (PowerVR Rogue BXM-4-64) by running vulkaninfo
repeatedly. Without this change the device intermittently stayed
runtime-active after the last user went away, because the firmware had
not yet reached ROGUE_FWIF_POW_IDLE when the idle check ran. With the
change the device reliably suspends.
---
 drivers/gpu/drm/imagination/pvr_power.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c
index eb4b6ecdf4f..6f38249ffcb 100644
--- a/drivers/gpu/drm/imagination/pvr_power.c
+++ b/drivers/gpu/drm/imagination/pvr_power.c
@@ -434,7 +434,16 @@ pvr_power_device_idle(struct device *dev)
 	struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
 	struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
 
-	return pvr_power_is_idle(pvr_dev) ? 0 : -EBUSY;
+	if (pvr_power_is_idle(pvr_dev))
+		return 0;
+
+	/*
+	 * Firmware not yet idle; reject but schedule autosuspend so
+	 * runtime_idle() can be retried.
+	 */
+	pm_runtime_autosuspend(dev);
+
+	return -EBUSY;
 }
 
 static int

---
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
change-id: 20261029-img-pm-autosuspend-7772d83416f7

Best regards,
--  
Baihui Liang <liangbaihui@linux.spacemit.com>


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] drm/imagination: retry runtime idle when firmware is not yet idle
@ 2026-10-29  8:38 ` Baihui Liang
  0 siblings, 0 replies; 3+ messages in thread
From: Baihui Liang @ 2026-10-29  8:38 UTC (permalink / raw)
  To: Alessio Belle, Luigi Santivetti, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Yixun Lan,
	Troy Mitchell
  Cc: imagination, dri-devel, linux-kernel, linux-riscv, spacemit,
	Baihui Liang

Returning -EBUSY from ->runtime_idle() prevents the PM core from
retrying the idle check. Schedule an autosuspend so the idle state
can be re-evaluated once the firmware reaches ROGUE_FWIF_POW_IDLE.

Signed-off-by: Baihui Liang <liangbaihui@linux.spacemit.com>
---
Tested on SpacemiT K3 (PowerVR Rogue BXM-4-64) by running vulkaninfo
repeatedly. Without this change the device intermittently stayed
runtime-active after the last user went away, because the firmware had
not yet reached ROGUE_FWIF_POW_IDLE when the idle check ran. With the
change the device reliably suspends.
---
 drivers/gpu/drm/imagination/pvr_power.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c
index eb4b6ecdf4f..6f38249ffcb 100644
--- a/drivers/gpu/drm/imagination/pvr_power.c
+++ b/drivers/gpu/drm/imagination/pvr_power.c
@@ -434,7 +434,16 @@ pvr_power_device_idle(struct device *dev)
 	struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
 	struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
 
-	return pvr_power_is_idle(pvr_dev) ? 0 : -EBUSY;
+	if (pvr_power_is_idle(pvr_dev))
+		return 0;
+
+	/*
+	 * Firmware not yet idle; reject but schedule autosuspend so
+	 * runtime_idle() can be retried.
+	 */
+	pm_runtime_autosuspend(dev);
+
+	return -EBUSY;
 }
 
 static int

---
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
change-id: 20261029-img-pm-autosuspend-7772d83416f7

Best regards,
--  
Baihui Liang <liangbaihui@linux.spacemit.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/imagination: retry runtime idle when firmware is not yet idle
  2026-10-29  8:38 ` Baihui Liang
  (?)
@ 2026-10-29  8:58 ` sashiko-bot
  -1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-29  8:58 UTC (permalink / raw)
  To: Baihui Liang; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/imagination: pvr_power_device_idle() bypasses idle check on autosuspend
--

commit 21bc022f1187eccd547ba4f832837505cc945974
Author: Baihui Liang <liangbaihui@linux.spacemit.com>

drm/imagination: retry runtime idle when firmware is not yet idle

This patch modifies pvr_power_device_idle() to call pm_runtime_autosuspend()
before returning -EBUSY when pvr_power_is_idle() returns false, aiming to
retry the idle check once the firmware reaches ROGUE_FWIF_POW_IDLE.

> diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c
> index eb4b6ecdf4f4d..6f38249ffcb72 100644
> --- a/drivers/gpu/drm/imagination/pvr_power.c
> +++ b/drivers/gpu/drm/imagination/pvr_power.c
> @@ -434,7 +434,16 @@ pvr_power_device_idle(struct device *dev)
>  	struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
>  	struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
>  
> -	return pvr_power_is_idle(pvr_dev) ? 0 : -EBUSY;
> +	if (pvr_power_is_idle(pvr_dev))
> +		return 0;
> +
> +	/*
> +	 * Firmware not yet idle; reject but schedule autosuspend so
> +	 * runtime_idle() can be retried.
> +	 */
> +	pm_runtime_autosuspend(dev);
> +
> +	return -EBUSY;
>  }

[Severity: High]
Does calling pm_runtime_autosuspend() from pvr_power_device_idle() actually
retry the ->runtime_idle() callback, or does it bypass the idle check and run
pvr_power_device_suspend() directly?

Looking at pm_runtime_autosuspend() in include/linux/pm_runtime.h:

static inline int pm_runtime_autosuspend(struct device *dev)
{
	pm_runtime_mark_last_busy(dev);
	return __pm_runtime_suspend(dev, RPM_AUTO);
}

When pvr_power_device_idle() calls pm_runtime_autosuspend() because
pvr_power_is_idle() returned false (for example, when pvr_kccb_send_cmd()
in drivers/gpu/drm/imagination/pvr_ccb.c drops its runtime PM reference via
pvr_power_put() while a caller is still waiting in
pvr_kccb_wait_for_completion(), or while firmware has not yet transitioned
to ROGUE_FWIF_POW_IDLE), __pm_runtime_suspend(dev, RPM_AUTO) invokes
rpm_suspend(dev, RPM_AUTO).

When the autosuspend delay is non-zero, rpm_suspend() arms
dev->power.suspend_timer with dev->power.timer_autosuspends = 1, and
returning -EBUSY from pvr_power_device_idle() to rpm_idle() does not cancel
that timer. When the timer fires, pm_suspend_timer_fn() in
drivers/base/power/runtime.c runs:

	if (expires > 0 && expires <= ktime_get_mono_fast_ns()) {
		dev->power.timer_expires = 0;
		rpm_suspend(dev, dev->power.timer_autosuspends ?
		    (RPM_ASYNC | RPM_AUTO) : RPM_ASYNC);
	}

This queues RPM_REQ_AUTOSUSPEND on pm_wq, which calls rpm_suspend() ->
pvr_power_device_suspend() directly without calling rpm_idle() or
pvr_power_device_idle().

Because pvr_power_device_suspend() in drivers/gpu/drm/imagination/pvr_power.c
does not check pvr_power_is_idle():

int
pvr_power_device_suspend(struct device *dev)
{
	...
	if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
		err = pvr_power_fw_disable(pvr_dev, false, true);

won't the driver unconditionally disable firmware when the autosuspend timer
expires, even if the firmware or KCCB is still busy?

Furthermore, if pm_runtime_autosuspend_expiration() returns 0 when
pm_runtime_autosuspend() is called (for example, if autosuspend_delay_ms is
set to 0 via sysfs), __pm_runtime_suspend(dev, RPM_AUTO) is synchronous and
will execute pvr_power_device_suspend() immediately from inside
pvr_power_device_idle() right after pvr_power_is_idle() returned false.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261029-img-pm-autosuspend-v1-1-26851840a34e@linux.spacemit.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-29  8:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29  8:38 [PATCH] drm/imagination: retry runtime idle when firmware is not yet idle Baihui Liang
2026-10-29  8:38 ` Baihui Liang
2026-10-29  8:58 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.