Commit fceafc9b authored by Evan Quan's avatar Evan Quan Committed by Alex Deucher

drm/amd/powerplay: maximum the code sharing around metrics table retrieving

Instead of having one copy in each ASIC.
Signed-off-by: default avatarEvan Quan <evan.quan@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent a9c75edc
...@@ -541,49 +541,6 @@ static int arcturus_freqs_in_same_level(int32_t frequency1, ...@@ -541,49 +541,6 @@ static int arcturus_freqs_in_same_level(int32_t frequency1,
return (abs(frequency1 - frequency2) <= EPSILON); return (abs(frequency1 - frequency2) <= EPSILON);
} }
static int arcturus_get_metrics_table_locked(struct smu_context *smu,
SmuMetrics_t *metrics_table,
bool bypass_cache)
{
struct smu_table_context *smu_table= &smu->smu_table;
int ret = 0;
if (bypass_cache ||
!smu_table->metrics_time ||
time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(1))) {
ret = smu_cmn_update_table(smu,
SMU_TABLE_SMU_METRICS,
0,
smu_table->metrics_table,
false);
if (ret) {
dev_info(smu->adev->dev, "Failed to export SMU metrics table!\n");
return ret;
}
smu_table->metrics_time = jiffies;
}
if (metrics_table)
memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
return 0;
}
static int arcturus_get_metrics_table(struct smu_context *smu,
SmuMetrics_t *metrics_table,
bool bypass_cache)
{
int ret = 0;
mutex_lock(&smu->metrics_lock);
ret = arcturus_get_metrics_table_locked(smu,
metrics_table,
bypass_cache);
mutex_unlock(&smu->metrics_lock);
return ret;
}
static int arcturus_get_smu_metrics_data(struct smu_context *smu, static int arcturus_get_smu_metrics_data(struct smu_context *smu,
MetricsMember_t member, MetricsMember_t member,
uint32_t *value) uint32_t *value)
...@@ -594,7 +551,7 @@ static int arcturus_get_smu_metrics_data(struct smu_context *smu, ...@@ -594,7 +551,7 @@ static int arcturus_get_smu_metrics_data(struct smu_context *smu,
mutex_lock(&smu->metrics_lock); mutex_lock(&smu->metrics_lock);
ret = arcturus_get_metrics_table_locked(smu, ret = smu_cmn_get_metrics_table_locked(smu,
NULL, NULL,
false); false);
if (ret) { if (ret) {
...@@ -2305,7 +2262,7 @@ static ssize_t arcturus_get_gpu_metrics(struct smu_context *smu, ...@@ -2305,7 +2262,7 @@ static ssize_t arcturus_get_gpu_metrics(struct smu_context *smu,
SmuMetrics_t metrics; SmuMetrics_t metrics;
int ret = 0; int ret = 0;
ret = arcturus_get_metrics_table(smu, ret = smu_cmn_get_metrics_table(smu,
&metrics, &metrics,
true); true);
if (ret) if (ret)
......
...@@ -504,34 +504,6 @@ static int navi10_tables_init(struct smu_context *smu) ...@@ -504,34 +504,6 @@ static int navi10_tables_init(struct smu_context *smu)
return -ENOMEM; return -ENOMEM;
} }
static int navi10_get_metrics_table_locked(struct smu_context *smu,
SmuMetrics_t *metrics_table,
bool bypass_cache)
{
struct smu_table_context *smu_table= &smu->smu_table;
int ret = 0;
if (bypass_cache ||
!smu_table->metrics_time ||
time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(1))) {
ret = smu_cmn_update_table(smu,
SMU_TABLE_SMU_METRICS,
0,
smu_table->metrics_table,
false);
if (ret) {
dev_info(smu->adev->dev, "Failed to export SMU metrics table!\n");
return ret;
}
smu_table->metrics_time = jiffies;
}
if (metrics_table)
memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
return 0;
}
static int navi10_get_smu_metrics_data(struct smu_context *smu, static int navi10_get_smu_metrics_data(struct smu_context *smu,
MetricsMember_t member, MetricsMember_t member,
uint32_t *value) uint32_t *value)
...@@ -547,7 +519,7 @@ static int navi10_get_smu_metrics_data(struct smu_context *smu, ...@@ -547,7 +519,7 @@ static int navi10_get_smu_metrics_data(struct smu_context *smu,
mutex_lock(&smu->metrics_lock); mutex_lock(&smu->metrics_lock);
ret = navi10_get_metrics_table_locked(smu, ret = smu_cmn_get_metrics_table_locked(smu,
NULL, NULL,
false); false);
if (ret) { if (ret) {
...@@ -2526,14 +2498,15 @@ static ssize_t navi10_get_gpu_metrics(struct smu_context *smu, ...@@ -2526,14 +2498,15 @@ static ssize_t navi10_get_gpu_metrics(struct smu_context *smu,
mutex_lock(&smu->metrics_lock); mutex_lock(&smu->metrics_lock);
ret = navi10_get_metrics_table_locked(smu, ret = smu_cmn_get_metrics_table_locked(smu,
&metrics, NULL,
true); true);
if (ret) { if (ret) {
mutex_unlock(&smu->metrics_lock); mutex_unlock(&smu->metrics_lock);
return ret; return ret;
} }
memcpy(&metrics, smu_table->metrics_table, sizeof(SmuMetrics_t));
if (adev->asic_type == CHIP_NAVI12) if (adev->asic_type == CHIP_NAVI12)
memcpy(&nv12_metrics, smu_table->metrics_table, sizeof(SmuMetrics_NV12_t)); memcpy(&nv12_metrics, smu_table->metrics_table, sizeof(SmuMetrics_NV12_t));
......
...@@ -128,36 +128,6 @@ static struct cmn2asic_mapping renoir_workload_map[PP_SMC_POWER_PROFILE_COUNT] = ...@@ -128,36 +128,6 @@ static struct cmn2asic_mapping renoir_workload_map[PP_SMC_POWER_PROFILE_COUNT] =
WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM, WORKLOAD_PPLIB_CUSTOM_BIT), WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM, WORKLOAD_PPLIB_CUSTOM_BIT),
}; };
static int renoir_get_metrics_table(struct smu_context *smu,
SmuMetrics_t *metrics_table,
bool bypass_cache)
{
struct smu_table_context *smu_table= &smu->smu_table;
int ret = 0;
mutex_lock(&smu->metrics_lock);
if (bypass_cache ||
!smu_table->metrics_time ||
time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(1))) {
ret = smu_cmn_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
(void *)smu_table->metrics_table, false);
if (ret) {
dev_info(smu->adev->dev, "Failed to export SMU metrics table!\n");
mutex_unlock(&smu->metrics_lock);
return ret;
}
smu_table->metrics_time = jiffies;
}
if (metrics_table)
memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
mutex_unlock(&smu->metrics_lock);
return ret;
}
static int renoir_init_smc_tables(struct smu_context *smu) static int renoir_init_smc_tables(struct smu_context *smu)
{ {
struct smu_table_context *smu_table = &smu->smu_table; struct smu_table_context *smu_table = &smu->smu_table;
...@@ -381,7 +351,7 @@ static int renoir_print_clk_levels(struct smu_context *smu, ...@@ -381,7 +351,7 @@ static int renoir_print_clk_levels(struct smu_context *smu,
memset(&metrics, 0, sizeof(metrics)); memset(&metrics, 0, sizeof(metrics));
ret = renoir_get_metrics_table(smu, &metrics, false); ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret) if (ret)
return ret; return ret;
...@@ -527,7 +497,7 @@ static int renoir_get_current_clk_freq_by_table(struct smu_context *smu, ...@@ -527,7 +497,7 @@ static int renoir_get_current_clk_freq_by_table(struct smu_context *smu,
int ret = 0, clk_id = 0; int ret = 0, clk_id = 0;
SmuMetrics_t metrics; SmuMetrics_t metrics;
ret = renoir_get_metrics_table(smu, &metrics, false); ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret) if (ret)
return ret; return ret;
...@@ -610,7 +580,7 @@ static int renoir_get_gpu_temperature(struct smu_context *smu, uint32_t *value) ...@@ -610,7 +580,7 @@ static int renoir_get_gpu_temperature(struct smu_context *smu, uint32_t *value)
if (!value) if (!value)
return -EINVAL; return -EINVAL;
ret = renoir_get_metrics_table(smu, &metrics, false); ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret) if (ret)
return ret; return ret;
...@@ -630,7 +600,7 @@ static int renoir_get_current_activity_percent(struct smu_context *smu, ...@@ -630,7 +600,7 @@ static int renoir_get_current_activity_percent(struct smu_context *smu,
if (!value) if (!value)
return -EINVAL; return -EINVAL;
ret = renoir_get_metrics_table(smu, &metrics, false); ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret) if (ret)
return ret; return ret;
...@@ -1016,7 +986,7 @@ static ssize_t renoir_get_gpu_metrics(struct smu_context *smu, ...@@ -1016,7 +986,7 @@ static ssize_t renoir_get_gpu_metrics(struct smu_context *smu,
SmuMetrics_t metrics; SmuMetrics_t metrics;
int ret = 0; int ret = 0;
ret = renoir_get_metrics_table(smu, &metrics, true); ret = smu_cmn_get_metrics_table(smu, &metrics, true);
if (ret) if (ret)
return ret; return ret;
......
...@@ -407,49 +407,6 @@ static int sienna_cichlid_tables_init(struct smu_context *smu) ...@@ -407,49 +407,6 @@ static int sienna_cichlid_tables_init(struct smu_context *smu)
return -ENOMEM; return -ENOMEM;
} }
static int sienna_cichlid_get_metrics_table_locked(struct smu_context *smu,
SmuMetrics_t *metrics_table,
bool bypass_cache)
{
struct smu_table_context *smu_table= &smu->smu_table;
int ret = 0;
if (bypass_cache ||
!smu_table->metrics_time ||
time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(1))) {
ret = smu_cmn_update_table(smu,
SMU_TABLE_SMU_METRICS,
0,
smu_table->metrics_table,
false);
if (ret) {
dev_info(smu->adev->dev, "Failed to export SMU metrics table!\n");
return ret;
}
smu_table->metrics_time = jiffies;
}
if (metrics_table)
memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
return 0;
}
static int sienna_cichlid_get_metrics_table(struct smu_context *smu,
SmuMetrics_t *metrics_table,
bool bypass_cache)
{
int ret = 0;
mutex_lock(&smu->metrics_lock);
ret = sienna_cichlid_get_metrics_table_locked(smu,
metrics_table,
bypass_cache);
mutex_unlock(&smu->metrics_lock);
return ret;
}
static int sienna_cichlid_get_smu_metrics_data(struct smu_context *smu, static int sienna_cichlid_get_smu_metrics_data(struct smu_context *smu,
MetricsMember_t member, MetricsMember_t member,
uint32_t *value) uint32_t *value)
...@@ -460,7 +417,7 @@ static int sienna_cichlid_get_smu_metrics_data(struct smu_context *smu, ...@@ -460,7 +417,7 @@ static int sienna_cichlid_get_smu_metrics_data(struct smu_context *smu,
mutex_lock(&smu->metrics_lock); mutex_lock(&smu->metrics_lock);
ret = sienna_cichlid_get_metrics_table_locked(smu, ret = smu_cmn_get_metrics_table_locked(smu,
NULL, NULL,
false); false);
if (ret) { if (ret) {
...@@ -2698,7 +2655,7 @@ static ssize_t sienna_cichlid_get_gpu_metrics(struct smu_context *smu, ...@@ -2698,7 +2655,7 @@ static ssize_t sienna_cichlid_get_gpu_metrics(struct smu_context *smu,
SmuMetrics_t metrics; SmuMetrics_t metrics;
int ret = 0; int ret = 0;
ret = sienna_cichlid_get_metrics_table(smu, ret = smu_cmn_get_metrics_table(smu,
&metrics, &metrics,
true); true);
if (ret) if (ret)
......
...@@ -631,3 +631,48 @@ int smu_cmn_write_pptable(struct smu_context *smu) ...@@ -631,3 +631,48 @@ int smu_cmn_write_pptable(struct smu_context *smu)
pptable, pptable,
true); true);
} }
int smu_cmn_get_metrics_table_locked(struct smu_context *smu,
void *metrics_table,
bool bypass_cache)
{
struct smu_table_context *smu_table= &smu->smu_table;
uint32_t table_size =
smu_table->tables[SMU_TABLE_SMU_METRICS].size;
int ret = 0;
if (bypass_cache ||
!smu_table->metrics_time ||
time_after(jiffies, smu_table->metrics_time + msecs_to_jiffies(1))) {
ret = smu_cmn_update_table(smu,
SMU_TABLE_SMU_METRICS,
0,
smu_table->metrics_table,
false);
if (ret) {
dev_info(smu->adev->dev, "Failed to export SMU metrics table!\n");
return ret;
}
smu_table->metrics_time = jiffies;
}
if (metrics_table)
memcpy(metrics_table, smu_table->metrics_table, table_size);
return 0;
}
int smu_cmn_get_metrics_table(struct smu_context *smu,
void *metrics_table,
bool bypass_cache)
{
int ret = 0;
mutex_lock(&smu->metrics_lock);
ret = smu_cmn_get_metrics_table_locked(smu,
metrics_table,
bypass_cache);
mutex_unlock(&smu->metrics_lock);
return ret;
}
...@@ -79,5 +79,13 @@ int smu_cmn_write_watermarks_table(struct smu_context *smu); ...@@ -79,5 +79,13 @@ int smu_cmn_write_watermarks_table(struct smu_context *smu);
int smu_cmn_write_pptable(struct smu_context *smu); int smu_cmn_write_pptable(struct smu_context *smu);
int smu_cmn_get_metrics_table_locked(struct smu_context *smu,
void *metrics_table,
bool bypass_cache);
int smu_cmn_get_metrics_table(struct smu_context *smu,
void *metrics_table,
bool bypass_cache);
#endif #endif
#endif #endif
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