summaryrefslogtreecommitdiff
path: root/lib/igt_pm.c
diff options
context:
space:
mode:
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>2018-07-23 12:46:55 +0100
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>2018-08-02 11:32:11 +0100
commit9615bbc7259d5113f7ded9419487bd52d1e708b9 (patch)
tree031037a750d613de2c6de2e8a96bc75b5df6e386 /lib/igt_pm.c
parent111829d21847a2353c57ef67e70fbc3de8280602 (diff)
lib/igt_pm: Make exit handlers signal safe
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> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_pm.c')
-rw-r--r--lib/igt_pm.c77
1 files changed, 53 insertions, 24 deletions
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 8ac13226..6f3b0a2d 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();
}
/**