[PATCH i-g-t] i915/sysfs_rc6: Exercise rc6 controls

Ashutosh Dixit ashutosh.dixit at intel.com
Tue Nov 15 04:36:16 UTC 2022


From: Chris Wilson <chris.p.wilson at intel.com>

As rc6_enable has been exposed to allow the sysadmin to disable/enable
rc6 on individual gt, we must check that in doing so does prevent entry
to rc6 and vice versa.

v2: Fix build break due to gem_context_create_for_gt

Signed-off-by: Chris Wilson <chris.p.wilson at intel.com>
---
 tests/i915/sysfs_rc6.c                | 285 ++++++++++++++++++++++++++
 tests/intel-ci/fast-feedback.testlist |   4 +
 tests/meson.build                     |   1 +
 3 files changed, 290 insertions(+)
 create mode 100644 tests/i915/sysfs_rc6.c

diff --git a/tests/i915/sysfs_rc6.c b/tests/i915/sysfs_rc6.c
new file mode 100644
index 00000000000..93b3c8b146d
--- /dev/null
+++ b/tests/i915/sysfs_rc6.c
@@ -0,0 +1,285 @@
+/*
+ * Copyright © 2019 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.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "drmtest.h"
+#include "i915/gem.h"
+#include "i915/gem_context.h"
+#include "igt_dummyload.h"
+#include "igt_sysfs.h"
+
+#define __assert_within_epsilon(x, ref, tol_up, tol_down) \
+	igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \
+		     (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \
+		     "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n",\
+		     #x, #ref, (double)(x), \
+		     (tol_up) * 100.0, (tol_down) * 100.0, \
+		     (double)(ref))
+
+#define assert_within_epsilon(x, ref, tolerance) \
+	__assert_within_epsilon(x, ref, tolerance, tolerance)
+
+static void test_residency_nowrite(int i915, int gt)
+{
+	int fd;
+
+	fd = openat(gt, "rc6_residency_ms", O_WRONLY);
+	igt_assert(fd == -1);
+}
+
+static unsigned long long read_ull(int fd)
+{
+	char buf[4096];
+	int len;
+
+	lseek(fd, 0, SEEK_SET);
+	len = read(fd, buf, sizeof(buf) - 1);
+	igt_assert(len != -1);
+	buf[len] = '\0';
+
+	return strtoull(buf, NULL, 0);
+}
+
+static void test_idle(int i915, int gt)
+{
+	unsigned long long start, end, elapsed;
+	struct timespec tv;
+	int fd;
+
+	fd = openat(gt, "rc6_residency_ms", O_RDONLY);
+	igt_require(fd != -1);
+
+	gem_quiescent_gpu(i915);
+
+	igt_gettime(&tv);
+	start = read_ull(fd);
+	usleep(100000); /* 100ms */
+	end = read_ull(fd);
+	elapsed = igt_nsec_elapsed(&tv) / 1000000;
+
+	close(fd);
+
+	igt_info("Measured %llums of rc6 residency in %llums\n",
+		 end - start, elapsed);
+	assert_within_epsilon(end - start, elapsed, 0.1);
+}
+
+static bool rc6_enable(int i915, int gt, int fd)
+{
+	int loops = 200;
+
+	igt_sysfs_set(gt, "rc6_enable", "1\n");
+	gem_quiescent_gpu(i915);
+
+	while (loops--) {
+		unsigned long long start, end;
+
+		start = read_ull(fd);
+		usleep(5000); /* 5ms */
+		end = read_ull(fd);
+		if (end > start)
+			return true;
+	}
+
+	return false;
+}
+
+static void test_disable(int i915, int gt)
+{
+	unsigned long long start, end, elapsed;
+	struct timespec tv;
+	int fd;
+
+	fd = openat(gt, "rc6_residency_ms", O_RDONLY);
+	igt_require(fd != -1);
+
+	/* Start with rc6 enabled and resident */
+	igt_require(rc6_enable(i915, gt, fd));
+
+	igt_sysfs_set(gt, "rc6_enable", "0\n");
+	usleep(5000); /* short idle to make sure the counters have stopped */
+
+	igt_gettime(&tv);
+	start = read_ull(fd);
+	usleep(100000); /* 100ms */
+	end = read_ull(fd);
+	elapsed = igt_nsec_elapsed(&tv) / 1000000;
+
+	igt_sysfs_set(gt, "rc6_enable", "1\n");
+	close(fd);
+
+	igt_info("Measured %llums of rc6 residency in %llums\n",
+		 end - start, elapsed);
+	igt_assert(end == start);
+}
+
+static void test_enable(int i915, int gt)
+{
+	const intel_ctx_t *ctx = intel_ctx_create_all_physical(i915);
+	unsigned long long start, end, elapsed;
+	struct timespec tv;
+	igt_spin_t *spin;
+	int fd;
+
+	fd = openat(gt, "rc6_residency_ms", O_RDONLY);
+	igt_require(fd != -1);
+
+	/* Check we start with rc6 working */
+	igt_require(rc6_enable(i915, gt, fd));
+
+	/* Switch off before waking up the GPU */
+	igt_sysfs_set(gt, "rc6_enable", "0\n");
+	usleep(5000); /* short idle to make sure the counters have stopped */
+
+	spin = igt_spin_new(i915, .ctx = ctx, .flags = IGT_SPIN_POLL_RUN);
+	igt_spin_busywait_until_started(spin);
+
+	/* Check rc6 is still disabled */
+	igt_gettime(&tv);
+	start = read_ull(fd);
+	usleep(10000); /* 10ms */
+	end = read_ull(fd);
+	igt_require(end == start);
+
+	/* Enable rc6, while the gpu is very busy and should not sleep */
+	igt_sysfs_set(gt, "rc6_enable", "1\n");
+	igt_gettime(&tv);
+	start = read_ull(fd);
+	usleep(100000); /* 100ms */
+	end = read_ull(fd);
+	igt_require(end == start);
+
+	/* Let the gpu park */
+	igt_spin_free(i915, spin);
+	gem_quiescent_gpu(i915);
+	usleep(100000); /* 100ms */
+
+	/* GPU is now idle, rc6 should be incrementing again */
+	igt_gettime(&tv);
+	start = read_ull(fd);
+	usleep(100000); /* 100ms */
+	end = read_ull(fd);
+	elapsed = igt_nsec_elapsed(&tv) / 1000000;
+
+	close(fd);
+	intel_ctx_destroy(i915, ctx);
+
+	igt_info("Measured %llums of rc6 residency in %llums\n",
+		 end - start, elapsed);
+	assert_within_epsilon(end - start, elapsed, 0.1);
+}
+
+static void dyn_sysfs_gts(int i915, int gts, const char *file,
+			  void (*test)(int, int))
+{
+	char buf[512];
+	int len;
+
+	lseek(gts, 0, SEEK_SET);
+	while ((len = syscall(SYS_getdents64, gts, buf, sizeof(buf))) > 0) {
+		void *ptr = buf;
+
+		while (len) {
+			struct linux_dirent64 {
+				ino64_t        d_ino;
+				off64_t        d_off;
+				unsigned short d_reclen;
+				unsigned char  d_type;
+				char           d_name[];
+			} *de = ptr;
+			char *id;
+			int gt;
+
+			ptr += de->d_reclen;
+			len -= de->d_reclen;
+
+			gt = openat(gts, de->d_name, O_RDONLY);
+			id = igt_sysfs_get(gt, "id");
+			if (!id) {
+				close(gt);
+				continue;
+			}
+
+			igt_dynamic(de->d_name) {
+				if (file) {
+					struct stat st;
+
+					igt_require(fstatat(gt, file, &st, 0) == 0);
+				}
+
+				errno = 0; /* start afresh */
+				test(i915, gt);
+			}
+
+			close(gt);
+		}
+	}
+}
+
+igt_main
+{
+	int i915 = -1, gts = -1;
+
+	igt_fixture {
+		int sys;
+
+		i915 = drm_open_driver(DRIVER_INTEL);
+		igt_require_gem(i915);
+
+		sys = igt_sysfs_open(i915);
+		igt_require(sys != -1);
+
+		gts = openat(sys, "gt", O_RDONLY);
+		igt_require(gts != -1);
+
+		close(sys);
+	}
+
+	/* XXX Restore to defaults? */
+
+	igt_subtest_with_dynamic("residency-invalid-write")
+		dyn_sysfs_gts(i915, gts, "rc6_residency_ms", test_residency_nowrite);
+
+	igt_subtest_with_dynamic("residency")
+		dyn_sysfs_gts(i915, gts, "rc6_residency_ms", test_idle);
+
+	igt_subtest_with_dynamic("disable")
+		dyn_sysfs_gts(i915, gts, "rc6_enable", test_disable);
+
+	igt_subtest_with_dynamic("enable")
+		dyn_sysfs_gts(i915, gts, "rc6_enable", test_enable);
+
+	igt_fixture {
+		close(gts);
+		close(i915);
+	}
+}
diff --git a/tests/intel-ci/fast-feedback.testlist b/tests/intel-ci/fast-feedback.testlist
index f57f8ff3be1..cd59f78dbe7 100644
--- a/tests/intel-ci/fast-feedback.testlist
+++ b/tests/intel-ci/fast-feedback.testlist
@@ -141,6 +141,10 @@ igt at prime_vgem@basic-gtt
 igt at prime_vgem@basic-read
 igt at prime_vgem@basic-write
 igt at prime_vgem@basic-userptr
+igt at sysfs_rc6@residency-invalid-write
+igt at sysfs_rc6@residency
+igt at sysfs_rc6@disable
+igt at sysfs_rc6@enable
 igt at vgem_basic@setversion
 igt at vgem_basic@create
 igt at vgem_basic@debugfs
diff --git a/tests/meson.build b/tests/meson.build
index 12e53e0bd2d..db619738345 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -249,6 +249,7 @@ i915_progs = [
 	'sysfs_defaults',
 	'sysfs_heartbeat_interval',
 	'sysfs_preempt_timeout',
+	'sysfs_rc6',
 	'sysfs_timeslice_duration',
 ]
 
-- 
2.38.0



More information about the Intel-gfx-trybot mailing list