All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t] tests/gem_ppgtt: Check for vm leaks with flink and ppgtt
Date: Mon, 20 Apr 2015 13:14:14 +0100	[thread overview]
Message-ID: <1429532054-29948-1-git-send-email-tvrtko.ursulin@linux.intel.com> (raw)

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma
per Xorg startup cycle.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/gem_ppgtt.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/tests/gem_ppgtt.c b/tests/gem_ppgtt.c
index 5bf773c..9b5b3ee 100644
--- a/tests/gem_ppgtt.c
+++ b/tests/gem_ppgtt.c
@@ -200,6 +200,103 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+static void flink_and_contexts(void)
+{
+	drm_intel_bufmgr *bufmgr;
+	int fd, fd2;
+	dri_bo *bo;
+	uint32_t flink_name;
+	unsigned int max_line = 0, num_lines = 0, cnt = 0;
+	int ret;
+
+	/*
+	 * Export a bo via flink and access it from a child process via a
+	 * different ppggtt context. Make sure when child exists that the vma
+	 * (and hence the vm), associated with its ppgtt context, is torn down.
+	 */
+
+	fd = drm_open_any();
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+	igt_assert(bufmgr);
+
+	bo = create_bo(bufmgr, 0);
+	igt_assert(bo);
+
+	ret = drm_intel_bo_flink(bo, &flink_name);
+	igt_assert(ret == 0);
+
+	igt_fork(child, 20) {
+		int devid;
+		drm_intel_bufmgr *bufmgr;
+		int fd;
+		dri_bo *bo, *import;
+		struct intel_batchbuffer *batch;
+
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		igt_assert(bufmgr);
+
+		bo = create_bo(bufmgr, 0);
+		import = drm_intel_bo_gem_create_from_name(bufmgr,
+							   "flink_and_contexts",
+							   flink_name);
+		igt_assert(bo && import);
+
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+		igt_assert(batch);
+
+		intel_copy_bo(batch, bo, import, SIZE);
+
+		intel_batchbuffer_free(batch);
+
+		dri_bo_unreference(import);
+		dri_bo_unreference(bo);
+
+		drm_intel_bufmgr_destroy(bufmgr);
+		close(fd);
+
+		exit(0);
+	}
+
+	igt_waitchildren();
+
+	/*
+	 * Count the longest line in the file which lists the vmas per object.
+	 * This might be a bit fragile so maybe there is a better way.
+	 */
+	fd2 = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);
+	igt_assert(fd2 >= 0);
+
+	do {
+		char ch;
+
+		ret = read(fd2, &ch, 1);
+		if (ret == 0)
+			break;
+		igt_assert(ret == 1);
+		if (ch == '\n') {
+			if (cnt > max_line)
+				max_line = cnt;
+			num_lines++;
+			cnt = 0;
+		} else {
+			cnt++;
+		}
+	} while (true);
+
+	close(fd2);
+
+	dri_bo_unreference(bo);
+	drm_intel_bufmgr_destroy(bufmgr);
+	close(fd);
+
+	igt_assert(num_lines >= 1);
+	igt_assert(max_line < 1000);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -229,5 +326,8 @@ int main(int argc, char **argv)
 		surfaces_check(rcs, N_CHILD, 0x8000 / N_CHILD);
 	}
 
+	igt_subtest("flink-vs-ctx-vm-leak")
+		flink_and_contexts();
+
 	igt_exit();
 }
-- 
2.3.5

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

             reply	other threads:[~2015-04-20 12:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-20 12:14 Tvrtko Ursulin [this message]
2015-04-20 12:50 ` [PATCH i-g-t] tests/gem_ppgtt: Check for vm leaks with flink and ppgtt Chris Wilson
2015-04-20 14:56   ` Tvrtko Ursulin
2015-04-20 15:01     ` Chris Wilson
2015-04-20 16:25   ` Daniel Vetter
2015-04-23  9:30 ` [PATCH v2] [i-g-t] " daniele.ceraolospurio
2015-04-23  9:43   ` Chris Wilson
2015-04-23 10:14     ` Ceraolo Spurio, Daniele
2015-04-23 10:31       ` Chris Wilson
2015-04-23 11:23   ` [PATCH v3] " daniele.ceraolospurio
2015-04-23 11:36     ` Chris Wilson
2015-04-23 13:01       ` Ceraolo Spurio, Daniele
2015-04-23 13:09         ` Chris Wilson
2015-04-23 11:46     ` Tvrtko Ursulin
2015-04-23 14:39     ` [PATCH v4] " daniele.ceraolospurio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429532054-29948-1-git-send-email-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.