send message to pmfw when SMT changes
v2 cover send message to pmfw when SMT changes
When the CPU SMT changes on the fly, send the message to pmfw to notify the SMT status changed.
Changes in v2:
1/. Embed the smt notifer callback into "struct smu_context" structure. 2/. Correct the PPSMC_Message_Count value.
3./ Improve several code styles and others.
Wenyou Yang (3):
cpu/smt: add a notifier to notify the SMT changes drm/amd/pm: send the SMT enable message to pmfw drm/amd/pm: vangogh: support to send SMT enable message
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 39 +++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 7 ++++ .../pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h | 3 +- drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h | 3 +- .../gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 8 ++++ include/linux/cpu.h | 5 +++ kernel/cpu.c | 10 ++++- 7 files changed, 72 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.2
PATCH v2 1/3 cpu/smt: add a notifier to notify the SMT changes
Add the notifier chain to notify the cpu SMT status changes
--- include/linux/cpu.h | 5 +++++ kernel/cpu.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
include/linux/cpu.h +5 -0
@@ -213,6 +213,11 @@ enum cpuhp_smt_control { CPU_SMT_NOT_IMPLEMENTED, }; +enum cpuhp_smt_status { +SMT_ENABLED , +SMT_DISABLED , +}; +#if defined(CONFIG_SMP ) && defined(CONFIG_HOTPLUG_SMT )extern enum cpuhp_smt_control cpu_smt_control;extern void cpu_smt_disable (bool force);
kernel/cpu.c +9 -1
@@ -89,6 +89,9 @@ static DEFINE_PER_CPU(struct cpuhp_cpu_state, cpuhp_state) = {cpumask_t cpus_booted_once_mask;#endif +RAW_NOTIFIER_HEAD (smt_notifier_head); +EXPORT_SYMBOL (smt_notifier_head); +#if defined(CONFIG_LOCKDEP ) && defined(CONFIG_SMP )static struct lockdep_map cpuhp_state_up_map =STATIC_LOCKDEP_MAP_INIT ("cpuhp_state-up" , &cpuhp_state_up_map);
@@ -2281,8 +2284,10 @@ int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)*/ cpuhp_offline_cpu_device (cpu); } -if (!ret) +if (!ret) { cpu_smt_control = ctrlval; +raw_notifier_call_chain (&smt_notifier_head,SMT_DISABLED ,NULL ); + }cpu_maps_update_done ();return ret; }
@@ -2303,6 +2308,9 @@ int cpuhp_smt_enable(void)/* See comment in cpuhp_smt_disable() */ cpuhp_online_cpu_device (cpu); } +if (!ret) +raw_notifier_call_chain (&smt_notifier_head,SMT_ENABLED ,NULL ); +cpu_maps_update_done ();return ret; }
Signature · 1 line
2.39.2
PATCH v2 2/3 drm/amd/pm: send the SMT enable message to pmfw
In reply to Wenyou YangWhen the CPU SMT status is changed in the fly, sent the SMT enable message to pmfw to notify it that the SMT status changed.
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 39 +++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 7 ++++ 2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +39 -0
@@ -22,6 +22,7 @@#define SWSMU_CODE_LAYER_L1 +#include <linux/cpu.h> #include <linux/firmware.h> #include <linux/pci.h>
@@ -54,6 +55,8 @@#undef pr_info#undef pr_debug +extern struct raw_notifier_head smt_notifier_head; +static const struct amd_pm_funcs swsmu_pm_funcs; static int smu_force_smuclk_levels(struct smu_context *smu, enum smu_clk_type clk_type,
@@ -69,6 +72,9 @@ 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); +static int smt_notifier_callback (struct notifier_block *nb, +unsigned long action,void *data); +static int smu_sys_get_pp_feature_mask (void *handle,char *buf) {
@@ -647,6 +653,8 @@ static int smu_early_init(void *handle) adev->powerplay.pp_handle = smu; adev->powerplay.pp_funcs = &swsmu_pm_funcs; + smu->nb.notifier_call = smt_notifier_callback; + r =smu_set_funcs (adev);if (r)return r;
@@ -1105,6 +1113,8 @@ static int smu_sw_init(void *handle)if (!smu->ppt_funcs->get_fan_control_mode) smu->adev->pm.no_fan = true; +raw_notifier_chain_register (&smt_notifier_head, &smu->nb); +return 0 ; }
@@ -1122,6 +1132,9 @@ static int smu_sw_fini(void *handle)smu_fini_microcode (smu); +if (smu->nb.notifier_call !=NULL ) +raw_notifier_chain_unregister (&smt_notifier_head, &smu->nb); +return 0 ; }
@@ -3241,3 +3254,29 @@ int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size)return ret; } + +static int smu_set_cpu_smt_enable (struct smu_context *smu,bool enable) +{ +int ret = -EINVAL ; + +if (smu->ppt_funcs && smu->ppt_funcs->set_cpu_smt_enable) + ret = smu->ppt_funcs->set_cpu_smt_enable (smu, enable); + +return ret; +} + +static int smt_notifier_callback (struct notifier_block *nb, +unsigned long action,void *data) +{ + struct smu_context *smu = container_of(nb, struct smu_context, nb); +int ret; + + smu = container_of(nb, struct smu_context, nb); + + ret =smu_set_cpu_smt_enable (smu, action ==SMT_ENABLED ); + +dev_dbg (smu->adev->dev,"failed to set cclk_pd_limit for SMT %sabled: %d\n" , + action ==SMT_ENABLED ?"en" :"dis" , ret); + +return ret ?NOTIFY_BAD :NOTIFY_OK ; +}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +7 -0
@@ -566,6 +566,8 @@ struct smu_contextstruct firmware pptable_firmware; +struct notifier_block nb; +u32 param_reg;u32 msg_reg;u32 resp_reg;
@@ -1354,6 +1356,11 @@ struct pptable_funcs {* @init_pptable_microcode: Prepare the pptable microcode to upload via PSP */ int (*init_pptable_microcode)(struct smu_context *smu); + +/** +* @set_cpu_smt_enable: Set the CPU SMT status. +*/ +int (*set_cpu_smt_enable)(struct smu_context *smu,bool smt_enable); }; typedef enum {
Signature · 1 line
2.39.2
Re: [PATCH v2 2/3] drm/amd/pm: send the SMT enable message to pmfw
Quoted 50 lines · Wenyou Yang
When the CPU SMT status is changed in the fly, sent the SMT enable message to pmfw to notify it that the SMT status changed.
Signed-off-by Wenyou Yang <[email protected]>--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 39 +++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 7 ++++ 2 files changed, 46 insertions(+)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +8
-0@@ -22,6 +22,7 @@#define SWSMU_CODE_LAYER_L1 +#include <linux/cpu.h> #include <linux/firmware.h> #include <linux/pci.h> @@ -54,6 +55,8 @@#undef pr_info#undef pr_debug +extern struct raw_notifier_head smt_notifier_head; +static const struct amd_pm_funcs swsmu_pm_funcs; static int smu_force_smuclk_levels(struct smu_context *smu, enum smu_clk_type clk_type,@@ -69,6 +72,9 @@ 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); +static int smt_notifier_callback (struct notifier_block *nb, +unsigned long action,void *data); +static int smu_sys_get_pp_feature_mask (void *handle,char *buf) {@@ -647,6 +653,8 @@ static int smu_early_init(void *handle) adev->powerplay.pp_handle = smu; adev->powerplay.pp_funcs = &swsmu_pm_funcs; + smu->nb.notifier_call = smt_notifier_callback; + r =smu_set_funcs (adev);if (r)return r;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_sw_init(void *handle) · line 1117
Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2
-0@@ -1105,6 +1113,8 @@ static int smu_sw_init(void *handle)if (!smu->ppt_funcs->get_fan_control_mode) smu->adev->pm.no_fan = true; +raw_notifier_chain_register (&smt_notifier_head, &smu->nb); +
As mentioned before, it's not a blind registration for any ASIC. This should only be done by the ASICs which are interested in the notification and not here. So this should be somewhere inside vangogh_set_ppt_funcs or part of a software init callback like vangogh_init_smc_tables.
Thanks,
Lijo
Quoted 68 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +29
-0return 0 ; }@@ -1122,6 +1132,9 @@ static int smu_sw_fini(void *handle)smu_fini_microcode (smu); +if (smu->nb.notifier_call !=NULL ) +raw_notifier_chain_unregister (&smt_notifier_head, &smu->nb); +return 0 ; }@@ -3241,3 +3254,29 @@ int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size)return ret; } + +static int smu_set_cpu_smt_enable (struct smu_context *smu,bool enable) +{ +int ret = -EINVAL ; + +if (smu->ppt_funcs && smu->ppt_funcs->set_cpu_smt_enable) + ret = smu->ppt_funcs->set_cpu_smt_enable (smu, enable); + +return ret; +} + +static int smt_notifier_callback (struct notifier_block *nb, +unsigned long action,void *data) +{ + struct smu_context *smu = container_of(nb, struct smu_context, nb); +int ret; + + smu = container_of(nb, struct smu_context, nb); + + ret =smu_set_cpu_smt_enable (smu, action ==SMT_ENABLED ); + +dev_dbg (smu->adev->dev,"failed to set cclk_pd_limit for SMT %sabled: %d\n" , + action ==SMT_ENABLED ?"en" :"dis" , ret); + +return ret ?NOTIFY_BAD :NOTIFY_OK ; +}drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +7
-0@@ -566,6 +566,8 @@ struct smu_contextstruct firmware pptable_firmware; +struct notifier_block nb; +u32 param_reg;u32 msg_reg;u32 resp_reg;@@ -1354,6 +1356,11 @@ struct pptable_funcs {* @init_pptable_microcode: Prepare the pptable microcode to upload via PSP */ int (*init_pptable_microcode)(struct smu_context *smu); + +/** +* @set_cpu_smt_enable: Set the CPU SMT status. +*/ +int (*set_cpu_smt_enable)(struct smu_context *smu,bool smt_enable); }; typedef enum {
RE: [PATCH v2 2/3] drm/amd/pm: send the SMT enable message to pmfw
[AMD Official Use Only - General]
Hi Lijo.
Quoted 82 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, March 27, 2023 8:34 PM
To: Yang, WenYou <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Quan, Evan <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Yuan, Perry <[email protected]>; Li, Ying <[email protected]>; amd- [email protected]; [email protected]; Liu, Kun <[email protected]>; Liang, Richard qi <[email protected]>
Subject: Re: [PATCH v2 2/3] drm/amd/pm: send the SMT enable message to pmfwQuoted 6 lines · Wenyou Yang
When the CPU SMT status is changed in the fly, sent the SMT enable message to pmfw to notify it that the SMT status changed.
Signed-off-by Wenyou Yang <[email protected]>--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 39+++++++++++++++++++
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle,
Quoted 26 lines
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 7 ++++ 2 files changed, 46 insertions(+)drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-0@@ -22,6 +22,7 @@#define SWSMU_CODE_LAYER_L1 +#include <linux/cpu.h> #include <linux/firmware.h> #include <linux/pci.h> @@ -54,6 +55,8 @@#undef pr_info#undef pr_debug +extern struct raw_notifier_head smt_notifier_head; +static const struct amd_pm_funcs swsmu_pm_funcs; static int smu_force_smuclk_levels(struct smu_context *smu, enum smu_clk_type clk_type,@@ -69,6 +72,9 @@ static int smu_set_fan_speed_rpm(void *handle,
uint32_tspeed);Quoted 20 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-0static 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); +static int smt_notifier_callback (struct notifier_block *nb, +unsigned long action,void *data); +static int smu_sys_get_pp_feature_mask (void *handle,char *buf){drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2
-0@@ -647,6 +653,8 @@ static int smu_early_init(void *handle) adev->powerplay.pp_handle = smu; adev->powerplay.pp_funcs = &swsmu_pm_funcs; + smu->nb.notifier_call = smt_notifier_callback; + r =smu_set_funcs (adev);if (r)return r;drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_sw_init(void *handle) · line 1117
Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2
-0@@ -1105,6 +1113,8 @@ static int smu_sw_init(void *handle)if (!smu->ppt_funcs->get_fan_control_mode) smu->adev->pm.no_fan = true; +raw_notifier_chain_register (&smt_notifier_head, &smu->nb); +As mentioned before, it's not a blind registration for any ASIC. This should only be done by the ASICs which are interested in the notification and not here. So this should be somewhere inside
vangogh_set_ppt_funcsor part of a software init callback likevangogh_init_smc_tables.
Quoted 2 lines
Thanks,
Lijo
You are right, only Vangogh PMFW will handle the CCLK PD Limit update request.
Hi @Yang, WenYou
It will need to limit the update message within the Vangogh Asic.
Quoted 73 lines
Quoted 31 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +14
-0return 0 ; }@@ -1122,6 +1132,9 @@ static int smu_sw_fini(void *handle)smu_fini_microcode (smu); +if (smu->nb.notifier_call !=NULL ) +raw_notifier_chain_unregister (&smt_notifier_head, &smu- nb); +return 0 ; }@@ -3241,3 +3254,29 @@ int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) return ret; } + +static int smu_set_cpu_smt_enable (struct smu_context *smu,bool +enable) { +int ret = -EINVAL ; + +if (smu->ppt_funcs && smu->ppt_funcs->set_cpu_smt_enable) + ret = smu->ppt_funcs->set_cpu_smt_enable (smu, enable); + +return ret; +} +drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct
Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10
-0+static int smt_notifier_callback (struct notifier_block *nb, +unsigned long action,void *data) { + struct smu_context *smu = container_of(nb, struct smu_context, nb); +int ret; + + smu = container_of(nb, struct smu_context, nb); + + ret =smu_set_cpu_smt_enable (smu, action ==SMT_ENABLED ); + + dev_dbg(smu->adev->dev, "failed to set cclk_pd_limit forSMT %sabled: %d\n",
Quoted 18 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3
-0+ action == SMT_ENABLED ? "en" : "dis", ret); + +return ret ?NOTIFY_BAD :NOTIFY_OK ; }drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +2
-0@@ -566,6 +566,8 @@ struct smu_contextstruct firmware pptable_firmware; +struct notifier_block nb; +u32 param_reg;u32 msg_reg;u32 resp_reg;drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h struct pptable_funcs { · line 1356
Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +0
-0@@ -1354,6 +1356,11 @@ struct pptable_funcs {* @init_pptable_microcode: Prepare the pptable microcode to upload via PSP
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h struct pptable_funcs {
Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +5
-0*/ int (*init_pptable_microcode)(struct smu_context *smu); + +/** +* @set_cpu_smt_enable: Set the CPU SMT status. +*/ + int (*set_cpu_smt_enable)(struct smu_context *smu, bool
smt_enable);Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +0
-0}; typedef enum {
PATCH v2 3/3 drm/amd/pm: vangogh: support to send SMT enable message
In reply to Wenyou YangAdd the support to send PPSMC_MSG_SetCClkSMTEnable(0x58) message to pmfw for vangogh.
--- .../gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h | 3 ++- drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h | 3 ++- drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h +2 -1
@@ -111,7 +111,8 @@#define PPSMC_MSG_GetGfxOffStatus 0x50#define PPSMC_MSG_GetGfxOffEntryCount 0x51#define PPSMC_MSG_LogGfxOffResidency 0x52 -#define PPSMC_Message_Count 0x53 +#define PPSMC_MSG_SetCClkSMTEnable 0x58 +#define PPSMC_Message_Count 0x59//Argument for PPSMC_MSG_GfxDeviceDriverReset enum {
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
@@ -245,7 +245,8 @@__SMU_DUMMY_MAP (AllowGpo), \__SMU_DUMMY_MAP (Mode2Reset), \__SMU_DUMMY_MAP (RequestI2cTransaction), \ -__SMU_DUMMY_MAP (GetMetricsTable), +__SMU_DUMMY_MAP (GetMetricsTable), \ +__SMU_DUMMY_MAP (SetCClkSMTEnable), #undef __SMU_DUMMY_MAP#define __SMU_DUMMY_MAP (type) SMU_MSG_##type
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +8 -0
@@ -141,6 +141,7 @@ static struct cmn2asic_msg_mapping vangogh_message_map[SMU_MSG_MAX_COUNT] = {MSG_MAP (GetGfxOffStatus, PPSMC_MSG_GetGfxOffStatus,0 ),MSG_MAP (GetGfxOffEntryCount, PPSMC_MSG_GetGfxOffEntryCount,0 ),MSG_MAP (LogGfxOffResidency, PPSMC_MSG_LogGfxOffResidency,0 ), + MSG_MAP(SetCClkSMTEnable, PPSMC_MSG_SetCClkSMTEnable, 0), }; static struct cmn2asic_mapping vangogh_feature_mask_map[SMU_FEATURE_COUNT] = {
@@ -2428,6 +2429,12 @@ static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entrreturn ret; } +static int vangogh_set_cpu_smt_enable (struct smu_context *smu,bool enable) +{ +return smu_cmn_send_smc_msg_with_param (smu, SMU_MSG_SetCClkSMTEnable, + enable ?1 :0 ,NULL ); +} +static const struct pptable_funcs vangogh_ppt_funcs = { .check_fw_status = smu_v11_0_check_fw_status,
@@ -2474,6 +2481,7 @@ static const struct pptable_funcs vangogh_ppt_funcs = { .get_power_limit = vangogh_get_power_limit, .set_power_limit = vangogh_set_power_limit, .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values, + .set_cpu_smt_enable = vangogh_set_cpu_smt_enable, };void vangogh_set_ppt_funcs (struct smu_context *smu)
Signature · 1 line
2.39.2