[PATCH 22/27] gpu trash

Matthew Auld matthew.auld at intel.com
Wed Oct 2 11:04:29 UTC 2019


Signed-off-by: Matthew Auld <matthew.auld at intel.com>
---
 drivers/gpu/drm/i915/selftests/i915_gem.c | 96 ++++++++++++++++++-----
 1 file changed, 77 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_gem.c b/drivers/gpu/drm/i915/selftests/i915_gem.c
index 4951957a4d8d..cc560750d88f 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem.c
@@ -6,6 +6,8 @@
 
 #include <linux/random.h>
 
+#include "gem/i915_gem_region.h"
+#include "gem/i915_gem_object_blt.h"
 #include "gem/selftests/igt_gem_utils.h"
 #include "gem/selftests/mock_context.h"
 #include "gt/intel_gt.h"
@@ -34,16 +36,24 @@ static int switch_to_context(struct drm_i915_private *i915,
 	return 0;
 }
 
-static void trash_stolen(struct drm_i915_private *i915)
+static void trash_stolen_cpu(struct drm_i915_private *i915)
 {
+	const resource_size_t size = resource_size(&i915->dsm);
 	struct i915_ggtt *ggtt = &i915->ggtt;
 	const u64 slot = ggtt->error_capture.start;
-	const resource_size_t size = resource_size(&i915->dsm);
-	unsigned long page;
+	intel_wakeref_t wakeref;
 	u32 prng = 0x12345678;
+	unsigned long page;
 
-	if (!HAS_MAPPABLE_APERTURE(i915))
-		return;
+	/*
+	 * As a final sting in the tail, invalidate stolen. Under a real S4,
+	 * stolen is lost and needs to be refilled on resume. However, under
+	 * CI we merely do S4-device testing (as full S4 is too unreliable
+	 * for automated testing across a cluster), so to simulate the effect
+	 * of stolen being trashed across S4, we trash it ourselves.
+	 */
+
+	wakeref = intel_runtime_pm_get(&i915->runtime_pm);
 
 	for (page = 0; page < size; page += PAGE_SIZE) {
 		const dma_addr_t dma = i915->dsm.start + page;
@@ -61,24 +71,55 @@ static void trash_stolen(struct drm_i915_private *i915)
 	}
 
 	ggtt->vm.clear_range(&ggtt->vm, slot, PAGE_SIZE);
+
+	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 }
 
-static void simulate_hibernate(struct drm_i915_private *i915)
+static void trash_stolen_gpu(struct i915_gem_context *ctx)
 {
-	intel_wakeref_t wakeref;
+	struct drm_i915_private *i915 = ctx->vm->i915;
+	const resource_size_t size = resource_size(&i915->dsm);
+	struct intel_memory_region *clone;
+	struct drm_i915_gem_object *obj;
+	struct intel_context *ce;
+	u32 prng = 0x12345678;
+	int err;
 
-	wakeref = intel_runtime_pm_get(&i915->runtime_pm);
+	if (!HAS_ENGINE(i915, BCS0))
+		return;
 
-	/*
-	 * As a final sting in the tail, invalidate stolen. Under a real S4,
-	 * stolen is lost and needs to be refilled on resume. However, under
-	 * CI we merely do S4-device testing (as full S4 is too unreliable
-	 * for automated testing across a cluster), so to simulate the effect
-	 * of stolen being trashed across S4, we trash it ourselves.
-	 */
-	trash_stolen(i915);
+	if (!size)
+		return;
 
-	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
+	clone = mock_region_create(i915, i915->dsm.start, size, PAGE_SIZE, 0);
+	if (IS_ERR(clone)) {
+		WARN_ON(1);
+		return;
+	}
+
+	obj = i915_gem_object_create_region(clone, size, 0);
+	if (IS_ERR(obj)) {
+		WARN_ON(1);
+		return;
+	}
+
+	ce = i915_gem_context_get_engine(ctx, BCS0);
+	if (IS_ERR(ce)) {
+		WARN_ON(1);
+		return;
+	}
+
+	mutex_lock(&i915->drm.struct_mutex);
+	err = i915_gem_object_fill_blt(obj, ce, prng);
+	mutex_unlock(&i915->drm.struct_mutex);
+
+	intel_context_put(ce);
+	i915_gem_object_put(obj);
+	intel_memory_region_put(clone);
+	if (err) {
+		WARN_ON(1);
+		return;
+	}
 }
 
 static int pm_prepare(struct drm_i915_private *i915)
@@ -151,6 +192,18 @@ static int igt_gem_suspend(void *arg)
 	if (err)
 		goto out;
 
+	/*
+	 * If we lack the mappable aperture we can't really access stolen from
+	 * the cpu, but we can always trash it from the gpu, we just need to do
+	 * so early, before we start suspending stuff. We shouldn't see any
+	 * hangs doing this so early, since things like ring state won't be
+	 * allocated in stolen if we can't access it from the cpu. Although if
+	 * that's the case maybe there is not much point in bothering with this
+	 * anyway...
+	 */
+	if (!HAS_MAPPABLE_APERTURE(i915))
+		trash_stolen_gpu(ctx);
+
 	err = pm_prepare(i915);
 	if (err)
 		goto out;
@@ -158,7 +211,8 @@ static int igt_gem_suspend(void *arg)
 	pm_suspend(i915);
 
 	/* Here be dragons! Note that with S3RST any S3 may become S4! */
-	simulate_hibernate(i915);
+	if (HAS_MAPPABLE_APERTURE(i915))
+		trash_stolen_cpu(i915);
 
 	pm_resume(i915);
 
@@ -190,6 +244,9 @@ static int igt_gem_hibernate(void *arg)
 	if (err)
 		goto out;
 
+	if (!HAS_MAPPABLE_APERTURE(i915))
+		trash_stolen_gpu(ctx);
+
 	err = pm_prepare(i915);
 	if (err)
 		goto out;
@@ -197,7 +254,8 @@ static int igt_gem_hibernate(void *arg)
 	pm_hibernate(i915);
 
 	/* Here be dragons! */
-	simulate_hibernate(i915);
+	if (HAS_MAPPABLE_APERTURE(i915))
+		trash_stolen_cpu(i915);
 
 	pm_resume(i915);
 
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list