[PATCH v2 2/4] drm/amd/pm: Add support to fetch pm metrics sample

Wang, Yang(Kevin) KevinYang.Wang at amd.com
Wed Nov 8 04:42:31 UTC 2023


[AMD Official Use Only - General]

Series is.
Reviewed-by: Yang Wang <kevinyang.wang at amd.com>

Best Regards,
Kevin
-----Original Message-----
From: Lazar, Lijo <Lijo.Lazar at amd.com>
Sent: Wednesday, November 8, 2023 12:22 PM
To: amd-gfx at lists.freedesktop.org
Cc: Zhang, Hawking <Hawking.Zhang at amd.com>; Deucher, Alexander <Alexander.Deucher at amd.com>; Wang, Yang(Kevin) <KevinYang.Wang at amd.com>
Subject: [PATCH v2 2/4] drm/amd/pm: Add support to fetch pm metrics sample

Add API support to fetch a snapshot of power management metrics from PMFW.

Signed-off-by: Lijo Lazar <lijo.lazar at amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang at amd.com>
---
v2:
        Return EOPNOTSUPP if callback not implemented (KevinYang)

 drivers/gpu/drm/amd/include/kgd_pp_interface.h |  1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c            | 17 +++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h        | 12 ++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c      | 15 +++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h  | 10 ++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h   |  3 ++-
 6 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index f9c438d16c56..6a1d31e8fdd1 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -431,6 +431,7 @@ struct amd_pm_funcs {
        int (*set_df_cstate)(void *handle, enum pp_df_cstate state);
        int (*set_xgmi_pstate)(void *handle, uint32_t pstate);
        ssize_t (*get_gpu_metrics)(void *handle, void **table);
+       ssize_t (*get_pm_metrics)(void *handle, void *pmmetrics, size_t size);
        int (*set_watermarks_for_clock_ranges)(void *handle,
                                               struct pp_smu_wm_range_sets *ranges);
        int (*display_disable_memory_clock_switch)(void *handle, diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 1ae3b81548fa..4717884a2bc4 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -1299,6 +1299,23 @@ int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table)
        return ret;
 }

+ssize_t amdgpu_dpm_get_pm_metrics(struct amdgpu_device *adev, void *pm_metrics,
+                                 size_t size)
+{
+       const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+       int ret = 0;
+
+       if (!pp_funcs->get_pm_metrics)
+               return -EOPNOTSUPP;
+
+       mutex_lock(&adev->pm.mutex);
+       ret = pp_funcs->get_pm_metrics(adev->powerplay.pp_handle, pm_metrics,
+                                      size);
+       mutex_unlock(&adev->pm.mutex);
+
+       return ret;
+}
+
 int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
                                    uint32_t *fan_mode)
 {
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index feccd2a7120d..9b3fef5474b1 100644
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
@@ -511,6 +511,18 @@ int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,  int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
                                      long *input, uint32_t size);
 int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table);
+
+/**
+ * @get_pm_metrics: Get one snapshot of power management metrics from
+PMFW. The
+ * sample is copied to pm_metrics buffer. It's expected to be allocated
+by the
+ * caller and size of the allocated buffer is passed. Max size expected
+for a
+ * metrics sample is 4096 bytes.
+ *
+ * Return: Actual size of the metrics sample  */ ssize_t
+amdgpu_dpm_get_pm_metrics(struct amdgpu_device *adev, void *pm_metrics,
+                                 size_t size);
+
 int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
                                    uint32_t *fan_mode);
 int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 37c2605f9b35..930e7e3532ad 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -3189,6 +3189,20 @@ static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table)
        return smu->ppt_funcs->get_gpu_metrics(smu, table);  }

+static ssize_t smu_sys_get_pm_metrics(void *handle, void *pm_metrics,
+                                     size_t size)
+{
+       struct smu_context *smu = handle;
+
+       if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
+               return -EOPNOTSUPP;
+
+       if (!smu->ppt_funcs->get_pm_metrics)
+               return -EOPNOTSUPP;
+
+       return smu->ppt_funcs->get_pm_metrics(smu, pm_metrics, size); }
+
 static int smu_enable_mgpu_fan_boost(void *handle)  {
        struct smu_context *smu = handle;
@@ -3330,6 +3344,7 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
        .set_df_cstate                    = smu_set_df_cstate,
        .set_xgmi_pstate                  = smu_set_xgmi_pstate,
        .get_gpu_metrics                  = smu_sys_get_gpu_metrics,
+       .get_pm_metrics                   = smu_sys_get_pm_metrics,
        .set_watermarks_for_clock_ranges     = smu_set_watermarks_for_clock_ranges,
        .display_disable_memory_clock_switch = smu_display_disable_memory_clock_switch,
        .get_max_sustainable_clocks_by_dc    = smu_get_max_sustainable_clocks_by_dc,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
index 8def291b18bc..32600ba74bf1 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
@@ -253,6 +253,7 @@ struct smu_table {
        uint64_t mc_address;
        void *cpu_addr;
        struct amdgpu_bo *bo;
+       uint32_t version;
 };

 enum smu_perf_level_designation {
@@ -1252,6 +1253,15 @@ struct pptable_funcs {
         */
        ssize_t (*get_gpu_metrics)(struct smu_context *smu, void **table);

+       /**
+        * @get_pm_metrics: Get one snapshot of power management metrics from
+        * PMFW.
+        *
+        * Return: Size of the metrics sample
+        */
+       ssize_t (*get_pm_metrics)(struct smu_context *smu, void *pm_metrics,
+                                 size_t size);
+
        /**
         * @enable_mgpu_fan_boost: Enable multi-GPU fan boost.
         */
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
index 9dd47d91093e..ea8ea99b7436 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
@@ -259,7 +259,8 @@
        __SMU_DUMMY_MAP(PowerUpUmsch),  \
        __SMU_DUMMY_MAP(PowerDownUmsch),        \
        __SMU_DUMMY_MAP(SetSoftMaxVpe), \
-       __SMU_DUMMY_MAP(SetSoftMinVpe),
+       __SMU_DUMMY_MAP(SetSoftMinVpe), \
+       __SMU_DUMMY_MAP(GetMetricsVersion),

 #undef __SMU_DUMMY_MAP
 #define __SMU_DUMMY_MAP(type)  SMU_MSG_##type
--
2.25.1



More information about the amd-gfx mailing list