[PATCH i-g-t] gem_ppgtt: Test VMA leak on context destruction

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

 



From: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>

Test that VMAs associated with a context are cleaned up when
contexts are destroyed.

In practice this emulates the leak seen between fbcon and X server.
Every time the X server exits we gain one VMA on the fbcon frame
buffer object as externally visible via for example
/sys/kernel/debug/dri/0/i915_gem_gtt.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
---
 tests/gem_ppgtt.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/tests/gem_ppgtt.c b/tests/gem_ppgtt.c
index 4f6df063214a..363f9d701585 100644
--- a/tests/gem_ppgtt.c
+++ b/tests/gem_ppgtt.c
@@ -265,6 +265,83 @@ static void flink_and_close(void)
 	close(fd2);
 }
 
+static int grep_name(char *match, int to_match)
+{
+	int fdd, ret, matched;
+
+	fdd = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);
+	igt_assert(fdd >= 0);
+
+	matched = 0;
+	do {
+		char ch;
+
+		ret = read(fdd, &ch, 1);
+		if (ret == 0)
+			break;
+		igt_assert(ret == 1);
+
+		if (ch == match[matched])
+			matched++;
+		else
+			matched = 0;
+	} while (matched < to_match);
+
+	close(fdd);
+
+	return matched;
+}
+
+static void flink_and_exit(void)
+{
+	uint32_t fd, fd2;
+	uint32_t bo, flinked_bo, name;
+	char match[100];
+	int matched, to_match;
+	int retry = 0;
+	const int retries = 50;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));
+
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	to_match  = snprintf(match, sizeof(match), "(name: %u)", name);
+	igt_assert(to_match < sizeof(match));
+
+	fd2 = drm_open_any();
+
+	flinked_bo = gem_open(fd2, name);
+	exec_and_get_offset(fd2, flinked_bo);
+	gem_sync(fd2, flinked_bo);
+
+	/* Verify looking for string works OK. */
+	matched = grep_name(match, to_match);
+	igt_assert_eq(matched, to_match);
+
+	gem_close(fd2, flinked_bo);
+
+	/* Close the context. */
+	close(fd2);
+
+retry:
+	/* Give cleanup some time to run. */
+	usleep(100000);
+
+	/* The flinked bo VMA should have been cleared now, so list of VMAs
+	 * in debugfs should not contain the one for the imported object.
+	 */
+	matched = grep_name(match, to_match);
+	if (matched >= to_match && retry++ < retries)
+		goto retry;
+
+	igt_assert_lt(matched, to_match);
+
+	gem_close(fd, bo);
+	close(fd);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -297,5 +374,8 @@ int main(int argc, char **argv)
 	igt_subtest("flink-and-close-vma-leak")
 		flink_and_close();
 
+	igt_subtest("flink-and-exit-vma-leak")
+		flink_and_exit();
+
 	igt_exit();
 }
-- 
2.5.1

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




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux