From: Tvrtko Ursulin <tursulin@ursulin.net>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org,
Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [PATCH i-g-t v3] tests/perf_pmu: Restore runtime PM at subtest exit
Date: Fri, 20 Jul 2018 13:12:22 +0100 [thread overview]
Message-ID: <20180720121222.31090-1-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <153208022343.25018.4045411798193903976@skylake-alporthouse-com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Restore runtime PM state (via a newly added library function) when the
test which sets it up exit. This was we avoid running all subsequent sub-
tests in the aggressive runtime PM mode.
v2:
* Skip double restore. (Chris Wilson)
* Close previously leaked fd.
v3:
* Refactor atexit handlers to be signal safe. (Chris Wilson)
* Restore audio runtime PM status.
* Add a different PCI path to audio device.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 152 ++++++++++++++++++++++++++++++++++++-----------
lib/igt_pm.h | 1 +
tests/perf_pmu.c | 3 +
3 files changed, 122 insertions(+), 34 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 8ac132269d79..1fe8f5f46399 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -63,36 +63,73 @@ enum {
/* Remember to fix this if adding longer strings */
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
+static const char *const __igt_pm_audio_runtime_control_paths[] = {
+ "/sys/bus/pci/devices/0000:00:03.0/power/control",
+ "/sys/bus/pci/devices/0000:00:1f.3/power/control",
+};
+
static char __igt_pm_audio_runtime_power_save[64];
+static const char * __igt_pm_audio_runtime_control_path;
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);
+ fd = open(__igt_pm_audio_runtime_control_path, 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_restore_runtime_pm(void)
+{
+ int ret;
+
+ if (!__igt_pm_audio_runtime_power_save[0])
+ return;
+
+ igt_debug("Restoring audio power management to '%s' and '%s'\n",
+ __igt_pm_audio_runtime_power_save,
+ __igt_pm_audio_runtime_control);
+
+ ret = __igt_pm_audio_restore_runtime_pm();
+ if (ret)
+ igt_warn("Failed to restore runtime audio PM! (errno=%d)\n",
+ ret);
+}
+
+static void __igt_pm_audio_runtime_exit_handler(int sig)
+{
+ __igt_pm_audio_restore_runtime_pm();
}
static void strchomp(char *str)
@@ -116,7 +153,7 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
- int fd;
+ int fd, i;
/* Check if already enabled. */
if (__igt_pm_audio_runtime_power_save[0])
@@ -131,14 +168,23 @@ void igt_pm_enable_audio_runtime_pm(void)
igt_assert_eq(write(fd, "1\n", 2), 2);
close(fd);
}
- 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);
+
+ for (i = 0; i < ARRAY_SIZE(__igt_pm_audio_runtime_control_paths); i++) {
+ const char *path = __igt_pm_audio_runtime_control_paths[i];
+
+ fd = open(path, O_RDWR);
+ if (fd >= 0) {
+ __igt_pm_audio_runtime_control_path = path;
+ 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);
+ break;
+ }
}
+ if (!__igt_pm_audio_runtime_control_path)
+ igt_warn("Failed to find audio PCI device!\n");
igt_debug("Saved audio power management as '%s' and '%s'\n",
__igt_pm_audio_runtime_power_save,
@@ -291,39 +337,77 @@ void igt_pm_restore_sata_link_power_management(int8_t *pm_data)
free(file_name);
}
#define POWER_DIR "/sys/devices/pci0000:00/0000:00:02.0/power"
-/* 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)
+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;
+}
+
+/**
+ * igt_restore_runtime_pm:
+ *
+ * Restores the runtime PM configuration as it was before the call to
+ * igt_setup_runtime_pm.
+ */
+void igt_restore_runtime_pm(void)
+{
+ int ret;
+
+ if (pm_status_fd < 0)
+ return;
+
+ igt_debug("Restoring runtime PM management to '%s' and '%s'\n",
+ __igt_pm_runtime_autosuspend,
+ __igt_pm_runtime_control);
+
+ ret = __igt_restore_runtime_pm();
+ if (ret)
+ igt_warn("Failed to restore runtime PM! (errno=%d)\n", ret);
+
+ igt_pm_audio_restore_runtime_pm();
+}
+
+static void __igt_pm_runtime_exit_handler(int sig)
+{
+ __igt_restore_runtime_pm();
}
/**
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index eced39f8801a..10cc6794e4e7 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -47,6 +47,7 @@ enum igt_runtime_pm_status {
};
bool igt_setup_runtime_pm(void);
+void igt_restore_runtime_pm(void);
enum igt_runtime_pm_status igt_get_runtime_pm_status(void);
bool igt_wait_for_pm_status(enum igt_runtime_pm_status status);
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index a1d36ac4fa9d..9a20abb6b95c 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -1441,6 +1441,9 @@ test_rc6(int gem_fd, unsigned int flags)
close(fw);
close(fd);
+ if (flags & TEST_RUNTIME_PM)
+ igt_restore_runtime_pm();
+
assert_within_epsilon(busy - prev, 0.0, tolerance);
}
--
2.17.1
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tursulin@ursulin.net>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t v3] tests/perf_pmu: Restore runtime PM at subtest exit
Date: Fri, 20 Jul 2018 13:12:22 +0100 [thread overview]
Message-ID: <20180720121222.31090-1-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <153208022343.25018.4045411798193903976@skylake-alporthouse-com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Restore runtime PM state (via a newly added library function) when the
test which sets it up exit. This was we avoid running all subsequent sub-
tests in the aggressive runtime PM mode.
v2:
* Skip double restore. (Chris Wilson)
* Close previously leaked fd.
v3:
* Refactor atexit handlers to be signal safe. (Chris Wilson)
* Restore audio runtime PM status.
* Add a different PCI path to audio device.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 152 ++++++++++++++++++++++++++++++++++++-----------
lib/igt_pm.h | 1 +
tests/perf_pmu.c | 3 +
3 files changed, 122 insertions(+), 34 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 8ac132269d79..1fe8f5f46399 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -63,36 +63,73 @@ enum {
/* Remember to fix this if adding longer strings */
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
+static const char *const __igt_pm_audio_runtime_control_paths[] = {
+ "/sys/bus/pci/devices/0000:00:03.0/power/control",
+ "/sys/bus/pci/devices/0000:00:1f.3/power/control",
+};
+
static char __igt_pm_audio_runtime_power_save[64];
+static const char * __igt_pm_audio_runtime_control_path;
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);
+ fd = open(__igt_pm_audio_runtime_control_path, 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_restore_runtime_pm(void)
+{
+ int ret;
+
+ if (!__igt_pm_audio_runtime_power_save[0])
+ return;
+
+ igt_debug("Restoring audio power management to '%s' and '%s'\n",
+ __igt_pm_audio_runtime_power_save,
+ __igt_pm_audio_runtime_control);
+
+ ret = __igt_pm_audio_restore_runtime_pm();
+ if (ret)
+ igt_warn("Failed to restore runtime audio PM! (errno=%d)\n",
+ ret);
+}
+
+static void __igt_pm_audio_runtime_exit_handler(int sig)
+{
+ __igt_pm_audio_restore_runtime_pm();
}
static void strchomp(char *str)
@@ -116,7 +153,7 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
- int fd;
+ int fd, i;
/* Check if already enabled. */
if (__igt_pm_audio_runtime_power_save[0])
@@ -131,14 +168,23 @@ void igt_pm_enable_audio_runtime_pm(void)
igt_assert_eq(write(fd, "1\n", 2), 2);
close(fd);
}
- 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);
+
+ for (i = 0; i < ARRAY_SIZE(__igt_pm_audio_runtime_control_paths); i++) {
+ const char *path = __igt_pm_audio_runtime_control_paths[i];
+
+ fd = open(path, O_RDWR);
+ if (fd >= 0) {
+ __igt_pm_audio_runtime_control_path = path;
+ 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);
+ break;
+ }
}
+ if (!__igt_pm_audio_runtime_control_path)
+ igt_warn("Failed to find audio PCI device!\n");
igt_debug("Saved audio power management as '%s' and '%s'\n",
__igt_pm_audio_runtime_power_save,
@@ -291,39 +337,77 @@ void igt_pm_restore_sata_link_power_management(int8_t *pm_data)
free(file_name);
}
#define POWER_DIR "/sys/devices/pci0000:00/0000:00:02.0/power"
-/* 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)
+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;
+}
+
+/**
+ * igt_restore_runtime_pm:
+ *
+ * Restores the runtime PM configuration as it was before the call to
+ * igt_setup_runtime_pm.
+ */
+void igt_restore_runtime_pm(void)
+{
+ int ret;
+
+ if (pm_status_fd < 0)
+ return;
+
+ igt_debug("Restoring runtime PM management to '%s' and '%s'\n",
+ __igt_pm_runtime_autosuspend,
+ __igt_pm_runtime_control);
+
+ ret = __igt_restore_runtime_pm();
+ if (ret)
+ igt_warn("Failed to restore runtime PM! (errno=%d)\n", ret);
+
+ igt_pm_audio_restore_runtime_pm();
+}
+
+static void __igt_pm_runtime_exit_handler(int sig)
+{
+ __igt_restore_runtime_pm();
}
/**
diff --git a/lib/igt_pm.h b/lib/igt_pm.h
index eced39f8801a..10cc6794e4e7 100644
--- a/lib/igt_pm.h
+++ b/lib/igt_pm.h
@@ -47,6 +47,7 @@ enum igt_runtime_pm_status {
};
bool igt_setup_runtime_pm(void);
+void igt_restore_runtime_pm(void);
enum igt_runtime_pm_status igt_get_runtime_pm_status(void);
bool igt_wait_for_pm_status(enum igt_runtime_pm_status status);
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index a1d36ac4fa9d..9a20abb6b95c 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -1441,6 +1441,9 @@ test_rc6(int gem_fd, unsigned int flags)
close(fw);
close(fd);
+ if (flags & TEST_RUNTIME_PM)
+ igt_restore_runtime_pm();
+
assert_within_epsilon(busy - prev, 0.0, tolerance);
}
--
2.17.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2018-07-20 12:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-19 16:37 [igt-dev] [PATCH i-g-t] tests/perf_pmu: Restore runtime PM at subtest exit Tvrtko Ursulin
2018-07-19 16:37 ` Tvrtko Ursulin
2018-07-19 16:48 ` [igt-dev] " Chris Wilson
2018-07-19 16:48 ` Chris Wilson
2018-07-20 9:42 ` [Intel-gfx] [PATCH i-g-t v2] " Tvrtko Ursulin
2018-07-20 9:42 ` Tvrtko Ursulin
2018-07-20 9:50 ` [igt-dev] " Chris Wilson
2018-07-20 9:50 ` Chris Wilson
2018-07-20 12:12 ` Tvrtko Ursulin [this message]
2018-07-20 12:12 ` [PATCH i-g-t v3] " Tvrtko Ursulin
2018-07-20 12:21 ` [Intel-gfx] [igt-dev] " Chris Wilson
2018-07-20 12:21 ` Chris Wilson
2018-07-19 17:02 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-07-19 20:36 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-07-20 10:02 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/perf_pmu: Restore runtime PM at subtest exit (rev2) Patchwork
2018-07-20 13:33 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-07-20 13:39 ` [igt-dev] ✗ Fi.CI.BAT: failure for tests/perf_pmu: Restore runtime PM at subtest exit (rev3) Patchwork
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=20180720121222.31090-1-tvrtko.ursulin@linux.intel.com \
--to=tursulin@ursulin.net \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=tvrtko.ursulin@intel.com \
/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 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.