drm/i915: Exercise request cancellation using a mock selftest
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 23 Feb 2017 07:44:18 +0000 (07:44 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 23 Feb 2017 14:50:42 +0000 (14:50 +0000)
Add a mock selftest to preempt a request and check that we cancel it,
requeue the request and then complete its execution.

v2: Error leaks no more.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/20170223074422.4125-13-chris@chris-wilson.co.uk
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
drivers/gpu/drm/i915/selftests/i915_gem_request.c
drivers/gpu/drm/i915/selftests/mock_request.c
drivers/gpu/drm/i915/selftests/mock_request.h

index 9d056a86723d3d01d107d6999d580a6655da9b66..42bdeac93324278b6630b6e061a4d0b87c719905 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "../i915_selftest.h"
 
+#include "mock_context.h"
 #include "mock_gem_device.h"
 
 static int igt_add_request(void *arg)
@@ -181,12 +182,75 @@ out_locked:
        return err;
 }
 
+static int igt_request_rewind(void *arg)
+{
+       struct drm_i915_private *i915 = arg;
+       struct drm_i915_gem_request *request, *vip;
+       struct i915_gem_context *ctx[2];
+       int err = -EINVAL;
+
+       mutex_lock(&i915->drm.struct_mutex);
+       ctx[0] = mock_context(i915, "A");
+       request = mock_request(i915->engine[RCS], ctx[0], 2 * HZ);
+       if (!request) {
+               err = -ENOMEM;
+               goto err_context_0;
+       }
+
+       i915_gem_request_get(request);
+       i915_add_request(request);
+
+       ctx[1] = mock_context(i915, "B");
+       vip = mock_request(i915->engine[RCS], ctx[1], 0);
+       if (!vip) {
+               err = -ENOMEM;
+               goto err_context_1;
+       }
+
+       /* Simulate preemption by manual reordering */
+       if (!mock_cancel_request(request)) {
+               pr_err("failed to cancel request (already executed)!\n");
+               i915_add_request(vip);
+               goto err_context_1;
+       }
+       i915_gem_request_get(vip);
+       i915_add_request(vip);
+       request->engine->submit_request(request);
+
+       mutex_unlock(&i915->drm.struct_mutex);
+
+       if (i915_wait_request(vip, 0, HZ) == -ETIME) {
+               pr_err("timed out waiting for high priority request, vip.seqno=%d, current seqno=%d\n",
+                      vip->global_seqno, intel_engine_get_seqno(i915->engine[RCS]));
+               goto err;
+       }
+
+       if (i915_gem_request_completed(request)) {
+               pr_err("low priority request already completed\n");
+               goto err;
+       }
+
+       err = 0;
+err:
+       i915_gem_request_put(vip);
+       mutex_lock(&i915->drm.struct_mutex);
+err_context_1:
+       mock_context_close(ctx[1]);
+       i915_gem_request_put(request);
+err_context_0:
+       mock_context_close(ctx[0]);
+       mock_device_flush(i915);
+       mutex_unlock(&i915->drm.struct_mutex);
+       return err;
+}
+
 int i915_gem_request_mock_selftests(void)
 {
        static const struct i915_subtest tests[] = {
                SUBTEST(igt_add_request),
                SUBTEST(igt_wait_request),
                SUBTEST(igt_fence_wait),
+               SUBTEST(igt_request_rewind),
        };
        struct drm_i915_private *i915;
        int err;
index e23242d1b88afae83c9f3d73f0209c2550da54fe..0e8d2e7f8c7032ad73b4e99899dd21cfb0d414b5 100644 (file)
@@ -22,6 +22,7 @@
  *
  */
 
+#include "mock_engine.h"
 #include "mock_request.h"
 
 struct drm_i915_gem_request *
@@ -42,3 +43,21 @@ mock_request(struct intel_engine_cs *engine,
 
        return &mock->base;
 }
+
+bool mock_cancel_request(struct drm_i915_gem_request *request)
+{
+       struct mock_request *mock = container_of(request, typeof(*mock), base);
+       struct mock_engine *engine =
+               container_of(request->engine, typeof(*engine), base);
+       bool was_queued;
+
+       spin_lock_irq(&engine->hw_lock);
+       was_queued = !list_empty(&mock->link);
+       list_del_init(&mock->link);
+       spin_unlock_irq(&engine->hw_lock);
+
+       if (was_queued)
+               i915_gem_request_unsubmit(request);
+
+       return was_queued;
+}
index cc76d4f4eb4e89ca339601a1a636e1ddbdcdcb8c..4dea74c8e96db0b467bd6580cb99489bee9e8850 100644 (file)
@@ -41,4 +41,6 @@ mock_request(struct intel_engine_cs *engine,
             struct i915_gem_context *context,
             unsigned long delay);
 
+bool mock_cancel_request(struct drm_i915_gem_request *request);
+
 #endif /* !__MOCK_REQUEST__ */