Skip to contentSkip to conversation

drm/amd: Return -EBUSY in read_sensor() if RAS interrupt triggered

PATCH In review Mario Limonciello 2 participants 4 messages Dec 15, 2023 – Dec 18, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 drm/amd: Return -EBUSY in read_sensor() if RAS interrupt triggered

Any callers to read_sensor() may get the wrong data if the RAS interrupt has been triggered and no actual sensor read occurred.

Adjust the return code for this condition to be -EBUSY.

---
 drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c    | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c   | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +1 -1
index 4cd43bbec910..1fa4c14326ac 100644
@@ -1059,7 +1059,7 @@ static int arcturus_read_sensor(struct smu_context *smu,
 	int ret = 0;
 
 	if (amdgpu_ras_intr_triggered())
-		return 0;
+		return -EBUSY;
 
 	if (!data || !size)
 		return -EINVAL;
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +1 -1
index f1440869d1ce..e1c561ece319 100644
@@ -1091,7 +1091,7 @@ static int aldebaran_read_sensor(struct smu_context *smu,
 	int ret = 0;
 
 	if (amdgpu_ras_intr_triggered())
-		return 0;
+		return -EBUSY;
 
 	if (!data || !size)
 		return -EINVAL;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +1 -1
index 3998c9b31d07..ac7982132951 100644
@@ -1296,7 +1296,7 @@ static int smu_v13_0_6_read_sensor(struct smu_context *smu,
 	int ret = 0;
 
 	if (amdgpu_ras_intr_triggered())
-		return 0;
+		return -EBUSY;
 
 	if (!data || !size)
 		return -EINVAL;
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 2/3 drm/amd: Make SW CTF handler cope with different read_sensor() results

The SW CTF handler assumes that the read_sensor() call always succeeds and has updated hotspot_tmp, but this may not be guaranteed.

For example some of the read_sensor() callbacks will return 0 when a RAS interrupt is triggered in which case hotspot_tmp won't be updated.

Adjust the logic to catch this circumstance and output a warning.

---
v2->v3:
* Correctly handle fallthrough case
v1->v2:
* Only show Failed to read hotspot temperature when sensor read fails

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 24 ++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +15 -9
index d24fccf28f6a..963cf6e76935 100644
@@ -1165,21 +1165,27 @@ static void smu_swctf_delayed_work_handler(struct work_struct *work)
 	struct smu_temperature_range *range =
 				&smu->thermal_range;
 	struct amdgpu_device *adev = smu->adev;
-	uint32_t hotspot_tmp, size;
+	uint32_t hotspot_tmp = 0, size;
 
 	/*
 	 * If the hotspot temperature is confirmed as below SW CTF setting point
 	 * after the delay enforced, nothing will be done.
 	 * Otherwise, a graceful shutdown will be performed to prevent further damage.
 	 */
-	if (range->software_shutdown_temp &&
-	    smu->ppt_funcs->read_sensor &&
-	    !smu->ppt_funcs->read_sensor(smu,
-					 AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
-					 &hotspot_tmp,
-					 &size) &&
-	    hotspot_tmp / 1000 < range->software_shutdown_temp)
-		return;
+	if (range->software_shutdown_temp && smu->ppt_funcs->read_sensor) {
+		int r = smu->ppt_funcs->read_sensor(smu,
+						    AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
+						    &hotspot_tmp,
+						    &size);
+		switch (r) {
+		case 0:
+			if (hotspot_tmp / 1000 < range->software_shutdown_temp)
+				return;
+			break;
+		default:
+			dev_err(adev->dev, "Failed to read hotspot temperature: %d\n", r);
+		}
+	}
 
 	dev_emerg(adev->dev, "ERROR: GPU over temperature range(SW CTF) detected!\n");
 	dev_emerg(adev->dev, "ERROR: System is going to shutdown due to GPU SW CTF!\n");
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 3/3 drm/amd: Retry delayed work handler if sensor is busy

In reply to Mario Limonciello

The SW CTF delayed work handler triggers a shutdown if a sensor read failed for any reason.

The specific circumstance of a busy sensor should be retried however to ensure that a good value can be returned.

---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +6 -0
index 963cf6e76935..5eb46b6bad43 100644
@@ -1182,6 +1182,12 @@ static void smu_swctf_delayed_work_handler(struct work_struct *work)
 			if (hotspot_tmp / 1000 < range->software_shutdown_temp)
 				return;
 			break;
+		case -EBUSY:
+			dev_warn(adev->dev, "Unable to read hotspot sensor, retrying in %d ms\n",
+				 AMDGPU_SWCTF_EXTRA_DELAY);
+			schedule_delayed_work(&smu->swctf_delayed_work,
+					      msecs_to_jiffies(AMDGPU_SWCTF_EXTRA_DELAY));
+			return;
 		default:
 			dev_err(adev->dev, "Failed to read hotspot temperature: %d\n", r);
 		}
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v3 3/3] drm/amd: Retry delayed work handler if sensor is busy

Quoted 16 lines · Mario Limonciello

The SW CTF delayed work handler triggers a shutdown if a sensor read failed for any reason.

The specific circumstance of a busy sensor should be retried however to ensure that a good value can be returned.

---
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
index 963cf6e76935..5eb46b6bad43 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_swctf_delayed_work_handler(struct work_struct *work) · line 1185

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -1182,6 +1182,12 @@ static void smu_swctf_delayed_work_handler(struct work_struct *work)
  			if (hotspot_tmp / 1000 < range->software_shutdown_temp)
  				return;
  			break;
+		case -EBUSY:

In patch 1, presently -EBUSY is returned for
1) RAS interrupt - A RAS interrupt will eventually result in a reset of
the device. All processes running on the device are going to be suspended before that, so a reschedule here won't be necessary.
2) Only for arcturus, aldebaran and smu v13.0.6 - Aldebaran and SMU
v13.0.6 don't use SW CTF (SW CTF limit is set in aldebaran in such a way that it won't be hit). I don't know about SW CTF usage in arcturus.

Thanks,
Lijo

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
+			dev_warn(adev->dev, "Unable to read hotspot sensor, retrying in %d ms\n",
+				 AMDGPU_SWCTF_EXTRA_DELAY);
+			schedule_delayed_work(&smu->swctf_delayed_work,
+					      msecs_to_jiffies(AMDGPU_SWCTF_EXTRA_DELAY));
+			return;
  		default:
  			dev_err(adev->dev, "Failed to read hotspot temperature: %d\n", r);
  		}