<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">Comment inline</span><br>
</p>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Quan, Evan <Evan.Quan@amd.com><br>
<b>Sent:</b> Friday, July 19, 2019 1:03 PM<br>
<b>To:</b> Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Feng, Kenneth <Kenneth.Feng@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Xu, Feifei <Feifei.Xu@amd.com>; Gui, Jack <Jack.Gui@amd.com><br>
<b>Subject:</b> RE: [PATCH] drm/amd/powerplay: custom peak clock freq for navi10</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Comment inline<br>
<br>
> -----Original Message-----<br>
> From: Wang, Kevin(Yang) <Kevin1.Wang@amd.com><br>
> Sent: Friday, July 19, 2019 11:46 AM<br>
> To: amd-gfx@lists.freedesktop.org<br>
> Cc: Feng, Kenneth <Kenneth.Feng@amd.com>; Quan, Evan<br>
> <Evan.Quan@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Xu, Feifei<br>
> <Feifei.Xu@amd.com>; Gui, Jack <Jack.Gui@amd.com>; Wang, Kevin(Yang)<br>
> <Kevin1.Wang@amd.com><br>
> Subject: [PATCH] drm/amd/powerplay: custom peak clock freq for navi10<br>
> <br>
> 1.NAVI10_PEAK_SCLK_XTX    1830 Mhz<br>
> 2.NAVI10_PEAK_SCLK_XT     1755 Mhz<br>
> 3.NAVI10_PEAK_SCLK_XL     1625 Mhz<br>
> <br>
> Change-Id: I48863a9d0e261b9e7778a6c0e4a8762d7c978da6<br>
> Signed-off-by: Kevin Wang <kevin1.wang@amd.com><br>
> ---<br>
>  drivers/gpu/drm/amd/powerplay/amdgpu_smu.c    | 65 ++++++++++--------<br>
> -<br>
>  .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |  4 ++<br>
>  drivers/gpu/drm/amd/powerplay/navi10_ppt.c    | 55 ++++++++++++++++<br>
>  drivers/gpu/drm/amd/powerplay/navi10_ppt.h    |  4 ++<br>
>  4 files changed, 97 insertions(+), 31 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
> b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
> index 7f51bbd2ac90..ab389dde9562 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
> @@ -1360,37 +1360,40 @@ int smu_adjust_power_state_dynamic(struct<br>
> smu_context *smu,<br>
>        }<br>
> <br>
>        if (smu_dpm_ctx->dpm_level != level) {<br>
> -             switch (level) {<br>
> -             case AMD_DPM_FORCED_LEVEL_HIGH:<br>
> -                     ret = smu_force_dpm_limit_value(smu, true);<br>
> -                     break;<br>
> -             case AMD_DPM_FORCED_LEVEL_LOW:<br>
> -                     ret = smu_force_dpm_limit_value(smu, false);<br>
> -                     break;<br>
> -<br>
> -             case AMD_DPM_FORCED_LEVEL_AUTO:<br>
> -             case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:<br>
> -                     ret = smu_unforce_dpm_levels(smu);<br>
> -                     break;<br>
> -<br>
> -             case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:<br>
> -             case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:<br>
> -             case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:<br>
> -                     ret = smu_get_profiling_clk_mask(smu, level,<br>
> -                                                      &sclk_mask,<br>
> -                                                      &mclk_mask,<br>
> -                                                      &soc_mask);<br>
> -                     if (ret)<br>
> -                             return ret;<br>
> -                     smu_force_clk_levels(smu, SMU_SCLK, 1 <<<br>
> sclk_mask);<br>
> -                     smu_force_clk_levels(smu, SMU_MCLK, 1 <<<br>
> mclk_mask);<br>
> -                     smu_force_clk_levels(smu, SMU_SOCCLK, 1 <<<br>
> soc_mask);<br>
> -                     break;<br>
> -<br>
> -             case AMD_DPM_FORCED_LEVEL_MANUAL:<br>
> -             case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:<br>
> -             default:<br>
> -                     break;<br>
> +             ret = smu_set_performance_level(smu, level);<br>
> +             if (ret) {<br>
[Quan, Evan] Since this actually handles AMD_DPM_FORCED_LEVEL_PROFILE_PEAK only. Please move this under "case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:".<br>
And please give it a more meaningful name e.g. smu_set_asic_peak_profile().</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">[kevin]: in the future, for specifc asic, it may be custom other performance level, so we should have this <span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">capacity
 to </span>support other asic with any performance level. <span style="font-size: 11pt;">and i think
</span><span style="font-size: 11pt;">it is not a good way to handle performance level use </span><span style="font-size: 11pt;">case by case method for each asic.</span></div>
<div class="PlainText"><br>
> +                     switch (level) {<br>
> +                     case AMD_DPM_FORCED_LEVEL_HIGH:<br>
> +                             ret = smu_force_dpm_limit_value(smu, true);<br>
> +                             break;<br>
> +                     case AMD_DPM_FORCED_LEVEL_LOW:<br>
> +                             ret = smu_force_dpm_limit_value(smu,<br>
> false);<br>
> +                             break;<br>
> +<br>
> +                     case AMD_DPM_FORCED_LEVEL_AUTO:<br>
> +                     case<br>
> AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:<br>
> +                             ret = smu_unforce_dpm_levels(smu);<br>
> +                             break;<br>
> +<br>
> +                     case<br>
> AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:<br>
> +                     case<br>
> AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:<br>
> +                     case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:<br>
> +                             ret = smu_get_profiling_clk_mask(smu, level,<br>
> +                                                              &sclk_mask,<br>
> +                                                              &mclk_mask,<br>
> +                                                              &soc_mask);<br>
> +                             if (ret)<br>
> +                                     return ret;<br>
> +                             smu_force_clk_levels(smu, SMU_SCLK, 1 <<<br>
> sclk_mask);<br>
> +                             smu_force_clk_levels(smu, SMU_MCLK, 1 <<<br>
> mclk_mask);<br>
> +                             smu_force_clk_levels(smu, SMU_SOCCLK, 1<br>
> << soc_mask);<br>
> +                             break;<br>
> +<br>
> +                     case AMD_DPM_FORCED_LEVEL_MANUAL:<br>
> +                     case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:<br>
> +                     default:<br>
> +                             break;<br>
> +                     }<br>
>                }<br>
> <br>
>                if (!ret)<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
> b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
> index 514d31518853..ba5ddafcbdba 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
> +++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h<br>
> @@ -631,6 +631,7 @@ struct pptable_funcs {<br>
>        int (*get_thermal_temperature_range)(struct smu_context *smu,<br>
> struct smu_temperature_range *range);<br>
>        int (*get_uclk_dpm_states)(struct smu_context *smu, uint32_t<br>
> *clocks_in_khz, uint32_t *num_states);<br>
>        int (*set_default_od_settings)(struct smu_context *smu, bool<br>
> initialize);<br>
> +     int (*set_performance_level)(struct smu_context *smu, int32_t<br>
> level);<br>
>  };<br>
> <br>
>  struct smu_funcs<br>
> @@ -928,6 +929,9 @@ struct smu_funcs<br>
>        ((smu)->funcs->baco_get_state? (smu)->funcs-<br>
> >baco_get_state((smu), (state)) : 0)<br>
>  #define smu_baco_reset(smu) \<br>
>        ((smu)->funcs->baco_reset? (smu)->funcs->baco_reset((smu)) : 0)<br>
> +#define smu_set_performance_level(smu, level) \<br>
> +     ((smu)->ppt_funcs->set_performance_level? (smu)->ppt_funcs-<br>
> >set_performance_level((smu), (level)) : -EINVAL);<br>
> +<br>
> <br>
>  extern int smu_get_atom_data_table(struct smu_context *smu, uint32_t<br>
> table,<br>
>                                   uint16_t *size, uint8_t *frev, uint8_t *crev,<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
> b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
> index e44041a25e64..9024d91477f0 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
> @@ -1590,6 +1590,60 @@ static int navi10_set_ppfeature_status(struct<br>
> smu_context *smu,<br>
>        return 0;<br>
>  }<br>
> <br>
> +static int navi10_set_peak_clock_by_device(struct smu_context *smu)<br>
> +{<br>
> +     struct amdgpu_device *adev = smu->adev;<br>
> +     int ret = 0;<br>
> +     uint32_t sclk_freq = 0, uclk_freq = 0;<br>
> +     uint32_t uclk_level = 0;<br>
> +<br>
> +     switch (adev->rev_id) {<br>
> +     case 0xf0: /* XTX */<br>
> +     case 0xC0:<br>
> +             sclk_freq = NAVI10_PEAK_SCLK_XTX;<br>
> +             break;<br>
> +     case 0xf1: /* XT */<br>
> +     case 0xC1:<br>
> +             sclk_freq = NAVI10_PEAK_SCLK_XT;<br>
> +             break;<br>
> +     default: /* XL */<br>
> +             sclk_freq = NAVI10_PEAK_SCLK_XL;<br>
> +             break;<br>
> +     }<br>
> +<br>
> +     ret = smu_get_dpm_level_count(smu, SMU_UCLK, &uclk_level);<br>
> +     if (ret)<br>
> +             return ret;<br>
> +     ret = smu_get_dpm_freq_by_index(smu, SMU_UCLK, uclk_level - 1,<br>
> &uclk_freq);<br>
> +     if (ret)<br>
> +             return ret;<br>
[Quan, Evan] I think with dpm level (3rd argument) set as 0xff directly,  you can  get the clock frequency for the max level.</div>
<div class="PlainText">[kevin]: not right, 0xff will return dpm clock level count, see function smu_get_dpm_level_count <br>
> +<br>
> +     ret = smu_set_soft_freq_range(smu, SMU_SCLK, sclk_freq,<br>
> sclk_freq);<br>
> +     if (ret)<br>
> +             return ret;<br>
> +     ret = smu_set_soft_freq_range(smu, SMU_UCLK, uclk_freq,<br>
> uclk_freq);<br>
> +     if (ret)<br>
> +             return ret;<br>
> +<br>
> +     return ret;<br>
> +}<br>
> +<br>
> +static int navi10_set_performance_level(struct smu_context *smu, int32_t<br>
> level)<br>
> +{<br>
> +     int ret = 0;<br>
> +<br>
> +     switch (level) {<br>
> +     case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:<br>
> +             ret = navi10_set_peak_clock_by_device(smu);<br>
> +             break;<br>
> +     default:<br>
> +             ret = -EINVAL;<br>
> +             break;<br>
> +     }<br>
> +<br>
> +     return ret;<br>
> +}<br>
> +<br>
>  static const struct pptable_funcs navi10_ppt_funcs = {<br>
>        .tables_init = navi10_tables_init,<br>
>        .alloc_dpm_context = navi10_allocate_dpm_context,<br>
> @@ -1625,6 +1679,7 @@ static const struct pptable_funcs navi10_ppt_funcs<br>
> = {<br>
>        .get_uclk_dpm_states = navi10_get_uclk_dpm_states,<br>
>        .get_ppfeature_status = navi10_get_ppfeature_status,<br>
>        .set_ppfeature_status = navi10_set_ppfeature_status,<br>
> +     .set_performance_level = navi10_set_performance_level,<br>
>  };<br>
> <br>
>  void navi10_set_ppt_funcs(struct smu_context *smu)<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.h<br>
> b/drivers/gpu/drm/amd/powerplay/navi10_ppt.h<br>
> index 957288e22f47..620ff17c2fef 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.h<br>
> +++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.h<br>
> @@ -23,6 +23,10 @@<br>
>  #ifndef __NAVI10_PPT_H__<br>
>  #define __NAVI10_PPT_H__<br>
> <br>
> +#define NAVI10_PEAK_SCLK_XTX         (1830)<br>
> +#define NAVI10_PEAK_SCLK_XT           (1755)<br>
> +#define NAVI10_PEAK_SCLK_XL           (1625)<br>
> +<br>
>  extern void navi10_set_ppt_funcs(struct smu_context *smu);<br>
> <br>
>  #endif<br>
> --<br>
> 2.22.0<br>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>