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>
41 #include <sys/ioctl.h>
44 #include "ioctl_wrappers.h"
47 #define OBJECT_SIZE (128*1024) /* restricted to 1MiB alignment on i915 fences */
49 /* Before introduction of the LRU list for fences, allocation of a fence for a page
50 * fault would use the first inactive fence (i.e. in preference one with no outstanding
51 * GPU activity, or it would wait on the first to finish). Given the choice, it would simply
52 * reuse the fence that had just been allocated for the previous page-fault - the worst choice
53 * when copying between two buffers and thus constantly swapping fences.
63 bo_create (int fd, int tiling)
68 handle = gem_create(fd, OBJECT_SIZE);
70 /* dirty cpu caches a bit ... */
71 ptr = gem_mmap__cpu(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
73 memset(ptr, 0, OBJECT_SIZE);
74 munmap(ptr, OBJECT_SIZE);
76 gem_set_tiling(fd, handle, tiling, 1024);
78 ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
81 /* XXX: mmap_gtt pulls the bo into the GTT read domain. */
90 struct test *t = (struct test *)_arg;
95 a = bo_create (fd, t->tiling);
96 b = bo_create (fd, t->tiling);
98 for (n = 0; n < 1000; n++) {
99 memcpy (a, b, OBJECT_SIZE);
107 _bo_write_verify(struct test *t)
113 unsigned int dwords = OBJECT_SIZE >> 2;
114 const char *tile_str[] = { "none", "x", "y" };
116 igt_assert(t->tiling >= 0 && t->tiling <= I915_TILING_Y);
117 igt_assert(t->num_surfaces > 0);
119 s = calloc(sizeof(*s), t->num_surfaces);
122 for (k = 0; k < t->num_surfaces; k++)
123 s[k] = bo_create(fd, t->tiling);
125 for (k = 0; k < t->num_surfaces; k++) {
126 volatile uint32_t *a = s[k];
128 for (i = 0; i < dwords; i++) {
132 "tiling %s: write failed at %d (%x)\n",
133 tile_str[t->tiling], i, v);
136 for (i = 0; i < dwords; i++) {
139 "tiling %s: verify failed at %d (%x)\n",
140 tile_str[t->tiling], i, v);
144 for (k = 0; k < t->num_surfaces; k++)
145 munmap(s[k], OBJECT_SIZE);
151 bo_write_verify(void *_arg)
153 struct test *t = (struct test *)_arg;
156 for (i = 0; i < 10; i++)
162 static int run_test(int threads_per_fence, void *f, int tiling,
163 int surfaces_per_thread)
167 int n, num_fences, num_threads;
169 t.fd = drm_open_any();
171 t.num_surfaces = surfaces_per_thread;
173 num_fences = gem_available_fences(t.fd);
174 igt_assert(num_fences > 0);
176 num_threads = threads_per_fence * num_fences;
178 igt_info("%s: threads %d, fences %d, tiling %d, surfaces per thread %d\n",
179 f == bo_copy ? "copy" : "write-verify", num_threads,
180 num_fences, tiling, surfaces_per_thread);
182 if (threads_per_fence) {
183 threads = calloc(sizeof(*threads), num_threads);
184 igt_assert(threads != NULL);
186 for (n = 0; n < num_threads; n++)
187 pthread_create (&threads[n], NULL, f, &t);
189 for (n = 0; n < num_threads; n++)
190 pthread_join (threads[n], NULL);
192 void *(*func)(void *) = f;
193 igt_assert(func(&t) == (void *)0);
203 igt_skip_on_simulation();
205 igt_subtest("bo-write-verify-none")
206 igt_assert(run_test(0, bo_write_verify, I915_TILING_NONE, 80) == 0);
208 igt_subtest("bo-write-verify-x")
209 igt_assert(run_test(0, bo_write_verify, I915_TILING_X, 80) == 0);
211 igt_subtest("bo-write-verify-y")
212 igt_assert(run_test(0, bo_write_verify, I915_TILING_Y, 80) == 0);
214 igt_subtest("bo-write-verify-threaded-none")
215 igt_assert(run_test(5, bo_write_verify, I915_TILING_NONE, 2) == 0);
217 igt_subtest("bo-write-verify-threaded-x") {
218 igt_assert(run_test(2, bo_write_verify, I915_TILING_X, 2) == 0);
219 igt_assert(run_test(5, bo_write_verify, I915_TILING_X, 2) == 0);
220 igt_assert(run_test(10, bo_write_verify, I915_TILING_X, 2) == 0);
221 igt_assert(run_test(20, bo_write_verify, I915_TILING_X, 2) == 0);
224 igt_subtest("bo-write-verify-threaded-y") {
225 igt_assert(run_test(2, bo_write_verify, I915_TILING_Y, 2) == 0);
226 igt_assert(run_test(5, bo_write_verify, I915_TILING_Y, 2) == 0);
227 igt_assert(run_test(10, bo_write_verify, I915_TILING_Y, 2) == 0);
228 igt_assert(run_test(20, bo_write_verify, I915_TILING_Y, 2) == 0);
231 igt_subtest("bo-copy")
232 igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);