Skip to contentSkip to conversation

drm/amd/pm: add the interface to set and save the bootup workload type

PATCH Superseded Kenneth Feng 2 participants 3 messages Jan 8, 2025

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kenneth Feng

author maintainer
#0 lore raw

PATCH v2 1/2 drm/amd/pm: add the interface to set and save the bootup workload type

add the interface to set and save the bootup workload type
v2: add is_support_sw_smu check and pm mutex lock.

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  3 ++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  1 +
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  1 +
 4 files changed, 44 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +39 -0
index 6a9e26905edf..94e92e496e55 100644
@@ -349,6 +349,45 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,
 	return ret;
 }
 
+int amdgpu_dpm_set_and_save_bootup_power_profile(struct amdgpu_device *adev,
+						bool en)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	struct smu_context *smu = (struct smu_context*)(adev->powerplay.pp_handle);
+	int ret = 0;
+	int current_profile_mode;
+	int saved_profile_mode;
+
+	mutex_lock(&adev->pm.mutex);
+	current_profile_mode = smu->power_profile_mode;
+	saved_profile_mode = smu->saved_power_profile_mode;
+	mutex_unlock(&adev->pm.mutex);
+
+	if (en && current_profile_mode == PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT)
+		return 0;
+
+	if (!en && current_profile_mode != PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT)
+		return 0;
+
+	if (en) {
+		ret = amdgpu_dpm_switch_power_profile(adev, current_profile_mode, !en);
+		mutex_lock(&adev->pm.mutex);
+		smu->saved_power_profile_mode = current_profile_mode;
+		smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+		mutex_unlock(&adev->pm.mutex);
+	} else {
+		ret = amdgpu_dpm_switch_power_profile(adev, saved_profile_mode, !en);
+		mutex_lock(&adev->pm.mutex);
+		smu->power_profile_mode = saved_profile_mode;
+		smu->saved_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+		mutex_unlock(&adev->pm.mutex);
+	}
+
+	return ret;
+}
+
 int amdgpu_dpm_set_xgmi_pstate(struct amdgpu_device *adev,
 			       uint32_t pstate)
 {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
index 1f5ac7e0230d..5fe404bbb033 100644
@@ -410,6 +410,9 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,
 				    enum PP_SMC_POWER_PROFILE type,
 				    bool en);
 
+int amdgpu_dpm_set_and_save_bootup_power_profile(struct amdgpu_device *adev,
+				    bool en);
+
 int amdgpu_dpm_baco_reset(struct amdgpu_device *adev);
 
 int amdgpu_dpm_mode2_reset(struct amdgpu_device *adev);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
index 8ca793c222ff..a6f748361198 100644
@@ -1272,6 +1272,7 @@ static void smu_init_power_profile(struct smu_context *smu)
 				PP_SMC_POWER_PROFILE_FULLSCREEN3D;
 	}
 	smu_power_profile_mode_get(smu, smu->power_profile_mode);
+	smu->saved_power_profile_mode = smu->power_profile_mode;
 }
 
 static int smu_sw_init(struct amdgpu_ip_block *ip_block)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +1 -0
index 3630593bce61..c58fc31fb1d7 100644
@@ -560,6 +560,7 @@ struct smu_context {
 	uint32_t workload_mask;
 	/* default/user workload preference */
 	uint32_t power_profile_mode;
+	uint32_t saved_power_profile_mode;
 	uint32_t workload_refcount[PP_SMC_POWER_PROFILE_COUNT];
 	/* backend specific custom workload settings */
 	long *custom_profile_params;
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 2/2 drm/amd/display: set the workload based on MALL status

set the workload based on MALL status

---
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +16 -2
index 8bc73922e3a6..c569c8b4bdf9 100644
@@ -244,6 +244,8 @@ static void amdgpu_dm_crtc_vblank_control_worker(struct work_struct *work)
 	struct vblank_control_work *vblank_work =
 		container_of(work, struct vblank_control_work, work);
 	struct amdgpu_display_manager *dm = vblank_work->dm;
+	struct amdgpu_device *adev = dm->adev;
+	int ret;
 
 	mutex_lock(&dm->dc_lock);
 
@@ -252,8 +254,14 @@ static void amdgpu_dm_crtc_vblank_control_worker(struct work_struct *work)
 	else if (dm->active_vblank_irq_count)
 		dm->active_vblank_irq_count--;
 
-	if (dm->active_vblank_irq_count > 0)
+	if (dm->active_vblank_irq_count > 0) {
+		ret = amdgpu_dpm_set_and_save_bootup_power_profile(adev, false);
+		if (ret) {
+			dev_err(adev->dev, "(%d) failed to exit bootup workload\n", ret);
+			return;
+		}
 		dc_allow_idle_optimizations(dm->dc, false);
+	}
 
 	/*
 	 * Control PSR based on vblank requirements from OS
@@ -271,8 +279,14 @@ static void amdgpu_dm_crtc_vblank_control_worker(struct work_struct *work)
 			vblank_work->acrtc->dm_irq_params.allow_sr_entry);
 	}
 
-	if (dm->active_vblank_irq_count == 0)
+	if (dm->active_vblank_irq_count == 0) {
+		ret = amdgpu_dpm_set_and_save_bootup_power_profile(adev, true);
+		if (ret) {
+			dev_err(adev->dev, "(%d) failed to set bootup workload\n", ret);
+			return;
+		}
 		dc_allow_idle_optimizations(dm->dc, true);
+	}
 
 	mutex_unlock(&dm->dc_lock);
 
Signature · 1 line
2.34.1
#2 lore raw
In reply to Kenneth Feng

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Kenneth Feng
Sent: Wednesday, January 8, 2025 11:36
To: [email protected]
Cc: Pillai, Aurabindo <[email protected]>; Deucher, Alexander <[email protected]>; Feng, Kenneth <[email protected]>
Subject: [PATCH v2 1/2] drm/amd/pm: add the interface to set and save the bootup workload type

add the interface to set and save the bootup workload type
v2: add is_support_sw_smu check and pm mutex lock.

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 39 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  3 ++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  1 +
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  1 +
 4 files changed, 44 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +35 -0
index 6a9e26905edf..94e92e496e55 100644
@@ -349,6 +349,45 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,
        return ret;
 }
 
+int amdgpu_dpm_set_and_save_bootup_power_profile(struct amdgpu_device *adev,
+                                               bool en)
+{
+       if (!is_support_sw_smu(adev))
+               return -EOPNOTSUPP;
+
+       struct smu_context *smu = (struct smu_context*)(adev->powerplay.pp_handle);
+       int ret = 0;
+       int current_profile_mode;
+       int saved_profile_mode;
+
+       mutex_lock(&adev->pm.mutex);
+       current_profile_mode = smu->power_profile_mode;
+       saved_profile_mode = smu->saved_power_profile_mode;
+       mutex_unlock(&adev->pm.mutex);
+
+       if (en && current_profile_mode == PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT)
+               return 0;
+
+       if (!en && current_profile_mode != PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT)
+               return 0;
+
+       if (en) {
+               ret = amdgpu_dpm_switch_power_profile(adev, current_profile_mode, !en);
+               mutex_lock(&adev->pm.mutex);
+               smu->saved_power_profile_mode = current_profile_mode;
+               smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+               mutex_unlock(&adev->pm.mutex);
+       } else {
+               ret = amdgpu_dpm_switch_power_profile(adev, saved_profile_mode, !en);
+               mutex_lock(&adev->pm.mutex);
+               smu->power_profile_mode = saved_profile_mode;
+               smu->saved_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+               mutex_unlock(&adev->pm.mutex);
+       }
 

[kevin]:
I think we'd better check ret value first, then assign new value to smu global profile state? which can avoid some logical errors in some corner cases, is it ok?

Best Regards,
Kevin
+ return ret;
+}
+
int amdgpu_dpm_set_xgmi_pstate(struct amdgpu_device *adev,
uint32_t pstate)
{

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
index 1f5ac7e0230d..5fe404bbb033 100644
@@ -410,6 +410,9 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,
                                    enum PP_SMC_POWER_PROFILE type,
                                    bool en);
 
+int amdgpu_dpm_set_and_save_bootup_power_profile(struct amdgpu_device *adev,
+                                   bool en);
+
 int amdgpu_dpm_baco_reset(struct amdgpu_device *adev);
 
 int amdgpu_dpm_mode2_reset(struct amdgpu_device *adev); diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

index 8ca793c222ff..a6f748361198 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -1272,6 +1272,7 @@ static void smu_init_power_profile(struct smu_context *smu)
                                PP_SMC_POWER_PROFILE_FULLSCREEN3D;
        }
        smu_power_profile_mode_get(smu, smu->power_profile_mode);
+       smu->saved_power_profile_mode = smu->power_profile_mode;
 }
 
 static int smu_sw_init(struct amdgpu_ip_block *ip_block) diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h

index 3630593bce61..c58fc31fb1d7 100644

drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +1 -0
@@ -560,6 +560,7 @@ struct smu_context {
        uint32_t workload_mask;
        /* default/user workload preference */
        uint32_t power_profile_mode;
+       uint32_t saved_power_profile_mode;
        uint32_t workload_refcount[PP_SMC_POWER_PROFILE_COUNT];
        /* backend specific custom workload settings */
        long *custom_profile_params;

--
2.34.1