drm/i915/selftests: Check timeout before flush and cond checks
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 30 Mar 2020 12:16:44 +0000 (13:16 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 30 Mar 2020 16:56:00 +0000 (17:56 +0100)
Allow a bit of leniency for the CPU scheduler to be distracted while we
flush the tasklet and so ensure that we always check the status of the
request once more before timing out.

v2: Wait until the HW acked the submit, and we do any secondary actions
for the submit (e.g. timeslices)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200330121644.25277-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gt/selftest_lrc.c

index 6f06ba7..d3e163c 100644 (file)
@@ -68,26 +68,41 @@ static void engine_heartbeat_enable(struct intel_engine_cs *engine,
        engine->props.heartbeat_interval_ms = saved;
 }
 
+static bool is_active(struct i915_request *rq)
+{
+       if (i915_request_is_active(rq))
+               return true;
+
+       if (i915_request_on_hold(rq))
+               return true;
+
+       if (i915_request_started(rq))
+               return true;
+
+       return false;
+}
+
 static int wait_for_submit(struct intel_engine_cs *engine,
                           struct i915_request *rq,
                           unsigned long timeout)
 {
        timeout += jiffies;
        do {
-               cond_resched();
-               intel_engine_flush_submission(engine);
-
-               if (READ_ONCE(engine->execlists.pending[0]))
-                       continue;
+               bool done = time_after(jiffies, timeout);
 
-               if (i915_request_is_active(rq))
+               if (i915_request_completed(rq)) /* that was quick! */
                        return 0;
 
-               if (i915_request_started(rq)) /* that was quick! */
+               /* Wait until the HW has acknowleged the submission (or err) */
+               intel_engine_flush_submission(engine);
+               if (!READ_ONCE(engine->execlists.pending[0]) && is_active(rq))
                        return 0;
-       } while (time_before(jiffies, timeout));
 
-       return -ETIME;
+               if (done)
+                       return -ETIME;
+
+               cond_resched();
+       } while (1);
 }
 
 static int wait_for_reset(struct intel_engine_cs *engine,