drm/i915/selftest: Fix engine timestamp and ktime disparity
authorAnshuman Gupta <anshuman.gupta@intel.com>
Thu, 23 Feb 2023 10:05:02 +0000 (15:35 +0530)
committerAnshuman Gupta <anshuman.gupta@intel.com>
Fri, 3 Mar 2023 14:06:33 +0000 (19:36 +0530)
While reading the engine timestamps there can be uncontrollable
concurrent mmio access via other i915 child drivers and by GuC,
which is not truly atomic context as expected by this selftest,
which may cause mmio latency to read the engine timestamps,
Account such latency to calculate time to read engine timestamp
such that selftest can validate the timestamp and ktime pair.

Cc: Chris Wilson <chris.p.wilson@intel.com>
Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
Reviewed-by: Badal Nilawar <badal.nilawar@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230223100503.3323627-2-anshuman.gupta@intel.com
drivers/gpu/drm/i915/gt/selftest_gt_pm.c
drivers/gpu/drm/i915/gt/selftest_rps.c

index b46425aeb2f04876dea28a39b5bda4433abb134e..0971241707ce8364322c9217ca204c6703cd97e4 100644 (file)
@@ -63,8 +63,8 @@ static void measure_clocks(struct intel_engine_cs *engine,
 
                udelay(1000);
 
-               dt[i] = ktime_sub(ktime_get(), dt[i]);
                cycles[i] += read_timestamp(engine);
+               dt[i] = ktime_sub(ktime_get(), dt[i]);
                local_irq_enable();
        }
 
index 6755bbc4ebdac01d9d4f96a5a1c30fb1044cc8d0..c0cc0dd78c7c8c1090e15d548bb8359cb5352122 100644 (file)
@@ -299,13 +299,13 @@ int live_rps_clock_interval(void *arg)
                        for (i = 0; i < 5; i++) {
                                preempt_disable();
 
-                               dt_[i] = ktime_get();
                                cycles_[i] = -intel_uncore_read_fw(gt->uncore, GEN6_RP_CUR_UP_EI);
+                               dt_[i] = ktime_get();
 
                                udelay(1000);
 
-                               dt_[i] = ktime_sub(ktime_get(), dt_[i]);
                                cycles_[i] += intel_uncore_read_fw(gt->uncore, GEN6_RP_CUR_UP_EI);
+                               dt_[i] = ktime_sub(ktime_get(), dt_[i]);
 
                                preempt_enable();
                        }