Skip to contentSkip to conversation

drm/amdgpu: Don't query CE and UE errors

PATCH In review Luben Tuikov 2 participants 5 messages May 26, 2021

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

PATCH 1/3 drm/amdgpu: Don't query CE and UE errors

On QUERY2 IOCTL don't query counts of correctable
and uncorrectable errors, since when RAS is
enabled and supported on Vega20 server boards,
this takes insurmountably long time, in O(n^3),
which slows the system down to the point of it
being unusable when we have GUI up.

Fixes ae363a212b14 ("drm/amdgpu: Add a new flag to AMDGPU_CTX_OP_QUERY_STATE2")
Cc Alexander Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -16
index fc83445fbc40..bb0cfe871aba 100644
@@ -337,7 +337,6 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
 {
 	struct amdgpu_ctx *ctx;
 	struct amdgpu_ctx_mgr *mgr;
-	unsigned long ras_counter;
 
 	if (!fpriv)
 		return -EINVAL;
@@ -362,21 +361,6 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
 	if (atomic_read(&ctx->guilty))
 		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_GUILTY;
 
-	/*query ue count*/
-	ras_counter = amdgpu_ras_query_error_count(adev, false);
-	/*ras counter is monotonic increasing*/
-	if (ras_counter != ctx->ras_counter_ue) {
-		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_UE;
-		ctx->ras_counter_ue = ras_counter;
-	}
-
-	/*query ce count*/
-	ras_counter = amdgpu_ras_query_error_count(adev, true);
-	if (ras_counter != ctx->ras_counter_ce) {
-		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_CE;
-		ctx->ras_counter_ce = ras_counter;
-	}
-
 	mutex_unlock(&mgr->lock);
 	return 0;
 }
Signature · 1 line
2.31.1.527.g2d677e5b15
#1 lore raw

PATCH 2/3 drm/amdgpu: Fix RAS function interface

The correctable and uncorrectable errors are calculated at each invocation of this function. Therefore, it is highly inefficient to return just one of them based on a Boolean input. If the caller wants both, twice the work would be done. (And this work is O(n^3) on Vega20.)

Fix this "interface" to simply return what it had calculated--both values. Let the caller choose what it wants to record, inspect, use.

Cc Alexander Deucher <[email protected]>
Cc John Clements <[email protected]>
Cc Hawking Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 23 +++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  5 +++--
 2 files changed, 18 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +15 -8
index e3a4c3a7635a..ed3c43e8b0b5 100644
@@ -1043,29 +1043,36 @@ int amdgpu_ras_error_inject(struct amdgpu_device *adev,
 }
 
 /* get the total error counts on all IPs */
-unsigned long amdgpu_ras_query_error_count(struct amdgpu_device *adev,
-		bool is_ce)
+void amdgpu_ras_query_error_count(struct amdgpu_device *adev,
+				  unsigned long *ce_count,
+				  unsigned long *ue_count)
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct ras_manager *obj;
-	struct ras_err_data data = {0, 0};
+	unsigned long ce, ue;
 
 	if (!adev->ras_enabled || !con)
-		return 0;
+		return;
 
+	ce = 0;
+	ue = 0;
 	list_for_each_entry(obj, &con->head, node) {
 		struct ras_query_if info = {
 			.head = obj->head,
 		};
 
 		if (amdgpu_ras_query_error_status(adev, &info))
-			return 0;
+			return;
 
-		data.ce_count += info.ce_count;
-		data.ue_count += info.ue_count;
+		ce += info.ce_count;
+		ue += info.ue_count;
 	}
 
-	return is_ce ? data.ce_count : data.ue_count;
+	if (ce_count)
+		*ce_count = ce;
+
+	if (ue_count)
+		*ue_count = ue;
 }
 /* query/inject/cure end */
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +3 -2
index bfa40c8ecc94..10fca0393106 100644
@@ -485,8 +485,9 @@ int amdgpu_ras_request_reset_on_boot(struct amdgpu_device *adev,
 void amdgpu_ras_resume(struct amdgpu_device *adev);
 void amdgpu_ras_suspend(struct amdgpu_device *adev);
 
-unsigned long amdgpu_ras_query_error_count(struct amdgpu_device *adev,
-		bool is_ce);
+void amdgpu_ras_query_error_count(struct amdgpu_device *adev,
+				  unsigned long *ce_count,
+				  unsigned long *ue_count);
 
 /* error handling functions */
 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
Signature · 6 lines
2.31.1.527.g2d677e5b15

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

PATCH 3/3 drm/amdgpu: Use delayed work to collect RAS error counters

In reply to Luben Tuikov

On Context Query2 IOCTL return the correctable and uncorrectable errors in O(1) fashion, from cached values, and schedule a delayed work function to calculate and cache them for the next such IOCTL.

v2: Cancel pending delayed work at ras_fini().

Cc Alexander Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc John Clements <[email protected]>
Cc Hawking Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 32 +++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 41 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  5 +++
 3 files changed, 76 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +30 -2
index bb0cfe871aba..4e95d255960b 100644
@@ -331,10 +331,13 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 	return 0;
 }
 
+#define AMDGPU_RAS_COUNTE_DELAY_MS 3000
+
 static int amdgpu_ctx_query2(struct amdgpu_device *adev,
-	struct amdgpu_fpriv *fpriv, uint32_t id,
-	union drm_amdgpu_ctx_out *out)
+			     struct amdgpu_fpriv *fpriv, uint32_t id,
+			     union drm_amdgpu_ctx_out *out)
 {
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct amdgpu_ctx *ctx;
 	struct amdgpu_ctx_mgr *mgr;
 
@@ -361,6 +364,31 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
 	if (atomic_read(&ctx->guilty))
 		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_GUILTY;
 
+	if (adev->ras_enabled && con) {
+		/* Return the cached values in O(1),
+		 * and schedule delayed work to cache
+		 * new vaues.
+		 */
+		int ce_count, ue_count;
+
+		ce_count = atomic_read(&con->ras_ce_count);
+		ue_count = atomic_read(&con->ras_ue_count);
+
+		if (ce_count != ctx->ras_counter_ce) {
+			ctx->ras_counter_ce = ce_count;
+			out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_CE;
+		}
+
+		if (ue_count != ctx->ras_counter_ue) {
+			ctx->ras_counter_ue = ue_count;
+			out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_UE;
+		}
+
+		if (!delayed_work_pending(&con->ras_counte_delay_work))
+			schedule_delayed_work(&con->ras_counte_delay_work,
+				  msecs_to_jiffies(AMDGPU_RAS_COUNTE_DELAY_MS));
+	}
+
 	mutex_unlock(&mgr->lock);
 	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +41 -0

77 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +5 -0
index 10fca0393106..256cea5d34f2 100644
@@ -340,6 +340,11 @@ struct amdgpu_ras {
 
 	/* disable ras error count harvest in recovery */
 	bool disable_ras_err_cnt_harvest;
+
+	/* RAS count errors delayed work */
+	struct delayed_work ras_counte_delay_work;
+	atomic_t ras_ue_count;
+	atomic_t ras_ce_count;
 };
 
 struct ras_fs_data {
Signature · 6 lines
2.31.1.527.g2d677e5b15

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

Re: [PATCH 3/3] drm/amdgpu: Use delayed work to collect RAS error counters

Am 26.05.21 um 02:40 schrieb Luben Tuikov:

Quoted 55 lines

On Context Query2 IOCTL return the correctable and uncorrectable errors in O(1) fashion, from cached values, and schedule a delayed work function to calculate and cache them for the next such IOCTL.

v2: Cancel pending delayed work at ras_fini().

Cc Alexander Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc John Clements <[email protected]>
Cc Hawking Zhang <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 32 +++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 41 +++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  5 +++
  3 files changed, 76 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +18 -2
index bb0cfe871aba..4e95d255960b 100644
@@ -331,10 +331,13 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
  	return 0;
  }
 
+#define AMDGPU_RAS_COUNTE_DELAY_MS 3000
+
  static int amdgpu_ctx_query2(struct amdgpu_device *adev,
-	struct amdgpu_fpriv *fpriv, uint32_t id,
-	union drm_amdgpu_ctx_out *out)
+			     struct amdgpu_fpriv *fpriv, uint32_t id,
+			     union drm_amdgpu_ctx_out *out)
  {
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  	struct amdgpu_ctx *ctx;
  	struct amdgpu_ctx_mgr *mgr;
 
@@ -361,6 +364,31 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
  	if (atomic_read(&ctx->guilty))
  		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_GUILTY;
 
+	if (adev->ras_enabled && con) {
+		/* Return the cached values in O(1),
+		 * and schedule delayed work to cache
+		 * new vaues.
+		 */
+		int ce_count, ue_count;
+
+		ce_count = atomic_read(&con->ras_ce_count);
+		ue_count = atomic_read(&con->ras_ue_count);
+
+		if (ce_count != ctx->ras_counter_ce) {
+			ctx->ras_counter_ce = ce_count;
+			out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_CE;

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_query2(struct amdgpu_device *adev, · line 389

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +10 -0
+		}
+
+		if (ue_count != ctx->ras_counter_ue) {
+			ctx->ras_counter_ue = ue_count;
+			out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_UE;
+		}
+
+		if (!delayed_work_pending(&con->ras_counte_delay_work))
+			schedule_delayed_work(&con->ras_counte_delay_work,
+				  msecs_to_jiffies(AMDGPU_RAS_COUNTE_DELAY_MS));

You can skip the delayed_work_pending() check here, if I'm not totally mistaken that is already integrated in the schedule_delayed_work() logic.

Quoted 83 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -0
+	}
+
  	mutex_unlock(&mgr->lock);
  	return 0;
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +38 -0
index ed3c43e8b0b5..01114529040a 100644
@@ -27,6 +27,7 @@
  #include <linux/uaccess.h>
  #include <linux/reboot.h>
  #include <linux/syscalls.h>
+#include <linux/pm_runtime.h>
 
  #include "amdgpu.h"
  #include "amdgpu_ras.h"
@@ -2116,6 +2117,30 @@ static void amdgpu_ras_check_supported(struct amdgpu_device *adev)
  		adev->ras_hw_enabled & amdgpu_ras_mask;
  }
 
+static void amdgpu_ras_counte_dw(struct work_struct *work)
+{
+	struct amdgpu_ras *con = container_of(work, struct amdgpu_ras,
+					      ras_counte_delay_work.work);
+	struct amdgpu_device *adev = con->adev;
+	struct drm_device *dev = &adev->ddev;
+	unsigned long ce_count, ue_count;
+	int res;
+
+	res = pm_runtime_get_sync(dev->dev);
+	if (res < 0)
+		goto Out;
+
+	/* Cache new values.
+	 */
+	amdgpu_ras_query_error_count(adev, &ce_count, &ue_count);
+	atomic_set(&con->ras_ce_count, ce_count);
+	atomic_set(&con->ras_ue_count, ue_count);
+
+	pm_runtime_mark_last_busy(dev->dev);
+Out:
+	pm_runtime_put_autosuspend(dev->dev);
+}
+
  int amdgpu_ras_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -2130,6 +2155,11 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
  	if (!con)
  		return -ENOMEM;
 
+	con->adev = adev;
+	INIT_DELAYED_WORK(&con->ras_counte_delay_work, amdgpu_ras_counte_dw);
+	atomic_set(&con->ras_ce_count, 0);
+	atomic_set(&con->ras_ue_count, 0);
+
  	con->objs = (struct ras_manager *)(con + 1);
 
  	amdgpu_ras_set_context(adev, con);
@@ -2233,6 +2263,8 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev,
  			 struct ras_fs_if *fs_info,
  			 struct ras_ih_if *ih_info)
  {
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+	unsigned long ue_count, ce_count;
  	int r;
 
  	/* disable RAS feature per IP block if it is not supported */
@@ -2273,6 +2305,12 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev,
  	if (r)
  		goto sysfs;
 
+	/* Those are the cached values at init.
+	 */
+	amdgpu_ras_query_error_count(adev, &ce_count, &ue_count);
+	atomic_set(&con->ras_ce_count, ce_count);
+	atomic_set(&con->ras_ue_count, ue_count);
+
  	return 0;
  cleanup:
  	amdgpu_ras_sysfs_remove(adev, ras_block);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c int amdgpu_ras_fini(struct amdgpu_device *adev) · line 2433

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -0
@@ -2390,6 +2428,9 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)
  	if (con->features)
  		amdgpu_ras_disable_all_features(adev, 1);
 
+	if (delayed_work_pending(&con->ras_counte_delay_work))
+		cancel_delayed_work_sync(&con->ras_counte_delay_work);
+

Using delayed_work_pending() here causes a race problem, because the work might be running at the moment.

Just calling cancel_delayed_work_sync() should fix that because the *_sync() variant also waits for running delayed work items to finish.

Apart from that the patch looks good to me.

Regards,
Christian.

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
  	amdgpu_ras_set_context(adev, NULL);
  	kfree(con);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +0 -0
index 10fca0393106..256cea5d34f2 100644
@@ -340,6 +340,11 @@ struct amdgpu_ras {
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h struct amdgpu_ras { · line 350

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +5 -0
  	/* disable ras error count harvest in recovery */
  	bool disable_ras_err_cnt_harvest;
+
+	/* RAS count errors delayed work */
+	struct delayed_work ras_counte_delay_work;
+	atomic_t ras_ue_count;
+	atomic_t ras_ce_count;
  };
 
  struct ras_fs_data {

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

#4 lore raw

Re: [PATCH 3/3] drm/amdgpu: Use delayed work to collect RAS error counters

Quoted 60 lines · Christian König

Am 26.05.21 um 02:40 schrieb Luben Tuikov:

Quoted 59 lines

On Context Query2 IOCTL return the correctable and uncorrectable errors in O(1) fashion, from cached values, and schedule a delayed work function to calculate and cache them for the next such IOCTL.

v2: Cancel pending delayed work at ras_fini().

Cc Alexander Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc John Clements <[email protected]>
Cc Hawking Zhang <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 32 +++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 41 +++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  5 +++
  3 files changed, 76 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +22 -2
index bb0cfe871aba..4e95d255960b 100644
@@ -331,10 +331,13 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
  	return 0;
  }
 
+#define AMDGPU_RAS_COUNTE_DELAY_MS 3000
+
  static int amdgpu_ctx_query2(struct amdgpu_device *adev,
-	struct amdgpu_fpriv *fpriv, uint32_t id,
-	union drm_amdgpu_ctx_out *out)
+			     struct amdgpu_fpriv *fpriv, uint32_t id,
+			     union drm_amdgpu_ctx_out *out)
  {
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
  	struct amdgpu_ctx *ctx;
  	struct amdgpu_ctx_mgr *mgr;
 
@@ -361,6 +364,31 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
  	if (atomic_read(&ctx->guilty))
  		out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_GUILTY;
 
+	if (adev->ras_enabled && con) {
+		/* Return the cached values in O(1),
+		 * and schedule delayed work to cache
+		 * new vaues.
+		 */
+		int ce_count, ue_count;
+
+		ce_count = atomic_read(&con->ras_ce_count);
+		ue_count = atomic_read(&con->ras_ue_count);
+
+		if (ce_count != ctx->ras_counter_ce) {
+			ctx->ras_counter_ce = ce_count;
+			out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_CE;
+		}
+
+		if (ue_count != ctx->ras_counter_ue) {
+			ctx->ras_counter_ue = ue_count;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_query2(struct amdgpu_device *adev, · line 389

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -0
+			out->state.flags |= AMDGPU_CTX_QUERY2_FLAGS_RAS_UE;
+		}
+
+		if (!delayed_work_pending(&con->ras_counte_delay_work))
+			schedule_delayed_work(&con->ras_counte_delay_work,
+				  msecs_to_jiffies(AMDGPU_RAS_COUNTE_DELAY_MS));

You can skip the delayed_work_pending() check here, if I'm not totally mistaken that is already integrated in the schedule_delayed_work() logic.

I'll take a look and if so I'll remove the check. I've remembered this check from many years ago--habit.

Quoted 87 lines
Quoted 87 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -0
+	}
+
  	mutex_unlock(&mgr->lock);
  	return 0;
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +38 -0
index ed3c43e8b0b5..01114529040a 100644
@@ -27,6 +27,7 @@
  #include <linux/uaccess.h>
  #include <linux/reboot.h>
  #include <linux/syscalls.h>
+#include <linux/pm_runtime.h>
 
  #include "amdgpu.h"
  #include "amdgpu_ras.h"
@@ -2116,6 +2117,30 @@ static void amdgpu_ras_check_supported(struct amdgpu_device *adev)
  		adev->ras_hw_enabled & amdgpu_ras_mask;
  }
 
+static void amdgpu_ras_counte_dw(struct work_struct *work)
+{
+	struct amdgpu_ras *con = container_of(work, struct amdgpu_ras,
+					      ras_counte_delay_work.work);
+	struct amdgpu_device *adev = con->adev;
+	struct drm_device *dev = &adev->ddev;
+	unsigned long ce_count, ue_count;
+	int res;
+
+	res = pm_runtime_get_sync(dev->dev);
+	if (res < 0)
+		goto Out;
+
+	/* Cache new values.
+	 */
+	amdgpu_ras_query_error_count(adev, &ce_count, &ue_count);
+	atomic_set(&con->ras_ce_count, ce_count);
+	atomic_set(&con->ras_ue_count, ue_count);
+
+	pm_runtime_mark_last_busy(dev->dev);
+Out:
+	pm_runtime_put_autosuspend(dev->dev);
+}
+
  int amdgpu_ras_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
@@ -2130,6 +2155,11 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
  	if (!con)
  		return -ENOMEM;
 
+	con->adev = adev;
+	INIT_DELAYED_WORK(&con->ras_counte_delay_work, amdgpu_ras_counte_dw);
+	atomic_set(&con->ras_ce_count, 0);
+	atomic_set(&con->ras_ue_count, 0);
+
  	con->objs = (struct ras_manager *)(con + 1);
 
  	amdgpu_ras_set_context(adev, con);
@@ -2233,6 +2263,8 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev,
  			 struct ras_fs_if *fs_info,
  			 struct ras_ih_if *ih_info)
  {
+	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
+	unsigned long ue_count, ce_count;
  	int r;
 
  	/* disable RAS feature per IP block if it is not supported */
@@ -2273,6 +2305,12 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev,
  	if (r)
  		goto sysfs;
 
+	/* Those are the cached values at init.
+	 */
+	amdgpu_ras_query_error_count(adev, &ce_count, &ue_count);
+	atomic_set(&con->ras_ce_count, ce_count);
+	atomic_set(&con->ras_ue_count, ue_count);
+
  	return 0;
  cleanup:
  	amdgpu_ras_sysfs_remove(adev, ras_block);
@@ -2390,6 +2428,9 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)
  	if (con->features)
  		amdgpu_ras_disable_all_features(adev, 1);
 
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c int amdgpu_ras_fini(struct amdgpu_device *adev) · line 2433

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -0
+	if (delayed_work_pending(&con->ras_counte_delay_work))
+		cancel_delayed_work_sync(&con->ras_counte_delay_work);
+

Using delayed_work_pending() here causes a race problem, because the work might be running at the moment.

Just calling cancel_delayed_work_sync() should fix that because the *_sync() variant also waits for running delayed work items to finish.

Yes, that's why I used the *_sync() version--we can't go on until the delayed work has finished.

Yes, I agree that it is indeed a race, and I saw that, and I wonder why that interface exists in the kernel in the first place.

Regards,
Luben

Quoted 24 lines

Apart from that the patch looks good to me.

Regards,
Christian.

Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
  	amdgpu_ras_set_context(adev, NULL);
  	kfree(con);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +5 -0
index 10fca0393106..256cea5d34f2 100644
@@ -340,6 +340,11 @@ struct amdgpu_ras {
 
  	/* disable ras error count harvest in recovery */
  	bool disable_ras_err_cnt_harvest;
+
+	/* RAS count errors delayed work */
+	struct delayed_work ras_counte_delay_work;
+	atomic_t ras_ue_count;
+	atomic_t ras_ce_count;
  };
 
Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h struct amdgpu_ras { · line 350

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +0 -0
  struct ras_fs_data {

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