diff options
Diffstat (limited to 'tests/gem_tiled_swapping.c')
-rw-r--r-- | tests/gem_tiled_swapping.c | 156 |
1 files changed, 105 insertions, 51 deletions
diff --git a/tests/gem_tiled_swapping.c b/tests/gem_tiled_swapping.c index d1484f0e..86c79f2d 100644 --- a/tests/gem_tiled_swapping.c +++ b/tests/gem_tiled_swapping.c @@ -47,22 +47,24 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <assert.h> #include <fcntl.h> #include <inttypes.h> #include <errno.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/ioctl.h> -#include <sys/mman.h> -#include "drm.h" -#include "i915_drm.h" +#include <pthread.h> + +#include <drm.h> + +#include "ioctl_wrappers.h" #include "drmtest.h" -#include "intel_gpu_tools.h" +#include "intel_io.h" +#include "igt_aux.h" #define WIDTH 512 #define HEIGHT 512 -static uint32_t linear[WIDTH * HEIGHT]; +#define LINEAR_DWORDS (4 * WIDTH * HEIGHT) static uint32_t current_tiling_mode; #define PAGE_SIZE 4096 @@ -74,72 +76,124 @@ create_bo_and_fill(int fd) uint32_t *data; int i; - handle = gem_create(fd, sizeof(linear)); + handle = gem_create(fd, LINEAR_DWORDS); gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t)); /* Fill the BO with dwords starting at start_val */ - data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE); + data = gem_mmap(fd, handle, LINEAR_DWORDS, PROT_READ | PROT_WRITE); + if (data == NULL && errno == ENOSPC) + return 0; + for (i = 0; i < WIDTH*HEIGHT; i++) data[i] = i; - munmap(data, sizeof(linear)); + munmap(data, LINEAR_DWORDS); return handle; } uint32_t *bo_handles; -int *idx_arr; -int -main(int argc, char **argv) +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; - current_tiling_mode = I915_TILING_X; + 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); +} - fd = drm_open_any(); - /* need slightly more than total ram */ - count = intel_get_total_ram_mb() * 11 / 10; - bo_handles = calloc(count, sizeof(uint32_t)); - assert(bo_handles); +static void *thread_run(void *data) +{ + struct thread *t = data; + int i; - idx_arr = calloc(count, sizeof(int)); - assert(idx_arr); + for (i = 0; i < t->count; i++) + check_bo(t->fd, bo_handles[t->idx_arr[i]]); - if (intel_get_total_swap_mb() == 0) { - printf("no swap detected\n"); - return 77; - } + return NULL; +} - if (intel_get_total_ram_mb() / 4 > intel_get_total_swap_mb()) { - printf("not enough swap detected\n"); - return 77; - } +static void thread_init(struct thread *t, int fd, int count) +{ + int i; - for (i = 0; i < count; i++) - bo_handles[i] = create_bo_and_fill(fd); + t->fd = fd; + t->count = count; + t->idx_arr = calloc(count, sizeof(int)); + igt_assert(t->idx_arr); for (i = 0; i < count; i++) - idx_arr[i] = i; - - drmtest_permute_array(idx_arr, count, - drmtest_exchange_int); - - for (i = 0; i < count/2; i++) { - /* Check the target bo's contents. */ - data = gem_mmap(fd, bo_handles[idx_arr[i]], - sizeof(linear), PROT_READ | PROT_WRITE); - for (j = 0; j < WIDTH*HEIGHT; j++) - if (data[j] != j) { - fprintf(stderr, "mismatch at %i: %i\n", - j, data[j]); - exit(1); - } - munmap(data, sizeof(linear)); + 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(); + intel_purge_vm_caches(); + + fd = drm_open_any(); + /* need slightly more than available memory */ + count = intel_get_total_ram_mb() + intel_get_total_swap_mb() / 4; + bo_handles = calloc(count, sizeof(uint32_t)); + igt_assert(bo_handles); + + 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", + count, + (long)intel_get_avail_ram_mb(), + (long)intel_get_total_ram_mb(), + (long)intel_get_total_swap_mb()); + igt_require(intel_check_memory(count, 1024*1024, CHECK_RAM | CHECK_SWAP)); + + for (n = 0; n < count; n++) { + bo_handles[n] = create_bo_and_fill(fd); + /* Not enough mmap address space possible. */ + igt_require(bo_handles[n]); } - close(fd); + 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]); + } + } - return 0; + close(fd); } |