[PATCH 1/1] SWDEV-306029 - add new sysfs interface for retrieving gpu metrics(V2)

Lazar, Lijo lijo.lazar at amd.com
Fri Nov 12 08:05:00 UTC 2021



On 11/12/2021 12:35 AM, Surbhi Kakarya wrote:
> A new interface for UMD to retrieve gpu metrics data.
> 
> Change-Id: Ieb8d56740147cf60a869a7fa0ef43d05cfbf802f
> Signed-off-by: Surbhi Kakarya <Surbhi.Kakarya at amd.com>

This is not the right way, looks like you need to port this to your tree 
- https://lore.kernel.org/all/20211019214934.4088-1-Vignesh.Chander@amd.com/

Thanks,
Lijo

> ---
>   drivers/gpu/drm/amd/pm/amdgpu_pm.c              | 17 +++++++++++++++--
>   drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h         |  2 +-
>   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c       |  4 +---
>   .../drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 10 ++++++++++
>   4 files changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> index 53bb2565cc61..2e5d2059556a 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> @@ -1799,9 +1799,11 @@ static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
>   		return ret;
>   	}
>   
> -	if (adev->powerplay.pp_funcs->get_gpu_metrics)
> +	if (is_support_sw_smu(adev)){
> +		size = smu_sys_get_gpu_metrics(&adev->smu, &gpu_metrics);
> +	} else if (adev->powerplay.pp_funcs->get_gpu_metrics) {
>   		size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
> -
> +	}
>   	if (size <= 0)
>   		goto out;
>   
> @@ -1817,6 +1819,8 @@ static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
>   	return size;
>   }
>   
> +static DEVICE_ATTR(gpu_metrics, S_IRUGO, amdgpu_get_gpu_metrics, NULL);
> +
>   /**
>    * DOC: smartshift_apu_power
>    *
> @@ -3527,6 +3531,13 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
>   		return ret;
>   	}
>   
> +	if (adev->asic_type >= CHIP_VEGA12) {
> +		ret = device_create_file(adev->dev, &dev_attr_gpu_metrics);
> +		if (ret) {
> +			DRM_ERROR("failed to create device file gpu_metrics\n");
> +			return ret;
> +		}
> +	}
>   	switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
>   	case SRIOV_VF_MODE_ONE_VF:
>   		mask = ATTR_FLAG_ONEVF;
> @@ -3562,6 +3573,8 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
>   		hwmon_device_unregister(adev->pm.int_hwmon_dev);
>   
>   	amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
> +	if (adev->asic_type >= CHIP_VEGA12)
> +		device_remove_file(adev->dev, &dev_attr_gpu_metrics);
>   }
>   
>   /*
> diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
> index 73fca113f3d9..cbb22d0c5568 100644
> --- a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
> +++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
> @@ -1339,6 +1339,6 @@ int smu_set_light_sbr(struct smu_context *smu, bool enable);
>   
>   int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
>   		       uint64_t event_arg);
> -
> +ssize_t smu_sys_get_gpu_metrics(struct smu_context *smu, void **table);
>   #endif
>   #endif
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
> index b4ea8b233240..6a3424d0a014 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
> @@ -2919,9 +2919,8 @@ static int smu_get_dpm_clock_table(void *handle,
>   	return ret;
>   }
>   
> -static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table)
> +ssize_t smu_sys_get_gpu_metrics(struct smu_context *smu, void **table)
>   {
> -	struct smu_context *smu = handle;
>   	ssize_t size;
>   
>   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
> @@ -3049,7 +3048,6 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
>   	.asic_reset_mode_2                = smu_mode2_reset,
>   	.set_df_cstate                    = smu_set_df_cstate,
>   	.set_xgmi_pstate                  = smu_set_xgmi_pstate,
> -	.get_gpu_metrics                  = smu_sys_get_gpu_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/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> index e0632530e9bf..cc5d9768c33f 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> @@ -3672,6 +3672,16 @@ static ssize_t sienna_cichlid_get_gpu_metrics(struct smu_context *smu,
>   	gpu_metrics->average_socket_power = metrics->AverageSocketPower;
>   	gpu_metrics->energy_accumulator = metrics->EnergyAccumulator;
>   
> +	if (metrics->CurrGfxVoltageOffset)
> +		gpu_metrics->voltage_gfx =
> +			(155000 - 625 * metrics->CurrGfxVoltageOffset) / 100;
> +	if (metrics->CurrMemVidOffset)
> +		gpu_metrics->voltage_mem =
> +			(155000 - 625 * metrics->CurrMemVidOffset) / 100;
> +	if (metrics->CurrSocVoltageOffset)
> +		gpu_metrics->voltage_soc =
> +			(155000 - 625 * metrics->CurrSocVoltageOffset) / 100;
> +
>   	if (metrics->AverageGfxActivity <= SMU_11_0_7_GFX_BUSY_THRESHOLD)
>   		gpu_metrics->average_gfxclk_frequency = metrics->AverageGfxclkFrequencyPostDs;
>   	else
> 


More information about the amd-gfx mailing list