Skip to contentSkip to conversation

send message to pmfw when SMT changes

PATCH Superseded Wenyou Yang 3 participants 12 messages Mar 22, 2023 – Mar 25, 2023

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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.

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     | 41 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++
 .../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  | 19 +++++++++
 include/linux/cpu.h                           |  5 +++
 kernel/cpu.c                                  | 11 ++++-
 7 files changed, 84 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 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        | 11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
include/linux/cpu.h +5 -0
index 314802f98b9d..9a842317fe2d 100644
@@ -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 +10 -1
index 6c0a92ca6bb5..accae0fa9868 100644
@@ -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,7 +2308,11 @@ 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;
 }
 #endif
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/3 drm/amd/pm: send the SMT-enable message to pmfw

In reply to Wenyou Yang

When the CPU SMT status change 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     | 41 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++
 2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +41 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
 
 #define SWSMU_CODE_LAYER_L1
 
+#include <linux/cpu.h>
 #include <linux/firmware.h>
 #include <linux/pci.h>
 
@@ -69,6 +70,14 @@ 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);
+
+extern struct raw_notifier_head smt_notifier_head;
+
+static struct notifier_block smt_notifier = {
+	.notifier_call = smt_notifier_callback,
+};
+
 static int smu_sys_get_pp_feature_mask(void *handle,
 				       char *buf)
 {
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device *adev)
 	return 0;
 }
 
+static struct smu_context *current_smu;
+
 static int smu_early_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -645,6 +656,7 @@ static int smu_early_init(void *handle)
 	mutex_init(&smu->message_lock);
 
 	adev->powerplay.pp_handle = smu;
+	current_smu = smu;
 	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
 
 	r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
 	return 0;
 }
 
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
 
 	smu_fini_microcode(smu);
 
+	raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
 	return 0;
 }
 
@@ -3241,3 +3257,28 @@ 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 = current_smu;
+	int ret = NOTIFY_OK;
+
+	ret = (action == SMT_ENABLED) ?
+				smu_set_cpu_smt_enable(smu, true) :
+				smu_set_cpu_smt_enable(smu, false);
+	if (ret)
+		ret = NOTIFY_BAD;
+
+	return ret;
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +5 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,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 enable);
 };
 
 typedef enum {
Signature · 1 line
2.39.2
#3 lore raw

Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

Quoted 81 lines · Wenyou Yang

When the CPU SMT status change 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     | 41 +++++++++++++++++++
  drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++
  2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +22 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
 
  #define SWSMU_CODE_LAYER_L1
 
+#include <linux/cpu.h>
  #include <linux/firmware.h>
  #include <linux/pci.h>
 
@@ -69,6 +70,14 @@ 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);
+
+extern struct raw_notifier_head smt_notifier_head;
+
+static struct notifier_block smt_notifier = {
+	.notifier_call = smt_notifier_callback,
+};
+
  static int smu_sys_get_pp_feature_mask(void *handle,
  				       char *buf)
  {
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device *adev)
  	return 0;
  }
 
+static struct smu_context *current_smu;
+
  static int smu_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -645,6 +656,7 @@ static int smu_early_init(void *handle)
  	mutex_init(&smu->message_lock);
 
  	adev->powerplay.pp_handle = smu;
+	current_smu = smu;
  	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
 
  	r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
  	return 0;
  }
 
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
 
  	smu_fini_microcode(smu);
 
+	raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
  	return 0;
  }
 
@@ -3241,3 +3257,28 @@ 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)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3275

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
+		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 = current_smu;
+	int ret = NOTIFY_OK;

This initialization is pointless, it's clobbered in the next line.

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3279

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+
+	ret = (action == SMT_ENABLED) ?
+				smu_set_cpu_smt_enable(smu, true) :
+				smu_set_cpu_smt_enable(smu, false);

How about this instead, it should be more readable:

	ret = smu_set_cpu_smt_enable(smu, action == SMT_ENABLED);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3283

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+	if (ret)
+		ret = NOTIFY_BAD;
+
+	return ret;

How about instead:

	dev_dbg(adev->dev, "failed to %sable SMT: %d\n", action == SMT_ENABLED 

? "en" : "dis", ret);

	return ret ? NOTIFY_BAD : NOTIFY_OK;
Quoted 17 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +5 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,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 enable);
  };
 
  typedef enum {
#4 lore raw

Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

Quoted 39 lines · Mario
Quoted 38 lines · Wenyou Yang

When the CPU SMT status change 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     | 41 +++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++

  2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
   #define SWSMU_CODE_LAYER_L1
+#include <linux/cpu.h>
   #include <linux/firmware.h>
   #include <linux/pci.h>
@@ -69,6 +70,14 @@ 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);
+
+extern struct raw_notifier_head smt_notifier_head;
+
+static struct notifier_block smt_notifier = {
+    .notifier_call = smt_notifier_callback,
+};
+
   static int smu_sys_get_pp_feature_mask(void *handle,
                          char *buf)

  {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device *adev)
       return 0;
   }
+static struct smu_context *current_smu;
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 658

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
+
   static int smu_early_init(void *handle)
   {
       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -645,6 +656,7 @@ static int smu_early_init(void *handle)
       mutex_init(&smu->message_lock);
       adev->powerplay.pp_handle = smu;
+    current_smu = smu;

Although this series is intended for the Van Gogh case right now, I dont't think this would scale well for multiple GPUs in a system.

I think that instead you may want to move the notifier callback to be a level "higher" in amdgpu. Perhaps amdgpu_device.c? Then when that notifier call is received you'll want to walk through the PCI device space to find any GPUs that are bound with AMDGPU a series of wrappers/calls that end up calling smu_set_cpu_smt_enable with the approriate arguments.

Quoted 76 lines
Quoted 25 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
       adev->powerplay.pp_funcs = &swsmu_pm_funcs;
       r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
       return 0;
   }
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
       smu_fini_microcode(smu);
+    raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
       return 0;
   }
@@ -3241,3 +3257,28 @@ 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)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct · line 3275

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
+        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 = current_smu;
+    int ret = NOTIFY_OK;

This initialization is pointless, it's clobbered in the next line.

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3279

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+
+    ret = (action == SMT_ENABLED) ?
+                smu_set_cpu_smt_enable(smu, true) :
+                smu_set_cpu_smt_enable(smu, false);

How about this instead, it should be more readable:

    ret = smu_set_cpu_smt_enable(smu, action == SMT_ENABLED);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3283

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+    if (ret)
+        ret = NOTIFY_BAD;
+
+    return ret;

How about instead:

    dev_dbg(adev->dev, "failed to %sable SMT: %d\n", action ==
SMT_ENABLED ? "en" : "dis", ret);

    return ret ? NOTIFY_BAD : NOTIFY_OK;

Quoted 16 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +5 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,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 enable);
   };
   typedef enum {
#5 lore raw

Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

Quoted 51 lines · Mario
Quoted 39 lines · Mario
Quoted 38 lines · Wenyou Yang

When the CPU SMT status change 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     | 41 +++++++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++

  2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
   #define SWSMU_CODE_LAYER_L1
+#include <linux/cpu.h>
   #include <linux/firmware.h>
   #include <linux/pci.h>
@@ -69,6 +70,14 @@ 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);
+
+extern struct raw_notifier_head smt_notifier_head;
+
+static struct notifier_block smt_notifier = {
+    .notifier_call = smt_notifier_callback,
+};
+
   static int smu_sys_get_pp_feature_mask(void *handle,
                          char *buf)

  {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device *adev)
       return 0;
   }
+static struct smu_context *current_smu;
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 658

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
+
   static int smu_early_init(void *handle)
   {
       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -645,6 +656,7 @@ static int smu_early_init(void *handle)
       mutex_init(&smu->message_lock);
       adev->powerplay.pp_handle = smu;
+    current_smu = smu;

Although this series is intended for the Van Gogh case right now, I dont't think this would scale well for multiple GPUs in a system.

Quoted 2 lines

I think that instead you may want to move the notifier callback to be a level "higher" in amdgpu.  Perhaps amdgpu_device.c?  Then when that notifier call is received you'll want to walk through the PCI device space to find any GPUs that are bound with AMDGPU a series of wrappers/calls that end up calling smu_set_cpu_smt_enable with the approriate arguments.

This is not required when the notifier is registered only within Vangogh ppt function. Then follow Evan's suggestion of keeping the notifier block inside smu. From the notifier block, it can find the smu block and then call cpu_smt_enable/disable. That way notifier callback comes only once even with multiple dGPUs + Vangogh and processed for the corresponding smu.

This notifier doesn't need to be registered for platforms only with dGPUs or APUs which don't need this.

Thanks,
Lijo

Quoted 77 lines
Quoted 76 lines
Quoted 26 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
       adev->powerplay.pp_funcs = &swsmu_pm_funcs;
       r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
       return 0;
   }
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
       smu_fini_microcode(smu);
+    raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
       return 0;
   }
@@ -3241,3 +3257,28 @@ 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)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct · line 3275

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
+        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 = current_smu;
+    int ret = NOTIFY_OK;

This initialization is pointless, it's clobbered in the next line.

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3279

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+
+    ret = (action == SMT_ENABLED) ?
+                smu_set_cpu_smt_enable(smu, true) :
+                smu_set_cpu_smt_enable(smu, false);

How about this instead, it should be more readable:

     ret = smu_set_cpu_smt_enable(smu, action == SMT_ENABLED);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3283

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+    if (ret)
+        ret = NOTIFY_BAD;
+
+    return ret;

How about instead:

     dev_dbg(adev->dev, "failed to %sable SMT: %d\n", action == SMT_ENABLED ? "en" : "dis", ret);

     return ret ? NOTIFY_BAD : NOTIFY_OK;

Quoted 16 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +5 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,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 enable);
   };
   typedef enum {
#6 lore raw

RE: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

[AMD Official Use Only - General]

Quoted 85 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 23, 2023 21:29
To: Limonciello, Mario <[email protected]>; Yang, WenYou <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Li, Ying <[email protected]>; Liu, Kun <[email protected]>; Liang, Richard qi <[email protected]>; [email protected]
Subject: Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

Quoted 8 lines · Mario
Quoted 7 lines · Mario
Quoted 6 lines · Wenyou Yang

When the CPU SMT status change 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     | 41

+++++++++++++++++++

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

  drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++

  2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
   #define SWSMU_CODE_LAYER_L1
+#include <linux/cpu.h>
   #include <linux/firmware.h>
   #include <linux/pci.h>
@@ -69,6 +70,14 @@ 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);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
+
+extern struct raw_notifier_head smt_notifier_head;
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_funcs(struct amdgpu_device

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+static struct notifier_block smt_notifier = {
+    .notifier_call = smt_notifier_callback,
+};
+

  static int smu_sys_get_pp_feature_mask(void *handle, char *buf)
  {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device

*adev)

Quoted 15 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 658

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
       return 0;
   }
+static struct smu_context *current_smu;
+
   static int smu_early_init(void *handle)
   {
       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -645,6 +656,7 @@ static int smu_early_init(void *handle)
       mutex_init(&smu->message_lock);
       adev->powerplay.pp_handle = smu;
+    current_smu = smu;

Although this series is intended for the Van Gogh case right now, I dont't think this would scale well for multiple GPUs in a system.

Quoted 7 lines

I think that instead you may want to move the notifier callback to be a level "higher" in amdgpu.  Perhaps amdgpu_device.c?  Then when that notifier call is received you'll want to walk through the PCI device space to find any GPUs that are bound with AMDGPU a series of wrappers/calls that end up calling smu_set_cpu_smt_enable with the approriate arguments.

This is not required when the notifier is registered only within Vangogh ppt function. Then follow Evan's suggestion of keeping the notifier block inside smu. From the notifier block, it can find the smu block and then call cpu_smt_enable/disable. That way notifier callback comes only once even with multiple dGPUs + Vangogh and processed for the corresponding smu.

Quoted 2 lines

This notifier doesn't need to be registered for platforms only with dGPUs or APUs which don't need this.

They don't right now, but I was thinking how this could scale to other APUs or dGPUs if they are interested in adding support for this message too.

Quoted 85 lines

Thanks,
Lijo

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
       adev->powerplay.pp_funcs = &swsmu_pm_funcs;
       r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
       return 0;
   }
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
       smu_fini_microcode(smu);
+    raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct · line 3261

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
       return 0;
   }
@@ -3241,3 +3257,28 @@ 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)

Quoted 58 lines
Quoted 57 lines
Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+{
+    int ret = -EINVAL;
+
+    if (smu->ppt_funcs && smu->ppt_funcs->set_cpu_smt_enable)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3275

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
+        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 = current_smu;
+    int ret = NOTIFY_OK;

This initialization is pointless, it's clobbered in the next line.

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3279

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+
+    ret = (action == SMT_ENABLED) ?
+                smu_set_cpu_smt_enable(smu, true) :
+                smu_set_cpu_smt_enable(smu, false);

How about this instead, it should be more readable:

     ret = smu_set_cpu_smt_enable(smu, action == SMT_ENABLED);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3283

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+    if (ret)
+        ret = NOTIFY_BAD;
+
+    return ret;

How about instead:

     dev_dbg(adev->dev, "failed to %sable SMT: %d\n", action == SMT_ENABLED ? "en" : "dis", ret);

     return ret ? NOTIFY_BAD : NOTIFY_OK;

Quoted 18 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +0 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,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 enable); };
  typedef enum {

#7 lore raw

Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

[AMD Official Use Only - General]

The notifier block is embedded in smu context of a device. If there are 4 devices and 3 of them are interested, they register using the notifier block within their smu context. Notifier is called in a chain and when received they use the container_of to get the smu context and communicate with the respective device's FW on the actions to do.

BTW, I don't know why dGPU PMFW would be interested in SMT change. On AMD APU + dGPU we already have things like smartshift and it will take care if communicated to APU alone.

Thanks,
Lijo
________________________________
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 24, 2023 11:19:55 PM
To: Lazar, Lijo <[email protected]>; Yang, WenYou <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Li, Ying <[email protected]>; Liu, Kun <[email protected]>; Liang, Richard qi <[email protected]>; [email protected] <[email protected]>
Subject: RE: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

[AMD Official Use Only - General]

Quoted 85 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, March 23, 2023 21:29
To: Limonciello, Mario <[email protected]>; Yang, WenYou <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Li, Ying <[email protected]>; Liu, Kun <[email protected]>; Liang, Richard qi <[email protected]>; [email protected]
Subject: Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

Quoted 8 lines · Mario
Quoted 7 lines · Mario
Quoted 6 lines · Wenyou Yang

When the CPU SMT status change 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     | 41

+++++++++++++++++++

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
  drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++
  2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
  #define SWSMU_CODE_LAYER_L1
+#include <linux/cpu.h>
  #include <linux/firmware.h>
  #include <linux/pci.h>
@@ -69,6 +70,14 @@ 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);
+
+extern struct raw_notifier_head smt_notifier_head;
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_funcs(struct amdgpu_device

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+static struct notifier_block smt_notifier = {
+    .notifier_call = smt_notifier_callback,
+};
+
  static int smu_sys_get_pp_feature_mask(void *handle,

char *buf)
{

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device

*adev)

Quoted 15 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 658

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
      return 0;
  }
+static struct smu_context *current_smu;
+
  static int smu_early_init(void *handle)
  {
      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -645,6 +656,7 @@ static int smu_early_init(void *handle)
      mutex_init(&smu->message_lock);
      adev->powerplay.pp_handle = smu;
+    current_smu = smu;

Although this series is intended for the Van Gogh case right now, I dont't think this would scale well for multiple GPUs in a system.

Quoted 7 lines

I think that instead you may want to move the notifier callback to be a level "higher" in amdgpu. Perhaps amdgpu_device.c? Then when that notifier call is received you'll want to walk through the PCI device space to find any GPUs that are bound with AMDGPU a series of wrappers/calls that end up calling smu_set_cpu_smt_enable with the approriate arguments.

This is not required when the notifier is registered only within Vangogh ppt function. Then follow Evan's suggestion of keeping the notifier block inside smu. From the notifier block, it can find the smu block and then call cpu_smt_enable/disable. That way notifier callback comes only once even with multiple dGPUs + Vangogh and processed for the corresponding smu.

Quoted 2 lines

This notifier doesn't need to be registered for platforms only with dGPUs or APUs which don't need this.

They don't right now, but I was thinking how this could scale to other APUs or dGPUs if they are interested in adding support for this message too.

Quoted 85 lines

Thanks,
Lijo

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
      adev->powerplay.pp_funcs = &swsmu_pm_funcs;
      r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
      return 0;
  }
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
      smu_fini_microcode(smu);
+    raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct · line 3261

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
      return 0;
  }
@@ -3241,3 +3257,28 @@ 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)

Quoted 58 lines
Quoted 57 lines
Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+{
+    int ret = -EINVAL;
+
+    if (smu->ppt_funcs && smu->ppt_funcs->set_cpu_smt_enable)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3275

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +10 -0
+        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 = current_smu;
+    int ret = NOTIFY_OK;

This initialization is pointless, it's clobbered in the next line.

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3279

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+
+    ret = (action == SMT_ENABLED) ?
+                smu_set_cpu_smt_enable(smu, true) :
+                smu_set_cpu_smt_enable(smu, false);

How about this instead, it should be more readable:

     ret = smu_set_cpu_smt_enable(smu, action == SMT_ENABLED);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3283

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+    if (ret)
+        ret = NOTIFY_BAD;
+
+    return ret;

How about instead:

     dev_dbg(adev->dev, "failed to %sable SMT: %d\n", action ==

SMT_ENABLED ? "en" : "dis", ret);

     return ret ? NOTIFY_BAD : NOTIFY_OK;
Quoted 18 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +0 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,11 @@ struct pptable_funcs {
       * @init_pptable_microcode: Prepare the pptable microcode to

upload via PSP

       */
      int (*init_pptable_microcode)(struct smu_context *smu);
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +5 -0
+
+    /**
+     * @set_cpu_smt_enable: Set the CPU SMT status
+     */
+    int (*set_cpu_smt_enable)(struct smu_context *smu, bool enable);
  };
  typedef enum {
#8 lore raw

RE: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

In reply to Limonciello, Mario

[AMD Official Use Only - General]

Quoted 102 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 24, 2023 1:42 AM
To: Yang, WenYou <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Li, Ying <[email protected]>; Liu, Kun <[email protected]>; amd- [email protected]; Liang, Richard qi <[email protected]>
Subject: Re: [v1,2/3] drm/amd/pm: send the SMT-enable message to pmfw

Quoted 6 lines · Wenyou Yang

When the CPU SMT status change 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     | 41

+++++++++++++++++++

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle,

Quoted 17 lines
  drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  5 +++
  2 files changed, 46 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
index b5d64749990e..5cd85a9d149d 100644
@@ -22,6 +22,7 @@
 
  #define SWSMU_CODE_LAYER_L1
 
+#include <linux/cpu.h>
  #include <linux/firmware.h>
  #include <linux/pci.h>
 
@@ -69,6 +70,14 @@ static int smu_set_fan_speed_rpm(void *handle,

uint32_t speed);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_funcs(struct amdgpu_device

Quoted 16 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +8 -0
  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);
+
+extern struct raw_notifier_head smt_notifier_head;
+
+static struct notifier_block smt_notifier = {
+	.notifier_call = smt_notifier_callback, };
+
  static int smu_sys_get_pp_feature_mask(void *handle,
  				       char *buf)
  {
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -625,6 +634,8 @@ static int smu_set_funcs(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_funcs(struct amdgpu_device *adev) · line 641

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
  	return 0;
  }
 
+static struct smu_context *current_smu;
+
  static int smu_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;

@@

Quoted 40 lines

-645,6 +656,7 @@ static int smu_early_init(void *handle)
mutex_init(&smu->message_lock);

  	adev->powerplay.pp_handle = smu;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +14 -0
+	current_smu = smu;
  	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
 
  	r = smu_set_funcs(adev);
@@ -1105,6 +1117,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, &smt_notifier);
+
  	return 0;
  }
 
@@ -1122,6 +1136,8 @@ static int smu_sw_fini(void *handle)
 
  	smu_fini_microcode(smu);
 
+	raw_notifier_chain_unregister(&smt_notifier_head, &smt_notifier);
+
  	return 0;
  }
 
@@ -3241,3 +3257,28 @@ 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;
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3275

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +6 -0
+}
+
+static int smt_notifier_callback(struct notifier_block *nb,
+				 unsigned long action, void *data) {
+	struct smu_context *smu = current_smu;
+	int ret = NOTIFY_OK;

This initialization is pointless, it's clobbered in the next line.

Yes, accept.

Quoted 9 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3279

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+
+	ret = (action == SMT_ENABLED) ?
+				smu_set_cpu_smt_enable(smu, true) :
+				smu_set_cpu_smt_enable(smu, false);

How about this instead, it should be more readable:

	ret = smu_set_cpu_smt_enable(smu, action == SMT_ENABLED);

Accept.

Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_send_hbm_bad_channel_flag(struct smu_context *smu, uint32_t size) · line 3283

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -0
+	if (ret)
+		ret = NOTIFY_BAD;
+
+	return ret;

How about instead:

Quoted 5 lines
	dev_dbg(adev->dev, "failed to %sable SMT: %d\n", action ==

SMT_ENABLED ? "en" : "dis", ret);

	return ret ? NOTIFY_BAD : NOTIFY_OK;

Accept.

Thanks
Wenyou

Quoted 19 lines

drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h struct pptable_funcs { · line 1354

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+}
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +0 -0
index 09469c750a96..7c6594bba796 100644
@@ -1354,6 +1354,11 @@ struct pptable_funcs {
  	 * @init_pptable_microcode: Prepare the pptable microcode to

upload via PSP

Quoted 10 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 enable);
  };
 
  typedef enum {
#9 lore raw

PATCH 3/3 drm/amd/pm: vangogh: support to send SMT enable message

In reply to Wenyou Yang

Add the support to PPSMC_MSG_SetCClkSMTEnable(0x58) message to pmfw for vangogh.

---
 .../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  | 19 +++++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h +2 -1
index 7471e2df2828..2b182dbc6f9c 100644
@@ -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                            0x54
 
 //Argument for PPSMC_MSG_GfxDeviceDriverReset
 enum {
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
index 297b70b9388f..820812d910bf 100644
@@ -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 +19 -0
index 7433dcaa16e0..f0eeb42df96b 100644
@@ -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,23 @@ static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entr
 	return ret;
 }
 
+static int vangogh_set_cpu_smt_enable(struct smu_context *smu, bool enable)
+{
+	int ret = 0;
+
+	if (enable) {
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+						      SMU_MSG_SetCClkSMTEnable,
+						      1, NULL);
+	} else {
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+						      SMU_MSG_SetCClkSMTEnable,
+						      0, NULL);
+	}
+
+	return ret;
+}
+
 static const struct pptable_funcs vangogh_ppt_funcs = {
 
 	.check_fw_status = smu_v11_0_check_fw_status,
@@ -2474,6 +2492,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
#10 lore raw

Re: [v1,3/3] drm/amd/pm: vangogh: support to send SMT enable message

Quoted 15 lines · Wenyou Yang

Add the support to PPSMC_MSG_SetCClkSMTEnable(0x58) message to pmfw for vangogh.

---
  .../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  | 19 +++++++++++++++++++
  3 files changed, 23 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h +0 -0
index 7471e2df2828..2b182dbc6f9c 100644

drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h line 115

Quoted 6 lines
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                            0x54

This doesn't make sense that the PPSMC_Message_Count would be smaller than the biggest message. This should be:

#define PPSMC_Message_Count 0x59

Quoted 61 lines
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h +0 -0
  //Argument for PPSMC_MSG_GfxDeviceDriverReset
  enum {
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
index 297b70b9388f..820812d910bf 100644
@@ -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 +19 -0
index 7433dcaa16e0..f0eeb42df96b 100644
@@ -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,23 @@ static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entr
  	return ret;
  }
 
+static int vangogh_set_cpu_smt_enable(struct smu_context *smu, bool enable)
+{
+	int ret = 0;
+
+	if (enable) {
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+						      SMU_MSG_SetCClkSMTEnable,
+						      1, NULL);
+	} else {
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+						      SMU_MSG_SetCClkSMTEnable,
+						      0, NULL);
+	}
+
+	return ret;
+}
+
  static const struct pptable_funcs vangogh_ppt_funcs = {
 
  	.check_fw_status = smu_v11_0_check_fw_status,
@@ -2474,6 +2492,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)
#11 lore raw

RE: [v1,3/3] drm/amd/pm: vangogh: support to send SMT enable message

[AMD Official Use Only - General]

Quoted 42 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 24, 2023 1:15 AM
To: Yang, WenYou <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>
Cc: Li, Ying <[email protected]>; Liu, Kun <[email protected]>; amd- [email protected]; Liang, Richard qi <[email protected]>
Subject: Re: [v1,3/3] drm/amd/pm: vangogh: support to send SMT enable message

Quoted 1 line · Wenyou Yang

Add the support to PPSMC_MSG_SetCClkSMTEnable(0x58) message to

pmfw

Quoted 7 lines

for vangogh.

---
  .../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  | 19

+++++++++++++++++++

Quoted 8 lines
  3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h index 7471e2df2828..2b182dbc6f9c 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h
+++

b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h

drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h line 115

Quoted 7 lines
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                            0x54

This doesn't make sense that the PPSMC_Message_Count would be smaller than the biggest message. This should be:

Quoted 2 lines

#define PPSMC_Message_Count 0x59

Accepted.

Thanks
Wenyou

Quoted 75 lines

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static struct cmn2asic_msg_mapping

Quoted 24 lines
drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v11_5_ppsmc.h +0 -0
  //Argument for PPSMC_MSG_GfxDeviceDriverReset
  enum {
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
index 297b70b9388f..820812d910bf 100644
@@ -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 +0 -0
index 7433dcaa16e0..f0eeb42df96b 100644
@@ -141,6 +141,7 @@ static struct cmn2asic_msg_mapping

vangogh_message_map[SMU_MSG_MAX_COUNT] = {

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static struct cmn2asic_msg_mapping · line 141

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +0 -0
  	MSG_MAP(GetGfxOffStatus,

PPSMC_MSG_GetGfxOffStatus,

	0),

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static struct cmn2asic_msg_mapping · line 142

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +0 -0
  	MSG_MAP(GetGfxOffEntryCount,

PPSMC_MSG_GetGfxOffEntryCount, 0),

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static struct cmn2asic_msg_mapping · line 143

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +0 -0
  	MSG_MAP(LogGfxOffResidency,

PPSMC_MSG_LogGfxOffResidency, 0),

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static struct cmn2asic_msg_mapping · line 144

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +1 -0
+	MSG_MAP(SetCClkSMTEnable,

PPSMC_MSG_SetCClkSMTEnable,

	0),
Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +0 -0
  };
 
  static struct cmn2asic_mapping

vangogh_feature_mask_map[SMU_FEATURE_COUNT] = { @@ -2428,6

+2429,23 @@ static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entr

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entr · line 2445

Quoted 10 lines
  	return ret;
  }
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +7 -0
+static int vangogh_set_cpu_smt_enable(struct smu_context *smu, bool
+enable) {
+	int ret = 0;
+
+	if (enable) {
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+

SMU_MSG_SetCClkSMTEnable,

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entr · line 2445

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +4 -0
+						      1, NULL);
+	} else {
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+

SMU_MSG_SetCClkSMTEnable,

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c static u32 vangogh_get_gfxoff_entrycount(struct smu_context *smu, uint64_t *entr

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +6 -0
+						      0, NULL);
+	}
+
+	return ret;
+}
+
  static const struct pptable_funcs vangogh_ppt_funcs = {
 
  	.check_fw_status = smu_v11_0_check_fw_status, @@ -2474,6

+2492,7 @@

Quoted 8 lines

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,

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +1 -0
+	.set_cpu_smt_enable = vangogh_set_cpu_smt_enable,
  };
 
  void vangogh_set_ppt_funcs(struct smu_context *smu)