All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] lib/igt_pm: Restore runtime pm state on test exit
@ 2018-02-28 11:08 ` Tvrtko Ursulin
  0 siblings, 0 replies; 31+ messages in thread
From: Tvrtko Ursulin @ 2018-02-28 11:08 UTC (permalink / raw)
  To: igt-dev; +Cc: Intel-gfx

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Some tests (the ones which call igt_setup_runtime_pm and
igt_pm_enable_audio_runtime_pm) change default system configuration and
never restore it.

The configured runtime suspend is aggressive and may influence behaviour
of subsequent tests, so it is better to restore to previous values on test
exit.

This way system behaviour, with regards to a random sequence of executed
tests, will be more consistent from one run to another.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
---
 lib/igt_pm.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 104 insertions(+), 3 deletions(-)

diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 5bf5b2e23cdc..0c8b5e8e9257 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -63,6 +63,46 @@ enum {
 /* Remember to fix this if adding longer strings */
 #define MAX_POLICY_STRLEN	strlen(MAX_PERFORMANCE_STR)
 
+static char __igt_pm_audio_runtime_power_save[64];
+static char __igt_pm_audio_runtime_control[64];
+
+static void __igt_pm_audio_runtime_exit_handler(int sig)
+{
+	int fd;
+
+	igt_debug("Restoring audio power management to '%s' and '%s'\n",
+		  __igt_pm_audio_runtime_power_save,
+		  __igt_pm_audio_runtime_control);
+
+	fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY);
+	if (fd < 0)
+		return;
+	if (write(fd, __igt_pm_audio_runtime_power_save,
+		  strlen(__igt_pm_audio_runtime_power_save)) !=
+	    strlen(__igt_pm_audio_runtime_power_save))
+		igt_warn("Failed to restore audio power_save to '%s'\n",
+			 __igt_pm_audio_runtime_power_save);
+	close(fd);
+
+	fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY);
+	if (fd < 0)
+		return;
+	if (write(fd, __igt_pm_audio_runtime_control,
+		  strlen(__igt_pm_audio_runtime_control)) !=
+	    strlen(__igt_pm_audio_runtime_control))
+		igt_warn("Failed to restore audio control to '%s'\n",
+			 __igt_pm_audio_runtime_control);
+	close(fd);
+}
+
+static void strchomp(char *str)
+{
+	int len = strlen(str);
+
+	if (str[len - 1] == '\n')
+		str[len - 1] = 0;
+}
+
 /**
  * igt_pm_enable_audio_runtime_pm:
  *
@@ -78,16 +118,32 @@ void igt_pm_enable_audio_runtime_pm(void)
 {
 	int fd;
 
-	fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY);
+	/* Check if already enabled. */
+	if (__igt_pm_audio_runtime_power_save[0])
+		return;
+
+	fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
 	if (fd >= 0) {
+		igt_assert(read(fd, __igt_pm_audio_runtime_power_save,
+				sizeof(__igt_pm_audio_runtime_power_save)) > 0);
+		strchomp(__igt_pm_audio_runtime_power_save);
 		igt_assert_eq(write(fd, "1\n", 2), 2);
+		igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
 		close(fd);
 	}
-	fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY);
+	fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_RDWR);
 	if (fd >= 0) {
+		igt_assert(read(fd, __igt_pm_audio_runtime_control,
+				sizeof(__igt_pm_audio_runtime_control)) > 0);
+		strchomp(__igt_pm_audio_runtime_control);
 		igt_assert_eq(write(fd, "auto\n", 5), 5);
 		close(fd);
 	}
+
+	igt_debug("Saved audio power management as '%s' and '%s'\n",
+		  __igt_pm_audio_runtime_power_save,
+		  __igt_pm_audio_runtime_control);
+
 	/* Give some time for it to react. */
 	sleep(1);
 }
@@ -238,6 +294,38 @@ void igt_pm_restore_sata_link_power_management(int8_t *pm_data)
 /* We just leak this on exit ... */
 int pm_status_fd = -1;
 
+static char __igt_pm_runtime_autosuspend[64];
+static char __igt_pm_runtime_control[64];
+
+static void __igt_pm_runtime_exit_handler(int sig)
+{
+	int fd;
+
+	igt_debug("Restoring runtime management to '%s' and '%s'\n",
+		  __igt_pm_runtime_autosuspend,
+		  __igt_pm_runtime_control);
+
+	fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY);
+	if (fd < 0)
+		return;
+	if (write(fd, __igt_pm_runtime_autosuspend,
+		  strlen(__igt_pm_runtime_autosuspend)) !=
+	    strlen(__igt_pm_runtime_autosuspend))
+		igt_warn("Failed to restore runtime pm autosuspend delay to '%s'\n",
+			 __igt_pm_runtime_autosuspend);
+	close(fd);
+
+	fd = open(POWER_DIR "/control", O_WRONLY);
+	if (fd < 0)
+		return;
+	if (write(fd, __igt_pm_runtime_control,
+		  strlen(__igt_pm_runtime_control)) !=
+	    strlen(__igt_pm_runtime_control))
+		igt_warn("Failed to restore runtime pm control to '%s'\n",
+			 __igt_pm_runtime_control);
+	close(fd);
+}
+
 /**
  * igt_setup_runtime_pm:
  *
@@ -261,10 +349,16 @@ bool igt_setup_runtime_pm(void)
 	/* Our implementation uses autosuspend. Try to set it to 0ms so the test
 	 * suite goes faster and we have a higher probability of triggering race
 	 * conditions. */
-	fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY);
+	fd = open(POWER_DIR "/autosuspend_delay_ms", O_RDWR);
 	igt_assert_f(fd >= 0,
 		     "Can't open " POWER_DIR "/autosuspend_delay_ms\n");
 
+	/* Save previous values and install exit handler to restore them. */
+	igt_assert(read(fd, __igt_pm_runtime_autosuspend,
+			sizeof(__igt_pm_runtime_autosuspend)) > 0);
+	strchomp(__igt_pm_runtime_autosuspend);
+	igt_install_exit_handler(__igt_pm_runtime_exit_handler);
+
 	/* If we fail to write to the file, it means this system doesn't support
 	 * runtime PM. */
 	size = write(fd, "0\n", 2);
@@ -278,6 +372,13 @@ bool igt_setup_runtime_pm(void)
 	fd = open(POWER_DIR "/control", O_RDWR);
 	igt_assert_f(fd >= 0, "Can't open " POWER_DIR "/control\n");
 
+	igt_assert(read(fd, __igt_pm_runtime_control,
+			sizeof(__igt_pm_runtime_control)) > 0);
+	strchomp(__igt_pm_runtime_control);
+
+	igt_debug("Saved runtime power management as '%s' and '%s'\n",
+		  __igt_pm_runtime_autosuspend, __igt_pm_runtime_control);
+
 	size = write(fd, "auto\n", 5);
 	igt_assert(size == 5);
 
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2018-03-05 10:20 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 11:08 [PATCH i-g-t] lib/igt_pm: Restore runtime pm state on test exit Tvrtko Ursulin
2018-02-28 11:08 ` [igt-dev] " Tvrtko Ursulin
2018-02-28 11:12 ` Chris Wilson
2018-02-28 11:12   ` [igt-dev] [Intel-gfx] " Chris Wilson
2018-02-28 11:38   ` Tvrtko Ursulin
2018-02-28 11:38     ` [Intel-gfx] " Tvrtko Ursulin
2018-02-28 12:27     ` Chris Wilson
2018-02-28 12:27       ` [igt-dev] [Intel-gfx] " Chris Wilson
2018-02-28 14:33       ` Tvrtko Ursulin
2018-02-28 14:33         ` [igt-dev] [Intel-gfx] " Tvrtko Ursulin
2018-02-28 12:50 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork
2018-02-28 15:17   ` Tvrtko Ursulin
2018-02-28 14:23 ` [PATCH i-g-t] " Chris Wilson
2018-02-28 14:23   ` [igt-dev] [Intel-gfx] " Chris Wilson
2018-02-28 15:35 ` [PATCH i-g-t v2] " Tvrtko Ursulin
2018-02-28 15:35   ` [Intel-gfx] " Tvrtko Ursulin
2018-03-01  8:12   ` Chris Wilson
2018-03-01  8:12     ` [igt-dev] [Intel-gfx] " Chris Wilson
2018-03-02  9:29   ` Imre Deak
2018-03-02  9:29     ` [igt-dev] " Imre Deak
2018-03-02  9:51     ` [PATCH i-g-t v3] " Tvrtko Ursulin
2018-03-02  9:51       ` [Intel-gfx] " Tvrtko Ursulin
2018-03-02  9:56     ` [PATCH i-g-t v2] " Tvrtko Ursulin
2018-03-02  9:56       ` [igt-dev] [Intel-gfx] " Tvrtko Ursulin
2018-03-02 12:29       ` Imre Deak
2018-03-02 12:29         ` [igt-dev] [Intel-gfx] " Imre Deak
2018-02-28 16:33 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_pm: Restore runtime pm state on test exit (rev2) Patchwork
2018-02-28 20:22 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-03-02 18:21 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_pm: Restore runtime pm state on test exit (rev3) Patchwork
2018-03-05  9:04 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2018-03-05 10:20 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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.