Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008-9 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * Chris Wilson <chris@chris-wilson.co.uk> |
| 26 | * |
| 27 | */ |
| 28 | |
Damien Lespiau | 7ee278f | 2013-02-20 14:40:07 +0000 | [diff] [blame] | 29 | #ifdef HAVE_CONFIG_H |
Alan Coopersmith | 504c4fa | 2012-01-06 15:45:29 -0800 | [diff] [blame] | 30 | #include "config.h" |
Damien Lespiau | 7ee278f | 2013-02-20 14:40:07 +0000 | [diff] [blame] | 31 | #endif |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 32 | |
| 33 | #include <unistd.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <stdio.h> |
| 36 | #include <string.h> |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 37 | #include <fcntl.h> |
| 38 | #include <inttypes.h> |
| 39 | #include <errno.h> |
| 40 | #include <sys/stat.h> |
| 41 | #include <sys/ioctl.h> |
| 42 | #include <sys/mman.h> |
| 43 | #include <pthread.h> |
| 44 | #include "drm.h" |
| 45 | #include "i915_drm.h" |
| 46 | #include "drmtest.h" |
| 47 | |
Daniel Vetter | 2e9e27c | 2011-10-15 13:46:19 +0200 | [diff] [blame] | 48 | #define OBJECT_SIZE (128*1024) /* restricted to 1MiB alignment on i915 fences */ |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 49 | |
| 50 | /* Before introduction of the LRU list for fences, allocation of a fence for a page |
| 51 | * fault would use the first inactive fence (i.e. in preference one with no outstanding |
| 52 | * GPU activity, or it would wait on the first to finish). Given the choice, it would simply |
| 53 | * reuse the fence that had just been allocated for the previous page-fault - the worst choice |
| 54 | * when copying between two buffers and thus constantly swapping fences. |
| 55 | */ |
| 56 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 57 | struct test { |
| 58 | int fd; |
| 59 | int tiling; |
| 60 | int num_surfaces; |
| 61 | }; |
| 62 | |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 63 | static void * |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 64 | bo_create (int fd, int tiling) |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 65 | { |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 66 | void *ptr; |
| 67 | int handle; |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 68 | |
Daniel Vetter | ff93f35 | 2012-03-24 19:22:21 +0100 | [diff] [blame] | 69 | handle = gem_create(fd, OBJECT_SIZE); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 70 | |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 71 | /* dirty cpu caches a bit ... */ |
| 72 | ptr = gem_mmap__cpu(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 73 | igt_assert(ptr); |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 74 | memset(ptr, 0, OBJECT_SIZE); |
| 75 | munmap(ptr, OBJECT_SIZE); |
| 76 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 77 | gem_set_tiling(fd, handle, tiling, 1024); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 78 | |
Daniel Vetter | ff93f35 | 2012-03-24 19:22:21 +0100 | [diff] [blame] | 79 | ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 80 | igt_assert(ptr); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 81 | |
| 82 | /* XXX: mmap_gtt pulls the bo into the GTT read domain. */ |
Daniel Vetter | 673e6b2 | 2012-01-10 16:05:34 +0100 | [diff] [blame] | 83 | gem_sync(fd, handle); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 84 | |
| 85 | return ptr; |
| 86 | } |
| 87 | |
| 88 | static void * |
| 89 | bo_copy (void *_arg) |
| 90 | { |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 91 | struct test *t = (struct test *)_arg; |
| 92 | int fd = t->fd; |
Daniel Vetter | 2e9e27c | 2011-10-15 13:46:19 +0200 | [diff] [blame] | 93 | int n; |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 94 | char *a, *b; |
| 95 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 96 | a = bo_create (fd, t->tiling); |
| 97 | b = bo_create (fd, t->tiling); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 98 | |
Daniel Vetter | 2e9e27c | 2011-10-15 13:46:19 +0200 | [diff] [blame] | 99 | for (n = 0; n < 1000; n++) { |
| 100 | memcpy (a, b, OBJECT_SIZE); |
Alan Coopersmith | 0075159 | 2012-01-06 15:45:28 -0800 | [diff] [blame] | 101 | sched_yield (); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | return NULL; |
| 105 | } |
| 106 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 107 | static void |
| 108 | _bo_write_verify(struct test *t) |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 109 | { |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 110 | int fd = t->fd; |
| 111 | int i, k; |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 112 | uint32_t **s; |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 113 | uint32_t v; |
| 114 | unsigned int dwords = OBJECT_SIZE >> 2; |
| 115 | const char *tile_str[] = { "none", "x", "y" }; |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 116 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 117 | assert (t->tiling >= 0 && t->tiling <= I915_TILING_Y); |
| 118 | assert (t->num_surfaces > 0); |
| 119 | |
Chris Wilson | 74f6e41 | 2013-03-27 11:32:47 +0000 | [diff] [blame] | 120 | s = calloc(sizeof(*s), t->num_surfaces); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 121 | igt_assert(s); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 122 | |
Chris Wilson | 74f6e41 | 2013-03-27 11:32:47 +0000 | [diff] [blame] | 123 | for (k = 0; k < t->num_surfaces; k++) |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 124 | s[k] = bo_create(fd, t->tiling); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 125 | |
| 126 | for (k = 0; k < t->num_surfaces; k++) { |
| 127 | volatile uint32_t *a = s[k]; |
| 128 | |
| 129 | for (i = 0; i < dwords; i++) { |
| 130 | a[i] = i; |
| 131 | v = a[i]; |
| 132 | if (v != i) { |
| 133 | printf("tiling %s: write failed at %d (%x)\n", |
| 134 | tile_str[t->tiling], i, v); |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 135 | igt_fail(-1); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | for (i = 0; i < dwords; i++) { |
| 140 | v = a[i]; |
| 141 | if (v != i) { |
| 142 | printf("tiling %s: verify failed at %d (%x)\n", |
| 143 | tile_str[t->tiling], i, v); |
Daniel Vetter | 5e25fcc | 2013-08-13 12:56:06 +0200 | [diff] [blame] | 144 | igt_fail(-2); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 149 | for (k = 0; k < t->num_surfaces; k++) |
| 150 | munmap(s[k], OBJECT_SIZE); |
| 151 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 152 | free(s); |
| 153 | } |
| 154 | |
| 155 | static void * |
| 156 | bo_write_verify(void *_arg) |
| 157 | { |
| 158 | struct test *t = (struct test *)_arg; |
| 159 | int i; |
| 160 | |
| 161 | for (i = 0; i < 10; i++) |
| 162 | _bo_write_verify(t); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int run_test(int threads_per_fence, void *f, int tiling, |
| 168 | int surfaces_per_thread) |
| 169 | { |
| 170 | struct test t; |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 171 | pthread_t *threads; |
| 172 | int n, num_fences, num_threads; |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 173 | |
| 174 | t.fd = drm_open_any(); |
| 175 | t.tiling = tiling; |
| 176 | t.num_surfaces = surfaces_per_thread; |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 177 | |
Ville Syrjälä | 1d1f683 | 2013-04-09 15:25:38 +0300 | [diff] [blame] | 178 | num_fences = gem_available_fences(t.fd); |
| 179 | assert (num_fences > 0); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 180 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 181 | num_threads = threads_per_fence * num_fences; |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 182 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 183 | printf("%s: threads %d, fences %d, tiling %d, surfaces per thread %d\n", |
| 184 | f == bo_copy ? "copy" : "write-verify", num_threads, |
| 185 | num_fences, tiling, surfaces_per_thread); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 186 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 187 | if (threads_per_fence) { |
| 188 | threads = calloc(sizeof(*threads), num_threads); |
| 189 | assert (threads != NULL); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 190 | |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 191 | for (n = 0; n < num_threads; n++) |
| 192 | pthread_create (&threads[n], NULL, f, &t); |
| 193 | |
| 194 | for (n = 0; n < num_threads; n++) |
| 195 | pthread_join (threads[n], NULL); |
| 196 | } else { |
| 197 | void *(*func)(void *) = f; |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 198 | igt_assert(func(&t) == (void *)0); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | close(t.fd); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | int |
| 207 | main(int argc, char **argv) |
| 208 | { |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 209 | igt_subtest_init(argc, argv); |
| 210 | igt_skip_on_simulation(); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 211 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 212 | igt_subtest("bo-write-verify-none") |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 213 | assert (run_test(0, bo_write_verify, I915_TILING_NONE, 80) == 0); |
| 214 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 215 | igt_subtest("bo-write-verify-x") |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 216 | assert (run_test(0, bo_write_verify, I915_TILING_X, 80) == 0); |
| 217 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 218 | igt_subtest("bo-write-verify-y") |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 219 | assert (run_test(0, bo_write_verify, I915_TILING_Y, 80) == 0); |
| 220 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 221 | igt_subtest("bo-write-verify-threaded-none") |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 222 | assert (run_test(5, bo_write_verify, I915_TILING_NONE, 2) == 0); |
| 223 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 224 | igt_subtest("bo-write-verify-threaded-x") { |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 225 | assert (run_test(2, bo_write_verify, I915_TILING_X, 2) == 0); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 226 | assert (run_test(5, bo_write_verify, I915_TILING_X, 2) == 0); |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 227 | assert (run_test(10, bo_write_verify, I915_TILING_X, 2) == 0); |
| 228 | assert (run_test(20, bo_write_verify, I915_TILING_X, 2) == 0); |
| 229 | } |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 230 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 231 | igt_subtest("bo-write-verify-threaded-y") { |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 232 | assert (run_test(2, bo_write_verify, I915_TILING_Y, 2) == 0); |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 233 | assert (run_test(5, bo_write_verify, I915_TILING_Y, 2) == 0); |
Daniel Vetter | 0a8bfbf | 2013-04-08 09:19:05 +0200 | [diff] [blame] | 234 | assert (run_test(10, bo_write_verify, I915_TILING_Y, 2) == 0); |
| 235 | assert (run_test(20, bo_write_verify, I915_TILING_Y, 2) == 0); |
| 236 | } |
Mika Kuoppala | ee79b8f | 2013-03-27 12:48:07 +0200 | [diff] [blame] | 237 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 238 | igt_subtest("bo-copy") |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 239 | igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 240 | |
Daniel Vetter | a1ca8ef | 2013-08-14 16:02:24 +0200 | [diff] [blame] | 241 | igt_exit(); |
Chris Wilson | 8f3f862 | 2009-09-01 10:09:55 +0100 | [diff] [blame] | 242 | } |