Skip to contentSkip to conversation

Revert "drm/amd: flush any delayed gfxoff on suspend entry"

PATCH In review Mario Limonciello 3 participants 7 messages Feb 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 Revert "drm/amd: flush any delayed gfxoff on suspend entry"

commit ab4750332dbe ("drm/amdgpu/sdma5.2: add begin/end_use ring callbacks") caused GFXOFF control to be used more heavily and the codepath that was removed from commit 0dee72639533 ("drm/amd: flush any delayed gfxoff on suspend entry") now can be exercised at suspend again.

Users report that by using GNOME to suspend the lockscreen trigger will cause SDMA traffic and the system can deadlock.

This reverts commit 0dee726395333fea833eaaf838bc80962df886c8.

Fixes ab4750332dbe ("drm/amdgpu/sdma5.2: add begin/end_use ring callbacks")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 9 ++++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
index 670ecb789d59..2bc460cb993d 100644
@@ -4573,7 +4573,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)
 		drm_fb_helper_set_suspend_unlocked(adev_to_drm(adev)->fb_helper, true);
 
 	cancel_delayed_work_sync(&adev->delayed_init_work);
-	flush_delayed_work(&adev->gfx.gfx_off_delay_work);
 
 	amdgpu_ras_suspend(adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -1
index aa8e1d29d10a..9831dd854532 100644
@@ -727,8 +727,15 @@ void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, bool enable)
 
 		if (adev->gfx.gfx_off_req_count == 0 &&
 		    !adev->gfx.gfx_off_state) {
-			schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
+			/* If going to s2idle, no need to wait */
+			if (adev->in_s0ix) {
+				if (!amdgpu_dpm_set_powergating_by_smu(adev,
+						AMD_IP_BLOCK_TYPE_GFX, true))
+					adev->gfx.gfx_off_state = true;
+			} else {
+				schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
 					      delay);
+			}
 		}
 	} else {
 		if (adev->gfx.gfx_off_req_count == 0) {
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 2/3 drm/amd: Stop evicting resources on APUs in suspend

commit 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback") intentionally moved the eviction of resources to earlier in the suspend process, but this introduced a subtle change that it occurs before adev->in_s0ix or adev->in_s3 are set. This meant that APUs actually started to evict resources at suspend time as well.

Explicitly set s0ix or s3 in the prepare() stage, and unset them if the prepare() stage failed.

Fixes 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback")

---
v3->v4:
* New function to set s0ix/s3 and explicitly unset in cleanup
v2->v3:
* Whitespace
v1->v2:
* Add and use new in_prepare member

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c   | 15 +++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 11 +++++++++--
 3 files changed, 26 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index 3d8a48f46b01..f6c38a974bae 100644
@@ -1547,9 +1547,11 @@ static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
 bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
 bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
+void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
 #else
 static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { return false; }
 static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { return false; }
+static void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }
 #endif
 
 #if defined(CONFIG_DRM_AMD_DC)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +15 -0
index 2deebece810e..cc21ed67a330 100644
@@ -1519,4 +1519,19 @@ bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
 #endif /* CONFIG_AMD_PMC */
 }
 
+/**
+ * amdgpu_choose_low_power_state
+ *
+ * @adev: amdgpu_device_pointer
+ *
+ * Choose the target low power state for the GPU
+ */
+void amdgpu_choose_low_power_state(struct amdgpu_device *adev)
+{
+	if (amdgpu_acpi_is_s0ix_active(adev))
+		adev->in_s0ix = true;
+	else if (amdgpu_acpi_is_s3_active(adev))
+		adev->in_s3 = true;
+}
+
 #endif /* CONFIG_SUSPEND */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -2
index 2bc460cb993d..dab03865c827 100644
@@ -4518,13 +4518,15 @@ int amdgpu_device_prepare(struct drm_device *dev)
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	int i, r;
 
+	amdgpu_choose_low_power_state(adev);
+
 	if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
 		return 0;
 
 	/* Evict the majority of BOs before starting suspend sequence */
 	r = amdgpu_device_evict_resources(adev);
 	if (r)
-		return r;
+		goto unprepare;
 
 	for (i = 0; i < adev->num_ip_blocks; i++) {
 		if (!adev->ip_blocks[i].status.valid)
@@ -4533,10 +4535,15 @@ int amdgpu_device_prepare(struct drm_device *dev)
 			continue;
 		r = adev->ip_blocks[i].version->funcs->prepare_suspend((void *)adev);
 		if (r)
-			return r;
+			goto unprepare;
 	}
 
 	return 0;
+
+unprepare:
+	adev->in_s0ix = adev->in_s3 = false;
+
+	return r;
 }
 
 /**
Signature · 1 line
2.34.1
Acked-by on v4 2/3
#2 lore raw

Re: [PATCH v4 2/3] drm/amd: Stop evicting resources on APUs in suspend

Quoted 7 lines · Mario Limonciello

commit 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback") intentionally moved the eviction of resources to earlier in the suspend process, but this introduced a subtle change that it occurs before adev->in_s0ix or adev->in_s3 are set. This meant that APUs actually started to evict resources at suspend time as well.

Quoted 7 lines

Explicitly set s0ix or s3 in the prepare() stage, and unset them if the prepare() stage failed.

Fixes 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback")
Quoted 94 lines

---
v3->v4:
* New function to set s0ix/s3 and explicitly unset in cleanup
v2->v3:
* Whitespace
v1->v2:
* Add and use new in_prepare member

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c   | 15 +++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 11 +++++++++--
 3 files changed, 26 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index 3d8a48f46b01..f6c38a974bae 100644
@@ -1547,9 +1547,11 @@ static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
 bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
 bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
+void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
 #else
 static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { return false; }
 static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { return false; }
+static void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }
 #endif
 
 #if defined(CONFIG_DRM_AMD_DC)
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +15 -0
index 2deebece810e..cc21ed67a330 100644
@@ -1519,4 +1519,19 @@ bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
 #endif /* CONFIG_AMD_PMC */
 }
 
+/**
+ * amdgpu_choose_low_power_state
+ *
+ * @adev: amdgpu_device_pointer
+ *
+ * Choose the target low power state for the GPU
+ */
+void amdgpu_choose_low_power_state(struct amdgpu_device *adev)
+{
+       if (amdgpu_acpi_is_s0ix_active(adev))
+               adev->in_s0ix = true;
+       else if (amdgpu_acpi_is_s3_active(adev))
+               adev->in_s3 = true;
+}
+
 #endif /* CONFIG_SUSPEND */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -3
index 2bc460cb993d..dab03865c827 100644
@@ -4518,13 +4518,15 @@ int amdgpu_device_prepare(struct drm_device *dev)
        struct amdgpu_device *adev = drm_to_adev(dev);
        int i, r;
 
+       amdgpu_choose_low_power_state(adev);
+
        if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
                return 0;
 
        /* Evict the majority of BOs before starting suspend sequence */
        r = amdgpu_device_evict_resources(adev);
        if (r)
-               return r;
+               goto unprepare;
 
        for (i = 0; i < adev->num_ip_blocks; i++) {
                if (!adev->ip_blocks[i].status.valid)
@@ -4533,10 +4535,15 @@ int amdgpu_device_prepare(struct drm_device *dev)
                        continue;
                r = adev->ip_blocks[i].version->funcs->prepare_suspend((void *)adev);
                if (r)
-                       return r;
+                       goto unprepare;
        }
 
        return 0;
+
+unprepare:
+       adev->in_s0ix = adev->in_s3 = false;
+
+       return r;
 }
 
 /**
--

2.34.1

#3 lore raw

PATCH v4 3/3 drm/amd: Drop unneeded functions to check if s3/s0ix active

In reply to Mario Limonciello

amdgpu_acpi_is_s0ix_active() and amdgpu_acpi_is_s0ix_active() aren't needed to be checked multiple times in a suspend cycle. Checking and setting up policy one time in the prepare() callback is sufficient.

---
v4: New patch

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c |  7 +++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  | 17 ++---------------
 3 files changed, 5 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -4
index f6c38a974bae..53823539eba5 100644
@@ -1545,12 +1545,8 @@ static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
 #endif
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
 void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
 #else
-static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { return false; }
-static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { return false; }
 static void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }
 #endif
 
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +3 -4
index cc21ed67a330..1d58728f8c3f 100644
@@ -1366,8 +1366,7 @@ bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
 	    adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */
 		return false;
 
-	if ((adev->flags & AMD_IS_APU) &&
-	    amdgpu_acpi_is_s3_active(adev))
+	if ((adev->flags & AMD_IS_APU) && adev->in_s3)
 		return false;
 
 	if (amdgpu_sriov_vf(adev))
@@ -1472,7 +1471,7 @@ void amdgpu_acpi_release(void)
  *
  * returns true if supported, false if not.
  */
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
 {
 	return !(adev->flags & AMD_IS_APU) ||
 		(pm_suspend_target_state == PM_SUSPEND_MEM);
@@ -1485,7 +1484,7 @@ bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
  *
  * returns true if supported, false if not.
  */
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
 {
 	if (!(adev->flags & AMD_IS_APU) ||
 	    (pm_suspend_target_state != PM_SUSPEND_TO_IDLE))
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -15
index 971acf01bea6..2bc4c5bb9b5a 100644
@@ -2456,13 +2456,6 @@ static int amdgpu_pmops_prepare(struct device *dev)
 	    pm_runtime_suspended(dev))
 		return 1;
 
-	/* if we will not support s3 or s2i for the device
-	 *  then skip suspend
-	 */
-	if (!amdgpu_acpi_is_s0ix_active(adev) &&
-	    !amdgpu_acpi_is_s3_active(adev))
-		return 1;
-
 	return amdgpu_device_prepare(drm_dev);
 }
 
@@ -2476,10 +2469,6 @@ static int amdgpu_pmops_suspend(struct device *dev)
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(drm_dev);
 
-	if (amdgpu_acpi_is_s0ix_active(adev))
-		adev->in_s0ix = true;
-	else if (amdgpu_acpi_is_s3_active(adev))
-		adev->in_s3 = true;
 	if (!adev->in_s0ix && !adev->in_s3)
 		return 0;
 	return amdgpu_device_suspend(drm_dev, true);
@@ -2510,10 +2499,8 @@ static int amdgpu_pmops_resume(struct device *dev)
 		adev->no_hw_access = true;
 
 	r = amdgpu_device_resume(drm_dev, true);
-	if (amdgpu_acpi_is_s0ix_active(adev))
-		adev->in_s0ix = false;
-	else
-		adev->in_s3 = false;
+	adev->in_s0ix = adev->in_s3 = false;
+
 	return r;
 }
 
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v4 3/3] drm/amd: Drop unneeded functions to check if s3/s0ix active

Am 08.02.24 um 06:52 schrieb Mario Limonciello:

Quoted 3 lines

amdgpu_acpi_is_s0ix_active() and amdgpu_acpi_is_s0ix_active() aren't needed to be checked multiple times in a suspend cycle. Checking and setting up policy one time in the prepare() callback is sufficient.

Mhm, looking at amdgpu_acpi_is_s3_active() I think we should not cache that in a variable in the first place.

Just calling the function all the time to check the state should be sufficient, or do we then run into any state transition problems?

Regards,
Christian.

Quoted 101 lines

---
v4: New patch

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 ----
  drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c |  7 +++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  | 17 ++---------------
  3 files changed, 5 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -4
index f6c38a974bae..53823539eba5 100644
@@ -1545,12 +1545,8 @@ static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
  #endif
 
  #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
  void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
  #else
-static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { return false; }
-static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { return false; }
  static void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }
  #endif
 
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +3 -4
index cc21ed67a330..1d58728f8c3f 100644
@@ -1366,8 +1366,7 @@ bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
  	    adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */
  		return false;
 
-	if ((adev->flags & AMD_IS_APU) &&
-	    amdgpu_acpi_is_s3_active(adev))
+	if ((adev->flags & AMD_IS_APU) && adev->in_s3)
  		return false;
 
  	if (amdgpu_sriov_vf(adev))
@@ -1472,7 +1471,7 @@ void amdgpu_acpi_release(void)
   *
   * returns true if supported, false if not.
   */
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
  {
  	return !(adev->flags & AMD_IS_APU) ||
  		(pm_suspend_target_state == PM_SUSPEND_MEM);
@@ -1485,7 +1484,7 @@ bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
   *
   * returns true if supported, false if not.
   */
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
  {
  	if (!(adev->flags & AMD_IS_APU) ||
  	    (pm_suspend_target_state != PM_SUSPEND_TO_IDLE))
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -15
index 971acf01bea6..2bc4c5bb9b5a 100644
@@ -2456,13 +2456,6 @@ static int amdgpu_pmops_prepare(struct device *dev)
  	    pm_runtime_suspended(dev))
  		return 1;
 
-	/* if we will not support s3 or s2i for the device
-	 *  then skip suspend
-	 */
-	if (!amdgpu_acpi_is_s0ix_active(adev) &&
-	    !amdgpu_acpi_is_s3_active(adev))
-		return 1;
-
  	return amdgpu_device_prepare(drm_dev);
  }
 
@@ -2476,10 +2469,6 @@ static int amdgpu_pmops_suspend(struct device *dev)
  	struct drm_device *drm_dev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(drm_dev);
 
-	if (amdgpu_acpi_is_s0ix_active(adev))
-		adev->in_s0ix = true;
-	else if (amdgpu_acpi_is_s3_active(adev))
-		adev->in_s3 = true;
  	if (!adev->in_s0ix && !adev->in_s3)
  		return 0;
  	return amdgpu_device_suspend(drm_dev, true);
@@ -2510,10 +2499,8 @@ static int amdgpu_pmops_resume(struct device *dev)
  		adev->no_hw_access = true;
 
  	r = amdgpu_device_resume(drm_dev, true);
-	if (amdgpu_acpi_is_s0ix_active(adev))
-		adev->in_s0ix = false;
-	else
-		adev->in_s3 = false;
+	adev->in_s0ix = adev->in_s3 = false;
+
  	return r;
  }
 
#5 lore raw

Re: [PATCH v4 3/3] drm/amd: Drop unneeded functions to check if s3/s0ix active

Quoted 8 lines · Christian König

Am 08.02.24 um 06:52 schrieb Mario Limonciello:

Quoted 3 lines

amdgpu_acpi_is_s0ix_active() and amdgpu_acpi_is_s0ix_active() aren't needed to be checked multiple times in a suspend cycle.  Checking and setting up policy one time in the prepare() callback is sufficient.

Mhm, looking at amdgpu_acpi_is_s3_active() I think we should not cache that in a variable in the first place.

Just calling the function all the time to check the state should be sufficient, or do we then run into any state transition problems?

I think calling to check it each time is perfectly fine, it should never change once the sequence starts until it's over.

If the first 2 patches look OK, I'd like to get those merged so we can fix the regressions. I'll do another series that can drop the cached parameters.

Quoted 105 lines

Regards,
Christian.

Quoted 100 lines

---
v4: New patch
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 ---- drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c |  7 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  | 17 ++---------------

  3 files changed, 5 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -4
index f6c38a974bae..53823539eba5 100644
@@ -1545,12 +1545,8 @@ static inline int 
 amdgpu_acpi_smart_shift_update(struct drm_device *dev,
   #endif
   #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
   void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
   #else
-static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device 
 *adev) { return false; }
-static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device 
 *adev) { return false; }
   static void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }

  #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +0 -0
index cc21ed67a330..1d58728f8c3f 100644
@@ -1366,8 +1366,7 @@ bool amdgpu_acpi_should_gpu_reset(struct 
 amdgpu_device *adev)

          adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */ return false;
-    if ((adev->flags & AMD_IS_APU) &&
-        amdgpu_acpi_is_s3_active(adev))
+    if ((adev->flags & AMD_IS_APU) && adev->in_s3)
          return false;
      if (amdgpu_sriov_vf(adev))

drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +1 -1
@@ -1472,7 +1471,7 @@ void amdgpu_acpi_release(void)
    *
    * returns true if supported, false if not.
    */
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
   {

      return !(adev->flags & AMD_IS_APU) || (pm_suspend_target_state == PM_SUSPEND_MEM);

drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +1 -1
@@ -1485,7 +1484,7 @@ bool amdgpu_acpi_is_s3_active(struct 
 amdgpu_device *adev)
    *
    * returns true if supported, false if not.
    */
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device 
 *adev)
   {

      if (!(adev->flags & AMD_IS_APU) || (pm_suspend_target_state != PM_SUSPEND_TO_IDLE))

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -15
index 971acf01bea6..2bc4c5bb9b5a 100644
@@ -2456,13 +2456,6 @@ static int amdgpu_pmops_prepare(struct device 
 *dev)
           pm_runtime_suspended(dev))
           return 1;
-    /* if we will not support s3 or s2i for the device
-     *  then skip suspend
-     */
-    if (!amdgpu_acpi_is_s0ix_active(adev) &&
-        !amdgpu_acpi_is_s3_active(adev))
-        return 1;
-
       return amdgpu_device_prepare(drm_dev);
   }
@@ -2476,10 +2469,6 @@ static int amdgpu_pmops_suspend(struct device 
 *dev)
       struct drm_device *drm_dev = dev_get_drvdata(dev);
       struct amdgpu_device *adev = drm_to_adev(drm_dev);
-    if (amdgpu_acpi_is_s0ix_active(adev))
-        adev->in_s0ix = true;
-    else if (amdgpu_acpi_is_s3_active(adev))
-        adev->in_s3 = true;
       if (!adev->in_s0ix && !adev->in_s3)
           return 0;
       return amdgpu_device_suspend(drm_dev, true);
@@ -2510,10 +2499,8 @@ static int amdgpu_pmops_resume(struct device *dev)
           adev->no_hw_access = true;
       r = amdgpu_device_resume(drm_dev, true);
-    if (amdgpu_acpi_is_s0ix_active(adev))
-        adev->in_s0ix = false;
-    else
-        adev->in_s3 = false;
+    adev->in_s0ix = adev->in_s3 = false;
+
       return r;
   }
#6 lore raw

Re: [PATCH v4 3/3] drm/amd: Drop unneeded functions to check if s3/s0ix active

Am 08.02.24 um 16:04 schrieb Mario Limonciello:

Quoted 6 lines · Christian König
Quoted 5 lines

Am 08.02.24 um 06:52 schrieb Mario Limonciello:

Quoted 3 lines

amdgpu_acpi_is_s0ix_active() and amdgpu_acpi_is_s0ix_active() aren't needed to be checked multiple times in a suspend cycle. Checking and setting up policy one time in the prepare() callback is sufficient.

Quoted 7 lines
Quoted 3 lines

Mhm, looking at amdgpu_acpi_is_s3_active() I think we should not cache that in a variable in the first place.

Just calling the function all the time to check the state should be sufficient, or do we then run into any state transition problems?

I think calling to check it each time is perfectly fine, it should never change once the sequence starts until it's over.

If the first 2 patches look OK, I'd like to get those merged so we can fix the regressions.  I'll do another series that can drop the cached parameters.

Feel free to add my Acked-by to the series, but for ACPI stuff I would wait for Alex to take a look as well.

Regards,
Christian.

Quoted 109 lines
Quoted 108 lines

Regards,
Christian.

Quoted 102 lines

---
v4: New patch
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 ---- drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c |  7 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  | 17 ++---------------

  3 files changed, 5 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -4
index f6c38a974bae..53823539eba5 100644
@@ -1545,12 +1545,8 @@ static inline int 
 amdgpu_acpi_smart_shift_update(struct drm_device *dev,
   #endif
   #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
   void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
   #else
-static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device 
 *adev) { return false; }
-static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device 
 *adev) { return false; }
   static void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }

  #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +0 -0
index cc21ed67a330..1d58728f8c3f 100644
@@ -1366,8 +1366,7 @@ bool amdgpu_acpi_should_gpu_reset(struct 
 amdgpu_device *adev)

          adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */ return false;
-    if ((adev->flags & AMD_IS_APU) &&
-        amdgpu_acpi_is_s3_active(adev))
+    if ((adev->flags & AMD_IS_APU) && adev->in_s3)
          return false;
      if (amdgpu_sriov_vf(adev))

drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +1 -1
@@ -1472,7 +1471,7 @@ void amdgpu_acpi_release(void)
    *
    * returns true if supported, false if not.
    */
-bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device 
 *adev)
   {

      return !(adev->flags & AMD_IS_APU) || (pm_suspend_target_state == PM_SUSPEND_MEM);

drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +1 -1
@@ -1485,7 +1484,7 @@ bool amdgpu_acpi_is_s3_active(struct 
 amdgpu_device *adev)
    *
    * returns true if supported, false if not.
    */
-bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
+static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device 
 *adev)
   {

      if (!(adev->flags & AMD_IS_APU) || (pm_suspend_target_state != PM_SUSPEND_TO_IDLE))

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -15
index 971acf01bea6..2bc4c5bb9b5a 100644
@@ -2456,13 +2456,6 @@ static int amdgpu_pmops_prepare(struct device 
 *dev)
           pm_runtime_suspended(dev))
           return 1;
-    /* if we will not support s3 or s2i for the device
-     *  then skip suspend
-     */
-    if (!amdgpu_acpi_is_s0ix_active(adev) &&
-        !amdgpu_acpi_is_s3_active(adev))
-        return 1;
-
       return amdgpu_device_prepare(drm_dev);
   }
@@ -2476,10 +2469,6 @@ static int amdgpu_pmops_suspend(struct device 
 *dev)
       struct drm_device *drm_dev = dev_get_drvdata(dev);
       struct amdgpu_device *adev = drm_to_adev(drm_dev);
-    if (amdgpu_acpi_is_s0ix_active(adev))
-        adev->in_s0ix = true;
-    else if (amdgpu_acpi_is_s3_active(adev))
-        adev->in_s3 = true;
       if (!adev->in_s0ix && !adev->in_s3)
           return 0;
       return amdgpu_device_suspend(drm_dev, true);
@@ -2510,10 +2499,8 @@ static int amdgpu_pmops_resume(struct device 
 *dev)
           adev->no_hw_access = true;
       r = amdgpu_device_resume(drm_dev, true);
-    if (amdgpu_acpi_is_s0ix_active(adev))
-        adev->in_s0ix = false;
-    else
-        adev->in_s3 = false;
+    adev->in_s0ix = adev->in_s3 = false;
+
       return r;
   }