drm/amdgpu: add pm metrics structure definition
Subsystems (3)
PATCH v2 1/4 drm/amdgpu: add pm metrics structure definition
From: Alex Deucher <[email protected]>
Define the pm metrics structures to be exposed via sysfs.
--- drivers/gpu/drm/amd/include/kgd_pp_interface.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +15 -0
@@ -1127,4 +1127,19 @@ struct gpu_metrics_v3_0 {/* Metrics table alpha filter time constant [us] */ uint32_t time_filter_alphavalue; }; + +struct amdgpu_pmmetrics_header { +uint16_t structure_size; +uint16_t pad; +uint32_t mp1_ip_discovery_version; +uint32_t pmfw_version; +uint32_t pmmetrics_version; +}; + +struct amdgpu_pm_metrics { +struct amdgpu_pmmetrics_header common_header; + +uint8_t data[]; +}; +#endif
Signature · 1 line
2.25.1
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.
---
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(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -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,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +17 -0
@@ -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) {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +12 -0
@@ -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,
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +15 -0
@@ -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,
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +10 -0
@@ -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. */
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
@@ -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
Signature · 1 line
2.25.1
RE: [PATCH v2 2/4] drm/amd/pm: Add support to fetch pm metrics sample
[AMD Official Use Only - General]
Series is.
Best Regards,
Kevin
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, November 8, 2023 12:22 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Wang, Yang(Kevin) <[email protected]>
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.
---
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(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -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
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +17 -0
@@ -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) {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +14 -0
@@ -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
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +14 -0
@@ -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,
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +10 -0
@@ -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. */
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +2 -1
@@ -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
PATCH v2 3/4 drm/amd/pm: Add pm metrics support to SMU v13.0.6
In reply to Lijo LazarAdd support to fetch PM metrics sample from SMU v13.0.6
--- .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +47 -0
@@ -128,6 +128,7 @@ struct mca_ras_info {#define P2S_TABLE_ID_A 0x50325341#define P2S_TABLE_ID_X 0x50325358 +// clang-format off static const struct cmn2asic_msg_mapping smu_v13_0_6_message_map[SMU_MSG_MAX_COUNT ] = {MSG_MAP (TestMessage, PPSMC_MSG_TestMessage,0 ),MSG_MAP (GetSmuVersion, PPSMC_MSG_GetSmuVersion,1 ),
@@ -136,6 +137,7 @@ static const struct cmn2asic_msg_mapping smu_v13_0_6_message_map[SMU_MSG_MAX_COUMSG_MAP (DisableAllSmuFeatures, PPSMC_MSG_DisableAllSmuFeatures,0 ),MSG_MAP (RequestI2cTransaction, PPSMC_MSG_RequestI2cTransaction,0 ),MSG_MAP (GetMetricsTable, PPSMC_MSG_GetMetricsTable,1 ), +MSG_MAP (GetMetricsVersion, PPSMC_MSG_GetMetricsVersion,1 ),MSG_MAP (GetEnabledSmuFeaturesHigh, PPSMC_MSG_GetEnabledSmuFeaturesHigh,1 ),MSG_MAP (GetEnabledSmuFeaturesLow, PPSMC_MSG_GetEnabledSmuFeaturesLow,1 ), MSG_MAP(SetDriverDramAddrHigh, PPSMC_MSG_SetDriverDramAddrHigh, 1),
@@ -179,6 +181,7 @@ static const struct cmn2asic_msg_mapping smu_v13_0_6_message_map[SMU_MSG_MAX_COU MSG_MAP(SelectPLPDMode, PPSMC_MSG_SelectPLPDMode, 0), }; +// clang-format on static const struct cmn2asic_mapping smu_v13_0_6_clk_map[SMU_CLK_COUNT ] = {CLK_MAP (SOCCLK ,PPCLK_SOCCLK ),CLK_MAP (FCLK ,PPCLK_FCLK ),
@@ -436,6 +439,41 @@ static int smu_v13_0_6_get_metrics_table(struct smu_context *smu,return 0 ; } +static ssize_t smu_v13_0_6_get_pm_metrics (struct smu_context *smu, +void *metrics,size_t max_size) +{ +struct smu_table_context *smu_tbl_ctxt = &smu->smu_table; +uint32_t table_version = smu_tbl_ctxt->tables[SMU_TABLE_SMU_METRICS ].version; +uint32_t table_size = smu_tbl_ctxt->tables[SMU_TABLE_SMU_METRICS ].size; +struct amdgpu_pm_metrics *pm_metrics = metrics; +uint32_t pmfw_version; +int ret; + +if (!pm_metrics || !max_size) +return -EINVAL ; + +if (max_size < (table_size +sizeof (pm_metrics->common_header))) +return -EOVERFLOW ; + +/* Don't use cached metrics data */ + ret =smu_v13_0_6_get_metrics_table (smu, pm_metrics->data, true); +if (ret) +return ret; + +smu_cmn_get_smc_version (smu,NULL , &pmfw_version); + +memset (&pm_metrics->common_header,0 , +sizeof (pm_metrics->common_header)); + pm_metrics->common_header.mp1_ip_discovery_version = +IP_VERSION (13 ,0 ,6 ); + pm_metrics->common_header.pmfw_version = pmfw_version; + pm_metrics->common_header.pmmetrics_version = table_version; + pm_metrics->common_header.structure_size = +sizeof (pm_metrics->common_header) + table_size; + +return pm_metrics->common_header.structure_size; +} +static int smu_v13_0_6_setup_driver_pptable (struct smu_context *smu) {struct smu_table_context *smu_table = &smu->smu_table;
@@ -443,6 +481,7 @@ static int smu_v13_0_6_setup_driver_pptable(struct smu_context *smu)struct PPTable_t *pptable = (struct PPTable_t *)smu_table->driver_pptable;int ret, i, retry =100 ; +uint32_t table_version;/* Store one-time values in driver PPTable */ if (!pptable->Init) {
@@ -461,6 +500,13 @@ static int smu_v13_0_6_setup_driver_pptable(struct smu_context *smu)if (!retry)return -ETIME ; + ret =smu_cmn_send_smc_msg (smu, SMU_MSG_GetMetricsVersion, + &table_version); +if (ret) +return ret; + smu_table->tables[SMU_TABLE_SMU_METRICS ].version = + table_version; + pptable->MaxSocketPowerLimit =SMUQ10_ROUND (metrics->MaxSocketPowerLimit); pptable->MaxGfxclkFrequency =
@@ -2889,6 +2935,7 @@ static const struct pptable_funcs smu_v13_0_6_ppt_funcs = { .log_thermal_throttling_event = smu_v13_0_6_log_thermal_throttling_event, .get_pp_feature_mask = smu_cmn_get_pp_feature_mask, .get_gpu_metrics = smu_v13_0_6_get_gpu_metrics, + .get_pm_metrics = smu_v13_0_6_get_pm_metrics, .get_thermal_temperature_range = smu_v13_0_6_get_thermal_temperature_range, .mode1_reset_is_support = smu_v13_0_6_is_mode1_reset_supported, .mode2_reset_is_support = smu_v13_0_6_is_mode2_reset_supported,
Signature · 1 line
2.25.1
PATCH v2 4/4 drm/amd/pm: Add sysfs attribute to get pm metrics
In reply to Lijo LazarAdd sysfs attribute to read power management metrics. A snapshot is captured to the buffer when the attribute is read.
--- drivers/gpu/drm/amd/pm/amdgpu_pm.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +40 -0
@@ -1798,6 +1798,44 @@ static ssize_t amdgpu_set_apu_thermal_cap(struct device *dev,return count; } +static int amdgpu_pm_metrics_attr_update (struct amdgpu_device *adev, +struct amdgpu_device_attr *attr, +uint32_t mask, +enum amdgpu_device_attr_states *states) +{ +if (amdgpu_dpm_get_pm_metrics (adev,NULL ,0 ) == -EOPNOTSUPP ) + *states =ATTR_STATE_UNSUPPORTED ; + +return 0 ; +} + +static ssize_t amdgpu_get_pm_metrics (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev =drm_to_adev (ddev); +ssize_t size =0 ; +int ret; + +if (amdgpu_in_reset (adev)) +return -EPERM ; +if (adev->in_suspend && !adev->in_runpm) +return -EPERM ; + + ret =pm_runtime_get_sync (ddev->dev); +if (ret <0 ) { +pm_runtime_put_autosuspend (ddev->dev); +return ret; + } + + size =amdgpu_dpm_get_pm_metrics (adev, buf,PAGE_SIZE ); + +pm_runtime_mark_last_busy (ddev->dev); +pm_runtime_put_autosuspend (ddev->dev); + +return size; +} +/** * DOC: gpu_metrics *
@@ -2095,6 +2133,8 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {AMDGPU_DEVICE_ATTR_RW (smartshift_bias,ATTR_FLAG_BASIC , .attr_update = ss_bias_attr_update),AMDGPU_DEVICE_ATTR_RW (xgmi_plpd_policy,ATTR_FLAG_BASIC ), +AMDGPU_DEVICE_ATTR_RO (pm_metrics,ATTR_FLAG_BASIC , + .attr_update = amdgpu_pm_metrics_attr_update), }; static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
Signature · 1 line
2.25.1