drm/amd/pm: add xgmi_plpd_policy sysfs node for user to change plpd policy
authorLe Ma <le.ma@amd.com>
Thu, 7 Sep 2023 07:50:14 +0000 (15:50 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 26 Sep 2023 21:00:23 +0000 (17:00 -0400)
Add xgmi_plpd_policy sysfs node for users to check and select xgmi
per-link power down policy:
  - arg 0: disallow plpd
  - arg 1: default policy
  - arg 2: optimized policy

v2: split from smu v13.0.6 code and miscellaneous updates
v3: add usage comments around set/get functions

Signed-off-by: Le Ma <le.ma@amd.com>
Reviewed-by: Asad Kamal <asad.kamal@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/amdgpu_dpm.c
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

index 078aaaa53162801e4e10f08dd8f66641ddc41c9b..9a157fe4cbc728777f282811b8c35552b5b91304 100644 (file)
@@ -365,6 +365,49 @@ int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en)
        return ret;
 }
 
+int amdgpu_dpm_get_xgmi_plpd_mode(struct amdgpu_device *adev, char **mode_desc)
+{
+       struct smu_context *smu = adev->powerplay.pp_handle;
+       int mode = XGMI_PLPD_NONE;
+
+       if (is_support_sw_smu(adev)) {
+               mode = smu->plpd_mode;
+               if (mode_desc == NULL)
+                       return mode;
+               switch (smu->plpd_mode) {
+               case XGMI_PLPD_DISALLOW:
+                       *mode_desc = "disallow";
+                       break;
+               case XGMI_PLPD_DEFAULT:
+                       *mode_desc = "default";
+                       break;
+               case XGMI_PLPD_OPTIMIZED:
+                       *mode_desc = "optimized";
+                       break;
+               case XGMI_PLPD_NONE:
+               default:
+                       *mode_desc = "none";
+                       break;
+               }
+       }
+
+       return mode;
+}
+
+int amdgpu_dpm_set_xgmi_plpd_mode(struct amdgpu_device *adev, int mode)
+{
+       struct smu_context *smu = adev->powerplay.pp_handle;
+       int ret = -EOPNOTSUPP;
+
+       if (is_support_sw_smu(adev)) {
+               mutex_lock(&adev->pm.mutex);
+               ret = smu_set_xgmi_plpd_mode(smu, mode);
+               mutex_unlock(&adev->pm.mutex);
+       }
+
+       return ret;
+}
+
 int amdgpu_dpm_enable_mgpu_fan_boost(struct amdgpu_device *adev)
 {
        void *pp_handle = adev->powerplay.pp_handle;
index 2d19282e4fbef8922fdffeb2da62ae45fa188a21..886bb00eaa782fec94eeefb1e270f1b2f8187795 100644 (file)
@@ -1991,6 +1991,70 @@ static int ss_bias_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
        return 0;
 }
 
+/* Following items will be read out to indicate current plpd policy:
+ *  - -1: none
+ *  - 0: disallow
+ *  - 1: default
+ *  - 2: optimized
+ */
+static ssize_t amdgpu_get_xgmi_plpd_policy(struct device *dev,
+                                          struct device_attribute *attr,
+                                          char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+       char *mode_desc = "none";
+       int mode;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       mode = amdgpu_dpm_get_xgmi_plpd_mode(adev, &mode_desc);
+
+       return sysfs_emit(buf, "%d: %s\n", mode, mode_desc);
+}
+
+/* Following argument value is expected from user to change plpd policy
+ *  - arg 0: disallow plpd
+ *  - arg 1: default policy
+ *  - arg 2: optimized policy
+ */
+static ssize_t amdgpu_set_xgmi_plpd_policy(struct device *dev,
+                                          struct device_attribute *attr,
+                                          const char *buf, size_t count)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+       int mode, ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = kstrtos32(buf, 0, &mode);
+       if (ret)
+               return -EINVAL;
+
+       ret = pm_runtime_get_sync(ddev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(ddev->dev);
+               return ret;
+       }
+
+       ret = amdgpu_dpm_set_xgmi_plpd_mode(adev, mode);
+
+       pm_runtime_mark_last_busy(ddev->dev);
+       pm_runtime_put_autosuspend(ddev->dev);
+
+       if (ret)
+               return ret;
+
+       return count;
+}
+
 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
        AMDGPU_DEVICE_ATTR_RW(power_dpm_state,                          ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
        AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level,        ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
@@ -2026,6 +2090,7 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
                              .attr_update = ss_power_attr_update),
        AMDGPU_DEVICE_ATTR_RW(smartshift_bias,                          ATTR_FLAG_BASIC,
                              .attr_update = ss_bias_attr_update),
+       AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,                         ATTR_FLAG_BASIC),
 };
 
 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
@@ -2124,6 +2189,9 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
                        *states = ATTR_STATE_UNSUPPORTED;
                else if (gc_ver == IP_VERSION(10, 3, 0) && amdgpu_sriov_vf(adev))
                        *states = ATTR_STATE_UNSUPPORTED;
+       } else if (DEVICE_ATTR_IS(xgmi_plpd_policy)) {
+               if (amdgpu_dpm_get_xgmi_plpd_mode(adev, NULL) == XGMI_PLPD_NONE)
+                       *states = ATTR_STATE_UNSUPPORTED;
        }
 
        switch (gc_ver) {
index 5efdba6e358fdf5b762b57dd5f4007a0bb8a086f..564494f297173d9508bcdcaa66e686a21c79e970 100644 (file)
@@ -426,6 +426,11 @@ int amdgpu_dpm_set_df_cstate(struct amdgpu_device *adev,
 
 int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en);
 
+int amdgpu_dpm_get_xgmi_plpd_mode(struct amdgpu_device *adev,
+                                 char **mode);
+
+int amdgpu_dpm_set_xgmi_plpd_mode(struct amdgpu_device *adev, int mode);
+
 int amdgpu_dpm_enable_mgpu_fan_boost(struct amdgpu_device *adev);
 
 int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,