Skip to content

Commit cf907f6

Browse files
committed
i915/guc: Ensure busyness counter increases motonically
Active busyness of an engine is calculated using gt timestamp and the context switch in time. While capturing the gt timestamp, it's possible that the context switches out. This race could result in an active busyness value that is greater than the actual context runtime value by a small amount. This leads to a negative delta and throws off busyness calculations for the user. If a subsequent count is smaller than the previous one, just return the previous one, since we expect the busyness to catch up. Fixes: 77cdd05 ("drm/i915/pmu: Connect engine busyness stats from GuC to pmu") Signed-off-by: Umesh Nerlige Ramappa <[email protected]> Reviewed-by: John Harrison <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent abd3182 commit cf907f6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

drivers/gpu/drm/i915/gt/intel_engine_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ struct intel_engine_guc_stats {
343343
* @start_gt_clk: GT clock time of last idle to active transition.
344344
*/
345345
u64 start_gt_clk;
346+
347+
/**
348+
* @total: The last value of total returned
349+
*/
350+
u64 total;
346351
};
347352

348353
union intel_engine_tlb_inv_reg {

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,9 +1378,12 @@ static ktime_t guc_engine_busyness(struct intel_engine_cs *engine, ktime_t *now)
13781378
total += intel_gt_clock_interval_to_ns(gt, clk);
13791379
}
13801380

1381+
if (total > stats->total)
1382+
stats->total = total;
1383+
13811384
spin_unlock_irqrestore(&guc->timestamp.lock, flags);
13821385

1383-
return ns_to_ktime(total);
1386+
return ns_to_ktime(stats->total);
13841387
}
13851388

13861389
static void guc_enable_busyness_worker(struct intel_guc *guc)

0 commit comments

Comments
 (0)