Skip to contentSkip to conversation

drm/amdgpu: use cached baco flag as the check in runpm (v2)

PATCH In review Guchun Chen 2 participants 3 messages Jul 12, 2022

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

PATCH 2/2 drm/amdgpu: use cached baco flag as the check in runpm (v2)

SMU will perform dpm disablement when entering BACO, and enable them later on, so talking to SMU to get enabled features mask in runpm cycle as BACO support check is not reliable. Hence, use a cached baco flag to fix it.

v2: cache this flag in load sequence to simplify code (from Evan)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 845d6054992a..816f813a5df2 100644
@@ -1014,6 +1014,7 @@ struct amdgpu_device {
 	bool                            runpm;
 	bool                            in_runpm;
 	bool                            has_pr3;
+	bool				is_baco_supported;
 
 	bool                            pm_sysfs_en;
 	bool                            ucode_sysfs_en;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 1cc9260e75de..c3f870c01c47 100644
@@ -2513,7 +2513,7 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
 		drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
 	} else if (amdgpu_device_supports_boco(drm_dev)) {
 		/* nothing to do */
-	} else if (amdgpu_device_supports_baco(drm_dev)) {
+	} else if (adev->is_baco_supported) {
 		amdgpu_device_baco_enter(drm_dev);
 	}
 
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
index 4b663866d33a..532406d32fba 100644
@@ -188,8 +188,10 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
 
 		amdgpu_runtime_pm_quirk(adev);
 
-		if (adev->runpm)
+		if (adev->runpm) {
 			dev_info(adev->dev, "Using BACO for runtime pm\n");
+			adev->is_baco_supported = true;
+		}
 	}
 
 	/* Call ACPI methods: require modeset init
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -1
index de59dc051340..f05d7ac03122 100644
@@ -2353,7 +2353,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
 	 */
 	if (adev->in_runpm &&
 	    !amdgpu_device_supports_boco(adev_to_drm(adev)) &&
-	    amdgpu_device_supports_baco(adev_to_drm(adev)))
+	    adev->is_baco_supported)
 		return 0;
 
 	if (!ucode->fw || amdgpu_sriov_vf(psp->adev))
Signature · 1 line
2.17.1
#1 lore raw

Instead of doing this way, suggest to cache the run_pm_mode in

struct amdgpu_pm {
}

You could cache the run_pm modes in kms logic - https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c#L183

Afterwards, you may use the cached value for any check

For ex: adev->pm.run_pm_mode == AMDGPU_RPM_BACO

Thanks,
Lijo

Quoted 71 lines · Guchun Chen

SMU will perform dpm disablement when entering BACO, and enable them later on, so talking to SMU to get enabled features mask in runpm cycle as BACO support check is not reliable. Hence, use a cached baco flag to fix it.

v2: cache this flag in load sequence to simplify code (from Evan)

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +-
  4 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 845d6054992a..816f813a5df2 100644
@@ -1014,6 +1014,7 @@ struct amdgpu_device {
  	bool                            runpm;
  	bool                            in_runpm;
  	bool                            has_pr3;
+	bool				is_baco_supported;
 
  	bool                            pm_sysfs_en;
  	bool                            ucode_sysfs_en;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 1cc9260e75de..c3f870c01c47 100644
@@ -2513,7 +2513,7 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
  		drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
  	} else if (amdgpu_device_supports_boco(drm_dev)) {
  		/* nothing to do */
-	} else if (amdgpu_device_supports_baco(drm_dev)) {
+	} else if (adev->is_baco_supported) {
  		amdgpu_device_baco_enter(drm_dev);
  	}
 
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
index 4b663866d33a..532406d32fba 100644
@@ -188,8 +188,10 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
 
  		amdgpu_runtime_pm_quirk(adev);
 
-		if (adev->runpm)
+		if (adev->runpm) {
  			dev_info(adev->dev, "Using BACO for runtime pm\n");
+			adev->is_baco_supported = true;
+		}
  	}
 
  	/* Call ACPI methods: require modeset init
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -1
index de59dc051340..f05d7ac03122 100644
@@ -2353,7 +2353,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
  	 */
  	if (adev->in_runpm &&
  	    !amdgpu_device_supports_boco(adev_to_drm(adev)) &&
-	    amdgpu_device_supports_baco(adev_to_drm(adev)))
+	    adev->is_baco_supported)
  		return 0;
 
  	if (!ucode->fw || amdgpu_sriov_vf(psp->adev))
#2 lore raw

Thanks for your suggestion, Lijo. I will follow your suggestion in a new patch set.

Regards,
Guchun

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, July 12, 2022 2:57 PM
To: Chen, Guchun <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Quan, Evan <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: use cached baco flag as the check in runpm (v2)

Instead of doing this way, suggest to cache the run_pm_mode in

struct amdgpu_pm {
}

You could cache the run_pm modes in kms logic -
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c#L183

Afterwards, you may use the cached value for any check

For ex: adev->pm.run_pm_mode == AMDGPU_RPM_BACO

Thanks,
Lijo

Quoted 75 lines · Guchun Chen

SMU will perform dpm disablement when entering BACO, and enable them later on, so talking to SMU to get enabled features mask in runpm cycle as BACO support check is not reliable. Hence, use a cached baco flag to fix it.

v2: cache this flag in load sequence to simplify code (from Evan)

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +-
  4 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 845d6054992a..816f813a5df2 100644
@@ -1014,6 +1014,7 @@ struct amdgpu_device {
  	bool                            runpm;
  	bool                            in_runpm;
  	bool                            has_pr3;
+	bool				is_baco_supported;
 
  	bool                            pm_sysfs_en;
  	bool                            ucode_sysfs_en;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 1cc9260e75de..c3f870c01c47 100644
@@ -2513,7 +2513,7 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
  		drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
  	} else if (amdgpu_device_supports_boco(drm_dev)) {
  		/* nothing to do */
-	} else if (amdgpu_device_supports_baco(drm_dev)) {
+	} else if (adev->is_baco_supported) {
  		amdgpu_device_baco_enter(drm_dev);
  	}
 
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
index 4b663866d33a..532406d32fba 100644
@@ -188,8 +188,10 @@ int amdgpu_driver_load_kms(struct amdgpu_device 
 *adev, unsigned long flags)
 
  		amdgpu_runtime_pm_quirk(adev);
 
-		if (adev->runpm)
+		if (adev->runpm) {
  			dev_info(adev->dev, "Using BACO for runtime pm\n");
+			adev->is_baco_supported = true;
+		}
  	}
 

/* Call ACPI methods: require modeset init diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index de59dc051340..f05d7ac03122 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -1
@@ -2353,7 +2353,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
  	 */
  	if (adev->in_runpm &&
  	    !amdgpu_device_supports_boco(adev_to_drm(adev)) &&
-	    amdgpu_device_supports_baco(adev_to_drm(adev)))
+	    adev->is_baco_supported)
  		return 0;
 
  	if (!ucode->fw || amdgpu_sriov_vf(psp->adev))