Adjustment to power limit setting
Subsystems (3)
cover Adjustment to power limit setting
Lijo pointed out to me that
commit ed4efe426a49 ("drm/amd: Restore cached power limit during resume") commit 796ff8a7e01b ("drm/amd: Restore cached manual clock settings during resume")
both should be unnecessary because smu_restore_dpm_user_profile() already restores them. However in looking at the code there is a case that isn't properly restored - the FAST PPT limits supported by Van Gogh. The nuance isn't immediately obvious because the limit variable is overloaded with limit type.
This series attempts to address that issue by passing limit type around and saving/restoring both types.
Mario Limonciello (3):
drm/amd: Remove some unncessary header includes
drm/amd: Stop overloading power limit with limit type drm/amd: Drop calls to restore power limit and clock from smu_resume()
.../gpu/drm/amd/include/kgd_pp_interface.h | 2 +- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 3 +- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 3 +- drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 +- .../gpu/drm/amd/pm/powerplay/amd_powerplay.c | 5 +- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 46 +++++++++---------- drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 3 +- 7 files changed, 31 insertions(+), 33 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/3 drm/amd: Remove some unncessary header includes
Unnecessary headers can slow down the build, drop em.
No intended functional changes.
--- drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -3
@@ -20,7 +20,6 @@* OTHER DEALINGS IN THE SOFTWARE. * */ -#include "pp_debug.h" #include <linux/types.h> #include <linux/kernel.h> #include <linux/gfp.h>
@@ -28,12 +27,10 @@#include <linux/firmware.h> #include <linux/reboot.h> #include "amd_shared.h" -#include "amd_powerplay.h" #include "power_state.h" #include "amdgpu.h" #include "hwmgr.h" #include "amdgpu_dpm_internal.h" -#include "amdgpu_display.h" static const struct amd_pm_funcs pp_dpm_funcs;
Signature · 1 line
2.51.0
PATCH 2/3 drm/amd: Stop overloading power limit with limit type
In reply to Mario LimoncielloWhen passed around internally the upper 8 bits of power limit include the limit type. This is non-obvious without digging into the nuances of each function. Instead pass the limit type as an argument to all applicable layers.
When the limit type is passed around it is apparent that the user settings for power limits are only being restored for default limit not fast limit. Save and restore both.
--- .../gpu/drm/amd/include/kgd_pp_interface.h | 2 +- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 3 +- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 3 +- drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 +- .../gpu/drm/amd/pm/powerplay/amd_powerplay.c | 2 +- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 39 +++++++++++++------ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 3 +- 7 files changed, 35 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -1
@@ -445,7 +445,7 @@ struct amd_pm_funcs {bool gate, int inst);int (*set_clockgating_by_smu)(void *handle,uint32_t msg_id); -int (*set_power_limit)(void *handle,uint32_t n); +int (*set_power_limit)(void *handle,uint32_t limit_type,uint32_t n);int (*get_power_limit)(void *handle,uint32_t *limit,enum pp_power_limit_level pp_limit_level,enum pp_power_type power_type);
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -1
@@ -1605,6 +1605,7 @@ int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev, }int amdgpu_dpm_set_power_limit (struct amdgpu_device *adev, +uint32_t limit_type,uint32_t limit) {const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
@@ -1615,7 +1616,7 @@ int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,mutex_lock (&adev->pm.mutex); ret = pp_funcs->set_power_limit (adev->powerplay.pp_handle, - limit); + limit_type, limit);mutex_unlock (&adev->pm.mutex);return ret;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
@@ -3172,13 +3172,12 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,return err; value = value /1000000 ;/* convert to Watt */ - value |= limit_type <<24 ; err =amdgpu_pm_get_access (adev);if (err <0 )return err; - err =amdgpu_dpm_set_power_limit (adev, value); + err =amdgpu_dpm_set_power_limit (adev, limit_type, value);amdgpu_pm_put_access (adev);
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -1
@@ -555,7 +555,7 @@ int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,enum pp_power_limit_level pp_limit_level, enum pp_power_type power_type);int amdgpu_dpm_set_power_limit (struct amdgpu_device *adev, -uint32_t limit); +uint32_t limit_type,uint32_t limit);int amdgpu_dpm_is_cclk_dpm_supported (struct amdgpu_device *adev);int amdgpu_dpm_debugfs_print_current_performance_level (struct amdgpu_device *adev,struct seq_file *m);
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
@@ -952,7 +952,7 @@ static int pp_dpm_switch_power_profile(void *handle,return 0 ; } -static int pp_set_power_limit (void *handle,uint32_t limit) +static int pp_set_power_limit (void *handle,uint32_t limit_type,uint32_t limit) {struct pp_hwmgr *hwmgr = handle;uint32_t max_power_limit;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +27 -12
@@ -68,7 +68,7 @@ static int smu_handle_task(struct smu_context *smu,static int smu_reset (struct smu_context *smu);static int smu_set_fan_speed_pwm (void *handle,u32 speed);static int smu_set_fan_control_mode (void *handle,u32 value); -static int smu_set_power_limit (void *handle,uint32_t limit); +static int smu_set_power_limit (void *handle,uint32_t limit_type,uint32_t limit);static int smu_set_fan_speed_rpm (void *handle,uint32_t speed);static int smu_set_gfx_cgpg (struct smu_context *smu,bool enabled);static int smu_set_mp1_state (void *handle,enum pp_mp1_state mp1_state);
@@ -508,11 +508,18 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu)/* Enable restore flag */ smu->user_dpm_profile.flags |=SMU_DPM_USER_PROFILE_RESTORE ; -/* set the user dpm power limit */ -if (smu->user_dpm_profile.power_limit) { - ret =smu_set_power_limit (smu, smu->user_dpm_profile.power_limit); +/* set the user dpm power limits */ +if (smu->user_dpm_profile.power_limit_default) { + ret =smu_set_power_limit (smu,SMU_DEFAULT_PPT_LIMIT , + smu->user_dpm_profile.power_limit_default);if (ret) -dev_err (smu->adev->dev,"Failed to set power limit value\n" ); +dev_err (smu->adev->dev,"Failed to set default power limit value\n" ); + } +if (smu->user_dpm_profile.power_limit_fast) { + ret =smu_set_power_limit (smu,SMU_FAST_PPT_LIMIT , + smu->user_dpm_profile.power_limit_fast); +if (ret) +dev_err (smu->adev->dev,"Failed to set fast power limit value\n" ); }/* set the user dpm clock configurations */
@@ -2229,7 +2236,7 @@ static int smu_resume(struct amdgpu_ip_block *ip_block) adev->pm.dpm_enabled = true;if (smu->current_power_limit) { - ret =smu_set_power_limit (smu, smu->current_power_limit); + ret =smu_set_power_limit (smu,SMU_DEFAULT_PPT_LIMIT , smu->current_power_limit);if (ret && ret != -EOPNOTSUPP )return ret; }
@@ -2929,16 +2936,14 @@ int smu_get_power_limit(void *handle,return ret; } -static int smu_set_power_limit (void *handle,uint32_t limit) +static int smu_set_power_limit (void *handle,uint32_t limit_type,uint32_t limit) {struct smu_context *smu = handle; -uint32_t limit_type = limit >>24 ;int ret =0 ;if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)return -EOPNOTSUPP ; - limit &= (1 <<24 )-1 ;if ((limit > smu->max_power_limit) || (limit < smu->min_power_limit)) { dev_err(smu->adev->dev, "New power limit (%d) is out of range [%d,%d]\n",
@@ -2951,11 +2956,21 @@ static int smu_set_power_limit(void *handle, uint32_t limit)if (smu->ppt_funcs->set_power_limit) { ret = smu->ppt_funcs->set_power_limit (smu, limit_type, limit); -if (!ret && !(smu->user_dpm_profile.flags &SMU_DPM_USER_PROFILE_RESTORE )) - smu->user_dpm_profile.power_limit = limit; +if (ret) +return ret; +if (!(smu->user_dpm_profile.flags &SMU_DPM_USER_PROFILE_RESTORE )) { +switch (limit_type) { +case SMU_DEFAULT_PPT_LIMIT : + smu->user_dpm_profile.power_limit_default = limit; +break ; +case SMU_FAST_PPT_LIMIT : + smu->user_dpm_profile.power_limit_fast = limit; +break ; + }; + } } -return ret; +return 0 ; }static int smu_print_smuclk_levels (struct smu_context *smu,enum smu_clk_type clk_type,char *buf)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +2 -1
@@ -231,7 +231,8 @@ enum smu_memory_pool_size {struct smu_user_dpm_profile {uint32_t fan_mode; -uint32_t power_limit; +uint32_t power_limit_default; +uint32_t power_limit_fast;uint32_t fan_speed_pwm;uint32_t fan_speed_rpm;uint32_t flags;
Signature · 1 line
2.51.0
RE: [PATCH 2/3] drm/amd: Stop overloading power limit with limit type
[Public]
Patches 1 and 3 are
For this one, suggest splitting to two patches - one to pass the limit type and the other to save/restore fast ppt limit. Could add LIMIT_TYPE_COUNT to enum smu_ppt_limit_type and keep an array in smu_user_dpm_profile. However, this fast ppt limit is only there for Vangogh now.
Thanks,
Lijo
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Wednesday, October 1, 2025 11:34 PM
To: Limonciello, Mario <[email protected]>; [email protected]
Cc: Lazar, Lijo <[email protected]>
Subject: [PATCH 2/3] drm/amd: Stop overloading power limit with limit type
When passed around internally the upper 8 bits of power limit include the limit type. This is non-obvious without digging into the nuances of each function. Instead pass the limit type as an argument to all applicable layers.
When the limit type is passed around it is apparent that the user settings for power limits are only being restored for default limit not fast limit. Save and restore both.
--- .../gpu/drm/amd/include/kgd_pp_interface.h | 2 +- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 3 +- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 3 +- drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 +- .../gpu/drm/amd/pm/powerplay/amd_powerplay.c | 2 +- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 39 +++++++++++++------ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 3 +- 7 files changed, 35 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -1
@@ -445,7 +445,7 @@ struct amd_pm_funcs {bool gate, int inst);int (*set_clockgating_by_smu)(void *handle,uint32_t msg_id); -int (*set_power_limit)(void *handle,uint32_t n); +int (*set_power_limit)(void *handle,uint32_t limit_type,uint32_t n);int (*get_power_limit)(void *handle,uint32_t *limit,enum pp_power_limit_level pp_limit_level,enum pp_power_type power_type);
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
@@ -1605,6 +1605,7 @@ int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev, }int amdgpu_dpm_set_power_limit (struct amdgpu_device *adev, +uint32_t limit_type,uint32_t limit) { const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; @@ -1615,7 +1616,7 @@ int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
mutex_lock(&adev->pm.mutex);
ret = pp_funcs->set_power_limit(adev->powerplay.pp_handle,
- limit);
+ limit_type, limit);
mutex_unlock(&adev->pm.mutex);
return ret;drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
@@ -3172,13 +3172,12 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,return err; value = value /1000000 ;/* convert to Watt */ - value |= limit_type <<24 ; err =amdgpu_pm_get_access (adev);if (err <0 )return err; - err =amdgpu_dpm_set_power_limit (adev, value); + err =amdgpu_dpm_set_power_limit (adev, limit_type, value);amdgpu_pm_put_access (adev);
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -1
@@ -555,7 +555,7 @@ int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,enum pp_power_limit_level pp_limit_level, enum pp_power_type power_type); int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev, -uint32_t limit); +uint32_t limit_type,uint32_t limit);int amdgpu_dpm_is_cclk_dpm_supported (struct amdgpu_device *adev);int amdgpu_dpm_debugfs_print_current_performance_level (struct amdgpu_device *adev,struct seq_file *m);
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -1
@@ -952,7 +952,7 @@ static int pp_dpm_switch_power_profile(void *handle,return 0 ; } -static int pp_set_power_limit (void *handle,uint32_t limit) +static int pp_set_power_limit (void *handle,uint32_t limit_type, +uint32_t limit) {struct pp_hwmgr *hwmgr = handle;
uint32_t max_power_limit;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
@@ -68,7 +68,7 @@ static int smu_handle_task(struct smu_context *smu, static int smu_reset(struct smu_context *smu); static int smu_set_fan_speed_pwm(void *handle, u32 speed); static int smu_set_fan_control_mode(void *handle, u32 value); -static int smu_set_power_limit(void *handle, uint32_t limit); +static int smu_set_power_limit (void *handle,uint32_t limit_type, +uint32_t limit); static int smu_set_fan_speed_rpm(void *handle, uint32_t speed); static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled); static int smu_set_mp1_state(void *handle, enum pp_mp1_state mp1_state); @@ -508,11 +508,18 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu) /* Enable restore flag */ smu->user_dpm_profile.flags |= SMU_DPM_USER_PROFILE_RESTORE; -/* set the user dpm power limit */ -if (smu->user_dpm_profile.power_limit) { - ret =smu_set_power_limit (smu, smu->user_dpm_profile.power_limit); +/* set the user dpm power limits */
+ if (smu->user_dpm_profile.power_limit_default) {
+ ret = smu_set_power_limit(smu, SMU_DEFAULT_PPT_LIMIT,
+ smu->user_dpm_profile.power_limit_default);
if (ret)
- dev_err(smu->adev->dev, "Failed to set power limit value\n");
+ dev_err(smu->adev->dev, "Failed to set default power limit value\n");
+ }
+ if (smu->user_dpm_profile.power_limit_fast) {
+ ret = smu_set_power_limit(smu, SMU_FAST_PPT_LIMIT,
+ smu->user_dpm_profile.power_limit_fast);
+ if (ret)
+ dev_err(smu->adev->dev, "Failed to set fast power limit value\n");
}
/* set the user dpm clock configurations */ @@ -2229,7 +2236,7 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)
adev->pm.dpm_enabled = true;
if (smu->current_power_limit) {
- ret = smu_set_power_limit(smu, smu->current_power_limit);
+ ret = smu_set_power_limit(smu, SMU_DEFAULT_PPT_LIMIT,
+smu->current_power_limit);
if (ret && ret != -EOPNOTSUPP)
return ret;
}
@@ -2929,16 +2936,14 @@ int smu_get_power_limit(void *handle,
return ret;}
-static int smu_set_power_limit(void *handle, uint32_t limit) +static int smu_set_power_limit(void *handle, uint32_t limit_type, +uint32_t limit)
{
struct smu_context *smu = handle;
- uint32_t limit_type = limit >> 24;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP;- limit &= (1<<24)-1;
if ((limit > smu->max_power_limit) || (limit < smu->min_power_limit)) {
dev_err(smu->adev->dev,
"New power limit (%d) is out of range [%d,%d]\n", @@ -2951,11 +2956,21 @@ static int smu_set_power_limit(void *handle, uint32_t limit)
if (smu->ppt_funcs->set_power_limit) {
ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit);- if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE))
- smu->user_dpm_profile.power_limit = limit;
+ if (ret)
+ return ret;
+ if (!(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
+ switch (limit_type) {
+ case SMU_DEFAULT_PPT_LIMIT:
+ smu->user_dpm_profile.power_limit_default = limit;
+ break;
+ case SMU_FAST_PPT_LIMIT:
+ smu->user_dpm_profile.power_limit_fast = limit;
+ break;
+ };
+ }
}
- return ret;
+ return 0;
}
static int smu_print_smuclk_levels(struct smu_context *smu, enum smu_clk_type clk_type, char *buf) 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 b52e194397e2..19689ef1db99 100644
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +2 -1
@@ -231,7 +231,8 @@ enum smu_memory_pool_size {struct smu_user_dpm_profile {uint32_t fan_mode; -uint32_t power_limit; +uint32_t power_limit_default; +uint32_t power_limit_fast;uint32_t fan_speed_pwm;uint32_t fan_speed_rpm;uint32_t flags;
--
2.51.0
PATCH 3/3 drm/amd: Drop calls to restore power limit and clock from smu_resume()
In reply to Mario LimoncielloUser requested power limits and clock settings are already restored as part of smu_restore_dpm_user_profile(). It's unnecessary to call the same restore as part of smu_resume().
Revert the following commits to drop that extra restore:
commit ed4efe426a49 ("drm/amd: Restore cached power limit during resume")
commit 796ff8a7e01b ("drm/amd: Restore cached manual clock settings during resume") commit f9b80514a722 ("drm/amd: Only restore cached manual clock settings in restore if OD enabled")
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -13
@@ -2203,7 +2203,6 @@ static int smu_resume(struct amdgpu_ip_block *ip_block)int ret;struct amdgpu_device *adev = ip_block->adev;struct smu_context *smu = adev->powerplay.pp_handle; -struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);if (amdgpu_sriov_multi_vf_mode (adev))return 0 ;
@@ -2235,18 +2234,6 @@ static int smu_resume(struct amdgpu_ip_block *ip_block) adev->pm.dpm_enabled = true; -if (smu->current_power_limit) { - ret =smu_set_power_limit (smu,SMU_DEFAULT_PPT_LIMIT , smu->current_power_limit); -if (ret && ret != -EOPNOTSUPP ) -return ret; - } - -if (smu_dpm_ctx->dpm_level ==AMD_DPM_FORCED_LEVEL_MANUAL && smu->od_enabled) { - ret =smu_od_edit_dpm_table (smu,PP_OD_COMMIT_DPM_TABLE ,NULL ,0 ); -if (ret) -return ret; - } -dev_info (adev->dev,"SMU is resumed successfully!\n" );return 0 ;
Signature · 1 line
2.51.0