2 * Copyright © 2008-9 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
25 * Chris Wilson <chris@chris-wilson.co.uk>
42 #include <sys/ioctl.h>
49 #define OBJECT_SIZE (128*1024) /* restricted to 1MiB alignment on i915 fences */
51 /* Before introduction of the LRU list for fences, allocation of a fence for a page
52 * fault would use the first inactive fence (i.e. in preference one with no outstanding
53 * GPU activity, or it would wait on the first to finish). Given the choice, it would simply
54 * reuse the fence that had just been allocated for the previous page-fault - the worst choice
55 * when copying between two buffers and thus constantly swapping fences.
65 bo_create (int fd, int tiling)
70 handle = gem_create(fd, OBJECT_SIZE);
72 /* dirty cpu caches a bit ... */
73 ptr = gem_mmap__cpu(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
75 memset(ptr, 0, OBJECT_SIZE);
76 munmap(ptr, OBJECT_SIZE);
78 gem_set_tiling(fd, handle, tiling, 1024);
80 ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
83 /* XXX: mmap_gtt pulls the bo into the GTT read domain. */
92 struct test *t = (struct test *)_arg;
97 a = bo_create (fd, t->tiling);
98 b = bo_create (fd, t->tiling);
100 for (n = 0; n < 1000; n++) {
101 memcpy (a, b, OBJECT_SIZE);
109 _bo_write_verify(struct test *t)
115 unsigned int dwords = OBJECT_SIZE >> 2;
116 const char *tile_str[] = { "none", "x", "y" };
118 assert (t->tiling >= 0 && t->tiling <= I915_TILING_Y);
119 assert (t->num_surfaces > 0);
121 s = calloc(sizeof(*s), t->num_surfaces);
124 for (k = 0; k < t->num_surfaces; k++)
125 s[k] = bo_create(fd, t->tiling);
127 for (k = 0; k < t->num_surfaces; k++) {
128 volatile uint32_t *a = s[k];
130 for (i = 0; i < dwords; i++) {
134 printf("tiling %s: write failed at %d (%x)\n",
135 tile_str[t->tiling], i, v);
140 for (i = 0; i < dwords; i++) {
143 printf("tiling %s: verify failed at %d (%x)\n",
144 tile_str[t->tiling], i, v);
150 for (k = 0; k < t->num_surfaces; k++)
151 munmap(s[k], OBJECT_SIZE);
157 bo_write_verify(void *_arg)
159 struct test *t = (struct test *)_arg;
162 for (i = 0; i < 10; i++)
168 static int run_test(int threads_per_fence, void *f, int tiling,
169 int surfaces_per_thread)
173 int n, num_fences, num_threads;
175 t.fd = drm_open_any();
177 t.num_surfaces = surfaces_per_thread;
179 num_fences = gem_available_fences(t.fd);
180 assert (num_fences > 0);
182 num_threads = threads_per_fence * num_fences;
184 printf("%s: threads %d, fences %d, tiling %d, surfaces per thread %d\n",
185 f == bo_copy ? "copy" : "write-verify", num_threads,
186 num_fences, tiling, surfaces_per_thread);
188 if (threads_per_fence) {
189 threads = calloc(sizeof(*threads), num_threads);
190 assert (threads != NULL);
192 for (n = 0; n < num_threads; n++)
193 pthread_create (&threads[n], NULL, f, &t);
195 for (n = 0; n < num_threads; n++)
196 pthread_join (threads[n], NULL);
198 void *(*func)(void *) = f;
199 assert(func(&t) == (void *)0);
208 main(int argc, char **argv)
210 drmtest_subtest_init(argc, argv);
212 if (drmtest_run_subtest("bo-write-verify-none"))
213 assert (run_test(0, bo_write_verify, I915_TILING_NONE, 80) == 0);
215 if (drmtest_run_subtest("bo-write-verify-x"))
216 assert (run_test(0, bo_write_verify, I915_TILING_X, 80) == 0);
218 if (drmtest_run_subtest("bo-write-verify-y"))
219 assert (run_test(0, bo_write_verify, I915_TILING_Y, 80) == 0);
221 if (drmtest_run_subtest("bo-write-verify-threaded-none"))
222 assert (run_test(5, bo_write_verify, I915_TILING_NONE, 2) == 0);
224 if (drmtest_run_subtest("bo-write-verify-threaded-x")) {
225 assert (run_test(2, bo_write_verify, I915_TILING_X, 2) == 0);
226 assert (run_test(5, bo_write_verify, I915_TILING_X, 2) == 0);
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);
231 if (drmtest_run_subtest("bo-write-verify-threaded-y")) {
232 assert (run_test(2, bo_write_verify, I915_TILING_Y, 2) == 0);
233 assert (run_test(5, bo_write_verify, I915_TILING_Y, 2) == 0);
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);
238 if (drmtest_run_subtest("bo-copy"))
239 assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);