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,
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,
MetricsMember_t member,
uint32_t *value)
......@@ -594,9 +551,9 @@ static int arcturus_get_smu_metrics_data(struct smu_context *smu,
mutex_lock(&smu->metrics_lock);
ret = arcturus_get_metrics_table_locked(smu,
NULL,
false);
ret = smu_cmn_get_metrics_table_locked(smu,
NULL,
false);
if (ret) {
mutex_unlock(&smu->metrics_lock);
return ret;
......@@ -2305,9 +2262,9 @@ static ssize_t arcturus_get_gpu_metrics(struct smu_context *smu,
SmuMetrics_t metrics;
int ret = 0;
ret = arcturus_get_metrics_table(smu,
&metrics,
true);
ret = smu_cmn_get_metrics_table(smu,
&metrics,
true);
if (ret)
return ret;
......
......@@ -504,34 +504,6 @@ static int navi10_tables_init(struct smu_context *smu)
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,
MetricsMember_t member,
uint32_t *value)
......@@ -547,9 +519,9 @@ static int navi10_get_smu_metrics_data(struct smu_context *smu,
mutex_lock(&smu->metrics_lock);
ret = navi10_get_metrics_table_locked(smu,
NULL,
false);
ret = smu_cmn_get_metrics_table_locked(smu,
NULL,
false);
if (ret) {
mutex_unlock(&smu->metrics_lock);
return ret;
......@@ -2526,14 +2498,15 @@ static ssize_t navi10_get_gpu_metrics(struct smu_context *smu,
mutex_lock(&smu->metrics_lock);
ret = navi10_get_metrics_table_locked(smu,
&metrics,
true);
ret = smu_cmn_get_metrics_table_locked(smu,
NULL,
true);
if (ret) {
mutex_unlock(&smu->metrics_lock);
return ret;
}
memcpy(&metrics, smu_table->metrics_table, sizeof(SmuMetrics_t));
if (adev->asic_type == CHIP_NAVI12)
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] =
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)
{
struct smu_table_context *smu_table = &smu->smu_table;
......@@ -381,7 +351,7 @@ static int renoir_print_clk_levels(struct smu_context *smu,
memset(&metrics, 0, sizeof(metrics));
ret = renoir_get_metrics_table(smu, &metrics, false);
ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret)
return ret;
......@@ -527,7 +497,7 @@ static int renoir_get_current_clk_freq_by_table(struct smu_context *smu,
int ret = 0, clk_id = 0;
SmuMetrics_t metrics;
ret = renoir_get_metrics_table(smu, &metrics, false);
ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret)
return ret;
......@@ -610,7 +580,7 @@ static int renoir_get_gpu_temperature(struct smu_context *smu, uint32_t *value)
if (!value)
return -EINVAL;
ret = renoir_get_metrics_table(smu, &metrics, false);
ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret)
return ret;
......@@ -630,7 +600,7 @@ static int renoir_get_current_activity_percent(struct smu_context *smu,
if (!value)
return -EINVAL;
ret = renoir_get_metrics_table(smu, &metrics, false);
ret = smu_cmn_get_metrics_table(smu, &metrics, false);
if (ret)
return ret;
......@@ -1016,7 +986,7 @@ static ssize_t renoir_get_gpu_metrics(struct smu_context *smu,
SmuMetrics_t metrics;
int ret = 0;
ret = renoir_get_metrics_table(smu, &metrics, true);
ret = smu_cmn_get_metrics_table(smu, &metrics, true);
if (ret)
return ret;
......
......@@ -407,49 +407,6 @@ static int sienna_cichlid_tables_init(struct smu_context *smu)
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,
MetricsMember_t member,
uint32_t *value)
......@@ -460,9 +417,9 @@ static int sienna_cichlid_get_smu_metrics_data(struct smu_context *smu,
mutex_lock(&smu->metrics_lock);
ret = sienna_cichlid_get_metrics_table_locked(smu,
NULL,
false);
ret = smu_cmn_get_metrics_table_locked(smu,
NULL,
false);
if (ret) {
mutex_unlock(&smu->metrics_lock);
return ret;
......@@ -2698,9 +2655,9 @@ static ssize_t sienna_cichlid_get_gpu_metrics(struct smu_context *smu,
SmuMetrics_t metrics;
int ret = 0;
ret = sienna_cichlid_get_metrics_table(smu,
&metrics,
true);
ret = smu_cmn_get_metrics_table(smu,
&metrics,
true);
if (ret)
return ret;
......
......@@ -631,3 +631,48 @@ int smu_cmn_write_pptable(struct smu_context *smu)
pptable,
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);
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
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