All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Subject: [Intel-gfx] [PATCH 3/6] drm/i915/selftests: Declare suspend_state before testing suspend
Date: Wed, 10 Feb 2021 22:19:52 +0000	[thread overview]
Message-ID: <20210210221955.10025-3-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20210210221955.10025-1-chris@chris-wilson.co.uk>

As we mock the suspend routines to exercise suspending driver and
manipulating backing storage across the suspend, declare the suspend
target as we do.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/selftests/i915_gem.c | 40 +++++++++++++++++------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_gem.c b/drivers/gpu/drm/i915/selftests/i915_gem.c
index dc394fb7ccfa..6c764bcfe512 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/random.h>
+#include <linux/suspend.h>
 
 #include "gem/selftests/igt_gem_utils.h"
 #include "gem/selftests/mock_context.h"
@@ -87,25 +88,38 @@ static void simulate_hibernate(struct drm_i915_private *i915)
 	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 }
 
-static int pm_prepare(struct drm_i915_private *i915)
+static int do_prepare(struct drm_i915_private *i915)
 {
 	i915_gem_suspend(i915);
 
 	return 0;
 }
 
-static void pm_suspend(struct drm_i915_private *i915)
+static suspend_state_t set_pm_target(suspend_state_t target)
 {
+#ifdef CONFIG_PM_SLEEP
+	return xchg(&pm_suspend_target_state, target);
+#else
+	return PM_SUSPEND_ON;
+#endif
+}
+
+static suspend_state_t do_suspend(struct drm_i915_private *i915)
+{
+	suspend_state_t old = set_pm_target(PM_SUSPEND_MEM);
 	intel_wakeref_t wakeref;
 
 	with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
 		i915_ggtt_suspend(&i915->ggtt);
 		i915_gem_suspend_late(i915);
 	}
+
+	return old;
 }
 
-static void pm_hibernate(struct drm_i915_private *i915)
+static suspend_state_t do_hibernate(struct drm_i915_private *i915)
 {
+	suspend_state_t old = set_pm_target(PM_SUSPEND_MAX);
 	intel_wakeref_t wakeref;
 
 	with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
@@ -114,9 +128,11 @@ static void pm_hibernate(struct drm_i915_private *i915)
 		i915_gem_freeze(i915);
 		i915_gem_freeze_late(i915);
 	}
+
+	return old;
 }
 
-static void pm_resume(struct drm_i915_private *i915)
+static void do_resume(struct drm_i915_private *i915, suspend_state_t saved)
 {
 	intel_wakeref_t wakeref;
 
@@ -128,12 +144,15 @@ static void pm_resume(struct drm_i915_private *i915)
 		i915_ggtt_resume(&i915->ggtt);
 		i915_gem_resume(i915);
 	}
+
+	set_pm_target(saved);
 }
 
 static int igt_gem_suspend(void *arg)
 {
 	struct drm_i915_private *i915 = arg;
 	struct i915_gem_context *ctx;
+	suspend_state_t saved;
 	struct file *file;
 	int err;
 
@@ -148,16 +167,16 @@ static int igt_gem_suspend(void *arg)
 	if (err)
 		goto out;
 
-	err = pm_prepare(i915);
+	err = do_prepare(i915);
 	if (err)
 		goto out;
 
-	pm_suspend(i915);
+	saved = do_suspend(i915);
 
 	/* Here be dragons! Note that with S3RST any S3 may become S4! */
 	simulate_hibernate(i915);
 
-	pm_resume(i915);
+	do_resume(i915, saved);
 
 	err = switch_to_context(ctx);
 out:
@@ -169,6 +188,7 @@ static int igt_gem_hibernate(void *arg)
 {
 	struct drm_i915_private *i915 = arg;
 	struct i915_gem_context *ctx;
+	suspend_state_t saved;
 	struct file *file;
 	int err;
 
@@ -183,16 +203,16 @@ static int igt_gem_hibernate(void *arg)
 	if (err)
 		goto out;
 
-	err = pm_prepare(i915);
+	err = do_prepare(i915);
 	if (err)
 		goto out;
 
-	pm_hibernate(i915);
+	saved = do_hibernate(i915);
 
 	/* Here be dragons! */
 	simulate_hibernate(i915);
 
-	pm_resume(i915);
+	do_resume(i915, saved);
 
 	err = switch_to_context(ctx);
 out:
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2021-02-10 22:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 22:19 [Intel-gfx] [PATCH 1/6] drm/i915/gt: Sanitize GPU during prepare-to-suspend Chris Wilson
2021-02-10 22:19 ` [Intel-gfx] [PATCH 2/6] drm/i915: Clear internal GT state on hibernate Chris Wilson
2021-02-11  4:28   ` Rodrigo Vivi
2021-02-11  8:46     ` Chris Wilson
2021-02-10 22:19 ` Chris Wilson [this message]
2021-02-10 22:19 ` [Intel-gfx] [PATCH 4/6] drm/i915/selftests: Restrict partial-tiling to write into the object Chris Wilson
2021-02-10 22:19 ` [Intel-gfx] [PATCH 5/6] drm/i915: Check for scratch page scribbling Chris Wilson
2021-02-10 22:19 ` [Intel-gfx] [PATCH 6/6] drm/i915: Remove unused debug functions Chris Wilson
2021-02-10 23:06 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for series starting with [1/6] drm/i915/gt: Sanitize GPU during prepare-to-suspend Patchwork
2021-02-10 23:34 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2021-02-11  4:25 ` [Intel-gfx] [PATCH 1/6] " Rodrigo Vivi
2021-02-11  8:57   ` Chris Wilson
2021-02-11 13:09 ` [Intel-gfx] ✗ Fi.CI.IGT: failure for series starting with [1/6] " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210210221955.10025-3-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.