* [PATCH i-g-t 1/4] lib/igt_pm: Make exit handlers signal safe
@ 2018-07-23 11:46 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
` (2 more replies)
0 siblings, 3 replies; 11+ 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] 11+ messages in thread
* [PATCH i-g-t 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
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 ` Tvrtko Ursulin
2018-07-23 12:46 ` [PATCH i-g-t v2 " Tvrtko Ursulin
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
2 siblings, 1 reply; 11+ 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>
HDA audio device can be present at various PCI paths on different systems
which the existing code did not account for.
Furthermore the failure to enable runtime PM was silent leaving callers
in the dark.
Improve it by auto-locating the PCI path and logging a warning when
something is not as expected.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 60 insertions(+), 17 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6f3b0a2d897d..a4c0cf335f6d 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
#include "drmtest.h"
#include "igt_pm.h"
@@ -64,6 +65,7 @@ enum {
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
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 int __igt_pm_audio_restore_runtime_pm(void)
@@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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 errno;
@@ -130,36 +132,77 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
+ char *path = NULL;
+ struct dirent *de;
+ DIR *dir;
int fd;
/* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
- 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);
+ dir = opendir("/sys/bus/pci/drivers/snd_hda_intel");
+ if (!dir)
+ goto err;
+
+ while ((de = readdir(dir))) {
+ const char *prefix = "/sys/bus/pci/devices/";
+ const char *suffix = "/power/control";
+ const char *match = "0000:00:";
+
+ if (strncmp(de->d_name, match, strlen(match)))
+ continue;
+
+ path = malloc(strlen(prefix) +
+ strlen(de->d_name) +
+ strlen(suffix) +
+ 1);
+ if (!path)
+ goto err;
+
+ strcpy(path, prefix);
+ strcat(path, de->d_name);
+ strcat(path, suffix);
+
+ igt_debug("Audio device PCI path is %s\n", path);
}
+ if (!path)
+ goto err;
+
+ fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
+ igt_assert_eq(write(fd, "1\n", 2), 2);
+ close(fd);
+
+ fd = open(path, O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_pm_audio_runtime_control_path = path;
+
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);
+
+ return;
+
+err:
+ igt_warn("Failed to enable audio runtime PM! (%d)", errno);
}
/**
--
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] 11+ messages in thread
* [PATCH i-g-t 3/4] lib/igt_pm: Export function to restore runtime PM status
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 ` [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 ` 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
2 siblings, 0 replies; 11+ 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>
In cases when runtime PM is enabled only from individual subtests and not
whole tests it is usable to be able to restore the old runtime PM config
and so avoid running subsequent subtests in an unexpected environment.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 41 +++++++++++++++++++++++++++++++++++++++++
lib/igt_pm.h | 1 +
2 files changed, 42 insertions(+)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index a4c0cf335f6d..a861055d382b 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -106,6 +106,23 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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();
@@ -393,6 +410,30 @@ static int __igt_restore_runtime_pm(void)
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);
--
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] 11+ messages in thread
* [PATCH i-g-t 4/4] tests/perf_pmu: Restore runtime PM status at rc6 test exit
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 ` [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 ` [PATCH i-g-t 3/4] lib/igt_pm: Export function to restore runtime PM status Tvrtko Ursulin
@ 2018-07-23 11:46 ` Tvrtko Ursulin
2 siblings, 0 replies; 11+ 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>
Avoid running subsequent subtests in non-default setup by restoring the
runtime PM config in one particular subtest.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
tests/perf_pmu.c | 3 +++
1 file changed, 3 insertions(+)
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH i-g-t v2 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
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 ` Tvrtko Ursulin
2018-07-23 12:54 ` [igt-dev] " Chris Wilson
0 siblings, 1 reply; 11+ messages in thread
From: Tvrtko Ursulin @ 2018-07-23 12:46 UTC (permalink / raw)
To: igt-dev; +Cc: intel-gfx
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
HDA audio device can be present at various PCI paths on different systems
which the existing code did not account for.
Furthermore the failure to enable runtime PM was silent leaving callers
in the dark.
Improve it by auto-locating the PCI path and logging a warning when
something is not as expected.
v2:
* If there is no audio hw/driver there is no failure.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 60 insertions(+), 17 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6f3b0a2d897d..26150fdfedf5 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
#include "drmtest.h"
#include "igt_pm.h"
@@ -64,6 +65,7 @@ enum {
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
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 int __igt_pm_audio_restore_runtime_pm(void)
@@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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 errno;
@@ -130,36 +132,77 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
+ char *path = NULL;
+ struct dirent *de;
+ DIR *dir;
int fd;
/* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
- 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);
+ dir = opendir("/sys/bus/pci/drivers/snd_hda_intel");
+ if (!dir)
+ return;
+
+ while ((de = readdir(dir))) {
+ const char *prefix = "/sys/bus/pci/devices/";
+ const char *suffix = "/power/control";
+ const char *match = "0000:00:";
+
+ if (strncmp(de->d_name, match, strlen(match)))
+ continue;
+
+ path = malloc(strlen(prefix) +
+ strlen(de->d_name) +
+ strlen(suffix) +
+ 1);
+ if (!path)
+ goto err;
+
+ strcpy(path, prefix);
+ strcat(path, de->d_name);
+ strcat(path, suffix);
+
+ igt_debug("Audio device PCI path is %s\n", path);
}
+ if (!path)
+ goto err;
+
+ fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
+ igt_assert_eq(write(fd, "1\n", 2), 2);
+ close(fd);
+
+ fd = open(path, O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_pm_audio_runtime_control_path = path;
+
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);
+
+ return;
+
+err:
+ igt_warn("Failed to enable audio runtime PM! (%d)", errno);
}
/**
--
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] 11+ messages in thread
* Re: [igt-dev] [PATCH i-g-t v2 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
2018-07-23 12:46 ` [PATCH i-g-t v2 " Tvrtko Ursulin
@ 2018-07-23 12:54 ` Chris Wilson
2018-07-23 15:31 ` [PATCH i-g-t v3 " Tvrtko Ursulin
0 siblings, 1 reply; 11+ messages in thread
From: Chris Wilson @ 2018-07-23 12:54 UTC (permalink / raw)
To: Tvrtko Ursulin, igt-dev; +Cc: intel-gfx
Quoting Tvrtko Ursulin (2018-07-23 13:46:49)
> @@ -130,36 +132,77 @@ static void strchomp(char *str)
> */
> void igt_pm_enable_audio_runtime_pm(void)
> {
> + char *path = NULL;
> + struct dirent *de;
> + DIR *dir;
> int fd;
>
> /* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
> - 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);
> + dir = opendir("/sys/bus/pci/drivers/snd_hda_intel");
> + if (!dir)
> + return;
> +
> + while ((de = readdir(dir))) {
> + const char *prefix = "/sys/bus/pci/devices/";
> + const char *suffix = "/power/control";
> + const char *match = "0000:00:";
> +
> + if (strncmp(de->d_name, match, strlen(match)))
> + continue;
> +
> + path = malloc(strlen(prefix) +
> + strlen(de->d_name) +
> + strlen(suffix) +
> + 1);
> + if (!path)
> + goto err;
> +
> + strcpy(path, prefix);
> + strcat(path, de->d_name);
> + strcat(path, suffix);
if (asprintf(&path, "/sys/bus/pci/devices/%s/power/control", de->d_name) < 0)
goto err;
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH i-g-t v3 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
2018-07-23 12:54 ` [igt-dev] " Chris Wilson
@ 2018-07-23 15:31 ` Tvrtko Ursulin
2018-07-24 9:59 ` [PATCH i-g-t v4 " Tvrtko Ursulin
0 siblings, 1 reply; 11+ messages in thread
From: Tvrtko Ursulin @ 2018-07-23 15:31 UTC (permalink / raw)
To: igt-dev; +Cc: intel-gfx
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
HDA audio device can be present at various PCI paths on different systems
which the existing code did not account for.
Furthermore the failure to enable runtime PM was silent leaving callers
in the dark.
Improve it by auto-locating the PCI path and logging a warning when
something is not as expected.
v2:
* If there is no audio hw/driver there is no failure.
v3
* Comment.
* Skip non-symlinks.
* Free path on failure and restore.
* Simplify with asprintf. (Chris Wilson)
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 76 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 59 insertions(+), 17 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6f3b0a2d897d..fd2880c9df11 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
#include "drmtest.h"
#include "igt_pm.h"
@@ -64,6 +65,7 @@ enum {
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
static char __igt_pm_audio_runtime_power_save[64];
+static char * __igt_pm_audio_runtime_control_path;
static char __igt_pm_audio_runtime_control[64];
static int __igt_pm_audio_restore_runtime_pm(void)
@@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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 errno;
@@ -100,6 +102,8 @@ static int __igt_pm_audio_restore_runtime_pm(void)
close(fd);
__igt_pm_audio_runtime_power_save[0] = 0;
+ free(__igt_pm_audio_runtime_control_path);
+ __igt_pm_audio_runtime_control_path = NULL;
return 0;
}
@@ -130,36 +134,74 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
+ char *path = NULL;
+ struct dirent *de;
+ DIR *dir;
int fd;
/* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
- 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);
+ dir = opendir("/sys/bus/pci/drivers/snd_hda_intel");
+ if (!dir)
+ return;
+
+ /* Find PCI device claimed by snd_hda_intel. */
+ while ((de = readdir(dir))) {
+ const char *match = "0000:00:";
+
+ if (de->d_type != DT_LNK ||
+ strncmp(de->d_name, match, strlen(match)))
+ continue;
+
+ igt_assert(asprintf(&path,
+ "/sys/bus/pci/devices/%s/power/control",
+ de->d_name));
+
+ igt_debug("Audio device PCI path is %s\n", path);
+
+ break;
}
+ if (!path)
+ goto err;
+
+ fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
+ igt_assert_eq(write(fd, "1\n", 2), 2);
+ close(fd);
+
+ fd = open(path, O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_pm_audio_runtime_control_path = path;
+
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);
+
+ return;
+
+err:
+ igt_warn("Failed to enable audio runtime PM! (%d)", errno);
+ free(path);
}
/**
--
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] 11+ messages in thread
* [PATCH i-g-t v4 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
2018-07-23 15:31 ` [PATCH i-g-t v3 " Tvrtko Ursulin
@ 2018-07-24 9:59 ` Tvrtko Ursulin
2018-07-24 10:08 ` [PATCH i-g-t v5 " Tvrtko Ursulin
0 siblings, 1 reply; 11+ messages in thread
From: Tvrtko Ursulin @ 2018-07-24 9:59 UTC (permalink / raw)
To: igt-dev; +Cc: intel-gfx
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
HDA audio device can be present at various PCI paths on different systems
which the existing code did not account for.
Furthermore the failure to enable runtime PM was silent leaving callers
in the dark.
Improve it by auto-locating the PCI path and logging a warning when
something is not as expected.
v2:
* If there is no audio hw/driver there is no failure.
v3:
* Comment.
* Skip non-symlinks.
* Free path on failure and restore.
* Simplify with asprintf. (Chris Wilson)
v4:
* Find snd_hda_intel instance tied with an Intel device.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 92 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 76 insertions(+), 16 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6f3b0a2d897d..22d8d420c5d7 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
#include "drmtest.h"
#include "igt_pm.h"
@@ -64,6 +65,7 @@ enum {
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
static char __igt_pm_audio_runtime_power_save[64];
+static char * __igt_pm_audio_runtime_control_path;
static char __igt_pm_audio_runtime_control[64];
static int __igt_pm_audio_restore_runtime_pm(void)
@@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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 errno;
@@ -100,6 +102,8 @@ static int __igt_pm_audio_restore_runtime_pm(void)
close(fd);
__igt_pm_audio_runtime_power_save[0] = 0;
+ free(__igt_pm_audio_runtime_control_path);
+ __igt_pm_audio_runtime_control_path = NULL;
return 0;
}
@@ -130,36 +134,92 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
+ char *path = NULL;
+ struct dirent *de;
+ DIR *dir;
int fd;
/* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
- 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);
+ dir = opendir("/sys/class/sound");
+ if (!dir)
+ return;
+
+ /* Find PCI device claimed by snd_hda_intel and tied to i915. */
+ while ((de = readdir(dir))) {
+ const char *match = "hwC";
+ char buf[32];
+ char *tmp;
+ int ret;
+
+ if (de->d_type != DT_LNK ||
+ strncmp(de->d_name, match, strlen(match)))
+ continue;
+
+ igt_assert(asprintf(&tmp,
+ "/sys/class/sound/%s/vendor_name",
+ de->d_name));
+
+ fd = open(tmp, O_RDONLY);
+ igt_assert_fd(fd);
+ ret = read(fd, buf, sizeof(buf));
close(fd);
+ igt_assert(ret >= 0);
+ strchomp(buf);
+
+ /* Realtek and similar devices are not what we are after. */
+ if (strcmp(buf, "Intel"))
+ continue;
+
+ igt_assert(asprintf(&path,
+ "/sys/class/sound/%s/device/device/power/control",
+ de->d_name));
+
+ igt_debug("Audio device path is %s\n", path);
+
+ break;
}
+ if (!path)
+ goto err;
+
+ fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
+ igt_assert_eq(write(fd, "1\n", 2), 2);
+ close(fd);
+
+ fd = open(path, O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_pm_audio_runtime_control_path = path;
+
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);
+
+ return;
+
+err:
+ igt_warn("Failed to enable audio runtime PM! (%d)", errno);
+ free(path);
}
/**
--
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] 11+ messages in thread
* [PATCH i-g-t v5 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
2018-07-24 9:59 ` [PATCH i-g-t v4 " Tvrtko Ursulin
@ 2018-07-24 10:08 ` Tvrtko Ursulin
2018-07-24 10:29 ` [PATCH i-g-t v6 " Tvrtko Ursulin
0 siblings, 1 reply; 11+ messages in thread
From: Tvrtko Ursulin @ 2018-07-24 10:08 UTC (permalink / raw)
To: igt-dev; +Cc: intel-gfx
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
HDA audio device can be present at various PCI paths on different systems
which the existing code did not account for.
Furthermore the failure to enable runtime PM was silent leaving callers
in the dark.
Improve it by auto-locating the PCI path and logging a warning when
something is not as expected.
v2:
* If there is no audio hw/driver there is no failure.
v3:
* Comment.
* Skip non-symlinks.
* Free path on failure and restore.
* Simplify with asprintf. (Chris Wilson)
v4:
* Find snd_hda_intel instance tied with an Intel device.
v5:
* Fix memory leak and silence Valgrind warning.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 93 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 77 insertions(+), 16 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6f3b0a2d897d..21eb01e1903e 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
#include "drmtest.h"
#include "igt_pm.h"
@@ -64,6 +65,7 @@ enum {
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
static char __igt_pm_audio_runtime_power_save[64];
+static char * __igt_pm_audio_runtime_control_path;
static char __igt_pm_audio_runtime_control[64];
static int __igt_pm_audio_restore_runtime_pm(void)
@@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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 errno;
@@ -100,6 +102,8 @@ static int __igt_pm_audio_restore_runtime_pm(void)
close(fd);
__igt_pm_audio_runtime_power_save[0] = 0;
+ free(__igt_pm_audio_runtime_control_path);
+ __igt_pm_audio_runtime_control_path = NULL;
return 0;
}
@@ -130,36 +134,93 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
+ char *path = NULL;
+ struct dirent *de;
+ DIR *dir;
int fd;
/* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
- 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);
+ dir = opendir("/sys/class/sound");
+ if (!dir)
+ return;
+
+ /* Find PCI device claimed by snd_hda_intel and tied to i915. */
+ while ((de = readdir(dir))) {
+ const char *match = "hwC";
+ char buf[32] = { }; /* for Valgrind */
+ char *tmp;
+ int ret;
+
+ if (de->d_type != DT_LNK ||
+ strncmp(de->d_name, match, strlen(match)))
+ continue;
+
+ igt_assert(asprintf(&tmp,
+ "/sys/class/sound/%s/vendor_name",
+ de->d_name));
+
+ fd = open(tmp, O_RDONLY);
+ free(tmp);
+ igt_assert_fd(fd);
+ ret = read(fd, buf, sizeof(buf));
close(fd);
+ igt_assert(ret > 0);
+ strchomp(buf);
+
+ /* Realtek and similar devices are not what we are after. */
+ if (strcmp(buf, "Intel"))
+ continue;
+
+ igt_assert(asprintf(&path,
+ "/sys/class/sound/%s/device/device/power/control",
+ de->d_name));
+
+ igt_debug("Audio device path is %s\n", path);
+
+ break;
}
+ if (!path)
+ goto err;
+
+ fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
+ igt_assert_eq(write(fd, "1\n", 2), 2);
+ close(fd);
+
+ fd = open(path, O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_pm_audio_runtime_control_path = path;
+
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);
+
+ return;
+
+err:
+ igt_warn("Failed to enable audio runtime PM! (%d)", errno);
+ free(path);
}
/**
--
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] 11+ messages in thread
* [PATCH i-g-t v6 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
2018-07-24 10:08 ` [PATCH i-g-t v5 " Tvrtko Ursulin
@ 2018-07-24 10:29 ` Tvrtko Ursulin
2018-07-24 12:27 ` [igt-dev] " Chris Wilson
0 siblings, 1 reply; 11+ messages in thread
From: Tvrtko Ursulin @ 2018-07-24 10:29 UTC (permalink / raw)
To: igt-dev; +Cc: intel-gfx
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
HDA audio device can be present at various PCI paths on different systems
which the existing code did not account for.
Furthermore the failure to enable runtime PM was silent leaving callers
in the dark.
Improve it by auto-locating the PCI path and logging a warning when
something is not as expected.
v2:
* If there is no audio hw/driver there is no failure.
v3:
* Comment.
* Skip non-symlinks.
* Free path on failure and restore.
* Simplify with asprintf. (Chris Wilson)
v4:
* Find snd_hda_intel instance tied with an Intel device.
v5:
* Fix memory leak and silence Valgrind warning.
v6:
* Fix error out logic.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
lib/igt_pm.c | 93 ++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 79 insertions(+), 14 deletions(-)
diff --git a/lib/igt_pm.c b/lib/igt_pm.c
index 6f3b0a2d897d..94d4dd2d3c37 100644
--- a/lib/igt_pm.c
+++ b/lib/igt_pm.c
@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
#include "drmtest.h"
#include "igt_pm.h"
@@ -64,6 +65,7 @@ enum {
#define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR)
static char __igt_pm_audio_runtime_power_save[64];
+static char * __igt_pm_audio_runtime_control_path;
static char __igt_pm_audio_runtime_control[64];
static int __igt_pm_audio_restore_runtime_pm(void)
@@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void)
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 errno;
@@ -100,6 +102,8 @@ static int __igt_pm_audio_restore_runtime_pm(void)
close(fd);
__igt_pm_audio_runtime_power_save[0] = 0;
+ free(__igt_pm_audio_runtime_control_path);
+ __igt_pm_audio_runtime_control_path = NULL;
return 0;
}
@@ -130,36 +134,97 @@ static void strchomp(char *str)
*/
void igt_pm_enable_audio_runtime_pm(void)
{
+ char *path = NULL;
+ struct dirent *de;
+ DIR *dir;
int fd;
/* 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
- igt_assert_eq(write(fd, "1\n", 2), 2);
+ dir = opendir("/sys/class/sound");
+ if (!dir)
+ return;
+
+ /* Find PCI device claimed by snd_hda_intel and tied to i915. */
+ while ((de = readdir(dir))) {
+ const char *match = "hwC";
+ char buf[32] = { }; /* for Valgrind */
+ char *tmp;
+ int ret;
+
+ if (de->d_type != DT_LNK ||
+ strncmp(de->d_name, match, strlen(match)))
+ continue;
+
+ igt_assert(asprintf(&tmp,
+ "/sys/class/sound/%s/vendor_name",
+ de->d_name));
+
+ fd = open(tmp, O_RDONLY);
+ free(tmp);
+ igt_assert_fd(fd);
+ ret = read(fd, buf, sizeof(buf));
close(fd);
+ igt_assert(ret > 0);
+ strchomp(buf);
+
+ /* Realtek and similar devices are not what we are after. */
+ if (strcmp(buf, "Intel"))
+ continue;
+
+ igt_assert(asprintf(&path,
+ "/sys/class/sound/%s/device/device/power/control",
+ de->d_name));
+
+ igt_debug("Audio device path is %s\n", path);
+
+ break;
}
- 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);
+
+ fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR);
+ if (fd < 0)
+ return;
+
+ /* snd_hda_intel loaded but no path found is an error. */
+ if (!path) {
close(fd);
+ errno = ESRCH;
+ goto err;
}
+ 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_install_exit_handler(__igt_pm_audio_runtime_exit_handler);
+ igt_assert_eq(write(fd, "1\n", 2), 2);
+ close(fd);
+
+ fd = open(path, O_RDWR);
+ if (fd < 0)
+ goto err;
+
+ 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_pm_audio_runtime_control_path = path;
+
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);
+
+ return;
+
+err:
+ igt_warn("Failed to enable audio runtime PM! (%d)", errno);
+ free(path);
}
/**
--
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] 11+ messages in thread
* Re: [igt-dev] [PATCH i-g-t v6 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM
2018-07-24 10:29 ` [PATCH i-g-t v6 " Tvrtko Ursulin
@ 2018-07-24 12:27 ` Chris Wilson
0 siblings, 0 replies; 11+ messages in thread
From: Chris Wilson @ 2018-07-24 12:27 UTC (permalink / raw)
To: Tvrtko Ursulin, igt-dev; +Cc: intel-gfx
Quoting Tvrtko Ursulin (2018-07-24 11:29:31)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
> HDA audio device can be present at various PCI paths on different systems
> which the existing code did not account for.
>
> Furthermore the failure to enable runtime PM was silent leaving callers
> in the dark.
>
> Improve it by auto-locating the PCI path and logging a warning when
> something is not as expected.
>
> v2:
> * If there is no audio hw/driver there is no failure.
>
> v3:
> * Comment.
> * Skip non-symlinks.
> * Free path on failure and restore.
> * Simplify with asprintf. (Chris Wilson)
>
> v4:
> * Find snd_hda_intel instance tied with an Intel device.
>
> v5:
> * Fix memory leak and silence Valgrind warning.
>
> v6:
> * Fix error out logic.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
CI looks promising, as far my knowledge goes (and I am sorry to say
finding the child devices is beyond my sysfs ken), series is
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-07-24 12:27 UTC | newest]
Thread overview: 11+ 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 ` [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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox