2 * SPDX-License-Identifier: MIT
4 * Copyright © 2018 Intel Corporation
7 #include "gem/i915_gem_pm.h"
9 #include "i915_selftest.h"
11 #include "igt_flush_test.h"
12 #include "lib_sw_fence.h"
15 struct i915_active base;
19 static void __live_active_retire(struct i915_active *base)
21 struct live_active *active = container_of(base, typeof(*active), base);
23 active->retired = true;
26 static int __live_active_setup(struct drm_i915_private *i915,
27 struct live_active *active)
29 struct intel_engine_cs *engine;
30 struct i915_sw_fence *submit;
31 enum intel_engine_id id;
32 unsigned int count = 0;
35 submit = heap_fence_create(GFP_KERNEL);
39 i915_active_init(i915, &active->base, __live_active_retire);
40 active->retired = false;
42 if (!i915_active_acquire(&active->base)) {
43 pr_err("First i915_active_acquire should report being idle\n");
48 for_each_engine(engine, i915, id) {
49 struct i915_request *rq;
51 rq = i915_request_create(engine->kernel_context);
57 err = i915_sw_fence_await_sw_fence_gfp(&rq->submit,
61 err = i915_active_ref(&active->base,
62 rq->fence.context, rq);
65 pr_err("Failed to track active ref!\n");
72 i915_active_release(&active->base);
73 if (active->retired && count) {
74 pr_err("i915_active retired before submission!\n");
77 if (active->base.count != count) {
78 pr_err("i915_active not tracking all requests, found %d, expected %d\n",
79 active->base.count, count);
84 i915_sw_fence_commit(submit);
85 heap_fence_put(submit);
90 static int live_active_wait(void *arg)
92 struct drm_i915_private *i915 = arg;
93 struct live_active active;
94 intel_wakeref_t wakeref;
97 /* Check that we get a callback when requests retire upon waiting */
99 mutex_lock(&i915->drm.struct_mutex);
100 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
102 err = __live_active_setup(i915, &active);
104 i915_active_wait(&active.base);
105 if (!active.retired) {
106 pr_err("i915_active not retired after waiting!\n");
110 i915_active_fini(&active.base);
111 if (igt_flush_test(i915, I915_WAIT_LOCKED))
114 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
115 mutex_unlock(&i915->drm.struct_mutex);
119 static int live_active_retire(void *arg)
121 struct drm_i915_private *i915 = arg;
122 struct live_active active;
123 intel_wakeref_t wakeref;
126 /* Check that we get a callback when requests are indirectly retired */
128 mutex_lock(&i915->drm.struct_mutex);
129 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
131 err = __live_active_setup(i915, &active);
133 /* waits for & retires all requests */
134 if (igt_flush_test(i915, I915_WAIT_LOCKED))
137 if (!active.retired) {
138 pr_err("i915_active not retired after flushing!\n");
142 i915_active_fini(&active.base);
143 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
144 mutex_unlock(&i915->drm.struct_mutex);
148 int i915_active_live_selftests(struct drm_i915_private *i915)
150 static const struct i915_subtest tests[] = {
151 SUBTEST(live_active_wait),
152 SUBTEST(live_active_retire),
155 if (i915_terminally_wedged(i915))
158 return i915_subtests(tests, i915);