Commit ed09a629 authored by Alex Deucher's avatar Alex Deucher

drm/amdgpu/smu: add metrics table lock for renoir (v2)

To protect access to the metrics table.

v2: unlock on error

Bug: https://gitlab.freedesktop.org/drm/amd/issues/900Reviewed-by: default avatarKevin Wang <kevin1.wang@amd.com>
Reviewed-by: default avatarEvan Quan <evan.quan@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 885d3865
...@@ -171,17 +171,20 @@ static int renoir_get_metrics_table(struct smu_context *smu, ...@@ -171,17 +171,20 @@ static int renoir_get_metrics_table(struct smu_context *smu,
struct smu_table_context *smu_table= &smu->smu_table; struct smu_table_context *smu_table= &smu->smu_table;
int ret = 0; int ret = 0;
mutex_lock(&smu->metrics_lock);
if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(100))) { if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(100))) {
ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0, ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
(void *)smu_table->metrics_table, false); (void *)smu_table->metrics_table, false);
if (ret) { if (ret) {
pr_info("Failed to export SMU metrics table!\n"); pr_info("Failed to export SMU metrics table!\n");
mutex_unlock(&smu->metrics_lock);
return ret; return ret;
} }
smu_table->metrics_time = jiffies; smu_table->metrics_time = jiffies;
} }
memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t)); memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
mutex_unlock(&smu->metrics_lock);
return ret; return ret;
} }
...@@ -239,8 +242,7 @@ static int renoir_print_clk_levels(struct smu_context *smu, ...@@ -239,8 +242,7 @@ static int renoir_print_clk_levels(struct smu_context *smu,
memset(&metrics, 0, sizeof(metrics)); memset(&metrics, 0, sizeof(metrics));
ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0, ret = renoir_get_metrics_table(smu, &metrics);
(void *)&metrics, false);
if (ret) if (ret)
return ret; return ret;
......
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