Skip to contentSkip to conversation

lib/drmtest: Add a new test helper to check for Full PPGTT usage

PATCH In review [email protected] 3 participants 7 messages Dec 10, 2013 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 lib/drmtest: Add a new test helper to check for Full PPGTT usage

From: Oscar Mateo <[email protected]>

---
 lib/drmtest.c |   14 ++++++++++++++
 lib/drmtest.h |    1 +
 2 files changed, 15 insertions(+)
lib/drmtest.c +14 -0
index f2624a1..c2483ee 100644
@@ -87,6 +87,20 @@ is_intel(int fd)
 	return IS_INTEL(devid);
 }
 
+bool gem_uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val;
+
+	gp.param = 28; /* HAS_FULL_PPGTT */
+	gp.value = &val;
+
+	if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
+		return 0;
+
+	return val;
+}
+
 bool gem_uses_aliasing_ppgtt(int fd)
 {
 	struct drm_i915_getparam gp;
lib/drmtest.h +1 -0
index 20e2620..61769e2 100644
@@ -91,6 +91,7 @@ void gem_sw_finish(int fd, uint32_t handle);
 bool gem_bo_busy(int fd, uint32_t handle);
 
 /* feature test helpers */
+bool gem_uses_full_ppgtt(int fd);
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
 
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/3 tests/gem_close_race: Adapt the test for Full PPGTT

From: Oscar Mateo <[email protected]>

With Full PPGTT, each new fd creates a new context and thus a new PPGTT, so we have to reduce the number of simultaneous fds or face OOM problems. For every new PPGTT, its PDEs are stored in the GGTT which imposes a limit of 1024 new contexts. We want to leave at least 1/4 of the GGTT available for "important" stuff like scanout buffers, so never open more than 768 fds.

---
 tests/gem_close_race.c |   39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
tests/gem_close_race.c +26 -13
index 6064c02..f658c90 100644
@@ -49,6 +49,8 @@
 
 static char device[80];
 static uint32_t devid;
+static unsigned int num_childs = 2000;
+static unsigned int num_fds = 32000;
 
 static void selfcopy(int fd, uint32_t handle, int loops)
 {
@@ -136,11 +138,10 @@ static void run(int child)
 		gem_read(fd, handle, 0, &handle, sizeof(handle));
 }
 
-#define NUM_FD 32000
-
 struct thread {
 	pthread_mutex_t mutex;
-	int fds[NUM_FD];
+	unsigned int num_fds;
+	int *fds;
 	int done;
 };
 
@@ -152,7 +153,7 @@ static void *thread_run(void *_data)
 	while (!t->done) {
 		pthread_mutex_unlock(&t->mutex);
 
-		for (int n = 0; n < NUM_FD; n++) {
+		for (int n = 0; n < t->num_fds; n++) {
 			struct drm_i915_gem_create create;
 
 			create.handle = 0;
@@ -185,7 +186,7 @@ static void *thread_busy(void *_data)
 
 		pthread_mutex_unlock(&t->mutex);
 
-		n  = rand() % NUM_FD;
+		n  = rand() % t->num_fds;
 
 		create.handle = 0;
 		create.size = OBJECT_SIZE;
@@ -213,16 +214,23 @@ igt_main
 {
 	igt_skip_on_simulation();
 
-	sprintf(device, "/dev/dri/card%d", drm_get_card());
-	{
-		int fd = open(device, O_RDWR);
+	igt_fixture {
+		int fd;
+		sprintf(device, "/dev/dri/card%d", drm_get_card());
+		fd = open(device, O_RDWR);
 		igt_assert(fd != -1);
 		devid = intel_get_drm_devid(fd);
+		if (gem_uses_full_ppgtt(fd))
+		{
+			/* Reduce the number of simultaneous fds or face OOM */
+			num_childs = 768;
+			num_fds = 768;
+		}
 		close(fd);
 	}
 
 	igt_subtest("process-exit") {
-		igt_fork(child, 2000)
+		igt_fork(child, num_childs)
 			run(child);
 		igt_waitchildren();
 	}
@@ -232,17 +240,21 @@ igt_main
 		struct thread *data = calloc(1, sizeof(struct thread));
 		int n;
 
+		data->num_fds = num_fds;
+		data->fds = calloc(num_fds, sizeof(int));
+
 		igt_assert(data);
+		igt_assert(data->fds);
 
 		pthread_mutex_init(&data->mutex, NULL);
-		for (n = 0; n < NUM_FD; n++)
+		for (n = 0; n < num_fds; n++)
 			data->fds[n] = open(device, O_RDWR);
 
 		pthread_create(&thread[0], NULL, thread_run, data);
 		pthread_create(&thread[1], NULL, thread_busy, data);
 
-		for (n = 0; n < 1000*NUM_FD; n++) {
-			int i = rand() % NUM_FD;
+		for (n = 0; n < 1000*num_fds; n++) {
+			int i = rand() % num_fds;
 			if (data->fds[i] == -1) {
 				data->fds[i] = open(device, O_RDWR);
 			} else{
@@ -258,8 +270,9 @@ igt_main
 		pthread_join(thread[1], NULL);
 		pthread_join(thread[0], NULL);
 
-		for (n = 0; n < NUM_FD; n++)
+		for (n = 0; n < num_fds; n++)
 			close(data->fds[n]);
+		free(data->fds);
 		free(data);
 	}
 }
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH 2/3] tests/gem_close_race: Adapt the test for Full PPGTT

Quoted 10 lines · On Tue, Dec 10, 2013 at 09:36:22AM +0000, [email protected] wrote:

From: Oscar Mateo <[email protected]>

With Full PPGTT, each new fd creates a new context and thus a new PPGTT, so we have to reduce the number of simultaneous fds or face OOM problems. For every new PPGTT, its PDEs are stored in the GGTT which imposes a limit of 1024 new contexts. We want to leave at least 1/4 of the GGTT available for "important" stuff like scanout buffers, so never open more than 768 fds.

This test hasn't been terribly effective at provoking the bug it tries to hit, so I think we can just unconditionally use the lower limit. That also helps with the really long runtime of this case a bit.
-Daniel

Quoted 120 lines
---
 tests/gem_close_race.c |   39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
tests/gem_close_race.c +26 -13
index 6064c02..f658c90 100644
@@ -49,6 +49,8 @@
 
 static char device[80];
 static uint32_t devid;
+static unsigned int num_childs = 2000;
+static unsigned int num_fds = 32000;
 
 static void selfcopy(int fd, uint32_t handle, int loops)
 {
@@ -136,11 +138,10 @@ static void run(int child)
 		gem_read(fd, handle, 0, &handle, sizeof(handle));
 }
 
-#define NUM_FD 32000
-
 struct thread {
 	pthread_mutex_t mutex;
-	int fds[NUM_FD];
+	unsigned int num_fds;
+	int *fds;
 	int done;
 };
 
@@ -152,7 +153,7 @@ static void *thread_run(void *_data)
 	while (!t->done) {
 		pthread_mutex_unlock(&t->mutex);
 
-		for (int n = 0; n < NUM_FD; n++) {
+		for (int n = 0; n < t->num_fds; n++) {
 			struct drm_i915_gem_create create;
 
 			create.handle = 0;
@@ -185,7 +186,7 @@ static void *thread_busy(void *_data)
 
 		pthread_mutex_unlock(&t->mutex);
 
-		n  = rand() % NUM_FD;
+		n  = rand() % t->num_fds;
 
 		create.handle = 0;
 		create.size = OBJECT_SIZE;
@@ -213,16 +214,23 @@ igt_main
 {
 	igt_skip_on_simulation();
 
-	sprintf(device, "/dev/dri/card%d", drm_get_card());
-	{
-		int fd = open(device, O_RDWR);
+	igt_fixture {
+		int fd;
+		sprintf(device, "/dev/dri/card%d", drm_get_card());
+		fd = open(device, O_RDWR);
 		igt_assert(fd != -1);
 		devid = intel_get_drm_devid(fd);
+		if (gem_uses_full_ppgtt(fd))
+		{
+			/* Reduce the number of simultaneous fds or face OOM */
+			num_childs = 768;
+			num_fds = 768;
+		}
 		close(fd);
 	}
 
 	igt_subtest("process-exit") {
-		igt_fork(child, 2000)
+		igt_fork(child, num_childs)
 			run(child);
 		igt_waitchildren();
 	}
@@ -232,17 +240,21 @@ igt_main
 		struct thread *data = calloc(1, sizeof(struct thread));
 		int n;
 
+		data->num_fds = num_fds;
+		data->fds = calloc(num_fds, sizeof(int));
+
 		igt_assert(data);
+		igt_assert(data->fds);
 
 		pthread_mutex_init(&data->mutex, NULL);
-		for (n = 0; n < NUM_FD; n++)
+		for (n = 0; n < num_fds; n++)
 			data->fds[n] = open(device, O_RDWR);
 
 		pthread_create(&thread[0], NULL, thread_run, data);
 		pthread_create(&thread[1], NULL, thread_busy, data);
 
-		for (n = 0; n < 1000*NUM_FD; n++) {
-			int i = rand() % NUM_FD;
+		for (n = 0; n < 1000*num_fds; n++) {
+			int i = rand() % num_fds;
 			if (data->fds[i] == -1) {
 				data->fds[i] = open(device, O_RDWR);
 			} else{
@@ -258,8 +270,9 @@ igt_main
 		pthread_join(thread[1], NULL);
 		pthread_join(thread[0], NULL);
 
-		for (n = 0; n < NUM_FD; n++)
+		for (n = 0; n < num_fds; n++)
 			close(data->fds[n]);
+		free(data->fds);
 		free(data);
 	}
 }
Signature · 6 lines
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw

Re: [PATCH 2/3] tests/gem_close_race: Adapt the test for Full PPGTT

Quoted 10 lines · Daniel Vetter
Quoted 9 lines · On Tue, Dec 10, 2013 at 09:36:22AM +0000, [email protected] wrote:

From: Oscar Mateo <[email protected]>

With Full PPGTT, each new fd creates a new context and thus a new PPGTT, so we have to reduce the number of simultaneous fds or face OOM problems. For every new PPGTT, its PDEs are stored in the GGTT which imposes a limit of 1024 new contexts. We want to leave at least 1/4 of the GGTT available for "important" stuff like scanout buffers, so never open more than 768 fds.

Quoted 6 lines
Quoted 1 line

This test hasn't been terribly effective at provoking the bug it tries to hit, so I think we can just unconditionally use the lower limit. That also helps with the really long runtime of this case a bit.
-Daniel

FWIW, all 3 of these patches, or their equivalents were in the branch I sent in my cover letter.

My implementation on this specifically was slightly different. Same idea.

Quoted 126 lines
Quoted 121 lines
---
 tests/gem_close_race.c |   39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)
tests/gem_close_race.c +26 -13
index 6064c02..f658c90 100644
@@ -49,6 +49,8 @@
 
 static char device[80];
 static uint32_t devid;
+static unsigned int num_childs = 2000;
+static unsigned int num_fds = 32000;
 
 static void selfcopy(int fd, uint32_t handle, int loops)
 {
@@ -136,11 +138,10 @@ static void run(int child)
 		gem_read(fd, handle, 0, &handle, sizeof(handle));
 }
 
-#define NUM_FD 32000
-
 struct thread {
 	pthread_mutex_t mutex;
-	int fds[NUM_FD];
+	unsigned int num_fds;
+	int *fds;
 	int done;
 };
 
@@ -152,7 +153,7 @@ static void *thread_run(void *_data)
 	while (!t->done) {
 		pthread_mutex_unlock(&t->mutex);
 
-		for (int n = 0; n < NUM_FD; n++) {
+		for (int n = 0; n < t->num_fds; n++) {
 			struct drm_i915_gem_create create;
 
 			create.handle = 0;
@@ -185,7 +186,7 @@ static void *thread_busy(void *_data)
 
 		pthread_mutex_unlock(&t->mutex);
 
-		n  = rand() % NUM_FD;
+		n  = rand() % t->num_fds;
 
 		create.handle = 0;
 		create.size = OBJECT_SIZE;
@@ -213,16 +214,23 @@ igt_main
 {
 	igt_skip_on_simulation();
 
-	sprintf(device, "/dev/dri/card%d", drm_get_card());
-	{
-		int fd = open(device, O_RDWR);
+	igt_fixture {
+		int fd;
+		sprintf(device, "/dev/dri/card%d", drm_get_card());
+		fd = open(device, O_RDWR);
 		igt_assert(fd != -1);
 		devid = intel_get_drm_devid(fd);
+		if (gem_uses_full_ppgtt(fd))
+		{
+			/* Reduce the number of simultaneous fds or face OOM */
+			num_childs = 768;
+			num_fds = 768;
+		}
 		close(fd);
 	}
 
 	igt_subtest("process-exit") {
-		igt_fork(child, 2000)
+		igt_fork(child, num_childs)
 			run(child);
 		igt_waitchildren();
 	}
@@ -232,17 +240,21 @@ igt_main
 		struct thread *data = calloc(1, sizeof(struct thread));
 		int n;
 
+		data->num_fds = num_fds;
+		data->fds = calloc(num_fds, sizeof(int));
+
 		igt_assert(data);
+		igt_assert(data->fds);
 
 		pthread_mutex_init(&data->mutex, NULL);
-		for (n = 0; n < NUM_FD; n++)
+		for (n = 0; n < num_fds; n++)
 			data->fds[n] = open(device, O_RDWR);
 
 		pthread_create(&thread[0], NULL, thread_run, data);
 		pthread_create(&thread[1], NULL, thread_busy, data);
 
-		for (n = 0; n < 1000*NUM_FD; n++) {
-			int i = rand() % NUM_FD;
+		for (n = 0; n < 1000*num_fds; n++) {
+			int i = rand() % num_fds;
 			if (data->fds[i] == -1) {
 				data->fds[i] = open(device, O_RDWR);
 			} else{
@@ -258,8 +270,9 @@ igt_main
 		pthread_join(thread[1], NULL);
 		pthread_join(thread[0], NULL);
 
-		for (n = 0; n < NUM_FD; n++)
+		for (n = 0; n < num_fds; n++)
 			close(data->fds[n]);
+		free(data->fds);
 		free(data);
 	}
 }
Signature · 6 lines
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#4 lore raw

Re: [PATCH 2/3] tests/gem_close_race: Adapt the test for Full PPGTT

Quoted 4 lines
Quoted 4 lines

This test hasn't been terribly effective at provoking the bug it tries to hit, so I think we can just unconditionally use the lower limit. That also helps with the really long runtime of this case a bit. -Daniel

Understood. I´ll simplify the patch and send it again then.

Quoted 2 lines

FWIW, all 3 of these patches, or their equivalents were in the branch I sent in my cover letter.

I saw your series and I thought that I better send these patches over, but I missed that point in your cover letter, sorry :( How should we do it, then? will Daniel take them directly from your branch?

-- Oscar

#5 lore raw

Re: [PATCH 2/3] tests/gem_close_race: Adapt the test for Full PPGTT

Quoted 7 lines · Oscar
Quoted 4 lines
Quoted 4 lines

This test hasn't been terribly effective at provoking the bug it tries to hit, so I think we can just unconditionally use the lower limit. That also helps with the really long runtime of this case a bit. -Daniel

Understood. I´ll simplify the patch and send it again then.

Quoted 7 lines
Quoted 2 lines

FWIW, all 3 of these patches, or their equivalents were in the branch I sent in my cover letter.

I saw your series and I thought that I better send these patches over, but I missed that point in your cover letter, sorry :( How should we do it, then? will Daniel take them directly from your branch?

-- Oscar

You're fine. Use these when support is merged. My point to Daniel was reiterating that this was tested on the patches I've submitted. (though not with the identical patches).

Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

PATCH 3/3 tests/gem_ppgtt: New Full PPGTT set of tests

In reply to [email protected]

From: Oscar Mateo <[email protected]>

These tests cover some tricky corner cases found during the True-and-only Full PPGTT feature development.

v2: Add pthread requirement to Makefile.
v3: Added new "pinned" testcase.
v4: Require Full PPGTT.

---
 tests/.gitignore       |    1 +
 tests/Makefile.am      |    1 +
 tests/Makefile.sources |    1 +
 tests/gem_full_ppgtt.c |  327 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 330 insertions(+)
 create mode 100644 tests/gem_full_ppgtt.c
tests/.gitignore +1 -0
index 8a00364..a77b544 100644
@@ -55,6 +55,7 @@ gem_partial_pwrite_pread
 gem_persistent_relocs
 gem_pin
 gem_pipe_control_store_loop
+gem_full_ppgtt
 gem_pread
 gem_pread_after_blit
 gem_pwrite
tests/Makefile.am +1 -0
index b8cddd5..02e0796 100644
@@ -32,6 +32,7 @@ LDADD = ../lib/libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS)
 LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS)
 AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)
 
+gem_full_ppgtt_LDADD = $(LDADD) -lpthread
 gem_close_race_LDADD = $(LDADD) -lpthread
 gem_fence_thrash_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_fence_thrash_LDADD = $(LDADD) -lpthread
tests/Makefile.sources +1 -0
index ca2b58c..c3c1852 100644
@@ -36,6 +36,7 @@ TESTS_progs_M = \
 	gem_mmap_gtt \
 	gem_partial_pwrite_pread \
 	gem_persistent_relocs \
+	gem_full_ppgtt \
 	gem_pread \
 	gem_pread_after_blit \
 	gem_pwrite \
tests/gem_full_ppgtt.c new file +327 -0

327 lines not on this page · raw message

Signature · 6 lines
1.7.9.5

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