Commit 2a67b18e authored by Umesh Nerlige Ramappa's avatar Umesh Nerlige Ramappa Committed by John Harrison

drm/i915/pmu: Fix synchronization of PMU callback with reset

Since the PMU callback runs in irq context, it synchronizes with gt
reset using the reset count. We could run into a case where the PMU
callback could read the reset count before it is updated. This has a
potential of corrupting the busyness stats.

In addition to the reset count, check if the reset bit is set before
capturing busyness.

In addition save the previous stats only if you intend to update them.

v2:
- The 2 reset counts captured in the PMU callback can end up being the
  same if they were captured right after the count is incremented in the
  reset flow. This can lead to a bad busyness state. Ensure that reset
  is not in progress when the initial reset count is captured.
Signed-off-by: default avatarUmesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Signed-off-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211108211057.68783-1-umesh.nerlige.ramappa@intel.com
parent 95d35838
...@@ -1183,15 +1183,20 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now) ...@@ -1183,15 +1183,20 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now)
u64 total, gt_stamp_saved; u64 total, gt_stamp_saved;
unsigned long flags; unsigned long flags;
u32 reset_count; u32 reset_count;
bool in_reset;
spin_lock_irqsave(&guc->timestamp.lock, flags); spin_lock_irqsave(&guc->timestamp.lock, flags);
/* /*
* If a reset happened, we risk reading partially updated * If a reset happened, we risk reading partially updated engine
* engine busyness from GuC, so we just use the driver stored * busyness from GuC, so we just use the driver stored copy of busyness.
* copy of busyness. Synchronize with gt reset using reset_count. * Synchronize with gt reset using reset_count and the
* I915_RESET_BACKOFF flag. Note that reset flow updates the reset_count
* after I915_RESET_BACKOFF flag, so ensure that the reset_count is
* usable by checking the flag afterwards.
*/ */
reset_count = i915_reset_count(gpu_error); reset_count = i915_reset_count(gpu_error);
in_reset = test_bit(I915_RESET_BACKOFF, &gt->reset.flags);
*now = ktime_get(); *now = ktime_get();
...@@ -1201,9 +1206,9 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now) ...@@ -1201,9 +1206,9 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now)
* start_gt_clk is derived from GuC state. To get a consistent * start_gt_clk is derived from GuC state. To get a consistent
* view of activity, we query the GuC state only if gt is awake. * view of activity, we query the GuC state only if gt is awake.
*/ */
stats_saved = *stats; if (intel_gt_pm_get_if_awake(gt) && !in_reset) {
gt_stamp_saved = guc->timestamp.gt_stamp; stats_saved = *stats;
if (intel_gt_pm_get_if_awake(gt)) { gt_stamp_saved = guc->timestamp.gt_stamp;
guc_update_engine_gt_clks(engine); guc_update_engine_gt_clks(engine);
guc_update_pm_timestamp(guc, engine, now); guc_update_pm_timestamp(guc, engine, now);
intel_gt_pm_put_async(gt); intel_gt_pm_put_async(gt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment