Re: [PATCH v2 2/7] drm/amdgpu: Add new function to set GPU power profile

From: Yadav, Arvind
Date: Tue Aug 22 2023 - 08:40:43 EST



On 8/22/2023 11:55 AM, Lazar, Lijo wrote:


On 8/21/2023 12:17 PM, Arvind Yadav wrote:
This patch adds a function which will change the GPU
power profile based on a submitted job. This can optimize
the power performance when the workload is on.

v2:
- Splitting workload_profile_set and workload_profile_put
   into two separate patches.
- Addressed review comment.

Cc: Shashank Sharma <shashank.sharma@xxxxxxx>
Cc: Christian Koenig <christian.koenig@xxxxxxx>
Cc: Alex Deucher <alexander.deucher@xxxxxxx>
Signed-off-by: Arvind Yadav <Arvind.Yadav@xxxxxxx>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c  | 56 +++++++++++++++++++
  drivers/gpu/drm/amd/include/amdgpu_workload.h |  3 +
  2 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c
index 32166f482f77..e661cc5b3d92 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_workload.c
@@ -24,6 +24,62 @@
    #include "amdgpu.h"
  +static enum PP_SMC_POWER_PROFILE
+ring_to_power_profile(uint32_t ring_type)
+{
+    switch (ring_type) {
+    case AMDGPU_RING_TYPE_GFX:
+        return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_RING_TYPE_COMPUTE:
+        return PP_SMC_POWER_PROFILE_COMPUTE;
+    case AMDGPU_RING_TYPE_UVD:
+    case AMDGPU_RING_TYPE_VCE:
+    case AMDGPU_RING_TYPE_UVD_ENC:
+    case AMDGPU_RING_TYPE_VCN_DEC:
+    case AMDGPU_RING_TYPE_VCN_ENC:
+    case AMDGPU_RING_TYPE_VCN_JPEG:
+        return PP_SMC_POWER_PROFILE_VIDEO;
+    default:
+        return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+    }
+}
+
+static int
+amdgpu_power_profile_set(struct amdgpu_device *adev,
+             enum PP_SMC_POWER_PROFILE profile)
+{
+    int ret = amdgpu_dpm_switch_power_profile(adev, profile, true);
+

You don't need to interact with FW for every set() call. Only send the message if workload_status doesn't have the profile set or refcount is zero. Otherwise, only need to increment the refcount.
Noted.
Thank You,
~Arvind

Thanks,
Lijo

+    if (!ret) {
+        /* Set the bit for the submitted workload profile */
+        adev->smu_workload.submit_workload_status |= (1 << profile);
+ atomic_inc(&adev->smu_workload.power_profile_ref[profile]);
+    }
+
+    return ret;
+}
+
+void amdgpu_workload_profile_set(struct amdgpu_device *adev,
+                 uint32_t ring_type)
+{
+    struct amdgpu_smu_workload *workload = &adev->smu_workload;
+    enum PP_SMC_POWER_PROFILE profile = ring_to_power_profile(ring_type);
+    int ret;
+
+    if (profile == PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT)
+        return;
+
+    mutex_lock(&workload->workload_lock);
+
+    ret = amdgpu_power_profile_set(adev, profile);
+    if (ret) {
+        DRM_WARN("Failed to set workload profile to %s, error = %d\n",
+             amdgpu_workload_mode_name[profile], ret);
+    }
+
+    mutex_unlock(&workload->workload_lock);
+}
+
  void amdgpu_workload_profile_init(struct amdgpu_device *adev)
  {
      adev->smu_workload.adev = adev;
diff --git a/drivers/gpu/drm/amd/include/amdgpu_workload.h b/drivers/gpu/drm/amd/include/amdgpu_workload.h
index 5d0f068422d4..5022f28fc2f9 100644
--- a/drivers/gpu/drm/amd/include/amdgpu_workload.h
+++ b/drivers/gpu/drm/amd/include/amdgpu_workload.h
@@ -46,6 +46,9 @@ static const char * const amdgpu_workload_mode_name[] = {
      "Window3D"
  };
  +void amdgpu_workload_profile_set(struct amdgpu_device *adev,
+                 uint32_t ring_type);
+
  void amdgpu_workload_profile_init(struct amdgpu_device *adev);
    void amdgpu_workload_profile_fini(struct amdgpu_device *adev);