Skip to contentSkip to conversation

drm/amdgpu/smu: add metrics table lock

PATCH Superseded Alex Deucher 4 participants 8 messages Dec 17, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 drm/amdgpu/smu: add metrics table lock

This table is used for lots of things, add it's own lock.

---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 1 +
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +1 -0
index 6dddd7818558..6177a6664737 100644
@@ -872,6 +872,7 @@ static int smu_sw_init(void *handle)
 	smu->smu_baco.platform_support = false;
 
 	mutex_init(&smu->sensor_lock);
+	mutex_init(&smu->metrics_lock);
 
 	smu->watermarks_bitmap = 0;
 	smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +1 -0
index ca3fdc6777cf..503099f254c1 100644
@@ -350,6 +350,7 @@ struct smu_context
 	const struct pptable_funcs	*ppt_funcs;
 	struct mutex			mutex;
 	struct mutex			sensor_lock;
+	struct mutex			metrics_lock;
 	uint64_t pool_size;
 
 	struct smu_table_context	smu_table;
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

PATCH 2/5 drm/amdgpu/smu: add metrics table lock for arcturus

To protect access to the metrics table.

---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +2 -0
index 17eeb546c550..bd5bb7040638 100644
@@ -867,6 +867,7 @@ static int arcturus_get_metrics_table(struct smu_context *smu,
 	struct smu_table_context *smu_table= &smu->smu_table;
 	int ret = 0;
 
+	mutex_lock(&smu->metrics_lock);
 	if (!smu_table->metrics_time ||
 	     time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
 		ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
@@ -879,6 +880,7 @@ static int arcturus_get_metrics_table(struct smu_context *smu,
 	}
 
 	memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+	mutex_unlock(&smu->metrics_lock);
 
 	return ret;
 }
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#2 lore raw

PATCH 3/5 drm/amdgpu/smu: add metrics table lock for navi

In reply to Alex Deucher

To protect access to the metrics table.

---
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +2 -0
index 15403b7979d6..102fddda925b 100644
@@ -564,6 +564,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
 	struct smu_table_context *smu_table= &smu->smu_table;
 	int ret = 0;
 
+	mutex_lock(&smu->metrics_lock);
 	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,
 				(void *)smu_table->metrics_table, false);
@@ -575,6 +576,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
 	}
 
 	memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+	mutex_unlock(&smu->metrics_lock);
 
 	return ret;
 }
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw

Re: [PATCH 3/5] drm/amdgpu/smu: add metrics table lock for navi

Hi Alex,

Isn't this patch missing something like this:

    pr_info("Failed to export SMU metrics table!\n");
+   mutex_unlock(&smu->metrics_lock);
    return ret;

to release the lock in case of error?

Regards,
Pierre-Eric

Quoted 22 lines · Alex Deucher

To protect access to the metrics table.

---
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
index 15403b7979d6..102fddda925b 100644
@@ -564,6 +564,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
 	struct smu_table_context *smu_table= &smu->smu_table;
 	int ret = 0;
 
+	mutex_lock(&smu->metrics_lock);
 	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,
 				(void *)smu_table->metrics_table, false);

drivers/gpu/drm/amd/powerplay/navi10_ppt.c static int navi10_get_metrics_table(struct smu_context *smu, · line 582

Quoted 7 lines
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
@@ -575,6 +576,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
 	}
 
 	memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+	mutex_unlock(&smu->metrics_lock);
 
 	return ret;
 }

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw

Re: [PATCH 3/5] drm/amdgpu/smu: add metrics table lock for navi

[AMD Official Use Only - Internal Distribution Only]

yeah, they need some fixes.

Alex
________________________________
From: Pelloux-prayer, Pierre-eric <[email protected]>
Sent: Tuesday, December 17, 2019 1:56 PM
To: Alex Deucher <[email protected]>; [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 3/5] drm/amdgpu/smu: add metrics table lock for navi

Hi Alex,

Isn't this patch missing something like this:

    pr_info("Failed to export SMU metrics table!\n");
+   mutex_unlock(&smu->metrics_lock);
    return ret;

to release the lock in case of error?

Regards,
Pierre-Eric

Quoted 22 lines · Alex Deucher

To protect access to the metrics table.

---
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
index 15403b7979d6..102fddda925b 100644
@@ -564,6 +564,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
       struct smu_table_context *smu_table= &smu->smu_table;
       int ret = 0;
 
+     mutex_lock(&smu->metrics_lock);
       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,
                               (void *)smu_table->metrics_table, false);

drivers/gpu/drm/amd/powerplay/navi10_ppt.c static int navi10_get_metrics_table(struct smu_context *smu, · line 582

Quoted 7 lines
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
@@ -575,6 +576,7 @@ static int navi10_get_metrics_table(struct smu_context *smu,
       }
 
       memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+     mutex_unlock(&smu->metrics_lock);
 
       return ret;
 }

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

PATCH 4/5 drm/amdgpu/smu: add metrics table lock for renoir

In reply to Alex Deucher

To protect access to the metrics table.

---
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +3 -2
index 81520b0fca68..8e723022be3e 100644
@@ -171,6 +171,7 @@ static int renoir_get_metrics_table(struct smu_context *smu,
 	struct smu_table_context *smu_table= &smu->smu_table;
 	int ret = 0;
 
+	mutex_lock(&smu->metrics_lock);
 	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,
 				(void *)smu_table->metrics_table, false);
@@ -182,6 +183,7 @@ static int renoir_get_metrics_table(struct smu_context *smu,
 	}
 
 	memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+	mutex_unlock(&smu->metrics_lock);
 
 	return ret;
 }
@@ -239,8 +241,7 @@ static int renoir_print_clk_levels(struct smu_context *smu,
 
 	memset(&metrics, 0, sizeof(metrics));
 
-	ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
-			       (void *)&metrics, false);
+	ret = renoir_get_metrics_table(smu, &metrics);
 	if (ret)
 		return ret;
 
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#6 lore raw

PATCH 5/5 drm/amdgpu/smu: add metrics table lock for vega20

In reply to Alex Deucher

To protect access to the metrics table.

---
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +2 -0
index 12bcc3e3ba99..740cf62e74f3 100644
@@ -1678,6 +1678,7 @@ static int vega20_get_metrics_table(struct smu_context *smu,
 	struct smu_table_context *smu_table= &smu->smu_table;
 	int ret = 0;
 
+	mutex_lock(&smu->metrics_lock);
 	if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
 		ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
 				(void *)smu_table->metrics_table, false);
@@ -1689,6 +1690,7 @@ static int vega20_get_metrics_table(struct smu_context *smu,
 	}
 
 	memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+	mutex_unlock(&smu->metrics_lock);
 
 	return ret;
 }
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/5
#7 lore raw
In reply to Alex Deucher

[AMD Official Use Only - Internal Distribution Only]

the swSMU should be add metrics lock to protect the maintenance data of the metrics table.

The series patches are

Best Regards,
Kevin
________________________________
From: amd-gfx <[email protected]> on behalf of Alex Deucher <[email protected]>
Sent: Tuesday, December 17, 2019 10:55 PM
To: [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 1/5] drm/amdgpu/smu: add metrics table lock

This table is used for lots of things, add it's own lock.

---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 1 +
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +1 -0
index 6dddd7818558..6177a6664737 100644
@@ -872,6 +872,7 @@ static int smu_sw_init(void *handle)
         smu->smu_baco.platform_support = false;
 
         mutex_init(&smu->sensor_lock);
+       mutex_init(&smu->metrics_lock);
 
         smu->watermarks_bitmap = 0;
         smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +1 -0
index ca3fdc6777cf..503099f254c1 100644
@@ -350,6 +350,7 @@ struct smu_context
         const struct pptable_funcs      *ppt_funcs;
         struct mutex                    mutex;
         struct mutex                    sensor_lock;
+       struct mutex                    metrics_lock;
         uint64_t pool_size;
 
         struct smu_table_context        smu_table;

--
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CKevin1.Wang%40amd.com%7C4ea0cd2cfad44f285ffb08d7830121d7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637121913347070548&amp;sdata=EwWmrrJWWxG14kfkuXeM4YPA9odQI2gWyq0iT4pOXCQ%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx