Commit 95868b85 authored by Evan Quan's avatar Evan Quan Committed by Alex Deucher

drm/amd/powerplay: add Renoir support for gpu metrics export(V2)

Add Renoir gpu metrics export interface.

V2: use memcpy to make code more compact
Signed-off-by: default avatarEvan Quan <evan.quan@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Acked-by: default avatarNirmoy Das <nirmoy.das@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 8ca78a0a
...@@ -60,5 +60,7 @@ int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_ ...@@ -60,5 +60,7 @@ int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_
int smu_v12_0_set_driver_table_location(struct smu_context *smu); int smu_v12_0_set_driver_table_location(struct smu_context *smu);
void smu_v12_0_init_gpu_metrics_v2_0(struct gpu_metrics_v2_0 *gpu_metrics);
#endif #endif
#endif #endif
...@@ -166,18 +166,32 @@ static int renoir_init_smc_tables(struct smu_context *smu) ...@@ -166,18 +166,32 @@ static int renoir_init_smc_tables(struct smu_context *smu)
smu_table->clocks_table = kzalloc(sizeof(DpmClocks_t), GFP_KERNEL); smu_table->clocks_table = kzalloc(sizeof(DpmClocks_t), GFP_KERNEL);
if (!smu_table->clocks_table) if (!smu_table->clocks_table)
return -ENOMEM; goto err0_out;
smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL); smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
if (!smu_table->metrics_table) if (!smu_table->metrics_table)
return -ENOMEM; goto err1_out;
smu_table->metrics_time = 0; smu_table->metrics_time = 0;
smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL); smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
if (!smu_table->watermarks_table) if (!smu_table->watermarks_table)
return -ENOMEM; goto err2_out;
smu_table->gpu_metrics_table_size = sizeof(struct gpu_metrics_v2_0);
smu_table->gpu_metrics_table = kzalloc(smu_table->gpu_metrics_table_size, GFP_KERNEL);
if (!smu_table->gpu_metrics_table)
goto err3_out;
return 0; return 0;
err3_out:
kfree(smu_table->watermarks_table);
err2_out:
kfree(smu_table->metrics_table);
err1_out:
kfree(smu_table->clocks_table);
err0_out:
return -ENOMEM;
} }
/** /**
...@@ -995,6 +1009,65 @@ static bool renoir_is_dpm_running(struct smu_context *smu) ...@@ -995,6 +1009,65 @@ static bool renoir_is_dpm_running(struct smu_context *smu)
} }
static ssize_t renoir_get_gpu_metrics(struct smu_context *smu,
void **table)
{
struct smu_table_context *smu_table = &smu->smu_table;
struct gpu_metrics_v2_0 *gpu_metrics =
(struct gpu_metrics_v2_0 *)smu_table->gpu_metrics_table;
SmuMetrics_t metrics;
int ret = 0;
ret = renoir_get_metrics_table(smu, &metrics);
if (ret)
return ret;
smu_v12_0_init_gpu_metrics_v2_0(gpu_metrics);
gpu_metrics->temperature_gfx = metrics.GfxTemperature;
gpu_metrics->temperature_soc = metrics.SocTemperature;
memcpy(&gpu_metrics->temperature_core[0],
&metrics.CoreTemperature[0],
sizeof(uint16_t) * 8);
gpu_metrics->temperature_l3[0] = metrics.L3Temperature[0];
gpu_metrics->temperature_l3[1] = metrics.L3Temperature[1];
gpu_metrics->average_gfx_activity = metrics.AverageGfxActivity;
gpu_metrics->average_mm_activity = metrics.AverageUvdActivity;
gpu_metrics->average_socket_power = metrics.CurrentSocketPower;
gpu_metrics->average_cpu_power = metrics.Power[0];
gpu_metrics->average_soc_power = metrics.Power[1];
memcpy(&gpu_metrics->average_core_power[0],
&metrics.CorePower[0],
sizeof(uint16_t) * 8);
gpu_metrics->average_gfxclk_frequency = metrics.AverageGfxclkFrequency;
gpu_metrics->average_socclk_frequency = metrics.AverageSocclkFrequency;
gpu_metrics->average_fclk_frequency = metrics.AverageFclkFrequency;
gpu_metrics->average_vclk_frequency = metrics.AverageVclkFrequency;
gpu_metrics->current_gfxclk = metrics.ClockFrequency[CLOCK_GFXCLK];
gpu_metrics->current_socclk = metrics.ClockFrequency[CLOCK_SOCCLK];
gpu_metrics->current_uclk = metrics.ClockFrequency[CLOCK_UMCCLK];
gpu_metrics->current_fclk = metrics.ClockFrequency[CLOCK_FCLK];
gpu_metrics->current_vclk = metrics.ClockFrequency[CLOCK_VCLK];
gpu_metrics->current_dclk = metrics.ClockFrequency[CLOCK_DCLK];
memcpy(&gpu_metrics->current_coreclk[0],
&metrics.CoreFrequency[0],
sizeof(uint16_t) * 8);
gpu_metrics->current_l3clk[0] = metrics.L3Frequency[0];
gpu_metrics->current_l3clk[1] = metrics.L3Frequency[1];
gpu_metrics->throttle_status = metrics.ThrottlerStatus;
gpu_metrics->fan_pwm = metrics.FanPwm;
*table = (void *)gpu_metrics;
return sizeof(struct gpu_metrics_v2_0);
}
static const struct pptable_funcs renoir_ppt_funcs = { static const struct pptable_funcs renoir_ppt_funcs = {
.set_power_state = NULL, .set_power_state = NULL,
.print_clk_levels = renoir_print_clk_levels, .print_clk_levels = renoir_print_clk_levels,
...@@ -1029,6 +1102,7 @@ static const struct pptable_funcs renoir_ppt_funcs = { ...@@ -1029,6 +1102,7 @@ static const struct pptable_funcs renoir_ppt_funcs = {
.is_dpm_running = renoir_is_dpm_running, .is_dpm_running = renoir_is_dpm_running,
.get_pp_feature_mask = smu_cmn_get_pp_feature_mask, .get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
.set_pp_feature_mask = smu_cmn_set_pp_feature_mask, .set_pp_feature_mask = smu_cmn_set_pp_feature_mask,
.get_gpu_metrics = renoir_get_gpu_metrics,
}; };
void renoir_set_ppt_funcs(struct smu_context *smu) void renoir_set_ppt_funcs(struct smu_context *smu)
......
...@@ -274,3 +274,15 @@ int smu_v12_0_set_driver_table_location(struct smu_context *smu) ...@@ -274,3 +274,15 @@ int smu_v12_0_set_driver_table_location(struct smu_context *smu)
return ret; return ret;
} }
void smu_v12_0_init_gpu_metrics_v2_0(struct gpu_metrics_v2_0 *gpu_metrics)
{
memset(gpu_metrics, 0xFF, sizeof(struct gpu_metrics_v2_0));
gpu_metrics->common_header.structure_size =
sizeof(struct gpu_metrics_v2_0);
gpu_metrics->common_header.format_revision = 2;
gpu_metrics->common_header.content_revision = 0;
gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment