Commit c9d08cc3 authored by Chris Wilson's avatar Chris Wilson
Browse files

drm/i915/selftests: Mark up rpm wakerefs



Track the temporary wakerefs used within the selftests so that leaks are
clear.

v2: Add a couple of coarse annotations for mock selftests as we now
loudly warn about the errors.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190114142129.24398-14-chris@chris-wilson.co.uk
parent 2cb2cb5f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1756,6 +1756,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *dev_priv)
	};
	struct drm_file *file;
	struct i915_gem_context *ctx;
	intel_wakeref_t wakeref;
	int err;

	if (!HAS_PPGTT(dev_priv)) {
@@ -1771,7 +1772,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *dev_priv)
		return PTR_ERR(file);

	mutex_lock(&dev_priv->drm.struct_mutex);
	intel_runtime_pm_get(dev_priv);
	wakeref = intel_runtime_pm_get(dev_priv);

	ctx = live_context(dev_priv, file);
	if (IS_ERR(ctx)) {
@@ -1785,7 +1786,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *dev_priv)
	err = i915_subtests(tests, ctx);

out_unlock:
	intel_runtime_pm_put_unchecked(dev_priv);
	intel_runtime_pm_put(dev_priv, wakeref);
	mutex_unlock(&dev_priv->drm.struct_mutex);

	mock_file_free(dev_priv, file);
+19 −10
Original line number Diff line number Diff line
@@ -16,9 +16,10 @@ static int switch_to_context(struct drm_i915_private *i915,
{
	struct intel_engine_cs *engine;
	enum intel_engine_id id;
	intel_wakeref_t wakeref;
	int err = 0;

	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);

	for_each_engine(engine, i915, id) {
		struct i915_request *rq;
@@ -32,7 +33,7 @@ static int switch_to_context(struct drm_i915_private *i915,
		i915_request_add(rq);
	}

	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);

	return err;
}
@@ -65,7 +66,9 @@ static void trash_stolen(struct drm_i915_private *i915)

static void simulate_hibernate(struct drm_i915_private *i915)
{
	intel_runtime_pm_get(i915);
	intel_wakeref_t wakeref;

	wakeref = intel_runtime_pm_get(i915);

	/*
	 * As a final sting in the tail, invalidate stolen. Under a real S4,
@@ -76,7 +79,7 @@ static void simulate_hibernate(struct drm_i915_private *i915)
	 */
	trash_stolen(i915);

	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
}

static int pm_prepare(struct drm_i915_private *i915)
@@ -93,39 +96,45 @@ static int pm_prepare(struct drm_i915_private *i915)

static void pm_suspend(struct drm_i915_private *i915)
{
	intel_runtime_pm_get(i915);
	intel_wakeref_t wakeref;

	wakeref = intel_runtime_pm_get(i915);

	i915_gem_suspend_gtt_mappings(i915);
	i915_gem_suspend_late(i915);

	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
}

static void pm_hibernate(struct drm_i915_private *i915)
{
	intel_runtime_pm_get(i915);
	intel_wakeref_t wakeref;

	wakeref = intel_runtime_pm_get(i915);

	i915_gem_suspend_gtt_mappings(i915);

	i915_gem_freeze(i915);
	i915_gem_freeze_late(i915);

	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
}

static void pm_resume(struct drm_i915_private *i915)
{
	intel_wakeref_t wakeref;

	/*
	 * Both suspend and hibernate follow the same wakeup path and assume
	 * that runtime-pm just works.
	 */
	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);

	intel_engines_sanitize(i915, false);
	i915_gem_sanitize(i915);
	i915_gem_resume(i915);

	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
}

static int igt_gem_suspend(void *arg)
+3 −2
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ static int igt_gem_coherency(void *arg)
	struct drm_i915_private *i915 = arg;
	const struct igt_coherency_mode *read, *write, *over;
	struct drm_i915_gem_object *obj;
	intel_wakeref_t wakeref;
	unsigned long count, n;
	u32 *offsets, *values;
	int err = 0;
@@ -298,7 +299,7 @@ static int igt_gem_coherency(void *arg)
	values = offsets + ncachelines;

	mutex_lock(&i915->drm.struct_mutex);
	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);
	for (over = igt_coherency_mode; over->name; over++) {
		if (!over->set)
			continue;
@@ -376,7 +377,7 @@ static int igt_gem_coherency(void *arg)
		}
	}
unlock:
	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
	mutex_unlock(&i915->drm.struct_mutex);
	kfree(offsets);
	return err;
+17 −10
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ static int live_nop_switch(void *arg)
	struct intel_engine_cs *engine;
	struct i915_gem_context **ctx;
	enum intel_engine_id id;
	intel_wakeref_t wakeref;
	struct drm_file *file;
	struct live_test t;
	unsigned long n;
@@ -140,7 +141,7 @@ static int live_nop_switch(void *arg)
		return PTR_ERR(file);

	mutex_lock(&i915->drm.struct_mutex);
	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);

	ctx = kcalloc(nctx, sizeof(*ctx), GFP_KERNEL);
	if (!ctx) {
@@ -243,7 +244,7 @@ static int live_nop_switch(void *arg)
	}

out_unlock:
	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
	mutex_unlock(&i915->drm.struct_mutex);
	mock_file_free(i915, file);
	return err;
@@ -593,6 +594,8 @@ static int igt_ctx_exec(void *arg)
		}

		for_each_engine(engine, i915, id) {
			intel_wakeref_t wakeref;

			if (!engine->context_size)
				continue; /* No logical context support in HW */

@@ -607,9 +610,9 @@ static int igt_ctx_exec(void *arg)
				}
			}

			intel_runtime_pm_get(i915);
			wakeref = intel_runtime_pm_get(i915);
			err = gpu_fill(obj, ctx, engine, dw);
			intel_runtime_pm_put_unchecked(i915);
			intel_runtime_pm_put(i915, wakeref);
			if (err) {
				pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) in ctx %u [full-ppgtt? %s], err=%d\n",
				       ndwords, dw, max_dwords(obj),
@@ -699,6 +702,8 @@ static int igt_ctx_readonly(void *arg)
		unsigned int id;

		for_each_engine(engine, i915, id) {
			intel_wakeref_t wakeref;

			if (!intel_engine_can_store_dword(engine))
				continue;

@@ -713,9 +718,9 @@ static int igt_ctx_readonly(void *arg)
					i915_gem_object_set_readonly(obj);
			}

			intel_runtime_pm_get(i915);
			wakeref = intel_runtime_pm_get(i915);
			err = gpu_fill(obj, ctx, engine, dw);
			intel_runtime_pm_put_unchecked(i915);
			intel_runtime_pm_put(i915, wakeref);
			if (err) {
				pr_err("Failed to fill dword %lu [%lu/%lu] with gpu (%s) in ctx %u [full-ppgtt? %s], err=%d\n",
				       ndwords, dw, max_dwords(obj),
@@ -976,6 +981,7 @@ static int igt_vm_isolation(void *arg)
	struct drm_i915_private *i915 = arg;
	struct i915_gem_context *ctx_a, *ctx_b;
	struct intel_engine_cs *engine;
	intel_wakeref_t wakeref;
	struct drm_file *file;
	I915_RND_STATE(prng);
	unsigned long count;
@@ -1022,7 +1028,7 @@ static int igt_vm_isolation(void *arg)
	GEM_BUG_ON(ctx_b->ppgtt->vm.total != vm_total);
	vm_total -= I915_GTT_PAGE_SIZE;

	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);

	count = 0;
	for_each_engine(engine, i915, id) {
@@ -1067,7 +1073,7 @@ static int igt_vm_isolation(void *arg)
		count, RUNTIME_INFO(i915)->num_rings);

out_rpm:
	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
out_unlock:
	if (end_live_test(&t))
		err = -EIO;
@@ -1165,6 +1171,7 @@ static int igt_switch_to_kernel_context(void *arg)
	struct intel_engine_cs *engine;
	struct i915_gem_context *ctx;
	enum intel_engine_id id;
	intel_wakeref_t wakeref;
	int err;

	/*
@@ -1175,7 +1182,7 @@ static int igt_switch_to_kernel_context(void *arg)
	 */

	mutex_lock(&i915->drm.struct_mutex);
	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);

	ctx = kernel_context(i915);
	if (IS_ERR(ctx)) {
@@ -1200,7 +1207,7 @@ out_unlock:
	if (igt_flush_test(i915, I915_WAIT_LOCKED))
		err = -EIO;

	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
	mutex_unlock(&i915->drm.struct_mutex);

	kernel_context_close(ctx);
+12 −4
Original line number Diff line number Diff line
@@ -336,6 +336,7 @@ static int igt_evict_contexts(void *arg)
		struct drm_mm_node node;
		struct reserved *next;
	} *reserved = NULL;
	intel_wakeref_t wakeref;
	struct drm_mm_node hole;
	unsigned long count;
	int err;
@@ -355,7 +356,7 @@ static int igt_evict_contexts(void *arg)
		return 0;

	mutex_lock(&i915->drm.struct_mutex);
	intel_runtime_pm_get(i915);
	wakeref = intel_runtime_pm_get(i915);

	/* Reserve a block so that we know we have enough to fit a few rq */
	memset(&hole, 0, sizeof(hole));
@@ -400,8 +401,10 @@ static int igt_evict_contexts(void *arg)
		struct drm_file *file;

		file = mock_file(i915);
		if (IS_ERR(file))
			return PTR_ERR(file);
		if (IS_ERR(file)) {
			err = PTR_ERR(file);
			break;
		}

		count = 0;
		mutex_lock(&i915->drm.struct_mutex);
@@ -464,7 +467,7 @@ out_locked:
	}
	if (drm_mm_node_allocated(&hole))
		drm_mm_remove_node(&hole);
	intel_runtime_pm_put_unchecked(i915);
	intel_runtime_pm_put(i915, wakeref);
	mutex_unlock(&i915->drm.struct_mutex);

	return err;
@@ -480,6 +483,7 @@ int i915_gem_evict_mock_selftests(void)
		SUBTEST(igt_overcommit),
	};
	struct drm_i915_private *i915;
	intel_wakeref_t wakeref;
	int err;

	i915 = mock_gem_device();
@@ -487,7 +491,11 @@ int i915_gem_evict_mock_selftests(void)
		return -ENOMEM;

	mutex_lock(&i915->drm.struct_mutex);
	wakeref = intel_runtime_pm_get(i915);

	err = i915_subtests(tests, i915);

	intel_runtime_pm_put(i915, wakeref);
	mutex_unlock(&i915->drm.struct_mutex);

	drm_dev_put(&i915->drm);
Loading