All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t 1/4] lib/igt_pm: Make exit handlers signal safe
@ 2018-07-23 11:46 ` Tvrtko Ursulin
  0 siblings, 0 replies; 33+ messages in thread
From: Tvrtko Ursulin @ 2018-07-23 11:46 UTC (permalink / raw)
  To: igt-dev; +Cc: intel-gfx

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

IGT logging helpers are not signal safe so avoid calling them from exit
handlers.

At the same time refactor the code a bit to enable following patches.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 53 insertions(+), 24 deletions(-)

diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 8ac132269d79..6f3b0a2d897d 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -66,33 +66,47 @@ enum {
 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)
+static int __igt_pm_audio_restore_runtime_pm(void)
 {
 	int fd;
 
-	igt_debug("Restoring audio power management to '%s' and '%s'\n",
-		  __igt_pm_audio_runtime_power_save,
-		  __igt_pm_audio_runtime_control);
+	if (!__igt_pm_audio_runtime_power_save[0])
+		return 0;
 
 	fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY);
 	if (fd < 0)
-		return;
+		return errno;
+
 	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);
+	    strlen(__igt_pm_audio_runtime_power_save)) {
+		close(fd);
+		return errno;
+	}
+
 	close(fd);
 
 	fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY);
 	if (fd < 0)
-		return;
+		return errno;
+
 	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);
+	    strlen(__igt_pm_audio_runtime_control)) {
+		close(fd);
+		return errno;
+	}
+
 	close(fd);
+
+	__igt_pm_audio_runtime_power_save[0] = 0;
+
+	return 0;
+}
+
+static void __igt_pm_audio_runtime_exit_handler(int sig)
+{
+	__igt_pm_audio_restore_runtime_pm();
 }
 
 static void strchomp(char *str)
@@ -297,33 +311,48 @@ 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)
+static int __igt_restore_runtime_pm(void)
 {
 	int fd;
 
-	igt_debug("Restoring runtime management to '%s' and '%s'\n",
-		  __igt_pm_runtime_autosuspend,
-		  __igt_pm_runtime_control);
+	if (pm_status_fd < 0)
+		return 0;
 
 	fd = open(POWER_DIR "/autosuspend_delay_ms", O_WRONLY);
 	if (fd < 0)
-		return;
+		return errno;
+
 	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);
+	    strlen(__igt_pm_runtime_autosuspend)) {
+		close(fd);
+		return errno;
+	}
+
 	close(fd);
 
 	fd = open(POWER_DIR "/control", O_WRONLY);
 	if (fd < 0)
-		return;
+		return errno;
+
 	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);
+	    strlen(__igt_pm_runtime_control)) {
+		close(fd);
+		return errno;
+	}
+
 	close(fd);
+
+	close(pm_status_fd);
+	pm_status_fd = -1;
+
+	return 0;
+}
+
+static void __igt_pm_runtime_exit_handler(int sig)
+{
+	__igt_restore_runtime_pm();
 }
 
 /**
-- 
2.17.1

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

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

end of thread, other threads:[~2018-07-26 17:08 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-23 11:46 [PATCH i-g-t 1/4] lib/igt_pm: Make exit handlers signal safe Tvrtko Ursulin
2018-07-23 11:46 ` [igt-dev] " Tvrtko Ursulin
2018-07-23 11:46 ` [PATCH i-g-t 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM Tvrtko Ursulin
2018-07-23 11:46   ` [Intel-gfx] " Tvrtko Ursulin
2018-07-23 12:46   ` [PATCH i-g-t v2 " Tvrtko Ursulin
2018-07-23 12:46     ` [Intel-gfx] " Tvrtko Ursulin
2018-07-23 12:54     ` [igt-dev] " Chris Wilson
2018-07-23 12:54       ` [Intel-gfx] " Chris Wilson
2018-07-23 15:31       ` [PATCH i-g-t v3 " Tvrtko Ursulin
2018-07-23 15:31         ` [igt-dev] " Tvrtko Ursulin
2018-07-24  9:59         ` [PATCH i-g-t v4 " Tvrtko Ursulin
2018-07-24  9:59           ` [igt-dev] " Tvrtko Ursulin
2018-07-24 10:08           ` [PATCH i-g-t v5 " Tvrtko Ursulin
2018-07-24 10:08             ` [igt-dev] " Tvrtko Ursulin
2018-07-24 10:29             ` [PATCH i-g-t v6 " Tvrtko Ursulin
2018-07-24 10:29               ` [Intel-gfx] " Tvrtko Ursulin
2018-07-24 12:27               ` [igt-dev] " Chris Wilson
2018-07-24 12:27                 ` [Intel-gfx] " Chris Wilson
2018-07-23 11:46 ` [PATCH i-g-t 3/4] lib/igt_pm: Export function to restore runtime PM status Tvrtko Ursulin
2018-07-23 11:46   ` [igt-dev] " Tvrtko Ursulin
2018-07-23 11:46 ` [PATCH i-g-t 4/4] tests/perf_pmu: Restore runtime PM status at rc6 test exit Tvrtko Ursulin
2018-07-23 11:46   ` [igt-dev] " Tvrtko Ursulin
2018-07-23 12:37 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe Patchwork
2018-07-23 13:12 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev2) Patchwork
2018-07-23 13:58 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe Patchwork
2018-07-23 15:20 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev2) Patchwork
2018-07-23 15:54 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev3) Patchwork
2018-07-23 16:35   ` Tvrtko Ursulin
2018-07-24 10:34 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev5) Patchwork
2018-07-24 10:50 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev6) Patchwork
2018-07-24 11:27 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev5) Patchwork
2018-07-24 12:07 ` [igt-dev] ✗ Fi.CI.IGT: failure for series starting with [i-g-t,1/4] lib/igt_pm: Make exit handlers signal safe (rev6) Patchwork
2018-07-26 17:08 ` [igt-dev] ✓ Fi.CI.BAT: success " 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.