Skip to contentSkip to conversation

Add a lib for power management helpers

PATCH Superseded David Weinehall 1 participant 2 messages Jan 14, 2016 1 message not in the archive Library code

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v3 1/1 Add a lib for power management helpers

This patch aims to create a separate lib for power management related helpers. Initially it only contains code that modify settings for external components (to handle components with default settings that prevents entering deeper sleep states), but moving i915-related power management helpers to this lib would probably make sense too.

v2: Change name of library to igt_pm
Namespace all exported functions with igt_pm_

v3: Various fixes based on feedback from Thomas Wood

David Weinehall (1):
lib/igt_pm: Lib for power management

 .../intel-gpu-tools/intel-gpu-tools-docs.xml       |   1 +
 lib/Makefile.sources                               |   2 +
 lib/igt.h                                          |   1 +
 lib/igt_aux.c                                      |  15 +-
 lib/igt_pm.c                                       | 233 +++++++++++++++++++++
 lib/igt_pm.h                                       |  31 +++
 tests/pm_lpsp.c                                    |  25 +--
 tests/pm_rpm.c                                     |  40 +---
 8 files changed, 281 insertions(+), 67 deletions(-)
 create mode 100644 lib/igt_pm.c
 create mode 100644 lib/igt_pm.h
Signature · 6 lines
2.7.0.rc3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH v3 1/1 lib/igt_pm: Lib for power management

Move power management related code to a separate library. Initially this is done only for workarounds that apply to external components. Modify the users of such workarounds accordingly. This currently involves HD audio and SATA link power management. For SATA link PM there's also code to save the previous settings, to allow for resetting the values after we've finished testing.

---
 .../intel-gpu-tools/intel-gpu-tools-docs.xml       |   1 +
 lib/Makefile.sources                               |   2 +
 lib/igt.h                                          |   1 +
 lib/igt_aux.c                                      |  15 +-
 lib/igt_pm.c                                       | 233 +++++++++++++++++++++
 lib/igt_pm.h                                       |  31 +++
 tests/pm_lpsp.c                                    |  25 +--
 tests/pm_rpm.c                                     |  40 +---
 8 files changed, 281 insertions(+), 67 deletions(-)
 create mode 100644 lib/igt_pm.c
 create mode 100644 lib/igt_pm.h
docs/reference/intel-gpu-tools/intel-gpu-tools-docs.xml +1 -0
index 618dc5fd7076..3ea3563a029a 100644
@@ -24,6 +24,7 @@
     <xi:include href="xml/igt_fb.xml"/>
     <xi:include href="xml/igt_aux.xml"/>
     <xi:include href="xml/igt_gt.xml"/>
+    <xi:include href="xml/igt_pm.xml"/>
     <xi:include href="xml/ioctl_wrappers.xml"/>
     <xi:include href="xml/intel_batchbuffer.xml"/>
     <xi:include href="xml/intel_chipset.xml"/>
lib/Makefile.sources +2 -0
index 4999868052b1..2f0eb2075e14 100644
@@ -60,6 +60,8 @@ libintel_tools_la_SOURCES = 	\
 	igt_core.h		\
 	igt_draw.c		\
 	igt_draw.h		\
+	igt_pm.c	\
+	igt_pm.h	\
 	$(NULL)
 
 .PHONY: version.h.tmp
lib/igt.h +1 -0
index 3be25511bb77..d751f2439de2 100644
@@ -35,6 +35,7 @@
 #include "igt_fb.h"
 #include "igt_gt.h"
 #include "igt_kms.h"
+#include "igt_pm.h"
 #include "igt_stats.h"
 #include "instdone.h"
 #include "intel_batchbuffer.h"
lib/igt_aux.c +2 -13
index 4d08d68bb932..cd7f14649fe2 100644
@@ -59,6 +59,7 @@
 #include "intel_reg.h"
 #include "ioctl_wrappers.h"
 #include "igt_kms.h"
+#include "igt_pm.h"
 
 /**
  * SECTION:igt_aux
@@ -531,19 +532,7 @@ bool igt_setup_runtime_pm(void)
 	if (pm_status_fd >= 0)
 		return true;
 
-	/* The Audio driver can get runtime PM references, so we need to make
-	 * sure its runtime PM is enabled, so it can release the refs and
-	 * actually enable us to runtime suspend. */
-	fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY);
-	if (fd >= 0) {
-		igt_assert(write(fd, "1\n", 2) == 2);
-		close(fd);
-	}
-	fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY);
-	if (fd >= 0) {
-		igt_assert(write(fd, "auto\n", 5) == 5);
-		close(fd);
-	}
+	igt_pm_enable_audio_runtime_pm();
 
 	/* Our implementation uses autosuspend. Try to set it to 0ms so the test
 	 * suite goes faster and we have a higher probability of triggering race
lib/igt_pm.c new file +233 -0

233 lines not on this page · raw message

lib/igt_pm.h new file +31 -0
new file mode 100644
index 000000000000..c14ff1f7a0ef
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef IGT_PM_H
+#define IGT_PM_H
+
+void igt_pm_enable_audio_runtime_pm(void);
+int8_t *igt_pm_enable_sata_link_power_management(void);
+void igt_pm_restore_sata_link_power_management(int8_t *pm_data);
+
+#endif /* IGT_PM_H */
tests/pm_lpsp.c +1 -24
index 257ae1b8b1d9..6cb697ed0bd5 100644
@@ -31,29 +31,6 @@
 #include <unistd.h>
 
 
-/* We know that if we don't enable audio runtime PM, snd_hda_intel will never
- * release its power well refcount, and we'll never reach the LPSP sate. OTOH
- * there's no guarantee that it will release the power well if we enable runtime
- * PM, but at least we can try.  We don't have any assertions since the user may
- * not even have snd_hda_intel loaded, which is not a problem. */
-static void disable_audio_runtime_pm(void)
-{
-	int fd;
-
-	fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_WRONLY);
-	if (fd >= 0) {
-		igt_assert_eq(write(fd, "1\n", 2), 2);
-		close(fd);
-	}
-	fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY);
-	if (fd >= 0) {
-		igt_assert_eq(write(fd, "auto\n", 5), 5);
-		close(fd);
-	}
-	/* Give some time for it to react. */
-	sleep(1);
-}
-
 static bool supports_lpsp(uint32_t devid)
 {
 	return IS_HASWELL(devid) || IS_BROADWELL(devid);
@@ -234,7 +211,7 @@ igt_main
 			drm_connectors[i] = drmModeGetConnectorCurrent(drm_fd,
 							drm_res->connectors[i]);
 
-		disable_audio_runtime_pm();
+		igt_pm_enable_audio_runtime_pm();
 
 		igt_require(supports_lpsp(devid));
 
tests/pm_rpm.c +10 -30
index 55fdb31cb723..13618a1b3246 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2013 Intel Corporation
+ * Copyright © 2013, 2015 Intel Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -111,6 +111,8 @@ struct modeset_params lpsp_mode_params;
 struct modeset_params non_lpsp_mode_params;
 struct modeset_params *default_mode_params;
 
+static int8_t *pm_data = NULL;
+
 /* If the read fails, then the machine doesn't support PC8+ residencies. */
 static bool supports_pc8_plus_residencies(void)
 {
@@ -670,41 +672,13 @@ static void setup_pc8(void)
 	has_pc8 = true;
 }
 
-/* If we want to actually reach PC8+ states, we need to properly configure all
- * the devices on the system to allow this. This function will try to setup the
- * things we know we need, but won't scream in case anything fails: we don't
- * know which devices are present on your machine, so we can't really expect
- * anything, just try to help with the more common problems. */
-static void setup_non_graphics_runtime_pm(void)
-{
-	int fd, i;
-	char *file_name;
-
-	/* Disk runtime PM policies. */
-	file_name = malloc(PATH_MAX);
-	for (i = 0; ; i++) {
-
-		snprintf(file_name, PATH_MAX,
-			 "/sys/class/scsi_host/host%d/link_power_management_policy",
-			 i);
-
-		fd = open(file_name, O_WRONLY);
-		if (fd < 0)
-			break;
-
-		igt_assert(write(fd, "min_power\n", 10) == 10);
-		close(fd);
-	}
-	free(file_name);
-}
-
 static void setup_environment(void)
 {
 	drm_fd = drm_open_driver_master(DRIVER_INTEL);
 
 	init_mode_set_data(&ms_data);
 
-	setup_non_graphics_runtime_pm();
+	pm_data = igt_pm_enable_sata_link_power_management();
 
 	has_runtime_pm = igt_setup_runtime_pm();
 	setup_pc8();
@@ -713,11 +687,17 @@ static void setup_environment(void)
 	igt_info("PC8 residency support: %d\n", has_pc8);
 
 	igt_require(has_runtime_pm);
+}
 
+static void restore_environment(void)
+{
+	igt_pm_restore_sata_link_power_management(pm_data);
+	free(pm_data);
 }
 
 static void teardown_environment(void)
 {
+	restore_environment();
 	fini_mode_set_data(&ms_data);
 	drmClose(drm_fd);
 	close(msr_fd);
Signature · 6 lines
2.7.0.rc3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx