Skip to contentSkip to conversation

i915/guc: Run busyness worker only if gt is awake

PATCH In review Umesh Nerlige Ramappa 2 participants 3 messages Sep 9, 2023 – Sep 12, 2023

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

PATCH 1/1 i915/guc: Run busyness worker only if gt is awake

The worker is canceled in the __gt_park path, but we still see it running sometimes during suspend. This is likely because some code is getting a gt wakeref in the __gt_park path.

Only update stats if gt is awake. If not, intel_guc_busyness_park would have already updated the stats. Note that we do not requeue the worker if gt is not awake since intel_guc_busyness_unpark would do that at some point.

If the gt was parked longer than time taken for GT timestamp to roll over, we ignore those rollovers since we don't care about tracking the exact GT time. We only care about roll overs when the gt is active and running workloads.

---
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23 -4
index e250bedf90fb..df31d6047ce9 100644
@@ -1457,10 +1457,27 @@ static void guc_timestamp_ping(struct work_struct *wrk)
 	struct intel_uc *uc = container_of(guc, typeof(*uc), guc);
 	struct intel_gt *gt = guc_to_gt(guc);
 	struct intel_context *ce;
-	intel_wakeref_t wakeref;
 	unsigned long index;
 	int srcu, ret;
 
+	/*
+	 * The worker is canceled in the __gt_park path, but we still see it
+	 * running sometimes during suspend. This is likely because some code
+	 * is getting a gt wakeref in the __gt_park path.
+	 *
+	 * Only update stats if gt is awake. If not, intel_guc_busyness_park
+	 * would have already updated the stats. Note that we do not requeue the
+	 * worker in this case since intel_guc_busyness_unpark would do that at
+	 * some point.
+	 *
+	 * If the gt was parked longer than time taken for GT timestamp to roll
+	 * over, we ignore those rollovers since we don't care about tracking
+	 * the exact GT time. We only care about roll overs when the gt is
+	 * active and running workloads.
+	 */
+	if (!intel_gt_pm_get_if_awake(gt))
+		return;
+
 	/*
 	 * Synchronize with gt reset to make sure the worker does not
 	 * corrupt the engine/guc stats. NB: can't actually block waiting
@@ -1468,17 +1485,19 @@ static void guc_timestamp_ping(struct work_struct *wrk)
 	 * this worker thread if started. So waiting would deadlock.
 	 */
 	ret = intel_gt_reset_trylock(gt, &srcu);
-	if (ret)
+	if (ret) {
+		intel_gt_pm_put(gt);
 		return;
+	}
 
-	with_intel_runtime_pm(&gt->i915->runtime_pm, wakeref)
-		__update_guc_busyness_stats(guc);
+	__update_guc_busyness_stats(guc);
 
 	/* adjust context stats for overflow */
 	xa_for_each(&guc->context_lookup, index, ce)
 		guc_context_update_stats(ce);
 
 	intel_gt_reset_unlock(gt, srcu);
+	intel_gt_pm_put(gt);
 
 	guc_enable_busyness_worker(guc);
 }
Signature · 1 line
2.38.1
#1 lore raw
Quoted 3 lines · Umesh Nerlige Ramappa

The worker is canceled in the __gt_park path, but we still see it running sometimes during suspend. This is likely because some code is getting a gt wakeref in the __gt_park path.

This possible root-cause doesn't seem plausible to me, because a gt wakeref would cause an unpark, so taking it within the park would probably cause a deadlock. Is it not more likely that the worker re-queued itself?

Quoted 11 lines

Only update stats if gt is awake. If not, intel_guc_busyness_park would have already updated the stats. Note that we do not requeue the worker if gt is not awake since intel_guc_busyness_unpark would do that at some point.

If the gt was parked longer than time taken for GT timestamp to roll over, we ignore those rollovers since we don't care about tracking the exact GT time. We only care about roll overs when the gt is active and running workloads.

This needs a fixes tag. Also, I'm not 100% sure but I believe we prefer "Link" to "Closes".

Quoted 11 lines
---
  .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 27 ++++++++++++++++---
  1 file changed, 23 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0 -0
index e250bedf90fb..df31d6047ce9 100644
@@ -1457,10 +1457,27 @@ static void guc_timestamp_ping(struct work_struct *wrk)
  	struct intel_uc *uc = container_of(guc, typeof(*uc), guc);

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_timestamp_ping(struct work_struct *wrk) · line 1466

Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4 -1
  	struct intel_gt *gt = guc_to_gt(guc);
  	struct intel_context *ce;
-	intel_wakeref_t wakeref;
  	unsigned long index;
  	int srcu, ret;
 
+	/*
+	 * The worker is canceled in the __gt_park path, but we still see it
+	 * running sometimes during suspend. This is likely because some code
+	 * is getting a gt wakeref in the __gt_park path.

Same comment from before about this explanation. I would just remove this part from the comment.

Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4 -0
+	 *
+	 * Only update stats if gt is awake. If not, intel_guc_busyness_park
+	 * would have already updated the stats. Note that we do not requeue the
+	 * worker in this case since intel_guc_busyness_unpark would do that at

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_timestamp_ping(struct work_struct *wrk) · line 1480

Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10 -0
+	 * some point.
+	 *
+	 * If the gt was parked longer than time taken for GT timestamp to roll
+	 * over, we ignore those rollovers since we don't care about tracking
+	 * the exact GT time. We only care about roll overs when the gt is
+	 * active and running workloads.
+	 */
+	if (!intel_gt_pm_get_if_awake(gt))
+		return;
+

Do we need to drop the _sync from the busyness stats worker parking if we take the gt_pm wakeref in here, instead of an rpm one? because if the gt_pm_put below causes a park and the park waits on this worker to complete then we'll deadlock.

Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3 -1
  	/*
  	 * Synchronize with gt reset to make sure the worker does not
  	 * corrupt the engine/guc stats. NB: can't actually block waiting
@@ -1468,17 +1485,19 @@ static void guc_timestamp_ping(struct work_struct *wrk)
  	 * this worker thread if started. So waiting would deadlock.
  	 */
  	ret = intel_gt_reset_trylock(gt, &srcu);
-	if (ret)
+	if (ret) {
+		intel_gt_pm_put(gt);
  		return;
+	}
 

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_timestamp_ping(struct work_struct *wrk) · line 1500

Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2 -2
-	with_intel_runtime_pm(&gt->i915->runtime_pm, wakeref)
-		__update_guc_busyness_stats(guc);
+	__update_guc_busyness_stats(guc);
 
  	/* adjust context stats for overflow */
  	xa_for_each(&guc->context_lookup, index, ce)
  		guc_context_update_stats(ce);
 
  	intel_gt_reset_unlock(gt, srcu);
+	intel_gt_pm_put(gt);

I think this needs to go after the queuing, because it could cause a park and if it does we don't want to re-queue the worker immediately after, while if we queue it before then the park will cancel it. Non-blocking style comment: with gt_pm_put the last thing in function, you can also transform that early return in a "goto put;" and have a single place for the gt_put.

Daniele

Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0 -0
  	guc_enable_busyness_worker(guc);
  }
#2 lore raw
Quoted 9 lines · Daniele Ceraolo Spurio

On 9/8/2023 10:16 PM, Umesh Nerlige Ramappa wrote:

The worker is canceled in the __gt_park path, but we still see it running sometimes during suspend. This is likely because some code is getting a gt wakeref in the __gt_park path.

This possible root-cause doesn't seem plausible to me, because a gt wakeref would cause an unpark, so taking it within the park would probably cause a deadlock. Is it not more likely that the worker re-queued itself?

Will drop the likely part. The worker running during suspend is the issue, so keeping that part.

Quoted 11 lines

Only update stats if gt is awake. If not, intel_guc_busyness_park would have already updated the stats. Note that we do not requeue the worker if gt is not awake since intel_guc_busyness_unpark would do that at some point.

If the gt was parked longer than time taken for GT timestamp to roll over, we ignore those rollovers since we don't care about tracking the exact GT time. We only care about roll overs when the gt is active and running workloads.

Quoted 4 lines
Closes [1]https://gitlab.freedesktop.org/drm/intel/-/issues/7077

This needs a fixes tag. Also, I'm not 100% sure but I believe we prefer "Link" to "Closes".

I thought Link was mostly for the patchworks link. I can change this to Link.

Any idea if there is a document/link that explains which tag to use for what? I have been confused by this before.

Quoted 35 lines
---
 .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +13 -1
index e250bedf90fb..df31d6047ce9 100644
@@ -1457,10 +1457,27 @@ static void guc_timestamp_ping(struct work_struct *wrk)
        struct intel_uc *uc = container_of(guc, typeof(*uc), guc);
        struct intel_gt *gt = guc_to_gt(guc);
        struct intel_context *ce;
-       intel_wakeref_t wakeref;
        unsigned long index;
        int srcu, ret;
 
+       /*
+        * The worker is canceled in the __gt_park path, but we still see it
+        * running sometimes during suspend. This is likely because some code
+        * is getting a gt wakeref in the __gt_park path.
 
  Same comment from before about this explanation. I would just remove this
  part from the comment.
 
+        *
+        * Only update stats if gt is awake. If not, intel_guc_busyness_park
+        * would have already updated the stats. Note that we do not requeue the
+        * worker in this case since intel_guc_busyness_unpark would do that at
+        * some point.
+        *
+        * If the gt was parked longer than time taken for GT timestamp to roll
+        * over, we ignore those rollovers since we don't care about tracking
+        * the exact GT time. We only care about roll overs when the gt is

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_timestamp_ping(struct work_struct *wrk)

Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5 -0
+        * active and running workloads.
+        */
+       if (!intel_gt_pm_get_if_awake(gt))
+               return;
+
 
  Do we need to drop the _sync from the busyness stats worker parking if we
  take the gt_pm wakeref in here, instead of an rpm one? because if the
  gt_pm_put below causes a park and the park waits on this worker to
  complete then we'll deadlock.

Hmm, My bad, That's not what I intended. It should be intel_runtime_pm_get_if_active(). I will change that

Quoted 27 lines

/*
* Synchronize with gt reset to make sure the worker does not
* corrupt the engine/guc stats. NB: can't actually block waiting

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5 -3
@@ -1468,17 +1485,19 @@ static void guc_timestamp_ping(struct work_struct *wrk)
         * this worker thread if started. So waiting would deadlock.
         */
        ret = intel_gt_reset_trylock(gt, &srcu);
-       if (ret)
+       if (ret) {
+               intel_gt_pm_put(gt);
                return;
+       }
 
-       with_intel_runtime_pm(&gt->i915->runtime_pm, wakeref)
-               __update_guc_busyness_stats(guc);
+       __update_guc_busyness_stats(guc);
 
        /* adjust context stats for overflow */
        xa_for_each(&guc->context_lookup, index, ce)
                guc_context_update_stats(ce);
 
        intel_gt_reset_unlock(gt, srcu);
+       intel_gt_pm_put(gt);
 
  I think this needs to go after the queuing, because it could cause a park
  and if it does we don't want to re-queue the worker immediately after,
Quoted 4 lines

while if we queue it before then the park will cancel it. Non-blocking style comment: with gt_pm_put the last thing in function, you can also transform that early return in a "goto put;" and have a single place for the gt_put.

Will change, although I am not sure if the runtime pm put may also cause a gt park. Assuming it can, I will make these changes.

Thanks
Umesh

Quoted 12 lines

Daniele

        guc_enable_busyness_worker(guc);

}

References

Visible links
1. https://gitlab.freedesktop.org/drm/intel/-/issues/7077
2. mailto:[email protected]