[PATCH i-g-t] i915/gem_exec_suspend: Measure power consumption during suspend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For this test, we need a laptop running on battery power so that we can
read the battery charge level before and after suspend. And then wait
long enough for a reliable measure.

References: https://bugs.freedesktop.org/show_bug.cgi?id=111909
Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: Mika Kuoppala <mika.kuoppala@xxxxxxxxxxxxxxx>
---
 tests/i915/gem_exec_suspend.c | 37 ++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/tests/i915/gem_exec_suspend.c b/tests/i915/gem_exec_suspend.c
index af6190ddd..21cfa888a 100644
--- a/tests/i915/gem_exec_suspend.c
+++ b/tests/i915/gem_exec_suspend.c
@@ -27,9 +27,13 @@
  * Exercise executing batches across suspend before checking the results.
  */
 
+#include <fcntl.h>
+#include <unistd.h>
+
 #include "igt.h"
-#include "igt_gt.h"
 #include "igt_dummyload.h"
+#include "igt_gt.h"
+#include "igt_sysfs.h"
 
 #define NOSLEEP 0
 #define IDLE 1
@@ -232,6 +236,32 @@ static void run_test(int fd, unsigned engine, unsigned flags)
 		test_all(fd, flags);
 }
 
+static void power_test(int i915, unsigned engine, unsigned flags)
+{
+	uint64_t before, after;
+	char *status;
+	int dir;
+
+	dir = open("/sys/class/power_supply/BAT0", O_RDONLY);
+	igt_require_f(dir != -1, "/sys/class/power_supply/BAT0 not available\n");
+
+	status = igt_sysfs_get(dir, "status");
+	igt_require_f(status && strcmp(status, "Discharging") == 0,
+		      "power test needs to be on battery, not mains, power\n");
+	free(status);
+
+	igt_set_autoresume_delay(30 * 60); /* 30 minutes */
+
+	igt_sysfs_scanf(dir, "energy_now", "%"PRIu64, &before);
+	run_test(i915, engine, flags);
+	igt_sysfs_scanf(dir, "energy_now", "%"PRIu64, &after);
+
+	igt_set_autoresume_delay(0);
+
+	igt_info("Power consumed while suspended: %.3fmWh\n",
+		 (before - after) * 1e-3);
+}
+
 igt_main
 {
 	const struct {
@@ -289,6 +319,11 @@ igt_main
 	igt_subtest("hang-S4")
 		run_test(fd, 0, HIBERNATE | HANG);
 
+	igt_subtest("power-S0")
+		power_test(fd, 0, IDLE);
+	igt_subtest("power-S3")
+		power_test(fd, 0, SUSPEND);
+
 	igt_fixture {
 		igt_disallow_hang(fd, hang);
 		close(fd);
-- 
2.24.0.rc1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux