From: Tvrtko Ursulin <tursulin@ursulin.net>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t 1/4] lib/igt_pm: Make exit handlers signal safe
Date: Mon, 23 Jul 2018 12:46:55 +0100 [thread overview]
Message-ID: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> (raw)
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
next reply other threads:[~2018-07-23 11:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 11:46 Tvrtko Ursulin [this message]
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 12:46 ` [PATCH i-g-t v2 " Tvrtko Ursulin
2018-07-23 12:54 ` [igt-dev] " Chris Wilson
2018-07-23 15:31 ` [PATCH i-g-t v3 " Tvrtko Ursulin
2018-07-24 9:59 ` [PATCH i-g-t v4 " Tvrtko Ursulin
2018-07-24 10:08 ` [PATCH i-g-t v5 " Tvrtko Ursulin
2018-07-24 10:29 ` [PATCH i-g-t v6 " Tvrtko Ursulin
2018-07-24 12:27 ` [igt-dev] " 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 ` [PATCH i-g-t 4/4] tests/perf_pmu: Restore runtime PM status at rc6 test exit Tvrtko Ursulin
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=20180723114658.13025-1-tvrtko.ursulin@linux.intel.com \
--to=tursulin@ursulin.net \
--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