drm/amd/powerplay: support power profile retrieval and setting on arcturus
Subsystems (3)
PATCH 1/2 drm/amd/powerplay: support power profile retrieval and setting on arcturus
Enable arcturus power profile retrieval and setting.
--- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +69 -0
@@ -1503,6 +1503,73 @@ static int arcturus_get_power_limit(struct smu_context *smu,return 0 ; } +static int arcturus_get_power_profile_mode (struct smu_context *smu, +char *buf) +{ +static const char *profile_name[] = { +"BOOTUP_DEFAULT" , +"3D_FULL_SCREEN" , +"POWER_SAVING" , +"VIDEO" , +"VR" , +"COMPUTE" , +"CUSTOM" }; +uint32_t i, size =0 ; +int16_t workload_type =0 ; + +if (!smu->pm_enabled || !buf) +return -EINVAL ; + +for (i =0 ; i <=PP_SMC_POWER_PROFILE_CUSTOM ; i++) { +/* +* Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT +* Not all profile modes are supported on arcturus. +*/ + workload_type =smu_workload_get_type (smu, i); +if (workload_type <0 ) +continue ; + + size +=sprintf (buf + size,"%2d %14s%s\n" , + i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " ); + } + +return size; +} + +static int arcturus_set_power_profile_mode (struct smu_context *smu, +long *input, +uint32_t size) +{ +int workload_type =0 ; +uint32_t profile_mode = input[size]; + +if (!smu->pm_enabled) +return -EINVAL ; + +if (profile_mode >PP_SMC_POWER_PROFILE_CUSTOM ) { +pr_err ("Invalid power profile mode %d\n" , profile_mode); +return -EINVAL ; + } + +/* +* Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT +* Not all profile modes are supported on arcturus. +*/ + workload_type =smu_workload_get_type (smu, profile_mode); +if (workload_type <0 ) { +pr_err ("Unsupported power profile mode %d on arcturus\n" , profile_mode); +return -EINVAL ; + } + +smu_send_smc_msg_with_param (smu, + SMU_MSG_SetWorkloadMask, +1 << workload_type); + + smu->power_profile_mode = profile_mode; + +return 0 ; +} +static void arcturus_dump_pptable (struct smu_context *smu) {struct smu_table_context *table_context = &smu->smu_table;
@@ -1968,6 +2035,8 @@ static const struct pptable_funcs arcturus_ppt_funcs = { .force_dpm_limit_value = arcturus_force_dpm_limit_value, .unforce_dpm_levels = arcturus_unforce_dpm_levels, .get_profiling_clk_mask = arcturus_get_profiling_clk_mask, + .get_power_profile_mode = arcturus_get_power_profile_mode, + .set_power_profile_mode = arcturus_set_power_profile_mode,/* debug (internal used) */ .dump_pptable = arcturus_dump_pptable, .get_power_limit = arcturus_get_power_limit,
Signature · 6 lines
2.22.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/2 drm/amd/powerplay: enable SW SMU power profile switch support in KFD
Hook up the SW SMU power profile switch in KFD routine.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 8 +++-- drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 36 +++++++++++++++++++ .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 3 ++ 3 files changed, 45 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +6 -2
@@ -672,8 +672,12 @@ void amdgpu_amdkfd_set_compute_idle(struct kgd_dev *kgd, bool idle) {struct amdgpu_device *adev = (struct amdgpu_device *)kgd; -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->switch_power_profile) +if (is_support_sw_smu (adev)) +smu_switch_power_profile (&adev->smu, +PP_SMC_POWER_PROFILE_COMPUTE , + !idle); +else if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->switch_power_profile)amdgpu_dpm_switch_power_profile (adev,PP_SMC_POWER_PROFILE_COMPUTE , !idle);
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +36 -0
@@ -1447,6 +1447,42 @@ int smu_handle_task(struct smu_context *smu,return ret; } +int smu_switch_power_profile (struct smu_context *smu, +enum PP_SMC_POWER_PROFILE type, +bool en) +{ +struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm); +long workload; +uint32_t index; + +if (!smu->pm_enabled) +return -EINVAL ; + +if (!(type <PP_SMC_POWER_PROFILE_CUSTOM )) +return -EINVAL ; + +mutex_lock (&smu->mutex); + +if (!en) { + smu->workload_mask &= ~(1 << smu->workload_prority[type]); + index =fls (smu->workload_mask); + index = index >0 && index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; + workload = smu->workload_setting[index]; + }else { + smu->workload_mask |= (1 << smu->workload_prority[type]); + index =fls (smu->workload_mask); + index = index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; + workload = smu->workload_setting[index]; + } + +if (smu_dpm_ctx->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL ) +smu_set_power_profile_mode (smu, &workload,0 ); + +mutex_unlock (&smu->mutex); + +return 0 ; +} +enum amd_dpm_forced_level smu_get_performance_level (struct smu_context *smu) {struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +3 -0
@@ -973,6 +973,9 @@ extern int smu_dpm_set_power_gate(struct smu_context *smu,uint32_t block_type, bextern int smu_handle_task (struct smu_context *smu,enum amd_dpm_forced_level level,enum amd_pp_task task_id); +int smu_switch_power_profile (struct smu_context *smu, +enum PP_SMC_POWER_PROFILE type, +bool en);int smu_get_smc_version (struct smu_context *smu,uint32_t *if_version,uint32_t *smu_version);int smu_get_dpm_freq_by_index (struct smu_context *smu,enum smu_clk_type clk_type,uint16_t level,uint32_t *value);
Signature · 6 lines
2.22.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Kevin Wang
Reviewed-byRe: [PATCH 2/2] drm/amd/powerplay: enable SW SMU power profile switch support in KFD
BR
Kevin
Quoted 81 lines · Evan Quan
Hook up the SW SMU power profile switch in KFD routine.
Change-Id I41e53762cdc7504285de89f30e3e6e2bb396b953Signed-off-by Evan Quan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 8 +++-- drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 36 +++++++++++++++++++ .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 3 ++ 3 files changed, 45 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +6
-2@@ -672,8 +672,12 @@ void amdgpu_amdkfd_set_compute_idle(struct kgd_dev *kgd, bool idle) {struct amdgpu_device *adev = (struct amdgpu_device *)kgd; -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->switch_power_profile) +if (is_support_sw_smu (adev)) +smu_switch_power_profile (&adev->smu, +PP_SMC_POWER_PROFILE_COMPUTE , + !idle); +else if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->switch_power_profile)amdgpu_dpm_switch_power_profile (adev,PP_SMC_POWER_PROFILE_COMPUTE , !idle);drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +36
-0@@ -1447,6 +1447,42 @@ int smu_handle_task(struct smu_context *smu,return ret; } +int smu_switch_power_profile (struct smu_context *smu, +enum PP_SMC_POWER_PROFILE type, +bool en) +{ +struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm); +long workload; +uint32_t index; + +if (!smu->pm_enabled) +return -EINVAL ; + +if (!(type <PP_SMC_POWER_PROFILE_CUSTOM )) +return -EINVAL ; + +mutex_lock (&smu->mutex); + +if (!en) { + smu->workload_mask &= ~(1 << smu->workload_prority[type]); + index =fls (smu->workload_mask); + index = index >0 && index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; + workload = smu->workload_setting[index]; + }else { + smu->workload_mask |= (1 << smu->workload_prority[type]); + index =fls (smu->workload_mask); + index = index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; + workload = smu->workload_setting[index]; + } + +if (smu_dpm_ctx->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL ) +smu_set_power_profile_mode (smu, &workload,0 ); + +mutex_unlock (&smu->mutex); + +return 0 ; +} +enum amd_dpm_forced_level smu_get_performance_level (struct smu_context *smu) {struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +0
-0
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h extern int smu_dpm_set_power_gate(struct smu_context *smu,uint32_t block_type, b · line 981
Quoted 9 lines
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +3
-0@@ -973,6 +973,9 @@ extern int smu_dpm_set_power_gate(struct smu_context *smu,uint32_t block_type, bextern int smu_handle_task (struct smu_context *smu,enum amd_dpm_forced_level level,enum amd_pp_task task_id); +int smu_switch_power_profile (struct smu_context *smu, +enum PP_SMC_POWER_PROFILE type, +bool en);int smu_get_smc_version (struct smu_context *smu,uint32_t *if_version,uint32_t *smu_version);int smu_get_dpm_freq_by_index (struct smu_context *smu,enum smu_clk_type clk_type,uint16_t level,uint32_t *value);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Kevin Wang
Reviewed-byQuoted 67 lines · Evan Quan
Enable arcturus power profile retrieval and setting.
Change-Id I85447ba9ca7de8e197840f76ce3745363c4133a6Signed-off-by Evan Quan <[email protected]>--- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+)drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +51
-0@@ -1503,6 +1503,73 @@ static int arcturus_get_power_limit(struct smu_context *smu,return 0 ; } +static int arcturus_get_power_profile_mode (struct smu_context *smu, +char *buf) +{ +static const char *profile_name[] = { +"BOOTUP_DEFAULT" , +"3D_FULL_SCREEN" , +"POWER_SAVING" , +"VIDEO" , +"VR" , +"COMPUTE" , +"CUSTOM" }; +uint32_t i, size =0 ; +int16_t workload_type =0 ; + +if (!smu->pm_enabled || !buf) +return -EINVAL ; + +for (i =0 ; i <=PP_SMC_POWER_PROFILE_CUSTOM ; i++) { +/* +* Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT +* Not all profile modes are supported on arcturus. +*/ + workload_type =smu_workload_get_type (smu, i); +if (workload_type <0 ) +continue ; + + size +=sprintf (buf + size,"%2d %14s%s\n" , + i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " ); + } + +return size; +} + +static int arcturus_set_power_profile_mode (struct smu_context *smu, +long *input, +uint32_t size) +{ +int workload_type =0 ; +uint32_t profile_mode = input[size]; + +if (!smu->pm_enabled) +return -EINVAL ; + +if (profile_mode >PP_SMC_POWER_PROFILE_CUSTOM ) { +pr_err ("Invalid power profile mode %d\n" , profile_mode); +return -EINVAL ; + } + +/* +* Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT +* Not all profile modes are supported on arcturus.
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c static int arcturus_get_power_limit(struct smu_context *smu, · line 1566
Quoted 10 lines
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +10
-0+*/ + workload_type =smu_workload_get_type (smu, profile_mode); +if (workload_type <0 ) { +pr_err ("Unsupported power profile mode %d on arcturus\n" , profile_mode); +return -EINVAL ; + } + +smu_send_smc_msg_with_param (smu, + SMU_MSG_SetWorkloadMask, +1 << workload_type);
[kevin]:
please d check return value, after send message succeed, then modify power_profile_mode value.
if send message failed, you can't update power_profile_mode value.
after fixed:
Quoted 10 lines
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +6
-0+ + smu->power_profile_mode = profile_mode; + +return 0 ; +} +static void arcturus_dump_pptable (struct smu_context *smu) {struct smu_table_context *table_context = &smu->smu_table;
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c static const struct pptable_funcs arcturus_ppt_funcs = { · line 2042
Quoted 8 lines
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +2
-0@@ -1968,6 +2035,8 @@ static const struct pptable_funcs arcturus_ppt_funcs = { .force_dpm_limit_value = arcturus_force_dpm_limit_value, .unforce_dpm_levels = arcturus_unforce_dpm_levels, .get_profiling_clk_mask = arcturus_get_profiling_clk_mask, + .get_power_profile_mode = arcturus_get_power_profile_mode, + .set_power_profile_mode = arcturus_set_power_profile_mode,/* debug (internal used) */ .dump_pptable = arcturus_dump_pptable, .get_power_limit = arcturus_get_power_limit,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx