Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Felix Kuehling

Am 2022-09-26 um 17:40 schrieb Shashank Sharma:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o amdgpu_pll.o \
-   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_ctx_workload.o 
amdgpu_sync.o \
amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o \
amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+   switch (hint) {
+   case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+   default:
+   return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+   case AMDGPU_CTX_WORKLOAD_HINT_3D:
+   return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+   case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+   return PP_SMC_POWER_PROFILE_VIDEO;
+   case AMDGPU_CTX_WORKLOAD_HINT_VR:
+   return PP_SMC_POWER_PROFILE_VR;
+   case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+   return PP_SMC_POWER_PROFILE_COMPUTE;
+   }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+   uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (adev->pm.workload_mode == hint)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);
+
+   if (adev->pm.workload_mode == hint)
+   goto unlock;
+
+   ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
+   if (!ret)
+   adev->pm.workload_mode = hint;
+   atomic_inc(>pm.workload_switch_ref);
+
+unlock:
+   mutex_unlock(>pm.smu_workload_lock);
+   return ret;
+}
+
+int amdgpu_clear_workload_profile(struct amdgpu_device *adev,
+ uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (hint == AMDGPU_CTX_WORKLOAD_HINT_NONE)
+   return 0;
+
+   /* Do not reset GPU power profile if another reset is coming */
+   if (atomic_dec_return(>pm.workload_switch_ref) > 0)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);
+
+   if (adev->pm.workload_mode != hint)
+   goto unlock;
+
+   ret = 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 4:34 PM, Lazar, Lijo wrote:



On 9/27/2022 7:50 PM, Sharma, Shashank wrote:



On 9/27/2022 4:00 PM, Lazar, Lijo wrote:



On 9/27/2022 7:17 PM, Sharma, Shashank wrote:



On 9/27/2022 3:29 PM, Lazar, Lijo wrote:



On 9/27/2022 6:23 PM, Sharma, Shashank wrote:



On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 
+++

  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o 
amdgpu_ib.o amdgpu_pll.o \
-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o 
amdgpu_vram_mgr.o amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git 
a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any 
person obtaining a
+ * copy of this software and associated documentation files 
(the "Software"),
+ * to deal in the Software without restriction, including 
without limitation
+ * the rights to use, copy, modify, merge, publish, 
distribute, sublicense,
+ * and/or sell copies of the Software, and to permit 
persons to whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice 
shall be included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 
ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  
IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY 
CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 
OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API 
should rather be inside amd/pm subsystem. No need to expose 
the variable outside pm subsytem. Also currently all 
amdgpu_dpm* calls are protected under one mutex. Then this 
extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that 
the job management and scheduling is handled into amdgpu_ctx, 
so the workload hint is set in context_management API. The API 
is consumed when the job is actually run from amdgpu_run() 
layer. So its a joint 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Lazar, Lijo




On 9/27/2022 7:50 PM, Sharma, Shashank wrote:



On 9/27/2022 4:00 PM, Lazar, Lijo wrote:



On 9/27/2022 7:17 PM, Sharma, Shashank wrote:



On 9/27/2022 3:29 PM, Lazar, Lijo wrote:



On 9/27/2022 6:23 PM, Sharma, Shashank wrote:



On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \
-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any 
person obtaining a
+ * copy of this software and associated documentation files 
(the "Software"),
+ * to deal in the Software without restriction, including 
without limitation
+ * the rights to use, copy, modify, merge, publish, 
distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons 
to whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice 
shall be included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN 
NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY 
CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 
OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API 
should rather be inside amd/pm subsystem. No need to expose 
the variable outside pm subsytem. Also currently all 
amdgpu_dpm* calls are protected under one mutex. Then this 
extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that 
the job management and scheduling is handled into amdgpu_ctx, 
so the workload hint is set in context_management API. The API 
is consumed when the job is actually run from amdgpu_run() 
layer. So its a joint interface between context and PM.




If you take out 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 4:00 PM, Lazar, Lijo wrote:



On 9/27/2022 7:17 PM, Sharma, Shashank wrote:



On 9/27/2022 3:29 PM, Lazar, Lijo wrote:



On 9/27/2022 6:23 PM, Sharma, Shashank wrote:



On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any 
person obtaining a
+ * copy of this software and associated documentation files 
(the "Software"),
+ * to deal in the Software without restriction, including 
without limitation
+ * the rights to use, copy, modify, merge, publish, 
distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons 
to whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice 
shall be included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN 
NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY 
CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
THE USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API 
should rather be inside amd/pm subsystem. No need to expose the 
variable outside pm subsytem. Also currently all amdgpu_dpm* 
calls are protected under one mutex. Then this extra lock won't 
be needed.




This is tricky, this is not all about PM subsystem. Note that 
the job management and scheduling is handled into amdgpu_ctx, so 
the workload hint is set in context_management API. The API is 
consumed when the job is actually run from amdgpu_run() layer. 
So its a joint interface between context and PM.




If you take out amdgpu_workload_to_power_profile() line, 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Lazar, Lijo




On 9/27/2022 7:17 PM, Sharma, Shashank wrote:



On 9/27/2022 3:29 PM, Lazar, Lijo wrote:



On 9/27/2022 6:23 PM, Sharma, Shashank wrote:



On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files 
(the "Software"),
+ * to deal in the Software without restriction, including 
without limitation
+ * the rights to use, copy, modify, merge, publish, 
distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons 
to whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice shall 
be included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN 
NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY 
CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
THE USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API 
should rather be inside amd/pm subsystem. No need to expose the 
variable outside pm subsytem. Also currently all amdgpu_dpm* 
calls are protected under one mutex. Then this extra lock won't 
be needed.




This is tricky, this is not all about PM subsystem. Note that the 
job management and scheduling is handled into amdgpu_ctx, so the 
workload hint is set in context_management API. The API is 
consumed when the job is actually run from amdgpu_run() layer. So 
its a joint interface between context and PM.




If you take out amdgpu_workload_to_power_profile() line, 
everything else looks to touch only pm 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 3:29 PM, Lazar, Lijo wrote:



On 9/27/2022 6:23 PM, Sharma, Shashank wrote:



On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files 
(the "Software"),
+ * to deal in the Software without restriction, including 
without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,
+ * and/or sell copies of the Software, and to permit persons to 
whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice shall 
be included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO 
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY 
CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
THE USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should 
rather be inside amd/pm subsystem. No need to expose the variable 
outside pm subsytem. Also currently all amdgpu_dpm* calls are 
protected under one mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the 
job management and scheduling is handled into amdgpu_ctx, so the 
workload hint is set in context_management API. The API is 
consumed when the job is actually run from amdgpu_run() layer. So 
its a joint interface between context and PM.




If you take out amdgpu_workload_to_power_profile() line, everything 
else looks to touch only pm variables/functions. 


That's not a line, that function 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Lazar, Lijo




On 9/27/2022 6:23 PM, Sharma, Shashank wrote:



On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files (the 
"Software"),
+ * to deal in the Software without restriction, including 
without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,
+ * and/or sell copies of the Software, and to permit persons to 
whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice shall 
be included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO 
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, 
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
THE USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should 
rather be inside amd/pm subsystem. No need to expose the variable 
outside pm subsytem. Also currently all amdgpu_dpm* calls are 
protected under one mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the 
job management and scheduling is handled into amdgpu_ctx, so the 
workload hint is set in context_management API. The API is consumed 
when the job is actually run from amdgpu_run() layer. So its a 
joint interface between context and PM.




If you take out amdgpu_workload_to_power_profile() line, everything 
else looks to touch only pm variables/functions. 


That's not a line, that function converts a AMGPU_CTX hint to PPM 
profile. And 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 2:39 PM, Lazar, Lijo wrote:



On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h


diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files (the 
"Software"),
+ * to deal in the Software without restriction, including without 
limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,
+ * and/or sell copies of the Software, and to permit persons to 
whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice shall be 
included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO 
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, 
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should 
rather be inside amd/pm subsystem. No need to expose the variable 
outside pm subsytem. Also currently all amdgpu_dpm* calls are 
protected under one mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the 
job management and scheduling is handled into amdgpu_ctx, so the 
workload hint is set in context_management API. The API is consumed 
when the job is actually run from amdgpu_run() layer. So its a joint 
interface between context and PM.




If you take out amdgpu_workload_to_power_profile() line, everything 
else looks to touch only pm variables/functions. 


That's not a line, that function converts a AMGPU_CTX hint to PPM 
profile. And going by that logic, this whole code was kept in the 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Lazar, Lijo




On 9/27/2022 5:53 PM, Sharma, Shashank wrote:



On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files (the 
"Software"),
+ * to deal in the Software without restriction, including without 
limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,
+ * and/or sell copies of the Software, and to permit persons to 
whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice shall be 
included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO 
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, 
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should 
rather be inside amd/pm subsystem. No need to expose the variable 
outside pm subsytem. Also currently all amdgpu_dpm* calls are 
protected under one mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the job 
management and scheduling is handled into amdgpu_ctx, so the workload 
hint is set in context_management API. The API is consumed when the 
job is actually run from amdgpu_run() layer. So its a joint interface 
between context and PM.




If you take out amdgpu_workload_to_power_profile() line, everything 
else looks to touch only pm variables/functions. 


That's not a line, that function converts a AMGPU_CTX hint to PPM 
profile. And going by that logic, this whole code was kept in the 
amdgpu_ctx.c file as well, coz this code is 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 2:10 PM, Lazar, Lijo wrote:



On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 
+++

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files (the 
"Software"),
+ * to deal in the Software without restriction, including without 
limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,
+ * and/or sell copies of the Software, and to permit persons to 
whom the
+ * Software is furnished to do so, subject to the following 
conditions:

+ *
+ * The above copyright notice and this permission notice shall be 
included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO 
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, 
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should 
rather be inside amd/pm subsystem. No need to expose the variable 
outside pm subsytem. Also currently all amdgpu_dpm* calls are 
protected under one mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the job 
management and scheduling is handled into amdgpu_ctx, so the workload 
hint is set in context_management API. The API is consumed when the 
job is actually run from amdgpu_run() layer. So its a joint interface 
between context and PM.




If you take out amdgpu_workload_to_power_profile() line, everything else 
looks to touch only pm variables/functions. 


That's not a line, that function converts a AMGPU_CTX hint to PPM 
profile. And going by that logic, this whole code was kept in the 
amdgpu_ctx.c file as well, coz this code is consuming the PM API. So to 
avoid these conflicts 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Lazar, Lijo




On 9/27/2022 5:11 PM, Sharma, Shashank wrote:



On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files (the 
"Software"),
+ * to deal in the Software without restriction, including without 
limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom 
the

+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be 
included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO 
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, 
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
USE OR

+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should 
rather be inside amd/pm subsystem. No need to expose the variable 
outside pm subsytem. Also currently all amdgpu_dpm* calls are 
protected under one mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the job 
management and scheduling is handled into amdgpu_ctx, so the workload 
hint is set in context_management API. The API is consumed when the job 
is actually run from amdgpu_run() layer. So its a joint interface 
between context and PM.




If you take out amdgpu_workload_to_power_profile() line, everything else 
looks to touch only pm variables/functions. You could still keep a 
wrapper though. Also dpm_* functions are protected, so the extra mutex 
can be avoided as well.



+
+    if (adev->pm.workload_mode == hint)
+    goto unlock;
+
+    ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
+    if (!ret)
+    

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 11:58 AM, Lazar, Lijo wrote:



On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
  atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
  atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
  amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o 
amdgpu_pll.o \

-    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+    amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o 
amdgpu_ctx_workload.o amdgpu_sync.o \
  amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o 
amdgpu_virt.o \

  amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
  amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c

new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person 
obtaining a
+ * copy of this software and associated documentation files (the 
"Software"),
+ * to deal in the Software without restriction, including without 
limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 
sublicense,

+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be 
included in

+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT 
SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, 
DAMAGES OR

+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+    switch (hint) {
+    case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+    default:
+    return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+    case AMDGPU_CTX_WORKLOAD_HINT_3D:
+    return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+    case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+    return PP_SMC_POWER_PROFILE_VIDEO;
+    case AMDGPU_CTX_WORKLOAD_HINT_VR:
+    return PP_SMC_POWER_PROFILE_VR;
+    case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+    return PP_SMC_POWER_PROFILE_COMPUTE;
+    }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+    uint32_t hint)
+{
+    int ret = 0;
+    enum PP_SMC_POWER_PROFILE profile =
+    amdgpu_workload_to_power_profile(hint);
+
+    if (adev->pm.workload_mode == hint)
+    return 0;
+
+    mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should rather 
be inside amd/pm subsystem. No need to expose the variable outside pm 
subsytem. Also currently all amdgpu_dpm* calls are protected under one 
mutex. Then this extra lock won't be needed.




This is tricky, this is not all about PM subsystem. Note that the job 
management and scheduling is handled into amdgpu_ctx, so the workload 
hint is set in context_management API. The API is consumed when the job 
is actually run from amdgpu_run() layer. So its a joint interface 
between context and PM.



+
+    if (adev->pm.workload_mode == hint)
+    goto unlock;
+
+    ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
+    if (!ret)
+    adev->pm.workload_mode = hint;
+    atomic_inc(>pm.workload_switch_ref);


Why is this reference kept? The swtiching happens inside a lock and 
there is already a check not to switch if the hint matches with current 
workload.




This reference is kept so that we would not reset the PM mode to 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank




On 9/27/2022 11:29 AM, Quan, Evan wrote:

[AMD Official Use Only - General]




-Original Message-
From: Sharma, Shashank 
Sent: Tuesday, September 27, 2022 3:30 PM
To: Quan, Evan ; amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander ; Somalapuram,
Amaranath ; Koenig, Christian

Subject: Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU
power profile

Hello Evan,

On 9/27/2022 4:14 AM, Quan, Evan wrote:

[AMD Official Use Only - General]




-Original Message-
From: amd-gfx  On Behalf Of
Shashank Sharma
Sent: Tuesday, September 27, 2022 5:40 AM
To: amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander ; Somalapuram,
Amaranath ; Koenig, Christian
; Sharma, Shashank

Subject: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU
power profile

This patch adds new functions which will allow a user to change the
GPU power profile based a GPU workload hint flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
   drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
   .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97
+++
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
   .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
   drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
   5 files changed, 158 insertions(+), 1 deletion(-)
   create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
   create mode 100644
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o
amdgpu_pll.o \
-   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o
amdgpu_ctx_workload.o amdgpu_sync.o \
amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o
amdgpu_virt.o \
amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \ diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
"Software"),
+ * to deal in the Software without restriction, including without
+ limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+ sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom
+ the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY

KIND,

EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN

NO

EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint) {
+   switch (hint) {
+   case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+   default:
+   return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+   case AMDGPU_CTX_WORKLOAD_HINT_3D:
+   return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+   case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+   return PP_SMC_POWER_PROFILE_VIDEO;
+   case AMDGPU_CTX_WORKLOAD_HINT_VR:
+   return PP_SMC_POWER_PROFILE_VR;
+   case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+   return PP_SMC_POWER_PROFILE_COMPUTE;
+   }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+   uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (adev->pm.workload_mode == hint)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);
+
+   if (adev->pm.workload_mode == hint)
+   goto unlock;

[Quan, Evan] This seems redundant with code above. I saw you dropped

this in Patch4.

But 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Lazar, Lijo




On 9/27/2022 3:10 AM, Shashank Sharma wrote:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o amdgpu_pll.o \
-   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_ctx_workload.o 
amdgpu_sync.o \
amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o \
amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+   switch (hint) {
+   case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+   default:
+   return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+   case AMDGPU_CTX_WORKLOAD_HINT_3D:
+   return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+   case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+   return PP_SMC_POWER_PROFILE_VIDEO;
+   case AMDGPU_CTX_WORKLOAD_HINT_VR:
+   return PP_SMC_POWER_PROFILE_VR;
+   case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+   return PP_SMC_POWER_PROFILE_COMPUTE;
+   }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+   uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (adev->pm.workload_mode == hint)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);


If it's all about pm subsystem variable accesses, this API should rather 
be inside amd/pm subsystem. No need to expose the variable outside pm 
subsytem. Also currently all amdgpu_dpm* calls are protected under one 
mutex. Then this extra lock won't be needed.



+
+   if (adev->pm.workload_mode == hint)
+   goto unlock;
+
+   ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
+   if (!ret)
+   adev->pm.workload_mode = hint;
+   atomic_inc(>pm.workload_switch_ref);


Why is this reference kept? The swtiching happens inside a lock and 
there is already a check not to switch if the hint matches with current 
workload.


Thanks,
Lijo


+
+unlock:
+   mutex_unlock(>pm.smu_workload_lock);
+   return ret;
+}
+
+int amdgpu_clear_workload_profile(struct amdgpu_device *adev,
+ uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+

RE: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Quan, Evan
[AMD Official Use Only - General]



> -Original Message-
> From: Sharma, Shashank 
> Sent: Tuesday, September 27, 2022 3:30 PM
> To: Quan, Evan ; amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander ; Somalapuram,
> Amaranath ; Koenig, Christian
> 
> Subject: Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU
> power profile
> 
> Hello Evan,
> 
> On 9/27/2022 4:14 AM, Quan, Evan wrote:
> > [AMD Official Use Only - General]
> >
> >
> >
> >> -Original Message-
> >> From: amd-gfx  On Behalf Of
> >> Shashank Sharma
> >> Sent: Tuesday, September 27, 2022 5:40 AM
> >> To: amd-gfx@lists.freedesktop.org
> >> Cc: Deucher, Alexander ; Somalapuram,
> >> Amaranath ; Koenig, Christian
> >> ; Sharma, Shashank
> >> 
> >> Subject: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU
> >> power profile
> >>
> >> This patch adds new functions which will allow a user to change the
> >> GPU power profile based a GPU workload hint flag.
> >>
> >> Cc: Alex Deucher 
> >> Signed-off-by: Shashank Sharma 
> >> ---
> >>   drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
> >>   .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97
> >> +++
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
> >>   .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
> >>   drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
> >>   5 files changed, 158 insertions(+), 1 deletion(-)
> >>   create mode 100644
> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> >>   create mode 100644
> >> drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> >> b/drivers/gpu/drm/amd/amdgpu/Makefile
> >> index 5a283d12f8e1..34679c657ecc 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> >> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> >> @@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
> >>atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
> >>atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
> >>amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o
> >> amdgpu_pll.o \
> >> -  amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
> >> +  amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o
> >> amdgpu_ctx_workload.o amdgpu_sync.o \
> >>amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o
> >> amdgpu_virt.o \
> >>amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
> >>amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \ diff --git
> >> a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> >> new file mode 100644
> >> index ..a11cf29bc388
> >> --- /dev/null
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> >> @@ -0,0 +1,97 @@
> >> +/*
> >> + * Copyright 2022 Advanced Micro Devices, Inc.
> >> + *
> >> + * Permission is hereby granted, free of charge, to any person
> >> +obtaining a
> >> + * copy of this software and associated documentation files (the
> >> "Software"),
> >> + * to deal in the Software without restriction, including without
> >> + limitation
> >> + * the rights to use, copy, modify, merge, publish, distribute,
> >> + sublicense,
> >> + * and/or sell copies of the Software, and to permit persons to whom
> >> + the
> >> + * Software is furnished to do so, subject to the following conditions:
> >> + *
> >> + * The above copyright notice and this permission notice shall be
> >> + included in
> >> + * all copies or substantial portions of the Software.
> >> + *
> >> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
> KIND,
> >> EXPRESS OR
> >> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> >> MERCHANTABILITY,
> >> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN
> NO
> >> EVENT SHALL
> >> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> >> DAMAGES OR
> >> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> >> OTHERWISE,
> >> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
> >> THE USE OR
> >> + * OTHER DEALINGS IN THE SOFTWARE.
> >> + *
> >> + */
> >> +

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Sharma, Shashank

Hello Evan,

On 9/27/2022 4:14 AM, Quan, Evan wrote:

[AMD Official Use Only - General]




-Original Message-
From: amd-gfx  On Behalf Of
Shashank Sharma
Sent: Tuesday, September 27, 2022 5:40 AM
To: amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander ; Somalapuram,
Amaranath ; Koenig, Christian
; Sharma, Shashank

Subject: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power
profile

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 
---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97
+++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644
drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o
amdgpu_pll.o \
-   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o
amdgpu_ctx_workload.o amdgpu_sync.o \
amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o
amdgpu_virt.o \
amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
"Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+   switch (hint) {
+   case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+   default:
+   return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+   case AMDGPU_CTX_WORKLOAD_HINT_3D:
+   return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+   case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+   return PP_SMC_POWER_PROFILE_VIDEO;
+   case AMDGPU_CTX_WORKLOAD_HINT_VR:
+   return PP_SMC_POWER_PROFILE_VR;
+   case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+   return PP_SMC_POWER_PROFILE_COMPUTE;
+   }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+   uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (adev->pm.workload_mode == hint)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);
+
+   if (adev->pm.workload_mode == hint)
+   goto unlock;

[Quan, Evan] This seems redundant with code above. I saw you dropped this in 
Patch4.
But I kind of feel this should be the one which needs to be kept.


Yes, this shuffle happened during the rebase-testing of V3, will update 
this.



+
+   ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
+   if (!ret)
+   adev->pm.workload_mode = hint;
+   atomic_inc(>pm.workload_switch_ref);
+
+unlock:
+   mutex_unlock(>pm.smu_workload_lock);
+   return ret;
+}
+
+int amdgpu_clear_workload_profile(struct 

Re: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-27 Thread Christian König

Am 26.09.22 um 23:40 schrieb Shashank Sharma:

This patch adds new functions which will allow a user to
change the GPU power profile based a GPU workload hint
flag.

Cc: Alex Deucher 
Signed-off-by: Shashank Sharma 


Alex needs to take a closer look at this stuff, but feel free to add my 
acked-by.


Christian.


---
  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
  5 files changed, 158 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
  create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 5a283d12f8e1..34679c657ecc 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o amdgpu_pll.o \
-   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
+   amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_ctx_workload.o 
amdgpu_sync.o \
amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o \
amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
new file mode 100644
index ..a11cf29bc388
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include 
+#include "kgd_pp_interface.h"
+#include "amdgpu_ctx_workload.h"
+
+static enum PP_SMC_POWER_PROFILE
+amdgpu_workload_to_power_profile(uint32_t hint)
+{
+   switch (hint) {
+   case AMDGPU_CTX_WORKLOAD_HINT_NONE:
+   default:
+   return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+
+   case AMDGPU_CTX_WORKLOAD_HINT_3D:
+   return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+   case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
+   return PP_SMC_POWER_PROFILE_VIDEO;
+   case AMDGPU_CTX_WORKLOAD_HINT_VR:
+   return PP_SMC_POWER_PROFILE_VR;
+   case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
+   return PP_SMC_POWER_PROFILE_COMPUTE;
+   }
+}
+
+int amdgpu_set_workload_profile(struct amdgpu_device *adev,
+   uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (adev->pm.workload_mode == hint)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);
+
+   if (adev->pm.workload_mode == hint)
+   goto unlock;
+
+   ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
+   if (!ret)
+   adev->pm.workload_mode = hint;
+   atomic_inc(>pm.workload_switch_ref);
+
+unlock:
+   mutex_unlock(>pm.smu_workload_lock);
+   return ret;
+}
+
+int amdgpu_clear_workload_profile(struct amdgpu_device *adev,
+ uint32_t hint)
+{
+   int ret = 0;
+   enum PP_SMC_POWER_PROFILE profile =
+   amdgpu_workload_to_power_profile(hint);
+
+   if (hint == AMDGPU_CTX_WORKLOAD_HINT_NONE)
+   return 0;
+
+   /* Do not reset GPU power profile if another reset is coming */
+   if (atomic_dec_return(>pm.workload_switch_ref) > 0)
+   return 0;
+
+   mutex_lock(>pm.smu_workload_lock);
+
+  

RE: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power profile

2022-09-26 Thread Quan, Evan
[AMD Official Use Only - General]



> -Original Message-
> From: amd-gfx  On Behalf Of
> Shashank Sharma
> Sent: Tuesday, September 27, 2022 5:40 AM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander ; Somalapuram,
> Amaranath ; Koenig, Christian
> ; Sharma, Shashank
> 
> Subject: [PATCH v3 2/5] drm/amdgpu: add new functions to set GPU power
> profile
> 
> This patch adds new functions which will allow a user to
> change the GPU power profile based a GPU workload hint
> flag.
> 
> Cc: Alex Deucher 
> Signed-off-by: Shashank Sharma 
> ---
>  drivers/gpu/drm/amd/amdgpu/Makefile   |  2 +-
>  .../gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c  | 97
> +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c|  1 +
>  .../gpu/drm/amd/include/amdgpu_ctx_workload.h | 54 +++
>  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  5 +
>  5 files changed, 158 insertions(+), 1 deletion(-)
>  create mode 100644
> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
>  create mode 100644
> drivers/gpu/drm/amd/include/amdgpu_ctx_workload.h
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index 5a283d12f8e1..34679c657ecc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -50,7 +50,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
>   atombios_dp.o amdgpu_afmt.o amdgpu_trace_points.o \
>   atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
>   amdgpu_dma_buf.o amdgpu_vm.o amdgpu_vm_pt.o amdgpu_ib.o
> amdgpu_pll.o \
> - amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
> + amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o
> amdgpu_ctx_workload.o amdgpu_sync.o \
>   amdgpu_gtt_mgr.o amdgpu_preempt_mgr.o amdgpu_vram_mgr.o
> amdgpu_virt.o \
>   amdgpu_atomfirmware.o amdgpu_vf_error.o amdgpu_sched.o \
>   amdgpu_debugfs.o amdgpu_ids.o amdgpu_gmc.o \
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> new file mode 100644
> index ..a11cf29bc388
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx_workload.c
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright 2022 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
> EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
> THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +#include 
> +#include "kgd_pp_interface.h"
> +#include "amdgpu_ctx_workload.h"
> +
> +static enum PP_SMC_POWER_PROFILE
> +amdgpu_workload_to_power_profile(uint32_t hint)
> +{
> + switch (hint) {
> + case AMDGPU_CTX_WORKLOAD_HINT_NONE:
> + default:
> + return PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
> +
> + case AMDGPU_CTX_WORKLOAD_HINT_3D:
> + return PP_SMC_POWER_PROFILE_FULLSCREEN3D;
> + case AMDGPU_CTX_WORKLOAD_HINT_VIDEO:
> + return PP_SMC_POWER_PROFILE_VIDEO;
> + case AMDGPU_CTX_WORKLOAD_HINT_VR:
> + return PP_SMC_POWER_PROFILE_VR;
> + case AMDGPU_CTX_WORKLOAD_HINT_COMPUTE:
> + return PP_SMC_POWER_PROFILE_COMPUTE;
> + }
> +}
> +
> +int amdgpu_set_workload_profile(struct amdgpu_device *adev,
> + uint32_t hint)
> +{
> + int ret = 0;
> + enum PP_SMC_POWER_PROFILE profile =
> + amdgpu_workload_to_power_profile(hint);
> +
> + if (adev->pm.workload_mode == hint)
> + return 0;
> +
> + mutex_lock(>pm.smu_workload_lock);
> +
> + if (adev->pm.workload_mode == hint)
> + goto unlock;
[Quan, Evan] This seems redundant with code above. I saw you dropped this in 
Patch4.
But I kind of feel this should be the one which needs to be kept.
> +
> + ret = amdgpu_dpm_switch_power_profile(adev, profile, 1);
> + if (!ret)
> + adev->pm.workload_mode = hint;
> + atomic_inc(>pm.workload_switch_ref);
> +
> +unlock:
> + mutex_unlock(>pm.smu_workload_lock);
> + return ret;
> +}
> +