Skip to contentSkip to conversation

drm/amdgpu: don't runtime suspend if there are displays attached (v2)

PATCH In review Alex Deucher 5 participants 8 messages Apr 13, 2022 – Apr 21, 2022

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: don't runtime suspend if there are displays attached (v2)

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."), the driver took a runtime pm reference when the fbdev emulation was
enabled because we didn't implement proper shadowing support for
vram access when the device was off so the device never runtime
suspended when there was a console bound. Once that commit landed,
we now utilize the core fb helper implementation which properly
handles the emulation, so runtime pm now suspends in cases where it did
not before. Ultimately, we need to sort out why runtime suspend in not
working in this case for some users, but this should restore similar
behavior to before.

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's.")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++--------
 1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +72 -35
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device *dev)
 	return amdgpu_device_resume(drm_dev, true);
 }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct drm_device *drm_dev = pci_get_drvdata(pdev);
+	struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+	if (adev->mode_info.num_crtc) {
+		struct drm_connector *list_connector;
+		struct drm_connector_list_iter iter;
+		int ret = 0;
+
+		/* XXX: Return busy if any displays are connected to avoid
+		 * possible display wake ups after runtime resume due to
+		 * hotplug events in case any displays were connected while
+		 * the GPU was in suspend.  Remove this once that is fixed.
+		 */
+		mutex_lock(&drm_dev->mode_config.mutex);
+		drm_connector_list_iter_begin(drm_dev, &iter);
+		drm_for_each_connector_iter(list_connector, &iter) {
+			if (list_connector->status == connector_status_connected) {
+				ret = -EBUSY;
+				break;
+			}
+		}
+		drm_connector_list_iter_end(&iter);
+		mutex_unlock(&drm_dev->mode_config.mutex);
+
+		if (ret)
+			return ret;
+
+		if (amdgpu_device_has_dc_support(adev)) {
+			struct drm_crtc *crtc;
+
+			drm_for_each_crtc(crtc, drm_dev) {
+				drm_modeset_lock(&crtc->mutex, NULL);
+				if (crtc->state->active)
+					ret = -EBUSY;
+				drm_modeset_unlock(&crtc->mutex);
+				if (ret < 0)
+					break;
+			}
+		} else {
+			mutex_lock(&drm_dev->mode_config.mutex);
+			drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
+
+			drm_connector_list_iter_begin(drm_dev, &iter);
+			drm_for_each_connector_iter(list_connector, &iter) {
+				if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
+					ret = -EBUSY;
+					break;
+				}
+			}
+
+			drm_connector_list_iter_end(&iter);
+
+			drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
+			mutex_unlock(&drm_dev->mode_config.mutex);
+		}
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int amdgpu_pmops_runtime_suspend(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
 		return -EBUSY;
 	}
 
+	ret = amdgpu_runtime_idle_check_display(dev);
+	if (ret)
+		return ret;
+
 	/* wait for all rings to drain before suspending */
 	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
 		struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
 		return -EBUSY;
 	}
 
-	if (amdgpu_device_has_dc_support(adev)) {
-		struct drm_crtc *crtc;
-
-		drm_for_each_crtc(crtc, drm_dev) {
-			drm_modeset_lock(&crtc->mutex, NULL);
-			if (crtc->state->active)
-				ret = -EBUSY;
-			drm_modeset_unlock(&crtc->mutex);
-			if (ret < 0)
-				break;
-		}
-
-	} else {
-		struct drm_connector *list_connector;
-		struct drm_connector_list_iter iter;
-
-		mutex_lock(&drm_dev->mode_config.mutex);
-		drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
-
-		drm_connector_list_iter_begin(drm_dev, &iter);
-		drm_for_each_connector_iter(list_connector, &iter) {
-			if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
-				ret = -EBUSY;
-				break;
-			}
-		}
-
-		drm_connector_list_iter_end(&iter);
-
-		drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
-		mutex_unlock(&drm_dev->mode_config.mutex);
-	}
-
-	if (ret == -EBUSY)
-		DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+	ret = amdgpu_runtime_idle_check_display(dev);
+	if (ret)
+		return ret;
 
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_autosuspend(dev);
Signature · 1 line
2.35.1
#1 lore raw

Ping?

Quoted 163 lines · Alex Deucher

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."), the driver took a runtime pm reference when the fbdev emulation was
enabled because we didn't implement proper shadowing support for
vram access when the device was off so the device never runtime
suspended when there was a console bound. Once that commit landed,
we now utilize the core fb helper implementation which properly
handles the emulation, so runtime pm now suspends in cases where it did
not before. Ultimately, we need to sort out why runtime suspend in not
working in this case for some users, but this should restore similar
behavior to before.

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's.")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++--------
 1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +72 -36
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device *dev)
        return amdgpu_device_resume(drm_dev, true);
 }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct drm_device *drm_dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+       if (adev->mode_info.num_crtc) {
+               struct drm_connector *list_connector;
+               struct drm_connector_list_iter iter;
+               int ret = 0;
+
+               /* XXX: Return busy if any displays are connected to avoid
+                * possible display wake ups after runtime resume due to
+                * hotplug events in case any displays were connected while
+                * the GPU was in suspend.  Remove this once that is fixed.
+                */
+               mutex_lock(&drm_dev->mode_config.mutex);
+               drm_connector_list_iter_begin(drm_dev, &iter);
+               drm_for_each_connector_iter(list_connector, &iter) {
+                       if (list_connector->status == connector_status_connected) {
+                               ret = -EBUSY;
+                               break;
+                       }
+               }
+               drm_connector_list_iter_end(&iter);
+               mutex_unlock(&drm_dev->mode_config.mutex);
+
+               if (ret)
+                       return ret;
+
+               if (amdgpu_device_has_dc_support(adev)) {
+                       struct drm_crtc *crtc;
+
+                       drm_for_each_crtc(crtc, drm_dev) {
+                               drm_modeset_lock(&crtc->mutex, NULL);
+                               if (crtc->state->active)
+                                       ret = -EBUSY;
+                               drm_modeset_unlock(&crtc->mutex);
+                               if (ret < 0)
+                                       break;
+                       }
+               } else {
+                       mutex_lock(&drm_dev->mode_config.mutex);
+                       drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
+
+                       drm_connector_list_iter_begin(drm_dev, &iter);
+                       drm_for_each_connector_iter(list_connector, &iter) {
+                               if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
+                                       ret = -EBUSY;
+                                       break;
+                               }
+                       }
+
+                       drm_connector_list_iter_end(&iter);
+
+                       drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
+                       mutex_unlock(&drm_dev->mode_config.mutex);
+               }
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
 static int amdgpu_pmops_runtime_suspend(struct device *dev)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
                return -EBUSY;
        }
 
+       ret = amdgpu_runtime_idle_check_display(dev);
+       if (ret)
+               return ret;
+
        /* wait for all rings to drain before suspending */
        for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
                struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
                return -EBUSY;
        }
 
-       if (amdgpu_device_has_dc_support(adev)) {
-               struct drm_crtc *crtc;
-
-               drm_for_each_crtc(crtc, drm_dev) {
-                       drm_modeset_lock(&crtc->mutex, NULL);
-                       if (crtc->state->active)
-                               ret = -EBUSY;
-                       drm_modeset_unlock(&crtc->mutex);
-                       if (ret < 0)
-                               break;
-               }
-
-       } else {
-               struct drm_connector *list_connector;
-               struct drm_connector_list_iter iter;
-
-               mutex_lock(&drm_dev->mode_config.mutex);
-               drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
-
-               drm_connector_list_iter_begin(drm_dev, &iter);
-               drm_for_each_connector_iter(list_connector, &iter) {
-                       if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
-                               ret = -EBUSY;
-                               break;
-                       }
-               }
-
-               drm_connector_list_iter_end(&iter);
-
-               drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
-               mutex_unlock(&drm_dev->mode_config.mutex);
-       }
-
-       if (ret == -EBUSY)
-               DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+       ret = amdgpu_runtime_idle_check_display(dev);
+       if (ret)
+               return ret;
 
        pm_runtime_mark_last_busy(dev);
        pm_runtime_autosuspend(dev);
--

2.35.1

#2 lore raw

Ping? Anyone care to review this?

Alex

Quoted 167 lines · Alex Deucher

Ping?

Quoted 163 lines · Alex Deucher

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."), the driver took a runtime pm reference when the fbdev emulation was
enabled because we didn't implement proper shadowing support for
vram access when the device was off so the device never runtime
suspended when there was a console bound. Once that commit landed,
we now utilize the core fb helper implementation which properly
handles the emulation, so runtime pm now suspends in cases where it did
not before. Ultimately, we need to sort out why runtime suspend in not
working in this case for some users, but this should restore similar
behavior to before.

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's.")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++--------
 1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +72 -36
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device *dev)
        return amdgpu_device_resume(drm_dev, true);
 }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct drm_device *drm_dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+       if (adev->mode_info.num_crtc) {
+               struct drm_connector *list_connector;
+               struct drm_connector_list_iter iter;
+               int ret = 0;
+
+               /* XXX: Return busy if any displays are connected to avoid
+                * possible display wake ups after runtime resume due to
+                * hotplug events in case any displays were connected while
+                * the GPU was in suspend.  Remove this once that is fixed.
+                */
+               mutex_lock(&drm_dev->mode_config.mutex);
+               drm_connector_list_iter_begin(drm_dev, &iter);
+               drm_for_each_connector_iter(list_connector, &iter) {
+                       if (list_connector->status == connector_status_connected) {
+                               ret = -EBUSY;
+                               break;
+                       }
+               }
+               drm_connector_list_iter_end(&iter);
+               mutex_unlock(&drm_dev->mode_config.mutex);
+
+               if (ret)
+                       return ret;
+
+               if (amdgpu_device_has_dc_support(adev)) {
+                       struct drm_crtc *crtc;
+
+                       drm_for_each_crtc(crtc, drm_dev) {
+                               drm_modeset_lock(&crtc->mutex, NULL);
+                               if (crtc->state->active)
+                                       ret = -EBUSY;
+                               drm_modeset_unlock(&crtc->mutex);
+                               if (ret < 0)
+                                       break;
+                       }
+               } else {
+                       mutex_lock(&drm_dev->mode_config.mutex);
+                       drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
+
+                       drm_connector_list_iter_begin(drm_dev, &iter);
+                       drm_for_each_connector_iter(list_connector, &iter) {
+                               if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
+                                       ret = -EBUSY;
+                                       break;
+                               }
+                       }
+
+                       drm_connector_list_iter_end(&iter);
+
+                       drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
+                       mutex_unlock(&drm_dev->mode_config.mutex);
+               }
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
 static int amdgpu_pmops_runtime_suspend(struct device *dev)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
                return -EBUSY;
        }
 
+       ret = amdgpu_runtime_idle_check_display(dev);
+       if (ret)
+               return ret;
+
        /* wait for all rings to drain before suspending */
        for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
                struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
                return -EBUSY;
        }
 
-       if (amdgpu_device_has_dc_support(adev)) {
-               struct drm_crtc *crtc;
-
-               drm_for_each_crtc(crtc, drm_dev) {
-                       drm_modeset_lock(&crtc->mutex, NULL);
-                       if (crtc->state->active)
-                               ret = -EBUSY;
-                       drm_modeset_unlock(&crtc->mutex);
-                       if (ret < 0)
-                               break;
-               }
-
-       } else {
-               struct drm_connector *list_connector;
-               struct drm_connector_list_iter iter;
-
-               mutex_lock(&drm_dev->mode_config.mutex);
-               drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
-
-               drm_connector_list_iter_begin(drm_dev, &iter);
-               drm_for_each_connector_iter(list_connector, &iter) {
-                       if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
-                               ret = -EBUSY;
-                               break;
-                       }
-               }
-
-               drm_connector_list_iter_end(&iter);
-
-               drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
-               mutex_unlock(&drm_dev->mode_config.mutex);
-       }
-
-       if (ret == -EBUSY)
-               DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+       ret = amdgpu_runtime_idle_check_display(dev);
+       if (ret)
+               return ret;
 
        pm_runtime_mark_last_busy(dev);
        pm_runtime_autosuspend(dev);
--

2.35.1

#3 lore raw

I could ack it, but I'm absolutely not an expert on that stuff.

Our DC team maybe? Or anybody working more on the PM code?

Christian.

Am 20.04.22 um 15:57 schrieb Alex Deucher:

Quoted 170 lines

Ping? Anyone care to review this?

Alex

Quoted 165 lines · Alex Deucher

Ping?

Quoted 162 lines · Alex Deucher

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."), the driver took a runtime pm reference when the fbdev emulation was
enabled because we didn't implement proper shadowing support for
vram access when the device was off so the device never runtime
suspended when there was a console bound. Once that commit landed,
we now utilize the core fb helper implementation which properly
handles the emulation, so runtime pm now suspends in cases where it did
not before. Ultimately, we need to sort out why runtime suspend in not
working in this case for some users, but this should restore similar
behavior to before.

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's.")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++--------
  1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +72 -36
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device *dev)
         return amdgpu_device_resume(drm_dev, true);
  }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct drm_device *drm_dev = pci_get_drvdata(pdev);
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+       if (adev->mode_info.num_crtc) {
+               struct drm_connector *list_connector;
+               struct drm_connector_list_iter iter;
+               int ret = 0;
+
+               /* XXX: Return busy if any displays are connected to avoid
+                * possible display wake ups after runtime resume due to
+                * hotplug events in case any displays were connected while
+                * the GPU was in suspend.  Remove this once that is fixed.
+                */
+               mutex_lock(&drm_dev->mode_config.mutex);
+               drm_connector_list_iter_begin(drm_dev, &iter);
+               drm_for_each_connector_iter(list_connector, &iter) {
+                       if (list_connector->status == connector_status_connected) {
+                               ret = -EBUSY;
+                               break;
+                       }
+               }
+               drm_connector_list_iter_end(&iter);
+               mutex_unlock(&drm_dev->mode_config.mutex);
+
+               if (ret)
+                       return ret;
+
+               if (amdgpu_device_has_dc_support(adev)) {
+                       struct drm_crtc *crtc;
+
+                       drm_for_each_crtc(crtc, drm_dev) {
+                               drm_modeset_lock(&crtc->mutex, NULL);
+                               if (crtc->state->active)
+                                       ret = -EBUSY;
+                               drm_modeset_unlock(&crtc->mutex);
+                               if (ret < 0)
+                                       break;
+                       }
+               } else {
+                       mutex_lock(&drm_dev->mode_config.mutex);
+                       drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
+
+                       drm_connector_list_iter_begin(drm_dev, &iter);
+                       drm_for_each_connector_iter(list_connector, &iter) {
+                               if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
+                                       ret = -EBUSY;
+                                       break;
+                               }
+                       }
+
+                       drm_connector_list_iter_end(&iter);
+
+                       drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
+                       mutex_unlock(&drm_dev->mode_config.mutex);
+               }
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
  static int amdgpu_pmops_runtime_suspend(struct device *dev)
  {
         struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
                 return -EBUSY;
         }
 
+       ret = amdgpu_runtime_idle_check_display(dev);
+       if (ret)
+               return ret;
+
         /* wait for all rings to drain before suspending */
         for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
                 struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
                 return -EBUSY;
         }
 
-       if (amdgpu_device_has_dc_support(adev)) {
-               struct drm_crtc *crtc;
-
-               drm_for_each_crtc(crtc, drm_dev) {
-                       drm_modeset_lock(&crtc->mutex, NULL);
-                       if (crtc->state->active)
-                               ret = -EBUSY;
-                       drm_modeset_unlock(&crtc->mutex);
-                       if (ret < 0)
-                               break;
-               }
-
-       } else {
-               struct drm_connector *list_connector;
-               struct drm_connector_list_iter iter;
-
-               mutex_lock(&drm_dev->mode_config.mutex);
-               drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
-
-               drm_connector_list_iter_begin(drm_dev, &iter);
-               drm_for_each_connector_iter(list_connector, &iter) {
-                       if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
-                               ret = -EBUSY;
-                               break;
-                       }
-               }
-
-               drm_connector_list_iter_end(&iter);
-
-               drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
-               mutex_unlock(&drm_dev->mode_config.mutex);
-       }
-
-       if (ret == -EBUSY)
-               DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+       ret = amdgpu_runtime_idle_check_display(dev);
+       if (ret)
+               return ret;
 
         pm_runtime_mark_last_busy(dev);
         pm_runtime_autosuspend(dev);
--

2.35.1

#4 lore raw
In reply to Alex Deucher

Dear Alex,

Thank you for the patch.

Am 13.04.22 um 22:15 schrieb Alex Deucher:

Quoted 18 lines

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."), the driver took a runtime pm reference when the fbdev emulation was
enabled because we didn't implement proper shadowing support for
vram access when the device was off so the device never runtime
suspended when there was a console bound. Once that commit landed,
we now utilize the core fb helper implementation which properly
handles the emulation, so runtime pm now suspends in cases where it did
not before. Ultimately, we need to sort out why runtime suspend in not
working in this case for some users, but this should restore similar
behavior to before.

Quoted 4 lines

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's.")

On what system and device?

Quoted 16 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++--------
  1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -0
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device *dev)
  	return amdgpu_device_resume(drm_dev, true);
  }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_restore(struct device *dev) · line 2410

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
+	struct drm_device *drm_dev = pci_get_drvdata(pdev);
+	struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+	if (adev->mode_info.num_crtc) {
+		struct drm_connector *list_connector;
+		struct drm_connector_list_iter iter;
+		int ret = 0;
+
+		/* XXX: Return busy if any displays are connected to avoid
+		 * possible display wake ups after runtime resume due to

Nit: wakeups

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_restore(struct device *dev) · line 2413

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -0
+		 * hotplug events in case any displays were connected while
+		 * the GPU was in suspend.  Remove this once that is fixed.
+		 */

Do you have an (internal) issue to track this?

Quoted 98 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +53 -31
+		mutex_lock(&drm_dev->mode_config.mutex);
+		drm_connector_list_iter_begin(drm_dev, &iter);
+		drm_for_each_connector_iter(list_connector, &iter) {
+			if (list_connector->status == connector_status_connected) {
+				ret = -EBUSY;
+				break;
+			}
+		}
+		drm_connector_list_iter_end(&iter);
+		mutex_unlock(&drm_dev->mode_config.mutex);
+
+		if (ret)
+			return ret;
+
+		if (amdgpu_device_has_dc_support(adev)) {
+			struct drm_crtc *crtc;
+
+			drm_for_each_crtc(crtc, drm_dev) {
+				drm_modeset_lock(&crtc->mutex, NULL);
+				if (crtc->state->active)
+					ret = -EBUSY;
+				drm_modeset_unlock(&crtc->mutex);
+				if (ret < 0)
+					break;
+			}
+		} else {
+			mutex_lock(&drm_dev->mode_config.mutex);
+			drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
+
+			drm_connector_list_iter_begin(drm_dev, &iter);
+			drm_for_each_connector_iter(list_connector, &iter) {
+				if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
+					ret = -EBUSY;
+					break;
+				}
+			}
+
+			drm_connector_list_iter_end(&iter);
+
+			drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
+			mutex_unlock(&drm_dev->mode_config.mutex);
+		}
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
  static int amdgpu_pmops_runtime_suspend(struct device *dev)
  {
  	struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
  		return -EBUSY;
  	}
 
+	ret = amdgpu_runtime_idle_check_display(dev);
+	if (ret)
+		return ret;
+
  	/* wait for all rings to drain before suspending */
  	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  		struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
  		return -EBUSY;
  	}
 
-	if (amdgpu_device_has_dc_support(adev)) {
-		struct drm_crtc *crtc;
-
-		drm_for_each_crtc(crtc, drm_dev) {
-			drm_modeset_lock(&crtc->mutex, NULL);
-			if (crtc->state->active)
-				ret = -EBUSY;
-			drm_modeset_unlock(&crtc->mutex);
-			if (ret < 0)
-				break;
-		}
-
-	} else {
-		struct drm_connector *list_connector;
-		struct drm_connector_list_iter iter;
-
-		mutex_lock(&drm_dev->mode_config.mutex);
-		drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
-
-		drm_connector_list_iter_begin(drm_dev, &iter);
-		drm_for_each_connector_iter(list_connector, &iter) {
-			if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
-				ret = -EBUSY;
-				break;
-			}
-		}
-
-		drm_connector_list_iter_end(&iter);
-
-		drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
-		mutex_unlock(&drm_dev->mode_config.mutex);

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_idle(struct device *dev) · line 2593

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -4
-	}
-
-	if (ret == -EBUSY)
-		DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+	ret = amdgpu_runtime_idle_check_display(dev);
+	if (ret)
+		return ret;
 
  	pm_runtime_mark_last_busy(dev);
  	pm_runtime_autosuspend(dev);

The overall change looks good.

Kind regards,

Paul

#5 lore raw
Quoted 25 lines · Paul Menzel

Dear Alex,

Thank you for the patch.

Am 13.04.22 um 22:15 schrieb Alex Deucher:

Quoted 18 lines

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."), the driver took a runtime pm reference when the fbdev emulation was
enabled because we didn't implement proper shadowing support for
vram access when the device was off so the device never runtime
suspended when there was a console bound. Once that commit landed,
we now utilize the core fb helper implementation which properly
handles the emulation, so runtime pm now suspends in cases where it did
not before. Ultimately, we need to sort out why runtime suspend in not
working in this case for some users, but this should restore similar
behavior to before.

Quoted 6 lines
Quoted 4 lines

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's.")

On what system and device?

It was a polaris dGPU, but it has been seen on other GPUs as well. It's not device specific. The issue is hard to reproduce at least in our testing unfortunately.

Quoted 14 lines
Quoted 14 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++--------
  1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -0
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device *dev)
      return amdgpu_device_resume(drm_dev, true);
  }
 
Quoted 15 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_restore(struct device *dev) · line 2410

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +13 -0
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+     struct pci_dev *pdev = to_pci_dev(dev);
+     struct drm_device *drm_dev = pci_get_drvdata(pdev);
+     struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+     if (adev->mode_info.num_crtc) {
+             struct drm_connector *list_connector;
+             struct drm_connector_list_iter iter;
+             int ret = 0;
+
+             /* XXX: Return busy if any displays are connected to avoid
+              * possible display wake ups after runtime resume due to

Nit: wakeups

Ack.

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_restore(struct device *dev) · line 2413

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -0
+              * hotplug events in case any displays were connected while
+              * the GPU was in suspend.  Remove this once that is fixed.
+              */

Do you have an (internal) issue to track this?

Yes, we are tracking it.

Alex

Quoted 116 lines
Quoted 99 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +53 -31
+             mutex_lock(&drm_dev->mode_config.mutex);
+             drm_connector_list_iter_begin(drm_dev, &iter);
+             drm_for_each_connector_iter(list_connector, &iter) {
+                     if (list_connector->status == connector_status_connected) {
+                             ret = -EBUSY;
+                             break;
+                     }
+             }
+             drm_connector_list_iter_end(&iter);
+             mutex_unlock(&drm_dev->mode_config.mutex);
+
+             if (ret)
+                     return ret;
+
+             if (amdgpu_device_has_dc_support(adev)) {
+                     struct drm_crtc *crtc;
+
+                     drm_for_each_crtc(crtc, drm_dev) {
+                             drm_modeset_lock(&crtc->mutex, NULL);
+                             if (crtc->state->active)
+                                     ret = -EBUSY;
+                             drm_modeset_unlock(&crtc->mutex);
+                             if (ret < 0)
+                                     break;
+                     }
+             } else {
+                     mutex_lock(&drm_dev->mode_config.mutex);
+                     drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
+
+                     drm_connector_list_iter_begin(drm_dev, &iter);
+                     drm_for_each_connector_iter(list_connector, &iter) {
+                             if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
+                                     ret = -EBUSY;
+                                     break;
+                             }
+                     }
+
+                     drm_connector_list_iter_end(&iter);
+
+                     drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
+                     mutex_unlock(&drm_dev->mode_config.mutex);
+             }
+             if (ret)
+                     return ret;
+     }
+
+     return 0;
+}
+
  static int amdgpu_pmops_runtime_suspend(struct device *dev)
  {
      struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
              return -EBUSY;
      }
 
+     ret = amdgpu_runtime_idle_check_display(dev);
+     if (ret)
+             return ret;
+
      /* wait for all rings to drain before suspending */
      for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
              struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)
              return -EBUSY;
      }
 
-     if (amdgpu_device_has_dc_support(adev)) {
-             struct drm_crtc *crtc;
-
-             drm_for_each_crtc(crtc, drm_dev) {
-                     drm_modeset_lock(&crtc->mutex, NULL);
-                     if (crtc->state->active)
-                             ret = -EBUSY;
-                     drm_modeset_unlock(&crtc->mutex);
-                     if (ret < 0)
-                             break;
-             }
-
-     } else {
-             struct drm_connector *list_connector;
-             struct drm_connector_list_iter iter;
-
-             mutex_lock(&drm_dev->mode_config.mutex);
-             drm_modeset_lock(&drm_dev->mode_config.connection_mutex, NULL);
-
-             drm_connector_list_iter_begin(drm_dev, &iter);
-             drm_for_each_connector_iter(list_connector, &iter) {
-                     if (list_connector->dpms ==  DRM_MODE_DPMS_ON) {
-                             ret = -EBUSY;
-                             break;
-                     }
-             }
-
-             drm_connector_list_iter_end(&iter);
-
-             drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
-             mutex_unlock(&drm_dev->mode_config.mutex);

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_idle(struct device *dev) · line 2593

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -4
-     }
-
-     if (ret == -EBUSY)
-             DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+     ret = amdgpu_runtime_idle_check_display(dev);
+     if (ret)
+             return ret;
 
      pm_runtime_mark_last_busy(dev);
      pm_runtime_autosuspend(dev);

The overall change looks good.

Kind regards,

Paul

#6 lore raw
In reply to Alex Deucher

[AMD Official Use Only]

Quoted 171 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Thursday, April 14, 2022 4:15 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Michele Ballabio <[email protected]>
Subject: [PATCH] drm/amdgpu: don't runtime suspend if there are displays attached (v2)

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."),
the driver took a runtime pm reference when the fbdev emulation was enabled because we didn't implement proper shadowing support for vram access when the device was off so the device never runtime suspended when there was a console bound. Once that commit landed, we now utilize the core fb helper implementation which properly handles the emulation, so runtime pm now suspends in cases where it did not before. Ultimately, we need to sort out why runtime suspend in not working in this case for some users, but this should restore similar behavior to before.

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of

setting up AMD own's.")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++---
-----
 1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +47 -0
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device
 *dev)
 	return amdgpu_device_resume(drm_dev, true);
 }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct drm_device *drm_dev = pci_get_drvdata(pdev);
+	struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+	if (adev->mode_info.num_crtc) {
+		struct drm_connector *list_connector;
+		struct drm_connector_list_iter iter;
+		int ret = 0;
+
+		/* XXX: Return busy if any displays are connected to avoid
+		 * possible display wake ups after runtime resume due to
+		 * hotplug events in case any displays were connected while
+		 * the GPU was in suspend.  Remove this once that is fixed.
+		 */
+		mutex_lock(&drm_dev->mode_config.mutex);
+		drm_connector_list_iter_begin(drm_dev, &iter);
+		drm_for_each_connector_iter(list_connector, &iter) {
+			if (list_connector->status ==
 connector_status_connected) {
+				ret = -EBUSY;
+				break;
+			}
+		}
+		drm_connector_list_iter_end(&iter);
+		mutex_unlock(&drm_dev->mode_config.mutex);
+
+		if (ret)
+			return ret;
+
+		if (amdgpu_device_has_dc_support(adev)) {
+			struct drm_crtc *crtc;
+
+			drm_for_each_crtc(crtc, drm_dev) {
+				drm_modeset_lock(&crtc->mutex, NULL);
+				if (crtc->state->active)
+					ret = -EBUSY;
+				drm_modeset_unlock(&crtc->mutex);
+				if (ret < 0)
+					break;
+			}
+		} else {
+			mutex_lock(&drm_dev->mode_config.mutex);
+			drm_modeset_lock(&drm_dev-
 >mode_config.connection_mutex, NULL);
+
+			drm_connector_list_iter_begin(drm_dev, &iter);
+			drm_for_each_connector_iter(list_connector, &iter)

{

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
+				if (list_connector->dpms ==

DRM_MODE_DPMS_ON) {

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +8 -0
+					ret = -EBUSY;
+					break;
+				}
+			}
+
+			drm_connector_list_iter_end(&iter);
+
+			drm_modeset_unlock(&drm_dev-
Quoted 1 line

mode_config.connection_mutex);

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +13 -0
+			mutex_unlock(&drm_dev->mode_config.mutex);
+		}
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int amdgpu_pmops_runtime_suspend(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int
 amdgpu_pmops_runtime_suspend(struct device *dev)
 		return -EBUSY;
 	}
 
+	ret = amdgpu_runtime_idle_check_display(dev);
+	if (ret)
+		return ret;
+
 	/* wait for all rings to drain before suspending */
 	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -29
 		struct amdgpu_ring *ring = adev->rings[i];
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct
 device *dev)
 		return -EBUSY;
 	}
 
-	if (amdgpu_device_has_dc_support(adev)) {
-		struct drm_crtc *crtc;
-
-		drm_for_each_crtc(crtc, drm_dev) {
-			drm_modeset_lock(&crtc->mutex, NULL);
-			if (crtc->state->active)
-				ret = -EBUSY;
-			drm_modeset_unlock(&crtc->mutex);
-			if (ret < 0)
-				break;
-		}
-
-	} else {
-		struct drm_connector *list_connector;
-		struct drm_connector_list_iter iter;
-
-		mutex_lock(&drm_dev->mode_config.mutex);
-		drm_modeset_lock(&drm_dev-
 >mode_config.connection_mutex, NULL);
-
-		drm_connector_list_iter_begin(drm_dev, &iter);
-		drm_for_each_connector_iter(list_connector, &iter) {
-			if (list_connector->dpms ==  DRM_MODE_DPMS_ON)
 {
-				ret = -EBUSY;
-				break;
-			}
-		}
-
-		drm_connector_list_iter_end(&iter);
-

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_idle(struct · line 2590

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -6
-		drm_modeset_unlock(&drm_dev-
 >mode_config.connection_mutex);
-		mutex_unlock(&drm_dev->mode_config.mutex);
-	}
-
-	if (ret == -EBUSY)
-		DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+	ret = amdgpu_runtime_idle_check_display(dev);
+	if (ret)
+		return ret;

[Quan, Evan] Previously, the following actions(pm_runtime_mark_last_busy/pm_runtime_autosuspend) will be still performed even if ret is set as EBUSY. But with the new changes, it will abort directly without the following actions performed.
Is that expected? Will that make any logical change?

BR
Evan

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -1
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_autosuspend(dev);
--

2.35.1

#7 lore raw
Quoted 186 lines · Evan

[AMD Official Use Only]

Quoted 171 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Thursday, April 14, 2022 4:15 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Michele Ballabio <[email protected]>
Subject: [PATCH] drm/amdgpu: don't runtime suspend if there are displays attached (v2)

We normally runtime suspend when there are displays attached if they are in the DPMS off state, however, if something wakes the GPU we send a hotplug event on resume (in case any displays were connected while the GPU was in suspend) which can cause userspace to light up the displays again soon after they were turned off.

Prior to
commit 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of setting up AMD own's."),
the driver took a runtime pm reference when the fbdev emulation was enabled because we didn't implement proper shadowing support for vram access when the device was off so the device never runtime suspended when there was a console bound. Once that commit landed, we now utilize the core fb helper implementation which properly handles the emulation, so runtime pm now suspends in cases where it did not before. Ultimately, we need to sort out why runtime suspend in not working in this case for some users, but this should restore similar behavior to before.

v2: move check into runtime_suspend

Fixes 087451f372bf76 ("drm/amdgpu: use generic fb helpers instead of

setting up AMD own's.")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 107 ++++++++++++++++---
-----
 1 file changed, 72 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +47 -0
index 4efaa183abcd..97a1aa02d76e 100644
@@ -2395,6 +2395,71 @@ static int amdgpu_pmops_restore(struct device
 *dev)
      return amdgpu_device_resume(drm_dev, true);
 }
 
+static int amdgpu_runtime_idle_check_display(struct device *dev)
+{
+     struct pci_dev *pdev = to_pci_dev(dev);
+     struct drm_device *drm_dev = pci_get_drvdata(pdev);
+     struct amdgpu_device *adev = drm_to_adev(drm_dev);
+
+     if (adev->mode_info.num_crtc) {
+             struct drm_connector *list_connector;
+             struct drm_connector_list_iter iter;
+             int ret = 0;
+
+             /* XXX: Return busy if any displays are connected to avoid
+              * possible display wake ups after runtime resume due to
+              * hotplug events in case any displays were connected while
+              * the GPU was in suspend.  Remove this once that is fixed.
+              */
+             mutex_lock(&drm_dev->mode_config.mutex);
+             drm_connector_list_iter_begin(drm_dev, &iter);
+             drm_for_each_connector_iter(list_connector, &iter) {
+                     if (list_connector->status ==
 connector_status_connected) {
+                             ret = -EBUSY;
+                             break;
+                     }
+             }
+             drm_connector_list_iter_end(&iter);
+             mutex_unlock(&drm_dev->mode_config.mutex);
+
+             if (ret)
+                     return ret;
+
+             if (amdgpu_device_has_dc_support(adev)) {
+                     struct drm_crtc *crtc;
+
+                     drm_for_each_crtc(crtc, drm_dev) {
+                             drm_modeset_lock(&crtc->mutex, NULL);
+                             if (crtc->state->active)
+                                     ret = -EBUSY;
+                             drm_modeset_unlock(&crtc->mutex);
+                             if (ret < 0)
+                                     break;
+                     }
+             } else {
+                     mutex_lock(&drm_dev->mode_config.mutex);
+                     drm_modeset_lock(&drm_dev-
 >mode_config.connection_mutex, NULL);
+
+                     drm_connector_list_iter_begin(drm_dev, &iter);
+                     drm_for_each_connector_iter(list_connector, &iter)

{
+ if (list_connector->dpms ==
DRM_MODE_DPMS_ON) {

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +8 -0
+                                     ret = -EBUSY;
+                                     break;
+                             }
+                     }
+
+                     drm_connector_list_iter_end(&iter);
+
+                     drm_modeset_unlock(&drm_dev-
Quoted 1 line

mode_config.connection_mutex);

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +13 -0
+                     mutex_unlock(&drm_dev->mode_config.mutex);
+             }
+             if (ret)
+                     return ret;
+     }
+
+     return 0;
+}
+
 static int amdgpu_pmops_runtime_suspend(struct device *dev)
 {
      struct pci_dev *pdev = to_pci_dev(dev);
@@ -2407,6 +2472,10 @@ static int
 amdgpu_pmops_runtime_suspend(struct device *dev)
              return -EBUSY;
      }
 
+     ret = amdgpu_runtime_idle_check_display(dev);
+     if (ret)
+             return ret;
+
      /* wait for all rings to drain before suspending */
      for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
              struct amdgpu_ring *ring = adev->rings[i];
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -29
@@ -2516,41 +2585,9 @@ static int amdgpu_pmops_runtime_idle(struct
 device *dev)
              return -EBUSY;
      }
 
-     if (amdgpu_device_has_dc_support(adev)) {
-             struct drm_crtc *crtc;
-
-             drm_for_each_crtc(crtc, drm_dev) {
-                     drm_modeset_lock(&crtc->mutex, NULL);
-                     if (crtc->state->active)
-                             ret = -EBUSY;
-                     drm_modeset_unlock(&crtc->mutex);
-                     if (ret < 0)
-                             break;
-             }
-
-     } else {
-             struct drm_connector *list_connector;
-             struct drm_connector_list_iter iter;
-
-             mutex_lock(&drm_dev->mode_config.mutex);
-             drm_modeset_lock(&drm_dev-
 >mode_config.connection_mutex, NULL);
-
-             drm_connector_list_iter_begin(drm_dev, &iter);
-             drm_for_each_connector_iter(list_connector, &iter) {
-                     if (list_connector->dpms ==  DRM_MODE_DPMS_ON)
 {
-                             ret = -EBUSY;
-                             break;
-                     }
-             }
-
-             drm_connector_list_iter_end(&iter);
-

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_idle(struct · line 2590

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -6
-             drm_modeset_unlock(&drm_dev-
 >mode_config.connection_mutex);
-             mutex_unlock(&drm_dev->mode_config.mutex);
-     }
-
-     if (ret == -EBUSY)
-             DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
+     ret = amdgpu_runtime_idle_check_display(dev);
+     if (ret)
+             return ret;
Quoted 3 lines

[Quan, Evan] Previously, the following actions(pm_runtime_mark_last_busy/pm_runtime_autosuspend) will be still performed even if ret is set as EBUSY. But with the new changes, it will abort directly without the following actions performed.
Is that expected? Will that make any logical change?

Good point. I'll fix that up.

Alex

Quoted 8 lines

BR
Evan

Quoted 5 lines
      pm_runtime_mark_last_busy(dev);
      pm_runtime_autosuspend(dev);

--
2.35.1