Instead of having one copy in each ASIC.
Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
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)
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;
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;
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)
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;
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));
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;
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;
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;
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;
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;
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;
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)
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;
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;
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;
+}
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