gem_tiled_swapping: Test using all available fences
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 7 Apr 2014 12:10:41 +0000 (13:10 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 7 Apr 2014 12:12:29 +0000 (13:12 +0100)
Use extra threads to cause extra memory pressure and stress upon the
relevant code. Limit the number of threads to available fences to avoid
falling off the fence cliff.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
tests/Makefile.am
tests/gem_tiled_swapping.c

index c26a3d0..8ce0858 100644 (file)
@@ -55,6 +55,8 @@ gem_flink_race_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_flink_race_LDADD = $(LDADD) -lpthread
 gem_threaded_access_tiled_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_threaded_access_tiled_LDADD = $(LDADD) -lpthread
+gem_tiled_swapping_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
+gem_tiled_swapping_LDADD = $(LDADD) -lpthread
 prime_self_import_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 prime_self_import_LDADD = $(LDADD) -lpthread
 gen7_forcewake_mt_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
index aecd543..3bd2fa7 100644 (file)
@@ -53,6 +53,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/ioctl.h>
+#include <pthread.h>
 
 #include <drm.h>
 
@@ -91,14 +92,64 @@ create_bo_and_fill(int fd)
 }
 
 uint32_t *bo_handles;
-int *idx_arr;
 
-igt_simple_main
+struct thread {
+       pthread_t thread;
+       int *idx_arr;
+       int fd, count;
+};
+
+static void
+check_bo(int fd, uint32_t handle)
 {
-       int fd;
        uint32_t *data;
-       int i, j;
-       int count;
+       int j;
+
+       /* Check the target bo's contents. */
+       data = gem_mmap(fd, handle, LINEAR_DWORDS, PROT_READ | PROT_WRITE);
+       for (j = 0; j < WIDTH*HEIGHT; j++)
+               igt_assert_f(data[j] == j,
+                            "mismatch at %i: %i\n",
+                            j, data[j]);
+       munmap(data, LINEAR_DWORDS);
+}
+
+static void *thread_run(void *data)
+{
+       struct thread *t = data;
+       int i;
+
+       for (i = 0; i < t->count; i++)
+               check_bo(t->fd, bo_handles[t->idx_arr[i]]);
+
+       return NULL;
+}
+
+static void thread_init(struct thread *t, int fd, int count)
+{
+       int i;
+
+       t->fd = fd;
+       t->count = count;
+       t->idx_arr = calloc(count, sizeof(int));
+       igt_assert(t->idx_arr);
+
+       for (i = 0; i < count; i++)
+               t->idx_arr[i] = i;
+
+       igt_permute_array(t->idx_arr, count, igt_exchange_int);
+}
+
+static void thread_fini(struct thread *t)
+{
+       free(t->idx_arr);
+}
+
+igt_simple_main
+{
+       struct thread *threads;
+       int fd, n, count, num_threads;
+
        current_tiling_mode = I915_TILING_X;
 
        igt_skip_on_simulation();
@@ -110,8 +161,9 @@ igt_simple_main
        bo_handles = calloc(count, sizeof(uint32_t));
        igt_assert(bo_handles);
 
-       idx_arr = calloc(count, sizeof(int));
-       igt_assert(idx_arr);
+       num_threads = gem_available_fences(fd);
+       threads = calloc(num_threads, sizeof(struct thread));
+       igt_assert(threads);
 
        igt_log(IGT_LOG_INFO,
                "Using %d 1MiB objects (available RAM: %ld/%ld, swap: %ld)\n",
@@ -122,27 +174,26 @@ igt_simple_main
 
        igt_require(count < intel_get_avail_ram_mb() + intel_get_total_swap_mb());
 
-       for (i = 0; i < count; i++) {
-               bo_handles[i] = create_bo_and_fill(fd);
+       for (n = 0; n < count; n++) {
+               bo_handles[n] = create_bo_and_fill(fd);
                /* Not enough mmap address space possible. */
-               igt_require(bo_handles[i]);
+               igt_require(bo_handles[n]);
        }
 
-       for (i = 0; i < count; i++)
-               idx_arr[i] = i;
-
-       igt_permute_array(idx_arr, count,
-                             igt_exchange_int);
-
-       for (i = 0; i < count/2; i++) {
-               /* Check the target bo's contents. */
-               data = gem_mmap(fd, bo_handles[idx_arr[i]],
-                               LINEAR_DWORDS, PROT_READ | PROT_WRITE);
-               for (j = 0; j < WIDTH*HEIGHT; j++)
-                       igt_assert_f(data[j] == j,
-                                    "mismatch at %i: %i\n",
-                                    j, data[j]);
-               munmap(data, LINEAR_DWORDS);
+       thread_init(&threads[0], fd, count);
+       thread_run(&threads[0]);
+       thread_fini(&threads[0]);
+
+       /* Once more with threads */
+       igt_subtest("threaded") {
+               for (n = 0; n < num_threads; n++) {
+                       thread_init(&threads[n], fd, count);
+                       pthread_create(&threads[n].thread, NULL, thread_run, &threads[n]);
+               }
+               for (n = 0; n < num_threads; n++) {
+                       pthread_join(threads[n].thread, NULL);
+                       thread_fini(&threads[n]);
+               }
        }
 
        close(fd);