Skip to content

Commit

Permalink
drm/i915: Exercise request cancellation using a mock selftest
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chris Wilson committed Feb 23, 2017
1 parent d6a2289 commit 591c0fb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
64 changes: 64 additions & 0 deletions drivers/gpu/drm/i915/selftests/i915_gem_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "../i915_selftest.h"

#include "mock_context.h"
#include "mock_gem_device.h"

static int igt_add_request(void *arg)
Expand Down Expand Up @@ -181,12 +182,75 @@ static int igt_fence_wait(void *arg)
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;
Expand Down
19 changes: 19 additions & 0 deletions drivers/gpu/drm/i915/selftests/mock_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
*/

#include "mock_engine.h"
#include "mock_request.h"

struct drm_i915_gem_request *
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/selftests/mock_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */

0 comments on commit 591c0fb

Please sign in to comment.