Skip to contentSkip to conversation

tests/gem_userptr_blits: Expanded userptr test cases

PATCH In review Tvrtko Ursulin 3 participants 5 messages Jan 29, 2014 – Jan 30, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/gem_userptr_blits: Expanded userptr test cases

From: Tvrtko Ursulin <[email protected]>

A set of userptr test cases to support the new feature.

For the eviction and swapping stress testing I have extracted some common behaviour from gem_evict_everything and made both test cases use it to avoid duplicating the code.

Both unsynchronized and synchronized userptr objects are tested but the latter set of tests will be skipped if kernel is compiled without MMU_NOTIFIERS.

Also, with 32-bit userspace swapping tests are skipped if the system has a lot more RAM than process address space. Forking swapping tests are not skipped since they can still trigger swapping by cumulative effect.

Tested with userptr patch v18 on Android (with some swap added).

---
 lib/drmtest.c                |  185 ++++++++
 lib/drmtest.h                |   32 ++
 tests/.gitignore             |    2 +-
 tests/Makefile.sources       |    2 +-
 tests/gem_evict_everything.c |  182 ++------
 tests/gem_userptr_blits.c    |  990 ++++++++++++++++++++++++++++++++++++++++++
 tests/gem_vmap_blits.c       |  344 ---------------
 7 files changed, 1235 insertions(+), 502 deletions(-)
 create mode 100644 tests/gem_userptr_blits.c
 delete mode 100644 tests/gem_vmap_blits.c
lib/drmtest.c +185 -0
index 8bc70a3..b5c1971 100644
@@ -1685,3 +1685,188 @@ void igt_drop_root(void)
 	igt_assert(getgid() == 2);
 	igt_assert(getuid() == 2);
 }
+
+static void igt_exchange_uint32_t(void *array, unsigned i, unsigned j)
+{
+	uint32_t *i_arr = array;
+	uint32_t i_tmp;
+
+	i_tmp = i_arr[i];
+	i_arr[i] = i_arr[j];
+	i_arr[j] = i_tmp;
+}
+
+int igt_minor_evictions(int fd, struct igt_eviction_test_ops *ops,
+			int surface_size, int nr_surfaces)
+{
+	uint32_t *bo, *sel;
+	int n, m, pass, fail;
+
+	igt_require((uint64_t)nr_surfaces * surface_size / (1024 * 1024)
+			< intel_get_total_ram_mb() * 9 / 10);
+
+	bo = malloc(3*nr_surfaces*sizeof(*bo));
+	igt_assert(bo);
+
+	for (n = 0; n < 2*nr_surfaces; n++)
+		bo[n] = ops->create(fd, surface_size);
+
+	sel = bo + n;
+	for (fail = 0, m = 0; fail < 10; fail++) {
+		for (pass = 0; pass < 100; pass++) {
+			for (n = 0; n < nr_surfaces; n++, m += 7)
+				sel[n] = bo[m%(2*nr_surfaces)];
+			ops->copy(fd, sel[0], sel[1], sel, nr_surfaces, 0);
+		}
+		ops->copy(fd, bo[0], bo[0], bo, 2*nr_surfaces, ENOSPC);
+	}
+
+	for (n = 0; n < 2*nr_surfaces; n++)
+		ops->close(fd, bo[n]);
+	free(bo);
+
+	return 0;
+}
+
+int igt_major_evictions(int fd, struct igt_eviction_test_ops *ops,
+			int surface_size, int nr_surfaces)
+{
+	int n, m, loop;
+	uint32_t *bo;
+
+	igt_require((uint64_t)nr_surfaces * surface_size / (1024 * 1024)
+			< intel_get_total_ram_mb() * 9 / 10);
+
+	bo = malloc(nr_surfaces*sizeof(*bo));
+	igt_assert(bo);
+
+	for (n = 0; n < nr_surfaces; n++)
+		bo[n] = ops->create(fd, surface_size);
+
+	for (loop = 0, m = 0; loop < 100; loop++, m += 17) {
+		n = m % nr_surfaces;
+		ops->copy(fd, bo[n], bo[n], &bo[n], 1, 0);
+	}
+
+	for (n = 0; n < nr_surfaces; n++)
+		ops->close(fd, bo[n]);
+	free(bo);
+
+	return 0;
+}
+
+int igt_swapping_evictions(int fd, struct igt_eviction_test_ops *ops,
+			   int surface_size,
+			   int working_surfaces,
+			   int trash_surfaces)
+{
+	uint32_t *bo;
+	int i, n, pass;
+
+	igt_require((uint64_t)working_surfaces * surface_size / (1024 * 1024)
+			< intel_get_total_ram_mb() * 9 / 10);
+
+	if (trash_surfaces < working_surfaces)
+		trash_surfaces = working_surfaces;
+
+	bo = malloc(trash_surfaces*sizeof(*bo));
+	igt_assert(bo);
+
+	for (n = 0; n < trash_surfaces; n++)
+		bo[n] = ops->create(fd, surface_size);
+
+	for (i = 0; i < trash_surfaces/32; i++) {
+		igt_permute_array(bo, trash_surfaces, igt_exchange_uint32_t);
+
+		for (pass = 0; pass < 100; pass++) {
+			ops->copy(fd, bo[0], bo[1], bo, working_surfaces, 0);
+		}
+	}
+
+	for (n = 0; n < trash_surfaces; n++)
+		ops->close(fd, bo[n]);
+	free(bo);
+
+	return 0;
+}
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+
+int igt_forking_evictions(int fd, struct igt_eviction_test_ops *ops,
+			  int surface_size, int working_surfaces,
+			  int trash_surfaces, unsigned flags)
+{
+	uint32_t *bo;
+	int n, pass, l;
+	int num_threads = sysconf(_SC_NPROCESSORS_ONLN);
+	int bo_count;
+
+	igt_require((uint64_t)working_surfaces * surface_size / (1024 * 1024)
+			< intel_get_total_ram_mb() * 9 / 10);
+
+	if (flags & FORKING_EVICTIONS_SWAPPING) {
+		igt_require(intel_get_total_ram_mb() / 4
+				< intel_get_total_swap_mb());
+		bo_count = trash_surfaces;
+
+		if (bo_count < working_surfaces)
+			bo_count = working_surfaces;
+	} else
+		bo_count = working_surfaces;
+
+	bo = malloc(bo_count*sizeof(*bo));
+	igt_assert(bo);
+
+	for (n = 0; n < bo_count; n++)
+		bo[n] = ops->create(fd, surface_size);
+
+	igt_fork(i, min(num_threads * 4, 12)) {
+		int realfd = fd;
+		int num_passes = flags & FORKING_EVICTIONS_SWAPPING ? 10 : 100;
+
+		/* Every fork should have a different permutation! */
+		srand(i * 63);
+
+		if (flags & FORKING_EVICTIONS_INTERRUPTIBLE)
+			igt_fork_signal_helper();
+
+		igt_permute_array(bo, bo_count, igt_exchange_uint32_t);
+
+		if (flags & FORKING_EVICTIONS_DUP_DRMFD) {
+			realfd = drm_open_any();
+
+			/* We can overwrite the bo array since we're forked. */
+			for (l = 0; l < bo_count; l++) {
+				uint32_t flink;
+
+				flink = gem_flink(fd, bo[l]);
+				bo[l] = gem_open(realfd, flink);
+			}
+		}
+
+		for (pass = 0; pass < num_passes; pass++) {
+			ops->copy(realfd, bo[0], bo[1], bo, working_surfaces, 0);
+
+			for (l = 0; l < working_surfaces &&
+			  (flags & FORKING_EVICTIONS_MEMORY_PRESSURE);
+			    l++) {
+				ops->clear(realfd, bo[l], surface_size);
+			}
+		}
+
+		if (flags & FORKING_EVICTIONS_INTERRUPTIBLE)
+			igt_stop_signal_helper();
+
+		/* drmfd closing will take care of additional bo refs */
+		if (flags & FORKING_EVICTIONS_DUP_DRMFD)
+			close(realfd);
+	}
+
+	igt_waitchildren();
+
+	for (n = 0; n < bo_count; n++)
+		ops->close(fd, bo[n]);
+	free(bo);
+
+	return 0;
+}
lib/drmtest.h +32 -0
index d42a6f7..022af1d 100644
@@ -361,4 +361,36 @@ void igt_system_suspend_autoresume(void);
 /* dropping priviledges */
 void igt_drop_root(void);
 
+struct igt_eviction_test_ops
+{
+	uint32_t (*create)(int fd, int size);
+	void	 (*close)(int fd, uint32_t bo);
+	void	 (*copy)(int fd, uint32_t dst, uint32_t src,
+			 uint32_t *all_bo, int nr_bos, int error);
+	void	 (*clear)(int fd, uint32_t bo, int size);
+};
+
+int igt_minor_evictions(int fd, struct igt_eviction_test_ops *ops,
+			int surface_size, int nr_surfaces);
+
+int igt_major_evictions(int fd, struct igt_eviction_test_ops *ops,
+			int surface_size, int nr_surfaces);
+
+int igt_swapping_evictions(int fd, struct igt_eviction_test_ops *ops,
+			   int surface_size, int working_surfaces,
+			   int trash_surfaces);
+
+#define FORKING_EVICTIONS_INTERRUPTIBLE	  (1 << 0)
+#define FORKING_EVICTIONS_SWAPPING	  (1 << 1)
+#define FORKING_EVICTIONS_DUP_DRMFD	  (1 << 2)
+#define FORKING_EVICTIONS_MEMORY_PRESSURE (1 << 3)
+#define ALL_FORKING_EVICTIONS	(FORKING_EVICTIONS_INTERRUPTIBLE | \
+				 FORKING_EVICTIONS_SWAPPING | \
+				 FORKING_EVICTIONS_DUP_DRMFD | \
+				 FORKING_EVICTIONS_MEMORY_PRESSURE)
+
+int igt_forking_evictions(int fd, struct igt_eviction_test_ops *ops,
+			  int surface_size, int working_surfaces,
+			  int trash_surfaces, unsigned flags);
+
 #endif /* DRMTEST_H */
tests/.gitignore +1 -1
index 7377275..798eeed 100644
@@ -91,7 +91,7 @@ gem_tiled_swapping
 gem_tiling_max_stride
 gem_unfence_active_buffers
 gem_unref_active_buffers
-gem_vmap_blits
+gem_userptr_blits
 gem_wait_render_timeout
 gem_write_read_ring_switch
 gen3_mixed_blits
tests/Makefile.sources +1 -1
index a8c0c96..2d42a18 100644
@@ -115,7 +115,7 @@ TESTS_progs = \
 	gem_tiling_max_stride \
 	gem_unfence_active_buffers \
 	gem_unref_active_buffers \
-	gem_vmap_blits \
+	gem_userptr_blits \
 	gem_wait_render_timeout \
 	gen3_mixed_blits \
 	gen3_render_linear_blits \
tests/gem_evict_everything.c +26 -156

221 lines not on this page · raw message

tests/gem_userptr_blits.c new file +990 -0

990 lines not on this page · raw message

tests/gem_vmap_blits.c deleted +0 -344

344 lines not on this page · raw message

Signature · 6 lines
1.7.9.7

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

Not your fault, just exposed under recent testing

Quoted 9 lines · Tvrtko Ursulin
lib/drmtest.c +9 -0
+int igt_minor_evictions(int fd, struct igt_eviction_test_ops *ops,
+			int surface_size, int nr_surfaces)
+{
+	uint32_t *bo, *sel;
+	int n, m, pass, fail;
+
+	igt_require((uint64_t)nr_surfaces * surface_size / (1024 * 1024)
+			< intel_get_total_ram_mb() * 9 / 10);
+

lib/drmtest.c void igt_drop_root(void) · line 1717

Quoted 10 lines
lib/drmtest.c +10 -0
+	bo = malloc(3*nr_surfaces*sizeof(*bo));
+	igt_assert(bo);
+
+	for (n = 0; n < 2*nr_surfaces; n++)
+		bo[n] = ops->create(fd, surface_size);
+
+	sel = bo + n;
+	for (fail = 0, m = 0; fail < 10; fail++) {
+		for (pass = 0; pass < 100; pass++) {
+			for (n = 0; n < nr_surfaces; n++, m += 7)

The issue I found was that I had a nr_surface that was divisible by 7...

So we can either keep a table of prime numbers (may come in useful elsewhere) and pick the prime closest to nr_surfaces, or we can just tweak nr_surfaces not to be divisible by 7...

So something like:

/* Fudge to avoid duplicate bo during execbuffer */ nr_surfaces /= 7;
nr_surfaces *= 7;
nr_surfaces += 1;

should paper over the mistake.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
In reply to Tvrtko Ursulin
Quoted 12 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

A set of userptr test cases to support the new feature.

For the eviction and swapping stress testing I have extracted some common behaviour from gem_evict_everything and made both test cases use it to avoid duplicating the code.

Both unsynchronized and synchronized userptr objects are tested but the latter set of tests will be skipped if kernel is compiled without MMU_NOTIFIERS.

Quoted 8 lines

Also, with 32-bit userspace swapping tests are skipped if the system has a lot more RAM than process address space. Forking swapping tests are not skipped since they can still trigger swapping by cumulative effect.

Tested with userptr patch v18 on Android (with some swap added).

Minor thing on patch style: I'd split this up into 3 parts:
- Extraction of the helpers - always useful to shine a bit light onto new helper stuff so other people also notice them.
- The new testcase.
- Removal of the old vmap testcase.

The other patch style thing are the helpers - the forking_eviction stuff doesn't really sound like a bit of helper code. igt_exchange_uint32_t certainly is, but the other stuff I'd just put into a common source file which is included by both tests. Yeah #include "common.c" is a bit evil, but this is a testsuite ;-) Or just copy&paste the code into the userptr test, which is the approach I'd have done.

Now for test coverage it sounds like this testcases here has been more than good enough to shake down the userptr implementation, so I think we're covered.

But there is also basic interface coverage for sanity-checking and defending against evil userspace. For this case here I think we need:

- Tests with un-aligned ptr/size.
- Tests with invalid flags.
- Basic nastiness of handing in an invalid pointer.

Then there's all the interactions with other gem interfaces:
- pwrite/pread/set_tiling: Should probably all fail with -EINVAL or something like that.
- dma-buf export/gem flink: should succeed.
- But: dma-buf mapping for a foreign device should fail. This will be a pain to test on Android since we don't have anything else really. I can take that and do a test like the pile of prime_nv tests we have.
- gtt mmaps: Theoretically works, but dunno whether it makes sense.
- Anything esle I've forgotten?

I don't expect any real surprises here, but imo we need to have this.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw

Hi,

Quoted 4 lines · Daniel Vetter
Quoted 3 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

A set of userptr test cases to support the new feature.

[snip]

Quoted 5 lines

Minor thing on patch style: I'd split this up into 3 parts:
- Extraction of the helpers - always useful to shine a bit light onto new helper stuff so other people also notice them.
- The new testcase.
- Removal of the old vmap testcase.

I was afraid someone will say that, but was hoping for a lower bar since, to quote what yourself say later in this mail, "is a bit evil, but this is a testuite ;-)". :)

Okay, I'll split it up.

Quoted 6 lines

The other patch style thing are the helpers - the forking_eviction stuff doesn't really sound like a bit of helper code. igt_exchange_uint32_t certainly is, but the other stuff I'd just put into a common source file which is included by both tests. Yeah #include "common.c" is a bit evil, but this is a testsuite ;-) Or just copy&paste the code into the userptr test, which is the approach I'd have done.

It would be too much c&p for my liking so I chose this route.

Quoted 9 lines

Now for test coverage it sounds like this testcases here has been more than good enough to shake down the userptr implementation, so I think we're covered.

But there is also basic interface coverage for sanity-checking and defending against evil userspace. For this case here I think we need:

- Tests with un-aligned ptr/size.
- Tests with invalid flags.

Above are already there as test_usage_restrictions and test_input_checking.

Quoted 1 line

- Basic nastiness of handing in an invalid pointer.

You mean trying to map something which doesn't exist in user address space? Any idea how to obtain such a pointer? Or just use zero?

Quoted 3 lines

Then there's all the interactions with other gem interfaces:
- pwrite/pread/set_tiling: Should probably all fail with -EINVAL or something like that.

Ok.

Quoted 4 lines

- dma-buf export/gem flink: should succeed.
- But: dma-buf mapping for a foreign device should fail. This will be a pain to test on Android since we don't have anything else really. I can take that and do a test like the pile of prime_nv tests we have.

Flink is there in forking_evictions.

Dmabuf is something I know nothing at the moment so I'll have to look into it.

Quoted 1 line

- gtt mmaps: Theoretically works, but dunno whether it makes sense.

According to Chris not on all architectures, I have to find relevant documentation for that.

Quoted 1 line

- Anything esle I've forgotten?

Don't know, but thanks for your comments!

Regards,

Tvrtko

#4 lore raw
Quoted 34 lines · Tvrtko Ursulin
Quoted 6 lines · Daniel Vetter
Quoted 4 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

A set of userptr test cases to support the new feature.

[snip]

Quoted 5 lines

Minor thing on patch style: I'd split this up into 3 parts:
- Extraction of the helpers - always useful to shine a bit light onto new helper stuff so other people also notice them.
- The new testcase.
- Removal of the old vmap testcase.

I was afraid someone will say that, but was hoping for a lower bar since, to quote what yourself say later in this mail, "is a bit evil, but this is a testuite ;-)". :)

Okay, I'll split it up.

Quoted 6 lines

The other patch style thing are the helpers - the forking_eviction stuff doesn't really sound like a bit of helper code. igt_exchange_uint32_t certainly is, but the other stuff I'd just put into a common source file which is included by both tests. Yeah #include "common.c" is a bit evil, but this is a testsuite ;-) Or just copy&paste the code into the userptr test, which is the approach I'd have done.

Quoted 1 line

It would be too much c&p for my liking so I chose this route.

You have too high standards ;-) I'm quite a bit in favour of massive c&p in testcases since change tests always has the risk to break them, and hence lose a bit of coverage. But since this is for stress-tests the risk for subtle breakage is fairly small I think.

Quoted 4 lines
Quoted 4 lines

Now for test coverage it sounds like this testcases here has been more than good enough to shake down the userptr implementation, so I think we're covered.

Quoted 8 lines
Quoted 5 lines

But there is also basic interface coverage for sanity-checking and defending against evil userspace. For this case here I think we need:

- Tests with un-aligned ptr/size.
- Tests with invalid flags.

Above are already there as test_usage_restrictions and test_input_checking.

Oh, missed that. In that case we're good already.

Quoted 5 lines
Quoted 1 line

- Basic nastiness of handing in an invalid pointer.

You mean trying to map something which doesn't exist in user address space? Any idea how to obtain such a pointer? Or just use zero?

NULL should be good enough. 2nd version could use a gtt mmap'ed area obtained from i915.ko - those aren't struct page backed either and in addition also provoke lock inversion issues. I think with those two cases we should be well covered.

Quoted 14 lines
Quoted 3 lines

Then there's all the interactions with other gem interfaces:
- pwrite/pread/set_tiling: Should probably all fail with -EINVAL or something like that.

Ok.

Quoted 4 lines

- dma-buf export/gem flink: should succeed.
- But: dma-buf mapping for a foreign device should fail. This will be a pain to test on Android since we don't have anything else really. I can take that and do a test like the pile of prime_nv tests we have.

Quoted 4 lines

Flink is there in forking_evictions.

Dmabuf is something I know nothing at the moment so I'll have to look into it.

dma-buf has two use-case:
- Improved buffer sharing (better security) than flink, used by wayland and dri3.
- Sharing backing storage across devices (similar to what ION does on Android - actually ION is nowadays based on dma-buf internally).

We might want allow the 1. usecase with userptr I think, but we also need to reject the 2. one. But since this is a bit tricky it might be easier to outright reject all dma-buf exporting of userptrs for now. See the prime_self_import testcase, the actual exporting (i.e. where we'd need to insert a return -EINVAL) in the kernel happens in i915_gem_prime_export

Quoted 5 lines
Quoted 1 line

- gtt mmaps: Theoretically works, but dunno whether it makes sense.

According to Chris not on all architectures, I have to find relevant documentation for that.

I think we can just reject gtt mmaps for now then. Tbh I don't think it makes too much sense as a use-case really anyway.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch