From: Chris Wilson Date: Mon, 7 Apr 2014 12:10:41 +0000 (+0100) Subject: gem_tiled_swapping: Test using all available fences X-Git-Tag: intel-gpu-tools-1.7~165 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9eec5b0f11d864c986511db07d447e379bcef696;p=platform%2Fupstream%2Fintel-gpu-tools.git gem_tiled_swapping: Test using all available fences 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 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index c26a3d0..8ce0858 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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) diff --git a/tests/gem_tiled_swapping.c b/tests/gem_tiled_swapping.c index aecd543..3bd2fa7 100644 --- a/tests/gem_tiled_swapping.c +++ b/tests/gem_tiled_swapping.c @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -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);