public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 6/7] lib/igt_aux: Add helper to query suspend-to-mem modes
Date: Wed, 13 Nov 2019 17:49:12 +0200	[thread overview]
Message-ID: <20191113154913.8787-6-mika.kuoppala@linux.intel.com> (raw)
In-Reply-To: <20191113154913.8787-1-mika.kuoppala@linux.intel.com>

From: Imre Deak <imre.deak@intel.com>

Add a helper to query the supported and currently selected
suspend-to-mem modes.

v2:
- Fix for old kernels where the mem_sleep sysfs file didn't yet exist.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/igt_aux.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_aux.h | 24 +++++++++++++++
 2 files changed, 105 insertions(+)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 578f8579..f2cb3247 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -827,6 +827,87 @@ static uint32_t get_supported_suspend_states(int power_dir)
 	return state_mask;
 }
 
+static const char *suspend_to_mem_mode_name[] = {
+	[SUSPEND_TO_MEM_S2IDLE] = "s2idle",
+	[SUSPEND_TO_MEM_SHALLOW] = "shallow",
+	[SUSPEND_TO_MEM_DEEP] = "deep",
+};
+
+static uint32_t
+get_supported_suspend_to_mem_modes(int power_dir,
+				   enum igt_suspend_to_mem_mode *selected_mode)
+{
+	char *modes;
+	char *mode_name;
+	uint32_t mode_mask;
+	bool selected_found = false;
+
+	/*
+	 * Other modes than deep sleep were only introduced with the mem_sleep
+	 * sysfs file.
+	 */
+	modes = igt_sysfs_get(power_dir, "mem_sleep");
+	if (!modes) {
+		*selected_mode = SUSPEND_TO_MEM_DEEP;
+		return 1 << SUSPEND_TO_MEM_DEEP;
+	}
+
+	mode_mask = 0;
+	for (mode_name = strtok(modes, " "); mode_name;
+	     mode_name = strtok(NULL, " ")) {
+		enum igt_suspend_to_mem_mode mode;
+		bool selected = false;
+
+		if (mode_name[0] == '[') {
+			char *e = &mode_name[strlen(mode_name) - 1];
+
+			igt_assert(!selected_found);
+			igt_assert(*e == ']');
+			mode_name++;
+			*e = '\0';
+
+			selected = true;
+		}
+
+		for (mode = SUSPEND_TO_MEM_S2IDLE;
+		     mode < SUSPEND_TO_MEM_NUM;
+		     mode++)
+			if (strcmp(mode_name,
+				   suspend_to_mem_mode_name[mode]) == 0)
+				break;
+		igt_assert(mode < SUSPEND_TO_MEM_NUM);
+		mode_mask |= 1 << mode;
+		if (selected) {
+			selected_found = true;
+			if (selected_mode)
+				*selected_mode = mode;
+		}
+	}
+
+	igt_assert(selected_found);
+
+	free(modes);
+
+	return mode_mask;
+}
+
+/**
+ * igt_get_suspend_to_mem_mode:
+ *
+ * Returns the currently selected @igt_suspend_to_mem_mode.
+ */
+enum igt_suspend_to_mem_mode igt_get_suspend_to_mem_mode(void)
+{
+	int power_dir;
+	enum igt_suspend_to_mem_mode mode;
+
+	igt_require((power_dir = open("/sys/power", O_RDONLY)) >= 0);
+	(void)get_supported_suspend_to_mem_modes(power_dir, &mode);
+	close(power_dir);
+
+	return mode;
+}
+
 /**
  * igt_system_suspend_autoresume:
  * @state: an #igt_suspend_state, the target suspend state
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 04d22904..7ccaa8c4 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -184,10 +184,34 @@ enum igt_suspend_test {
 	SUSPEND_TEST_NUM,
 };
 
+/**
+ * igt_suspend_to_mem_mode:
+ * @SUSPEND_TO_MEM_S2IDLE: suspend to mem maps to @SUSPEND_STATE_FREEZE
+ * @SUSPEND_TO_MEM_SHALLOW: suspend to mem maps to @SUSPEND_STATE_STANDBY
+ * @SUSPEND_TO_MEM_DEEP: suspend to mem will target the ACPI S3 state
+ *
+ * The target system state when suspending to mem:
+ * - Suspending with @SUSPEND_STATE_MEM/@SUSPEND_TO_MEM_S2IDLE is equivalent to
+ *   suspending with @SUSPEND_STATE_FREEZE.
+ * - Suspending with @SUSPEND_STATE_MEM/@SUSPEND_TO_MEM_SHALLOW is equivalent to
+ *   suspending with @SUSPEND_STATE_STANDBY.
+ * - Suspending with @SUSPEND_STATE_MEM/@SUSPEND_TO_MEM_DEEP will target the
+ *   ACPI S3 state.
+ */
+enum igt_suspend_to_mem_mode {
+	SUSPEND_TO_MEM_S2IDLE,
+	SUSPEND_TO_MEM_SHALLOW,
+	SUSPEND_TO_MEM_DEEP,
+
+	/*< private >*/
+	SUSPEND_TO_MEM_NUM,
+};
+
 void igt_system_suspend_autoresume(enum igt_suspend_state state,
 				   enum igt_suspend_test test);
 void igt_set_autoresume_delay(int delay_secs);
 int igt_get_autoresume_delay(enum igt_suspend_state state);
+enum igt_suspend_to_mem_mode igt_get_suspend_to_mem_mode(void);
 
 /* dropping priviledges */
 void igt_drop_root(void);
-- 
2.17.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-11-13 15:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-13 15:49 [Intel-gfx] [PATCH i-g-t 1/7] lib/igt_dummyload: Send batch as first Mika Kuoppala
2019-11-13 15:49 ` [igt-dev] [PATCH i-g-t 2/7] igt: Use COND_BBEND for busy spinning on gen9 Mika Kuoppala
2019-11-13 16:02   ` [Intel-gfx] " Chris Wilson
2019-11-13 17:19     ` Mika Kuoppala
2019-11-13 15:49 ` [igt-dev] [PATCH i-g-t 3/7] lib/i915: Add query to detect if engine accepts only ro batches Mika Kuoppala
2019-11-13 23:44   ` [igt-dev] [Intel-gfx] " Chris Wilson
2019-11-13 23:55   ` Chris Wilson
2019-11-13 15:49 ` [igt-dev] [PATCH i-g-t 4/7] tests/i915: Skip if secure batches is not available Mika Kuoppala
2019-11-13 15:49 ` [igt-dev] [PATCH i-g-t 5/7] Add tests/gem_blt_parse Mika Kuoppala
2019-11-13 16:14   ` Chris Wilson
2019-11-13 16:37     ` Mika Kuoppala
2019-11-14  8:41   ` Daniel Vetter
2019-11-13 15:49 ` Mika Kuoppala [this message]
2019-11-13 15:49 ` [Intel-gfx] [PATCH i-g-t 7/7] test/i915: Add i915_rc6_ctx_corruption Mika Kuoppala
2019-11-13 16:18   ` [igt-dev] " Chris Wilson
2019-11-13 15:57 ` [Intel-gfx] [PATCH i-g-t 1/7] lib/igt_dummyload: Send batch as first Chris Wilson

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=20191113154913.8787-6-mika.kuoppala@linux.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox